1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-15 04:05:38 +02:00

Fix for 216945: GCCPerFileBOPConsoleParser doesn't handle symbolic links correctly

This commit is contained in:
Anton Leherbauer 2008-02-04 10:12:50 +00:00
parent cd0bd1eebb
commit 1c7064167a
5 changed files with 91 additions and 80 deletions

View file

@ -23,6 +23,7 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper;
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
import org.eclipse.cdt.make.internal.core.scannerconfig.gnu.GCCPerFileBOPConsoleParser;
import org.eclipse.cdt.make.internal.core.scannerconfig.util.CCommandDSC;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
@ -91,4 +92,26 @@ public class GCCPerFileBOPConsoleParserTests extends BaseBOPConsoleParserTests {
tempDir.delete();
}
}
public void testResolvingLinkedResourceArgument_Bug216945() throws Exception {
File tempRoot= new File(System.getProperty("java.io.tmpdir"));
File tempDir= new File(tempRoot, "cdttest_216945");
tempDir.mkdir();
File tempFile= null;
try {
tempFile= new File(tempDir, "test.c");
tempFile.createNewFile();
IFolder linkedFolder= fCProject.getProject().getFolder("cdttest");
linkedFolder.createLink(new Path(tempDir.toString()), IResource.ALLOW_MISSING_LOCAL, null);
fOutputParser.processLine("gcc -g -O0 -c \""+ tempFile.toString() + "\""); //$NON-NLS-1$
IFile file= linkedFolder.getFile("test.c");
List cmds = fCollector.getCollectedScannerInfo(file, ScannerInfoTypes.COMPILER_COMMAND);
assertEquals(1, cmds.size());
} finally {
if (tempFile != null) {
tempFile.delete();
}
tempDir.delete();
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2007 Wind River Systems, Inc. and others.
* Copyright (c) 2007, 2008 Wind River Systems, Inc. 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,6 +7,7 @@
*
* Contributors:
* Markus Schorn - initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.make.scannerdiscovery;
@ -24,7 +25,8 @@ import org.eclipse.cdt.make.internal.core.scannerconfig.util.CCommandDSC;
final class TestScannerInfoCollector implements IScannerInfoCollector {
private HashMap fInfoMap = new HashMap();
private HashMap fResourceToInfoMap = new HashMap();
public void contributeToScannerConfig(Object resource, Map scannerInfo) {
for (Iterator iterator = scannerInfo.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
@ -41,6 +43,9 @@ final class TestScannerInfoCollector implements IScannerInfoCollector {
}
}
}
if (resource != null) {
fResourceToInfoMap.put(resource, scannerInfo);
}
}
private void addTo(ScannerInfoTypes type, List col) {
@ -53,7 +58,15 @@ final class TestScannerInfoCollector implements IScannerInfoCollector {
}
public List getCollectedScannerInfo(Object resource, ScannerInfoTypes type) {
List result= (List) fInfoMap.get(type);
return result == null ? Collections.EMPTY_LIST : result;
if (resource == null) {
List result= (List) fInfoMap.get(type);
return result == null ? Collections.EMPTY_LIST : result;
}
Map scannerInfo= (Map)fResourceToInfoMap.get(resource);
if (scannerInfo != null) {
List result= (List) scannerInfo.get(type);
return result == null ? Collections.EMPTY_LIST : result;
}
return Collections.EMPTY_LIST;
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -10,6 +10,7 @@
* Tianchao Li (tianchao.li@gmail.com) - arbitrary build directory (bug #136136)
* Gerhard Schaber (Wind River Systems) - bug 187910
* Markus Schorn (Wind River Systems)
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig.gnu;
@ -27,6 +28,7 @@ import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
@ -116,22 +118,9 @@ public class GCCPerFileBOPConsoleParser extends AbstractGCCBOPConsoleParser {
}
}
CCommandDSC cmd = fUtil.getNewCCommandDSC(tokens, compilerInvocationIndex, extensionsIndex > 0);
IPath baseDirectory = fUtil.getBaseDirectory();
boolean isValidPath = baseDirectory.isPrefixOf(pFilePath);
if (!isValidPath) {
final IProject prj= fUtil.getProject();
IFile[] foundOccurrences = ((IWorkspaceRoot) prj.getParent()).findFilesForLocation(pFilePath);
for (int j=0; !isValidPath && j<foundOccurrences.length; j++) {
isValidPath= prj.equals(foundOccurrences[j].getProject());
}
}
if (isValidPath) {
List cmdList = new ArrayList();
cmdList.add(cmd);
Map sc = new HashMap(1);
sc.put(ScannerInfoTypes.COMPILER_COMMAND, cmdList);
IFile file= null;
IPath baseDirectory= fUtil.getBaseDirectory();
if (baseDirectory.isPrefixOf(pFilePath)) {
IPath relPath = pFilePath.removeFirstSegments(baseDirectory.segmentCount());
//Note: We add the scanner-config even if the resource doesn't actually
//exist below this project (which may happen when reading existing
@ -139,15 +128,28 @@ public class GCCPerFileBOPConsoleParser extends AbstractGCCBOPConsoleParser {
//and may not exist at the time of analyzing the config but re-built
//later on.
//if (getProject().exists(relPath)) {
IFile file = getProject().getFile(relPath);
getCollector().contributeToScannerConfig(file, sc);
file = getProject().getFile(relPath);
} else {
//TODO limiting to paths below this project means not being
//able to work with linked resources. Linked resources could
//be checked through IWorkspaceRoot.findFilesForLocation().
TraceUtil.outputError("Build command for file outside project: "+pFilePath.toString(), tokens); //$NON-NLS-1$
// search linked resources
final IProject prj= fUtil.getProject();
final IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
IFile[] foundOccurrences= root.findFilesForLocation(pFilePath);
for (int j=0; j<foundOccurrences.length; j++) {
if (prj.equals(foundOccurrences[j].getProject())) {
file= foundOccurrences[j];
break;
}
}
}
// fUtil.addGenericCommandForFile2(longFileName, genericLine);
if (file != null) {
CCommandDSC cmd = fUtil.getNewCCommandDSC(tokens, compilerInvocationIndex, extensionsIndex > 0);
List cmdList = new ArrayList();
cmdList.add(cmd);
Map sc = new HashMap(1);
sc.put(ScannerInfoTypes.COMPILER_COMMAND, cmdList);
getCollector().contributeToScannerConfig(file, sc);
} else
TraceUtil.outputError("Build command for file outside project: "+pFilePath.toString(), tokens); //$NON-NLS-1$
}
return true;
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -231,35 +231,33 @@ public class PerFileSICollector implements IScannerInfoCollector3, IScannerInfoC
addScannerInfo(((Integer)resource), scannerInfo);
return;
}
// GSA allow per project settings
// else if (!(resource instanceof IFile)) {
// errorMessage = "resource is not an IFile";//$NON-NLS-1$
// }
else if (!(resource instanceof IFile)) {
errorMessage = "resource is not an IFile";//$NON-NLS-1$
}
else if (((IFile) resource).getProject() == null) {
errorMessage = "project is null";//$NON-NLS-1$
}
else if (((IFile) resource).getProject() != project) {
else if (!((IFile) resource).getProject().equals(project)) {
errorMessage = "wrong project";//$NON-NLS-1$
}
if (errorMessage != null) {
TraceUtil.outputError("PerFileSICollector.contributeToScannerConfig : ", errorMessage); //$NON-NLS-1$
return;
}
if (resource instanceof IFile) {
IFile file = (IFile) resource;
for (Iterator i = scannerInfo.keySet().iterator(); i.hasNext(); ) {
ScannerInfoTypes type = (ScannerInfoTypes) i.next();
if (type.equals(ScannerInfoTypes.COMPILER_COMMAND)) {
List commands = (List) scannerInfo.get(type);
for (Iterator j = commands.iterator(); j.hasNext(); ) {
addCompilerCommand(file, (CCommandDSC) j.next());
}
}
else {
addScannerInfo(type, (List) scannerInfo.get(type));
}
}
IFile file = (IFile) resource;
for (Iterator i = scannerInfo.keySet().iterator(); i.hasNext(); ) {
ScannerInfoTypes type = (ScannerInfoTypes) i.next();
if (type.equals(ScannerInfoTypes.COMPILER_COMMAND)) {
List commands = (List) scannerInfo.get(type);
for (Iterator j = commands.iterator(); j.hasNext(); ) {
addCompilerCommand(file, (CCommandDSC) j.next());
}
}
else {
addScannerInfo(type, (List) scannerInfo.get(type));
}
}
}

View file

@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others.
* Copyright (c) 2004, 2008 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
@ -7,6 +7,7 @@
*
* Contributors:
* IBM - Initial API and implementation
* Anton Leherbauer (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig2;
@ -50,7 +51,7 @@ import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.SafeRunner;
import org.w3c.dom.Element;
/**
@ -107,7 +108,7 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
else if (((IResource) resource).getProject() == null) {
errorMessage = "project is null";//$NON-NLS-1$
}
else if (((IResource) resource).getProject() != project) {
else if (!((IResource) resource).getProject().equals(project)) {
errorMessage = "wrong project";//$NON-NLS-1$
}
if (errorMessage != null) {
@ -289,32 +290,6 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
return addedIncludes;
}
/*
* translated to raw map
*/
private Map translateDiscoveredIncludes(List list){
int baseSize = list.size();
LinkedHashMap map = new LinkedHashMap(baseSize);
List translated = CygpathTranslator.translateIncludePaths(project, list);
if(baseSize == translated.size()){
for(int i = 0; i < baseSize; i++){
map.put(translated.get(i), list.get(i));
}
} else {
List tmpList = new ArrayList(1);
for(int i = 0; i < baseSize; i++){
String basePath = (String)list.get(i);
tmpList.add(0, basePath);
List tr = CygpathTranslator.translateIncludePaths(project, tmpList);
if(tr.size() != 0){
String translatedPath = (String)tr.get(0);
map.put(translatedPath, basePath);
}
}
}
return map;
}
/**
* Compare symbol definitions with already discovered.
*
@ -507,7 +482,7 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
}
}
};
Platform.run(runnable);
SafeRunner.run(runnable);
}
private static void createDiscoveredPathContainer(IProject project, IProgressMonitor monitor) throws CModelException {