Skip to content

[Dependency Scanning] Restore passing external target map as inputs to the scanning action. #763

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 16, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,37 @@ public extension Driver {
moduleDependencyGraphUse: .dependencyScan)
// FIXME: MSVC runtime flags

// Pass in external target dependencies to be treated as placeholder dependencies by the scanner
if let externalTargetPaths = externalTargetModulePathMap {
let dependencyPlaceholderMapFile =
try serializeExternalDependencyArtifacts(externalTargetPaths: externalTargetPaths)
commandLine.appendFlag("-placeholder-dependency-module-map-file")
commandLine.appendPath(dependencyPlaceholderMapFile)
}

// Pass on the input files
commandLine.append(contentsOf: inputFiles.map { .path($0.file) })
return (inputs, commandLine)
}

/// Serialize a map of placeholder (external) dependencies for the dependency scanner.
private func serializeExternalDependencyArtifacts(externalTargetPaths: ExternalTargetModulePathMap)
throws -> VirtualPath {
var placeholderArtifacts: [SwiftModuleArtifactInfo] = []
// Explicit external targets
for (moduleId, binaryModulePath) in externalTargetPaths {
let modPath = TextualVirtualPath(path: VirtualPath.absolute(binaryModulePath).intern())
placeholderArtifacts.append(
SwiftModuleArtifactInfo(name: moduleId.moduleName,
modulePath: modPath))
}
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted]
let contents = try encoder.encode(placeholderArtifacts)
return VirtualPath.createUniqueTemporaryFileWithKnownContents(.init("\(moduleOutputInfo.name)-external-modules.json"),
contents)
}

/// Returns false if the lib is available and ready to use
private func initSwiftScanLib() throws -> Bool {
// If `-nonlib-dependency-scanner` was specified or the libSwiftScan library cannot be found,
Expand Down