From 2a0afcec10bc960e5ea9707c0684fa681175912c Mon Sep 17 00:00:00 2001 From: Xi Ge Date: Wed, 9 Aug 2023 15:45:46 -0700 Subject: [PATCH] Teach version requests to include the version of the separately installed blocklist --- Sources/SwiftDriver/Driver/Driver.swift | 15 +++++++++++++++ .../lib/swift/compilerClientsConfig_version.txt | 1 + Tests/SwiftDriverTests/SwiftDriverTests.swift | 6 ++++++ 3 files changed, 22 insertions(+) create mode 100644 TestInputs/Dummy.xctoolchain/usr/local/lib/swift/compilerClientsConfig_version.txt diff --git a/Sources/SwiftDriver/Driver/Driver.swift b/Sources/SwiftDriver/Driver/Driver.swift index 5d6d3b3ff..21a0dd410 100644 --- a/Sources/SwiftDriver/Driver/Driver.swift +++ b/Sources/SwiftDriver/Driver/Driver.swift @@ -459,6 +459,18 @@ public struct Driver { return results } + @_spi(Testing) + public static func findCompilerClientsConfigVersion(RelativeTo execDir: AbsolutePath) throws -> String? { + // Expect to find all blocklists in such dir: + // .../XcodeDefault.xctoolchain/usr/local/lib/swift/compilerClientsConfig_version.txt + let versionFilePath = execDir.parentDirectory + .appending(components: "local", "lib", "swift", "compilerClientsConfig_version.txt") + if (localFileSystem.exists(versionFilePath)) { + return try localFileSystem.readFileContents(versionFilePath).cString + } + return nil + } + /// Handler for emitting diagnostics to stderr. public static let stderrDiagnosticsHandler: DiagnosticsEngine.DiagnosticsHandler = { diagnostic in stdErrQueue.sync { @@ -1504,6 +1516,9 @@ extension Driver { // versions. if inPlaceJob.kind == .versionRequest && !Driver.driverSourceVersion.isEmpty { stderrStream <<< "swift-driver version: " <<< Driver.driverSourceVersion <<< " " + if let blocklistVersion = try Driver.findCompilerClientsConfigVersion(RelativeTo: try toolchain.executableDir) { + stderrStream <<< blocklistVersion <<< " " + } stderrStream.flush() } // In verbose mode, print out the job diff --git a/TestInputs/Dummy.xctoolchain/usr/local/lib/swift/compilerClientsConfig_version.txt b/TestInputs/Dummy.xctoolchain/usr/local/lib/swift/compilerClientsConfig_version.txt new file mode 100644 index 000000000..5d680de77 --- /dev/null +++ b/TestInputs/Dummy.xctoolchain/usr/local/lib/swift/compilerClientsConfig_version.txt @@ -0,0 +1 @@ +compilerClientsConfig-9999.99.9 \ No newline at end of file diff --git a/Tests/SwiftDriverTests/SwiftDriverTests.swift b/Tests/SwiftDriverTests/SwiftDriverTests.swift index f8e8a070b..2da48bc67 100644 --- a/Tests/SwiftDriverTests/SwiftDriverTests.swift +++ b/Tests/SwiftDriverTests/SwiftDriverTests.swift @@ -7069,6 +7069,12 @@ final class SwiftDriverTests: XCTestCase { XCTAssertTrue(list.allSatisfy { $0.extension! == "yml" || $0.extension! == "yaml"}) } + func testFindingBlockListVersion() throws { + let execDir = testInputsPath.appending(components: "Dummy.xctoolchain", "usr", "bin") + let version = try Driver.findCompilerClientsConfigVersion(RelativeTo: execDir) + XCTAssertEqual(version, "compilerClientsConfig-9999.99.9") + } + func testToolSearching() throws { #if os(Windows) let PATH = "Path"