Skip to content

Commit 192bb33

Browse files
Merge pull request swiftlang#78331 from cachemeifyoucan/eng/PR-141843125
2 parents 7057842 + 1e399d5 commit 192bb33

File tree

3 files changed

+58
-40
lines changed

3 files changed

+58
-40
lines changed

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -309,36 +309,41 @@ class ExplicitModuleDependencyResolver {
309309
llvm::Error handleSwiftInterfaceModuleDependency(
310310
ModuleDependencyID depModuleID,
311311
const SwiftInterfaceModuleDependenciesStorage &interfaceDepDetails) {
312-
auto &path = interfaceDepDetails.moduleCacheKey.empty()
313-
? interfaceDepDetails.moduleOutputPath
314-
: interfaceDepDetails.moduleCacheKey;
315-
commandline.push_back("-swift-module-file=" + depModuleID.ModuleName + "=" +
316-
path);
312+
if (!resolvingDepInfo.isSwiftSourceModule()) {
313+
auto &path = interfaceDepDetails.moduleCacheKey.empty()
314+
? interfaceDepDetails.moduleOutputPath
315+
: interfaceDepDetails.moduleCacheKey;
316+
commandline.push_back("-swift-module-file=" + depModuleID.ModuleName +
317+
"=" + path);
318+
}
317319
addMacroDependencies(depModuleID, interfaceDepDetails);
318320
return llvm::Error::success();
319321
}
320322

321323
llvm::Error handleSwiftBinaryModuleDependency(
322324
ModuleDependencyID depModuleID,
323325
const SwiftBinaryModuleDependencyStorage &binaryDepDetails) {
324-
auto &path = binaryDepDetails.moduleCacheKey.empty()
325-
? binaryDepDetails.compiledModulePath
326-
: binaryDepDetails.moduleCacheKey;
327-
commandline.push_back("-swift-module-file=" + depModuleID.ModuleName + "=" +
328-
path);
329-
// If this binary module was built with a header, the header's module
330-
// dependencies must also specify a .modulemap to the compilation, in
331-
// order to resolve the header's own header include directives.
332-
for (const auto &bridgingHeaderDepID :
333-
binaryDepDetails.headerModuleDependencies) {
334-
auto optionalBridgingHeaderDepModuleInfo = cache.findKnownDependency(
335-
bridgingHeaderDepID);
336-
const auto bridgingHeaderDepModuleDetails =
337-
optionalBridgingHeaderDepModuleInfo.getAsClangModule();
338-
commandline.push_back("-Xcc");
339-
commandline.push_back("-fmodule-map-file=" +
340-
cache.getScanService().remapPath(
341-
bridgingHeaderDepModuleDetails->moduleMapFile));
326+
if (!resolvingDepInfo.isSwiftSourceModule()) {
327+
auto &path = binaryDepDetails.moduleCacheKey.empty()
328+
? binaryDepDetails.compiledModulePath
329+
: binaryDepDetails.moduleCacheKey;
330+
commandline.push_back("-swift-module-file=" + depModuleID.ModuleName +
331+
"=" + path);
332+
// If this binary module was built with a header, the header's module
333+
// dependencies must also specify a .modulemap to the compilation, in
334+
// order to resolve the header's own header include directives.
335+
for (const auto &bridgingHeaderDepID :
336+
binaryDepDetails.headerModuleDependencies) {
337+
auto optionalBridgingHeaderDepModuleInfo =
338+
cache.findKnownDependency(bridgingHeaderDepID);
339+
const auto bridgingHeaderDepModuleDetails =
340+
optionalBridgingHeaderDepModuleInfo.getAsClangModule();
341+
commandline.push_back("-Xcc");
342+
commandline.push_back(
343+
"-fmodule-map-file=" +
344+
cache.getScanService().remapPath(
345+
bridgingHeaderDepModuleDetails->moduleMapFile));
346+
}
342347
}
343348
addMacroDependencies(depModuleID, binaryDepDetails);
344349
return llvm::Error::success();
@@ -347,26 +352,29 @@ class ExplicitModuleDependencyResolver {
347352
llvm::Error handleSwiftPlaceholderModuleDependency(
348353
ModuleDependencyID depModuleID,
349354
const SwiftPlaceholderModuleDependencyStorage &placeholderDetails) {
350-
commandline.push_back("-swift-module-file=" + depModuleID.ModuleName + "=" +
351-
placeholderDetails.compiledModulePath);
355+
if (!resolvingDepInfo.isSwiftSourceModule())
356+
commandline.push_back("-swift-module-file=" + depModuleID.ModuleName +
357+
"=" + placeholderDetails.compiledModulePath);
352358
return llvm::Error::success();
353359
}
354360

355361
llvm::Error handleClangModuleDependency(
356362
ModuleDependencyID depModuleID,
357363
const ClangModuleDependencyStorage &clangDepDetails) {
358-
if (!resolvingDepInfo.isClangModule()) {
359-
commandline.push_back("-Xcc");
360-
commandline.push_back("-fmodule-file=" + depModuleID.ModuleName + "=" +
361-
clangDepDetails.mappedPCMPath);
362-
}
363-
if (!clangDepDetails.moduleCacheKey.empty()) {
364-
commandline.push_back("-Xcc");
365-
commandline.push_back("-fmodule-file-cache-key");
366-
commandline.push_back("-Xcc");
367-
commandline.push_back(clangDepDetails.mappedPCMPath);
368-
commandline.push_back("-Xcc");
369-
commandline.push_back(clangDepDetails.moduleCacheKey);
364+
if (!resolvingDepInfo.isSwiftSourceModule()) {
365+
if (!resolvingDepInfo.isClangModule()) {
366+
commandline.push_back("-Xcc");
367+
commandline.push_back("-fmodule-file=" + depModuleID.ModuleName + "=" +
368+
clangDepDetails.mappedPCMPath);
369+
}
370+
if (!clangDepDetails.moduleCacheKey.empty()) {
371+
commandline.push_back("-Xcc");
372+
commandline.push_back("-fmodule-file-cache-key");
373+
commandline.push_back("-Xcc");
374+
commandline.push_back(clangDepDetails.mappedPCMPath);
375+
commandline.push_back("-Xcc");
376+
commandline.push_back(clangDepDetails.moduleCacheKey);
377+
}
370378
}
371379

372380
// Collect CAS deppendencies from clang modules.
@@ -1304,7 +1312,7 @@ bool swift::dependencies::scanDependencies(CompilerInstance &instance) {
13041312
*service, instance.getMainModule()->getNameStr().str(),
13051313
instance.getInvocation().getFrontendOptions().ExplicitModulesOutputPath,
13061314
instance.getInvocation().getModuleScanningHash());
1307-
1315+
13081316
if (opts.ReuseDependencyScannerCache)
13091317
deserializeDependencyCache(instance, cache);
13101318

@@ -1391,7 +1399,7 @@ bool swift::dependencies::batchScanDependencies(
13911399
return true;
13921400

13931401
auto batchScanResults = performBatchModuleScan(
1394-
instance, /*DependencyScanDiagnosticCollector*/ nullptr,
1402+
instance, /*DependencyScanDiagnosticCollector*/ nullptr,
13951403
cache, /*versionedPCMInstanceCache*/ nullptr, saver,
13961404
*batchInput);
13971405

@@ -1652,7 +1660,7 @@ swift::dependencies::performBatchModuleScan(
16521660
}
16531661
allDependencies = scanner.performDependencyScan(moduleID, cache);
16541662
}
1655-
1663+
16561664
batchScanResult.push_back(
16571665
generateFullDependencyGraph(instance, diagnosticCollector, cache,
16581666
allDependencies));

test/CAS/symbol-graph.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json A > %t/A.cmd
1010
// RUN: %swift_frontend_plain @%t/A.cmd
1111

12+
// RUN: %{python} %S/Inputs/GenerateExplicitModuleMap.py %t/deps.json > %t/map.json
13+
// RUN: llvm-cas --cas %t/cas --make-blob --data %t/map.json > %t/map.casid
1214
// RUN: %{python} %S/Inputs/BuildCommandExtractor.py %t/deps.json Test > %t/Test.cmd
1315
// RUN: %target-swift-frontend -module-name Test -module-cache-path %t/clang-module-cache -O \
1416
// RUN: -parse-stdlib -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
1517
// RUN: %t/main.swift -o %t/Test.swiftmodule -swift-version 5 -cache-compile-job -cas-path %t/cas -I %t/include \
18+
// RUN: -explicit-swift-module-map-file @%t/map.casid \
1619
// RUN: -emit-symbol-graph -emit-symbol-graph-dir %t/symbol-graph1 \
1720
// RUN: -emit-module @%t/Test.cmd -Rcache-compile-job 2>&1 | %FileCheck %s --check-prefix=CACHE-MISS
1821

@@ -22,6 +25,7 @@
2225
// RUN: %target-swift-frontend -module-name Test -module-cache-path %t/clang-module-cache -O \
2326
// RUN: -parse-stdlib -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
2427
// RUN: %t/main.swift -o %t/Test.swiftmodule -swift-version 5 -cache-compile-job -cas-path %t/cas -I %t/include \
28+
// RUN: -explicit-swift-module-map-file @%t/map.casid \
2529
// RUN: -emit-symbol-graph -emit-symbol-graph-dir %t/symbol-graph2 \
2630
// RUN: -emit-module @%t/Test.cmd -Rcache-compile-job 2>&1 | %FileCheck %s --check-prefix=CACHE-HIT
2731

@@ -35,13 +39,15 @@
3539
// RUN: %target-swift-frontend -module-name Test -module-cache-path %t/clang-module-cache -O \
3640
// RUN: -parse-stdlib -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
3741
// RUN: %t/main.swift -o %t/Test.swiftmodule -swift-version 5 -cache-compile-job -cas-path %t/cas -I %t/include \
42+
// RUN: -explicit-swift-module-map-file @%t/map.casid \
3843
// RUN: -emit-symbol-graph -emit-symbol-graph-dir %t/symbol-graph3 \
3944
// RUN: -emit-module @%t/Test.cmd -Rcache-compile-job > %t/key.casid
4045

4146
// RUN: %swift-scan-test -action replay_result -cas-path %t/cas -id @%t/key.casid -- \
4247
// RUN: %target-swift-frontend -module-name Test -module-cache-path %t/clang-module-cache -O \
4348
// RUN: -parse-stdlib -disable-implicit-string-processing-module-import -disable-implicit-concurrency-module-import \
4449
// RUN: %t/main.swift -o %t/Test.swiftmodule -swift-version 5 -cache-compile-job -cas-path %t/cas -I %t/include \
50+
// RUN: -explicit-swift-module-map-file @%t/map.casid \
4551
// RUN: -emit-symbol-graph -emit-symbol-graph-dir %t/symbol-graph3 \
4652
// RUN: -emit-module @%t/Test.cmd -Rcache-compile-job
4753

test/ScanDependencies/module_deps.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
// Check the contents of the JSON output
66
// RUN: %validate-json %t/deps.json | %FileCheck -check-prefix CHECK_NO_CLANG_TARGET %s
77

8+
// RUN: %{python} %S/../CAS/Inputs/BuildCommandExtractor.py %t/deps.json deps | %FileCheck --check-prefix CHECK-NO-MODULES %s --allow-empty
9+
// CHECK-NO-MODULES-NOT: -swift-module-file
10+
// CHECK-NO-MODULES-NOT: -fmodule-file
11+
812
// Check the contents of the JSON output
913
// RUN: %validate-json %t/deps.json | %FileCheck %s -check-prefix CHECK-NO-SEARCH-PATHS
1014

0 commit comments

Comments
 (0)