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

Partial fix for PR 94702: CygpathTranslator cannot work with old cygwin versions.

Scanner Configuration Discovery now uses 'cygpath' command specified in CygwinPEBinaryParser property page.
This commit is contained in:
Vladimir Hirsl 2005-05-26 21:01:08 +00:00
parent 3720c60ebd
commit f8dc010214
6 changed files with 114 additions and 125 deletions

View file

@ -51,3 +51,5 @@ ConsoleParser.Nonexistent_Include_Path_Error_Message=CDT Path Discovery has disc
DiscoveredContainer.description=Discovered Paths
DiscoveredContainer.ScopeErrorMessage=Invalid scanner configuration discovery profile scope
CygpathTranslator.NotAvailableErrorMessage=Error launching 'cygpath' command

View file

@ -10,144 +10,107 @@
**********************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig.util;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import org.eclipse.cdt.core.CommandLauncher;
import org.eclipse.cdt.make.core.MakeCorePlugin;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.core.IMarkerGenerator;
import org.eclipse.cdt.make.internal.core.MakeMessages;
import org.eclipse.cdt.make.internal.core.scannerconfig2.SCMarkerGenerator;
import org.eclipse.cdt.utils.CygPath;
import org.eclipse.cdt.utils.ICygwinToolsFactroy;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
/**
* Executes external command 'cygpath' to translate cygpaths to absolute paths.
* Use binary parser's 'cygpath' command to translate cygpaths to absolute paths.
*
* @author vhirsl
*/
public class CygpathTranslator {
private IPath cwd;
private String transPath;
private boolean isCygpathAvailable;
private boolean status;
private static final String CYGPATH_ERROR_MESSAGE = "CygpathTranslator.NotAvailableErrorMessage"; //$NON-NLS-1$
private CygPath cygPath = null;
private boolean isAvailable = false;
public CygpathTranslator() {
this(MakeCorePlugin.getDefault().getStateLocation());
}
public CygpathTranslator(IPath cwd) {
this.cwd = cwd;
isCygpathAvailable = Platform.getOS().equals(Platform.OS_WIN32);
translate("/"); //$NON-NLS-1$
isCygpathAvailable = status;
}
public String translate(final String path) {
if (!isCygpathAvailable)
return path;
ISafeRunnable runnable = new ISafeRunnable() {
public void run() throws Exception {
transPath = platformRun(path);
if (transPath.startsWith("cygpath:")) { //$NON-NLS-1$
transPath = null;
}
}
public void handleException(Throwable exception) {
transPath = path;
MakeCorePlugin.log(exception);
}
};
Platform.run(runnable);
return transPath;
}
/**
* @param path
* @return
*/
private String platformRun(String path) {
CommandLauncher launcher = new CommandLauncher();
launcher.showCommand(false);
OutputStream output = new ByteArrayOutputStream();
Process p = launcher.execute(
new Path("cygpath"), //$NON-NLS-1$
new String[] {"-m", path}, //$NON-NLS-1$
new String[0],//setEnvironment(launcher, "c:/"),//$NON-NLS-1$
cwd); //$NON-NLS-1$
if (p != null) {
public CygpathTranslator(IProject project) {
SCMarkerGenerator scMarkerGenerator = new SCMarkerGenerator();
try {
// Close the input of the Process explicitely.
// We will never write to it.
p.getOutputStream().close();
ICExtensionReference[] parserRef = CCorePlugin.getDefault().getBinaryParserExtensions(project);
for (int i = 0; i < parserRef.length; i++) {
try {
IBinaryParser parser = (IBinaryParser)parserRef[i].createExtension();
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)) {
cygPath = new CygPath("cygpath"); //$NON-NLS-1$
isAvailable = true;
}
}
catch (CoreException e) {
}
catch (IOException e) {
isAvailable = false;
scMarkerGenerator = new SCMarkerGenerator();
scMarkerGenerator.addMarker(project, -1,
MakeMessages.getString(CYGPATH_ERROR_MESSAGE),
IMarkerGenerator.SEVERITY_WARNING, null);
}
if (launcher.waitAndRead(output, output) != CommandLauncher.OK) {
//String errMsg = launcher.getErrorMessage();
status = false;
if (isAvailable) {
// remove problem markers
scMarkerGenerator.removeMarker(project, -1,
MakeMessages.getString(CYGPATH_ERROR_MESSAGE),
IMarkerGenerator.SEVERITY_WARNING, null);
}
else
status = true;
return output.toString().trim();
}
return path;
}
/**
* @param launcher
* @return
*/
private String[] setEnvironment(CommandLauncher launcher, String dir) {
// Set the environmennt, some scripts may need the CWD var to be set.
IPath workingDirectory = new Path(dir);
Properties props = launcher.getEnvironment();
props.put("CWD", workingDirectory.toOSString()); //$NON-NLS-1$
props.put("PWD", workingDirectory.toOSString()); //$NON-NLS-1$
String[] env = null;
ArrayList envList = new ArrayList();
Enumeration names = props.propertyNames();
if (names != null) {
while (names.hasMoreElements()) {
String key = (String) names.nextElement();
envList.add(key + "=" + props.getProperty(key)); //$NON-NLS-1$
}
env = (String[]) envList.toArray(new String[envList.size()]);
}
return env;
}
/**
* @param sumIncludes
* @return
*/
public static List translateIncludePaths(List sumIncludes) {
CygpathTranslator cygpath = new CygpathTranslator();
if (!cygpath.isCygpathAvailable) return sumIncludes;
public static List translateIncludePaths(IProject project, List sumIncludes) {
CygpathTranslator cygpath = new CygpathTranslator(project);
if (cygpath.cygPath == null) return sumIncludes;
List translatedIncludePaths = new ArrayList();
for (Iterator i = sumIncludes.iterator(); i.hasNext(); ) {
String includePath = (String) i.next();
IPath realPath = new Path(includePath);
if (!realPath.toFile().exists()) {
String translatedPath = cygpath.translate(includePath);
if (translatedPath != null && cygpath.status == true) {
if (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$
}
}
if (!translatedPath.equals(includePath)) {
// Check if the translated path exists
IPath transPath = new Path(translatedPath);
if (transPath.toFile().exists()) {
translatedIncludePaths.add(translatedPath);
translatedIncludePaths.add(transPath.toPortableString());
}
else {
// TODO VMIR for now add even if it does not exist
@ -159,14 +122,6 @@ public class CygpathTranslator {
translatedIncludePaths.add(translatedPath);
}
}
else {
TraceUtil.outputError("CygpathTranslator unable to translate path: ",//$NON-NLS-1$
includePath);
}
}
else {
translatedIncludePaths.add(includePath);
}
}
return translatedIncludePaths;
}

View file

@ -258,7 +258,7 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
List siItem = (List) scannerInfo.get(ScannerInfoTypes.SYMBOL_DEFINITIONS);
cmd.setSymbols(siItem);
siItem = (List) scannerInfo.get(ScannerInfoTypes.INCLUDE_PATHS);
cmd.setIncludes(CygpathTranslator.translateIncludePaths(siItem));
cmd.setIncludes(CygpathTranslator.translateIncludePaths(project, siItem));
siItem = (List) scannerInfo.get(ScannerInfoTypes.QUOTE_INCLUDE_PATHS);
cmd.setQuoteIncludes(siItem);

View file

@ -252,7 +252,7 @@ public class PerProjectSICollector implements IScannerInfoCollector2, IScannerIn
addedIncludes = addItemsWithOrder(sumDiscoveredIncludes, discoveredIncludes, true);
// try to translate cygpaths to absolute paths
List finalSumIncludes = CygpathTranslator.translateIncludePaths(sumDiscoveredIncludes);
List finalSumIncludes = CygpathTranslator.translateIncludePaths(project, sumDiscoveredIncludes);
// Step 2. Get project's scanner config
LinkedHashMap persistedIncludes = discPathInfo.getIncludeMap();

View file

@ -10,11 +10,15 @@
***********************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig2;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.IMarkerGenerator;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.runtime.CoreException;
/**
@ -67,6 +71,34 @@ public class SCMarkerGenerator implements IMarkerGenerator {
}
}
public void removeMarker(IResource file, int lineNumber, String errorDesc, int severity, String errorVar) {
IWorkspace workspace = file.getWorkspace();
// remove specific marker
try {
IMarker[] markers = file.findMarkers(ICModelMarker.C_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_ONE);
if (markers != null) {
List exactMarkers = new ArrayList();
for (int i = 0; i < markers.length; i++) {
IMarker marker = markers[i];
int location = ((Integer) marker.getAttribute(IMarker.LOCATION)).intValue();
String error = (String) marker.getAttribute(IMarker.MESSAGE);
int sev = ((Integer) marker.getAttribute(IMarker.SEVERITY)).intValue();
if (location == lineNumber &&
errorDesc.equals(error) &&
sev == severity) {
exactMarkers.add(marker);
}
}
if (exactMarkers.size() > 0) {
workspace.deleteMarkers((IMarker[]) exactMarkers.toArray(new IMarker[exactMarkers.size()]));
}
}
}
catch (CoreException e) {
CCorePlugin.log(e.getStatus());
}
}
int mapMarkerSeverity(int severity) {
switch (severity) {
case SEVERITY_ERROR_BUILD :

View file

@ -37,7 +37,7 @@ public class DefaultGnuWinScannerInfoCollector extends DefaultGCCScannerInfoColl
List symbols = (List) scannerInfo.get(ScannerInfoTypes.SYMBOL_DEFINITIONS);
// This method will be called by the parser each time there is a new value
List translatedIncludes = CygpathTranslator.translateIncludePaths(includes);
List translatedIncludes = CygpathTranslator.translateIncludePaths(project, includes);
Iterator pathIter = translatedIncludes.listIterator();
while (pathIter.hasNext()) {
String convertedPath = (String) pathIter.next();