mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-08 09:35:23 +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:
parent
35b02e5aed
commit
0c1c44a47d
4 changed files with 144 additions and 22 deletions
|
@ -1042,7 +1042,7 @@ public class AutotoolsNewMakeGenerator extends MarkerGenerator {
|
|||
new Path(SHELL_COMMAND), //$NON-NLS-1$
|
||||
new String[] { "-c", "echo $OSTYPE" }, //$NON-NLS-1$ //$NON-NLS-2$
|
||||
env,
|
||||
new Path("."), //$NON-NLS-1$
|
||||
buildLocation,
|
||||
SubMonitor.convert(monitor));
|
||||
if (launcher.waitAndRead(out, out) == ICommandLauncher.OK)
|
||||
winOSType = out.toString().trim();
|
||||
|
|
|
@ -12,11 +12,17 @@
|
|||
package org.eclipse.cdt.managedbuilder.internal.language.settings.providers;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.eclipse.cdt.core.EFSExtensionProvider;
|
||||
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.language.settings.providers.GCCBuiltinSpecsDetector;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
||||
/**
|
||||
* 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
|
||||
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$
|
||||
public static final String CONTAINER_ENABLEMENT_PROPERTY = "org.eclipse.cdt.docker.launcher.containerbuild.property.enablement"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* EFSExtensionProvider for Cygwin translations
|
||||
|
@ -46,7 +53,14 @@ public class GCCBuiltinSpecsDetectorCygwin extends GCCBuiltinSpecsDetector {
|
|||
String windowsPath = null;
|
||||
try {
|
||||
String cygwinPath = getPathFromURI(locationURI);
|
||||
windowsPath = Cygwin.cygwinToWindowsPath(cygwinPath, envPathValue);
|
||||
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);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
ManagedBuilderCorePlugin.log(e);
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.core.variables.VariablesPlugin;
|
||||
import org.eclipse.linuxtools.docker.ui.launch.ContainerLauncher;
|
||||
|
@ -131,32 +132,61 @@ public class ContainerCommandLauncher
|
|||
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<>();
|
||||
|
||||
StringBuilder b = new StringBuilder();
|
||||
b.append(commandPath.toString().trim());
|
||||
commandSegments.add(commandPath.toString().trim());
|
||||
String commandString = commandPath.toPortableString();
|
||||
if (commandPath.getDevice() != null) {
|
||||
commandString = "/" + commandString.replace(':', '/'); //$NON-NLS-1$
|
||||
}
|
||||
b.append(commandString);
|
||||
commandSegments.add(commandString);
|
||||
for (String arg : args) {
|
||||
b.append(" "); //$NON-NLS-1$
|
||||
String realArg = VariablesPlugin.getDefault()
|
||||
.getStringVariableManager().performStringSubstitution(arg);
|
||||
b.append(realArg);
|
||||
if (realArg.startsWith("/")) { //$NON-NLS-1$
|
||||
if (Platform.getOS().equals(Platform.OS_WIN32)) {
|
||||
// check if file exists and if so, add an additional directory
|
||||
IPath p = new Path(realArg);
|
||||
if (p.isValidPath(realArg)) {
|
||||
p = p.makeAbsolute();
|
||||
if (p.isValidPath(realArg) && p.getDevice() != null) {
|
||||
File f = p.toFile();
|
||||
if (f.exists()) {
|
||||
if (f.isFile()) {
|
||||
p = p.removeLastSegments(1);
|
||||
}
|
||||
additionalDirs.add(p.toPortableString());
|
||||
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()) {
|
||||
f = f.getParentFile();
|
||||
modifiedArg = "/" //$NON-NLS-1$
|
||||
+ p.toPortableString().replace(':', '/');
|
||||
p = p.removeLastSegments(1);
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -165,17 +195,30 @@ public class ContainerCommandLauncher
|
|||
String commandDir = commandPath.removeLastSegments(1).toString();
|
||||
if (commandDir.isEmpty()) {
|
||||
commandDir = null;
|
||||
} else if (commandPath.getDevice() != null) {
|
||||
commandDir = "/" + commandDir.replace(':', '/'); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
IProject[] referencedProjects = fProject.getReferencedProjects();
|
||||
for (IProject referencedProject : referencedProjects) {
|
||||
String referencedProjectPath = referencedProject.getLocation()
|
||||
.toPortableString();
|
||||
if (referencedProject.getLocation().getDevice() != null) {
|
||||
referencedProjectPath = "/" //$NON-NLS-1$
|
||||
+ referencedProjectPath.replace(':', '/');
|
||||
}
|
||||
additionalDirs
|
||||
.add(referencedProject.getLocation().toPortableString());
|
||||
.add(referencedProjectPath);
|
||||
}
|
||||
|
||||
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);
|
||||
Map<String, String> origEnv = null;
|
||||
|
||||
|
@ -205,7 +248,18 @@ public class ContainerCommandLauncher
|
|||
if (selectedVolumeString != null && !selectedVolumeString.isEmpty()) {
|
||||
String[] selectedVolumes = selectedVolumeString
|
||||
.split(VOLUME_SEPARATOR_REGEX);
|
||||
additionalDirs.addAll(Arrays.asList(selectedVolumes));
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
String connectionName = props
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.docker.launcher;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -129,10 +130,16 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate
|
|||
labels.put("org.eclipse.cdt.project-name", projectName); //$NON-NLS-1$
|
||||
if (mode.equals(ILaunchManager.RUN_MODE)) {
|
||||
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();
|
||||
b.append(commandPath.toString().trim());
|
||||
b.append(commandString);
|
||||
|
||||
String arguments = getProgramArguments(configuration);
|
||||
if (arguments.trim().length() > 0) {
|
||||
|
@ -146,6 +153,13 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate
|
|||
.getAttribute(
|
||||
ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
|
||||
(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(
|
||||
ILaunchManager.ATTR_ENVIRONMENT_VARIABLES,
|
||||
(Map<String, String>) null);
|
||||
|
@ -160,6 +174,18 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate
|
|||
List<String> additionalDirs = configuration.getAttribute(
|
||||
ILaunchConstants.ATTR_ADDITIONAL_DIRS,
|
||||
(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(
|
||||
ILaunchConstants.ATTR_IMAGE, (String) null);
|
||||
String connectionUri = configuration.getAttribute(
|
||||
|
@ -188,11 +214,18 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate
|
|||
String gdbserverCommand = configuration.getAttribute(
|
||||
ILaunchConstants.ATTR_GDBSERVER_COMMAND,
|
||||
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)
|
||||
.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();
|
||||
|
||||
|
@ -209,6 +242,14 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate
|
|||
.getAttribute(
|
||||
ICDTLaunchConfigurationConstants.ATTR_WORKING_DIRECTORY,
|
||||
(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(
|
||||
ILaunchManager.ATTR_ENVIRONMENT_VARIABLES,
|
||||
(Map<String, String>) null);
|
||||
|
@ -223,6 +264,19 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate
|
|||
List<String> additionalDirs = configuration.getAttribute(
|
||||
ILaunchConstants.ATTR_ADDITIONAL_DIRS,
|
||||
(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(
|
||||
ILaunchConstants.ATTR_IMAGE, (String) null);
|
||||
String connectionUri = configuration.getAttribute(
|
||||
|
|
Loading…
Add table
Reference in a new issue