Skip to content

Commit 1ae70a5

Browse files
committed
DependenciesScanner: avoid reporting output file path because build system should specify it
1 parent 3a214d9 commit 1ae70a5

File tree

4 files changed

+11
-63
lines changed

4 files changed

+11
-63
lines changed

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,6 @@ static ClangModuleDependenciesCacheImpl *getOrCreateClangImpl(
188188
return clangImpl;
189189
}
190190

191-
static std::string getModuleFilePath(StringRef moduleCacheDir,
192-
StringRef moduleName,
193-
StringRef contextHash) {
194-
SmallString<128> outputPath(moduleCacheDir);
195-
llvm::sys::path::append(outputPath, (llvm::Twine(moduleName)
196-
+ "-" + contextHash + ".pcm").str());
197-
return outputPath.str().str();
198-
}
199-
200-
static std::string getModuleFilePath(StringRef moduleCacheDir,
201-
const ModuleDeps &dep) {
202-
return getModuleFilePath(moduleCacheDir, dep.ModuleName, dep.ContextHash);
203-
}
204-
205191
/// Record the module dependencies we found by scanning Clang modules into
206192
/// the module dependencies cache.
207193
void ClangImporter::recordModuleDependencies(
@@ -213,23 +199,7 @@ void ClangImporter::recordModuleDependencies(
213199
};
214200
auto ModuleCacheDir = swift::getModuleCachePathFromClang(getClangInstance());
215201

216-
// A map keyed by module name and context hash.
217-
llvm::StringMap<llvm::StringMap<ModuleInfo>> moduleInfoMap;
218-
219-
// Traverse all Clang modules to populate moduleInfoMap for cross
220-
// referencing later.
221202
for (const auto &clangModuleDep : clangDependencies.DiscoveredModules) {
222-
moduleInfoMap[clangModuleDep.ModuleName][clangModuleDep.ContextHash] =
223-
{
224-
// Keep track of pcm path for output.
225-
getModuleFilePath(ModuleCacheDir, clangModuleDep),
226-
// Keep track of modulemap file for input.
227-
clangModuleDep.ClangModuleMapFile
228-
};
229-
}
230-
for (const auto &clangModuleDep : clangDependencies.DiscoveredModules) {
231-
assert(moduleInfoMap[clangModuleDep.ModuleName]
232-
.count(clangModuleDep.ContextHash));
233203
// If we've already cached this information, we're done.
234204
if (cache.hasDependencies(clangModuleDep.ModuleName,
235205
ModuleDependenciesKind::Clang))
@@ -265,24 +235,11 @@ void ClangImporter::recordModuleDependencies(
265235
addClangArg(arg);
266236
}
267237

268-
// Add -fmodule-map-file and -fmodule-file for direct dependencies.
269-
for (auto &dep: clangModuleDep.ClangModuleDeps) {
270-
assert(moduleInfoMap[dep.ModuleName].count(dep.ContextHash));
271-
addClangArg((llvm::Twine("-fmodule-map-file=")
272-
+ moduleInfoMap[dep.ModuleName][dep.ContextHash].ModuleMapPath).str());
273-
addClangArg((llvm::Twine("-fmodule-file=")
274-
+ moduleInfoMap[dep.ModuleName][dep.ContextHash].PCMPath).str());
275-
}
276238
// Swift frontend action: -emit-pcm
277239
swiftArgs.push_back("-emit-pcm");
278240
swiftArgs.push_back("-module-name");
279241
swiftArgs.push_back(clangModuleDep.ModuleName);
280242

281-
// Swift frontend option for output file path (Foo.pcm).
282-
swiftArgs.push_back("-o");
283-
swiftArgs.push_back(moduleInfoMap[clangModuleDep.ModuleName]
284-
[clangModuleDep.ContextHash].PCMPath);
285-
286243
// Swift frontend option for input file path (Foo.modulemap).
287244
swiftArgs.push_back(clangModuleDep.ClangModuleMapFile);
288245
// Module-level dependencies.

lib/Frontend/ModuleInterfaceLoader.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,10 +1368,6 @@ bool InterfaceSubContextDelegateImpl::runInSubCompilerInstance(StringRef moduleN
13681368
subInvocation.getFrontendOptions().InputsAndOutputs
13691369
.setMainAndSupplementaryOutputs(outputFiles, ModuleOutputPaths);
13701370

1371-
// Add -o for building the module explicitly.
1372-
BuildArgs.push_back("-o");
1373-
BuildArgs.push_back(outputPath);
1374-
13751371
SmallVector<const char *, 64> SubArgs;
13761372
std::string CompilerVersion;
13771373
// Extract compiler arguments from the interface file and use them to configure

test/ScanDependencies/Inputs/BuildModulesFromGraph.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ func findModuleBuildingCommand(_ moduleName: String) -> [String]? {
3939
if let command = findModuleBuildingCommand(moduleName) {
4040
var result = swiftPath
4141
command.forEach { result += " \($0)"}
42+
// Pass down additional args to the Swift invocation.
43+
CommandLine.arguments.dropFirst(4).forEach { result += " \($0)"}
4244
print(result)
4345
exit(0)
4446
} else {

test/ScanDependencies/module_deps.swift

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,15 @@
2222
// RUN: %target-build-swift %S/Inputs/ModuleDependencyGraph.swift %t/BuildModules/main.swift -o %t/ModuleBuilder
2323
// RUN: %target-codesign %t/ModuleBuilder
2424

25-
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path A.pcm | %S/Inputs/CommandRunner.py
26-
// RUN: ls %t/clang-module-cache/A-*.pcm
27-
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path B.pcm | %S/Inputs/CommandRunner.py
28-
// RUN: ls %t/clang-module-cache/B-*.pcm
29-
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path C.pcm | %S/Inputs/CommandRunner.py
30-
// RUN: ls %t/clang-module-cache/C-*.pcm
31-
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path A.swiftmodule | %S/Inputs/CommandRunner.py
32-
// RUN: ls %t/clang-module-cache/A-*.swiftmodule
33-
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path E.swiftmodule | %S/Inputs/CommandRunner.py
34-
// RUN: ls %t/clang-module-cache/E-*.swiftmodule
35-
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path F.swiftmodule | %S/Inputs/CommandRunner.py
36-
// RUN: ls %t/clang-module-cache/F-*.swiftmodule
37-
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path G.swiftmodule | %S/Inputs/CommandRunner.py
38-
// RUN: ls %t/clang-module-cache/G-*.swiftmodule
25+
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path SwiftShims.pcm -o %t/clang-module-cache/SwiftShims.pcm | %S/Inputs/CommandRunner.py
26+
// RUN: ls %t/clang-module-cache/SwiftShims.pcm
27+
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path A.pcm -o %t/clang-module-cache/A.pcm | %S/Inputs/CommandRunner.py
28+
// RUN: ls %t/clang-module-cache/A.pcm
29+
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path B.pcm -o %t/clang-module-cache/B.pcm -Xcc -Xclang -Xcc -fmodule-map-file=%S/Inputs/CHeaders/module.modulemap -Xcc -Xclang -Xcc -fmodule-file=%t/clang-module-cache/A.pcm | %S/Inputs/CommandRunner.py
30+
// RUN: ls %t/clang-module-cache/B.pcm
31+
// RUN: %target-run %t/ModuleBuilder %t/deps.json %swift-path C.pcm -o %t/clang-module-cache/C.pcm -Xcc -Xclang -Xcc -fmodule-map-file=%S/Inputs/CHeaders/module.modulemap -Xcc -Xclang -Xcc -fmodule-file=%t/clang-module-cache/B.pcm | %S/Inputs/CommandRunner.py
32+
// RUN: ls %t/clang-module-cache/C.pcm
33+
3934

4035
// REQUIRES: executable_test
4136
// REQUIRES: objc_interop
@@ -135,8 +130,6 @@ import G
135130
// CHECK: "-compile-module-from-interface"
136131
// CHECK: "-target"
137132
// CHECK: "-sdk"
138-
// CHECK: "-o"
139-
// CHECK: /clang-module-cache/G-{{.*}}.swiftmodule"
140133
// CHECK: "-module-name"
141134
// CHECK: "G"
142135
// CHECK: "-swift-version"

0 commit comments

Comments
 (0)