diff --git a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java index 2833538ef0f..b94eab734ec 100644 --- a/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java +++ b/build/org.eclipse.cdt.autotools.core/src/org/eclipse/cdt/internal/autotools/core/AutotoolsNewMakeGenerator.java @@ -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(); diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/GCCBuiltinSpecsDetectorCygwin.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/GCCBuiltinSpecsDetectorCygwin.java index d2a4b86ed7b..1c63fd73c84 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/GCCBuiltinSpecsDetectorCygwin.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/language/settings/providers/GCCBuiltinSpecsDetectorCygwin.java @@ -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); } diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerCommandLauncher.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerCommandLauncher.java index 999f540f218..79db65bd631 100644 --- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerCommandLauncher.java +++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerCommandLauncher.java @@ -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 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 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 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 diff --git a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerLaunchConfigurationDelegate.java b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerLaunchConfigurationDelegate.java index d0f14f22c8b..d45cbbd776a 100644 --- a/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerLaunchConfigurationDelegate.java +++ b/launch/org.eclipse.cdt.docker.launcher/src/org/eclipse/cdt/internal/docker/launcher/ContainerLaunchConfigurationDelegate.java @@ -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 envMap = configuration.getAttribute( ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) null); @@ -160,6 +174,18 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate List additionalDirs = configuration.getAttribute( ILaunchConstants.ATTR_ADDITIONAL_DIRS, (List) null); + if (additionalDirs != null) { + List 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 envMap = configuration.getAttribute( ILaunchManager.ATTR_ENVIRONMENT_VARIABLES, (Map) null); @@ -223,6 +264,19 @@ public class ContainerLaunchConfigurationDelegate extends GdbLaunchDelegate List additionalDirs = configuration.getAttribute( ILaunchConstants.ATTR_ADDITIONAL_DIRS, (List) null); + if (additionalDirs != null) { + List 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(