Skip to content

Commit eb54bad

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 329da56 commit eb54bad

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
@@ -19,6 +19,7 @@ add_library(Basics
1919
JSON+Extensions.swift
2020
JSONDecoder+Extensions.swift
2121
Sandbox.swift
22+
Triple+Extensions.swift
2223
SwiftVersion.swift
2324
SQLiteBackedCache.swift
2425
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
@@ -644,7 +644,8 @@ public class SwiftTool {
644644
// FIXME: At the moment we just pass the built products directory for the host. We will need to extend this
645645
// with a map of the names of tools available to each plugin. In particular this would not work with any
646646
// binary targets.
647-
let builtToolsDir = dataDir.appending(components: try self._hostToolchain.get().triple.tripleString, buildEnvironment.configuration.dirname)
647+
let hostTriple = try self._hostToolchain.get().triple
648+
let builtToolsDir = dataDir.appending(components: hostTriple.platformBuildPathComponent(), buildEnvironment.configuration.dirname)
648649
let diagnostics = DiagnosticsEngine()
649650

650651
// Create the cache directory, if needed.
@@ -757,7 +758,7 @@ public class SwiftTool {
757758
// can be used to build for any Apple platform and it has it's own
758759
// conventions for build subpaths based on platforms.
759760
let dataPath = buildPath.appending(
760-
component: options.buildSystem == .xcode ? "apple" : triple.tripleString)
761+
component: options.buildSystem == .xcode ? "apple" : triple.platformBuildPathComponent())
761762
return BuildParameters(
762763
dataPath: dataPath,
763764
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
@@ -74,7 +74,7 @@ final class BuildToolTests: XCTestCase {
7474
func testBinPathAndSymlink() throws {
7575
fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { path in
7676
let fullPath = resolveSymlinks(path)
77-
let targetPath = fullPath.appending(components: ".build", UserToolchain.default.triple.tripleString)
77+
let targetPath = fullPath.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent())
7878
let xcbuildTargetPath = fullPath.appending(components: ".build", "apple")
7979
XCTAssertEqual(try execute(["--show-bin-path"], packagePath: fullPath).stdout,
8080
"\(targetPath.appending(component: "debug").pathString)\n")

Tests/CommandsTests/PackageToolTests.swift

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

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

587587
// We should see it now in packages directory.
588588
let editsPath = fooPath.appending(components: "Packages", "bar")
@@ -656,7 +656,7 @@ final class PackageToolTests: XCTestCase {
656656
// Build it.
657657
XCTAssertBuilds(packageRoot)
658658
let buildPath = packageRoot.appending(component: ".build")
659-
let binFile = buildPath.appending(components: UserToolchain.default.triple.tripleString, "debug", "Bar")
659+
let binFile = buildPath.appending(components: UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Bar")
660660
XCTAssertFileExists(binFile)
661661
XCTAssert(localFileSystem.isDirectory(buildPath))
662662

@@ -675,7 +675,7 @@ final class PackageToolTests: XCTestCase {
675675
// Build it.
676676
XCTAssertBuilds(packageRoot)
677677
let buildPath = packageRoot.appending(component: ".build")
678-
let binFile = buildPath.appending(components: UserToolchain.default.triple.tripleString, "debug", "Bar")
678+
let binFile = buildPath.appending(components: UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Bar")
679679
XCTAssertFileExists(binFile)
680680
XCTAssert(localFileSystem.isDirectory(buildPath))
681681
// Clean, and check for removal of the build directory but not Packages.
@@ -745,7 +745,7 @@ final class PackageToolTests: XCTestCase {
745745
func build() throws -> String {
746746
return try SwiftPMProduct.SwiftBuild.execute([], packagePath: fooPath).stdout
747747
}
748-
let exec = [fooPath.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "foo").pathString]
748+
let exec = [fooPath.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "foo").pathString]
749749

750750
// Build and sanity check.
751751
_ = 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: 3 additions & 3 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])
@@ -42,7 +42,7 @@ class ModuleMapsTestCase: XCTestCase {
4242
XCTAssertBuilds(prefix.appending(component: "App"), Xld: Xld)
4343

4444
let triple = UserToolchain.default.triple
45-
let targetPath = prefix.appending(components: "App", ".build", triple.tripleString)
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class SwiftPMXCTestHelperTests: XCTestCase {
2323
// Build the package.
2424
XCTAssertBuilds(prefix)
2525
let triple = UserToolchain.default.triple
26-
XCTAssertFileExists(prefix.appending(components: ".build", triple.tripleString, "debug", "SwiftPMXCTestHelper.swiftmodule"))
26+
XCTAssertFileExists(prefix.appending(components: ".build", triple.platformBuildPathComponent(), "debug", "SwiftPMXCTestHelper.swiftmodule"))
2727
// Run swift-test on package.
2828
XCTAssertSwiftTest(prefix)
2929
// Expected output dictionary.
@@ -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)