@@ -143,7 +143,9 @@ public struct Driver {
143
143
public let incrementalCompilation : IncrementalCompilation
144
144
145
145
/// The path of the SDK.
146
- public let sdkPath : String ?
146
+ public var sdkPath : String ? {
147
+ frontendTargetInfo. paths. sdkPath
148
+ }
147
149
148
150
/// The path to the imported Objective-C header.
149
151
public let importedObjCHeader : VirtualPath ?
@@ -251,9 +253,14 @@ public struct Driver {
251
253
self . optionTable = OptionTable ( )
252
254
self . parsedOptions = try optionTable. parse ( Array ( args) , for: self . driverKind)
253
255
256
+ // Determine the compilation mode.
257
+ self . compilerMode = try Self . computeCompilerMode ( & parsedOptions, driverKind: driverKind, diagnosticsEngine: diagnosticEngine)
258
+
259
+ // Build the toolchain and determine target information.
254
260
( self . toolchain, self . frontendTargetInfo, self . swiftCompilerPrefixArgs) =
255
261
try Self . computeToolchain (
256
- & self . parsedOptions, diagnosticsEngine: diagnosticEngine, env: env,
262
+ & self . parsedOptions, diagnosticsEngine: diagnosticEngine,
263
+ compilerMode: self . compilerMode, env: env,
257
264
executor: self . executor, fileSystem: fileSystem)
258
265
259
266
// Compute the working directory.
@@ -296,9 +303,6 @@ public struct Driver {
296
303
self . outputFileMap = outputFileMap
297
304
}
298
305
299
- // Determine the compilation mode.
300
- self . compilerMode = try Self . computeCompilerMode ( & parsedOptions, driverKind: driverKind, diagnosticsEngine: diagnosticEngine)
301
-
302
306
// Figure out the primary outputs from the driver.
303
307
( self . compilerOutputType, self . linkerOutputType) = Self . determinePrimaryOutputs ( & parsedOptions, driverKind: driverKind, diagnosticsEngine: diagnosticEngine)
304
308
@@ -333,8 +337,6 @@ public struct Driver {
333
337
// Local variable to alias the target triple, because self.targetTriple
334
338
// is not available until the end of this initializer.
335
339
let targetTriple = self . frontendTargetInfo. target. triple
336
- self . sdkPath = Self . computeSDKPath ( & parsedOptions, compilerMode: compilerMode, toolchain: toolchain, targetTriple: targetTriple,
337
- fileSystem: fileSystem, diagnosticsEngine: diagnosticEngine, env: env)
338
340
339
341
self . importedObjCHeader = try Self . computeImportedObjCHeader ( & parsedOptions, compilerMode: compilerMode, diagnosticEngine: diagnosticEngine)
340
342
self . bridgingPrecompiledHeader = try Self . computeBridgingPrecompiledHeader ( & parsedOptions,
@@ -1411,25 +1413,20 @@ extension Driver {
1411
1413
_ parsedOptions: inout ParsedOptions ,
1412
1414
compilerMode: CompilerMode ,
1413
1415
toolchain: Toolchain ,
1414
- targetTriple: Triple ,
1416
+ targetTriple: Triple ? ,
1415
1417
fileSystem: FileSystem ,
1416
1418
diagnosticsEngine: DiagnosticsEngine ,
1417
1419
env: [ String : String ]
1418
- ) -> String ? {
1420
+ ) -> VirtualPath ? {
1419
1421
var sdkPath : String ?
1420
1422
1421
1423
if let arg = parsedOptions. getLastArgument ( . sdk) {
1422
1424
sdkPath = arg. asSingle
1423
1425
} else if let SDKROOT = env [ " SDKROOT " ] {
1424
1426
sdkPath = SDKROOT
1425
1427
} else if compilerMode == . immediate || compilerMode == . repl {
1426
- if targetTriple. isMacOSX == true {
1427
- // In immediate modes, use the SDK provided by xcrun.
1428
- // This will prefer the SDK alongside the Swift found by "xcrun swift".
1429
- // We don't do this in compilation modes because defaulting to the
1430
- // latest SDK may not be intended.
1431
- sdkPath = try ? toolchain. defaultSDKPath ( ) ? . pathString
1432
- }
1428
+ // In immediate modes, query the toolchain for a default SDK.
1429
+ sdkPath = try ? toolchain. defaultSDKPath ( targetTriple) ? . pathString
1433
1430
}
1434
1431
1435
1432
// An empty string explicitly clears the SDK.
@@ -1451,16 +1448,18 @@ extension Driver {
1451
1448
path = AbsolutePath ( sdkPath, relativeTo: cwd)
1452
1449
} else {
1453
1450
diagnosticsEngine. emit ( . warning_no_such_sdk( sdkPath) )
1454
- return sdkPath
1451
+ return nil
1455
1452
}
1456
1453
1457
1454
if !fileSystem. exists ( path) {
1458
1455
diagnosticsEngine. emit ( . warning_no_such_sdk( sdkPath) )
1459
1456
}
1460
1457
// .. else check if SDK is too old (we need target triple to diagnose that).
1458
+
1459
+ return . absolute( path)
1461
1460
}
1462
1461
1463
- return sdkPath
1462
+ return nil
1464
1463
}
1465
1464
}
1466
1465
@@ -1570,6 +1569,7 @@ extension Driver {
1570
1569
static func computeToolchain(
1571
1570
_ parsedOptions: inout ParsedOptions ,
1572
1571
diagnosticsEngine: DiagnosticsEngine ,
1572
+ compilerMode: CompilerMode ,
1573
1573
env: [ String : String ] ,
1574
1574
executor: DriverExecutor ,
1575
1575
fileSystem: FileSystem
@@ -1583,9 +1583,13 @@ extension Driver {
1583
1583
Triple ( $0, normalizing: true )
1584
1584
}
1585
1585
1586
- // FIXME: Compute these.
1587
- let sdkPath : VirtualPath ? = nil
1588
- let resourceDirPath : VirtualPath ? = nil
1586
+ // Determine the resource directory.
1587
+ let resourceDirPath : VirtualPath ?
1588
+ if let resourceDirArg = parsedOptions. getLastArgument ( . resourceDir) {
1589
+ resourceDirPath = try VirtualPath ( path: resourceDirArg. asSingle)
1590
+ } else {
1591
+ resourceDirPath = nil
1592
+ }
1589
1593
1590
1594
let toolchainType = try explicitTarget? . toolchainType ( diagnosticsEngine) ??
1591
1595
defaultToolchainType
@@ -1609,6 +1613,12 @@ extension Driver {
1609
1613
swiftCompilerPrefixArgs = [ ]
1610
1614
}
1611
1615
1616
+ // Find the SDK, if any.
1617
+ let sdkPath : VirtualPath ? = Self . computeSDKPath (
1618
+ & parsedOptions, compilerMode: compilerMode, toolchain: toolchain,
1619
+ targetTriple: explicitTarget, fileSystem: fileSystem,
1620
+ diagnosticsEngine: diagnosticsEngine, env: env)
1621
+
1612
1622
// Query the frontend to for target information.
1613
1623
var info = try executor. execute (
1614
1624
job: toolchain. printTargetInfoJob (
0 commit comments