Skip to content

Commit 6b5e7ef

Browse files
committed
[Dependency scanner] Capture Clang context hash and command-line arguments.
1 parent fdfadf8 commit 6b5e7ef

File tree

5 files changed

+42
-4
lines changed

5 files changed

+42
-4
lines changed

include/swift/AST/ModuleDependencies.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,26 @@ class ClangModuleDependenciesStorage : public ModuleDependenciesStorageBase {
9494
/// The module map file used to generate the Clang module.
9595
const std::string moduleMapFile;
9696

97+
/// The context hash describing the configuration options for this module.
98+
const std::string contextHash;
99+
100+
/// Partial (Clang) command line that can be used to build this module.
101+
const std::vector<std::string> nonPathCommandLine;
102+
97103
/// The file dependencies
98104
const std::vector<std::string> fileDependencies;
99105

100106
ClangModuleDependenciesStorage(
101107
const std::string &compiledModulePath,
102108
const std::string &moduleMapFile,
109+
const std::string &contextHash,
110+
const std::vector<std::string> &nonPathCommandLine,
103111
const std::vector<std::string> &fileDependencies
104112
) : ModuleDependenciesStorageBase(/*isSwiftModule=*/false,
105113
compiledModulePath),
106114
moduleMapFile(moduleMapFile),
115+
contextHash(contextHash),
116+
nonPathCommandLine(nonPathCommandLine),
107117
fileDependencies(fileDependencies) { }
108118

109119
ModuleDependenciesStorageBase *clone() const override {
@@ -158,11 +168,13 @@ class ModuleDependencies {
158168
static ModuleDependencies forClangModule(
159169
const std::string &compiledModulePath,
160170
const std::string &moduleMapFile,
171+
const std::string &contextHash,
172+
const std::vector<std::string> &nonPathCommandLine,
161173
const std::vector<std::string> &fileDependencies) {
162174
return ModuleDependencies(
163-
std::make_unique<ClangModuleDependenciesStorage>(compiledModulePath,
164-
moduleMapFile,
165-
fileDependencies));
175+
std::make_unique<ClangModuleDependenciesStorage>(
176+
compiledModulePath, moduleMapFile, contextHash, nonPathCommandLine,
177+
fileDependencies));
166178
}
167179

168180
/// Retrieve the path to the compiled module.

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,10 @@ static void recordModuleDependencies(
209209
llvm::StringSet<> alreadyAddedModules;
210210
auto dependencies = ModuleDependencies::forClangModule(
211211
clangModuleDep.ImplicitModulePCMPath,
212-
clangModuleDep.ClangModuleMapFile, fileDeps);
212+
clangModuleDep.ClangModuleMapFile,
213+
clangModuleDep.ContextHash,
214+
clangModuleDep.NonPathCommandLine,
215+
fileDeps);
213216
for (const auto &moduleName : clangModuleDep.ClangModuleDeps) {
214217
dependencies.addModuleDependency(moduleName.ModuleName, alreadyAddedModules);
215218
}

lib/FrontendTool/ScanDependencies.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ static void writeJSON(llvm::raw_ostream &out,
301301
// Module map file.
302302
writeJSONSingleField(out, "moduleMapPath",
303303
clangDeps->moduleMapFile, 5,
304+
/*trailingComma=*/true);
305+
306+
// Context hash.
307+
writeJSONSingleField(out, "contextHash",
308+
clangDeps->contextHash, 5,
309+
/*trailingComma=*/true);
310+
311+
// Command line.
312+
writeJSONSingleField(out, "commandLine",
313+
clangDeps->nonPathCommandLine, 5,
304314
/*trailingComma=*/false);
305315
}
306316

test/ScanDependencies/Inputs/ModuleDependencyGraph.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ struct SwiftModuleDetails: Codable {
7171
struct ClangModuleDetails: Codable {
7272
/// The path to the module map used to build this module.
7373
var moduleMapPath: String
74+
75+
/// The context hash used to discriminate this module file.
76+
var contextHash: String
77+
78+
/// The Clang command line arguments that need to be passed through
79+
/// to the -emit-pcm action to build this module.
80+
var commandLine: [String] = []
7481
}
7582

7683
struct ModuleDependencies: Codable {

test/ScanDependencies/module_deps.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ import E
7474
// CHECK: "moduleMapPath"
7575
// CHECK-SAME: module.modulemap
7676

77+
// CHECK: "contextHash"
78+
// CHECK-SAME: "{{.*}}"
79+
80+
// CHECK: "commandLine": [
81+
// CHECK-NEXT: "-remove-preceeding-explicit-module-build-incompatible-options"
82+
7783
/// --------Swift module E
7884
// CHECK: "swift": "E"
7985
// CHECK-LABEL: modulePath": "E.swiftmodule"

0 commit comments

Comments
 (0)