1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-22 06:02:11 +02:00

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
This commit is contained in:
Jeff Johnston 2019-04-12 23:13:36 -04:00
parent a7bb1da5e3
commit e153fa920d
8 changed files with 152 additions and 45 deletions

View file

@ -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",

View file

@ -11,3 +11,4 @@
pluginName=CDT Autotools Core
providerName=Eclipse CDT
extension-point.name = Autotools Core ToolChain File Provider

View file

@ -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$
}
}
}

View file

@ -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;
}

View file

@ -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);
}
}

View file

@ -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([

View file

@ -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"/>

View file

@ -1,2 +1,2 @@
bin_PROGRAMS = hello
hello_SOURCES = main.c
bin_PROGRAMS = ${projectName}
${projectName}_SOURCES = ${projectName}.c