Skip to content

Commit 33be2f1

Browse files
committed
Use target-platform-specific shared library file extension. (.so except for Darwin)
1 parent 7b0a9c4 commit 33be2f1

File tree

5 files changed

+33
-35
lines changed

5 files changed

+33
-35
lines changed

Sources/SwiftDriver/ExplicitModuleBuilds/ExplicitDependencyBuildPlanner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public typealias ExternalBuildArtifacts = (ExternalTargetModulePathMap, ModuleIn
3535
/// The toolchain to be used for frontend job generation.
3636
private let toolchain: Toolchain
3737

38-
/// Whether we are using the integrated driver via libSwiftDriver.dylib
38+
/// Whether we are using the integrated driver via libSwiftDriver shared lib
3939
private let integratedDriver: Bool
4040
private let mainModuleName: String?
4141

Sources/SwiftDriver/ExplicitModuleBuilds/InterModuleDependencies/InterModuleDependencyOracle.swift

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,11 @@ 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,
58-
osName: String) throws {
57+
swiftScanLibPath: AbsolutePath) throws {
5958
try queue.sync {
60-
let swiftScanLibPath = toolchainPath.appending(component: "lib")
61-
.appending(component: "swift")
62-
.appending(component: osName)
63-
.appending(component: "lib_InternalSwiftScan.dylib")
6459
if swiftScanLibInstance == nil {
65-
guard fileSystem.exists(toolchainPath) else {
66-
fatalError("Path to specified toolchain does not exist: \(toolchainPath.description)")
67-
}
68-
guard fileSystem.exists(toolchainPath) else {
69-
fatalError("Could not find libSwiftScan at: \(swiftScanLibPath.description)")
60+
guard fileSystem.exists(swiftScanLibPath) else {
61+
throw DependencyScanningError.scanningLibraryNotFound(swiftScanLibPath)
7062
}
7163
swiftScanLibInstance = try SwiftScan(dylib: swiftScanLibPath)
7264
} else {

Sources/SwiftDriver/ExplicitModuleBuilds/ModuleDependencyScanning.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ internal extension Driver {
9696
if (!parsedOptions.hasArgument(.driverScanDependenciesNonLib)) {
9797
try interModuleDependencyOracle
9898
.verifyOrCreateScannerInstance(fileSystem: fileSystem,
99-
toolchainPath: try getRootPath(of: toolchain),
100-
osName: targetTriple.osNameUnversioned)
99+
swiftScanLibPath: try getScanLibPath(of: toolchain,
100+
target: targetTriple))
101101
let cwd = workingDirectory ?? fileSystem.currentWorkingDirectory!
102102
var command = try itemizedJobCommand(of: scannerJob,
103103
forceResponseFiles: forceResponseFiles,
@@ -130,8 +130,8 @@ internal extension Driver {
130130
if (!parsedOptions.hasArgument(.driverScanDependenciesNonLib)) {
131131
try interModuleDependencyOracle
132132
.verifyOrCreateScannerInstance(fileSystem: fileSystem,
133-
toolchainPath: try getRootPath(of: toolchain),
134-
osName: targetTriple.osNameUnversioned)
133+
swiftScanLibPath: try getScanLibPath(of: toolchain,
134+
target: targetTriple))
135135
let cwd = workingDirectory ?? fileSystem.currentWorkingDirectory!
136136
var command = try itemizedJobCommand(of: batchScanningJob,
137137
forceResponseFiles: forceResponseFiles,
@@ -261,6 +261,21 @@ internal extension Driver {
261261
quotePaths: true)
262262
return args
263263
}
264+
}
265+
266+
@_spi(Testing) public extension Driver {
267+
func getScanLibPath(of toolchain: Toolchain, target: Triple) throws -> AbsolutePath {
268+
let sharedLibExt: String
269+
if target.isMacOSX {
270+
sharedLibExt = ".dylib"
271+
} else {
272+
sharedLibExt = ".so"
273+
}
274+
return try getRootPath(of: toolchain).appending(component: "lib")
275+
.appending(component: "swift")
276+
.appending(component: target.osNameUnversioned)
277+
.appending(component: "lib_InternalSwiftScan" + sharedLibExt)
278+
}
264279

265280
fileprivate func getRootPath(of toolchain: Toolchain) throws -> AbsolutePath {
266281
if let overrideString = env["SWIFT_DRIVER_SWIFT_SCAN_TOOLCHAIN_PATH"] {

Sources/SwiftDriver/SwiftScan/SwiftScan.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public enum DependencyScanningError: Error, DiagnosticData {
2525
case unsupportedDependencyDetailsKind(Int)
2626
case invalidStringPtr
2727
case scanningLibraryInvocationMismatch(AbsolutePath, AbsolutePath)
28+
case scanningLibraryNotFound(AbsolutePath)
2829

2930
public var description: String {
3031
switch self {
@@ -43,7 +44,9 @@ public enum DependencyScanningError: Error, DiagnosticData {
4344
case .invalidStringPtr:
4445
return "Dependency module details contains a corrupted string reference"
4546
case .scanningLibraryInvocationMismatch(let path1, let path2):
46-
return "Module scanning library differs across driver invocations: \(path1.description) and \(path2.description)"
47+
return "Dependency Scanning library differs across driver invocations: \(path1.description) and \(path2.description)"
48+
case .scanningLibraryNotFound(let path):
49+
return "Dependency Scanning library not found at path: \(path)"
4750
}
4851
}
4952
}

Tests/SwiftDriverTests/ExplicitModuleBuildTests.swift

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,11 @@ final class ExplicitModuleBuildTests: XCTestCase {
160160
try JSONDecoder().decode(
161161
InterModuleDependencyGraph.self,
162162
from: ModuleDependenciesInputs.fastDependencyScannerOutput.data(using: .utf8)!)
163-
let toolchainRootPath: AbsolutePath = try driver.toolchain.getToolPath(.swiftCompiler)
164-
.parentDirectory // bin
165-
.parentDirectory // toolchain root
166163
let dependencyOracle = InterModuleDependencyOracle()
167164
try dependencyOracle
168165
.verifyOrCreateScannerInstance(fileSystem: localFileSystem,
169-
toolchainPath: toolchainRootPath,
170-
osName: driver.targetTriple.osNameUnversioned)
166+
swiftScanLibPath: try driver.getScanLibPath(of: driver.toolchain,
167+
target: driver.targetTriple))
171168
try dependencyOracle.mergeModules(from: moduleDependencyGraph)
172169
driver.explicitDependencyBuildPlanner =
173170
try ExplicitDependencyBuildPlanner(dependencyGraph: moduleDependencyGraph,
@@ -217,15 +214,6 @@ final class ExplicitModuleBuildTests: XCTestCase {
217214
processSet: ProcessSet(),
218215
fileSystem: localFileSystem,
219216
env: ProcessEnv.vars)
220-
var toolchain: Toolchain
221-
#if os(macOS)
222-
toolchain = DarwinToolchain(env: ProcessEnv.vars, executor: executor)
223-
#else
224-
toolchain = GenericUnixToolchain(env: ProcessEnv.vars, executor: executor)
225-
#endif
226-
let toolchainRootPath: AbsolutePath = try toolchain.getToolPath(.swiftCompiler)
227-
.parentDirectory // bin
228-
.parentDirectory // toolchain root
229217
let dependencyOracle = InterModuleDependencyOracle()
230218
try dependencyOracle.mergeModules(from: inputDependencyGraph)
231219

@@ -245,8 +233,8 @@ final class ExplicitModuleBuildTests: XCTestCase {
245233
interModuleDependencyOracle: dependencyOracle)
246234
try dependencyOracle
247235
.verifyOrCreateScannerInstance(fileSystem: localFileSystem,
248-
toolchainPath: toolchainRootPath,
249-
osName: driver.targetTriple.osNameUnversioned)
236+
swiftScanLibPath: try driver.getScanLibPath(of: driver.toolchain,
237+
target: driver.targetTriple))
250238

251239
// Plan explicit dependency jobs, after resolving placeholders to actual dependencies.
252240
try moduleDependencyGraph.resolvePlaceholderDependencies(for: (targetModulePathMap, [:]),
@@ -533,8 +521,8 @@ final class ExplicitModuleBuildTests: XCTestCase {
533521
let dependencyOracle = InterModuleDependencyOracle()
534522
try dependencyOracle
535523
.verifyOrCreateScannerInstance(fileSystem: localFileSystem,
536-
toolchainPath: toolchainRootPath,
537-
osName: driver.targetTriple.osNameUnversioned)
524+
swiftScanLibPath: try driver.getScanLibPath(of: driver.toolchain,
525+
target: driver.targetTriple))
538526

539527
// Create a simple test case.
540528
try withTemporaryDirectory { path in

0 commit comments

Comments
 (0)