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:
parent
3720c60ebd
commit
f8dc010214
6 changed files with 114 additions and 125 deletions
|
@ -51,3 +51,5 @@ ConsoleParser.Nonexistent_Include_Path_Error_Message=CDT Path Discovery has disc
|
||||||
|
|
||||||
DiscoveredContainer.description=Discovered Paths
|
DiscoveredContainer.description=Discovered Paths
|
||||||
DiscoveredContainer.ScopeErrorMessage=Invalid scanner configuration discovery profile scope
|
DiscoveredContainer.ScopeErrorMessage=Invalid scanner configuration discovery profile scope
|
||||||
|
|
||||||
|
CygpathTranslator.NotAvailableErrorMessage=Error launching 'cygpath' command
|
||||||
|
|
|
@ -10,144 +10,107 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.core.scannerconfig.util;
|
package org.eclipse.cdt.make.internal.core.scannerconfig.util;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CommandLauncher;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.make.core.MakeCorePlugin;
|
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.IPath;
|
||||||
import org.eclipse.core.runtime.ISafeRunnable;
|
|
||||||
import org.eclipse.core.runtime.Path;
|
import org.eclipse.core.runtime.Path;
|
||||||
import org.eclipse.core.runtime.Platform;
|
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
|
* @author vhirsl
|
||||||
*/
|
*/
|
||||||
public class CygpathTranslator {
|
public class CygpathTranslator {
|
||||||
private IPath cwd;
|
private static final String CYGPATH_ERROR_MESSAGE = "CygpathTranslator.NotAvailableErrorMessage"; //$NON-NLS-1$
|
||||||
private String transPath;
|
private CygPath cygPath = null;
|
||||||
private boolean isCygpathAvailable;
|
private boolean isAvailable = false;
|
||||||
private boolean status;
|
|
||||||
|
|
||||||
|
public CygpathTranslator(IProject project) {
|
||||||
public CygpathTranslator() {
|
SCMarkerGenerator scMarkerGenerator = new SCMarkerGenerator();
|
||||||
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) {
|
|
||||||
try {
|
try {
|
||||||
// Close the input of the Process explicitely.
|
ICExtensionReference[] parserRef = CCorePlugin.getDefault().getBinaryParserExtensions(project);
|
||||||
// We will never write to it.
|
for (int i = 0; i < parserRef.length; i++) {
|
||||||
p.getOutputStream().close();
|
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) {
|
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) {
|
if (isAvailable) {
|
||||||
//String errMsg = launcher.getErrorMessage();
|
// remove problem markers
|
||||||
status = false;
|
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
|
* @param sumIncludes
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static List translateIncludePaths(List sumIncludes) {
|
public static List translateIncludePaths(IProject project, List sumIncludes) {
|
||||||
CygpathTranslator cygpath = new CygpathTranslator();
|
CygpathTranslator cygpath = new CygpathTranslator(project);
|
||||||
if (!cygpath.isCygpathAvailable) return sumIncludes;
|
if (cygpath.cygPath == null) return sumIncludes;
|
||||||
|
|
||||||
List translatedIncludePaths = new ArrayList();
|
List translatedIncludePaths = new ArrayList();
|
||||||
for (Iterator i = sumIncludes.iterator(); i.hasNext(); ) {
|
for (Iterator i = sumIncludes.iterator(); i.hasNext(); ) {
|
||||||
String includePath = (String) i.next();
|
String includePath = (String) i.next();
|
||||||
IPath realPath = new Path(includePath);
|
IPath realPath = new Path(includePath);
|
||||||
if (!realPath.toFile().exists()) {
|
if (realPath.toFile().exists()) {
|
||||||
String translatedPath = cygpath.translate(includePath);
|
translatedIncludePaths.add(includePath);
|
||||||
if (translatedPath != null && cygpath.status == true) {
|
}
|
||||||
|
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)) {
|
if (!translatedPath.equals(includePath)) {
|
||||||
// Check if the translated path exists
|
// Check if the translated path exists
|
||||||
IPath transPath = new Path(translatedPath);
|
IPath transPath = new Path(translatedPath);
|
||||||
if (transPath.toFile().exists()) {
|
if (transPath.toFile().exists()) {
|
||||||
translatedIncludePaths.add(translatedPath);
|
translatedIncludePaths.add(transPath.toPortableString());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO VMIR for now add even if it does not exist
|
// TODO VMIR for now add even if it does not exist
|
||||||
|
@ -159,14 +122,6 @@ public class CygpathTranslator {
|
||||||
translatedIncludePaths.add(translatedPath);
|
translatedIncludePaths.add(translatedPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
TraceUtil.outputError("CygpathTranslator unable to translate path: ",//$NON-NLS-1$
|
|
||||||
includePath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
translatedIncludePaths.add(includePath);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return translatedIncludePaths;
|
return translatedIncludePaths;
|
||||||
}
|
}
|
||||||
|
|
|
@ -258,7 +258,7 @@ public class PerFileSICollector implements IScannerInfoCollector2, IScannerInfoC
|
||||||
List siItem = (List) scannerInfo.get(ScannerInfoTypes.SYMBOL_DEFINITIONS);
|
List siItem = (List) scannerInfo.get(ScannerInfoTypes.SYMBOL_DEFINITIONS);
|
||||||
cmd.setSymbols(siItem);
|
cmd.setSymbols(siItem);
|
||||||
siItem = (List) scannerInfo.get(ScannerInfoTypes.INCLUDE_PATHS);
|
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);
|
siItem = (List) scannerInfo.get(ScannerInfoTypes.QUOTE_INCLUDE_PATHS);
|
||||||
cmd.setQuoteIncludes(siItem);
|
cmd.setQuoteIncludes(siItem);
|
||||||
|
|
||||||
|
|
|
@ -252,7 +252,7 @@ public class PerProjectSICollector implements IScannerInfoCollector2, IScannerIn
|
||||||
addedIncludes = addItemsWithOrder(sumDiscoveredIncludes, discoveredIncludes, true);
|
addedIncludes = addItemsWithOrder(sumDiscoveredIncludes, discoveredIncludes, true);
|
||||||
|
|
||||||
// try to translate cygpaths to absolute paths
|
// 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
|
// Step 2. Get project's scanner config
|
||||||
LinkedHashMap persistedIncludes = discPathInfo.getIncludeMap();
|
LinkedHashMap persistedIncludes = discPathInfo.getIncludeMap();
|
||||||
|
|
|
@ -10,11 +10,15 @@
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
package org.eclipse.cdt.make.internal.core.scannerconfig2;
|
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.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.IMarkerGenerator;
|
import org.eclipse.cdt.core.IMarkerGenerator;
|
||||||
import org.eclipse.cdt.core.model.ICModelMarker;
|
import org.eclipse.cdt.core.model.ICModelMarker;
|
||||||
import org.eclipse.core.resources.IMarker;
|
import org.eclipse.core.resources.IMarker;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.resources.IWorkspace;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
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) {
|
int mapMarkerSeverity(int severity) {
|
||||||
switch (severity) {
|
switch (severity) {
|
||||||
case SEVERITY_ERROR_BUILD :
|
case SEVERITY_ERROR_BUILD :
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class DefaultGnuWinScannerInfoCollector extends DefaultGCCScannerInfoColl
|
||||||
List symbols = (List) scannerInfo.get(ScannerInfoTypes.SYMBOL_DEFINITIONS);
|
List symbols = (List) scannerInfo.get(ScannerInfoTypes.SYMBOL_DEFINITIONS);
|
||||||
|
|
||||||
// This method will be called by the parser each time there is a new value
|
// 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();
|
Iterator pathIter = translatedIncludes.listIterator();
|
||||||
while (pathIter.hasNext()) {
|
while (pathIter.hasNext()) {
|
||||||
String convertedPath = (String) pathIter.next();
|
String convertedPath = (String) pathIter.next();
|
||||||
|
|
Loading…
Add table
Reference in a new issue