Skip to content

Commit d448a14

Browse files
committed
Fix for the compiler path in compile_commands.json file
Compiler path was wrongly created when anything was set on the "Prefix" option from "Cross Settings". The code needs to check if anything is set there before creating the default path for the compiler.
1 parent 04105c2 commit d448a14

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/jsoncdb/generator/CompilationDatabaseGenerator.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public final class CompilationDatabaseGenerator {
7070
* Checked on each build
7171
* Used before we look up the environment
7272
*/
73-
private Map<ITool, String> toolMap = new HashMap<>();
73+
private Map<String, String> toolMap = new HashMap<>();
7474
private IProject project;
7575
private IConfiguration configuration;
7676
private ICSourceEntry[] srcEntries;
@@ -229,10 +229,10 @@ private List<CompilationDatabaseInformation> populateObjList(IProject project, I
229229
outputLocation + "", inputStrings, sourceLocation, outputLocation); //$NON-NLS-1$
230230

231231
IBuildMacroProvider provider = ManagedBuildManager.getBuildMacroProvider();
232-
String compilerName = CompilationDatabaseGenerator.getCompilerName(tool);
233232
String commandLine = cmdLInfo.getCommandLine();
233+
String compilerName = CompilationDatabaseGenerator.getCompilerName(commandLine);
234234
commandLine = commandLine.replace(compilerName, "").trim(); //$NON-NLS-1$
235-
String compilerPath = findCompilerInPath(tool, config);
235+
String compilerPath = findCompilerInPath(tool, config, compilerName);
236236
String resolvedOptionFileContents;
237237
if (compilerPath != null && !compilerPath.isEmpty()) {
238238
resolvedOptionFileContents = provider.resolveValueToMakefileFormat(compilerPath + " " + commandLine, //$NON-NLS-1$
@@ -438,15 +438,15 @@ public boolean visit(IResourceProxy proxy) throws CoreException {
438438

439439
}
440440

441-
private String findCompilerInPath(ITool tool, IConfiguration config) {
442-
if (toolMap.containsKey(tool)) {
443-
return "\"" + toolMap.get(tool) + "\""; //$NON-NLS-1$//$NON-NLS-2$
441+
private String findCompilerInPath(ITool tool, IConfiguration config, String compilerName) {
442+
String cacheKey = tool + " " + compilerName; //$NON-NLS-1$
443+
if (toolMap.containsKey(cacheKey)) {
444+
return "\"" + toolMap.get(cacheKey) + "\""; //$NON-NLS-1$//$NON-NLS-2$
444445
}
445-
String compilerName = CompilationDatabaseGenerator.getCompilerName(tool);
446446
File pathToCompiler = new File(compilerName);
447447

448448
if (pathToCompiler.isAbsolute()) {
449-
toolMap.put(tool, compilerName);
449+
toolMap.put(cacheKey, compilerName);
450450
return "\"" + compilerName + "\""; //$NON-NLS-1$ //$NON-NLS-2$
451451
}
452452
ICConfigurationDescription cfg = ManagedBuildManager.getDescriptionForConfiguration(config);
@@ -458,7 +458,7 @@ private String findCompilerInPath(ITool tool, IConfiguration config) {
458458
IPath resolvedPath = PathUtil.findProgramLocation(compilerName, variable.getValue());
459459
if (resolvedPath != null) {
460460
String path = resolvedPath.toString();
461-
toolMap.put(tool, path);
461+
toolMap.put(cacheKey, path);
462462
return "\"" + path + "\""; //$NON-NLS-1$ //$NON-NLS-2$
463463
} else {
464464
return null; // Only one PATH so can exit early
@@ -469,9 +469,8 @@ private String findCompilerInPath(ITool tool, IConfiguration config) {
469469
return null;
470470
}
471471

472-
private static String getCompilerName(ITool tool) {
473-
String compilerCommand = tool.getToolCommand();
474-
String[] arguments = CommandLineUtil.argumentsToArray(compilerCommand);
472+
private static String getCompilerName(String commandLine) {
473+
String[] arguments = CommandLineUtil.argumentsToArray(commandLine);
475474
if (arguments.length == 0) {
476475
return ""; //$NON-NLS-1$
477476
}

0 commit comments

Comments
 (0)