Skip to content

Commit 1daa201

Browse files
committed
[5.10] Add and fix missing Triple tests (#6932)
Cherry-pick of #6843 Vendored Swift Driver triple was not checked against a few tests that weren't brought over from TSC after `TSC.Triple` type was deprecated. We should fix those tests, especially as they verified that per-component equality for triples worked instead of the current string-based equality check. (cherry picked from commit 8de70d3) ``` # Conflicts: # Tests/BasicsTests/TripleTests.swift ``` Related to rdar://113967401 Maybe related to rdar://115731621
1 parent 2d761c6 commit 1daa201

File tree

4 files changed

+36
-82
lines changed

4 files changed

+36
-82
lines changed

Sources/Basics/Triple+Basics.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,13 @@ extension Triple {
194194
self.arch == triple.arch &&
195195
self.vendor == triple.vendor &&
196196
self.os == triple.os &&
197-
self.environment == triple.environment
197+
self.environment == triple.environment,
198+
// If either of the triples have no `osVersion` specified, we can't determine compatibility and will
199+
// have to return `false`.
200+
let selfOSVersion = self.osVersion,
201+
let osVersion = triple.osVersion
198202
{
199-
return self.osVersion >= triple.osVersion
203+
return selfOSVersion >= osVersion
200204
} else {
201205
return false
202206
}

Sources/Basics/Vendor/Triple+Platforms.swift

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
//===--------------- Triple+Platforms.swift - Swift Platform Triples ------===//
1+
//===----------------------------------------------------------------------===//
22
//
3-
// This source file is part of the Swift.org open source project
3+
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
8-
// See https://swift.org/LICENSE.txt for license information
9-
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
1212

@@ -199,7 +199,7 @@ extension Triple {
199199
/// Not all combinations are valid; in particular, you cannot fetch a watchOS version
200200
/// from an iOS/tvOS triple or vice versa.
201201
public func version(for compatibilityPlatform: DarwinPlatform? = nil)
202-
-> Triple.Version
202+
-> Triple.Version?
203203
{
204204
switch compatibilityPlatform ?? darwinPlatform! {
205205
case .macOS:
@@ -239,53 +239,6 @@ extension Triple {
239239
}
240240
}
241241

242-
// The Darwin platform version used for linking.
243-
public var darwinLinkerPlatformVersion: Version {
244-
precondition(self.os?.isDarwin ?? false)
245-
switch darwinPlatform! {
246-
case .macOS:
247-
// The integrated driver falls back to `osVersion` for ivalid macOS
248-
// versions, this decision might be worth revisiting.
249-
let macVersion = _macOSVersion ?? osVersion
250-
// The first deployment of arm64 for macOS is version 11
251-
if macVersion.major < 11 && arch == .aarch64 {
252-
return Version(11, 0, 0)
253-
}
254-
255-
return macVersion
256-
case .iOS(.catalyst):
257-
// Mac Catalyst on arm was introduced with an iOS deployment target of
258-
// 14.0; the linker doesn't want to see a deployment target before that.
259-
if _iOSVersion.major < 14 && arch == .aarch64 {
260-
return Version(14, 0, 0)
261-
}
262-
263-
// Mac Catalyst was introduced with an iOS deployment target of 13.1;
264-
// the linker doesn't want to see a deployment target before that.
265-
if _iOSVersion.major < 13 {
266-
return Version(13, 1, 0)
267-
}
268-
269-
return _iOSVersion
270-
case .iOS(.device), .iOS(.simulator), .tvOS(_):
271-
// The first deployment of arm64 simulators is iOS/tvOS 14.0;
272-
// the linker doesn't want to see a deployment target before that.
273-
if _isSimulatorEnvironment && _iOSVersion.major < 14 && arch == .aarch64 {
274-
return Version(14, 0, 0)
275-
}
276-
277-
return _iOSVersion
278-
case .watchOS(_):
279-
// The first deployment of arm64 simulators is watchOS 7;
280-
// the linker doesn't want to see a deployment target before that.
281-
if _isSimulatorEnvironment && osVersion.major < 7 && arch == .aarch64 {
282-
return Version(7, 0, 0)
283-
}
284-
285-
return osVersion
286-
}
287-
}
288-
289242
/// The platform name, i.e. the name clang uses to identify this target in its
290243
/// resource directory.
291244
///
@@ -409,7 +362,8 @@ extension Triple {
409362
case .unavailable:
410363
return false
411364
case .available(let introducedVersion):
412-
return version(for: darwinPlatform) >= introducedVersion
365+
guard let tripleVersion = version(for: darwinPlatform) else { return false }
366+
return tripleVersion >= introducedVersion
413367
case .availableInAllVersions:
414368
return true
415369
}

Sources/Basics/Vendor/Triple.swift

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
//===--------------- Triple.swift - Swift Target Triples ------------------===//
1+
//===----------------------------------------------------------------------===//
22
//
3-
// This source file is part of the Swift.org open source project
3+
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2014 - 2019 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
8-
// See https://swift.org/LICENSE.txt for license information
9-
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
1212

@@ -72,14 +72,16 @@ public struct Triple {
7272

7373
/// Represents a version that may be present in the target triple.
7474
public struct Version: Equatable, Comparable, CustomStringConvertible {
75-
public static let zero = Version(0, 0, 0)
76-
7775
public var major: Int
7876
public var minor: Int
7977
public var micro: Int
8078

81-
public init<S: StringProtocol>(parse string: S) {
82-
let components = string.split(separator: ".", maxSplits: 3).map{ Int($0) ?? 0 }
79+
public init?(parse string: some StringProtocol) {
80+
guard !string.isEmpty else {
81+
return nil
82+
}
83+
84+
let components = string.split(separator: ".", maxSplits: 3).map { Int($0) ?? 0 }
8385
self.major = components.count > 0 ? components[0] : 0
8486
self.minor = components.count > 1 ? components[1] : 0
8587
self.micro = components.count > 2 ? components[2] : 0
@@ -162,10 +164,9 @@ public struct Triple {
162164

163165
// Now that we've parsed everything, we construct a normalized form of the
164166
// triple string.
165-
triple = parser.components.map({ $0.isEmpty ? "unknown" : $0 }).joined(separator: "-")
166-
}
167-
else {
168-
triple = string
167+
self.triple = parser.components.map { $0.isEmpty ? "unknown" : $0 }.joined(separator: "-")
168+
} else {
169+
self.triple = string
169170
}
170171

171172
// Unpack the parsed data into the fields. If no environment info was found,
@@ -1526,7 +1527,7 @@ extension Triple {
15261527
/// `darwin` OS version number is not adjusted to match the equivalent
15271528
/// `macosx` version number. It's usually better to use `version(for:)`
15281529
/// to get Darwin versions.
1529-
public var osVersion: Version {
1530+
public var osVersion: Version? {
15301531
var osName = self.osName[...]
15311532

15321533
// Assume that the OS portion of the triple starts with the canonical name.
@@ -1569,7 +1570,9 @@ extension Triple {
15691570
/// This accessor is semi-private; it's typically better to use `version(for:)` or
15701571
/// `Triple.FeatureAvailability`.
15711572
public var _macOSVersion: Version? {
1572-
var version = osVersion
1573+
guard var version = osVersion else {
1574+
return nil
1575+
}
15731576

15741577
switch os {
15751578
case .darwin:
@@ -1623,7 +1626,7 @@ extension Triple {
16231626
///
16241627
/// This accessor is semi-private; it's typically better to use `version(for:)` or
16251628
/// `Triple.FeatureAvailability`.
1626-
public var _iOSVersion: Version {
1629+
public var _iOSVersion: Version? {
16271630
switch os {
16281631
case .darwin, .macosx:
16291632
// Ignore the version from the triple. This is only handled because the
@@ -1632,7 +1635,7 @@ extension Triple {
16321635
// OS X.
16331636
return Version(5, 0, 0)
16341637
case .ios, .tvos:
1635-
var version = self.osVersion
1638+
guard var version = self.osVersion else { return nil }
16361639
// Default to 5.0 (or 7.0 for arm64).
16371640
if version.major == 0 {
16381641
version.major = arch == .aarch64 ? 7 : 5
@@ -1650,7 +1653,7 @@ extension Triple {
16501653
///
16511654
/// This accessor is semi-private; it's typically better to use `version(for:)` or
16521655
/// `Triple.FeatureAvailability`.
1653-
public var _watchOSVersion: Version {
1656+
public var _watchOSVersion: Version? {
16541657
switch os {
16551658
case .darwin, .macosx:
16561659
// Ignore the version from the triple. This is only handled because the
@@ -1659,7 +1662,7 @@ extension Triple {
16591662
// OS X.
16601663
return Version(2, 0, 0)
16611664
case .watchos:
1662-
var version = self.osVersion
1665+
guard var version = self.osVersion else { return nil }
16631666
if version.major == 0 {
16641667
version.major = 2
16651668
}

Tests/BasicsTests/TripleTests.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -220,11 +220,4 @@ final class TripleTests: XCTestCase {
220220
try XCTAssertFalse(Triple("x86_64-apple-macosx").isRuntimeCompatible(with: Triple("x86_64-apple-linux")))
221221
try XCTAssertTrue(Triple("x86_64-apple-macosx14.0").isRuntimeCompatible(with: Triple("x86_64-apple-macosx13.0")))
222222
}
223-
224-
func testIsRuntimeCompatibleWith() throws {
225-
try XCTAssertTrue(Triple("x86_64-apple-macosx").isRuntimeCompatible(with: Triple("x86_64-apple-macosx")))
226-
try XCTAssertTrue(Triple("x86_64-unknown-linux").isRuntimeCompatible(with: Triple("x86_64-unknown-linux")))
227-
try XCTAssertFalse(Triple("x86_64-apple-macosx").isRuntimeCompatible(with: Triple("x86_64-apple-linux")))
228-
try XCTAssertTrue(Triple("x86_64-apple-macosx14.0").isRuntimeCompatible(with: Triple("x86_64-apple-macosx13.0")))
229-
}
230223
}

0 commit comments

Comments
 (0)