Skip to content

Commit ef59ec2

Browse files
authored
Disuse unversioned triples on non-Darwin platforms. (#3576)
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 79f834c commit ef59ec2

15 files changed

+67
-36
lines changed

Sources/Basics/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_library(Basics
2121
JSONDecoder+Extensions.swift
2222
Observability.swift
2323
Sandbox.swift
24+
Triple+Extensions.swift
2425
SwiftVersion.swift
2526
SQLiteBackedCache.swift
2627
Version+Extensions.swift)
+21
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ public class SwiftTool {
723723
// FIXME: At the moment we just pass the built products directory for the host. We will need to extend this
724724
// with a map of the names of tools available to each plugin. In particular this would not work with any
725725
// binary targets.
726-
let builtToolsDir = dataDir.appending(components: try self._hostToolchain.get().triple.tripleString, buildEnvironment.configuration.dirname)
726+
let builtToolsDir = dataDir.appending(components: try self._hostToolchain.get().triple.platformBuildPathComponent(), buildEnvironment.configuration.dirname)
727727

728728
// Create the cache directory, if needed.
729729
try localFileSystem.createDirectory(cacheDir, recursive: true)
@@ -858,7 +858,7 @@ public class SwiftTool {
858858
// can be used to build for any Apple platform and it has it's own
859859
// conventions for build subpaths based on platforms.
860860
let dataPath = buildPath.appending(
861-
component: options.buildSystem == .xcode ? "apple" : triple.tripleString)
861+
component: options.buildSystem == .xcode ? "apple" : triple.platformBuildPathComponent())
862862
return BuildParameters(
863863
dataPath: dataPath,
864864
configuration: options.configuration,

Sources/SPMBuildCore/BinaryTarget+Extensions.swift

+8-1
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

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ final class BuildToolTests: XCTestCase {
7777
func testBinPathAndSymlink() throws {
7878
fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { path in
7979
let fullPath = resolveSymlinks(path)
80-
let targetPath = fullPath.appending(components: ".build", UserToolchain.default.triple.tripleString)
80+
let targetPath = fullPath.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent())
8181
let xcbuildTargetPath = fullPath.appending(components: ".build", "apple")
8282
XCTAssertEqual(try execute(["--show-bin-path"], packagePath: fullPath).stdout,
8383
"\(targetPath.appending(component: "debug").pathString)\n")
@@ -293,7 +293,7 @@ final class BuildToolTests: XCTestCase {
293293
let defaultOutput = try execute(["-c", "debug", "-v"], packagePath: path).stdout
294294

295295
// Look for certain things in the output from XCBuild.
296-
XCTAssertMatch(defaultOutput, .contains("-target \(UserToolchain.default.triple.tripleString)"))
296+
XCTAssertMatch(defaultOutput, .contains("-target \(UserToolchain.default.triple.tripleString(forPlatformVersion: ""))"))
297297
}
298298
}
299299

Tests/CommandsTests/PackageToolTests.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ final class PackageToolTests: XCTestCase {
595595
_ = try SwiftPMProduct.SwiftPackage.execute(["edit", "baz", "--branch", "bugfix"], packagePath: fooPath)
596596

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

600600
// We should see it now in packages directory.
601601
let editsPath = fooPath.appending(components: "Packages", "bar")
@@ -669,7 +669,7 @@ final class PackageToolTests: XCTestCase {
669669
// Build it.
670670
XCTAssertBuilds(packageRoot)
671671
let buildPath = packageRoot.appending(component: ".build")
672-
let binFile = buildPath.appending(components: UserToolchain.default.triple.tripleString, "debug", "Bar")
672+
let binFile = buildPath.appending(components: UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Bar")
673673
XCTAssertFileExists(binFile)
674674
XCTAssert(localFileSystem.isDirectory(buildPath))
675675

@@ -688,7 +688,7 @@ final class PackageToolTests: XCTestCase {
688688
// Build it.
689689
XCTAssertBuilds(packageRoot)
690690
let buildPath = packageRoot.appending(component: ".build")
691-
let binFile = buildPath.appending(components: UserToolchain.default.triple.tripleString, "debug", "Bar")
691+
let binFile = buildPath.appending(components: UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Bar")
692692
XCTAssertFileExists(binFile)
693693
XCTAssert(localFileSystem.isDirectory(buildPath))
694694
// Clean, and check for removal of the build directory but not Packages.
@@ -758,7 +758,7 @@ final class PackageToolTests: XCTestCase {
758758
func build() throws -> String {
759759
return try SwiftPMProduct.SwiftBuild.execute([], packagePath: fooPath).stdout
760760
}
761-
let exec = [fooPath.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "foo").pathString]
761+
let exec = [fooPath.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "foo").pathString]
762762

763763
// Build and sanity check.
764764
_ = try build()

Tests/FunctionalPerformanceTests/BuildPerfTests.swift

+2-2
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

+5-5
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CFamilyTargetTestCase: XCTestCase {
3838
func testCLibraryWithSpaces() {
3939
fixture(name: "CFamilyTargets/CLibraryWithSpaces") { prefix in
4040
XCTAssertBuilds(prefix)
41-
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug")
41+
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
4242
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Bar.c.o")
4343
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
4444
}
@@ -48,7 +48,7 @@ class CFamilyTargetTestCase: XCTestCase {
4848
fixture(name: "DependencyResolution/External/CUsingCDep") { prefix in
4949
let packageRoot = prefix.appending(component: "Bar")
5050
XCTAssertBuilds(packageRoot)
51-
let debugPath = prefix.appending(components: "Bar", ".build", UserToolchain.default.triple.tripleString, "debug")
51+
let debugPath = prefix.appending(components: "Bar", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
5252
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Sea.c.o")
5353
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
5454
let path = try SwiftPMProduct.packagePath(for: "Foo", packageRoot: packageRoot)
@@ -59,7 +59,7 @@ class CFamilyTargetTestCase: XCTestCase {
5959
func testModuleMapGenerationCases() {
6060
fixture(name: "CFamilyTargets/ModuleMapGenerationCases") { prefix in
6161
XCTAssertBuilds(prefix)
62-
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug")
62+
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
6363
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Jaz.c.o")
6464
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "main.swift.o")
6565
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "FlatInclude.c.o")
@@ -82,7 +82,7 @@ class CFamilyTargetTestCase: XCTestCase {
8282
// Try building a fixture which needs extra flags to be able to build.
8383
fixture(name: "CFamilyTargets/CDynamicLookup") { prefix in
8484
XCTAssertBuilds(prefix, Xld: ["-undefined", "dynamic_lookup"])
85-
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug")
85+
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
8686
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
8787
}
8888
}
@@ -92,7 +92,7 @@ class CFamilyTargetTestCase: XCTestCase {
9292
fixture(name: "CFamilyTargets/ObjCmacOSPackage") { prefix in
9393
// Build the package.
9494
XCTAssertBuilds(prefix)
95-
XCTAssertDirectoryContainsFile(dir: prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug"), filename: "HelloWorldExample.m.o")
95+
XCTAssertDirectoryContainsFile(dir: prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug"), filename: "HelloWorldExample.m.o")
9696
// Run swift-test on package.
9797
XCTAssertSwiftTest(prefix)
9898
}

Tests/FunctionalTests/DependencyResolutionTests.swift

+4-4
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

+6-6
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class MiscellaneousTestCase: XCTestCase {
4949

5050
fixture(name: "Miscellaneous/ExactDependencies") { prefix in
5151
XCTAssertBuilds(prefix.appending(component: "app"))
52-
let buildDir = prefix.appending(components: "app", ".build", UserToolchain.default.triple.tripleString, "debug")
52+
let buildDir = prefix.appending(components: "app", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
5353
XCTAssertFileExists(buildDir.appending(component: "FooExec"))
5454
XCTAssertFileExists(buildDir.appending(component: "FooLib1.swiftmodule"))
5555
XCTAssertFileExists(buildDir.appending(component: "FooLib2.swiftmodule"))
@@ -122,7 +122,7 @@ class MiscellaneousTestCase: XCTestCase {
122122
*/
123123
func testInternalDependencyEdges() {
124124
fixture(name: "Miscellaneous/DependencyEdges/Internal") { prefix in
125-
let execpath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "Foo").pathString
125+
let execpath = prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Foo").pathString
126126

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

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

178178
let packageRoot = prefix.appending(component: "root")
179179
XCTAssertBuilds(prefix.appending(component: "root"))
@@ -197,7 +197,7 @@ class MiscellaneousTestCase: XCTestCase {
197197
func testSpaces() {
198198
fixture(name: "Miscellaneous/Spaces Fixture") { prefix in
199199
XCTAssertBuilds(prefix)
200-
XCTAssertFileExists(prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "Module_Name_1.build", "Foo.swift.o"))
200+
XCTAssertFileExists(prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Module_Name_1.build", "Foo.swift.o"))
201201
}
202202
}
203203

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

342-
XCTAssertFileExists(moduleUser.appending(components: ".build", triple.tripleString, "debug", "SystemModuleUserClang"))
342+
XCTAssertFileExists(moduleUser.appending(components: ".build", triple.platformBuildPathComponent(), "debug", "SystemModuleUserClang"))
343343
}
344344
}
345345

Tests/FunctionalTests/ModuleMapTests.swift

+3-3
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

0 commit comments

Comments
 (0)