Skip to content

Commit 1c89f3d

Browse files
committed
[Dependency Scanning] Restore passing external target map as inputs to the scanning action.
I got overzealous when deleting code in swiftlang#749 and removed one piece of functionality that we still rely on. Although the external target map is no longer necessary when scanning dependencies using libSwiftScan, we still use it for resolution of `canImport` statements during the scan. We need to figure out a better way to deal with that in the scanner, but in the meantime this will restore functionality.
1 parent 80c70a4 commit 1c89f3d

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
@@ -52,11 +52,37 @@ public extension Driver {
5252
moduleDependencyGraphUse: .dependencyScan)
5353
// FIXME: MSVC runtime flags
5454

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

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

0 commit comments

Comments
 (0)