1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-09 02:36:01 +02:00

Revert [from sd90] "bug 357442: Added $CYGWIN_HOME to cygwin toolchain detection algorithm"

This reverts commit 459437b14d.
This commit is contained in:
Andrew Gvozdev 2013-01-31 12:09:08 -05:00
parent 383cb93e57
commit a3783e3f84
3 changed files with 57 additions and 100 deletions

View file

@ -30,19 +30,17 @@ import org.eclipse.cdt.utils.PathUtil;
import org.eclipse.cdt.utils.WindowsRegistry;
import org.eclipse.cdt.utils.spawner.ProcessFactory;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
/**
* @noextend This class is not intended to be subclassed by clients.
*/
public class CygwinPathResolver implements IBuildPathResolver {
private static final String DEFAULT_ROOT = "C:\\cygwin"; //$NON-NLS-1$
private static final String CYGWIN_DLL = "cygwin1.dll"; //$NON-NLS-1$
private static final String TOOL = "/cygpath -w -p "; //$NON-NLS-1$
private static final char BS = '\\';
private static final char SLASH = '/';
private static final String PROPERTY_OS_NAME = "os.name"; //$NON-NLS-1$
private static final String OS_WINDOWS = "windows";//$NON-NLS-1$
private static final String PROPERTY_OS_VALUE = "windows";//$NON-NLS-1$
private static final String SP = " "; //$NON-NLS-1$
private static final String REGISTRY_KEY_SETUP = "SOFTWARE\\Cygwin\\setup"; //$NON-NLS-1$
private static final String REGISTRY_KEY_SETUP_WIN64 = "SOFTWARE\\Wow6432Node\\Cygwin\\setup"; //$NON-NLS-1$
@ -61,10 +59,7 @@ public class CygwinPathResolver implements IBuildPathResolver {
private static final String MINGW_SPECIAL = "mingw "; //$NON-NLS-1$
private static final String CYGWIN_SPECIAL = "cygwin "; //$NON-NLS-1$
private static final String ENV_PATH = "PATH"; //$NON-NLS-1$
private static String envPathValueCached = null;
private static String envCygwinHomeValueCached = null;
private static String binCygwin = null;
private static String rootCygwin = null;
private static String etcCygwin = null;
@ -95,40 +90,40 @@ public class CygwinPathResolver implements IBuildPathResolver {
}
/**
* @return "/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() {
locateCygwin();
findPaths();
return etcCygwin;
}
/**
* @return "/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() {
locateCygwin();
findPaths();
return binCygwin;
}
/**
* @return 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() {
locateCygwin();
findPaths();
return rootCygwin;
}
public static boolean isWindows() {
return (System.getProperty(PROPERTY_OS_NAME).toLowerCase().startsWith(OS_WINDOWS));
return (System.getProperty(PROPERTY_OS_NAME).toLowerCase().startsWith(PROPERTY_OS_VALUE));
}
/**
@ -153,63 +148,55 @@ public class CygwinPathResolver implements IBuildPathResolver {
}
/**
* Returns the absolute path of the pattern by simply appending the relativePath to the root.
* Returns the absolute path of the pattern by
* simply appending the pattern to the root
*
* @param relativePath - the pattern to find.
* @return The absolute path to the pattern or {@code null} if path does not exist.
* @param pattern The pattern to find
* @return The absolute path to the pattern or null if pattern is not found
*/
private static String getPathFromRoot(String relativePath) {
private static String getValueFromRoot(String pattern) {
if (rootCygwin != null) {
String path = rootCygwin + relativePath;
String path = rootCygwin + pattern;
File file = new File(path);
if (file.exists() && file.isDirectory()) {
if (file.exists() && file.isDirectory())
return (path.replaceAll(BSLASH, SSLASH));
}
else
return null;
}
return null;
}
/**
* Returns the absolute path to cygwin's root
*
* @return The absolute path to cygwin's root or null if not found
*/
private static String findRoot(String paths) {
String rootValue = null;
// Check $CYGWIN_HOME
if (envCygwinHomeValueCached != null && !envCygwinHomeValueCached.isEmpty()) {
IPath location = new Path(envCygwinHomeValueCached + "/bin/" + CYGWIN_DLL);
if (location.toFile().exists()) {
// deduct rootValue from "rootValue\bin\cygwin1.dll"
rootValue = location.removeLastSegments(2).toOSString();
}
// 1. Look in PATH values. Look for bin\cygwin1.dll
IPath location = PathUtil.findProgramLocation("cygwin1.dll", paths); //$NON-NLS-1$
if (location!=null) {
rootValue = location.removeLastSegments(2).toOSString();
}
// Look in PATH values. Look for cygwin1.dll
if(rootValue == null) {
IPath location = PathUtil.findProgramLocation(CYGWIN_DLL, paths);
if (location != null) {
// deduct rootValue from "rootValue\bin\cygwin1.dll"
rootValue = location.removeLastSegments(2).toOSString();
}
}
// Try to find the root dir in SOFTWARE\Cygwin\setup
// 2. Try to find the root dir in SOFTWARE\Cygwin\setup
if(rootValue == null) {
rootValue = readValueFromRegistry(REGISTRY_KEY_SETUP, "rootdir"); //$NON-NLS-1$
}
// Try to find the root dir in SOFTWARE\Wow6432Node\Cygwin\setup
// 3. Try to find the root dir in SOFTWARE\Wow6432Node\Cygwin\setup
if(rootValue == null) {
rootValue = readValueFromRegistry(REGISTRY_KEY_SETUP_WIN64, "rootdir"); //$NON-NLS-1$
}
// Try to find the root dir in SOFTWARE\Cygnus Solutions
// 4. Try to find the root dir in SOFTWARE\Cygnus Solutions
if (rootValue == null) {
rootValue = readValueFromRegistry(REGISTRY_KEY_MOUNTS + ROOTPATTERN, PATH_NAME);
}
// Try the default Cygwin install dir
// 5. Try the default Cygwin install dir
if(rootValue == null) {
File file = new File(DEFAULT_ROOT);
if (file.exists() && file.isDirectory())
@ -225,36 +212,31 @@ public class CygwinPathResolver implements IBuildPathResolver {
/**
* Finds Cygwin's paths and sets corresponding properties.
*/
private static synchronized void locateCygwin() {
private static synchronized void findPaths() {
if (!isWindows()) {
return;
}
IEnvironmentVariable varPath = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable(ENV_PATH, null, true);
IEnvironmentVariable varPath = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable("PATH", null, true); //$NON-NLS-1$
String envPathValue = varPath != null ? varPath.getValue() : null;
IEnvironmentVariable varCygwinHome = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable("CYGWIN_HOME", null, true); //$NON-NLS-1$
String envCygwinHomeValue = varCygwinHome != null ? varCygwinHome.getValue() : null;
if (CDataUtil.objectsEqual(envPathValue, envPathValueCached) && CDataUtil.objectsEqual(envCygwinHomeValue, envCygwinHomeValueCached)) {
if (CDataUtil.objectsEqual(envPathValue, envPathValueCached)) {
return;
}
envPathValueCached = envPathValue;
envCygwinHomeValueCached = envCygwinHomeValue;
etcCygwin = null;
binCygwin = null;
rootCygwin = null;
rootCygwin = findRoot(envPathValue);
// Try to find the paths by appending the patterns to the root dir
etcCygwin = getPathFromRoot(ETCPATTERN);
binCygwin = getPathFromRoot(BINPATTERN);
// 1. Try to find the paths by appending the patterns to the root dir
etcCygwin = getValueFromRoot(ETCPATTERN);
binCygwin = getValueFromRoot(BINPATTERN);
if(binCygwin == null)
binCygwin = getPathFromRoot(BINPATTERN_ALTERNATE);
binCygwin = getValueFromRoot(BINPATTERN_ALTERNATE);
// Try to find the paths in SOFTWARE\\Cygnus Solutions
// 2. Try to find the paths in SOFTWARE\\Cygnus Solutions
if(etcCygwin == null)
etcCygwin = readValueFromRegistry(REGISTRY_KEY_MOUNTS + ETCPATTERN, PATH_NAME);
if(binCygwin == null)

View file

@ -15,22 +15,20 @@ import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable;
import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier;
import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider;
import org.eclipse.cdt.managedbuilder.internal.envvar.BuildEnvVar;
import org.eclipse.core.runtime.Path;
/**
* @noextend This class is not intended to be subclassed by clients.
*/
public class GnuCygwinConfigurationEnvironmentSupplier implements IConfigurationEnvironmentVariableSupplier {
private static final String ENV_PATH = "PATH"; //$NON-NLS-1$
private static final String ENV_CYGWIN_HOME = "CYGWIN_HOME"; //$NON-NLS-1$
private static final String ENV_LANG = "LANG"; //$NON-NLS-1$
private static final String ENV_LC_ALL = "LC_ALL"; //$NON-NLS-1$
private static final String ENV_LC_MESSAGES = "LC_MESSAGES"; //$NON-NLS-1$
private static final String PATH = "PATH"; //$NON-NLS-1$
private static final String DELIMITER_UNIX = ":"; //$NON-NLS-1$
private static final String PROPERTY_DELIMITER = "path.separator"; //$NON-NLS-1$
private static final String PROPERTY_OSNAME = "os.name"; //$NON-NLS-1$
private static final String LANG = "LANG"; //$NON-NLS-1$
private static final String LC_ALL = "LC_ALL"; //$NON-NLS-1$
private static final String LC_MESSAGES = "LC_MESSAGES"; //$NON-NLS-1$
@Override
public IBuildEnvironmentVariable getVariable(String variableName, IConfiguration configuration, IEnvironmentVariableProvider provider) {
if (variableName == null) {
@ -41,28 +39,19 @@ public class GnuCygwinConfigurationEnvironmentSupplier implements IConfiguration
return null;
}
if (variableName.equalsIgnoreCase(ENV_PATH)) {
String path = CygwinPathResolver.getBinPath();
if (path != null) {
path = new Path(path).toOSString();
return new BuildEnvVar(ENV_PATH, path, IBuildEnvironmentVariable.ENVVAR_PREPEND, System.getProperty(PROPERTY_DELIMITER, DELIMITER_UNIX));
if (variableName.equalsIgnoreCase(PATH)) {
String p = CygwinPathResolver.getBinPath();
if (p != null) {
return new BuildEnvVar(PATH, p.replace('/','\\'), IBuildEnvironmentVariable.ENVVAR_PREPEND, System.getProperty(PROPERTY_DELIMITER, DELIMITER_UNIX));
}
} else if (variableName.equals(ENV_CYGWIN_HOME)) {
String home = CygwinPathResolver.getRootPath();
if (home == null) {
home = ""; //$NON-NLS-1$
} else {
home = new Path(home).toOSString();
}
return new BuildEnvVar(ENV_CYGWIN_HOME, home);
} else if (variableName.equalsIgnoreCase(ENV_LANG)) {
} else if (variableName.equalsIgnoreCase(LANG)) {
// Workaround for not being able to select encoding for CDT console -> change codeset to Latin1
String langValue = System.getenv(ENV_LANG);
String langValue = System.getenv(LANG);
if (langValue == null || langValue.length() == 0) {
langValue = System.getenv(ENV_LC_ALL);
langValue = System.getenv(LC_ALL);
}
if (langValue == null || langValue.length() == 0) {
langValue = System.getenv(ENV_LC_MESSAGES);
langValue = System.getenv(LC_MESSAGES);
}
if (langValue != null && langValue.length() > 0) {
// langValue is [language[_territory][.codeset][@modifier]], i.e. "en_US.UTF-8@dict"
@ -73,21 +62,20 @@ public class GnuCygwinConfigurationEnvironmentSupplier implements IConfiguration
langValue = "C.ISO-8859-1"; //$NON-NLS-1$
}
return new BuildEnvVar(ENV_LANG, langValue);
return new BuildEnvVar(LANG, langValue);
}
return null;
}
@Override
public IBuildEnvironmentVariable[] getVariables(IConfiguration configuration, IEnvironmentVariableProvider provider) {
IBuildEnvironmentVariable varHome = getVariable(ENV_CYGWIN_HOME, configuration, provider);
IBuildEnvironmentVariable varLang = getVariable(ENV_LANG, configuration, provider);
IBuildEnvironmentVariable varPath = getVariable(ENV_PATH, configuration, provider);
IBuildEnvironmentVariable varLang = getVariable(LANG, configuration, provider);
IBuildEnvironmentVariable varPath = getVariable(PATH, configuration, provider);
if (varPath != null) {
return new IBuildEnvironmentVariable[] {varHome, varLang, varPath};
return new IBuildEnvironmentVariable[] {varLang, varPath};
} else {
return new IBuildEnvironmentVariable[] {varHome, varLang};
return new IBuildEnvironmentVariable[] {varLang};
}
}
}

View file

@ -29,7 +29,6 @@ import org.eclipse.core.runtime.Platform;
* @noextend This class is not intended to be subclassed by clients.
*/
public class MingwEnvironmentVariableSupplier implements IConfigurationEnvironmentVariableSupplier {
private static final String ENV_MINGW_HOME = "MINGW_HOME"; //$NON-NLS-1$
private static final String ENV_PATH = "PATH"; //$NON-NLS-1$
private static String envPathValueCached = null;
@ -99,7 +98,7 @@ public class MingwEnvironmentVariableSupplier implements IConfigurationEnvironme
private static void locateMingw() {
IEnvironmentVariable varPath = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable(ENV_PATH, null, true);
String envPathValue = varPath != null ? varPath.getValue() : null;
IEnvironmentVariable varMingwHome = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable(ENV_MINGW_HOME, null, true);
IEnvironmentVariable varMingwHome = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable("MINGW_HOME", null, true); //$NON-NLS-1$
String envMingwHomeValue = varMingwHome != null ? varMingwHome.getValue() : null;
if (CDataUtil.objectsEqual(envPathValue, envPathValueCached) && CDataUtil.objectsEqual(envMingwHomeValue, envMingwHomeValueCached)) {
@ -182,18 +181,7 @@ public class MingwEnvironmentVariableSupplier implements IConfigurationEnvironme
@Override
public IBuildEnvironmentVariable getVariable(String variableName, IConfiguration configuration, IEnvironmentVariableProvider provider) {
if (variableName.equals(ENV_MINGW_HOME)) {
locateMingw();
String home = envMingwHomeValueCached;
if (home == null) {
if (binDir != null) {
home = binDir.removeLastSegments(1).toOSString();
} else {
home = ""; //$NON-NLS-1$
}
}
return new MingwBuildEnvironmentVariable(ENV_MINGW_HOME, home, IBuildEnvironmentVariable.ENVVAR_REPLACE);
} else if (variableName.equals(ENV_PATH)) {
if (variableName.equals(ENV_PATH)) {
locateMingw();
if (binDir != null) {
String pathStr = binDir.toOSString();
@ -209,11 +197,10 @@ public class MingwEnvironmentVariableSupplier implements IConfigurationEnvironme
@Override
public IBuildEnvironmentVariable[] getVariables(IConfiguration configuration, IEnvironmentVariableProvider provider) {
IBuildEnvironmentVariable home = getVariable(ENV_MINGW_HOME, configuration, provider);
IBuildEnvironmentVariable path = getVariable(ENV_PATH, configuration, provider);
return path != null
? new IBuildEnvironmentVariable[] { home, path }
: new IBuildEnvironmentVariable[] { home };
? new IBuildEnvironmentVariable[] { path }
: new IBuildEnvironmentVariable[0];
}
}