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

View file

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