1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-13 03:55:22 +02:00

Bug 528169 - Run autotools commands within containers

- add new optional build property to run all Autotool
  commands in Container
- for Autotool nature projects only, add a checkbox to the
  ContainerPropertyTab to turn this new option on/off
- change the AbstractAutotoolsHandler class to look at the
  optional build properties for the project to determine if
  the fallback CommandLauncher used to run commands should come from
  the CommandLauncherManager to run in Container or to a
  local CommandLauncher
- change AutotoolsNewMakeGenerator the same way
- add new messages as needed (add a tooltip to warn user that
  choosing new option may cause inconsistencies for files shared
  among configurations)

Change-Id: Id828ec3015f32f320d2247bd0577944164c71df8
This commit is contained in:
Jeff Johnston 2018-01-05 15:11:03 -05:00
parent 7627e275ef
commit 1ae56d435a
5 changed files with 119 additions and 10 deletions

View file

@ -51,6 +51,7 @@ import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.make.core.makefile.IMakefile;
import org.eclipse.cdt.make.core.makefile.ITarget;
import org.eclipse.cdt.make.core.makefile.ITargetRule;
import org.eclipse.cdt.managedbuilder.buildproperties.IOptionalBuildProperties;
import org.eclipse.cdt.managedbuilder.core.IBuilder;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
@ -114,6 +115,9 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
private static final String TARGET = "buildTarget"; //$NON-NLS-1$
private static final String DEFAULT_AUTORECONF = "autoreconf"; //$NON-NLS-1$
public static final String RUN_IN_CONFIGURE_LAUNCHER = "org.eclipse.cdt.autotools.core.property.launchAutotoolsInContainer"; //$NON-NLS-1$
private IProject project;
private IProgressMonitor monitor;
@ -341,6 +345,15 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
initializeBuildConfigDirs(icfg, toolsCfg);
ICommandLauncher configureLauncher = CommandLauncherManager.getInstance().getCommandLauncher(project);
IOptionalBuildProperties props = icfg.getOptionalBuildProperties();
boolean runInCfgLauncher = false;
if (props != null) {
String runInCfgLauncherProperty = props.getProperty(RUN_IN_CONFIGURE_LAUNCHER);
if (runInCfgLauncherProperty != null) {
runInCfgLauncher = Boolean.parseBoolean(runInCfgLauncherProperty);
}
}
// Create the top-level directory for the build output
if (!createDirectory(buildDir)) {
@ -397,7 +410,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
System.arraycopy(newArgs, 0, makeargs, 0, newArgs.length);
}
makeargs[makeargs.length - 1] = target;
rc = runCommand(localCommandLauncher, makeCmd,
rc = runCommand(runInCfgLauncher ? configureLauncher : localCommandLauncher, makeCmd,
getProjectLocation(),
makeargs,
AutotoolsPlugin.getResourceString("MakeGenerator.clean.topdir"), //$NON-NLS-1$
@ -447,7 +460,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
System.arraycopy(newArgs, 0, makeargs, 0, newArgs.length);
}
makeargs[makeargs.length - 1] = target;
rc = runCommand(localCommandLauncher, makeCmd,
rc = runCommand(runInCfgLauncher ? configureLauncher : localCommandLauncher, makeCmd,
buildLocation,
makeargs,
AutotoolsPlugin.getFormattedString("MakeGenerator.clean.builddir", new String[]{buildDir}), //$NON-NLS-1$
@ -509,7 +522,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
configStatus.delete();
// Get any user-specified arguments for autogen.
String[] autogenArgs = getAutogenArgs(autogenCmdParms);
rc = runScript(localCommandLauncher, autogenPath,
rc = runScript(runInCfgLauncher ? configureLauncher : localCommandLauncher, autogenPath,
autogenPath.removeLastSegments(1), autogenArgs,
AutotoolsPlugin.getFormattedString("MakeGenerator.autogen.sh", new String[]{buildDir}), //$NON-NLS-1$
errMsg, console, autogenEnvs, consoleStart);
@ -532,7 +545,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
reconfCmd = DEFAULT_AUTORECONF;
IPath reconfCmdPath = new Path(reconfCmd);
reconfArgs[0] = "-i"; //$NON-NLS-1$
rc = runScript(localCommandLauncher, reconfCmdPath,
rc = runScript(runInCfgLauncher ? configureLauncher : localCommandLauncher, reconfCmdPath,
getSourcePath(),
reconfArgs,
AutotoolsPlugin.getFormattedString("MakeGenerator.autoreconf", new String[]{buildDir}), //$NON-NLS-1$
@ -565,7 +578,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
String[] makeargs = new String[1];
IPath makeCmd = builder.getBuildCommand();
makeargs[0] = "-f" + getMakefileCVSPath().toOSString(); //$NON-NLS-1$
rc = runCommand(localCommandLauncher, makeCmd,
rc = runCommand(runInCfgLauncher ? configureLauncher : localCommandLauncher, makeCmd,
getProjectLocation().append(buildDir),
makeargs,
AutotoolsPlugin.getFormattedString("MakeGenerator.makefile.cvs", new String[]{buildDir}), //$NON-NLS-1$
@ -597,7 +610,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
reconfCmd = DEFAULT_AUTORECONF;
IPath reconfCmdPath = new Path(reconfCmd);
reconfArgs[0] = "-i"; //$NON-NLS-1$
rc = runScript(localCommandLauncher, reconfCmdPath,
rc = runScript(runInCfgLauncher ? configureLauncher : localCommandLauncher, reconfCmdPath,
getSourcePath(),
reconfArgs,
AutotoolsPlugin.getFormattedString("MakeGenerator.autoreconf", new String[]{buildDir}), //$NON-NLS-1$

View file

@ -20,6 +20,7 @@ import java.util.StringTokenizer;
import org.eclipse.cdt.autotools.ui.AutotoolsUIPlugin;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CommandLauncher;
import org.eclipse.cdt.core.CommandLauncherManager;
import org.eclipse.cdt.core.ConsoleOutputStream;
import org.eclipse.cdt.core.ICommandLauncher;
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
@ -28,6 +29,7 @@ import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.resources.IConsole;
import org.eclipse.cdt.internal.autotools.core.AutotoolsNewMakeGenerator;
import org.eclipse.cdt.managedbuilder.buildproperties.IOptionalBuildProperties;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.IManagedBuildInfo;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
@ -300,9 +302,23 @@ public abstract class AbstractAutotoolsHandler extends AbstractHandler {
ArrayList<String> additionalEnvs = new ArrayList<>();
String strippedCommand = AutotoolsNewMakeGenerator.stripEnvVars(command, additionalEnvs);
// Get a launcher for the config command...default non-remote to use local
// commands
RemoteCommandLauncher launcher = new RemoteCommandLauncher(new CommandLauncher());
// Get a launcher for the config command...default for non-remote is a local
// launcher, but user can override to perform all Autotool commands in a
// Container when build in Container is enabled so check optional build
// properties
IOptionalBuildProperties props = cfg.getOptionalBuildProperties();
boolean runInContainer = false;
if (props != null) {
String runInContainerProperty = props
.getProperty(AutotoolsNewMakeGenerator.RUN_IN_CONFIGURE_LAUNCHER);
if (runInContainerProperty != null) {
runInContainer = Boolean.parseBoolean(runInContainerProperty);
}
}
ICommandLauncher fallbackLauncher = runInContainer
? CommandLauncherManager.getInstance().getCommandLauncher(project)
: new CommandLauncher();
RemoteCommandLauncher launcher = new RemoteCommandLauncher(fallbackLauncher);
launcher.setProject(project);
// Set the environment
IEnvironmentVariable variables[] = ManagedBuildManager.getEnvironmentVariableProvider()

View file

@ -28,6 +28,7 @@ import org.eclipse.cdt.core.settings.model.ICMultiConfigDescription;
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
import org.eclipse.cdt.core.settings.model.ICTargetPlatformSetting;
import org.eclipse.cdt.docker.launcher.ContainerCommandLauncher;
import org.eclipse.cdt.docker.launcher.DockerLaunchUIPlugin;
import org.eclipse.cdt.internal.docker.launcher.ContainerPropertyVolumesModel.MountType;
import org.eclipse.cdt.managedbuilder.buildproperties.IOptionalBuildProperties;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
@ -42,6 +43,9 @@ import org.eclipse.core.databinding.beans.IBeanValueProperty;
import org.eclipse.core.databinding.observable.list.IObservableList;
import org.eclipse.core.databinding.observable.map.IObservableMap;
import org.eclipse.core.databinding.property.Properties;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectNature;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.databinding.viewers.ObservableListContentProvider;
import org.eclipse.jface.databinding.viewers.ObservableMapLabelProvider;
import org.eclipse.jface.databinding.viewers.ViewerSupport;
@ -88,19 +92,23 @@ public class ContainerPropertyTab extends AbstractCBuildPropertyTab
private final static String GNU_ELF_PARSER_ID = "org.eclipse.cdt.core.GNU_ELF"; //$NON-NLS-1$
private final static String ELF_PARSER_ID = "org.eclipse.cdt.core.ELF"; //$NON-NLS-1$
private static final String RUN_IN_CONFIGURE_LAUNCHER = "org.eclipse.cdt.autotools.core.property.launchAutotoolsInContainer"; //$NON-NLS-1$
private Combo imageCombo;
private Combo connectionSelector;
private Button enableButton;
private Button launchAutotoolsButton;
private Button addButton;
private IDockerConnection connection;
private IDockerConnection[] connections;
private IDockerImageListener containerTab;
private boolean isAutotoolsProject;
private String connectionName;
private String connectionUri = ""; //$NON-NLS-1$
private boolean initialEnabled;
private boolean initialAutotoolsLaunchEnabled;
private String initialConnection;
private String initialImageId;
private String initialVolumes;
@ -235,6 +243,43 @@ public class ContainerPropertyTab extends AbstractCBuildPropertyTab
});
createVolumeSettingsContainer(usercomp);
try {
IProject project = iCfgd.getProjectDescription().getProject();
IProjectNature nature = project.getNature(
"org.eclipse.cdt.autotools.core.autotoolsNatureV2"); //$NON-NLS-1$
isAutotoolsProject = (nature != null);
if (isAutotoolsProject) {
launchAutotoolsButton = new Button(usercomp, SWT.CHECK);
launchAutotoolsButton.setText(
Messages.ContainerPropertyTab_Run_Autotools_In_Container_Msg);
launchAutotoolsButton.setToolTipText(
Messages.ContainerPropertyTab_Run_Autotools_In_Container_Tooltip);
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 5;
launchAutotoolsButton.setLayoutData(gd);
initializeLaunchAutotoolsButton();
launchAutotoolsButton
.addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
setLaunchAutotoolsEnablement(
launchAutotoolsButton.getSelection());
}
@Override
public void widgetDefaultSelected(
SelectionEvent e) {
// ignore
}
});
}
} catch (CoreException e) {
DockerLaunchUIPlugin.log(e);
}
initializeEnablementButton();
enableButton.addSelectionListener(new SelectionListener() {
@ -251,7 +296,6 @@ public class ContainerPropertyTab extends AbstractCBuildPropertyTab
});
createVolumeSettingsContainer(usercomp);
}
private void createVolumeSettingsContainer(final Composite container) {
@ -597,6 +641,23 @@ public class ContainerPropertyTab extends AbstractCBuildPropertyTab
}
}
private void setLaunchAutotoolsEnablement(boolean enabled) {
if (iCfg instanceof IMultiConfiguration) {
IConfiguration[] cfs = (IConfiguration[]) ((IMultiConfiguration) iCfg)
.getItems();
for (int i = 0; i < cfs.length; i++) {
IConfiguration cfg = cfs[i];
IOptionalBuildProperties p = cfg.getOptionalBuildProperties();
p.setProperty(RUN_IN_CONFIGURE_LAUNCHER,
Boolean.toString(launchAutotoolsButton.getSelection()));
}
} else {
IOptionalBuildProperties p = iCfg.getOptionalBuildProperties();
p.setProperty(RUN_IN_CONFIGURE_LAUNCHER,
Boolean.toString(launchAutotoolsButton.getSelection()));
}
}
private void setImageId(String imageId) {
if (iCfg instanceof IMultiConfiguration) {
IConfiguration[] cfs = (IConfiguration[]) ((IMultiConfiguration) iCfg)
@ -630,6 +691,9 @@ public class ContainerPropertyTab extends AbstractCBuildPropertyTab
private void setControlsEnabled(boolean enabled) {
imageCombo.setEnabled(enabled);
connectionSelector.setEnabled(enabled);
if (isAutotoolsProject) {
launchAutotoolsButton.setEnabled(enabled);
}
setVolumeControlsEnabled(new Button[] { addButton }, enabled);
}
@ -646,6 +710,16 @@ public class ContainerPropertyTab extends AbstractCBuildPropertyTab
setControlsEnabled(initialEnabled);
}
private void initializeLaunchAutotoolsButton() {
initialEnabled = false;
IOptionalBuildProperties properties = iCfg.getOptionalBuildProperties();
String savedEnabled = properties.getProperty(RUN_IN_CONFIGURE_LAUNCHER);
if (savedEnabled != null) {
initialAutotoolsLaunchEnabled = Boolean.parseBoolean(savedEnabled);
}
launchAutotoolsButton.setSelection(initialAutotoolsLaunchEnabled);
}
private void initializeConnectionSelector() {
int defaultIndex = -1;
initialConnection = null;
@ -871,6 +945,8 @@ public class ContainerPropertyTab extends AbstractCBuildPropertyTab
.getProperty(ContainerCommandLauncher.VOLUMES_ID);
initialSelectedVolumes = properties
.getProperty(ContainerCommandLauncher.SELECTED_VOLUMES_ID);
initialAutotoolsLaunchEnabled = Boolean.parseBoolean(
properties.getProperty(RUN_IN_CONFIGURE_LAUNCHER));
List<ILanguageSettingsProvider> providers = ((ILanguageSettingsProvidersKeeper) cfgd)
.getLanguageSettingProviders();
for (ILanguageSettingsProvider provider : providers) {

View file

@ -99,6 +99,8 @@ public class Messages extends NLS {
public static String ContainerPropertyTab_Title;
public static String ContainerPropertyTab_Enable_Msg;
public static String ContainerPropertyTab_Run_Autotools_In_Container_Msg;
public static String ContainerPropertyTab_Run_Autotools_In_Container_Tooltip;
public static String ContainerCommandLauncher_image_msg;
public static String CommandLauncher_CommandCancelled;

View file

@ -42,6 +42,8 @@ ContainerTab_Warning_Image_Not_Found=Docker Image: {0} is not a valid pulled ima
ContainerPropertyTab_Title=Container Settings
ContainerPropertyTab_Enable_Msg=Build inside Docker Image
ContainerPropertyTab_Run_Autotools_In_Container_Msg=Run all Autotools in Container
ContainerPropertyTab_Run_Autotools_In_Container_Tooltip=Run Autotool commands in the Docker Container. This may cause inconsistencies between configurations sharing generated files.
HeaderPreferencePage_Connection_Label=Connection
HeaderPreferencePage_Image_Label=Image