diff options
author | Mikhail Sennikovsky | 2005-05-23 16:12:19 +0000 |
---|---|---|
committer | Mikhail Sennikovsky | 2005-05-23 16:12:19 +0000 |
commit | 2853cf688d3aaab6ddd8892794375b1b95a898d8 (patch) | |
tree | fbdbcb1e77cbe7fb5f3e7d25328d921b963a851f /build/org.eclipse.cdt.managedbuilder.gnu.ui/src | |
parent | 734abeba9d813a8706ceceae6aee69364d4fc9b1 (diff) | |
download | org.eclipse.cdt-2853cf688d3aaab6ddd8892794375b1b95a898d8.tar.gz org.eclipse.cdt-2853cf688d3aaab6ddd8892794375b1b95a898d8.tar.xz org.eclipse.cdt-2853cf688d3aaab6ddd8892794375b1b95a898d8.zip |
Check-in of the Tool-chain installation support ( 87478) and the Managed Build Process Environment support ( 88497) implementation for the Gnu Cygwin tool-chain
Diffstat (limited to 'build/org.eclipse.cdt.managedbuilder.gnu.ui/src')
3 files changed, 245 insertions, 9 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 c4da0e291b8..9de5cf61f48 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 @@ -10,18 +10,196 @@ **********************************************************************/ package org.eclipse.cdt.managedbuilder.gnu.cygwin; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.ArrayList; + import org.eclipse.cdt.managedbuilder.core.IBuildPathResolver; import org.eclipse.cdt.managedbuilder.core.IConfiguration; +import org.eclipse.cdt.managedbuilder.gnu.ui.GnuUIPlugin; +import org.eclipse.cdt.utils.spawner.ProcessFactory; +import org.eclipse.core.runtime.IPath; + public class CygwinPathResolver implements IBuildPathResolver { + static final String TOOL = "/cygpath -w -p "; //$NON-NLS-1$ + static final char BS = '\\'; //$NON-NLS-1$ + static final char SLASH = '/'; //$NON-NLS-1$ + static final String PROPERTY_OS_NAME = "os.name"; //$NON-NLS-1$ + static final String PROPERTY_OS_VALUE = "windows";//$NON-NLS-1$ + static final String ARG0 = "regedit"; //$NON-NLS-1$ + static final String ARG1 = "/ea"; //$NON-NLS-1$ + static final String OUTFILE = "result.txt"; //$NON-NLS-1$ + static final String SP = " "; //$NON-NLS-1$ + static final String QUOT = "\""; //$NON-NLS-1$ + static final String REGISTRY_KEY = "\\SOFTWARE\\Cygnus Solutions\\Cygwin\\mounts v2"; //$NON-NLS-1$ + static final String[] REGISTRY_ROOTS = {"\"HKEY_CURRENT_USER", "\"HKEY_LOCAL_MACHINE"}; //$NON-NLS-1$ //$NON-NLS-2$ + static final String REGISTRY_BINS = "/usr/bin"; //$NON-NLS-1$ + static final String CYGPREF_NAME = "cygdrive prefix"; //$NON-NLS-1$ + static final String PATH_NAME = "native"; //$NON-NLS-1$ + static final String REG_SZ = "REG_SZ"; //$NON-NLS-1$ + static final String BINPATTERN = "/usr/bin"; //$NON-NLS-1$ + static final String ETCPATTERN = "/etc"; //$NON-NLS-1$ + static final String ROOTPATTERN = "/"; //$NON-NLS-1$ + static final String DELIMITER_UNIX = ":"; //$NON-NLS-1$ + static final String DELIMITER_WIN = ";"; //$NON-NLS-1$ + + static boolean checked = false; + static String binCygwin = null; + static String rootCygwin = null; + static String etcCygwin = null; /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.core.IBuildPathResolver#resolveBuildPaths(int, java.lang.String, java.lang.String, org.eclipse.cdt.managedbuilder.core.IConfiguration) */ public String[] resolveBuildPaths(int pathType, String variableName, String variableValue, IConfiguration configuration) { - // TODO implement - return new String[0]; + + String[] result = variableName.split(DELIMITER_UNIX); + if (!isWindows()) return result; + String exePath = getBinPath(); + if (exePath == null) { return result; } // no changes + File file = new File(exePath); + if (!file.exists() || !file.isDirectory()) { return result; } // no changes + + ArrayList ls = new ArrayList(); + String s = exePath + TOOL + variableValue; + String[] lines = exec(s); + if (s != null && s.length() > 0) { + result = lines[0].replace(BS,SLASH).split(DELIMITER_WIN); + } + return result; + } + /* + * returns "/etc" path in Windows format + */ + public static String getEtcPath() { + if (!checked) checkRegistry(); + return etcCygwin; } + /* + * returns "/usr/bin" path in Windows format + */ + public static String getBinPath() { + if (!checked) checkRegistry(); + return binCygwin; + } + /* + * returns Cygwin root ("/") path in Windows format + */ + + public static String getRootPath() { + if (!checked) checkRegistry(); + return rootCygwin; + } + /** + * @return + */ + public static boolean isWindows() { + return (System.getProperty(PROPERTY_OS_NAME).toLowerCase().startsWith(PROPERTY_OS_VALUE)); + } + + /** + * reads once data from registry (for Win32 only) + * and sets corresponding properties; + */ + + private static synchronized void checkRegistry() { + checked = true; + etcCygwin = null; + binCygwin = null; + rootCygwin = null; + if (!isWindows()) return; + for(int i = 0; i < REGISTRY_ROOTS.length; i++){ + IPath toSave = GnuUIPlugin.getDefault().getStateLocation(); + toSave = toSave.addTrailingSeparator().append(OUTFILE); + String[] args = {ARG0, ARG1, toSave.toOSString(), REGISTRY_ROOTS[i]+REGISTRY_KEY+QUOT }; + File f = new File(toSave.toOSString()); + f.delete(); + int result = -1; + try { + result = ProcessFactory.getFactory().exec(args).waitFor(); + } + catch (IOException e) {} + catch (InterruptedException e) {} + if (result == 0 && f.exists() && f.canRead()) { + BufferedReader r = null; + try { + r = new BufferedReader(new InputStreamReader(new FileInputStream(f))); + } catch (FileNotFoundException e) {} + ArrayList ls = new ArrayList(1); + try { + String s; + while ((s = r.readLine() ) != null ) ls.add(s); + r.close(); + f.delete(); + } catch (IOException e) {} + String[] aus = (String[])ls.toArray(new String[0]); + if (etcCygwin == null) { etcCygwin = getDir(aus, ETCPATTERN); } + if (binCygwin == null) { binCygwin = getDir(aus, BINPATTERN); } + if (rootCygwin == null) { rootCygwin = getDir(aus, ROOTPATTERN);} + } + } + } + + /** + * @param ls - "regedit"'s output + * @param pattern - path to search + * @return + */ + private static String getDir(String[] ls, String pattern) { + String tail = ""; //$NON-NLS-1$ + while (pattern.length() > 0) { + boolean search = false; + for (int i=0; i<ls.length; i++) { + int pos=0; + if (ls[i].lastIndexOf(REGISTRY_KEY) > 0) { + search = ls[i].endsWith(pattern+"]"); //$NON-NLS-1$ + } + else if (search && ((pos = ls[i].lastIndexOf(PATH_NAME)) > 0)) { + String s = ls[i].substring(pos + PATH_NAME.length() + 3).trim(); + s = s.substring(0, s.length() - 1) + tail; + return s.replaceAll("\\\\+", "/"); //$NON-NLS-1$ //$NON-NLS-2$ + } + } + if (pattern.equals(ROOTPATTERN)) break; // no other paths to search + int pos = pattern.lastIndexOf(SLASH); + if (pos < 0) break; + tail = pattern.substring(pos, pattern.length()) + tail; + if (pos == 0) + pattern = ROOTPATTERN; // leave leading slash + else + pattern = pattern.substring(0, pos); + } + return null; + } + + private static String[] exec(String cmd) { + try { +// Process proc = Runtime.getRuntime().exec(cmd); + Process proc = ProcessFactory.getFactory().exec(cmd.split(SP)); + if (proc != null) { + + InputStream ein = proc.getInputStream(); + BufferedReader d1 = new BufferedReader(new InputStreamReader(ein)); + ArrayList ls = new ArrayList(10); + String s; + while ((s = d1.readLine() ) != null ) { + ls.add(s); + } + ein.close(); + return (String[])ls.toArray(new String[0]); + } + } catch (IOException e) { + //TODO: log + } + return null; + } } +
\ No newline at end of file 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 1e063d530e6..62147892ab1 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 @@ -12,19 +12,33 @@ package org.eclipse.cdt.managedbuilder.gnu.cygwin; import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.envvar.IBuildEnvironmentVariable; +import org.eclipse.cdt.managedbuilder.internal.envvar.BuildEnvVar; import org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier; import org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider; public class GnuCygwinConfigurationEnvironmentSupplier implements IConfigurationEnvironmentVariableSupplier { + static final String VARNAME = "PATH"; //$NON-NLS-1$ + static final String DELIMITER_UNIX = ":"; //$NON-NLS-1$ + static final String PROPERTY_DELIMITER = "path.separator"; //$NON-NLS-1$ + static final String PROPERTY_OSNAME = "os.name"; //$NON-NLS-1$ /* (non-Javadoc) * @see org.eclipse.cdt.managedbuilder.envvar.IConfigurationEnvironmentVariableSupplier#getVariable(java.lang.String, org.eclipse.cdt.managedbuilder.core.IConfiguration, org.eclipse.cdt.managedbuilder.envvar.IEnvironmentVariableProvider) */ public IBuildEnvironmentVariable getVariable(String variableName, IConfiguration configuration, IEnvironmentVariableProvider provider) { - // TODO implement - return null; + + if (!System.getProperty(PROPERTY_OSNAME).toLowerCase().startsWith("windows ")) //$NON-NLS-1$ + return null; + + if (variableName == null) return null; + if (!VARNAME.equalsIgnoreCase(variableName)) return null; + + String p = CygwinPathResolver.getBinPath(); + if (p != null) + return new BuildEnvVar(VARNAME, p.replace('/','\\'), IBuildEnvironmentVariable.ENVVAR_PREPEND, System.getProperty(PROPERTY_DELIMITER, DELIMITER_UNIX)); //$NON-NLS-1$ //$NON-NLS-2$ + return null; } /* (non-Javadoc) @@ -32,8 +46,10 @@ public class GnuCygwinConfigurationEnvironmentSupplier implements */ public IBuildEnvironmentVariable[] getVariables( IConfiguration configuration, IEnvironmentVariableProvider provider) { - // TODO implement + + IBuildEnvironmentVariable[] tmp = new IBuildEnvironmentVariable[1]; + tmp[0] = getVariable(VARNAME, configuration, provider); + if (tmp[0] != null) return tmp; return null; } - } 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 c91f47d9815..c3318795386 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 @@ -10,17 +10,59 @@ **********************************************************************/ 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.managedbuilder.core.IManagedIsToolChainSupported; import org.eclipse.cdt.managedbuilder.core.IToolChain; import org.eclipse.core.runtime.PluginVersionIdentifier; public class IsGnuCygwinToolChainSupported implements IManagedIsToolChainSupported { + + static final String[] CHECKED_NAMES = {"gcc ", "binutils ", "make "}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + static boolean suppChecked = false; + static boolean toolchainIsSupported = false; + /* + * returns support status + */ public boolean isSupported(IToolChain toolChain, PluginVersionIdentifier version, String instance) { - // TODO implement - return true; - } + + if (suppChecked) return toolchainIsSupported; + suppChecked = true; + String etcCygwin = CygwinPathResolver.getEtcPath(); + if (etcCygwin != null) { + File file = new File(etcCygwin + "/setup/installed.db"); //$NON-NLS-1$ + BufferedReader data; + try { + data = new BufferedReader(new FileReader(file)); + } catch (FileNotFoundException e) { return false; } + + // all required package names should be found + boolean[] found = new boolean[CHECKED_NAMES.length]; + try { + 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;} + } + } + toolchainIsSupported = true; + for (int j = 0; j < CHECKED_NAMES.length; j++) { + toolchainIsSupported &= found[j]; + } + data.close(); + } catch (IOException e) { + //TODO: log + } + } + return toolchainIsSupported; + } } |