Skip to content

Commit c4a3aa5

Browse files
committed
[Explicit Module Build] Correctly discern libSwiftScan location in the os-specific directory of the toolchain
1 parent b2326f9 commit c4a3aa5

File tree

5 files changed

+48
-22
lines changed

5 files changed

+48
-22
lines changed

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyOracle.swift

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,26 @@ public class InterModuleDependencyOracle {
5454

5555
/// Given a specified toolchain path, locate and instantiate an instance of the SwiftScan library
5656
@_spi(Testing) public func verifyOrCreateScannerInstance(fileSystem: FileSystem,
57-
toolchainPath: AbsolutePath) throws {
57+
toolchainPath: AbsolutePath,
58+
osName: String) throws {
5859
try queue.sync {
60+
let swiftScanLibPath = toolchainPath.appending(component: "lib")
61+
.appending(component: "swift")
62+
.appending(component: osName)
63+
.appending(component: "lib_InternalSwiftScan.dylib")
5964
if swiftScanLibInstance == nil {
6065
guard fileSystem.exists(toolchainPath) else {
6166
fatalError("Path to specified toolchain does not exist: \(toolchainPath.description)")
6267
}
63-
64-
let swiftScanLibPath = toolchainPath.appending(component: "lib")
65-
.appending(component: "lib_InternalSwiftScan.dylib")
6668
guard fileSystem.exists(toolchainPath) else {
6769
fatalError("Could not find libSwiftScan at: \(swiftScanLibPath.description)")
6870
}
69-
7071
swiftScanLibInstance = try SwiftScan(dylib: swiftScanLibPath)
7172
} else {
72-
let swiftScanLibPath = toolchainPath.appending(component: "lib")
73-
.appending(component: "lib_InternalSwiftScan.dylib")
74-
assert(swiftScanLibInstance!.path == swiftScanLibPath)
73+
guard swiftScanLibInstance!.path == swiftScanLibPath else {
74+
throw DependencyScanningError
75+
.scanningLibraryInvocationMismatch(swiftScanLibInstance!.path, swiftScanLibPath)
76+
}
7577
}
7678
}
7779
}

Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,10 @@ internal extension Driver {
9494
let dependencyGraph: InterModuleDependencyGraph
9595

9696
if (!parsedOptions.hasArgument(.driverScanDependenciesNonLib)) {
97-
try interModuleDependencyOracle.verifyOrCreateScannerInstance(fileSystem: fileSystem,
98-
toolchainPath:
99-
try getRootPath(of: toolchain))
97+
try interModuleDependencyOracle
98+
.verifyOrCreateScannerInstance(fileSystem: fileSystem,
99+
toolchainPath: try getRootPath(of: toolchain),
100+
osName: targetTriple.osNameUnversioned)
100101
let cwd = workingDirectory ?? fileSystem.currentWorkingDirectory!
101102
var command = try itemizedJobCommand(of: scannerJob,
102103
forceResponseFiles: forceResponseFiles,
@@ -127,9 +128,10 @@ internal extension Driver {
127128

128129
let moduleVersionedGraphMap: [ModuleDependencyId: [InterModuleDependencyGraph]]
129130
if (!parsedOptions.hasArgument(.driverScanDependenciesNonLib)) {
130-
try interModuleDependencyOracle.verifyOrCreateScannerInstance(fileSystem: fileSystem,
131-
toolchainPath:
132-
try getRootPath(of: toolchain))
131+
try interModuleDependencyOracle
132+
.verifyOrCreateScannerInstance(fileSystem: fileSystem,
133+
toolchainPath: try getRootPath(of: toolchain),
134+
osName: targetTriple.osNameUnversioned)
133135
let cwd = workingDirectory ?? fileSystem.currentWorkingDirectory!
134136
var command = try itemizedJobCommand(of: batchScanningJob,
135137
forceResponseFiles: forceResponseFiles,

Sources/SwiftDriver/SwiftScan/SwiftScan.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public enum DependencyScanningError: Error, DiagnosticData {
2424
case moduleNameDecodeFailure(String)
2525
case unsupportedDependencyDetailsKind(Int)
2626
case invalidStringPtr
27+
case scanningLibraryInvocationMismatch(AbsolutePath, AbsolutePath)
2728

2829
public var description: String {
2930
switch self {
@@ -41,6 +42,8 @@ public enum DependencyScanningError: Error, DiagnosticData {
4142
return "Dependency module details field kind not supported: `\(kindRawValue)`"
4243
case .invalidStringPtr:
4344
return "Dependency module details contains a corrupted string reference"
45+
case .scanningLibraryInvocationMismatch(let path1, let path2):
46+
return "Module scanning library differs across driver invocations: \(path1.description) and \(path2.description)"
4447
}
4548
}
4649
}

Sources/SwiftDriver/Utilities/Triple.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1522,6 +1522,20 @@ extension Triple {
15221522

15231523
return Version(parse: osName)
15241524
}
1525+
1526+
public var osNameUnversioned: String {
1527+
var canonicalOsName = self.osName[...]
1528+
1529+
// Assume that the OS portion of the triple starts with the canonical name.
1530+
if let os = os {
1531+
if canonicalOsName.hasPrefix(os.name) {
1532+
canonicalOsName = osName.prefix(os.name.count)
1533+
} else if os == .macosx, osName.hasPrefix("macos") {
1534+
canonicalOsName = osName.prefix(5)
1535+
}
1536+
}
1537+
return String(canonicalOsName)
1538+
}
15251539
}
15261540

15271541
// MARK: - Darwin Versions

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ final class ExplicitModuleBuildTests: XCTestCase {
164164
.parentDirectory // bin
165165
.parentDirectory // toolchain root
166166
let dependencyOracle = InterModuleDependencyOracle()
167-
try dependencyOracle.verifyOrCreateScannerInstance(fileSystem: localFileSystem,
168-
toolchainPath: toolchainRootPath)
167+
try dependencyOracle
168+
.verifyOrCreateScannerInstance(fileSystem: localFileSystem,
169+
toolchainPath: toolchainRootPath,
170+
osName: driver.targetTriple.osNameUnversioned)
169171
try dependencyOracle.mergeModules(from: moduleDependencyGraph)
170172
driver.explicitDependencyBuildPlanner =
171173
try ExplicitDependencyBuildPlanner(dependencyGraph: moduleDependencyGraph,
@@ -225,8 +227,6 @@ final class ExplicitModuleBuildTests: XCTestCase {
225227
.parentDirectory // bin
226228
.parentDirectory // toolchain root
227229
let dependencyOracle = InterModuleDependencyOracle()
228-
try dependencyOracle.verifyOrCreateScannerInstance(fileSystem: localFileSystem,
229-
toolchainPath: toolchainRootPath)
230230
try dependencyOracle.mergeModules(from: inputDependencyGraph)
231231

232232
// Construct a module dependency graph that will contain .swiftPlaceholder("B"),
@@ -243,7 +243,10 @@ final class ExplicitModuleBuildTests: XCTestCase {
243243
var driver = try Driver(args: commandLine, executor: executor,
244244
externalBuildArtifacts: (targetModulePathMap, [:]),
245245
interModuleDependencyOracle: dependencyOracle)
246-
246+
try dependencyOracle
247+
.verifyOrCreateScannerInstance(fileSystem: localFileSystem,
248+
toolchainPath: toolchainRootPath,
249+
osName: driver.targetTriple.osNameUnversioned)
247250

248251
// Plan explicit dependency jobs, after resolving placeholders to actual dependencies.
249252
try moduleDependencyGraph.resolvePlaceholderDependencies(for: (targetModulePathMap, [:]),
@@ -523,9 +526,11 @@ final class ExplicitModuleBuildTests: XCTestCase {
523526
// The dependency oracle wraps an instance of libSwiftScan and ensures thread safety across
524527
// queries.
525528
let dependencyOracle = InterModuleDependencyOracle()
526-
try dependencyOracle.verifyOrCreateScannerInstance(fileSystem: localFileSystem,
527-
toolchainPath: toolchainRootPath)
528-
529+
try dependencyOracle
530+
.verifyOrCreateScannerInstance(fileSystem: localFileSystem,
531+
toolchainPath: toolchainRootPath,
532+
osName: driver.targetTriple.osNameUnversioned)
533+
529534
// Create a simple test case.
530535
try withTemporaryDirectory { path in
531536
let main = path.appending(component: "testDependencyScanning.swift")

0 commit comments

Comments
 (0)