mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-05 16:56:04 +02:00
Add MSYS2 support for managed build. A few Qt cleanups on Windows.
Change-Id: I07ed0cb4a83996de194559570fedf9fb1b21b42d
This commit is contained in:
parent
e091657eaf
commit
0d7ee343e0
9 changed files with 104 additions and 55 deletions
|
@ -41,8 +41,9 @@ import org.eclipse.core.runtime.Platform;
|
|||
import org.eclipse.core.runtime.PlatformObject;
|
||||
|
||||
/**
|
||||
* The GCC toolchain. This is the base class for all GCC toolchains. It represents GCC as found on
|
||||
* the user's PATH. It can be overriden to change environment variable settings.
|
||||
* The GCC toolchain. This is the base class for all GCC toolchains. It
|
||||
* represents GCC as found on the user's PATH. It can be overriden to change
|
||||
* environment variable settings.
|
||||
*/
|
||||
public class GCCToolChain extends PlatformObject implements IToolChain {
|
||||
|
||||
|
@ -50,7 +51,7 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
|
|||
private final String id;
|
||||
private final String version;
|
||||
private final String name;
|
||||
private final Path path;
|
||||
private final Path[] path;
|
||||
private final String prefix;
|
||||
private final IEnvironmentVariable pathVar;
|
||||
private final IEnvironmentVariable[] envVars;
|
||||
|
@ -61,11 +62,11 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
|
|||
this(provider, id, version, null, null);
|
||||
}
|
||||
|
||||
public GCCToolChain(IToolChainProvider provider, String id, String version, Path path) {
|
||||
public GCCToolChain(IToolChainProvider provider, String id, String version, Path[] path) {
|
||||
this(provider, id, version, path, null);
|
||||
}
|
||||
|
||||
public GCCToolChain(IToolChainProvider provider, String id, String version, Path path, String prefix) {
|
||||
public GCCToolChain(IToolChainProvider provider, String id, String version, Path[] path, String prefix) {
|
||||
this.provider = provider;
|
||||
this.id = id;
|
||||
this.version = version;
|
||||
|
@ -74,7 +75,14 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
|
|||
this.prefix = prefix;
|
||||
|
||||
if (path != null) {
|
||||
pathVar = new EnvironmentVariable("PATH", path.toString(), IEnvironmentVariable.ENVVAR_PREPEND, //$NON-NLS-1$
|
||||
StringBuilder pathString = new StringBuilder();
|
||||
for (int i = 0; i < path.length; ++i) {
|
||||
pathString.append(path[i].toString());
|
||||
if (i < path.length - 1) {
|
||||
pathString.append(File.pathSeparator);
|
||||
}
|
||||
}
|
||||
pathVar = new EnvironmentVariable("PATH", pathString.toString(), IEnvironmentVariable.ENVVAR_PREPEND, //$NON-NLS-1$
|
||||
File.pathSeparator);
|
||||
envVars = new IEnvironmentVariable[] { pathVar };
|
||||
} else {
|
||||
|
@ -92,12 +100,12 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
|
|||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -114,7 +122,7 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getBinaryParserId() {
|
||||
// Assume local builds
|
||||
|
@ -282,7 +290,12 @@ public class GCCToolChain extends PlatformObject implements IToolChain {
|
|||
}
|
||||
|
||||
if (path != null) {
|
||||
return path.resolve(command);
|
||||
for (Path p : path) {
|
||||
Path c = p.resolve(command);
|
||||
if (Files.isExecutable(c)) {
|
||||
return c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Look for it in the path environment var
|
||||
|
|
|
@ -11,6 +11,7 @@ import java.io.BufferedReader;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -73,7 +74,8 @@ public class GCCPathToolChainProvider implements IToolChainProvider {
|
|||
String name = target + " - " + version; //$NON-NLS-1$
|
||||
if (!names.contains(name)) {
|
||||
names.add(name);
|
||||
manager.addToolChain(new GCCToolChain(this, target, version, dir.toPath(), prefix));
|
||||
manager.addToolChain(new GCCToolChain(this, target, version,
|
||||
new Path[] { dir.toPath() }, prefix));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
|
|
@ -36,9 +36,11 @@ public class Msys2ToolChainProvider implements IToolChainProvider {
|
|||
String displayName = registry.getCurrentUserValue(compKey, "DisplayName"); //$NON-NLS-1$
|
||||
if ("MSYS2 64bit".equals(displayName)) { //$NON-NLS-1$
|
||||
String installLocation = registry.getCurrentUserValue(compKey, "InstallLocation"); //$NON-NLS-1$
|
||||
Path gccPath = Paths.get(installLocation + "\\mingw64\\bin\\gcc.exe"); //$NON-NLS-1$
|
||||
Path msysPath = Paths.get(installLocation);
|
||||
Path gccPath = msysPath.resolve("mingw64\\bin\\gcc.exe"); //$NON-NLS-1$
|
||||
if (Files.exists(gccPath)) {
|
||||
manager.addToolChain(new GCCToolChain(this, "msys2.x86_64", "", gccPath.getParent())); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
manager.addToolChain(new GCCToolChain(this, "x86_64-w64-mingw32", "msys2.x86_64", new Path[] { //$NON-NLS-1$ //$NON-NLS-2$
|
||||
gccPath.getParent(), msysPath.resolve("bin"), msysPath.resolve("usr\\bin") })); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,40 +33,6 @@ public class MingwEnvironmentVariableSupplier implements IConfigurationEnvironme
|
|||
private static final String BACKSLASH = java.io.File.separator;
|
||||
private static final String PATH_DELIMITER = EnvironmentVariableManager.getDefault().getDefaultDelimiter();
|
||||
|
||||
/**
|
||||
* @return location of $MINGW_HOME/bin folder on the file-system.
|
||||
* @deprecated. Deprecated as of CDT 8.2. Note that MinGW root path in general may depend on configuration.
|
||||
*
|
||||
* If you use this do not cache results to ensure user preferences are accounted for.
|
||||
* Please rely on internal caching.
|
||||
*/
|
||||
@Deprecated
|
||||
public static IPath getBinDir() {
|
||||
IPath binDir = null;
|
||||
String minGWHome = MinGW.getMinGWHome();
|
||||
if (minGWHome != null) {
|
||||
binDir = new Path(minGWHome).append("bin"); //$NON-NLS-1$
|
||||
}
|
||||
return binDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return location of $MINGW_HOME/msys/bin folder on the file-system.
|
||||
* @deprecated. Deprecated as of CDT 8.2. Note that MinGW root path in general may depend on configuration.
|
||||
*
|
||||
* If you use this do not cache results to ensure user preferences are accounted for.
|
||||
* Please rely on internal caching.
|
||||
*/
|
||||
@Deprecated
|
||||
public static IPath getMsysBinDir() {
|
||||
IPath msysBinDir = null;
|
||||
String msysHome = MinGW.getMSysHome();
|
||||
if (msysHome != null) {
|
||||
msysBinDir = new Path(msysHome).append("bin"); //$NON-NLS-1$
|
||||
}
|
||||
return msysBinDir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBuildEnvironmentVariable getVariable(String variableName, IConfiguration configuration, IEnvironmentVariableProvider provider) {
|
||||
if (variableName.equals(MinGW.ENV_MINGW_HOME)) {
|
||||
|
@ -98,7 +64,8 @@ public class MingwEnvironmentVariableSupplier implements IConfigurationEnvironme
|
|||
} else if (variableName.equals(ENV_PATH)) {
|
||||
@SuppressWarnings("nls")
|
||||
String path = "${" + MinGW.ENV_MINGW_HOME + "}" + BACKSLASH + "bin" + PATH_DELIMITER
|
||||
+ "${" + MinGW.ENV_MSYS_HOME + "}" + BACKSLASH + "bin";
|
||||
+ "${" + MinGW.ENV_MSYS_HOME + "}" + BACKSLASH + "bin" + PATH_DELIMITER
|
||||
+ "${" + MinGW.ENV_MSYS_HOME + "}" + BACKSLASH + "usr" + BACKSLASH + "bin";
|
||||
return new BuildEnvVar(ENV_PATH, path, IBuildEnvironmentVariable.ENVVAR_PREPEND);
|
||||
}
|
||||
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.WeakHashMap;
|
||||
|
@ -19,6 +21,7 @@ import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
|
|||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||
import org.eclipse.cdt.utils.PathUtil;
|
||||
import org.eclipse.cdt.utils.WindowsRegistry;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
@ -73,6 +76,21 @@ public class MinGW {
|
|||
rootValue = findMingwInPath(envPathValue);
|
||||
}
|
||||
|
||||
// Look in MSYS2
|
||||
if (rootValue == null) {
|
||||
WindowsRegistry registry = WindowsRegistry.getRegistry();
|
||||
String uninstallKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; //$NON-NLS-1$
|
||||
String subkey;
|
||||
for (int i = 0; (subkey = registry.getCurrentUserKeyName(uninstallKey, i)) != null; i++) {
|
||||
String compKey = uninstallKey + '\\' + subkey;
|
||||
String displayName = registry.getCurrentUserValue(compKey, "DisplayName"); //$NON-NLS-1$
|
||||
if ("MSYS2 64bit".equals(displayName)) { //$NON-NLS-1$
|
||||
rootValue = registry.getCurrentUserValue(compKey, "InstallLocation") + "\\mingw64"; //$NON-NLS-1$ //$NON-NLS-2$
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try the default MinGW install dir
|
||||
if (rootValue == null) {
|
||||
IPath mingwBinDir = new Path("C:\\MinGW"); //$NON-NLS-1$
|
||||
|
@ -137,6 +155,21 @@ public class MinGW {
|
|||
}
|
||||
}
|
||||
|
||||
// Try under MSYS2
|
||||
if (msysHome == null) {
|
||||
WindowsRegistry registry = WindowsRegistry.getRegistry();
|
||||
String uninstallKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; //$NON-NLS-1$
|
||||
String subkey;
|
||||
for (int i = 0; (subkey = registry.getCurrentUserKeyName(uninstallKey, i)) != null; i++) {
|
||||
String compKey = uninstallKey + '\\' + subkey;
|
||||
String displayName = registry.getCurrentUserValue(compKey, "DisplayName"); //$NON-NLS-1$
|
||||
if ("MSYS2 64bit".equals(displayName)) { //$NON-NLS-1$
|
||||
msysHome = registry.getCurrentUserValue(compKey, "InstallLocation"); //$NON-NLS-1$
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Try under default MinGW dir
|
||||
if (msysHome == null) {
|
||||
IPath minGwMsysBin = new Path("C:\\MinGW\\msys\\1.0\\bin"); //$NON-NLS-1$
|
||||
|
|
|
@ -16,6 +16,7 @@ package org.eclipse.cdt.managedbuilder.llvm.ui;
|
|||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.eclipse.cdt.internal.core.MinGW;
|
||||
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
|
||||
import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
|
||||
|
@ -301,6 +302,23 @@ public class LlvmEnvironmentVariableSupplier implements IConfigurationEnvironmen
|
|||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return location of $MINGW_HOME/bin folder on the file-system.
|
||||
* @deprecated. Deprecated as of CDT 8.2. Note that MinGW root path in general may depend on configuration.
|
||||
*
|
||||
* If you use this do not cache results to ensure user preferences are accounted for.
|
||||
* Please rely on internal caching.
|
||||
*/
|
||||
@Deprecated
|
||||
private static IPath getBinDir() {
|
||||
IPath binDir = null;
|
||||
String minGWHome = MinGW.getMinGWHome();
|
||||
if (minGWHome != null) {
|
||||
binDir = new Path(minGWHome).append("bin"); //$NON-NLS-1$
|
||||
}
|
||||
return binDir;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns stdc++ library path located in MinGW installation.
|
||||
*
|
||||
|
@ -308,7 +326,7 @@ public class LlvmEnvironmentVariableSupplier implements IConfigurationEnvironmen
|
|||
*/
|
||||
public static String getMinGWStdLib() {
|
||||
// get mingw bin path
|
||||
IPath mingwBinPath = MingwEnvironmentVariableSupplier.getBinDir();
|
||||
IPath mingwBinPath = getBinDir();
|
||||
if (mingwBinPath != null) {
|
||||
StringBuilder sB = new StringBuilder(mingwBinPath.toOSString());
|
||||
// drop bin
|
||||
|
|
|
@ -221,5 +221,16 @@
|
|||
value="x86_64">
|
||||
</property>
|
||||
</mapping>
|
||||
<mapping
|
||||
spec="win32-g++">
|
||||
<property
|
||||
key="os"
|
||||
value="win32">
|
||||
</property>
|
||||
<property
|
||||
key="arch"
|
||||
value="x86_64">
|
||||
</property>
|
||||
</mapping>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
|
|
@ -19,6 +19,8 @@ import org.eclipse.core.resources.IProject;
|
|||
import org.eclipse.core.resources.IProjectDescription;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.debug.core.ILaunchConfiguration;
|
||||
import org.eclipse.launchbar.core.target.ILaunchTarget;
|
||||
import org.eclipse.launchbar.core.target.launch.LaunchConfigurationTargetedDelegate;
|
||||
|
@ -30,16 +32,16 @@ public abstract class QtLaunchConfigurationDelegate extends LaunchConfigurationT
|
|||
IProgressMonitor monitor) throws CoreException {
|
||||
IQtBuildConfiguration qtBuildConfig = getQtBuildConfiguration(configuration, mode, target, monitor);
|
||||
|
||||
// Set it as active
|
||||
// If found, set as active, if not just return
|
||||
if (qtBuildConfig != null) {
|
||||
IProject project = qtBuildConfig.getBuildConfiguration().getProject();
|
||||
IProjectDescription desc = project.getDescription();
|
||||
desc.setActiveBuildConfig(qtBuildConfig.getBuildConfiguration().getName());
|
||||
project.setDescription(desc, monitor);
|
||||
return superBuildForLaunch(configuration, mode, monitor);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// And build
|
||||
return superBuildForLaunch(configuration, mode, monitor);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,7 +87,8 @@ public abstract class QtLaunchConfigurationDelegate extends LaunchConfigurationT
|
|||
}
|
||||
|
||||
// Couldn't find any
|
||||
return null;
|
||||
throw new CoreException(new Status(IStatus.ERROR, Activator.ID,
|
||||
String.format("No suitable SDK found for target %s.", target.getId())));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class QtMinGWToolChainProvider implements IToolChainProvider {
|
|||
try {
|
||||
Files.walk(Paths.get(installLocation).resolve("Tools"), 1) //$NON-NLS-1$
|
||||
.filter((path) -> Files.exists(path.resolve(gcc)))
|
||||
.map((path) -> new GCCToolChain(this, "qt.mingw", "", path.resolve("bin"))) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
.map((path) -> new GCCToolChain(this, "qt.mingw", "", new Path[] { path.resolve("bin") })) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
|
||||
.forEach(toolChain -> manager.addToolChain(toolChain));
|
||||
} catch (IOException e) {
|
||||
Activator.log(e);
|
||||
|
|
Loading…
Add table
Reference in a new issue