Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeff Johnston2019-04-12 23:13:36 -0400
committerJeff Johnston2019-04-15 16:17:53 -0400
commite153fa920d41caf4456943e9950f79866215dcb2 (patch)
treed5e30b9f4d1e213624287fd7db2617d531e9cae0
parenta7bb1da5e314e9b1af2f54ffe568e7e1203251e2 (diff)
downloadorg.eclipse.cdt-e153fa920d41caf4456943e9950f79866215dcb2.tar.gz
org.eclipse.cdt-e153fa920d41caf4456943e9950f79866215dcb2.tar.xz
org.eclipse.cdt-e153fa920d41caf4456943e9950f79866215dcb2.zip
Bug 546390 - Add Container build support to new Core Autotools
- add support for Container builds to AutotoolsBuildConfiguration, AutotoolsBuildConfigurationProvider - fix core Autotools templates to set up the default source and binary to be the same as the project name Change-Id: Ib262c1f6ddd65b136be2d2d3d25601226ddd289f
-rw-r--r--build/org.eclipse.cdt.core.autotools.core/META-INF/MANIFEST.MF2
-rw-r--r--build/org.eclipse.cdt.core.autotools.core/plugin.properties1
-rw-r--r--build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfiguration.java69
-rw-r--r--build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfigurationProvider.java89
-rw-r--r--build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/internal/Activator.java28
-rw-r--r--build/org.eclipse.cdt.core.autotools.core/templates/autotools/configure.ac2
-rw-r--r--build/org.eclipse.cdt.core.autotools.core/templates/autotools/manifest.xml2
-rw-r--r--build/org.eclipse.cdt.core.autotools.core/templates/autotools/src/Makefile.am4
8 files changed, 152 insertions, 45 deletions
diff --git a/build/org.eclipse.cdt.core.autotools.core/META-INF/MANIFEST.MF b/build/org.eclipse.cdt.core.autotools.core/META-INF/MANIFEST.MF
index 9854912f7e..30c228a6d3 100644
--- a/build/org.eclipse.cdt.core.autotools.core/META-INF/MANIFEST.MF
+++ b/build/org.eclipse.cdt.core.autotools.core/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.cdt.core.autotools.core;singleton:=true
-Bundle-Version: 1.0.1.qualifier
+Bundle-Version: 1.1.0.qualifier
Bundle-Activator: org.eclipse.cdt.core.autotools.core.internal.Activator
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.tools.templates.freemarker;bundle-version="1.0.0",
diff --git a/build/org.eclipse.cdt.core.autotools.core/plugin.properties b/build/org.eclipse.cdt.core.autotools.core/plugin.properties
index 099d7ca137..d255905e52 100644
--- a/build/org.eclipse.cdt.core.autotools.core/plugin.properties
+++ b/build/org.eclipse.cdt.core.autotools.core/plugin.properties
@@ -11,3 +11,4 @@
pluginName=CDT Autotools Core
providerName=Eclipse CDT
+extension-point.name = Autotools Core ToolChain File Provider
diff --git a/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfiguration.java b/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfiguration.java
index 32064b98df..f649754077 100644
--- a/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfiguration.java
+++ b/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfiguration.java
@@ -16,14 +16,20 @@ package org.eclipse.cdt.core.autotools.core;
import java.io.IOException;
import java.nio.file.Path;
+import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
+import org.eclipse.cdt.core.ConsoleOutputStream;
+import org.eclipse.cdt.core.ErrorParserManager;
+import org.eclipse.cdt.core.IConsoleParser;
import org.eclipse.cdt.core.autotools.core.internal.Activator;
import org.eclipse.cdt.core.build.CBuildConfiguration;
import org.eclipse.cdt.core.build.IToolChain;
+import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
+import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.core.resources.IBuildConfiguration;
import org.eclipse.core.resources.IProject;
@@ -48,6 +54,11 @@ public class AutotoolsBuildConfiguration extends CBuildConfiguration {
super(config, name, toolChain, "run"); // TODO: why "run" //$NON-NLS-1$
}
+ public AutotoolsBuildConfiguration(IBuildConfiguration config, String name, IToolChain toolChain,
+ String launchMode) {
+ super(config, name, toolChain, launchMode);
+ }
+
@Override
public IProject[] build(int kind, Map<String, String> args, IConsole console, IProgressMonitor monitor)
throws CoreException {
@@ -55,15 +66,15 @@ public class AutotoolsBuildConfiguration extends CBuildConfiguration {
IProject project = getProject();
execute(Arrays.asList(new String[] { "autoreconf", "--install" }), project.getLocation(), console, monitor); //$NON-NLS-1$ //$NON-NLS-2$
- execute(Arrays.asList(new String[] { "./configure" }), project.getLocation(), console, monitor); //$NON-NLS-1$
- execute(Arrays.asList(new String[] { "make" }), project.getLocation(), console, monitor); //$NON-NLS-1$
+ executeRemote(Arrays.asList(new String[] { "./configure" }), project.getLocation(), console, monitor); //$NON-NLS-1$
+ executeRemote(Arrays.asList(new String[] { "make" }), project.getLocation(), console, monitor); //$NON-NLS-1$
return new IProject[] { project };
}
@Override
public void clean(IConsole console, IProgressMonitor monitor) throws CoreException {
- execute(Arrays.asList(new String[] { "make", "clean" }), getProject().getLocation(), console, monitor); //$NON-NLS-1$ //$NON-NLS-2$
+ executeRemote(Arrays.asList(new String[] { "make", "clean" }), getProject().getLocation(), console, monitor); //$NON-NLS-1$ //$NON-NLS-2$
}
protected void execute(List<String> command, IPath dir, IConsole console, IProgressMonitor monitor)
@@ -97,10 +108,60 @@ public class AutotoolsBuildConfiguration extends CBuildConfiguration {
Process process = builder.start();
watchProcess(process, console);
} catch (IOException e) {
- throw new CoreException(Activator.errorStatus("Error executing: " + String.join(" ", command), e)); //$NON-NLS-2$
+ throw new CoreException(Activator.errorStatus("Error executing: " + String.join(" ", command), e)); //$NON-NLS-1$ //$NON-NLS-2$
}
getProject().refreshLocal(IResource.DEPTH_INFINITE, monitor);
}
+ protected void executeRemote(List<String> command, IPath dir, IConsole console, IProgressMonitor monitor)
+ throws CoreException {
+
+ IProject project = getProject();
+
+ try {
+ project.deleteMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE);
+
+ ConsoleOutputStream outStream = console.getOutputStream();
+
+ Path buildDir = getBuildDirectory();
+
+ String cmd = command.get(0);
+
+ if (cmd.startsWith(".")) { //$NON-NLS-1$
+ Path cmdPath = Paths.get(dir.toString(), cmd);
+ if (cmdPath.toFile().exists()) {
+ command.set(0, cmdPath.toAbsolutePath().toString());
+ }
+ }
+
+ outStream.write("Building in: " + buildDir.toString() + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
+
+ try (ErrorParserManager epm = new ErrorParserManager(project, getBuildDirectoryURI(), this,
+ getToolChain().getErrorParserIds())) {
+ epm.setOutputStream(console.getOutputStream());
+
+ IEnvironmentVariable[] env = new IEnvironmentVariable[0];
+
+ org.eclipse.core.runtime.Path workingDir = new org.eclipse.core.runtime.Path(
+ getBuildDirectory().toString());
+
+ Process p = startBuildProcess(command, env, workingDir, console, monitor);
+ if (p == null) {
+ console.getErrorStream().write(String.format("Error executing: {0}", String.join(" ", command))); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new CoreException(
+ Activator.errorStatus("Error executing: " + String.join(" ", command), null)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ watchProcess(p, new IConsoleParser[] { epm });
+ }
+
+ project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
+
+ } catch (IOException e) {
+ throw new CoreException(Activator.errorStatus("Error executing: " + String.join(" ", command), e)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ }
+
}
diff --git a/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfigurationProvider.java b/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfigurationProvider.java
index f43b3dcdd5..ae4f6087d1 100644
--- a/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfigurationProvider.java
+++ b/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/AutotoolsBuildConfigurationProvider.java
@@ -18,7 +18,6 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.cdt.core.autotools.core.internal.Activator;
-import org.eclipse.cdt.core.build.CBuildConfiguration;
import org.eclipse.cdt.core.build.ICBuildConfiguration;
import org.eclipse.cdt.core.build.ICBuildConfigurationManager;
import org.eclipse.cdt.core.build.ICBuildConfigurationProvider;
@@ -43,48 +42,45 @@ public class AutotoolsBuildConfigurationProvider implements ICBuildConfiguration
@Override
public ICBuildConfiguration getCBuildConfiguration(IBuildConfiguration config, String name) throws CoreException {
- IToolChain toolChain = null;
+ if (config.getName().equals(IBuildConfiguration.DEFAULT_CONFIG_NAME)) {
+ IToolChain toolChain = null;
- // try the toolchain for the local target
- Map<String, String> properties = new HashMap<>();
- properties.put(IToolChain.ATTR_OS, Platform.getOS());
- properties.put(IToolChain.ATTR_ARCH, Platform.getOSArch());
- IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class);
- for (IToolChain tc : toolChainManager.getToolChainsMatching(properties)) {
- toolChain = tc;
- break;
- }
-
- // local didn't work, try and find one that does
- if (toolChain == null) {
- for (IToolChain tc : toolChainManager.getToolChainsMatching(new HashMap<>())) {
+ // try the toolchain for the local target
+ Map<String, String> properties = new HashMap<>();
+ properties.put(IToolChain.ATTR_OS, Platform.getOS());
+ properties.put(IToolChain.ATTR_ARCH, Platform.getOSArch());
+ IToolChainManager toolChainManager = Activator.getService(IToolChainManager.class);
+ for (IToolChain tc : toolChainManager.getToolChainsMatching(properties)) {
toolChain = tc;
break;
}
- }
- if (toolChain != null) {
- return new AutotoolsBuildConfiguration(config, name, toolChain);
- } else {
+ // local didn't work, try and find one that does
+ if (toolChain == null) {
+ for (IToolChain tc : toolChainManager.getToolChainsMatching(new HashMap<>())) {
+ toolChain = tc;
+ break;
+ }
+ }
+
+ if (toolChain != null) {
+ return new AutotoolsBuildConfiguration(config, name, toolChain);
+ }
+ // No valid combinations
+ return null;
+ }
+ AutotoolsBuildConfiguration autotoolsConfig = new AutotoolsBuildConfiguration(config, name);
+ IToolChain toolChain = autotoolsConfig.getToolChain();
+ if (toolChain == null) {
+ // config not complete
return null;
}
+ return autotoolsConfig;
}
@Override
public ICBuildConfiguration createBuildConfiguration(IProject project, IToolChain toolChain, String launchMode,
IProgressMonitor monitor) throws CoreException {
- // See if there is one already
- for (IBuildConfiguration config : project.getBuildConfigs()) {
- ICBuildConfiguration cconfig = config.getAdapter(ICBuildConfiguration.class);
- if (cconfig != null) {
- CBuildConfiguration cmakeConfig = cconfig.getAdapter(AutotoolsBuildConfiguration.class);
- if (cmakeConfig != null && cmakeConfig.getToolChain().equals(toolChain)
- && launchMode.equals(cmakeConfig.getLaunchMode())) {
- return cconfig;
- }
- }
- }
-
// get matching toolchain file if any
Map<String, String> properties = new HashMap<>();
String os = toolChain.getProperty(IToolChain.ATTR_OS);
@@ -92,14 +88,37 @@ public class AutotoolsBuildConfigurationProvider implements ICBuildConfiguration
properties.put(IToolChain.ATTR_OS, os);
}
String arch = toolChain.getProperty(IToolChain.ATTR_ARCH);
- if (!arch.isEmpty()) {
+ if (arch != null && !arch.isEmpty()) {
properties.put(IToolChain.ATTR_ARCH, arch);
}
// create config
- String configName = "autotools." + launchMode + '.' + toolChain.getId(); //$NON-NLS-1$
- IBuildConfiguration config = configManager.createBuildConfiguration(this, project, configName, monitor);
- CBuildConfiguration autotoolsConfig = new AutotoolsBuildConfiguration(config, configName);
+ StringBuilder configName = new StringBuilder("autotools."); //$NON-NLS-1$
+ configName.append(launchMode);
+ if ("linux-container".equals(os)) { //$NON-NLS-1$
+ String osConfigName = toolChain.getProperty("linux-container-id"); //$NON-NLS-1$
+ osConfigName = osConfigName.replaceAll("/", "_"); //$NON-NLS-1$ //$NON-NLS-2$
+ configName.append('.');
+ configName.append(osConfigName);
+ } else {
+ if (os != null) {
+ configName.append('.');
+ configName.append(os);
+ }
+ if (arch != null && !arch.isEmpty()) {
+ configName.append('.');
+ configName.append(arch);
+ }
+ }
+ String name = configName.toString();
+ int i = 0;
+ while (configManager.hasConfiguration(this, project, name)) {
+ name = configName.toString() + '.' + (++i);
+ }
+
+ IBuildConfiguration config = configManager.createBuildConfiguration(this, project, name, monitor);
+ AutotoolsBuildConfiguration autotoolsConfig = new AutotoolsBuildConfiguration(config, name, toolChain,
+ launchMode);
configManager.addBuildConfiguration(config, autotoolsConfig);
return autotoolsConfig;
}
diff --git a/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/internal/Activator.java b/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/internal/Activator.java
index cc83a33894..74ff7d5cbe 100644
--- a/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/internal/Activator.java
+++ b/build/org.eclipse.cdt.core.autotools.core/src/org/eclipse/cdt/core/autotools/core/internal/Activator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2017 Intel Corporation and others.
+ * Copyright (c) 2017, 2019 Intel Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -14,6 +14,10 @@
package org.eclipse.cdt.core.autotools.core.internal;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.osgi.framework.BundleActivator;
@@ -49,4 +53,26 @@ public class Activator implements BundleActivator {
ServiceReference<T> ref = context.getServiceReference(service);
return ref != null ? context.getService(ref) : null;
}
+
+ public static void log(IStatus status) {
+ ResourcesPlugin.getPlugin().getLog().log(status);
+ }
+
+ public static void logErrorMessage(String message) {
+ log(new Status(IStatus.ERROR, PLUGIN_ID, IStatus.ERROR, message, null));
+ }
+
+ public static void log(Throwable e) {
+ if (e instanceof InvocationTargetException) {
+ e = ((InvocationTargetException) e).getTargetException();
+ }
+ IStatus status = null;
+ if (e instanceof CoreException) {
+ status = ((CoreException) e).getStatus();
+ } else {
+ status = new Status(IStatus.ERROR, PLUGIN_ID, IStatus.OK, e.getMessage(), e);
+ }
+ log(status);
+ }
+
}
diff --git a/build/org.eclipse.cdt.core.autotools.core/templates/autotools/configure.ac b/build/org.eclipse.cdt.core.autotools.core/templates/autotools/configure.ac
index be8adeb125..68d358f55e 100644
--- a/build/org.eclipse.cdt.core.autotools.core/templates/autotools/configure.ac
+++ b/build/org.eclipse.cdt.core.autotools.core/templates/autotools/configure.ac
@@ -1,4 +1,4 @@
-AC_INIT([main)], [1.0])
+AC_INIT([${projectName}], [1.0])
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_CONFIG_FILES([
diff --git a/build/org.eclipse.cdt.core.autotools.core/templates/autotools/manifest.xml b/build/org.eclipse.cdt.core.autotools.core/templates/autotools/manifest.xml
index 113682f647..6469bca65b 100644
--- a/build/org.eclipse.cdt.core.autotools.core/templates/autotools/manifest.xml
+++ b/build/org.eclipse.cdt.core.autotools.core/templates/autotools/manifest.xml
@@ -6,7 +6,7 @@
<file src="/templates/autotools/Makefile.am"
dest="/${projectName}/Makefile.am"/>
<file src="/templates/autotools/src/main.c"
- dest="/${projectName}/src/main.c"
+ dest="/${projectName}/src/${projectName}.c"
open="true"/>
<file src="/templates/autotools/src/Makefile.am"
dest="/${projectName}/src/Makefile.am"/>
diff --git a/build/org.eclipse.cdt.core.autotools.core/templates/autotools/src/Makefile.am b/build/org.eclipse.cdt.core.autotools.core/templates/autotools/src/Makefile.am
index 0552a00794..a0c01e0411 100644
--- a/build/org.eclipse.cdt.core.autotools.core/templates/autotools/src/Makefile.am
+++ b/build/org.eclipse.cdt.core.autotools.core/templates/autotools/src/Makefile.am
@@ -1,2 +1,2 @@
-bin_PROGRAMS = hello
-hello_SOURCES = main.c
+bin_PROGRAMS = ${projectName}
+${projectName}_SOURCES = ${projectName}.c

Back to the top