Skip to content

Commit 5e208ff

Browse files
authored
Merge pull request #62067 from artemcm/DepScanClangOutputPath
[Dependency Scanning] Produce canonical output path for Clang PCMs.
2 parents ddf5cf9 + dc7cae2 commit 5e208ff

10 files changed

+36
-13
lines changed

include/swift/AST/ModuleDependencies.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ class SwiftBinaryModuleDependencyStorage : public ModuleDependenciesStorageBase
237237
/// This class is mostly an implementation detail for \c ModuleDependencies.
238238
class ClangModuleDependenciesStorage : public ModuleDependenciesStorageBase {
239239
public:
240+
/// Destination output path
241+
const std::string pcmOutputPath;
242+
240243
/// The module map file used to generate the Clang module.
241244
const std::string moduleMapFile;
242245

@@ -254,12 +257,14 @@ class ClangModuleDependenciesStorage : public ModuleDependenciesStorageBase {
254257
const std::vector<std::string> capturedPCMArgs;
255258

256259
ClangModuleDependenciesStorage(
260+
const std::string &pcmOutputPath,
257261
const std::string &moduleMapFile,
258262
const std::string &contextHash,
259263
const std::vector<std::string> &nonPathCommandLine,
260264
const std::vector<std::string> &fileDependencies,
261265
const std::vector<std::string> &capturedPCMArgs
262266
) : ModuleDependenciesStorageBase(ModuleDependenciesKind::Clang),
267+
pcmOutputPath(pcmOutputPath),
263268
moduleMapFile(moduleMapFile),
264269
contextHash(contextHash),
265270
nonPathCommandLine(nonPathCommandLine),
@@ -367,15 +372,16 @@ class ModuleDependencies {
367372
/// Describe the module dependencies for a Clang module that can be
368373
/// built from a module map and headers.
369374
static ModuleDependencies forClangModule(
375+
const std::string &pcmOutputPath,
370376
const std::string &moduleMapFile,
371377
const std::string &contextHash,
372378
const std::vector<std::string> &nonPathCommandLine,
373379
const std::vector<std::string> &fileDependencies,
374380
const std::vector<std::string> &capturedPCMArgs) {
375381
return ModuleDependencies(
376382
std::make_unique<ClangModuleDependenciesStorage>(
377-
moduleMapFile, contextHash, nonPathCommandLine,
378-
fileDependencies, capturedPCMArgs));
383+
pcmOutputPath, moduleMapFile, contextHash,
384+
nonPathCommandLine, fileDependencies, capturedPCMArgs));
379385
}
380386

381387
/// Describe a placeholder dependency swift module.

include/swift/DependencyScan/SerializedModuleDependencyCacheFormat.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ using SwiftPlaceholderModuleDetailsLayout =
162162

163163
using ClangModuleDetailsLayout =
164164
BCRecordLayout<CLANG_MODULE_DETAILS_NODE, // ID
165+
FileIDField, // pcmOutputPath
165166
FileIDField, // moduleMapPath
166167
ContextHashField, // contextHash
167168
FlagIDArrayIDField, // commandLine

lib/ClangImporter/ClangModuleDependencyScanner.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ void ClangImporter::recordModuleDependencies(
159159
swiftArgs.push_back("-emit-pcm");
160160
swiftArgs.push_back("-module-name");
161161
swiftArgs.push_back(clangModuleDep.ID.ModuleName);
162+
163+
auto pcmPath = moduleCacheRelativeLookupModuleOutput(clangModuleDep.ID,
164+
ModuleOutputKind::ModuleFile,
165+
getModuleCachePathFromClang(getClangInstance()));
166+
swiftArgs.push_back("-o");
167+
swiftArgs.push_back(pcmPath);
162168

163169
// Ensure that the resulting PCM build invocation uses Clang frontend directly
164170
swiftArgs.push_back("-direct-clang-cc1-module-build");
@@ -186,6 +192,7 @@ void ClangImporter::recordModuleDependencies(
186192
// Module-level dependencies.
187193
llvm::StringSet<> alreadyAddedModules;
188194
auto dependencies = ModuleDependencies::forClangModule(
195+
pcmPath,
189196
clangModuleDep.ClangModuleMapFile,
190197
clangModuleDep.ID.ContextHash,
191198
swiftArgs,

lib/DependencyScan/ModuleDependencyCacheSerialization.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,15 @@ bool Deserializer::readGraph(GlobalModuleDependenciesCache &cache) {
446446
if (!hasCurrentModule)
447447
llvm::report_fatal_error("Unexpected CLANG_MODULE_DETAILS_NODE record");
448448
cache.configureForTriple(getTriple());
449-
unsigned moduleMapPathID, contextHashID, commandLineArrayID,
449+
unsigned pcmOutputPathID, moduleMapPathID, contextHashID, commandLineArrayID,
450450
fileDependenciesArrayID, capturedPCMArgsArrayID;
451-
ClangModuleDetailsLayout::readRecord(Scratch, moduleMapPathID,
451+
ClangModuleDetailsLayout::readRecord(Scratch, pcmOutputPathID, moduleMapPathID,
452452
contextHashID, commandLineArrayID,
453453
fileDependenciesArrayID,
454454
capturedPCMArgsArrayID);
455+
auto pcmOutputPath = getIdentifier(pcmOutputPathID);
456+
if (!pcmOutputPath)
457+
llvm::report_fatal_error("Bad pcm output path");
455458
auto moduleMapPath = getIdentifier(moduleMapPathID);
456459
if (!moduleMapPath)
457460
llvm::report_fatal_error("Bad module map path");
@@ -469,7 +472,7 @@ bool Deserializer::readGraph(GlobalModuleDependenciesCache &cache) {
469472
llvm::report_fatal_error("Bad captured PCM Args");
470473

471474
// Form the dependencies storage object
472-
auto moduleDep = ModuleDependencies::forClangModule(
475+
auto moduleDep = ModuleDependencies::forClangModule(*pcmOutputPath,
473476
*moduleMapPath, *contextHash, *commandLineArgs, *fileDependencies,
474477
*capturedPCMArgs);
475478

@@ -850,6 +853,7 @@ void Serializer::writeModuleInfo(ModuleDependencyID moduleID,
850853
assert(clangDeps);
851854
ClangModuleDetailsLayout::emitRecord(
852855
Out, ScratchRecord, AbbrCodes[ClangModuleDetailsLayout::Code],
856+
getIdentifier(clangDeps->pcmOutputPath),
853857
getIdentifier(clangDeps->moduleMapFile),
854858
getIdentifier(clangDeps->contextHash),
855859
getArray(moduleID, ModuleIdentifierArrayKind::NonPathCommandLine),
@@ -1017,6 +1021,7 @@ void Serializer::collectStringsAndArrays(
10171021
case swift::ModuleDependenciesKind::Clang: {
10181022
auto clangDeps = dependencyInfo.getAsClangModule();
10191023
assert(clangDeps);
1024+
addIdentifier(clangDeps->pcmOutputPath);
10201025
addIdentifier(clangDeps->moduleMapFile);
10211026
addIdentifier(clangDeps->contextHash);
10221027
addArray(moduleID, ModuleIdentifierArrayKind::NonPathCommandLine,

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,8 @@ static void writeJSON(llvm::raw_ostream &out,
590590
modulePath = get_C_string(swiftPlaceholderDeps->compiled_module_path);
591591
else if (swiftBinaryDeps)
592592
modulePath = get_C_string(swiftBinaryDeps->compiled_module_path);
593+
else if (clangDeps)
594+
modulePath = get_C_string(moduleInfo.module_path);
593595
else
594596
modulePath = moduleName + modulePathSuffix;
595597

@@ -831,6 +833,8 @@ generateFullDependencyGraph(CompilerInstance &instance,
831833
modulePath = swiftPlaceholderDeps->compiledModulePath;
832834
else if (swiftBinaryDeps)
833835
modulePath = swiftBinaryDeps->compiledModulePath;
836+
else if (clangDeps)
837+
modulePath = clangDeps->pcmOutputPath;
834838
else
835839
modulePath = module.first + modulePathSuffix;
836840

test/ModuleInterface/clang-args-transitive-availability.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import ImportsMacroSpecificClangModule
3535
// CHECK: "clang": "OnlyWithMacro"
3636
// CHECK-NEXT: },
3737
// CHECK-NEXT: {
38-
// CHECK-NEXT: "modulePath": "OnlyWithMacro.pcm",
38+
// CHECK-NEXT: "modulePath": "{{.*}}{{/|\\}}OnlyWithMacro-{{.*}}.pcm",
3939
// CHECK-NEXT: "sourceFiles": [
4040
// CHECK-DAG: "{{.*}}OnlyWithMacro.h"
4141
// CHECK-DAG: "{{.*}}module.modulemap"

test/ScanDependencies/batch_module_scan.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// CHECK-PCM-NEXT: "clang": "F"
2828
// CHECK-PCM-NEXT: },
2929
// CHECK-PCM-NEXT: {
30-
// CHECK-PCM-NEXT: "modulePath": "F.pcm",
30+
// CHECK-PCM-NEXT: "modulePath": "{{.*}}F-{{.*}}.pcm",
3131
// CHECK-PCM: "-I
3232

3333
// CHECK-SWIFT: {

test/ScanDependencies/batch_module_scan_versioned.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
// CHECK-PCM109-NEXT: "clang": "G"
2828
// CHECK-PCM109-NEXT: },
2929
// CHECK-PCM109-NEXT: {
30-
// CHECK-PCM109-NEXT: "modulePath": "G.pcm",
30+
// CHECK-PCM109-NEXT: "modulePath": "{{.*}}{{/|\\}}G-{{.*}}.pcm",
3131
// CHECK-PCM109: "directDependencies": [
3232
// CHECK-PCM109-NEXT: {
3333
// CHECK-PCM109-NEXT: "clang": "X"
@@ -42,7 +42,7 @@
4242
// CHECK-PCM110-NEXT: "clang": "G"
4343
// CHECK-PCM110-NEXT: },
4444
// CHECK-PCM110-NEXT: {
45-
// CHECK-PCM110-NEXT: "modulePath": "G.pcm",
45+
// CHECK-PCM110-NEXT: "modulePath": "{{.*}}{{/|\\}}G-{{.*}}.pcm",
4646
// CHECK-PCM110: "directDependencies": [
4747
// CHECK-PCM110-NEXT: ],
4848
// CHECK-PCM110-NOT: "clang": "X"

test/ScanDependencies/module_deps_cache_reuse.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ import SubE
9494
// CHECK-NEXT: },
9595

9696
/// --------Clang module C
97-
// CHECK-LABEL: "modulePath": "C.pcm",
97+
// CHECK-LABEL: "modulePath": "{{.*}}/C-{{.*}}.pcm",
9898

9999
// CHECK: "sourceFiles": [
100100
// CHECK-DAG: module.modulemap
@@ -181,7 +181,7 @@ import SubE
181181
// CHECK-NEXT: "clang": "SwiftShims"
182182

183183
/// --------Clang module B
184-
// CHECK-LABEL: "modulePath": "B.pcm"
184+
// CHECK-LABEL: "modulePath": "{{.*}}/B-{{.*}}.pcm",
185185

186186
// CHECK-NEXT: sourceFiles
187187
// CHECK-DAG: module.modulemap
@@ -193,4 +193,4 @@ import SubE
193193
// CHECK-NEXT: }
194194

195195
/// --------Clang module SwiftShims
196-
// CHECK-LABEL: "modulePath": "SwiftShims.pcm",
196+
// CHECK-LABEL: "modulePath": "{{.*}}/SwiftShims-{{.*}}.pcm",

test/ScanDependencies/module_deps_external.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ import SomeExternalModule
9696
// CHECK-NEXT: "clang": "SwiftShims"
9797

9898
/// --------Clang module SwiftShims
99-
// CHECK-LABEL: "modulePath": "SwiftShims.pcm",
99+
// CHECK-LABEL: "modulePath": "{{.*}}/SwiftShims-{{.*}}.pcm",
100100

101101
// Check make-style dependencies
102102
// CHECK-MAKE-DEPS: module_deps_external.swift

0 commit comments

Comments
 (0)