Index: clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h =================================================================== --- clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h +++ clang/include/clang/Tooling/DependencyScanning/ModuleDepCollector.h @@ -119,11 +119,9 @@ // the primary TU. bool ImportedByMainFile = false; - /// Compiler invocation that can be used to build this module (without paths). - CompilerInvocation BuildInvocation; - - /// Gets the canonical command line suitable for passing to clang. - std::vector getCanonicalCommandLine() const; + /// Compiler invocation that can be used to build this module. Does not + /// include argv[0]. + std::vector BuildArguments; }; class ModuleDepCollector; @@ -238,7 +236,7 @@ llvm::function_ref Optimize) const; /// Add paths that require looking up outputs to the given dependencies. - void addOutputPaths(ModuleDeps &Deps); + void addOutputPaths(CompilerInvocation &CI, ModuleDeps &Deps); }; } // end namespace dependencies Index: clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp =================================================================== --- clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -52,9 +52,8 @@ return Result; } -void ModuleDepCollector::addOutputPaths(ModuleDeps &Deps) { - CompilerInvocation &CI = Deps.BuildInvocation; - +void ModuleDepCollector::addOutputPaths(CompilerInvocation &CI, + ModuleDeps &Deps) { // These are technically *inputs* to the compilation, but we populate them // here in order to make \c getModuleContextHash() independent of // \c lookupModuleOutput(). @@ -170,11 +169,8 @@ return CI; } -std::vector ModuleDeps::getCanonicalCommandLine() const { - return BuildInvocation.getCC1CommandLine(); -} - static std::string getModuleContextHash(const ModuleDeps &MD, + const CompilerInvocation &CI, bool EagerLoadModules) { llvm::HashBuilder, llvm::support::endianness::native> @@ -188,7 +184,7 @@ // Hash the BuildInvocation without any input files. SmallVector DummyArgs; - MD.BuildInvocation.generateCC1CommandLine(DummyArgs, [&](const Twine &Arg) { + CI.generateCC1CommandLine(DummyArgs, [&](const Twine &Arg) { Scratch.clear(); StringRef Str = Arg.toStringRef(Scratch); HashBuilder.add(Str); @@ -397,7 +393,7 @@ llvm::DenseSet ProcessedModules; addAllAffectingModules(M, MD, ProcessedModules); - MD.BuildInvocation = MDC.makeInvocationForModuleBuildWithoutOutputs( + CompilerInvocation CI = MDC.makeInvocationForModuleBuildWithoutOutputs( MD, [&](CompilerInvocation &BuildInvocation) { if (MDC.OptimizeArgs) optimizeHeaderSearchOpts(BuildInvocation.getHeaderSearchOpts(), @@ -405,9 +401,12 @@ }); // Compute the context hash from the inputs. Requires dependencies. - MD.ID.ContextHash = getModuleContextHash(MD, MDC.EagerLoadModules); + MD.ID.ContextHash = getModuleContextHash(MD, CI, MDC.EagerLoadModules); // Finish the compiler invocation. Requires dependencies and the context hash. - MDC.addOutputPaths(MD); + MDC.addOutputPaths(CI, MD); + + MD.BuildArguments = CI.getCC1CommandLine(); + return MD.ID; } Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp =================================================================== --- clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ clang/tools/clang-scan-deps/ClangScanDeps.cpp @@ -304,7 +304,7 @@ {"file-deps", toJSONSorted(MD.FileDeps)}, {"clang-module-deps", toJSONSorted(MD.ClangModuleDeps)}, {"clang-modulemap-file", MD.ClangModuleMapFile}, - {"command-line", MD.getCanonicalCommandLine()}, + {"command-line", MD.BuildArguments}, }; OutModules.push_back(std::move(O)); }