diff options
author | Andrew Gvozdev | 2012-07-11 21:56:33 +0000 |
---|---|---|
committer | Andrew Gvozdev | 2013-02-01 14:52:26 +0000 |
commit | d960fff7ddd0f1120d1ad733b04cc880461555fe (patch) | |
tree | d256a5c96bce62198c374e6d1d29e16d9865be0c /build/org.eclipse.cdt.make.core | |
parent | b5807e9b299039e1370185c9e2444957c093039d (diff) | |
download | org.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.make.core')
-rw-r--r-- | build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CygpathTranslator.java | 238 |
1 files changed, 127 insertions, 111 deletions
diff --git a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CygpathTranslator.java b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CygpathTranslator.java index 820df07aac7..3dca63cf0c0 100644 --- a/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CygpathTranslator.java +++ b/build/org.eclipse.cdt.make.core/src/org/eclipse/cdt/make/internal/core/scannerconfig/util/CygpathTranslator.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2011 IBM Corporation and others. + * Copyright (c) 2004, 2013 IBM 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 @@ -20,8 +20,14 @@ import java.util.List; import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.envvar.IEnvironmentVariable; +import org.eclipse.cdt.core.envvar.IEnvironmentVariableManager; import org.eclipse.cdt.core.model.CoreModelUtil; import org.eclipse.cdt.core.settings.model.ICConfigExtensionReference; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.internal.core.Cygwin; +import org.eclipse.cdt.make.core.MakeCorePlugin; import org.eclipse.cdt.utils.CygPath; import org.eclipse.cdt.utils.ICygwinToolsFactroy; import org.eclipse.core.resources.IProject; @@ -32,125 +38,135 @@ import org.eclipse.core.runtime.Platform; /** * Use binary parser's 'cygpath' command to translate cygpaths to absolute paths. + * Note that this class does not support build configurations. * * @author vhirsl */ public class CygpathTranslator { - /** Default Cygwin root dir */ - private static final String DEFAULT_CYGWIN_ROOT= "C:\\cygwin"; //$NON-NLS-1$ - // private static final String CYGPATH_ERROR_MESSAGE = "CygpathTranslator.NotAvailableErrorMessage"; //$NON-NLS-1$ - private CygPath cygPath = null; - private boolean isAvailable = false; - - public CygpathTranslator(IProject project) { - try { - ICConfigExtensionReference[] parserRef = CCorePlugin.getDefault().getDefaultBinaryParserExtensions(project); - for (int i = 0; i < parserRef.length; i++) { - try { - IBinaryParser parser = CoreModelUtil.getBinaryParser(parserRef[i]); - ICygwinToolsFactroy cygwinToolFactory = (ICygwinToolsFactroy) parser.getAdapter(ICygwinToolsFactroy.class); - if (cygwinToolFactory != null) { - cygPath = cygwinToolFactory.getCygPath(); - if (cygPath != null) { - isAvailable = true; - break; - } - } - } catch (ClassCastException e) { - } - } - // No CygPath specified in BinaryParser page or not supported. - // Hoping that cygpath is on the path. - if (cygPath == null && Platform.getOS().equals(Platform.OS_WIN32)) { - if (new File(DEFAULT_CYGWIN_ROOT).exists()) { - cygPath = new CygPath(DEFAULT_CYGWIN_ROOT + "\\bin\\cygpath.exe"); //$NON-NLS-1$ - } else { - cygPath = new CygPath("cygpath"); //$NON-NLS-1$ - } - isAvailable = cygPath.getFileName("test").equals("test"); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - catch (CoreException e) { - } - catch (IOException e) { - isAvailable = false; - // Removing markers. if cygpath isn't in your path then you aren't using cygwin. - // Then why are we calling this.... -// scMarkerGenerator.addMarker(project, -1, -// MakeMessages.getString(CYGPATH_ERROR_MESSAGE), -// IMarkerGenerator.SEVERITY_WARNING, null); - } - } - - public static List<String> translateIncludePaths(IProject project, List<String> sumIncludes) { - // first check if cygpath translation is needed at all - boolean translationNeeded = false; - if (Platform.getOS().equals(Platform.OS_WIN32)) { - for (Iterator<String> i = sumIncludes.iterator(); i.hasNext(); ) { + private static final String ENV_PATH = "PATH"; //$NON-NLS-1$ + + private CygPath cygPath = null; + + public CygpathTranslator(IProject project) { + try { + ICConfigExtensionReference[] parserRef = CCorePlugin.getDefault().getDefaultBinaryParserExtensions(project); + for (int i = 0; i < parserRef.length; i++) { + try { + IBinaryParser parser = CoreModelUtil.getBinaryParser(parserRef[i]); + ICygwinToolsFactroy cygwinToolFactory = (ICygwinToolsFactroy) parser.getAdapter(ICygwinToolsFactroy.class); + if (cygwinToolFactory != null) { + cygPath = cygwinToolFactory.getCygPath(); + } + } catch (ClassCastException e) { + } + } + } + catch (CoreException e) { + } + } + + public static List<String> translateIncludePaths(IProject project, List<String> sumIncludes) { + // first check if cygpath translation is needed at all + boolean translationNeeded = false; + if (Platform.getOS().equals(Platform.OS_WIN32)) { + for (Iterator<String> i = sumIncludes.iterator(); i.hasNext(); ) { String include = i.next(); if (include.startsWith("/")) { //$NON-NLS-1$ translationNeeded = true; break; } } - } - if (!translationNeeded) { - return sumIncludes; - } - - CygpathTranslator cygpath = new CygpathTranslator(project); - - List<String> translatedIncludePaths = new ArrayList<String>(); - for (Iterator<String> i = sumIncludes.iterator(); i.hasNext(); ) { - String includePath = i.next(); - IPath realPath = new Path(includePath); - // only allow native pathes if they have a device prefix - // to avoid matches on the current drive, e.g. /usr/bin = C:\\usr\\bin - if (realPath.getDevice() != null && realPath.toFile().exists()) { - translatedIncludePaths.add(includePath); - } - else { - String translatedPath = includePath; - if (cygpath.isAvailable) { - try { - translatedPath = cygpath.cygPath.getFileName(includePath); - } - catch (IOException e) { - TraceUtil.outputError("CygpathTranslator unable to translate path: ", includePath); //$NON-NLS-1$ - } - } else if (realPath.segmentCount() >= 2) { - // try default conversions - // /cygdrive/x/ --> X:\ - if ("cygdrive".equals(realPath.segment(0))) { //$NON-NLS-1$ - String drive= realPath.segment(1); - if (drive.length() == 1) { - translatedPath= realPath.removeFirstSegments(2).makeAbsolute().setDevice(drive.toUpperCase() + ':').toOSString(); - } - } - } - if (!translatedPath.equals(includePath)) { - // Check if the translated path exists - if (new File(translatedPath).exists()) { - translatedIncludePaths.add(translatedPath); - } - else if (cygpath.isAvailable) { - // TODO VMIR for now add even if it does not exist - translatedIncludePaths.add(translatedPath); - } - else { - translatedIncludePaths.add(includePath); - } - } - else { - // TODO VMIR for now add even if it does not exist - translatedIncludePaths.add(translatedPath); - } - } - } - if (cygpath.cygPath != null) { - cygpath.cygPath.dispose(); - } - return translatedIncludePaths; - } + } + if (!translationNeeded) { + return sumIncludes; + } + + CygpathTranslator cygpath = new CygpathTranslator(project); + boolean useCygPathExtension = cygpath.cygPath != null; + boolean useCygwinFromPath = !useCygPathExtension; + + String envPath = null; + if (useCygwinFromPath) { + IEnvironmentVariableManager mngr = CCorePlugin.getDefault().getBuildEnvironmentManager(); + ICProjectDescription prjDes = CCorePlugin.getDefault().getProjectDescription(project, false); + if (prjDes != null) { + // we don't know for sure which configuration needs to be used here, so betting on "DefaultSettingConfiguration" + // considering that scanner discovery uses "DefaultSettingConfiguration" rather than "Active" configuration, + // see org.eclipse.cdt.build.core.scannerconfig.ScannerConfigBuilder.build(CfgInfoContext context, ...) + ICConfigurationDescription cfgDes = prjDes.getDefaultSettingConfiguration(); + IEnvironmentVariable envVar = mngr.getVariable(ENV_PATH, cfgDes, true); + if (envVar != null) { + envPath = envVar.getValue(); + } + } + if (envPath == null) { + IEnvironmentVariable envVar = mngr.getVariable(ENV_PATH, null, true); + if (envVar != null) { + envPath = envVar.getValue(); + } + } + + useCygwinFromPath = Cygwin.isAvailable(envPath); + } + + List<String> translatedIncludePaths = new ArrayList<String>(); + for (Iterator<String> i = sumIncludes.iterator(); i.hasNext(); ) { + String includePath = i.next(); + IPath realPath = new Path(includePath); + // only allow native pathes if they have a device prefix + // to avoid matches on the current drive, e.g. /usr/bin = C:\\usr\\bin + if (realPath.getDevice() != null && realPath.toFile().exists()) { + translatedIncludePaths.add(includePath); + } + else { + String translatedPath = includePath; + + if (useCygPathExtension) { + try { + translatedPath = cygpath.cygPath.getFileName(includePath); + } + catch (IOException e) { + TraceUtil.outputError("CygpathTranslator unable to translate path: ", includePath); //$NON-NLS-1$ + } + } else if (useCygwinFromPath) { + try { + translatedPath = Cygwin.cygwinToWindowsPath(includePath, envPath); + } catch (Exception e) { + MakeCorePlugin.log(e); + } + } else if (realPath.segmentCount() >= 2) { + // try default conversions + // /cygdrive/x/ --> X:\ + if ("cygdrive".equals(realPath.segment(0))) { //$NON-NLS-1$ + String drive= realPath.segment(1); + if (drive.length() == 1) { + translatedPath= realPath.removeFirstSegments(2).makeAbsolute().setDevice(drive.toUpperCase() + ':').toOSString(); + } + } + } + if (!translatedPath.equals(includePath)) { + // Check if the translated path exists + if (new File(translatedPath).exists()) { + translatedIncludePaths.add(translatedPath); + } + else if (useCygPathExtension || useCygwinFromPath) { + // TODO VMIR for now add even if it does not exist + translatedIncludePaths.add(translatedPath); + } + else { + translatedIncludePaths.add(includePath); + } + } + else { + // TODO VMIR for now add even if it does not exist + translatedIncludePaths.add(translatedPath); + } + } + } + if (useCygPathExtension) { + cygpath.cygPath.dispose(); + } + return translatedIncludePaths; + } } |