Skip to content

Commit 4ac062a

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 5e4695d commit 4ac062a

File tree

14 files changed

+58
-33
lines changed

14 files changed

+58
-33
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
@@ -656,7 +656,8 @@ public class SwiftTool {
656656
// FIXME: At the moment we just pass the built products directory for the host. We will need to extend this
657657
// with a map of the names of tools available to each plugin. In particular this would not work with any
658658
// binary targets.
659-
let builtToolsDir = dataDir.appending(components: try self._hostToolchain.get().triple.tripleString, buildEnvironment.configuration.dirname)
659+
let hostTriple = try self._hostToolchain.get().triple
660+
let builtToolsDir = dataDir.appending(components: hostTriple.platformBuildPathComponent(), buildEnvironment.configuration.dirname)
660661
let diagnostics = DiagnosticsEngine()
661662

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

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", Resources.default.toolchain.triple.tripleString)
77+
let targetPath = fullPath.appending(components: ".build", Resources.default.toolchain.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
@@ -586,7 +586,7 @@ final class PackageToolTests: XCTestCase {
586586
_ = try SwiftPMProduct.SwiftPackage.execute(["edit", "baz", "--branch", "bugfix"], packagePath: fooPath)
587587

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

591591
// We should see it now in packages directory.
592592
let editsPath = fooPath.appending(components: "Packages", "bar")
@@ -660,7 +660,7 @@ final class PackageToolTests: XCTestCase {
660660
// Build it.
661661
XCTAssertBuilds(packageRoot)
662662
let buildPath = packageRoot.appending(component: ".build")
663-
let binFile = buildPath.appending(components: Resources.default.toolchain.triple.tripleString, "debug", "Bar")
663+
let binFile = buildPath.appending(components: Resources.default.toolchain.triple.platformBuildPathComponent(), "debug", "Bar")
664664
XCTAssertFileExists(binFile)
665665
XCTAssert(localFileSystem.isDirectory(buildPath))
666666

@@ -679,7 +679,7 @@ final class PackageToolTests: XCTestCase {
679679
// Build it.
680680
XCTAssertBuilds(packageRoot)
681681
let buildPath = packageRoot.appending(component: ".build")
682-
let binFile = buildPath.appending(components: Resources.default.toolchain.triple.tripleString, "debug", "Bar")
682+
let binFile = buildPath.appending(components: Resources.default.toolchain.triple.platformBuildPathComponent(), "debug", "Bar")
683683
XCTAssertFileExists(binFile)
684684
XCTAssert(localFileSystem.isDirectory(buildPath))
685685
// Clean, and check for removal of the build directory but not Packages.
@@ -749,7 +749,7 @@ final class PackageToolTests: XCTestCase {
749749
func build() throws -> String {
750750
return try SwiftPMProduct.SwiftBuild.execute([], packagePath: fooPath).stdout
751751
}
752-
let exec = [fooPath.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug", "foo").pathString]
752+
let exec = [fooPath.appending(components: ".build", Resources.default.toolchain.triple.platformBuildPathComponent(), "debug", "foo").pathString]
753753

754754
// Build and sanity check.
755755
_ = try build()

Tests/FunctionalPerformanceTests/BuildPerfTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class BuildPerfTests: XCTestCasePerf {
5555
fixture(name: name) { prefix in
5656
let app = prefix.appending(components: (appString ?? ""))
5757
let triple = Resources.default.toolchain.triple
58-
let product = app.appending(components: ".build", triple.tripleString, "debug", productString)
58+
let product = app.appending(components: ".build", triple.platformBuildPathComponent(), "debug", productString)
5959
try self.execute(packagePath: app)
6060
measure {
6161
try! self.clean(packagePath: app)
@@ -69,7 +69,7 @@ class BuildPerfTests: XCTestCasePerf {
6969
fixture(name: name) { prefix in
7070
let app = prefix.appending(components: (appString ?? ""))
7171
let triple = Resources.default.toolchain.triple
72-
let product = app.appending(components: ".build", triple.tripleString, "debug", productString)
72+
let product = app.appending(components: ".build", triple.platformBuildPathComponent(), "debug", productString)
7373
try self.execute(packagePath: app)
7474
measure {
7575
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", Resources.default.toolchain.triple.tripleString, "debug")
39+
let debugPath = prefix.appending(components: ".build", Resources.default.toolchain.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", Resources.default.toolchain.triple.tripleString, "debug")
49+
let debugPath = prefix.appending(components: "Bar", ".build", Resources.default.toolchain.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", Resources.default.toolchain.triple.tripleString, "debug")
60+
let debugPath = prefix.appending(components: ".build", Resources.default.toolchain.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")
@@ -69,7 +69,7 @@ class CFamilyTargetTestCase: XCTestCase {
6969
// Try building a fixture which needs extra flags to be able to build.
7070
fixture(name: "CFamilyTargets/CDynamicLookup") { prefix in
7171
XCTAssertBuilds(prefix, Xld: ["-undefined", "dynamic_lookup"])
72-
let debugPath = prefix.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug")
72+
let debugPath = prefix.appending(components: ".build", Resources.default.toolchain.triple.platformBuildPathComponent(), "debug")
7373
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
7474
}
7575
}
@@ -82,7 +82,7 @@ class CFamilyTargetTestCase: XCTestCase {
8282
fixture(name: "CFamilyTargets/ObjCmacOSPackage") { prefix in
8383
// Build the package.
8484
XCTAssertBuilds(prefix)
85-
XCTAssertDirectoryContainsFile(dir: prefix.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug"), filename: "HelloWorldExample.m.o")
85+
XCTAssertDirectoryContainsFile(dir: prefix.appending(components: ".build", Resources.default.toolchain.triple.platformBuildPathComponent(), "debug"), filename: "HelloWorldExample.m.o")
8686
// Run swift-test on package.
8787
XCTAssertSwiftTest(prefix)
8888
}

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", Resources.default.toolchain.triple.tripleString, "debug", "Foo").pathString)
24+
let output = try Process.checkNonZeroExit(args: prefix.appending(components: ".build", Resources.default.toolchain.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", Resources.default.toolchain.triple.tripleString, "debug", "Foo").pathString)
39+
let output = try Process.checkNonZeroExit(args: prefix.appending(components: ".build", Resources.default.toolchain.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", Resources.default.toolchain.triple.tripleString, "debug", "Bar"))
55+
XCTAssertFileExists(prefix.appending(components: "Bar", ".build", Resources.default.toolchain.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", Resources.default.toolchain.triple.tripleString, "debug", "Dealer").pathString)
64+
let output = try Process.checkNonZeroExit(args: prefix.appending(components: "app", ".build", Resources.default.toolchain.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", Resources.default.toolchain.triple.tripleString, "debug")
50+
let buildDir = prefix.appending(components: "app", ".build", Resources.default.toolchain.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", Resources.default.toolchain.triple.tripleString, "debug", "Foo").pathString
123+
let execpath = prefix.appending(components: ".build", Resources.default.toolchain.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", Resources.default.toolchain.triple.tripleString, "debug", "Dealer").pathString
147+
let execpath = prefix.appending(components: "app", ".build", Resources.default.toolchain.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", Resources.default.toolchain.triple.tripleString, "debug", "dep2").pathString]
174+
let execpath = [prefix.appending(components: "root", ".build", Resources.default.toolchain.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", Resources.default.toolchain.triple.tripleString, "debug", "Module_Name_1.build", "Foo.swift.o"))
198+
XCTAssertFileExists(prefix.appending(components: ".build", Resources.default.toolchain.triple.platformBuildPathComponent(), "debug", "Module_Name_1.build", "Foo.swift.o"))
199199
}
200200
}
201201

@@ -346,7 +346,7 @@ class MiscellaneousTestCase: XCTestCase {
346346
let env = ["PKG_CONFIG_PATH": prefix.pathString]
347347
_ = try executeSwiftBuild(moduleUser, env: env)
348348

349-
XCTAssertFileExists(moduleUser.appending(components: ".build", triple.tripleString, "debug", "SystemModuleUserClang"))
349+
XCTAssertFileExists(moduleUser.appending(components: ".build", triple.platformBuildPathComponent(), "debug", "SystemModuleUserClang"))
350350
}
351351
}
352352

Tests/FunctionalTests/ModuleMapTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ModuleMapsTestCase: XCTestCase {
2121
SPMTestSupport.fixture(name: name) { prefix in
2222
let input = prefix.appending(components: cModuleName, "C", "foo.c")
2323
let triple = Resources.default.toolchain.triple
24-
let outdir = prefix.appending(components: rootpkg, ".build", triple.tripleString, "debug")
24+
let outdir = prefix.appending(components: rootpkg, ".build", triple.platformBuildPathComponent(), "debug")
2525
try makeDirectories(outdir)
2626
let output = outdir.appending(component: "libfoo\(triple.dynamicLibraryExtension)")
2727
try systemQuietly(["clang", "-shared", input.pathString, "-o", output.pathString])
@@ -41,7 +41,7 @@ class ModuleMapsTestCase: XCTestCase {
4141
XCTAssertBuilds(prefix.appending(component: "App"), Xld: Xld)
4242

4343
let triple = Resources.default.toolchain.triple
44-
let targetPath = prefix.appending(components: "App", ".build", triple.tripleString)
44+
let targetPath = prefix.appending(components: "App", ".build", triple.platformBuildPathComponent())
4545
let debugout = try Process.checkNonZeroExit(args: targetPath.appending(components: "debug", "App").pathString)
4646
XCTAssertEqual(debugout, "123\n")
4747
let releaseout = try Process.checkNonZeroExit(args: targetPath.appending(components: "release", "App").pathString)
@@ -56,7 +56,7 @@ class ModuleMapsTestCase: XCTestCase {
5656

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

Tests/FunctionalTests/SwiftPMXCTestHelperTests.swift

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

Tests/FunctionalTests/ToolsVersionTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class ToolsVersionTests: XCTestCase {
9191

9292
// Build the primary package.
9393
_ = try SwiftPMProduct.SwiftBuild.execute([], packagePath: primaryPath)
94-
let exe = primaryPath.appending(components: ".build", Resources.default.toolchain.triple.tripleString, "debug", "Primary").pathString
94+
let exe = primaryPath.appending(components: ".build", Resources.default.toolchain.triple.platformBuildPathComponent(), "debug", "Primary").pathString
9595
// v1 should get selected because v1.0.1 depends on a (way) higher set of tools.
9696
XCTAssertEqual(try Process.checkNonZeroExit(args: exe).spm_chomp(), "[email protected]")
9797

0 commit comments

Comments
 (0)