mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Indexing source files when multiple toolchains are used.
This change solves the indexing of C/C++ files when multiple toolchains are used in a single Makefile. This is for the use case in which one (Linux) gcc compiler plus one or more custom embedded C compilers (all producing ELF format binaries) are used. To get proper indexing we need to know for each resource which toolchain was used. The sub build configuration (via extension point org.eclipse.cdt.core.buildConfigProvider) extends StandardBuildConfiguration.java, and overrides method IToolChain (List<String> commandgetToolChain). tcMap is filled with a map of toolchains per resource. The primary toolchain keeps pointing to the gcc toolchain.
This commit is contained in:
parent
171e7e3047
commit
8c9faa1a50
1 changed files with 59 additions and 13 deletions
|
@ -106,6 +106,8 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
|
||||||
|
|
||||||
private static final List<String> DEFAULT_COMMAND = new ArrayList<>(0);
|
private static final List<String> DEFAULT_COMMAND = new ArrayList<>(0);
|
||||||
|
|
||||||
|
private final Map<IResource, IToolChain> tcMap = new HashMap<IResource, IToolChain>();
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final IBuildConfiguration config;
|
private final IBuildConfiguration config;
|
||||||
private final IToolChain toolChain;
|
private final IToolChain toolChain;
|
||||||
|
@ -310,6 +312,31 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
|
||||||
return toolChain;
|
return toolChain;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the toolchain based on the compiler found in the command line.
|
||||||
|
* Sub-classes can override this method to set their own method for
|
||||||
|
* getting the toolchain.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected IToolChain getToolChain(List<String> command) throws CoreException {
|
||||||
|
return getToolChain();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the toolchain that was used to compile this resource.
|
||||||
|
*
|
||||||
|
* @param resource
|
||||||
|
* @return
|
||||||
|
* @throws CoreException
|
||||||
|
*/
|
||||||
|
private IToolChain getToolChain(IResource resource) throws CoreException {
|
||||||
|
IToolChain tc = tcMap.get(resource);
|
||||||
|
if (tc == null)
|
||||||
|
return getToolChain();
|
||||||
|
else
|
||||||
|
return tc;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IEnvironmentVariable getVariable(String name) {
|
public IEnvironmentVariable getVariable(String name) {
|
||||||
IEnvironmentVariable[] vars = getVariables();
|
IEnvironmentVariable[] vars = getVariables();
|
||||||
|
@ -665,7 +692,8 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
|
||||||
if (celement instanceof ITranslationUnit) {
|
if (celement instanceof ITranslationUnit) {
|
||||||
try {
|
try {
|
||||||
ITranslationUnit tu = (ITranslationUnit) celement;
|
ITranslationUnit tu = (ITranslationUnit) celement;
|
||||||
info = getToolChain().getDefaultScannerInfo(getBuildConfiguration(), getBaseScannerInfo(resource),
|
IToolChain tc = getToolChain(resource);
|
||||||
|
info = tc.getDefaultScannerInfo(getBuildConfiguration(), getBaseScannerInfo(resource),
|
||||||
tu.getLanguage(), getBuildDirectoryURI());
|
tu.getLanguage(), getBuildDirectoryURI());
|
||||||
synchronized (scannerInfoLock) {
|
synchronized (scannerInfoLock) {
|
||||||
scannerInfoCache.addScannerInfo(DEFAULT_COMMAND, info, resource);
|
scannerInfoCache.addScannerInfo(DEFAULT_COMMAND, info, resource);
|
||||||
|
@ -736,7 +764,15 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
|
||||||
List<String> command = stripArgs(line);
|
List<String> command = stripArgs(line);
|
||||||
|
|
||||||
// Make sure it's a compile command
|
// Make sure it's a compile command
|
||||||
String[] compileCommands = toolChain.getCompileCommands();
|
String[] compileCommands;
|
||||||
|
IToolChain tc;
|
||||||
|
try {
|
||||||
|
tc = getToolChain(command);
|
||||||
|
compileCommands = tc.getCompileCommands();
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
loop: for (String arg : command) {
|
loop: for (String arg : command) {
|
||||||
// TODO we should really ask the toolchain, not all args start with '-'
|
// TODO we should really ask the toolchain, not all args start with '-'
|
||||||
|
@ -769,18 +805,19 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IResource[] resources = toolChain.getResourcesFromCommand(command, getBuildDirectoryURI());
|
IResource[] resources = tc.getResourcesFromCommand(command, getBuildDirectoryURI());
|
||||||
if (resources != null && resources.length > 0) {
|
if (resources != null && resources.length > 0) {
|
||||||
List<String> commandStrings = toolChain.stripCommand(command, resources);
|
List<String> commandStrings = tc.stripCommand(command, resources);
|
||||||
|
|
||||||
boolean needScannerRefresh = false;
|
boolean needScannerRefresh = false;
|
||||||
|
|
||||||
String needRefresh = toolChain.getProperty(NEED_REFRESH);
|
String needRefresh = tc.getProperty(NEED_REFRESH);
|
||||||
if ("true".equals(needRefresh)) { //$NON-NLS-1$
|
if ("true".equals(needRefresh)) { //$NON-NLS-1$
|
||||||
needScannerRefresh = true;
|
needScannerRefresh = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (IResource resource : resources) {
|
for (IResource resource : resources) {
|
||||||
|
tcMap.put(resource, tc);
|
||||||
loadScannerInfoCache();
|
loadScannerInfoCache();
|
||||||
boolean hasCommand = true;
|
boolean hasCommand = true;
|
||||||
synchronized (scannerInfoLock) {
|
synchronized (scannerInfoLock) {
|
||||||
|
@ -801,8 +838,8 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
|
||||||
Path commandPath = findCommand(command.get(0));
|
Path commandPath = findCommand(command.get(0));
|
||||||
if (commandPath != null) {
|
if (commandPath != null) {
|
||||||
command.set(0, commandPath.toString());
|
command.set(0, commandPath.toString());
|
||||||
IExtendedScannerInfo info = getToolChain().getScannerInfo(getBuildConfiguration(), command,
|
IExtendedScannerInfo info = tc.getScannerInfo(getBuildConfiguration(), command, null,
|
||||||
null, resource, getBuildDirectoryURI());
|
resource, getBuildDirectoryURI());
|
||||||
synchronized (scannerInfoLock) {
|
synchronized (scannerInfoLock) {
|
||||||
scannerInfoCache.addScannerInfo(commandStrings, info, resource);
|
scannerInfoCache.addScannerInfo(commandStrings, info, resource);
|
||||||
infoChanged = true;
|
infoChanged = true;
|
||||||
|
@ -864,7 +901,15 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
|
||||||
List<String> command = stripArgs(line);
|
List<String> command = stripArgs(line);
|
||||||
|
|
||||||
// Make sure it's a compile command
|
// Make sure it's a compile command
|
||||||
String[] compileCommands = toolChain.getCompileCommands();
|
String[] compileCommands;
|
||||||
|
IToolChain tc;
|
||||||
|
try {
|
||||||
|
tc = getToolChain(command);
|
||||||
|
compileCommands = tc.getCompileCommands();
|
||||||
|
} catch (CoreException e) {
|
||||||
|
CCorePlugin.log(e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
loop: for (String arg : command) {
|
loop: for (String arg : command) {
|
||||||
// TODO we should really ask the toolchain, not all args start with '-'
|
// TODO we should really ask the toolchain, not all args start with '-'
|
||||||
|
@ -897,18 +942,19 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IResource[] resources = toolChain.getResourcesFromCommand(command, getBuildDirectoryURI());
|
IResource[] resources = tc.getResourcesFromCommand(command, getBuildDirectoryURI());
|
||||||
if (resources != null && resources.length > 0) {
|
if (resources != null && resources.length > 0) {
|
||||||
List<String> commandStrings = toolChain.stripCommand(command, resources);
|
List<String> commandStrings = tc.stripCommand(command, resources);
|
||||||
|
|
||||||
boolean needScannerRefresh = false;
|
boolean needScannerRefresh = false;
|
||||||
|
|
||||||
String needRefresh = toolChain.getProperty(NEED_REFRESH);
|
String needRefresh = tc.getProperty(NEED_REFRESH);
|
||||||
if ("true".equals(needRefresh)) { //$NON-NLS-1$
|
if ("true".equals(needRefresh)) { //$NON-NLS-1$
|
||||||
needScannerRefresh = true;
|
needScannerRefresh = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (IResource resource : resources) {
|
for (IResource resource : resources) {
|
||||||
|
tcMap.put(resource, tc);
|
||||||
loadScannerInfoCache();
|
loadScannerInfoCache();
|
||||||
boolean hasCommand = true;
|
boolean hasCommand = true;
|
||||||
synchronized (scannerInfoLock) {
|
synchronized (scannerInfoLock) {
|
||||||
|
@ -930,8 +976,8 @@ public abstract class CBuildConfiguration extends PlatformObject implements ICBu
|
||||||
if (commandPath != null) {
|
if (commandPath != null) {
|
||||||
command.set(0, commandPath.toString());
|
command.set(0, commandPath.toString());
|
||||||
Job job = new ScannerInfoJob(
|
Job job = new ScannerInfoJob(
|
||||||
String.format(Messages.CBuildConfiguration_RunningScannerInfo, resource),
|
String.format(Messages.CBuildConfiguration_RunningScannerInfo, resource), tc,
|
||||||
getToolChain(), command, resource, getBuildDirectoryURI(), commandStrings);
|
command, resource, getBuildDirectoryURI(), commandStrings);
|
||||||
job.schedule();
|
job.schedule();
|
||||||
jobsArray.add(job);
|
jobsArray.add(job);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue