Skip to content

Commit c931c60

Browse files
committed
Compute the host triple using -print-target-info and use it to resolve location of the scanning library.
1 parent 33be2f1 commit c931c60

File tree

3 files changed

+32
-17
lines changed

3 files changed

+32
-17
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ public struct Driver {
124124
/// The target triple.
125125
@_spi(Testing) public var targetTriple: Triple { frontendTargetInfo.target.triple }
126126

127+
/// The host environment triple.
128+
@_spi(Testing) public let hostTriple: Triple
129+
127130
/// The variant target triple.
128131
var targetVariantTriple: Triple? {
129132
frontendTargetInfo.targetVariant?.triple
@@ -385,6 +388,12 @@ public struct Driver {
385388
executor: self.executor, fileSystem: fileSystem,
386389
useStaticResourceDir: self.useStaticResourceDir)
387390

391+
// Compute the host machine's triple
392+
self.hostTriple =
393+
try Self.computeHostTriple(toolchain: self.toolchain,
394+
executor: self.executor,
395+
swiftCompilerPrefixArgs: self.swiftCompilerPrefixArgs)
396+
388397
// Classify and collect all of the input files.
389398
let inputFiles = try Self.collectInputFiles(&self.parsedOptions)
390399
self.inputFiles = inputFiles
@@ -2081,6 +2090,17 @@ extension Driver {
20812090
static let defaultToolchainType: Toolchain.Type = GenericUnixToolchain.self
20822091
#endif
20832092

2093+
static func computeHostTriple(toolchain: Toolchain,
2094+
executor: DriverExecutor,
2095+
swiftCompilerPrefixArgs: [String]) throws -> Triple {
2096+
return try executor.execute(
2097+
job: toolchain.printTargetInfoJob(target: nil, targetVariant: nil,
2098+
swiftCompilerPrefixArgs: swiftCompilerPrefixArgs),
2099+
capturingJSONOutputAs: FrontendTargetInfo.self,
2100+
forceResponseFiles: false,
2101+
recordedInputModificationDates: [:]).target.triple
2102+
}
2103+
20842104
static func computeToolchain(
20852105
_ parsedOptions: inout ParsedOptions,
20862106
diagnosticsEngine: DiagnosticsEngine,

Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ internal extension Driver {
9696
if (!parsedOptions.hasArgument(.driverScanDependenciesNonLib)) {
9797
try interModuleDependencyOracle
9898
.verifyOrCreateScannerInstance(fileSystem: fileSystem,
99-
swiftScanLibPath: try getScanLibPath(of: toolchain,
100-
target: targetTriple))
99+
swiftScanLibPath: try getScanLibPath(of: toolchain))
101100
let cwd = workingDirectory ?? fileSystem.currentWorkingDirectory!
102101
var command = try itemizedJobCommand(of: scannerJob,
103102
forceResponseFiles: forceResponseFiles,
@@ -130,8 +129,7 @@ internal extension Driver {
130129
if (!parsedOptions.hasArgument(.driverScanDependenciesNonLib)) {
131130
try interModuleDependencyOracle
132131
.verifyOrCreateScannerInstance(fileSystem: fileSystem,
133-
swiftScanLibPath: try getScanLibPath(of: toolchain,
134-
target: targetTriple))
132+
swiftScanLibPath: try getScanLibPath(of: toolchain))
135133
let cwd = workingDirectory ?? fileSystem.currentWorkingDirectory!
136134
var command = try itemizedJobCommand(of: batchScanningJob,
137135
forceResponseFiles: forceResponseFiles,
@@ -264,16 +262,16 @@ internal extension Driver {
264262
}
265263

266264
@_spi(Testing) public extension Driver {
267-
func getScanLibPath(of toolchain: Toolchain, target: Triple) throws -> AbsolutePath {
265+
func getScanLibPath(of toolchain: Toolchain) throws -> AbsolutePath {
268266
let sharedLibExt: String
269-
if target.isMacOSX {
267+
if hostTriple.isMacOSX {
270268
sharedLibExt = ".dylib"
271269
} else {
272270
sharedLibExt = ".so"
273271
}
274272
return try getRootPath(of: toolchain).appending(component: "lib")
275273
.appending(component: "swift")
276-
.appending(component: target.osNameUnversioned)
274+
.appending(component: hostTriple.osNameUnversioned)
277275
.appending(component: "lib_InternalSwiftScan" + sharedLibExt)
278276
}
279277

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
163163
let dependencyOracle = InterModuleDependencyOracle()
164164
try dependencyOracle
165165
.verifyOrCreateScannerInstance(fileSystem: localFileSystem,
166-
swiftScanLibPath: try driver.getScanLibPath(of: driver.toolchain,
167-
target: driver.targetTriple))
166+
swiftScanLibPath: try driver.getScanLibPath(of: driver.toolchain))
168167
try dependencyOracle.mergeModules(from: moduleDependencyGraph)
169168
driver.explicitDependencyBuildPlanner =
170169
try ExplicitDependencyBuildPlanner(dependencyGraph: moduleDependencyGraph,
@@ -233,8 +232,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
233232
interModuleDependencyOracle: dependencyOracle)
234233
try dependencyOracle
235234
.verifyOrCreateScannerInstance(fileSystem: localFileSystem,
236-
swiftScanLibPath: try driver.getScanLibPath(of: driver.toolchain,
237-
target: driver.targetTriple))
235+
swiftScanLibPath: try driver.getScanLibPath(of: driver.toolchain))
238236

239237
// Plan explicit dependency jobs, after resolving placeholders to actual dependencies.
240238
try moduleDependencyGraph.resolvePlaceholderDependencies(for: (targetModulePathMap, [:]),
@@ -521,8 +519,7 @@ final class ExplicitModuleBuildTests: XCTestCase {
521519
let dependencyOracle = InterModuleDependencyOracle()
522520
try dependencyOracle
523521
.verifyOrCreateScannerInstance(fileSystem: localFileSystem,
524-
swiftScanLibPath: try driver.getScanLibPath(of: driver.toolchain,
525-
target: driver.targetTriple))
522+
swiftScanLibPath: try driver.getScanLibPath(of: driver.toolchain))
526523

527524
// Create a simple test case.
528525
try withTemporaryDirectory { path in
@@ -547,14 +544,14 @@ final class ExplicitModuleBuildTests: XCTestCase {
547544
// Here purely to dump diagnostic output in a reasonable fashion when things go wrong.
548545
let lock = NSLock()
549546

550-
// Module `X` is only imported when:
547+
// Module `X` is only imported on Darwin when:
551548
// #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 110000
552549
let expectedNumberOfDependencies: Int
553550
if driver.targetTriple.isMacOSX,
554-
driver.targetTriple.version(for: .macOS) < Triple.Version(11, 0, 0) {
555-
expectedNumberOfDependencies = 12
556-
} else {
551+
driver.targetTriple.version(for: .macOS) >= Triple.Version(11, 0, 0) {
557552
expectedNumberOfDependencies = 11
553+
} else {
554+
expectedNumberOfDependencies = 12
558555
}
559556

560557
// Dispatch several iterations in parallel

0 commit comments

Comments
 (0)