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);