1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

bug 384520: New Project Wizard ignores $PATH from preferences, won't show toolchain

This commit is contained in:
Andrew Gvozdev 2012-07-08 23:22:36 -04:00
parent d1bb13b08c
commit ba52a9aadb
4 changed files with 88 additions and 54 deletions

View file

@ -19,7 +19,9 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.envvar.IEnvironmentVariable; import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.managedbuilder.core.IBuildPathResolver; import org.eclipse.cdt.managedbuilder.core.IBuildPathResolver;
import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
@ -29,7 +31,6 @@ import org.eclipse.cdt.utils.WindowsRegistry;
import org.eclipse.cdt.utils.spawner.ProcessFactory; import org.eclipse.cdt.utils.spawner.ProcessFactory;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
/** /**
* @noextend This class is not intended to be subclassed by clients. * @noextend This class is not intended to be subclassed by clients.
*/ */
@ -58,15 +59,13 @@ public class CygwinPathResolver implements IBuildPathResolver {
private static final String MINGW_SPECIAL = "mingw "; //$NON-NLS-1$ private static final String MINGW_SPECIAL = "mingw "; //$NON-NLS-1$
private static final String CYGWIN_SPECIAL = "cygwin "; //$NON-NLS-1$ private static final String CYGWIN_SPECIAL = "cygwin "; //$NON-NLS-1$
private static boolean checked = false; private static String envPathValueCached = null;
private static String binCygwin = null; private static String binCygwin = null;
private static String rootCygwin = null; private static String rootCygwin = null;
private static String etcCygwin = null; private static String etcCygwin = null;
@Override @Override
public String[] resolveBuildPaths(int pathType, String variableName, public String[] resolveBuildPaths(int pathType, String variableName, String variableValue, IConfiguration configuration) {
String variableValue, IConfiguration configuration) {
if(!isWindows()) { if(!isWindows()) {
return variableValue.split(DELIMITER_UNIX); return variableValue.split(DELIMITER_UNIX);
} else if(isMinGW(configuration)) { } else if(isMinGW(configuration)) {
@ -92,25 +91,34 @@ public class CygwinPathResolver implements IBuildPathResolver {
/** /**
* returns "/etc" path in Windows format * returns "/etc" path in Windows format
*
* If you use this do not cache results to ensure user preferences are accounted for.
* Please rely on internal caching.
*/ */
public static String getEtcPath() { public static String getEtcPath() {
if (!checked) findPaths(); findPaths();
return etcCygwin; return etcCygwin;
} }
/** /**
* returns "/usr/bin" path in Windows format * returns "/usr/bin" path in Windows format
*
* If you use this do not cache results to ensure user preferences are accounted for.
* Please rely on internal caching.
*/ */
public static String getBinPath() { public static String getBinPath() {
if (!checked) findPaths(); findPaths();
return binCygwin; return binCygwin;
} }
/** /**
* returns Cygwin root ("/") path in Windows format * returns Cygwin root ("/") path in Windows format
*
* If you use this do not cache results to ensure user preferences are accounted for.
* Please rely on internal caching.
*/ */
public static String getRootPath() { public static String getRootPath() {
if (!checked) findPaths(); findPaths();
return rootCygwin; return rootCygwin;
} }
@ -164,11 +172,11 @@ public class CygwinPathResolver implements IBuildPathResolver {
* *
* @return The absolute path to cygwin's root or null if not found * @return The absolute path to cygwin's root or null if not found
*/ */
private static String findRoot() { private static String findRoot(String paths) {
String rootValue = null; String rootValue = null;
// 1. Look in PATH values. Look for bin\cygwin1.dll // 1. Look in PATH values. Look for bin\cygwin1.dll
IPath location = PathUtil.findProgramLocation("cygwin1.dll"); //$NON-NLS-1$ IPath location = PathUtil.findProgramLocation("cygwin1.dll", paths); //$NON-NLS-1$
if (location!=null) { if (location!=null) {
rootValue = location.removeLastSegments(2).toOSString(); rootValue = location.removeLastSegments(2).toOSString();
} }
@ -202,16 +210,25 @@ public class CygwinPathResolver implements IBuildPathResolver {
} }
/** /**
* Finds Cygwin's paths and sets corresponding properties * Finds Cygwin's paths and sets corresponding properties.
*/ */
private static synchronized void findPaths() { private static synchronized void findPaths() {
if (checked) return; if (!isWindows()) {
return;
}
IEnvironmentVariable varPath = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable("PATH", null, true); //$NON-NLS-1$
String envPathValue = varPath != null ? varPath.getValue() : null;
if (CDataUtil.objectsEqual(envPathValue, envPathValueCached)) {
return;
}
etcCygwin = null; etcCygwin = null;
binCygwin = null; binCygwin = null;
rootCygwin = null; rootCygwin = null;
if (!isWindows()) return;
rootCygwin = findRoot(); rootCygwin = findRoot(envPathValue);
// 1. Try to find the paths by appending the patterns to the root dir // 1. Try to find the paths by appending the patterns to the root dir
etcCygwin = getValueFromRoot(ETCPATTERN); etcCygwin = getValueFromRoot(ETCPATTERN);
@ -225,7 +242,7 @@ public class CygwinPathResolver implements IBuildPathResolver {
if(binCygwin == null) if(binCygwin == null)
binCygwin = readValueFromRegistry(REGISTRY_KEY_MOUNTS + BINPATTERN, PATH_NAME); binCygwin = readValueFromRegistry(REGISTRY_KEY_MOUNTS + BINPATTERN, PATH_NAME);
checked = true; envPathValueCached = envPathValue;
} }
private static String[] exec(String cmd, IConfiguration cfg) { private static String[] exec(String cmd, IConfiguration cfg) {

View file

@ -16,6 +16,7 @@ import java.io.FileNotFoundException;
import java.io.FileReader; import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.managedbuilder.core.IManagedIsToolChainSupported; import org.eclipse.cdt.managedbuilder.core.IManagedIsToolChainSupported;
import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.cdt.managedbuilder.core.IToolChain;
import org.osgi.framework.Version; import org.osgi.framework.Version;
@ -33,24 +34,23 @@ import org.osgi.framework.Version;
* @noextend This class is not intended to be subclassed by clients. * @noextend This class is not intended to be subclassed by clients.
*/ */
public class IsGnuCygwinToolChainSupported implements IManagedIsToolChainSupported { public class IsGnuCygwinToolChainSupported implements IManagedIsToolChainSupported {
static final String[] CHECKED_NAMES = {"gcc", "binutils", "make"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ private static final String[] CHECKED_NAMES = {"gcc", "binutils", "make"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
static boolean suppChecked = false; private static String etcCygwinCached = null;
static boolean toolchainIsSupported = false; private static boolean toolchainIsSupported = false;
/** /**
* @since 8.0 * @since 8.0
*/ */
@Override @Override
public boolean isSupported(IToolChain toolChain, Version version, String instance) { public boolean isSupported(IToolChain toolChain, Version version, String instance) {
if (suppChecked) return toolchainIsSupported;
String etcCygwin = CygwinPathResolver.getEtcPath(); String etcCygwin = CygwinPathResolver.getEtcPath();
if (etcCygwin != null) { if (CDataUtil.objectsEqual(etcCygwin, etcCygwinCached)) {
toolchainIsSupported = arePackagesInstalled(etcCygwin); return toolchainIsSupported;
} }
suppChecked = true; toolchainIsSupported = etcCygwin != null && arePackagesInstalled(etcCygwin);
etcCygwinCached = etcCygwin;
return toolchainIsSupported; return toolchainIsSupported;
} }

View file

@ -11,6 +11,9 @@
package org.eclipse.cdt.managedbuilder.gnu.mingw; package org.eclipse.cdt.managedbuilder.gnu.mingw;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable; import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier; import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
@ -26,7 +29,8 @@ import org.eclipse.core.runtime.Platform;
* @noextend This class is not intended to be subclassed by clients. * @noextend This class is not intended to be subclassed by clients.
*/ */
public class MingwEnvironmentVariableSupplier implements IConfigurationEnvironmentVariableSupplier { public class MingwEnvironmentVariableSupplier implements IConfigurationEnvironmentVariableSupplier {
private static boolean checked = false; private static String envPathValueCached = null;
private static String envMingwHomeValueCached = null;
private static IPath binDir = null; private static IPath binDir = null;
private static class MingwBuildEnvironmentVariable implements IBuildEnvironmentVariable { private static class MingwBuildEnvironmentVariable implements IBuildEnvironmentVariable {
@ -63,41 +67,61 @@ public class MingwEnvironmentVariableSupplier implements IConfigurationEnvironme
private IBuildEnvironmentVariable path; private IBuildEnvironmentVariable path;
/**
* @return location of $MINGW_HOME/bin folder on the file-system.
*
* If you use this do not cache results to ensure user preferences are accounted for.
* Please rely on internal caching.
*/
public static IPath getBinDir() { public static IPath getBinDir() {
if (!checked) { IEnvironmentVariable varPath = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable("PATH", null, true); //$NON-NLS-1$
binDir = findBinDir(); String envPathValue = varPath != null ? varPath.getValue() : null;
checked = true; IEnvironmentVariable varMingwHome = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable("MINGW_HOME", null, true); //$NON-NLS-1$
} String envMingwHomeValue = varMingwHome != null ? varMingwHome.getValue() : null;
return binDir;
}
private static IPath findBinDir() { if (CDataUtil.objectsEqual(envPathValue, envPathValueCached) && CDataUtil.objectsEqual(envMingwHomeValue, envMingwHomeValueCached)) {
// Try in MinGW home return binDir;
String mingwHome = System.getenv("MINGW_HOME"); //$NON-NLS-1$ }
IPath mingwBinDir = new Path(mingwHome + "\\bin"); //$NON-NLS-1$
if (mingwBinDir.toFile().isDirectory()) envPathValueCached = envPathValue;
return mingwBinDir; envMingwHomeValueCached = envMingwHomeValue;
binDir = null;
// Check $MINGW_HOME
IPath mingwBinDir = new Path(envMingwHomeValue + "\\bin"); //$NON-NLS-1$
if (mingwBinDir.toFile().isDirectory()) {
binDir = mingwBinDir;
return binDir;
}
// Try the mingw directory in the platform install directory // Try the mingw directory in the platform install directory
// CDT distributions like Wascana may distribute MinGW like that // CDT distributions like Wascana may distribute MinGW like that
IPath installPath = new Path(Platform.getInstallLocation().getURL().getFile()); IPath installPath = new Path(Platform.getInstallLocation().getURL().getFile());
mingwBinDir = installPath.append("mingw\\bin"); //$NON-NLS-1$ mingwBinDir = installPath.append("mingw\\bin"); //$NON-NLS-1$
if (mingwBinDir.toFile().isDirectory()) if (mingwBinDir.toFile().isDirectory()) {
return mingwBinDir; binDir = mingwBinDir;
return binDir;
}
// Look in PATH values. Look for mingw32-gcc.exe // Look in PATH values. Look for mingw32-gcc.exe
// TODO: Since this dir is already in the PATH, why are we adding it here? // TODO: Since this dir is already in the PATH, why are we adding it here?
// This is really only to support isToolchainAvail. Must be a better way. // This is really only to support isToolchainAvail. Must be a better way.
IPath gccLoc = PathUtil.findProgramLocation("mingw32-gcc.exe"); //$NON-NLS-1$ // AG: Because otherwise the toolchain won't be shown in the list of "supported" toolchains in UI
if (gccLoc != null) // when MinGW installed in custom location even if it is in the PATH
return gccLoc.removeLastSegments(1); IPath gccLoc = PathUtil.findProgramLocation("mingw32-gcc.exe", envPathValue); //$NON-NLS-1$
if (gccLoc != null) {
binDir = gccLoc.removeLastSegments(1);
return binDir;
}
// Try the default MinGW install dir // Try the default MinGW install dir
mingwBinDir = new Path("C:\\MinGW\\bin"); //$NON-NLS-1$ mingwBinDir = new Path("C:\\MinGW\\bin"); //$NON-NLS-1$
if (mingwBinDir.toFile().isDirectory()) if (mingwBinDir.toFile().isDirectory()) {
return mingwBinDir; binDir = mingwBinDir;
return binDir;
}
return null; return binDir;
} }
public static IPath getMsysBinDir() { public static IPath getMsysBinDir() {
@ -107,7 +131,7 @@ public class MingwEnvironmentVariableSupplier implements IConfigurationEnvironme
if (msysBinPath.toFile().isDirectory()) if (msysBinPath.toFile().isDirectory())
return msysBinPath; return msysBinPath;
String mingwHome = System.getenv("MINGW_HOME"); //$NON-NLS-1$ String mingwHome = envMingwHomeValueCached;
if (mingwHome != null) { if (mingwHome != null) {
msysBinPath = new Path(mingwHome + "\\msys\\1.0\\bin"); //$NON-NLS-1$ msysBinPath = new Path(mingwHome + "\\msys\\1.0\\bin"); //$NON-NLS-1$
if (msysBinPath.toFile().isDirectory()) if (msysBinPath.toFile().isDirectory())

View file

@ -21,17 +21,10 @@ import org.osgi.framework.Version;
* @noextend This class is not intended to be subclassed by clients. * @noextend This class is not intended to be subclassed by clients.
*/ */
public class MingwIsToolChainSupported implements IManagedIsToolChainSupported { public class MingwIsToolChainSupported implements IManagedIsToolChainSupported {
private final boolean supported;
public MingwIsToolChainSupported() {
// Only supported if we can find the mingw bin dir to run the compiler
supported = MingwEnvironmentVariableSupplier.getBinDir() != null;
}
@Override @Override
public boolean isSupported(IToolChain toolChain, Version version, String instance) { public boolean isSupported(IToolChain toolChain, Version version, String instance) {
return supported; // Only supported if we can find the mingw bin dir to run the compiler
return MingwEnvironmentVariableSupplier.getBinDir() != null;
} }
} }