Skip to content

Revert "Remove deprecated externalBuildArtifacts API." #533

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
Mar 9, 2021
Merged
Show file tree
Hide file tree
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
24 changes: 20 additions & 4 deletions Sources/SwiftDriver/Driver/Driver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,9 @@ public struct Driver {
/// expand response files, etc. By default this is the local filesystem.
/// - Parameter executor: Used by the driver to execute jobs. The default argument
/// is present to streamline testing, it shouldn't be used in production.
/// - Parameter externalTargetModulePathMap: All external artifacts a build system may pass in as input to the explicit
/// build of the current module. Consists of a map of externally-built targets, and their corresponding binary modules.
/// - Parameter interModuleDependencyOracle: A dependency oracle instance, re-used in multiple-target builds
/// to make use of caching of common dependency scanning queries
/// - Parameter externalBuildArtifacts: All external artifacts a build system may pass in as input to the explicit
/// build of the current module. Consists of a map of externally-built targets, and a map of all previously
/// discovered/scanned modules.
public init(
args: [String],
env: [String: String] = ProcessEnv.vars,
Expand All @@ -355,6 +354,9 @@ public struct Driver {
executor: DriverExecutor,
integratedDriver: Bool = true,
compilerExecutableDir: AbsolutePath? = nil,
// FIXME: Duplication with externalBuildArtifacts and externalTargetModulePathMap
// is a temporary backwards-compatibility shim to help transition SwiftPM to the new API
externalBuildArtifacts: ExternalBuildArtifacts? = nil,
externalTargetModulePathMap: ExternalTargetModulePathMap? = nil,
interModuleDependencyOracle: InterModuleDependencyOracle? = nil
) throws {
Expand All @@ -365,6 +367,12 @@ public struct Driver {
self.diagnosticEngine = diagnosticsEngine
self.executor = executor

if let externalArtifacts = externalBuildArtifacts {
self.externalBuildArtifacts = externalArtifacts
} else if let externalTargetPaths = externalTargetModulePathMap {
self.externalBuildArtifacts = (externalTargetPaths, [:])
}

if case .subcommand = try Self.invocationRunMode(forArgs: args).mode {
throw Error.subcommandPassedToDriver
}
Expand Down Expand Up @@ -455,6 +463,14 @@ public struct Driver {
self.interModuleDependencyOracle = dependencyOracle
} else {
self.interModuleDependencyOracle = InterModuleDependencyOracle()

// This is a shim for backwards-compatibility with ModuleInfoMap-based API
// used by SwiftPM
if let externalArtifacts = externalBuildArtifacts {
if !externalArtifacts.1.isEmpty {
try self.interModuleDependencyOracle.mergeModules(from: externalArtifacts.1)
}
}
}

self.fileListThreshold = try Self.computeFileListThreshold(&self.parsedOptions, diagnosticsEngine: diagnosticsEngine)
Expand Down
6 changes: 3 additions & 3 deletions Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
let scanLibPath = try Driver.getScanLibPath(of: driver.toolchain,
hostTriple: driver.hostTriple,
env: ProcessEnv.vars)
let _ = try dependencyOracle
try dependencyOracle
.verifyOrCreateScannerInstance(fileSystem: localFileSystem,
swiftScanLibPath: scanLibPath)
try dependencyOracle.mergeModules(from: moduleDependencyGraph)
Expand Down Expand Up @@ -246,12 +246,12 @@ final class ExplicitModuleBuildTests: XCTestCase {
"test.swift", "-module-name", "A", "-g"]

var driver = try Driver(args: commandLine, executor: executor,
externalTargetModulePathMap: targetModulePathMap,
externalBuildArtifacts: (targetModulePathMap, [:]),
interModuleDependencyOracle: dependencyOracle)
let scanLibPath = try Driver.getScanLibPath(of: driver.toolchain,
hostTriple: driver.hostTriple,
env: ProcessEnv.vars)
let _ = try dependencyOracle
try dependencyOracle
.verifyOrCreateScannerInstance(fileSystem: localFileSystem,
swiftScanLibPath: scanLibPath)

Expand Down