Skip to content

Commit 3b244de

Browse files
committed
Revert "Revert "[Dependency Scanning] Restore passing external target map as inputs to the scanning action.""
This reverts commit 095cdac.
1 parent 1cc3fa5 commit 3b244de

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,37 @@ public extension Driver {
5353
moduleDependencyGraphUse: .dependencyScan)
5454
// FIXME: MSVC runtime flags
5555

56+
// Pass in external target dependencies to be treated as placeholder dependencies by the scanner
57+
if let externalTargetPaths = externalTargetModuleDetailsMap?.mapValues({ $0.path }) {
58+
let dependencyPlaceholderMapFile =
59+
try serializeExternalDependencyArtifacts(externalTargetPaths: externalTargetPaths)
60+
commandLine.appendFlag("-placeholder-dependency-module-map-file")
61+
commandLine.appendPath(dependencyPlaceholderMapFile)
62+
}
63+
5664
// Pass on the input files
5765
commandLine.append(contentsOf: inputFiles.map { .path($0.file) })
5866
return (inputs, commandLine)
5967
}
6068

69+
/// Serialize a map of placeholder (external) dependencies for the dependency scanner.
70+
private func serializeExternalDependencyArtifacts(externalTargetPaths: ExternalTargetModulePathMap)
71+
throws -> VirtualPath {
72+
var placeholderArtifacts: [SwiftModuleArtifactInfo] = []
73+
// Explicit external targets
74+
for (moduleId, binaryModulePath) in externalTargetPaths {
75+
let modPath = TextualVirtualPath(path: VirtualPath.absolute(binaryModulePath).intern())
76+
placeholderArtifacts.append(
77+
SwiftModuleArtifactInfo(name: moduleId.moduleName,
78+
modulePath: modPath))
79+
}
80+
let encoder = JSONEncoder()
81+
encoder.outputFormatting = [.prettyPrinted]
82+
let contents = try encoder.encode(placeholderArtifacts)
83+
return VirtualPath.createUniqueTemporaryFileWithKnownContents(.init("\(moduleOutputInfo.name)-external-modules.json"),
84+
contents)
85+
}
86+
6187
/// Returns false if the lib is available and ready to use
6288
private func initSwiftScanLib() throws -> Bool {
6389
// If `-nonlib-dependency-scanner` was specified or the libSwiftScan library cannot be found,

0 commit comments

Comments
 (0)