Skip to content

Commit 32ffbb7

Browse files
authored
Merge pull request #763 from artemcm/PlaceholdersStillUsefulForCanImport
[Dependency Scanning] Restore passing external target map as inputs to the scanning action.
2 parents 8a1d5f3 + 1c89f3d commit 32ffbb7

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)