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 (issues with too aggressive caching)
This commit is contained in:
Andrew Gvozdev 2012-07-09 15:57:28 -04:00
parent 92a473a130
commit 09fed04601

View file

@ -29,11 +29,15 @@ 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 final String ENV_PATH = "PATH"; //$NON-NLS-1$
private static String envPathValueCached = null; private static String envPathValueCached = null;
private static String envMingwHomeValueCached = null; private static String envMingwHomeValueCached = null;
private static IPath binDir = null; private static IPath binDir = null;
private static IPath msysBinDir = null;
private static class MingwBuildEnvironmentVariable implements IBuildEnvironmentVariable { private static class MingwBuildEnvironmentVariable implements IBuildEnvironmentVariable {
private static final String PATH_SEPARATOR = ";"; //$NON-NLS-1$
private final String name; private final String name;
private final String value; private final String value;
private final int operation; private final int operation;
@ -61,12 +65,10 @@ public class MingwEnvironmentVariableSupplier implements IConfigurationEnvironme
@Override @Override
public String getDelimiter() { public String getDelimiter() {
return ";"; //$NON-NLS-1$ return PATH_SEPARATOR;
} }
} }
private IBuildEnvironmentVariable path;
/** /**
* @return location of $MINGW_HOME/bin folder on the file-system. * @return location of $MINGW_HOME/bin folder on the file-system.
* *
@ -74,24 +76,47 @@ public class MingwEnvironmentVariableSupplier implements IConfigurationEnvironme
* Please rely on internal caching. * Please rely on internal caching.
*/ */
public static IPath getBinDir() { public static IPath getBinDir() {
IEnvironmentVariable varPath = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable("PATH", null, true); //$NON-NLS-1$ locateMingw();
return binDir;
}
/**
* @return location of $MINGW_HOME/msys/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 getMsysBinDir() {
locateMingw();
return msysBinDir;
}
/**
* Locate MinGW directories. The results are judicially cached so it is reasonably cheap to call.
* The reason to call it each time is to check if user changed environment in preferences.
*/
private static void locateMingw() {
IEnvironmentVariable varPath = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable(ENV_PATH, null, true);
String envPathValue = varPath != null ? varPath.getValue() : null; String envPathValue = varPath != null ? varPath.getValue() : null;
IEnvironmentVariable varMingwHome = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable("MINGW_HOME", null, true); //$NON-NLS-1$ IEnvironmentVariable varMingwHome = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable("MINGW_HOME", null, true); //$NON-NLS-1$
String envMingwHomeValue = varMingwHome != null ? varMingwHome.getValue() : null; String envMingwHomeValue = varMingwHome != null ? varMingwHome.getValue() : null;
if (CDataUtil.objectsEqual(envPathValue, envPathValueCached) && CDataUtil.objectsEqual(envMingwHomeValue, envMingwHomeValueCached)) { if (CDataUtil.objectsEqual(envPathValue, envPathValueCached) && CDataUtil.objectsEqual(envMingwHomeValue, envMingwHomeValueCached)) {
return binDir; return;
} }
envPathValueCached = envPathValue; envPathValueCached = envPathValue;
envMingwHomeValueCached = envMingwHomeValue; envMingwHomeValueCached = envMingwHomeValue;
binDir = null;
binDir = locateBinDir();
msysBinDir = locateMsysBinDir(binDir);
}
private static IPath locateBinDir() {
// Check $MINGW_HOME // Check $MINGW_HOME
IPath mingwBinDir = new Path(envMingwHomeValue + "\\bin"); //$NON-NLS-1$ IPath mingwBinDir = new Path(envMingwHomeValueCached + "\\bin"); //$NON-NLS-1$
if (mingwBinDir.toFile().isDirectory()) { if (mingwBinDir.toFile().isDirectory()) {
binDir = mingwBinDir; return mingwBinDir;
return binDir;
} }
// Try the mingw directory in the platform install directory // Try the mingw directory in the platform install directory
@ -99,8 +124,7 @@ public class MingwEnvironmentVariableSupplier implements IConfigurationEnvironme
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()) {
binDir = mingwBinDir; return mingwBinDir;
return binDir;
} }
// Look in PATH values. Look for mingw32-gcc.exe // Look in PATH values. Look for mingw32-gcc.exe
@ -108,67 +132,64 @@ public class MingwEnvironmentVariableSupplier implements IConfigurationEnvironme
// This is really only to support isToolchainAvail. Must be a better way. // This is really only to support isToolchainAvail. Must be a better way.
// AG: Because otherwise the toolchain won't be shown in the list of "supported" toolchains in UI // AG: Because otherwise the toolchain won't be shown in the list of "supported" toolchains in UI
// when MinGW installed in custom location even if it is in the PATH // when MinGW installed in custom location even if it is in the PATH
IPath gccLoc = PathUtil.findProgramLocation("mingw32-gcc.exe", envPathValue); //$NON-NLS-1$ IPath gccLoc = PathUtil.findProgramLocation("mingw32-gcc.exe", envPathValueCached); //$NON-NLS-1$
if (gccLoc != null) { if (gccLoc != null) {
binDir = gccLoc.removeLastSegments(1); return 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()) {
binDir = mingwBinDir; return mingwBinDir;
return binDir;
} }
return binDir;
}
public static IPath getMsysBinDir() {
// Just look in the install location parent dir
IPath installPath = new Path(Platform.getInstallLocation().getURL().getFile());
IPath msysBinPath = installPath.append("msys\\bin"); //$NON-NLS-1$
if (msysBinPath.toFile().isDirectory())
return msysBinPath;
String mingwHome = envMingwHomeValueCached;
if (mingwHome != null) {
msysBinPath = new Path(mingwHome + "\\msys\\1.0\\bin"); //$NON-NLS-1$
if (msysBinPath.toFile().isDirectory())
return msysBinPath;
}
// Try the new MinGW msys bin dir
msysBinPath = new Path("C:\\MinGW\\msys\\1.0\\bin"); //$NON-NLS-1$
if (msysBinPath.toFile().isDirectory())
return msysBinPath;
return null; return null;
} }
public MingwEnvironmentVariableSupplier() { private static IPath locateMsysBinDir(IPath binPath) {
IPath binPath = getBinDir();
if (binPath != null) { if (binPath != null) {
String pathStr = binPath.toOSString(); // Just look in the install location parent dir
IPath msysBinPath = getMsysBinDir(); IPath installPath = new Path(Platform.getInstallLocation().getURL().getFile());
if (msysBinPath != null) IPath msysBinPath = installPath.append("msys\\bin"); //$NON-NLS-1$
pathStr += ';' + msysBinPath.toOSString(); if (msysBinPath.toFile().isDirectory()) {
return msysBinPath;
}
path = new MingwBuildEnvironmentVariable("PATH", pathStr, IBuildEnvironmentVariable.ENVVAR_PREPEND); //$NON-NLS-1$ if (envMingwHomeValueCached != null) {
msysBinPath = new Path(envMingwHomeValueCached + "\\msys\\1.0\\bin"); //$NON-NLS-1$
if (msysBinPath.toFile().isDirectory()) {
return msysBinPath;
}
}
// Try the new MinGW msys bin dir
msysBinPath = new Path("C:\\MinGW\\msys\\1.0\\bin"); //$NON-NLS-1$
if (msysBinPath.toFile().isDirectory()) {
return msysBinPath;
}
} }
return null;
} }
@Override @Override
public IBuildEnvironmentVariable getVariable(String variableName, public IBuildEnvironmentVariable getVariable(String variableName, IConfiguration configuration, IEnvironmentVariableProvider provider) {
IConfiguration configuration, IEnvironmentVariableProvider provider) { if (variableName.equals(ENV_PATH)) {
if (path != null && variableName.equals(path.getName())) locateMingw();
return path; if (binDir != null) {
else String pathStr = binDir.toOSString();
return null; if (msysBinDir != null) {
pathStr += MingwBuildEnvironmentVariable.PATH_SEPARATOR + msysBinDir.toOSString();
}
return new MingwBuildEnvironmentVariable(ENV_PATH, pathStr, IBuildEnvironmentVariable.ENVVAR_PREPEND);
}
}
return null;
} }
@Override @Override
public IBuildEnvironmentVariable[] getVariables( public IBuildEnvironmentVariable[] getVariables(IConfiguration configuration, IEnvironmentVariableProvider provider) {
IConfiguration configuration, IEnvironmentVariableProvider provider) { IBuildEnvironmentVariable path = getVariable(ENV_PATH, configuration, provider);
return path != null return path != null
? new IBuildEnvironmentVariable[] { path } ? new IBuildEnvironmentVariable[] { path }
: new IBuildEnvironmentVariable[0]; : new IBuildEnvironmentVariable[0];