Skip to content

Commit 11db1f7

Browse files
authored
Fix checkSupportedFrontendFlags (#6192)
Since this is querying a concrete compiler, it needs to receive the `Toolchain` object from the context in order to query the right one.
1 parent ae14833 commit 11db1f7

File tree

7 files changed

+12
-9
lines changed

7 files changed

+12
-9
lines changed

Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ let package = Package(
326326
.target(
327327
name: "DriverSupport",
328328
dependencies: [
329-
"Basics",
329+
"Basics",
330+
"PackageModel",
330331
.product(name: "SwiftDriver", package: "swift-driver"),
331332
],
332333
exclude: ["CMakeLists.txt"]

Sources/Build/BuildOperation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public final class BuildOperation: PackageStructureDelegate, SPMBuildCore.BuildS
171171
return
172172
}
173173
// Ensure the compiler supports the import-scan operation
174-
guard DriverSupport.checkSupportedFrontendFlags(flags: ["import-prescan"], fileSystem: localFileSystem) else {
174+
guard DriverSupport.checkSupportedFrontendFlags(flags: ["import-prescan"], toolchain: self.buildParameters.toolchain, fileSystem: localFileSystem) else {
175175
return
176176
}
177177

Sources/Commands/Utilities/SymbolGraphExtract.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public struct SymbolGraphExtract {
7575
}
7676

7777
let extensionBlockSymbolsFlag = emitExtensionBlockSymbols ? "-emit-extension-block-symbols" : "-omit-extension-block-symbols"
78-
if DriverSupport.checkSupportedFrontendFlags(flags: [extensionBlockSymbolsFlag.trimmingCharacters(in: ["-"])], fileSystem: fileSystem) {
78+
if DriverSupport.checkSupportedFrontendFlags(flags: [extensionBlockSymbolsFlag.trimmingCharacters(in: ["-"])], toolchain: buildParameters.toolchain, fileSystem: fileSystem) {
7979
commandLine += [extensionBlockSymbolsFlag]
8080
} else {
8181
observabilityScope.emit(warning: "dropped \(extensionBlockSymbolsFlag) flag because it is not supported by this compiler version")

Sources/CoreCommands/SwiftTool.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ public final class SwiftTool {
624624
workers: options.build.jobs ?? UInt32(ProcessInfo.processInfo.activeProcessorCount),
625625
shouldLinkStaticSwiftStdlib: options.linker.shouldLinkStaticSwiftStdlib,
626626
canRenameEntrypointFunctionName: DriverSupport.checkSupportedFrontendFlags(
627-
flags: ["entry-point-function-name"], fileSystem: self.fileSystem
627+
flags: ["entry-point-function-name"], toolchain: destinationToolchain, fileSystem: self.fileSystem
628628
),
629629
sanitizers: options.build.enabledSanitizers,
630630
enableCodeCoverage: false, // set by test commands when appropriate
@@ -718,11 +718,11 @@ public final class SwiftTool {
718718

719719
var extraManifestFlags = self.options.build.manifestFlags
720720
// Disable the implicit concurrency import if the compiler in use supports it to avoid warnings if we are building against an older SDK that does not contain a Concurrency module.
721-
if DriverSupport.checkSupportedFrontendFlags(flags: ["disable-implicit-concurrency-module-import"], fileSystem: self.fileSystem) {
721+
if DriverSupport.checkSupportedFrontendFlags(flags: ["disable-implicit-concurrency-module-import"], toolchain: try self.buildParameters().toolchain, fileSystem: self.fileSystem) {
722722
extraManifestFlags += ["-Xfrontend", "-disable-implicit-concurrency-module-import"]
723723
}
724724
// Disable the implicit string processing import if the compiler in use supports it to avoid warnings if we are building against an older SDK that does not contain a StringProcessing module.
725-
if DriverSupport.checkSupportedFrontendFlags(flags: ["disable-implicit-string-processing-module-import"], fileSystem: self.fileSystem) {
725+
if DriverSupport.checkSupportedFrontendFlags(flags: ["disable-implicit-string-processing-module-import"], toolchain: try self.buildParameters().toolchain, fileSystem: self.fileSystem) {
726726
extraManifestFlags += ["-Xfrontend", "-disable-implicit-string-processing-module-import"]
727727
}
728728

Sources/DriverSupport/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ set_target_properties(DriverSupport PROPERTIES
1414
INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY})
1515
target_link_libraries(DriverSupport PUBLIC
1616
Basics
17+
PackageModel
1718
SwiftDriver)
1819

1920
if(USE_CMAKE_INSTALL)

Sources/DriverSupport/DriverSupportUtils.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import SwiftDriver
1414
import Basics
15+
import PackageModel
1516
import class TSCBasic.Process
1617
import enum TSCBasic.ProcessEnv
1718
import struct TSCBasic.ProcessResult
@@ -22,10 +23,10 @@ public class DriverSupport {
2223
public init() {}
2324

2425
// This checks supported _frontend_ flags, which are not necessarily supported in the driver.
25-
public static func checkSupportedFrontendFlags(flags: Set<String>, fileSystem: FileSystem) -> Bool {
26+
public static func checkSupportedFrontendFlags(flags: Set<String>, toolchain: PackageModel.Toolchain, fileSystem: FileSystem) -> Bool {
2627
do {
2728
let executor = try SPMSwiftDriverExecutor(resolver: ArgsResolver(fileSystem: fileSystem), fileSystem: fileSystem, env: [:])
28-
let driver = try Driver(args: ["swiftc"], executor: executor)
29+
let driver = try Driver(args: ["swiftc"], executor: executor, compilerExecutableDir: toolchain.swiftCompilerPath.parentDirectory)
2930
return driver.supportedFrontendFlags.intersection(flags) == flags
3031
} catch {
3132
return false

Tests/CommandsTests/APIDiffTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ final class APIDiffTests: CommandsTestCase {
5353
// not all of which can be tested for easily. Fortunately, we can test for the
5454
// `-disable-fail-on-error` option, and any version which supports this flag
5555
// will meet the other requirements.
56-
guard DriverSupport.checkSupportedFrontendFlags(flags: ["disable-fail-on-error"], fileSystem: localFileSystem) else {
56+
guard DriverSupport.checkSupportedFrontendFlags(flags: ["disable-fail-on-error"], toolchain: try UserToolchain.default, fileSystem: localFileSystem) else {
5757
throw XCTSkip("swift-api-digester is too old")
5858
}
5959
}

0 commit comments

Comments
 (0)