Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Gvozdev2012-07-11 21:56:33 +0000
committerAndrew Gvozdev2013-02-01 14:52:26 +0000
commitd960fff7ddd0f1120d1ad733b04cc880461555fe (patch)
treed256a5c96bce62198c374e6d1d29e16d9865be0c /build/org.eclipse.cdt.managedbuilder.gnu.ui/src
parentb5807e9b299039e1370185c9e2444957c093039d (diff)
downloadorg.eclipse.cdt-d960fff7ddd0f1120d1ad733b04cc880461555fe.tar.gz
org.eclipse.cdt-d960fff7ddd0f1120d1ad733b04cc880461555fe.tar.xz
org.eclipse.cdt-d960fff7ddd0f1120d1ad733b04cc880461555fe.zip
bug 357442: Added $CYGWIN_HOME to cygwin toolchain detection algorithm
Diffstat (limited to 'build/org.eclipse.cdt.managedbuilder.gnu.ui/src')
-rw-r--r--build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/CygwinPathResolver.java270
-rw-r--r--build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/GnuCygwinConfigurationEnvironmentSupplier.java67
-rw-r--r--build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/IsGnuCygwinToolChainSupported.java71
3 files changed, 170 insertions, 238 deletions
diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/CygwinPathResolver.java b/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/CygwinPathResolver.java
index 8f2b5b7e781..f3e5dc9e034 100644
--- a/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/CygwinPathResolver.java
+++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/CygwinPathResolver.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Intel Corporation and others.
+ * Copyright (c) 2005, 2013 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -9,6 +9,7 @@
* Intel Corporation - Initial API and implementation
* Enrico Ehrich - http://bugs.eclipse.org/233866
* Marc-Andre Laperle - fix for Cygwin GCC is Not detected (bug 303900)
+ * Andrew Gvozdev - changes to recognize $CYGWIN_HOME
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.gnu.cygwin;
@@ -19,9 +20,8 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
-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.internal.core.Cygwin;
import org.eclipse.cdt.managedbuilder.core.IBuildPathResolver;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
@@ -30,40 +30,35 @@ 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.IStatus;
+import org.eclipse.core.runtime.Status;
/**
* @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 TOOL = "/cygpath -w -p "; //$NON-NLS-1$
- private static final char BS = '\\';
- private static final char SLASH = '/';
+ private static final String ENV_PATH = "PATH"; //$NON-NLS-1$
+ private static final String DELIMITER_UNIX = ":"; //$NON-NLS-1$
+ private static final String DELIMITER_WIN = ";"; //$NON-NLS-1$
+
private static final String PROPERTY_OS_NAME = "os.name"; //$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$
+ private static final String OS_WINDOWS = "windows";//$NON-NLS-1$
+ private static final char SLASH = '/';
+ private static final char BACKSLASH = '\\';
+
+ private static final String CYGPATH_PATH_LIST_TO_WINDOWS = "cygpath -w -p "; //$NON-NLS-1$
+
// note that in Cygwin 1.7 the mount point storage has been moved out of the registry
private static final String REGISTRY_KEY_MOUNTS = "SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2\\"; //$NON-NLS-1$
private static final String PATH_NAME = "native"; //$NON-NLS-1$
- private static final String SSLASH = "/"; //$NON-NLS-1$
- private static final String BSLASH = "\\\\"; //$NON-NLS-1$
private static final String BINPATTERN = "/usr/bin"; //$NON-NLS-1$
private static final String BINPATTERN_ALTERNATE = "/bin"; //$NON-NLS-1$
private static final String ETCPATTERN = "/etc"; //$NON-NLS-1$
- private static final String ROOTPATTERN = SSLASH;
- private static final String DELIMITER_UNIX = ":"; //$NON-NLS-1$
- private static final String DELIMITER_WIN = ";"; //$NON-NLS-1$
+
private static final String GCC_VERSION_CMD = "gcc --version"; //$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 String envPathValueCached = null;
- private static String binCygwin = null;
- private static String rootCygwin = null;
- private static String etcCygwin = null;
-
@Override
public String[] resolveBuildPaths(int pathType, String variableName, String variableValue, IConfiguration configuration) {
if(!isWindows()) {
@@ -72,58 +67,66 @@ public class CygwinPathResolver implements IBuildPathResolver {
return variableValue.split(DELIMITER_WIN);
}
- String[] result = variableValue.split(DELIMITER_UNIX);
- String exePath = getBinPath();
- if (exePath == null) {
- return result; // no changes
- }
- File file = new File(exePath);
- if (!file.exists() || !file.isDirectory()) {
- return result; // no changes
- }
- String s = exePath + TOOL + variableValue;
- String[] lines = exec(s, configuration);
+ String[] lines = executeInConfigurationContext(CYGPATH_PATH_LIST_TO_WINDOWS + variableValue, configuration);
if (lines != null && lines.length > 0) {
- result = lines[0].replace(BS,SLASH).split(DELIMITER_WIN);
+ String pathList = lines[0].replace(BACKSLASH, SLASH);
+ return pathList.split(DELIMITER_WIN);
}
- return result;
+
+ return variableValue.split(DELIMITER_UNIX);
}
/**
- * returns "/etc" path in Windows format
+ * @return "/etc" path in Windows format for workspace.
+ * @deprecated. Deprecated as of CDT 8.2. Note that Cygwin 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 String getEtcPath() {
- findPaths();
+ String etcCygwin = getPathFromRoot(ETCPATTERN);
+ // Try to find the paths in SOFTWARE\\Cygnus Solutions
+ if(etcCygwin == null) {
+ etcCygwin = readValueFromRegistry(REGISTRY_KEY_MOUNTS + ETCPATTERN, PATH_NAME);
+ }
return etcCygwin;
}
/**
- * returns "/usr/bin" path in Windows format
+ * @return "/usr/bin" path in Windows format for workspace.
+ * @deprecated. Deprecated as of CDT 8.2. Note that Cygwin 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 String getBinPath() {
- findPaths();
+ String binCygwin = getPathFromRoot(BINPATTERN);
+ if(binCygwin == null) {
+ binCygwin = getPathFromRoot(BINPATTERN_ALTERNATE);
+ }
+ // Try to find the paths in SOFTWARE\\Cygnus Solutions
+ if(binCygwin == null) {
+ binCygwin = readValueFromRegistry(REGISTRY_KEY_MOUNTS + BINPATTERN, PATH_NAME);
+ }
return binCygwin;
}
/**
- * returns Cygwin root ("/") path in Windows format
+ * @return Cygwin root ("/") path in Windows format for workspace.
+ * @deprecated. Deprecated as of CDT 8.2. Note that Cygwin 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 String getRootPath() {
- findPaths();
- return rootCygwin;
+ return Cygwin.getCygwinHome();
}
public static boolean isWindows() {
- return (System.getProperty(PROPERTY_OS_NAME).toLowerCase().startsWith(PROPERTY_OS_VALUE));
+ return (System.getProperty(PROPERTY_OS_NAME).toLowerCase().startsWith(OS_WINDOWS));
}
/**
@@ -136,146 +139,117 @@ public class CygwinPathResolver implements IBuildPathResolver {
*/
private static String readValueFromRegistry(String key, String name) {
WindowsRegistry registry = WindowsRegistry.getRegistry();
- if (null != registry) {
- String s = registry.getCurrentUserValue(key, name);
- if(s == null)
- s = registry.getLocalMachineValue(key, name);
-
- if (s != null)
- return (s.replaceAll(BSLASH, SSLASH));
+ if (registry != null) {
+ String value = registry.getCurrentUserValue(key, name);
+ if (value == null) {
+ value = registry.getLocalMachineValue(key, name);
+ }
+ if (value != null) {
+ return value.replace(BACKSLASH, SLASH);
+ }
}
return null;
}
/**
- * Returns the absolute path of the pattern by
- * simply appending the pattern to the root
+ * Returns the absolute path of the pattern by simply appending the relativePath to the root.
*
- * @param pattern The pattern to find
- * @return The absolute path to the pattern or null if pattern is not found
+ * @param relativePath - the pattern to find.
+ * @return The absolute path to the pattern or {@code null} if path does not exist.
*/
- private static String getValueFromRoot(String pattern) {
+ private static String getPathFromRoot(String relativePath) {
+ String rootCygwin = Cygwin.getCygwinHome();
if (rootCygwin != null) {
- String path = rootCygwin + pattern;
+ String path = rootCygwin + relativePath;
File file = new File(path);
- if (file.exists() && file.isDirectory())
- return (path.replaceAll(BSLASH, SSLASH));
- else
- return null;
+ if (file.exists() && file.isDirectory()) {
+ return path.replace(BACKSLASH, SLASH);
+ }
}
-
return null;
}
/**
- * Returns the absolute path to cygwin's root
+ * Resolve and return full path to program in context of configuration.
*
- * @return The absolute path to cygwin's root or null if not found
+ * @param program - program to resolve.
+ * @param cfg - configuration context.
+ * @return absolute path to program.
*/
- private static String findRoot(String paths) {
- String rootValue = null;
-
- // 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();
- }
-
- // 2. Try to find the root dir in SOFTWARE\Cygwin\setup
- if(rootValue == null) {
- rootValue = readValueFromRegistry(REGISTRY_KEY_SETUP, "rootdir"); //$NON-NLS-1$
- }
-
- // 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$
- }
-
- // 4. Try to find the root dir in SOFTWARE\Cygnus Solutions
- if (rootValue == null) {
- rootValue = readValueFromRegistry(REGISTRY_KEY_MOUNTS + ROOTPATTERN, PATH_NAME);
- }
-
- // 5. Try the default Cygwin install dir
- if(rootValue == null) {
- File file = new File(DEFAULT_ROOT);
- if (file.exists() && file.isDirectory())
- rootValue = DEFAULT_ROOT;
+ private static String resolveProgram(String program, IConfiguration cfg) {
+ String envPathValue = null;
+ try {
+ IEnvironmentVariable envPathVar = ManagedBuildManager.getEnvironmentVariableProvider().getVariable(ENV_PATH, cfg, true);
+ if (envPathVar != null) {
+ envPathValue = envPathVar.getValue();
+ IPath progPath = PathUtil.findProgramLocation(program, envPathValue);
+ if (progPath != null) {
+ program = progPath.toOSString();
+ }
+ // this resolves cygwin symbolic links
+ program = Cygwin.cygwinToWindowsPath(program, envPathValue);
+ }
+ } catch (Exception e) {
+ GnuUIPlugin.getDefault().log(new Status(IStatus.WARNING, GnuUIPlugin.PLUGIN_ID, "Problem trying to find program [" + program + "] in $PATH=[" + envPathValue + "]", e));
}
-
- if(rootValue != null)
- rootValue = rootValue.replaceAll(BSLASH, SSLASH);
-
- return rootValue;
+ return program;
}
/**
- * Finds Cygwin's paths and sets corresponding properties.
+ * Return environment in envp format, see {@link Runtime#exec(String, String[])}.
+ *
+ * @param cfg - configuration.
+ * @return environment as array of strings in format name=value.
*/
- private static synchronized void findPaths() {
- if (!isWindows()) {
- return;
+ private static String[] getEnvp(IConfiguration cfg) {
+ IEnvironmentVariable vars[] = ManagedBuildManager.getEnvironmentVariableProvider().getVariables(cfg,true);
+ String envp[] = new String[vars.length];
+ for(int i = 0; i < envp.length; i++) {
+ envp[i] = vars[i].getName() +'=';
+ String value = vars[i].getValue();
+ if(value != null)
+ envp[i] += value;
}
-
- 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;
- binCygwin = null;
- rootCygwin = null;
-
- rootCygwin = findRoot(envPathValue);
-
- // 1. Try to find the paths by appending the patterns to the root dir
- etcCygwin = getValueFromRoot(ETCPATTERN);
- binCygwin = getValueFromRoot(BINPATTERN);
- if(binCygwin == null)
- binCygwin = getValueFromRoot(BINPATTERN_ALTERNATE);
-
- // 2. Try to find the paths in SOFTWARE\\Cygnus Solutions
- if(etcCygwin == null)
- etcCygwin = readValueFromRegistry(REGISTRY_KEY_MOUNTS + ETCPATTERN, PATH_NAME);
- if(binCygwin == null)
- binCygwin = readValueFromRegistry(REGISTRY_KEY_MOUNTS + BINPATTERN, PATH_NAME);
-
- envPathValueCached = envPathValue;
+ return envp;
}
- private static String[] exec(String cmd, IConfiguration cfg) {
+ /**
+ * Execute command taking in account configuration environment.
+ *
+ * @param cmd - command to execute.
+ * @param cfg - configuration context.
+ * @return command output as string array.
+ */
+ private static String[] executeInConfigurationContext(String cmd, IConfiguration cfg) {
+ String[] args = cmd.split(" "); //$NON-NLS-1$
+ args[0] = resolveProgram(args[0], cfg);
+
+ String[] result = null;
try {
- IEnvironmentVariable vars[] = ManagedBuildManager.getEnvironmentVariableProvider().getVariables(cfg,true);
- String env[] = new String[vars.length];
- for(int i = 0; i < env.length; i++) {
- env[i] = vars[i].getName() + "="; //$NON-NLS-1$
- String value = vars[i].getValue();
- if(value != null)
- env[i] += value;
- }
- Process proc = ProcessFactory.getFactory().exec(cmd.split(SP), env);
+ String[] envp = getEnvp(cfg);
+ Process proc = ProcessFactory.getFactory().exec(args, envp);
if (proc != null) {
-
InputStream ein = proc.getInputStream();
- BufferedReader d1 = new BufferedReader(new InputStreamReader(ein));
- ArrayList<String> ls = new ArrayList<String>(10);
- String s;
- while ((s = d1.readLine() ) != null ) {
- ls.add(s);
+ try {
+ BufferedReader d1 = new BufferedReader(new InputStreamReader(ein));
+ ArrayList<String> ls = new ArrayList<String>(10);
+ String s;
+ while ((s = d1.readLine()) != null ) {
+ ls.add(s);
+ }
+ result = ls.toArray(new String[0]);
+ } finally {
+ ein.close();
}
- ein.close();
- return ls.toArray(new String[0]);
}
} catch (IOException e) {
- GnuUIPlugin.getDefault().log(e);
+ GnuUIPlugin.getDefault().log(new Status(IStatus.ERROR, GnuUIPlugin.PLUGIN_ID, "Error executing program [" +cmd + "]", e));
}
- return null;
+ return result;
}
public static boolean isMinGW(IConfiguration cfg) {
- String versionInfo[] = exec(GCC_VERSION_CMD, cfg);
+ String versionInfo[] = executeInConfigurationContext(GCC_VERSION_CMD, cfg);
if(versionInfo != null) {
for(int i = 0; i < versionInfo.length; i++) {
if(versionInfo[i].indexOf(MINGW_SPECIAL) != -1)
diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/GnuCygwinConfigurationEnvironmentSupplier.java b/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/GnuCygwinConfigurationEnvironmentSupplier.java
index ae08fcf841d..5b659ead2d2 100644
--- a/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/GnuCygwinConfigurationEnvironmentSupplier.java
+++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/GnuCygwinConfigurationEnvironmentSupplier.java
@@ -1,33 +1,38 @@
/*******************************************************************************
- * Copyright (c) 2005, 2011 Intel Corporation and others.
+ * Copyright (c) 2005, 2012 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
- * Intel Corporation - Initial API and implementation
+ * Intel Corporation - Initial API and implementation
+ * Andrew Gvozdev - Ability to use different Cygwin versions in different cfg
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.gnu.cygwin;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.envvar.IEnvironmentVariable;
+import org.eclipse.cdt.internal.core.Cygwin;
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
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.IPath;
+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 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 ENV_PATH = "PATH"; //$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 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$
+ private static final String PROPERTY_OSNAME = "os.name"; //$NON-NLS-1$
+ private static final String BACKSLASH = java.io.File.separator;
@Override
public IBuildEnvironmentVariable getVariable(String variableName, IConfiguration configuration, IEnvironmentVariableProvider provider) {
@@ -39,19 +44,33 @@ public class GnuCygwinConfigurationEnvironmentSupplier implements IConfiguration
return null;
}
- 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));
+ if (variableName.equalsIgnoreCase(ENV_PATH)) {
+ @SuppressWarnings("nls")
+ String path = "${" + Cygwin.ENV_CYGWIN_HOME + "}" + BACKSLASH + "bin";
+ return new BuildEnvVar(ENV_PATH, path, IBuildEnvironmentVariable.ENVVAR_PREPEND);
+
+ } else if (variableName.equals(Cygwin.ENV_CYGWIN_HOME)) {
+ String home = Cygwin.getCygwinHome();
+ // If the variable is not defined still show it in the environment variables list as a hint to user
+ if (home == null) {
+ home = ""; //$NON-NLS-1$
+ }
+ IPath homePath = new Path(home);
+ IEnvironmentVariable varCygwinHome = CCorePlugin.getDefault().getBuildEnvironmentManager().getVariable(Cygwin.ENV_CYGWIN_HOME, null, false);
+ if (varCygwinHome == null || (!homePath.equals(new Path(varCygwinHome.getValue())))) {
+ // Contribute if the variable does not already come from workspace environment
+ return new BuildEnvVar(Cygwin.ENV_CYGWIN_HOME, homePath.toOSString());
}
- } else if (variableName.equalsIgnoreCase(LANG)) {
+ return null;
+
+ } else if (variableName.equalsIgnoreCase(ENV_LANG)) {
// Workaround for not being able to select encoding for CDT console -> change codeset to Latin1
- String langValue = System.getenv(LANG);
+ String langValue = System.getenv(ENV_LANG);
if (langValue == null || langValue.length() == 0) {
- langValue = System.getenv(LC_ALL);
+ langValue = System.getenv(ENV_LC_ALL);
}
if (langValue == null || langValue.length() == 0) {
- langValue = System.getenv(LC_MESSAGES);
+ langValue = System.getenv(ENV_LC_MESSAGES);
}
if (langValue != null && langValue.length() > 0) {
// langValue is [language[_territory][.codeset][@modifier]], i.e. "en_US.UTF-8@dict"
@@ -61,21 +80,17 @@ public class GnuCygwinConfigurationEnvironmentSupplier implements IConfiguration
} else {
langValue = "C.ISO-8859-1"; //$NON-NLS-1$
}
-
- return new BuildEnvVar(LANG, langValue);
+ return new BuildEnvVar(ENV_LANG, langValue);
}
return null;
}
@Override
public IBuildEnvironmentVariable[] getVariables(IConfiguration configuration, IEnvironmentVariableProvider provider) {
- IBuildEnvironmentVariable varLang = getVariable(LANG, configuration, provider);
- IBuildEnvironmentVariable varPath = getVariable(PATH, configuration, provider);
+ IBuildEnvironmentVariable varHome = getVariable(Cygwin.ENV_CYGWIN_HOME, configuration, provider);
+ IBuildEnvironmentVariable varLang = getVariable(ENV_LANG, configuration, provider);
+ IBuildEnvironmentVariable varPath = getVariable(ENV_PATH, configuration, provider);
- if (varPath != null) {
- return new IBuildEnvironmentVariable[] {varLang, varPath};
- } else {
- return new IBuildEnvironmentVariable[] {varLang};
- }
+ return new IBuildEnvironmentVariable[] {varHome, varLang, varPath};
}
}
diff --git a/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/IsGnuCygwinToolChainSupported.java b/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/IsGnuCygwinToolChainSupported.java
index a2d2050338a..9a2fd648827 100644
--- a/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/IsGnuCygwinToolChainSupported.java
+++ b/build/org.eclipse.cdt.managedbuilder.gnu.ui/src/org/eclipse/cdt/managedbuilder/gnu/cygwin/IsGnuCygwinToolChainSupported.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2005, 2010 Intel Corporation and others.
+ * Copyright (c) 2005, 2013 Intel Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -7,85 +7,28 @@
*
* Contributors:
* Intel Corporation - Initial API and implementation
+ * Andrew Gvozdev - Ability to use different Cygwin versions in different configurations
*******************************************************************************/
package org.eclipse.cdt.managedbuilder.gnu.cygwin;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-
-import org.eclipse.cdt.core.settings.model.util.CDataUtil;
+import org.eclipse.cdt.internal.core.Cygwin;
import org.eclipse.cdt.managedbuilder.core.IManagedIsToolChainSupported;
import org.eclipse.cdt.managedbuilder.core.IToolChain;
+import org.eclipse.cdt.managedbuilder.internal.envvar.EnvironmentVariableManagerToolChain;
import org.osgi.framework.Version;
/**
* This class implements the IManagedIsToolChainSupported for the Gnu Cygwin tool-chain
- * The class is NOT used currently, because currently the gnu cygwin tool-chain
- * is intended to be used not only with Cygwin, but with MinGW also, and there is no
- * correct way of determining whether the appropriate packages are installed for MinGW.
- *
- * For the future MBS/CDT versions we might create the separate tool-chain/configuration/project-type
- * for the MinGW and define a set of converters using the tool-chain converter mechanism that MBS will provide,
- * that would convert the CygWin to the MinGW projects/tool-chains, and vice a versa.
*
* @noextend This class is not intended to be subclassed by clients.
*/
public class IsGnuCygwinToolChainSupported implements IManagedIsToolChainSupported {
- private static final String[] CHECKED_NAMES = {"gcc", "binutils", "make"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ private static final String ENV_PATH = "PATH"; //$NON-NLS-1$
- private static String etcCygwinCached = null;
- private static boolean toolchainIsSupported = false;
-
- /**
- * @since 8.0
- */
@Override
public boolean isSupported(IToolChain toolChain, Version version, String instance) {
- String etcCygwin = CygwinPathResolver.getEtcPath();
- if (CDataUtil.objectsEqual(etcCygwin, etcCygwinCached)) {
- return toolchainIsSupported;
- }
-
- toolchainIsSupported = etcCygwin != null && arePackagesInstalled(etcCygwin);
- etcCygwinCached = etcCygwin;
-
- return toolchainIsSupported;
+ String envPath = EnvironmentVariableManagerToolChain.getDefault().getVariableInConfigurationContext(ENV_PATH, toolChain, true);
+ return Cygwin.isAvailable(envPath);
}
- /**
- * Returns true if all required packages are installed, see CHECKED_NAMES for a list of packages. Cygwin
- * maintains a list of packages in /etc/setup/installed.db so we look for packages in this file.
- *
- * @param etcCygwin the absolute path of /etc containing /setup/installed.db
- * @return true if the packages specified in CHECKED_NAMES are installed
- */
- private boolean arePackagesInstalled(String etcCygwin) {
- boolean arePackagesInstalled = false;
- File file = new File(etcCygwin + "/setup/installed.db"); //$NON-NLS-1$
- try {
- BufferedReader data = new BufferedReader(new FileReader(file));
-
- // All required package names should be found
- boolean[] found = new boolean[CHECKED_NAMES.length];
- String s;
- while ((s = data.readLine()) != null ) {
- for (int j = 0; j < CHECKED_NAMES.length; j++) {
- if (s.startsWith(CHECKED_NAMES[j])) {
- found[j] = true;
- }
- }
- }
- arePackagesInstalled = true;
- for (int j = 0; j < CHECKED_NAMES.length; j++) {
- arePackagesInstalled &= found[j];
- }
- data.close();
- } catch (FileNotFoundException e) {
- } catch (IOException e) {
- }
- return arePackagesInstalled;
- }
}

Back to the top