-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Gate 6.0 dependent tests with a 6.0 compiler check
- Loading branch information
1 parent
5f4278c
commit 417bfc8
Showing
10 changed files
with
127 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See http://swift.org/LICENSE.txt for license information | ||
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import Basics | ||
import PackageModel | ||
import RegexBuilder | ||
import XCTest | ||
|
||
import class TSCBasic.Process | ||
import struct TSCBasic.StringError | ||
|
||
extension Toolchain { | ||
package func skipUnlessSwiftVersion( | ||
major: Int, | ||
minor: Int, | ||
file: StaticString = #file, | ||
line: UInt = #line | ||
) async throws { | ||
let currentVersion = try await getSwiftVersion(swiftCompilerPath) | ||
guard let currentVersion else { | ||
throw StringError("Failed to fine Swift version for '\(swiftCompilerPath)'") | ||
} | ||
|
||
if currentVersion.major < major || currentVersion.minor < minor { | ||
throw XCTSkip(""" | ||
Skipping because toolchain has Swift version \(currentVersion.major).\(currentVersion.minor) \ | ||
but test requires at least \(major).\(minor) | ||
""", file: file, line: line) | ||
} | ||
} | ||
} | ||
|
||
/// Return the major and minor version of Swift for a `swiftc` compiler at `swiftcPath`. | ||
fileprivate func getSwiftVersion(_ swiftcPath: AbsolutePath) async throws -> (major: Int, minor: Int)? { | ||
let process = Process(args: swiftcPath.pathString, "--version") | ||
try process.launch() | ||
let result = try await process.waitUntilExit() | ||
let output = String(bytes: try result.output.get(), encoding: .utf8) | ||
let regex = Regex { | ||
"Swift version " | ||
Capture { OneOrMore(.digit) } | ||
"." | ||
Capture { OneOrMore(.digit) } | ||
} | ||
guard let match = output?.firstMatch(of: regex) else { | ||
return nil | ||
} | ||
guard let major = Int(match.1), let minor = Int(match.2) else { | ||
return nil | ||
} | ||
return (major, minor) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters