From 582a7c10d543b637941152af86408eef06ee3a18 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Mon, 1 May 2017 23:26:21 -0400 Subject: [PATCH] Bug 515990 - Fix constant reindexing in CMake projects There were issues with how the Core Build calculated whether reindexing was required due to compiler settings changes. Also if a source file was built more than once in a CMake build, it ended up always triggering a reindexing since the second instance looked like a settings change. We now only use the last compile command for a file. Change-Id: Icf2922e527ae20e0c3b0dae898d981d334013109 --- .../core/internal/CMakeBuildConfiguration.java | 5 +++++ .../cdt/core/build/CBuildConfiguration.java | 7 +++++-- .../eclipse/cdt/core/build/ScannerInfoCache.java | 14 +++++++++++++- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java index be3b7aa1b16..c56396acf50 100644 --- a/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java +++ b/build/org.eclipse.cdt.cmake.core/src/org/eclipse/cdt/cmake/core/internal/CMakeBuildConfiguration.java @@ -15,6 +15,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -231,7 +232,11 @@ public class CMakeBuildConfiguration extends CBuildConfiguration { try (FileReader reader = new FileReader(commandsFile.toFile())) { Gson gson = new Gson(); CompileCommand[] commands = gson.fromJson(reader, CompileCommand[].class); + Map dedupedCmds = new HashMap<>(); for (CompileCommand command : commands) { + dedupedCmds.put(command.getFile(), command); + } + for (CompileCommand command : dedupedCmds.values()) { processLine(command.getCommand()); } shutdown(); diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java index c3daf8b8fb2..6f6a1fb38b0 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/CBuildConfiguration.java @@ -633,15 +633,18 @@ public abstract class CBuildConfiguration extends PlatformObject for (IResource resource : resources) { loadScannerInfoCache(); if (scannerInfoCache.hasCommand(commandStrings)) { - scannerInfoCache.addResource(commandStrings, resource); + if (!scannerInfoCache.hasResource(commandStrings, resource)) { + scannerInfoCache.addResource(commandStrings, resource); + infoChanged = true; + } } else { Path commandPath = findCommand(command.get(0)); command.set(0, commandPath.toString()); IExtendedScannerInfo info = getToolChain().getScannerInfo(getBuildConfiguration(), command, null, resource, getBuildDirectoryURI()); scannerInfoCache.addScannerInfo(commandStrings, info, resource); + infoChanged = true; } - infoChanged = true; } return true; } else { diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ScannerInfoCache.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ScannerInfoCache.java index 81f9ee74b7c..d055ce85f8b 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ScannerInfoCache.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/build/ScannerInfoCache.java @@ -77,7 +77,7 @@ public class ScannerInfoCache { oldCommand.resourcePaths.remove(resourcePath); if (oldCommand.resourcePaths.isEmpty()) { // unused, remove - commandMap.remove(commandStrings); + commandMap.remove(oldCommand.command); commands.remove(oldCommand); resourceMap.remove(resourcePath); } @@ -101,6 +101,18 @@ public class ScannerInfoCache { } } + /** + * @since 6.3 + */ + public boolean hasResource(List commandStrings, IResource resource) { + String resourcePath = resource.getLocation().toOSString(); + Command command = commandMap.get(commandStrings); + if (command == null) { + return false; + } + return command.resourcePaths.contains(resourcePath); + } + public void addResource(List commandStrings, IResource resource) { String resourcePath = resource.getLocation().toOSString(); Command command = commandMap.get(commandStrings);