1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-06-06 09:16:02 +02:00

The project scanner discovery has to append (rather than prepend) system includes to the search path, bug 226228.

This commit is contained in:
Markus Schorn 2008-05-07 07:05:42 +00:00
parent 1f35172785
commit b8817c486c
3 changed files with 82 additions and 59 deletions

View file

@ -1,16 +1,18 @@
/******************************************************************************* /*******************************************************************************
* 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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig.gnu; package org.eclipse.cdt.make.internal.core.scannerconfig.gnu;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -20,6 +22,7 @@ import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector;
import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser; import org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser;
import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes; import org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes;
import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil; import org.eclipse.cdt.make.internal.core.scannerconfig.util.TraceUtil;
import org.eclipse.cdt.make.internal.core.scannerconfig2.PerProjectSICollector;
import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPath;
@ -38,8 +41,8 @@ public class GCCSpecsConsoleParser implements IScannerInfoConsoleParser {
private IScannerInfoCollector fCollector = null; private IScannerInfoCollector fCollector = null;
private boolean expectingIncludes = false; private boolean expectingIncludes = false;
private List symbols = new ArrayList(); private List<String> symbols = new ArrayList<String>();
private List includes = new ArrayList(); private List<String> includes = new ArrayList<String>();
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser#startup(org.eclipse.core.resources.IProject, org.eclipse.core.runtime.IPath, org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector, org.eclipse.cdt.core.IMarkerGenerator) * @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoConsoleParser#startup(org.eclipse.core.resources.IProject, org.eclipse.core.runtime.IPath, org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector, org.eclipse.cdt.core.IMarkerGenerator)
@ -94,12 +97,18 @@ public class GCCSpecsConsoleParser implements IScannerInfoConsoleParser {
* @see org.eclipse.cdt.make.internal.core.scannerconfig.IScannerInfoConsoleParser#shutdown() * @see org.eclipse.cdt.make.internal.core.scannerconfig.IScannerInfoConsoleParser#shutdown()
*/ */
public void shutdown() { public void shutdown() {
Map scannerInfo = new HashMap(); Map<ScannerInfoTypes, List<String>> scannerInfo = new HashMap<ScannerInfoTypes, List<String>>();
scannerInfo.put(ScannerInfoTypes.INCLUDE_PATHS, includes); scannerInfo.put(ScannerInfoTypes.INCLUDE_PATHS, includes);
scannerInfo.put(ScannerInfoTypes.SYMBOL_DEFINITIONS, symbols); scannerInfo.put(ScannerInfoTypes.SYMBOL_DEFINITIONS, symbols);
if (fCollector != null) fCollector.contributeToScannerConfig(fProject, scannerInfo); if (fCollector != null) {
if (fCollector instanceof PerProjectSICollector) {
((PerProjectSICollector) fCollector).contributeToScannerConfig(fProject, scannerInfo, true);
} else {
fCollector.contributeToScannerConfig(fProject, scannerInfo);
}
}
TraceUtil.outputTrace("Scanner info from \'specs\' file", //$NON-NLS-1$ TraceUtil.outputTrace("Scanner info from \'specs\' file", //$NON-NLS-1$
"Include paths", includes, new ArrayList(), "Defined symbols", symbols); //$NON-NLS-1$ //$NON-NLS-2$); "Include paths", includes, Collections.emptyList(), "Defined symbols", symbols); //$NON-NLS-1$ //$NON-NLS-2$);
} }
} }

View file

@ -6,15 +6,15 @@
* http://www.eclipse.org/legal/epl-v10.html * http://www.eclipse.org/legal/epl-v10.html
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Anton Leherbauer (Wind River Systems) * Anton Leherbauer (Wind River Systems)
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.make.internal.core.scannerconfig2; package org.eclipse.cdt.make.internal.core.scannerconfig2;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -65,24 +65,25 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
private IProject project; private IProject project;
private InfoContext context; private InfoContext context;
private boolean isBuiltinConfig= false;
private Map discoveredSI; private Map<ScannerInfoTypes, List<String>> discoveredSI;
// private List discoveredIncludes; // private List discoveredIncludes;
// private List discoveredSymbols; // private List discoveredSymbols;
// private List discoveredTSO; // target specific options // private List discoveredTSO; // target specific options
// cumulative values // cumulative values
private List sumDiscoveredIncludes; private List<String> sumDiscoveredIncludes;
private Map sumDiscoveredSymbols; private Map<?, ?> sumDiscoveredSymbols;
private boolean scPersisted = false; private boolean scPersisted = false;
public PerProjectSICollector() { public PerProjectSICollector() {
discoveredSI = new HashMap(); discoveredSI = new HashMap<ScannerInfoTypes, List<String>>();
// discoveredIncludes = new ArrayList(); // discoveredIncludes = new ArrayList();
// discoveredSymbols = new ArrayList(); // discoveredSymbols = new ArrayList();
// discoveredTSO = new ArrayList(); // discoveredTSO = new ArrayList();
// //
sumDiscoveredIncludes = new ArrayList(); sumDiscoveredIncludes = new ArrayList<String>();
sumDiscoveredSymbols = new LinkedHashMap(); sumDiscoveredSymbols = new LinkedHashMap<Object, Object>();
} }
/* (non-Javadoc) /* (non-Javadoc)
@ -93,6 +94,16 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
this.context = new InfoContext(project); this.context = new InfoContext(project);
} }
public synchronized void contributeToScannerConfig(Object resource, Map scannerInfo, boolean isBuiltinConfig) {
this.isBuiltinConfig= isBuiltinConfig;
try {
contributeToScannerConfig(resource, scannerInfo);
}
finally {
this.isBuiltinConfig= false;
}
}
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector#contributeToScannerConfig(java.lang.Object, java.util.Map) * @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector#contributeToScannerConfig(java.lang.Object, java.util.Map)
*/ */
@ -127,22 +138,18 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
(project.hasNature(CProjectNature.C_NATURE_ID) || (project.hasNature(CProjectNature.C_NATURE_ID) ||
project.hasNature(CCProjectNature.CC_NATURE_ID))) { project.hasNature(CCProjectNature.CC_NATURE_ID))) {
for (Iterator I = scannerInfo.keySet().iterator(); I.hasNext(); ) { for (Object name : scannerInfo.keySet()) {
ScannerInfoTypes siType = (ScannerInfoTypes) I.next(); ScannerInfoTypes siType = (ScannerInfoTypes) name;
List delta = (List) scannerInfo.get(siType); List<String> delta = (List<String>) scannerInfo.get(siType);
List discovered = (List) discoveredSI.get(siType); List<String> discovered = discoveredSI.get(siType);
if (discovered == null) { if (discovered == null) {
discovered = new ArrayList(delta); discovered = new ArrayList<String>(delta);
discoveredSI.put(siType, discovered); discoveredSI.put(siType, discovered);
} }
else { else {
if (siType.equals(ScannerInfoTypes.INCLUDE_PATHS)) { final boolean addSorted= !isBuiltinConfig && siType.equals(ScannerInfoTypes.INCLUDE_PATHS);
contribute(discovered, delta, true); contribute(discovered, delta, addSorted);
}
else {
contribute(discovered, delta, false);
}
} }
} }
} }
@ -158,7 +165,7 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
* @param ordered - to preserve order or append at the end * @param ordered - to preserve order or append at the end
* @return true if there is a change in discovered symbols | includes | targetSpecificOptions * @return true if there is a change in discovered symbols | includes | targetSpecificOptions
*/ */
private boolean contribute(List discovered, List delta, boolean ordered) { private boolean contribute(List<String> discovered, List<String> delta, boolean ordered) {
if (delta == null || delta.isEmpty()) if (delta == null || delta.isEmpty())
return false; return false;
return addItemsWithOrder(discovered, delta, ordered); return addItemsWithOrder(discovered, delta, ordered);
@ -172,16 +179,22 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
* @param ordered - to preserve order or append at the end * @param ordered - to preserve order or append at the end
* @return boolean - true if added * @return boolean - true if added
*/ */
private boolean addItemsWithOrder(List sumIncludes, List includes, boolean ordered) { private boolean addItemsWithOrder(List<String> sumIncludes, List<String> includes, boolean ordered) {
if (includes.isEmpty())
return false;
boolean addedIncludes = false; boolean addedIncludes = false;
int prev = sumIncludes.size() - 1; // index of previously added/found contribution in already discovered list int insertionPoint= ordered ? 0 : sumIncludes.size();
for (Iterator i = includes.iterator(); i.hasNext(); ) { for (String item : includes) {
String item = (String) i.next(); int pos= sumIncludes.indexOf(item);
if (!sumIncludes.contains(item)) { if (pos >= 0) {
sumIncludes.add(prev + 1, item); if (ordered) {
insertionPoint= pos+1;
}
} else {
sumIncludes.add(insertionPoint++, item);
addedIncludes = true; addedIncludes = true;
} }
prev = ordered ? sumIncludes.indexOf(item) : sumIncludes.size() - 1;
} }
return addedIncludes; return addedIncludes;
} }
@ -205,7 +218,7 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
monitor.subTask(MakeMessages.getString("ScannerInfoCollector.Updating") + project.getName()); //$NON-NLS-1$ monitor.subTask(MakeMessages.getString("ScannerInfoCollector.Updating") + project.getName()); //$NON-NLS-1$
try { try {
// update scanner configuration // update scanner configuration
List resourceDelta = new ArrayList(1); List<IResource> resourceDelta = new ArrayList<IResource>(1);
resourceDelta.add(project); resourceDelta.add(project);
MakeCorePlugin.getDefault().getDiscoveryManager().updateDiscoveredInfo(context, pathInfo, context.isDefaultContext(), resourceDelta); MakeCorePlugin.getDefault().getDiscoveryManager().updateDiscoveredInfo(context, pathInfo, context.isDefaultContext(), resourceDelta);
monitor.worked(50); monitor.worked(50);
@ -241,7 +254,7 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
*/ */
private boolean includePathsNeedUpdate(IPerProjectDiscoveredPathInfo discPathInfo) { private boolean includePathsNeedUpdate(IPerProjectDiscoveredPathInfo discPathInfo) {
boolean addedIncludes = false; boolean addedIncludes = false;
List discoveredIncludes = (List) discoveredSI.get(ScannerInfoTypes.INCLUDE_PATHS); List<String> discoveredIncludes = discoveredSI.get(ScannerInfoTypes.INCLUDE_PATHS);
if (discoveredIncludes != null) { if (discoveredIncludes != null) {
// Step 1. Add discovered scanner config to the existing discovered scanner config // Step 1. Add discovered scanner config to the existing discovered scanner config
// add the includes from the latest discovery // add the includes from the latest discovery
@ -256,21 +269,20 @@ public class PerProjectSICollector implements IScannerInfoCollector3, 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(project, sumDiscoveredIncludes); List<String> finalSumIncludes = CygpathTranslator.translateIncludePaths(project, sumDiscoveredIncludes);
// Step 2. Get project's scanner config // Step 2. Get project's scanner config
LinkedHashMap persistedIncludes = discPathInfo.getIncludeMap(); LinkedHashMap<String, Boolean> persistedIncludes = discPathInfo.getIncludeMap();
// Step 3. Merge scanner config from steps 1 and 2 // Step 3. Merge scanner config from steps 1 and 2
// order is important, use list to preserve it // order is important, use list to preserve it
ArrayList persistedKeyList = new ArrayList(persistedIncludes.keySet()); ArrayList<String> persistedKeyList = new ArrayList<String>(persistedIncludes.keySet());
addedIncludes = addItemsWithOrder(persistedKeyList, finalSumIncludes, true); addedIncludes = addItemsWithOrder(persistedKeyList, finalSumIncludes, true);
LinkedHashMap newPersistedIncludes; LinkedHashMap<String, Boolean> newPersistedIncludes;
if (addedIncludes) { if (addedIncludes) {
newPersistedIncludes = new LinkedHashMap(persistedKeyList.size()); newPersistedIncludes = new LinkedHashMap<String, Boolean>(persistedKeyList.size());
for (Iterator i = persistedKeyList.iterator(); i.hasNext(); ) { for (String include : persistedKeyList) {
String include = (String) i.next();
if (persistedIncludes.containsKey(include)) { if (persistedIncludes.containsKey(include)) {
newPersistedIncludes.put(include, persistedIncludes.get(include)); newPersistedIncludes.put(include, persistedIncludes.get(include));
} }
@ -299,7 +311,7 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
*/ */
private boolean definedSymbolsNeedUpdate(IPerProjectDiscoveredPathInfo discPathInfo) { private boolean definedSymbolsNeedUpdate(IPerProjectDiscoveredPathInfo discPathInfo) {
boolean addedSymbols = false; boolean addedSymbols = false;
List discoveredSymbols = (List) discoveredSI.get(ScannerInfoTypes.SYMBOL_DEFINITIONS); List<?> discoveredSymbols = discoveredSI.get(ScannerInfoTypes.SYMBOL_DEFINITIONS);
if (discoveredSymbols != null) { if (discoveredSymbols != null) {
// Step 1. Add discovered scanner config to the existing discovered scanner config // Step 1. Add discovered scanner config to the existing discovered scanner config
// add the symbols from the latest discovery // add the symbols from the latest discovery
@ -309,10 +321,10 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
addedSymbols = ScannerConfigUtil.scAddSymbolsList2SymbolEntryMap(sumDiscoveredSymbols, discoveredSymbols, true); addedSymbols = ScannerConfigUtil.scAddSymbolsList2SymbolEntryMap(sumDiscoveredSymbols, discoveredSymbols, true);
// Step 2. Get project's scanner config // Step 2. Get project's scanner config
LinkedHashMap persistedSymbols = discPathInfo.getSymbolMap(); LinkedHashMap<?, ?> persistedSymbols = discPathInfo.getSymbolMap();
// Step 3. Merge scanner config from steps 1 and 2 // Step 3. Merge scanner config from steps 1 and 2
LinkedHashMap candidateSymbols = new LinkedHashMap(persistedSymbols); LinkedHashMap<?, ?> candidateSymbols = new LinkedHashMap<Object, Object>(persistedSymbols);
addedSymbols |= ScannerConfigUtil.scAddSymbolEntryMap2SymbolEntryMap(candidateSymbols, sumDiscoveredSymbols); addedSymbols |= ScannerConfigUtil.scAddSymbolEntryMap2SymbolEntryMap(candidateSymbols, sumDiscoveredSymbols);
// Step 4. Set resulting scanner config // Step 4. Set resulting scanner config
@ -324,8 +336,8 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector#getCollectedScannerInfo(java.lang.Object, org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes) * @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector#getCollectedScannerInfo(java.lang.Object, org.eclipse.cdt.make.core.scannerconfig.ScannerInfoTypes)
*/ */
public List getCollectedScannerInfo(Object resource, ScannerInfoTypes type) { public List<?> getCollectedScannerInfo(Object resource, ScannerInfoTypes type) {
List rv = null; List<?> rv = null;
// check the resource // check the resource
String errorMessage = null; String errorMessage = null;
if (resource == null) { if (resource == null) {
@ -345,7 +357,7 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
TraceUtil.outputError("PerProjectSICollector.getCollectedScannerInfo : ", errorMessage); //$NON-NLS-1$ TraceUtil.outputError("PerProjectSICollector.getCollectedScannerInfo : ", errorMessage); //$NON-NLS-1$
} }
else if (project.equals(((IResource)resource).getProject())) { else if (project.equals(((IResource)resource).getProject())) {
rv = (List) discoveredSI.get(type); rv = discoveredSI.get(type);
} }
return rv; return rv;
} }
@ -353,15 +365,15 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2#getDefinedSymbols() * @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2#getDefinedSymbols()
*/ */
public Map getDefinedSymbols() { public Map<?, ?> getDefinedSymbols() {
Map definedSymbols = ScannerConfigUtil.scSymbolEntryMap2Map(sumDiscoveredSymbols); Map<?, ?> definedSymbols = ScannerConfigUtil.scSymbolEntryMap2Map(sumDiscoveredSymbols);
return definedSymbols; return definedSymbols;
} }
/* (non-Javadoc) /* (non-Javadoc)
* @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2#getIncludePaths() * @see org.eclipse.cdt.make.core.scannerconfig.IScannerInfoCollector2#getIncludePaths()
*/ */
public List getIncludePaths() { public List<String> getIncludePaths() {
return sumDiscoveredIncludes; return sumDiscoveredIncludes;
} }
@ -490,10 +502,10 @@ public class PerProjectSICollector implements IScannerInfoCollector3, IScannerIn
ICProject cProject = CoreModel.getDefault().create(project); ICProject cProject = CoreModel.getDefault().create(project);
if (cProject != null) { if (cProject != null) {
IPathEntry[] entries = cProject.getRawPathEntries(); IPathEntry[] entries = cProject.getRawPathEntries();
List newEntries = new ArrayList(Arrays.asList(entries)); List<IPathEntry> newEntries = new ArrayList<IPathEntry>(Arrays.asList(entries));
if (!newEntries.contains(container)) { if (!newEntries.contains(container)) {
newEntries.add(container); newEntries.add(container);
cProject.setRawPathEntries((IPathEntry[])newEntries.toArray(new IPathEntry[newEntries.size()]), monitor); cProject.setRawPathEntries(newEntries.toArray(new IPathEntry[newEntries.size()]), monitor);
} }
} }
// create a new discovered scanner config store // create a new discovered scanner config store

View file

@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* IBM - Initial API and implementation * IBM - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.dom.parser.cpp; package org.eclipse.cdt.internal.core.dom.parser.cpp;
@ -115,9 +116,10 @@ public class CPPClassTemplatePartialSpecialization extends CPPClassTemplate impl
} catch (DOMException e) { } catch (DOMException e) {
return ObjectMap.EMPTY_MAP; return ObjectMap.EMPTY_MAP;
} }
// lengths should be equal, be defensive
ObjectMap map = new ObjectMap(params.length); final int len= Math.min(params.length, arg.length);
for (int i = 0; i < params.length; i++) { ObjectMap map = new ObjectMap(len);
for (int i = 0; i < len; i++) {
map.put(params[i], arg[i]); map.put(params[i], arg[i]);
} }