Author: Ben Langmuir Date: 2022-06-15T13:29:47-07:00 New Revision: 509223da61145c3eb982751cba9ab6ddf0f48e9d
URL: https://github.com/llvm/llvm-project/commit/509223da61145c3eb982751cba9ab6ddf0f48e9d DIFF: https://github.com/llvm/llvm-project/commit/509223da61145c3eb982751cba9ab6ddf0f48e9d.diff LOG: [clang][deps] Further canonicalize implicit modules options in dep scan Disable or canonicalize compiler options that are not relevant in explicit module builds, similar to what we already did for the modules cache path. This reduces uninteresting differences between command-lines, which is particularly useful if there is a tool that can cache the compilations. Differential Revision: https://reviews.llvm.org/D127883 Added: Modified: clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template clang/test/ClangScanDeps/removed-args.c Removed: ################################################################################ diff --git a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp index 5041a8eb6e597..26c2b2b2f3948 100644 --- a/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp +++ b/clang/lib/Tooling/DependencyScanning/DependencyScanningTool.cpp @@ -32,14 +32,17 @@ FullDependencies::getCommandLineWithoutModulePaths() const { for (const PrebuiltModuleDep &PMD : PrebuiltModuleDeps) Args.push_back("-fmodule-file=" + PMD.PCMFile); - // This argument is unused in explicit compiles. - llvm::erase_if(Args, [](const std::string &Arg) { - return Arg.find("-fmodules-cache-path=") == 0; + // These arguments are unused in explicit compiles. + llvm::erase_if(Args, [](StringRef Arg) { + if (Arg.consume_front("-fmodules-")) { + return Arg.startswith("cache-path=") || + Arg.startswith("prune-interval=") || + Arg.startswith("prune-after=") || + Arg == "validate-once-per-build-session"; + } + return Arg.startswith("-fbuild-session-file="); }); - // TODO: Filter out the remaining implicit modules leftovers - // (e.g. "-fmodules-prune-interval=" or "-fmodules-prune-after="). - return Args; } diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp index 6c7fdbc3944a6..8fad65c14e376 100644 --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -61,9 +61,17 @@ CompilerInvocation ModuleDepCollector::makeInvocationForModuleBuildWithoutPaths( CI.getLangOpts()->ModuleName = Deps.ID.ModuleName; CI.getFrontendOpts().IsSystemModule = Deps.IsSystem; + // Disable implicit modules and canonicalize options that are only used by + // implicit modules. CI.getLangOpts()->ImplicitModules = false; CI.getHeaderSearchOpts().ImplicitModuleMaps = false; CI.getHeaderSearchOpts().ModuleCachePath.clear(); + CI.getHeaderSearchOpts().ModulesValidateOncePerBuildSession = false; + CI.getHeaderSearchOpts().BuildSessionTimestamp = 0; + // The specific values we canonicalize to for pruning don't affect behaviour, + /// so use the default values so they will be dropped from the command-line. + CI.getHeaderSearchOpts().ModuleCachePruneInterval = 7 * 24 * 60 * 60; + CI.getHeaderSearchOpts().ModuleCachePruneAfter = 31 * 24 * 60 * 60; // Report the prebuilt modules this module uses. for (const auto &PrebuiltModule : Deps.PrebuiltModuleDeps) diff --git a/clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template b/clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template index 17337c579099d..f92e7884e1786 100644 --- a/clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template +++ b/clang/test/ClangScanDeps/Inputs/removed-args/cdb.json.template @@ -1,7 +1,7 @@ [ { "directory": "DIR", - "command": "clang -fsyntax-only DIR/tu.c -fmodules -fimplicit-module-maps -fmodules-cache-path=DIR/cache -include DIR/header.h -grecord-command-line -o DIR/tu.o", + "command": "clang -fsyntax-only DIR/tu.c -fmodules -fimplicit-module-maps -fmodules-validate-once-per-build-session -fbuild-session-file=DIR/build-session -fmodules-prune-interval=123 -fmodules-prune-after=123 -fmodules-cache-path=DIR/cache -include DIR/header.h -grecord-command-line -o DIR/tu.o", "file": "DIR/tu.c" } ] diff --git a/clang/test/ClangScanDeps/removed-args.c b/clang/test/ClangScanDeps/removed-args.c index 2867c669134a5..8c07ca8d1f7e9 100644 --- a/clang/test/ClangScanDeps/removed-args.c +++ b/clang/test/ClangScanDeps/removed-args.c @@ -2,10 +2,13 @@ // compatible with the semantics of modules or are likely to diff er between // identical modules discovered from diff erent translation units. This test // checks such arguments are removed from the command-lines: '-include', -// '-dwarf-debug-flag' and '-main-file-name'. +// '-dwarf-debug-flag' and '-main-file-name'. Similarly, several arguments +// such as '-fmodules-cache-path=' are only relevant for implicit modules, and +// are removed to better-canonicalize the compilation. // RUN: rm -rf %t && mkdir %t // RUN: cp %S/Inputs/removed-args/* %t +// RUN: touch %t/build-session // RUN: sed "s|DIR|%/t|g" %S/Inputs/removed-args/cdb.json.template > %t/cdb.json // RUN: clang-scan-deps -compilation-database %t/cdb.json -format experimental-full > %t/result.json @@ -21,6 +24,11 @@ // CHECK-NOT: "-dwarf-debug-flags" // CHECK-NOT: "-main-file-name" // CHECK-NOT: "-include" +// CHECK-NOT: "-fmodules-cache-path= +// CHECK-NOT: "-fmodules-validate-once-per-build-session" +// CHECK-NOT: "-fbuild-session-timestamp= +// CHECK-NOT: "-fmodules-prune-interval= +// CHECK-NOT: "-fmodules-prune-after= // CHECK: ], // CHECK-NEXT: "context-hash": "[[HASH_MOD_HEADER:.*]]", // CHECK-NEXT: "file-deps": [ @@ -34,7 +42,14 @@ // CHECK-NEXT: "clang-modulemap-file": "[[PREFIX]]/module.modulemap", // CHECK-NEXT: "command-line": [ // CHECK-NEXT: "-cc1" +// CHECK-NOT: "-dwarf-debug-flags" +// CHECK-NOT: "-main-file-name" // CHECK-NOT: "-include" +// CHECK-NOT: "-fmodules-cache-path= +// CHECK-NOT: "-fmodules-validate-once-per-build-session" +// CHECK-NOT: "-fbuild-session-timestamp= +// CHECK-NOT: "-fmodules-prune-interval= +// CHECK-NOT: "-fmodules-prune-after= // CHECK: ], // CHECK-NEXT: "context-hash": "[[HASH_MOD_TU:.*]]", // CHECK-NEXT: "file-deps": [ @@ -57,6 +72,14 @@ // CHECK-NEXT: "module-name": "ModTU" // CHECK-NEXT: } // CHECK-NEXT: ] +// CHECK-NEXT: "command-line": [ +// CHECK-NEXT: "-fsyntax-only", +// CHECK-NOT: "-fmodules-cache-path= +// CHECK-NOT: "-fmodules-validate-once-per-build-session" +// CHECK-NOT: "-fbuild-session-file= +// CHECK-NOT: "-fmodules-prune-interval= +// CHECK-NOT: "-fmodules-prune-after= +// CHECK: ], // CHECK: } // CHECK-NEXT: ] // CHECK-NEXT: } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits