diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp --- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp +++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp @@ -102,6 +102,7 @@ CI.getCodeGenOpts().CoverageCompilationDir.clear(); CI.getCodeGenOpts().CoverageDataFile.clear(); CI.getCodeGenOpts().CoverageNotesFile.clear(); + CI.getCodeGenOpts().RelaxAll = false; } // Map output paths that affect behaviour to "-" so their existence is in the diff --git a/clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c b/clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c new file mode 100644 --- /dev/null +++ b/clang/test/ClangScanDeps/shared-module-for-tu-and-pch.c @@ -0,0 +1,42 @@ +// RUN: rm -rf %t +// RUN: split-file %s %t + +// RUN: sed "s|DIR|%/t|g" %t/cdb.json.debug.template > %t/cdb.debug.json +// RUN: sed "s|DIR|%/t|g" %t/cdb.json.release.template > %t/cdb.release.json + +// RUN: clang-scan-deps -compilation-database %t/cdb.debug.json -format=experimental-full -brief | FileCheck %s +// RUN: clang-scan-deps -compilation-database %t/cdb.release.json -format=experimental-full -brief | FileCheck %s +// CHECK: num modules: 1 + +//--- cdb.json.debug.template +[{ + "directory": "DIR", + "file": "DIR/tu.c", + "command": "clang -target x86_64-apple-macosx12 -x c -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.c -o DIR/tu.o -O0 -g" +}, +{ + "directory": "DIR", + "file": "DIR/tu.prefix.h", + "command": "clang -target x86_64-apple-macosx12 -x c-header -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.prefix.h -o DIR/tu.pch -O0 -g" +}] +//--- cdb.json.release.template +[{ + "directory": "DIR", + "file": "DIR/tu.c", + "command": "clang -target x86_64-apple-macosx12 -x c -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.c -o DIR/tu.o -Os -g" +}, +{ + "directory": "DIR", + "file": "DIR/tu.prefix.h", + "command": "clang -target x86_64-apple-macosx12 -x c-header -fmodules -gmodules -fmodules-cache-path=DIR/cache -I DIR/include -c DIR/tu.prefix.h -o DIR/tu.pch -Os -g" +}] + +//--- include/module.modulemap +module Top { header "top.h" } +//--- include/top.h +#define TOP int +//--- tu.c +#include "top.h" +TOP fn(void); +//--- tu.prefix.h +#include "top.h" diff --git a/clang/tools/clang-scan-deps/ClangScanDeps.cpp b/clang/tools/clang-scan-deps/ClangScanDeps.cpp --- a/clang/tools/clang-scan-deps/ClangScanDeps.cpp +++ b/clang/tools/clang-scan-deps/ClangScanDeps.cpp @@ -90,6 +90,7 @@ static bool DeprecatedDriverCommand; static ResourceDirRecipeKind ResourceDirRecipe; static bool Verbose; +static bool BriefResult; static std::vector CommandLine; #ifndef NDEBUG @@ -201,6 +202,7 @@ } Verbose = Args.hasArg(OPT_verbose); + BriefResult = Args.hasArg(OPT_brief_result); RoundTripArgs = Args.hasArg(OPT_round_trip_args); @@ -462,6 +464,8 @@ OS << llvm::formatv("{0:2}\n", Value(std::move(Output))); } + size_t getNumModules() const { return Modules.size(); } + private: struct IndexedModuleID { ModuleID ID; @@ -950,6 +954,11 @@ if (FD && FD->roundTripCommands(llvm::errs())) HadErrors = true; + if (BriefResult && FD) { + llvm::outs() << "num modules: " << FD->getNumModules() << '\n'; + return HadErrors; + } + if (Format == ScanningOutputFormat::Full) FD->printFullOutput(llvm::outs()); else if (Format == ScanningOutputFormat::P1689) diff --git a/clang/tools/clang-scan-deps/Opts.td b/clang/tools/clang-scan-deps/Opts.td --- a/clang/tools/clang-scan-deps/Opts.td +++ b/clang/tools/clang-scan-deps/Opts.td @@ -33,6 +33,8 @@ def verbose : F<"v", "Use verbose output">; +def brief_result : F<"brief", "Use brief dependency info output">; + def round_trip_args : F<"round-trip-args", "verify that command-line arguments are canonical by parsing and re-serializing">; def DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>; \ No newline at end of file