Skip to content

Commit 5181dd9

Browse files
committed
unify some of the repeated useStaticResourceDir logic
1 parent d66f175 commit 5181dd9

File tree

3 files changed

+16
-27
lines changed

3 files changed

+16
-27
lines changed

Sources/SwiftDriver/Driver/Driver.swift

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,9 @@ public struct Driver {
126126
frontendTargetInfo.targetVariant?.triple
127127
}
128128

129+
/// `true` if the driver should use the static resource directory.
130+
let useStaticResourceDir: Bool
131+
129132
/// The kind of driver.
130133
let driverKind: DriverKind
131134

@@ -342,12 +345,21 @@ public struct Driver {
342345
try Self.applyWorkingDirectory(workingDirectory, to: &self.parsedOptions)
343346
}
344347

348+
let staticExecutable = parsedOptions.hasFlag(positive: .staticExecutable,
349+
negative: .noStaticExecutable,
350+
default: false)
351+
let staticStdlib = parsedOptions.hasFlag(positive: .staticStdlib,
352+
negative: .noStaticStdlib,
353+
default: false)
354+
self.useStaticResourceDir = staticExecutable || staticStdlib
355+
345356
// Build the toolchain and determine target information.
346357
(self.toolchain, self.frontendTargetInfo, self.swiftCompilerPrefixArgs) =
347358
try Self.computeToolchain(
348359
&self.parsedOptions, diagnosticsEngine: diagnosticEngine,
349360
compilerMode: self.compilerMode, env: env,
350-
executor: self.executor, fileSystem: fileSystem)
361+
executor: self.executor, fileSystem: fileSystem,
362+
useStaticResourceDir: self.useStaticResourceDir)
351363

352364
// Classify and collect all of the input files.
353365
let inputFiles = try Self.collectInputFiles(&self.parsedOptions)
@@ -1933,7 +1945,8 @@ extension Driver {
19331945
compilerMode: CompilerMode,
19341946
env: [String: String],
19351947
executor: DriverExecutor,
1936-
fileSystem: FileSystem
1948+
fileSystem: FileSystem,
1949+
useStaticResourceDir: Bool
19371950
) throws -> (Toolchain, FrontendTargetInfo, [String]) {
19381951
let explicitTarget = (parsedOptions.getLastArgument(.target)?.asSingle)
19391952
.map {
@@ -1952,16 +1965,6 @@ extension Driver {
19521965
resourceDirPath = nil
19531966
}
19541967

1955-
var useStaticResourceDir = false
1956-
if parsedOptions.hasFlag(positive: .staticExecutable,
1957-
negative: .noStaticExecutable,
1958-
default: false) ||
1959-
parsedOptions.hasFlag(positive: .staticStdlib,
1960-
negative: .noStaticStdlib,
1961-
default: false) {
1962-
useStaticResourceDir = true
1963-
}
1964-
19651968
let toolchainType = try explicitTarget?.toolchainType(diagnosticsEngine) ??
19661969
defaultToolchainType
19671970
// Find tools directory and pass it down to the toolchain

Sources/SwiftDriver/Jobs/FrontendJobHelpers.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,7 @@ extension Driver {
193193
commandLine.appendFlag(.resourceDir)
194194
commandLine.appendPath(frontendTargetInfo.runtimeResourcePath.path)
195195

196-
if parsedOptions.hasFlag(positive: .staticExecutable,
197-
negative: .noStaticExecutable,
198-
default: false) ||
199-
parsedOptions.hasFlag(positive: .staticStdlib,
200-
negative: .noStaticStdlib,
201-
default: false) {
196+
if self.useStaticResourceDir {
202197
commandLine.appendFlag("-use-static-resource-dir")
203198
}
204199

Sources/SwiftDriver/Jobs/Planning.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -438,15 +438,6 @@ extension Driver {
438438
if parsedOptions.hasArgument(.printTargetInfo) {
439439
let sdkPath = try parsedOptions.getLastArgument(.sdk).map { try VirtualPath(path: $0.asSingle) }
440440
let resourceDirPath = try parsedOptions.getLastArgument(.resourceDir).map { try VirtualPath(path: $0.asSingle) }
441-
var useStaticResourceDir = false
442-
if parsedOptions.hasFlag(positive: .staticExecutable,
443-
negative: .noStaticExecutable,
444-
default: false) ||
445-
parsedOptions.hasFlag(positive: .staticStdlib,
446-
negative: .noStaticStdlib,
447-
default: false) {
448-
useStaticResourceDir = true
449-
}
450441

451442
return try toolchain.printTargetInfoJob(target: targetTriple,
452443
targetVariant: targetVariantTriple,

0 commit comments

Comments
 (0)