Skip to content

Commit 5c034dd

Browse files
committed
Disuse unversioned triples on non-Darwin platforms.
The target flag should take the versioned triple, otherwise on platforms with versioned triples, the standard library won't be found. On Darwin, the unversioned triple should still be used throughout. This necessitates special-casing in the bootstrap script and when making subdirectories during the build. This platform-specific branch is encapsulated in a small extension on Triple in swiftpm. All tests that use the `tripleString` to construct the `.build` subdirectory are updated accordingly. See TSC pr #229.
1 parent c3bd142 commit 5c034dd

15 files changed

+67
-35
lines changed

Sources/Basics/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ add_library(Basics
1717
HTTPClient.swift
1818
JSON+Extensions.swift
1919
Sandbox.swift
20+
Triple+Extensions.swift
2021
SwiftVersion.swift
2122
SQLiteBackedCache.swift
2223
Version+Extensions.swift)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import TSCUtility
12+
13+
extension Triple {
14+
public func platformBuildPathComponent() -> String {
15+
if isDarwin() {
16+
return tripleString(forPlatformVersion: "")
17+
}
18+
19+
return tripleString
20+
}
21+
}

Sources/Commands/SwiftTool.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,8 @@ public class SwiftTool {
658658
// FIXME: At the moment we just pass the built products directory for the host. We will need to extend this
659659
// with a map of the names of tools available to each plugin. In particular this would not work with any
660660
// binary targets.
661-
let builtToolsDir = dataDir.appending(components: try self._hostToolchain.get().triple.tripleString, buildEnvironment.configuration.dirname)
661+
let hostTriple = try self._hostToolchain.get().triple
662+
let builtToolsDir = dataDir.appending(components: hostTriple.platformBuildPathComponent(), buildEnvironment.configuration.dirname)
662663
let diagnostics = DiagnosticsEngine()
663664

664665
// Create the cache directory, if needed.
@@ -771,7 +772,7 @@ public class SwiftTool {
771772
// can be used to build for any Apple platform and it has it's own
772773
// conventions for build subpaths based on platforms.
773774
let dataPath = buildPath.appending(
774-
component: options.buildSystem == .xcode ? "apple" : triple.tripleString)
775+
component: options.buildSystem == .xcode ? "apple" : triple.platformBuildPathComponent())
775776
return BuildParameters(
776777
dataPath: dataPath,
777778
configuration: options.configuration,

Sources/SPMBuildCore/BinaryTarget+Extensions.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ extension BinaryTarget {
6565
// Construct an ExecutableInfo for each matching variant.
6666
return executables.flatMap { entry in
6767
// FIXME: this filter needs to become more sophisticated
68-
entry.value.variants.filter{ $0.supportedTriples.contains(triple) }.map{
68+
entry.value.variants.filter {
69+
let tripleStrings = $0.supportedTriples.map { $0.tripleString }
70+
if triple.isDarwin() {
71+
return tripleStrings.contains(triple.tripleString(forPlatformVersion: ""))
72+
} else {
73+
return tripleStrings.contains(triple.tripleString)
74+
}
75+
}.map{
6976
ExecutableInfo(name: entry.key, executablePath: self.artifactPath.appending(RelativePath($0.path)))
7077
}
7178
}

Tests/CommandsTests/BuildToolTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ final class BuildToolTests: XCTestCase {
7575
func testBinPathAndSymlink() throws {
7676
fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { path in
7777
let fullPath = resolveSymlinks(path)
78-
let targetPath = fullPath.appending(components: ".build", UserToolchain.default.triple.tripleString)
78+
let targetPath = fullPath.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent())
7979
let xcbuildTargetPath = fullPath.appending(components: ".build", "apple")
8080
XCTAssertEqual(try execute(["--show-bin-path"], packagePath: fullPath).stdout,
8181
"\(targetPath.appending(component: "debug").pathString)\n")

Tests/CommandsTests/PackageToolTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ final class PackageToolTests: XCTestCase {
588588
_ = try SwiftPMProduct.SwiftPackage.execute(["edit", "baz", "--branch", "bugfix"], packagePath: fooPath)
589589

590590
// Path to the executable.
591-
let exec = [fooPath.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "foo").pathString]
591+
let exec = [fooPath.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "foo").pathString]
592592

593593
// We should see it now in packages directory.
594594
let editsPath = fooPath.appending(components: "Packages", "bar")
@@ -662,7 +662,7 @@ final class PackageToolTests: XCTestCase {
662662
// Build it.
663663
XCTAssertBuilds(packageRoot)
664664
let buildPath = packageRoot.appending(component: ".build")
665-
let binFile = buildPath.appending(components: UserToolchain.default.triple.tripleString, "debug", "Bar")
665+
let binFile = buildPath.appending(components: UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Bar")
666666
XCTAssertFileExists(binFile)
667667
XCTAssert(localFileSystem.isDirectory(buildPath))
668668

@@ -681,7 +681,7 @@ final class PackageToolTests: XCTestCase {
681681
// Build it.
682682
XCTAssertBuilds(packageRoot)
683683
let buildPath = packageRoot.appending(component: ".build")
684-
let binFile = buildPath.appending(components: UserToolchain.default.triple.tripleString, "debug", "Bar")
684+
let binFile = buildPath.appending(components: UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Bar")
685685
XCTAssertFileExists(binFile)
686686
XCTAssert(localFileSystem.isDirectory(buildPath))
687687
// Clean, and check for removal of the build directory but not Packages.
@@ -751,7 +751,7 @@ final class PackageToolTests: XCTestCase {
751751
func build() throws -> String {
752752
return try SwiftPMProduct.SwiftBuild.execute([], packagePath: fooPath).stdout
753753
}
754-
let exec = [fooPath.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "foo").pathString]
754+
let exec = [fooPath.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "foo").pathString]
755755

756756
// Build and sanity check.
757757
_ = try build()

Tests/FunctionalPerformanceTests/BuildPerfTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class BuildPerfTests: XCTestCasePerf {
5656
fixture(name: name) { prefix in
5757
let app = prefix.appending(components: (appString ?? ""))
5858
let triple = UserToolchain.default.triple
59-
let product = app.appending(components: ".build", triple.tripleString, "debug", productString)
59+
let product = app.appending(components: ".build", triple.platformBuildPathComponent(), "debug", productString)
6060
try self.execute(packagePath: app)
6161
measure {
6262
try! self.clean(packagePath: app)
@@ -70,7 +70,7 @@ class BuildPerfTests: XCTestCasePerf {
7070
fixture(name: name) { prefix in
7171
let app = prefix.appending(components: (appString ?? ""))
7272
let triple = UserToolchain.default.triple
73-
let product = app.appending(components: ".build", triple.tripleString, "debug", productString)
73+
let product = app.appending(components: ".build", triple.platformBuildPathComponent(), "debug", productString)
7474
try self.execute(packagePath: app)
7575
measure {
7676
try! self.execute(packagePath: app)

Tests/FunctionalTests/CFamilyTargetTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CFamilyTargetTestCase: XCTestCase {
3636
func testCLibraryWithSpaces() {
3737
fixture(name: "CFamilyTargets/CLibraryWithSpaces") { prefix in
3838
XCTAssertBuilds(prefix)
39-
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug")
39+
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
4040
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Bar.c.o")
4141
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
4242
}
@@ -46,7 +46,7 @@ class CFamilyTargetTestCase: XCTestCase {
4646
fixture(name: "DependencyResolution/External/CUsingCDep") { prefix in
4747
let packageRoot = prefix.appending(component: "Bar")
4848
XCTAssertBuilds(packageRoot)
49-
let debugPath = prefix.appending(components: "Bar", ".build", UserToolchain.default.triple.tripleString, "debug")
49+
let debugPath = prefix.appending(components: "Bar", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
5050
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Sea.c.o")
5151
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
5252
let path = try SwiftPMProduct.packagePath(for: "Foo", packageRoot: packageRoot)
@@ -57,7 +57,7 @@ class CFamilyTargetTestCase: XCTestCase {
5757
func testModuleMapGenerationCases() {
5858
fixture(name: "CFamilyTargets/ModuleMapGenerationCases") { prefix in
5959
XCTAssertBuilds(prefix)
60-
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug")
60+
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
6161
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Jaz.c.o")
6262
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "main.swift.o")
6363
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "FlatInclude.c.o")
@@ -80,7 +80,7 @@ class CFamilyTargetTestCase: XCTestCase {
8080
// Try building a fixture which needs extra flags to be able to build.
8181
fixture(name: "CFamilyTargets/CDynamicLookup") { prefix in
8282
XCTAssertBuilds(prefix, Xld: ["-undefined", "dynamic_lookup"])
83-
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug")
83+
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
8484
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
8585
}
8686
}
@@ -90,7 +90,7 @@ class CFamilyTargetTestCase: XCTestCase {
9090
fixture(name: "CFamilyTargets/ObjCmacOSPackage") { prefix in
9191
// Build the package.
9292
XCTAssertBuilds(prefix)
93-
XCTAssertDirectoryContainsFile(dir: prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug"), filename: "HelloWorldExample.m.o")
93+
XCTAssertDirectoryContainsFile(dir: prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug"), filename: "HelloWorldExample.m.o")
9494
// Run swift-test on package.
9595
XCTAssertSwiftTest(prefix)
9696
}

Tests/FunctionalTests/DependencyResolutionTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class DependencyResolutionTests: XCTestCase {
2121
fixture(name: "DependencyResolution/Internal/Simple") { prefix in
2222
XCTAssertBuilds(prefix)
2323

24-
let output = try Process.checkNonZeroExit(args: prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "Foo").pathString)
24+
let output = try Process.checkNonZeroExit(args: prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Foo").pathString)
2525
XCTAssertEqual(output, "Foo\nBar\n")
2626
}
2727
}
@@ -36,7 +36,7 @@ class DependencyResolutionTests: XCTestCase {
3636
fixture(name: "DependencyResolution/Internal/Complex") { prefix in
3737
XCTAssertBuilds(prefix)
3838

39-
let output = try Process.checkNonZeroExit(args: prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "Foo").pathString)
39+
let output = try Process.checkNonZeroExit(args: prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Foo").pathString)
4040
XCTAssertEqual(output, "meiow Baz\n")
4141
}
4242
}
@@ -52,7 +52,7 @@ class DependencyResolutionTests: XCTestCase {
5252

5353
let packageRoot = prefix.appending(component: "Bar")
5454
XCTAssertBuilds(packageRoot)
55-
XCTAssertFileExists(prefix.appending(components: "Bar", ".build", UserToolchain.default.triple.tripleString, "debug", "Bar"))
55+
XCTAssertFileExists(prefix.appending(components: "Bar", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Bar"))
5656
let path = try SwiftPMProduct.packagePath(for: "Foo", packageRoot: packageRoot)
5757
XCTAssert(try GitRepository(path: path).getTags().contains("1.2.3"))
5858
}
@@ -61,7 +61,7 @@ class DependencyResolutionTests: XCTestCase {
6161
func testExternalComplex() {
6262
fixture(name: "DependencyResolution/External/Complex") { prefix in
6363
XCTAssertBuilds(prefix.appending(component: "app"))
64-
let output = try Process.checkNonZeroExit(args: prefix.appending(components: "app", ".build", UserToolchain.default.triple.tripleString, "debug", "Dealer").pathString)
64+
let output = try Process.checkNonZeroExit(args: prefix.appending(components: "app", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Dealer").pathString)
6565
XCTAssertEqual(output, "♣︎K\n♣︎Q\n♣︎J\n♣︎10\n♣︎9\n♣︎8\n♣︎7\n♣︎6\n♣︎5\n♣︎4\n")
6666
}
6767
}

Tests/FunctionalTests/MiscellaneousTests.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class MiscellaneousTestCase: XCTestCase {
4747

4848
fixture(name: "Miscellaneous/ExactDependencies") { prefix in
4949
XCTAssertBuilds(prefix.appending(component: "app"))
50-
let buildDir = prefix.appending(components: "app", ".build", UserToolchain.default.triple.tripleString, "debug")
50+
let buildDir = prefix.appending(components: "app", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
5151
XCTAssertFileExists(buildDir.appending(component: "FooExec"))
5252
XCTAssertFileExists(buildDir.appending(component: "FooLib1.swiftmodule"))
5353
XCTAssertFileExists(buildDir.appending(component: "FooLib2.swiftmodule"))
@@ -120,7 +120,7 @@ class MiscellaneousTestCase: XCTestCase {
120120
*/
121121
func testInternalDependencyEdges() {
122122
fixture(name: "Miscellaneous/DependencyEdges/Internal") { prefix in
123-
let execpath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "Foo").pathString
123+
let execpath = prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Foo").pathString
124124

125125
XCTAssertBuilds(prefix)
126126
var output = try Process.checkNonZeroExit(args: execpath)
@@ -144,7 +144,7 @@ class MiscellaneousTestCase: XCTestCase {
144144
*/
145145
func testExternalDependencyEdges1() {
146146
fixture(name: "DependencyResolution/External/Complex") { prefix in
147-
let execpath = prefix.appending(components: "app", ".build", UserToolchain.default.triple.tripleString, "debug", "Dealer").pathString
147+
let execpath = prefix.appending(components: "app", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Dealer").pathString
148148

149149
let packageRoot = prefix.appending(component: "app")
150150
XCTAssertBuilds(packageRoot)
@@ -171,7 +171,7 @@ class MiscellaneousTestCase: XCTestCase {
171171
*/
172172
func testExternalDependencyEdges2() {
173173
fixture(name: "Miscellaneous/DependencyEdges/External") { prefix in
174-
let execpath = [prefix.appending(components: "root", ".build", UserToolchain.default.triple.tripleString, "debug", "dep2").pathString]
174+
let execpath = [prefix.appending(components: "root", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "dep2").pathString]
175175

176176
let packageRoot = prefix.appending(component: "root")
177177
XCTAssertBuilds(prefix.appending(component: "root"))
@@ -195,7 +195,7 @@ class MiscellaneousTestCase: XCTestCase {
195195
func testSpaces() {
196196
fixture(name: "Miscellaneous/Spaces Fixture") { prefix in
197197
XCTAssertBuilds(prefix)
198-
XCTAssertFileExists(prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "Module_Name_1.build", "Foo.swift.o"))
198+
XCTAssertFileExists(prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Module_Name_1.build", "Foo.swift.o"))
199199
}
200200
}
201201

@@ -337,7 +337,7 @@ class MiscellaneousTestCase: XCTestCase {
337337
let env = ["PKG_CONFIG_PATH": prefix.pathString]
338338
_ = try executeSwiftBuild(moduleUser, env: env)
339339

340-
XCTAssertFileExists(moduleUser.appending(components: ".build", triple.tripleString, "debug", "SystemModuleUserClang"))
340+
XCTAssertFileExists(moduleUser.appending(components: ".build", triple.platformBuildPathComponent(), "debug", "SystemModuleUserClang"))
341341
}
342342
}
343343

Tests/FunctionalTests/ModuleMapTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class ModuleMapsTestCase: XCTestCase {
2222
SPMTestSupport.fixture(name: name) { prefix in
2323
let input = prefix.appending(components: cModuleName, "C", "foo.c")
2424
let triple = UserToolchain.default.triple
25-
let outdir = prefix.appending(components: rootpkg, ".build", triple.tripleString, "debug")
25+
let outdir = prefix.appending(components: rootpkg, ".build", triple.platformBuildPathComponent(), "debug")
2626
try makeDirectories(outdir)
2727
let output = outdir.appending(component: "libfoo\(triple.dynamicLibraryExtension)")
2828
try systemQuietly(["clang", "-shared", input.pathString, "-o", output.pathString])
@@ -41,8 +41,8 @@ class ModuleMapsTestCase: XCTestCase {
4141

4242
XCTAssertBuilds(prefix.appending(component: "App"), Xld: Xld)
4343

44-
let triple = UserToolchain.default.triple
45-
let targetPath = prefix.appending(components: "App", ".build", triple.tripleString)
44+
let triple = UerToolchain.default.triple
45+
let targetPath = prefix.appending(components: "App", ".build", triple.platformBuildPathComponent())
4646
let debugout = try Process.checkNonZeroExit(args: targetPath.appending(components: "debug", "App").pathString)
4747
XCTAssertEqual(debugout, "123\n")
4848
let releaseout = try Process.checkNonZeroExit(args: targetPath.appending(components: "release", "App").pathString)
@@ -57,7 +57,7 @@ class ModuleMapsTestCase: XCTestCase {
5757

5858
func verify(_ conf: String, file: StaticString = #file, line: UInt = #line) throws {
5959
let triple = UserToolchain.default.triple
60-
let out = try Process.checkNonZeroExit(args: prefix.appending(components: "packageA", ".build", triple.tripleString, conf, "packageA").pathString)
60+
let out = try Process.checkNonZeroExit(args: prefix.appending(components: "packageA", ".build", triple.platformBuildPathComponent(), conf, "packageA").pathString)
6161
XCTAssertEqual(out, """
6262
calling Y.bar()
6363
Y.bar() called

Tests/FunctionalTests/SwiftPMXCTestHelperTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SwiftPMXCTestHelperTests: XCTestCase {
4040
] as Array<Dictionary<String, Any>>]] as Array<Dictionary<String, Any>>
4141
] as Dictionary<String, Any> as NSDictionary
4242
// Run the XCTest helper tool and check result.
43-
XCTAssertXCTestHelper(prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "SwiftPMXCTestHelperPackageTests.xctest"), testCases: testCases)
43+
XCTAssertXCTestHelper(prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "SwiftPMXCTestHelperPackageTests.xctest"), testCases: testCases)
4444
}
4545
#endif
4646
}

0 commit comments

Comments
 (0)