1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-08 17:45:24 +02:00

Add Windows support for CDT Build in Container

- fix AutotoolsNewMakeGenerator.getWinOSType to not specify "." for
  working dir
- fix GCCBuiltinSpecsDetectorCygwin to not map paths to Cygwin if
  the current configuration is enabled for container build
- add logic to ContainerCommandLauncher to look for Windows
  file formats and change them to unix format and map
  any "." working dir to be /tmp
- fix ContainerLauncherConfigurationDelegate similarly
This commit is contained in:
Jeff 2017-06-22 14:47:44 -07:00 committed by Jeff Johnston
parent 35b02e5aed
commit 0c1c44a47d
4 changed files with 144 additions and 22 deletions

View file

@ -1042,7 +1042,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
new Path(SHELL_COMMAND), //$NON-NLS-1$ new Path(SHELL_COMMAND), //$NON-NLS-1$
new String[] { "-c", "echo $OSTYPE" }, //$NON-NLS-1$ //$NON-NLS-2$ new String[] { "-c", "echo $OSTYPE" }, //$NON-NLS-1$ //$NON-NLS-2$
env, env,
new Path("."), //$NON-NLS-1$ buildLocation,
SubMonitor.convert(monitor)); SubMonitor.convert(monitor));
if (launcher.waitAndRead(out, out) == ICommandLauncher.OK) if (launcher.waitAndRead(out, out) == ICommandLauncher.OK)
winOSType = out.toString().trim(); winOSType = out.toString().trim();

View file

@ -12,11 +12,17 @@
package org.eclipse.cdt.managedbuilder.internal.language.settings.providers; package org.eclipse.cdt.managedbuilder.internal.language.settings.providers;
import java.net.URI; import java.net.URI;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.cdt.core.EFSExtensionProvider; import org.eclipse.cdt.core.EFSExtensionProvider;
import org.eclipse.cdt.internal.core.Cygwin; import org.eclipse.cdt.internal.core.Cygwin;
import org.eclipse.cdt.managedbuilder.buildproperties.IOptionalBuildProperties;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin; import org.eclipse.cdt.managedbuilder.core.ManagedBuilderCorePlugin;
import org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector; import org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector;
import org.eclipse.core.runtime.Platform;
/** /**
* Class to detect built-in compiler settings for Cygwin toolchain. * Class to detect built-in compiler settings for Cygwin toolchain.
@ -26,6 +32,7 @@ public class GCCBuiltinSpecsDetectorCygwin extends GCCBuiltinSpecsDetector {
// ID must match the tool-chain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point // ID must match the tool-chain definition in org.eclipse.cdt.managedbuilder.core.buildDefinitions extension point
private static final String GCC_TOOLCHAIN_ID_CYGWIN = "cdt.managedbuild.toolchain.gnu.cygwin.base"; //$NON-NLS-1$ private static final String GCC_TOOLCHAIN_ID_CYGWIN = "cdt.managedbuild.toolchain.gnu.cygwin.base"; //$NON-NLS-1$
private static final String ENV_PATH = "PATH"; //$NON-NLS-1$ private static final String ENV_PATH = "PATH"; //$NON-NLS-1$
public static final String CONTAINER_ENABLEMENT_PROPERTY = "org.eclipse.cdt.docker.launcher.containerbuild.property.enablement"; //$NON-NLS-1$
/** /**
* EFSExtensionProvider for Cygwin translations * EFSExtensionProvider for Cygwin translations
@ -46,7 +53,14 @@ public class GCCBuiltinSpecsDetectorCygwin extends GCCBuiltinSpecsDetector {
String windowsPath = null; String windowsPath = null;
try { try {
String cygwinPath = getPathFromURI(locationURI); String cygwinPath = getPathFromURI(locationURI);
IConfiguration cfg = ManagedBuildManager.getConfigurationForDescription(currentCfgDescription);
if (cfg != null) {
IOptionalBuildProperties bp = cfg.getOptionalBuildProperties();
String ep = bp.getProperty(CONTAINER_ENABLEMENT_PROPERTY);
if (ep == null || !Boolean.parseBoolean(ep)) {
windowsPath = Cygwin.cygwinToWindowsPath(cygwinPath, envPathValue); windowsPath = Cygwin.cygwinToWindowsPath(cygwinPath, envPathValue);
}
}
} catch (Exception e) { } catch (Exception e) {
ManagedBuilderCorePlugin.log(e); ManagedBuilderCorePlugin.log(e);
} }

View file

@ -23,6 +23,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.core.variables.VariablesPlugin; import org.eclipse.core.variables.VariablesPlugin;
import org.eclipse.linuxtools.docker.ui.launch.ContainerLauncher; import org.eclipse.linuxtools.docker.ui.launch.ContainerLauncher;
@ -131,32 +132,61 @@ public class ContainerCommandLauncher
List<String> additionalDirs = new ArrayList<>(); List<String> additionalDirs = new ArrayList<>();
// //
additionalDirs.add(fProject.getLocation().toPortableString()); IPath projectLocation = fProject.getLocation();
String projectPath = projectLocation.toPortableString();
if (projectLocation.getDevice() != null) {
projectPath = "/" + projectPath.replace(':', '/'); //$NON-NLS-1$
}
additionalDirs.add(projectPath);
ArrayList<String> commandSegments = new ArrayList<>(); ArrayList<String> commandSegments = new ArrayList<>();
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
b.append(commandPath.toString().trim()); String commandString = commandPath.toPortableString();
commandSegments.add(commandPath.toString().trim()); if (commandPath.getDevice() != null) {
commandString = "/" + commandString.replace(':', '/'); //$NON-NLS-1$
}
b.append(commandString);
commandSegments.add(commandString);
for (String arg : args) { for (String arg : args) {
b.append(" "); //$NON-NLS-1$ b.append(" "); //$NON-NLS-1$
String realArg = VariablesPlugin.getDefault() String realArg = VariablesPlugin.getDefault()
.getStringVariableManager().performStringSubstitution(arg); .getStringVariableManager().performStringSubstitution(arg);
b.append(realArg); if (Platform.getOS().equals(Platform.OS_WIN32)) {
if (realArg.startsWith("/")) { //$NON-NLS-1$
// check if file exists and if so, add an additional directory // check if file exists and if so, add an additional directory
IPath p = new Path(realArg); IPath p = new Path(realArg);
if (p.isValidPath(realArg)) { if (p.isValidPath(realArg) && p.getDevice() != null) {
p = p.makeAbsolute();
File f = p.toFile(); File f = p.toFile();
if (f.exists()) { String modifiedArg = realArg;
// if the directory of the arg as a file exists, we mount it
// and modify the argument to be unix-style
if (f.isFile()) { if (f.isFile()) {
f = f.getParentFile();
modifiedArg = "/" //$NON-NLS-1$
+ p.toPortableString().replace(':', '/');
p = p.removeLastSegments(1); p = p.removeLastSegments(1);
} }
additionalDirs.add(p.toPortableString()); if (f != null && f.exists()) {
additionalDirs.add(
"/" + p.toPortableString().replace(':', '/')); //$NON-NLS-1$
realArg = modifiedArg;
}
}
} else if (realArg.startsWith("/")) { //$NON-NLS-1$
// check if file directory exists and if so, add an additional
// directory
IPath p = new Path(realArg);
if (p.isValidPath(realArg)) {
File f = p.toFile();
if (f.isFile()) {
f = f.getParentFile();
}
if (f != null && f.exists()) {
additionalDirs.add(f.getAbsolutePath());
} }
} }
} }
b.append(realArg);
commandSegments.add(realArg); commandSegments.add(realArg);
} }
@ -165,17 +195,30 @@ public class ContainerCommandLauncher
String commandDir = commandPath.removeLastSegments(1).toString(); String commandDir = commandPath.removeLastSegments(1).toString();
if (commandDir.isEmpty()) { if (commandDir.isEmpty()) {
commandDir = null; commandDir = null;
} else if (commandPath.getDevice() != null) {
commandDir = "/" + commandDir.replace(':', '/'); //$NON-NLS-1$
} }
IProject[] referencedProjects = fProject.getReferencedProjects(); IProject[] referencedProjects = fProject.getReferencedProjects();
for (IProject referencedProject : referencedProjects) { for (IProject referencedProject : referencedProjects) {
String referencedProjectPath = referencedProject.getLocation()
.toPortableString();
if (referencedProject.getLocation().getDevice() != null) {
referencedProjectPath = "/" //$NON-NLS-1$
+ referencedProjectPath.replace(':', '/');
}
additionalDirs additionalDirs
.add(referencedProject.getLocation().toPortableString()); .add(referencedProjectPath);
} }
String command = b.toString(); String command = b.toString();
String workingDir = workingDirectory.toPortableString(); String workingDir = workingDirectory.makeAbsolute().toPortableString();
if (workingDirectory.toPortableString().equals(".")) { //$NON-NLS-1$
workingDir = "/tmp"; //$NON-NLS-1$
} else if (workingDirectory.getDevice() != null) {
workingDir = "/" + workingDir.replace(':', '/'); //$NON-NLS-1$
}
parseEnvironment(env); parseEnvironment(env);
Map<String, String> origEnv = null; Map<String, String> origEnv = null;
@ -205,8 +248,19 @@ public class ContainerCommandLauncher
if (selectedVolumeString != null && !selectedVolumeString.isEmpty()) { if (selectedVolumeString != null && !selectedVolumeString.isEmpty()) {
String[] selectedVolumes = selectedVolumeString String[] selectedVolumes = selectedVolumeString
.split(VOLUME_SEPARATOR_REGEX); .split(VOLUME_SEPARATOR_REGEX);
if (Platform.getOS().equals(Platform.OS_WIN32)) {
for (String selectedVolume : selectedVolumes) {
IPath path = new Path(selectedVolume);
String selectedPath = path.toPortableString();
if (path.getDevice() != null) {
selectedPath = "/" + selectedPath.replace(':', '/'); //$NON-NLS-1$
}
additionalDirs.add(selectedPath);
}
} else {
additionalDirs.addAll(Arrays.asList(selectedVolumes)); additionalDirs.addAll(Arrays.asList(selectedVolumes));
} }
}
String connectionName = props String connectionName = props
.getProperty(ContainerCommandLauncher.CONNECTION_ID); .getProperty(ContainerCommandLauncher.CONNECTION_ID);

View file

@ -10,6 +10,7 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.docker.launcher; package org.eclipse.cdt.internal.docker.launcher;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -129,10 +130,16 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate
labels.put("org.eclipse.cdt.project-name", projectName); //$NON-NLS-1$ labels.put("org.eclipse.cdt.project-name", projectName); //$NON-NLS-1$
if (mode.equals(ILaunchManager.RUN_MODE)) { if (mode.equals(ILaunchManager.RUN_MODE)) {
String commandDir = commandPath.removeLastSegments(1) String commandDir = commandPath.removeLastSegments(1)
.toString(); .toPortableString();
String commandString = commandPath.toPortableString();
if (commandPath.getDevice() != null) {
commandDir = "/" + commandDir.replace(':', '/'); //$NON-NLS-1$
commandString = "/" + commandString.replace(':', '/'); //$NON-NLS-1$
}
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
b.append(commandPath.toString().trim()); b.append(commandString);
String arguments = getProgramArguments(configuration); String arguments = getProgramArguments(configuration);
if (arguments.trim().length() > 0) { if (arguments.trim().length() > 0) {
@ -146,6 +153,13 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate
.getAttribute( .getAttribute(
ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
(String) null); (String) null);
if (workingDir != null) {
IPath workingPath = new Path(workingDir);
if (workingPath.getDevice() != null) {
workingDir = "/" + workingPath.toPortableString() //$NON-NLS-1$
.replace(':', '/');
}
}
Map<String, String> envMap = configuration.getAttribute( Map<String, String> envMap = configuration.getAttribute(
ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, ILaunchManager.ATTR_ENVIRONMENT_VARIABLES,
(Map<String, String>) null); (Map<String, String>) null);
@ -160,6 +174,18 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate
List<String> additionalDirs = configuration.getAttribute( List<String> additionalDirs = configuration.getAttribute(
ILaunchConstants.ATTR_ADDITIONAL_DIRS, ILaunchConstants.ATTR_ADDITIONAL_DIRS,
(List<String>) null); (List<String>) null);
if (additionalDirs != null) {
List<String> dirs = new ArrayList<>();
for (String additionalDir : additionalDirs) {
IPath path = new Path(additionalDir);
String dir = path.toPortableString();
if (path.getDevice() != null) {
dir = "/" + dir.replace(':', '/');
}
dirs.add(dir);
}
additionalDirs = dirs;
}
String image = configuration.getAttribute( String image = configuration.getAttribute(
ILaunchConstants.ATTR_IMAGE, (String) null); ILaunchConstants.ATTR_IMAGE, (String) null);
String connectionUri = configuration.getAttribute( String connectionUri = configuration.getAttribute(
@ -188,11 +214,18 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate
String gdbserverCommand = configuration.getAttribute( String gdbserverCommand = configuration.getAttribute(
ILaunchConstants.ATTR_GDBSERVER_COMMAND, ILaunchConstants.ATTR_GDBSERVER_COMMAND,
ILaunchConstants.ATTR_GDBSERVER_COMMAND_DEFAULT); ILaunchConstants.ATTR_GDBSERVER_COMMAND_DEFAULT);
String commandArguments = ":" + gdbserverPortNumber + " " //$NON-NLS-1$ //$NON-NLS-2$
+ spaceEscapify(commandPath.toString());
String commandString = commandPath.toPortableString();
String commandDir = commandPath.removeLastSegments(1) String commandDir = commandPath.removeLastSegments(1)
.toString(); .toPortableString();
if (commandPath.getDevice() != null) {
commandDir = "/" + commandDir.replace(':', '/'); //$NON-NLS-1$
commandString = "/" + commandString.replace(':', '/'); //$NON-NLS-1$
}
String commandArguments = ":" + gdbserverPortNumber + " " //$NON-NLS-1$ //$NON-NLS-2$
+ spaceEscapify(commandString);
StringBuilder b = new StringBuilder(); StringBuilder b = new StringBuilder();
@ -209,6 +242,14 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate
.getAttribute( .getAttribute(
ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY, ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
(String) null); (String) null);
if (workingDir != null) {
IPath workingPath = new Path(workingDir);
if (workingPath.getDevice() != null) {
workingDir = "/" + workingPath.toPortableString() //$NON-NLS-1$
.replace(':', '/');
}
}
Map<String, String> envMap = configuration.getAttribute( Map<String, String> envMap = configuration.getAttribute(
ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, ILaunchManager.ATTR_ENVIRONMENT_VARIABLES,
(Map<String, String>) null); (Map<String, String>) null);
@ -223,6 +264,19 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate
List<String> additionalDirs = configuration.getAttribute( List<String> additionalDirs = configuration.getAttribute(
ILaunchConstants.ATTR_ADDITIONAL_DIRS, ILaunchConstants.ATTR_ADDITIONAL_DIRS,
(List<String>) null); (List<String>) null);
if (additionalDirs != null) {
List<String> dirs = new ArrayList<>();
for (String additionalDir : additionalDirs) {
IPath path = new Path(additionalDir);
String dir = path.toPortableString();
if (path.getDevice() != null) {
dir = "/" + dir.replace(':', '/');
}
dirs.add(dir);
}
additionalDirs = dirs;
}
String image = configuration.getAttribute( String image = configuration.getAttribute(
ILaunchConstants.ATTR_IMAGE, (String) null); ILaunchConstants.ATTR_IMAGE, (String) null);
String connectionUri = configuration.getAttribute( String connectionUri = configuration.getAttribute(