Skip to content

Disuse unversioned triples on non-Darwin platforms. #3576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Sources/Basics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ add_library(Basics
JSONDecoder+Extensions.swift
Observability.swift
Sandbox.swift
Triple+Extensions.swift
SwiftVersion.swift
SQLiteBackedCache.swift
Version+Extensions.swift)
Expand Down
21 changes: 21 additions & 0 deletions Sources/Basics/Triple+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
This source file is part of the Swift.org open source project

Copyright (c) 2014 - 2020 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import TSCUtility

extension Triple {
public func platformBuildPathComponent() -> String {
if isDarwin() {
return tripleString(forPlatformVersion: "")
}

return tripleString
}
}
4 changes: 2 additions & 2 deletions Sources/Commands/SwiftTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ public class SwiftTool {
// FIXME: At the moment we just pass the built products directory for the host. We will need to extend this
// with a map of the names of tools available to each plugin. In particular this would not work with any
// binary targets.
let builtToolsDir = dataDir.appending(components: try self._hostToolchain.get().triple.tripleString, buildEnvironment.configuration.dirname)
let builtToolsDir = dataDir.appending(components: try self._hostToolchain.get().triple.platformBuildPathComponent(), buildEnvironment.configuration.dirname)

// Create the cache directory, if needed.
try localFileSystem.createDirectory(cacheDir, recursive: true)
Expand Down Expand Up @@ -794,7 +794,7 @@ public class SwiftTool {
// can be used to build for any Apple platform and it has it's own
// conventions for build subpaths based on platforms.
let dataPath = buildPath.appending(
component: options.buildSystem == .xcode ? "apple" : triple.tripleString)
component: options.buildSystem == .xcode ? "apple" : triple.platformBuildPathComponent())
return BuildParameters(
dataPath: dataPath,
configuration: options.configuration,
Expand Down
9 changes: 8 additions & 1 deletion Sources/SPMBuildCore/BinaryTarget+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ extension BinaryTarget {
// Construct an ExecutableInfo for each matching variant.
return executables.flatMap { entry in
// FIXME: this filter needs to become more sophisticated
entry.value.variants.filter{ $0.supportedTriples.contains(triple) }.map{
entry.value.variants.filter {
let tripleStrings = $0.supportedTriples.map { $0.tripleString }
if triple.isDarwin() {
return tripleStrings.contains(triple.tripleString(forPlatformVersion: ""))
} else {
return tripleStrings.contains(triple.tripleString)
}
}.map{
ExecutableInfo(name: entry.key, executablePath: self.artifactPath.appending(RelativePath($0.path)))
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/CommandsTests/BuildToolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ final class BuildToolTests: XCTestCase {
func testBinPathAndSymlink() throws {
fixture(name: "ValidLayouts/SingleModule/ExecutableNew") { path in
let fullPath = resolveSymlinks(path)
let targetPath = fullPath.appending(components: ".build", UserToolchain.default.triple.tripleString)
let targetPath = fullPath.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent())
let xcbuildTargetPath = fullPath.appending(components: ".build", "apple")
XCTAssertEqual(try execute(["--show-bin-path"], packagePath: fullPath).stdout,
"\(targetPath.appending(component: "debug").pathString)\n")
Expand Down Expand Up @@ -293,7 +293,7 @@ final class BuildToolTests: XCTestCase {
let defaultOutput = try execute(["-c", "debug", "-v"], packagePath: path).stdout

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

Expand Down
8 changes: 4 additions & 4 deletions Tests/CommandsTests/PackageToolTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ final class PackageToolTests: XCTestCase {
_ = try SwiftPMProduct.SwiftPackage.execute(["edit", "baz", "--branch", "bugfix"], packagePath: fooPath)

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

// We should see it now in packages directory.
let editsPath = fooPath.appending(components: "Packages", "bar")
Expand Down Expand Up @@ -651,7 +651,7 @@ final class PackageToolTests: XCTestCase {
// Build it.
XCTAssertBuilds(packageRoot)
let buildPath = packageRoot.appending(component: ".build")
let binFile = buildPath.appending(components: UserToolchain.default.triple.tripleString, "debug", "Bar")
let binFile = buildPath.appending(components: UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Bar")
XCTAssertFileExists(binFile)
XCTAssert(localFileSystem.isDirectory(buildPath))

Expand All @@ -670,7 +670,7 @@ final class PackageToolTests: XCTestCase {
// Build it.
XCTAssertBuilds(packageRoot)
let buildPath = packageRoot.appending(component: ".build")
let binFile = buildPath.appending(components: UserToolchain.default.triple.tripleString, "debug", "Bar")
let binFile = buildPath.appending(components: UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Bar")
XCTAssertFileExists(binFile)
XCTAssert(localFileSystem.isDirectory(buildPath))
// Clean, and check for removal of the build directory but not Packages.
Expand Down Expand Up @@ -740,7 +740,7 @@ final class PackageToolTests: XCTestCase {
func build() throws -> String {
return try SwiftPMProduct.SwiftBuild.execute([], packagePath: fooPath).stdout
}
let exec = [fooPath.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "foo").pathString]
let exec = [fooPath.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "foo").pathString]

// Build and sanity check.
_ = try build()
Expand Down
4 changes: 2 additions & 2 deletions Tests/FunctionalPerformanceTests/BuildPerfTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class BuildPerfTests: XCTestCasePerf {
fixture(name: name) { prefix in
let app = prefix.appending(components: (appString ?? ""))
let triple = UserToolchain.default.triple
let product = app.appending(components: ".build", triple.tripleString, "debug", productString)
let product = app.appending(components: ".build", triple.platformBuildPathComponent(), "debug", productString)
try self.execute(packagePath: app)
measure {
try! self.clean(packagePath: app)
Expand All @@ -70,7 +70,7 @@ class BuildPerfTests: XCTestCasePerf {
fixture(name: name) { prefix in
let app = prefix.appending(components: (appString ?? ""))
let triple = UserToolchain.default.triple
let product = app.appending(components: ".build", triple.tripleString, "debug", productString)
let product = app.appending(components: ".build", triple.platformBuildPathComponent(), "debug", productString)
try self.execute(packagePath: app)
measure {
try! self.execute(packagePath: app)
Expand Down
10 changes: 5 additions & 5 deletions Tests/FunctionalTests/CFamilyTargetTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CFamilyTargetTestCase: XCTestCase {
func testCLibraryWithSpaces() {
fixture(name: "CFamilyTargets/CLibraryWithSpaces") { prefix in
XCTAssertBuilds(prefix)
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug")
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Bar.c.o")
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
}
Expand All @@ -48,7 +48,7 @@ class CFamilyTargetTestCase: XCTestCase {
fixture(name: "DependencyResolution/External/CUsingCDep") { prefix in
let packageRoot = prefix.appending(component: "Bar")
XCTAssertBuilds(packageRoot)
let debugPath = prefix.appending(components: "Bar", ".build", UserToolchain.default.triple.tripleString, "debug")
let debugPath = prefix.appending(components: "Bar", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Sea.c.o")
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
let path = try SwiftPMProduct.packagePath(for: "Foo", packageRoot: packageRoot)
Expand All @@ -59,7 +59,7 @@ class CFamilyTargetTestCase: XCTestCase {
func testModuleMapGenerationCases() {
fixture(name: "CFamilyTargets/ModuleMapGenerationCases") { prefix in
XCTAssertBuilds(prefix)
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug")
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Jaz.c.o")
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "main.swift.o")
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "FlatInclude.c.o")
Expand All @@ -82,7 +82,7 @@ class CFamilyTargetTestCase: XCTestCase {
// Try building a fixture which needs extra flags to be able to build.
fixture(name: "CFamilyTargets/CDynamicLookup") { prefix in
XCTAssertBuilds(prefix, Xld: ["-undefined", "dynamic_lookup"])
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug")
let debugPath = prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
XCTAssertDirectoryContainsFile(dir: debugPath, filename: "Foo.c.o")
}
}
Expand All @@ -92,7 +92,7 @@ class CFamilyTargetTestCase: XCTestCase {
fixture(name: "CFamilyTargets/ObjCmacOSPackage") { prefix in
// Build the package.
XCTAssertBuilds(prefix)
XCTAssertDirectoryContainsFile(dir: prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug"), filename: "HelloWorldExample.m.o")
XCTAssertDirectoryContainsFile(dir: prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug"), filename: "HelloWorldExample.m.o")
// Run swift-test on package.
XCTAssertSwiftTest(prefix)
}
Expand Down
8 changes: 4 additions & 4 deletions Tests/FunctionalTests/DependencyResolutionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class DependencyResolutionTests: XCTestCase {
fixture(name: "DependencyResolution/Internal/Simple") { prefix in
XCTAssertBuilds(prefix)

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

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

let packageRoot = prefix.appending(component: "Bar")
XCTAssertBuilds(packageRoot)
XCTAssertFileExists(prefix.appending(components: "Bar", ".build", UserToolchain.default.triple.tripleString, "debug", "Bar"))
XCTAssertFileExists(prefix.appending(components: "Bar", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Bar"))
let path = try SwiftPMProduct.packagePath(for: "Foo", packageRoot: packageRoot)
XCTAssert(try GitRepository(path: path).getTags().contains("1.2.3"))
}
Expand All @@ -61,7 +61,7 @@ class DependencyResolutionTests: XCTestCase {
func testExternalComplex() {
fixture(name: "DependencyResolution/External/Complex") { prefix in
XCTAssertBuilds(prefix.appending(component: "app"))
let output = try Process.checkNonZeroExit(args: prefix.appending(components: "app", ".build", UserToolchain.default.triple.tripleString, "debug", "Dealer").pathString)
let output = try Process.checkNonZeroExit(args: prefix.appending(components: "app", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Dealer").pathString)
XCTAssertEqual(output, "♣︎K\n♣︎Q\n♣︎J\n♣︎10\n♣︎9\n♣︎8\n♣︎7\n♣︎6\n♣︎5\n♣︎4\n")
}
}
Expand Down
12 changes: 6 additions & 6 deletions Tests/FunctionalTests/MiscellaneousTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MiscellaneousTestCase: XCTestCase {

fixture(name: "Miscellaneous/ExactDependencies") { prefix in
XCTAssertBuilds(prefix.appending(component: "app"))
let buildDir = prefix.appending(components: "app", ".build", UserToolchain.default.triple.tripleString, "debug")
let buildDir = prefix.appending(components: "app", ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug")
XCTAssertFileExists(buildDir.appending(component: "FooExec"))
XCTAssertFileExists(buildDir.appending(component: "FooLib1.swiftmodule"))
XCTAssertFileExists(buildDir.appending(component: "FooLib2.swiftmodule"))
Expand Down Expand Up @@ -122,7 +122,7 @@ class MiscellaneousTestCase: XCTestCase {
*/
func testInternalDependencyEdges() {
fixture(name: "Miscellaneous/DependencyEdges/Internal") { prefix in
let execpath = prefix.appending(components: ".build", UserToolchain.default.triple.tripleString, "debug", "Foo").pathString
let execpath = prefix.appending(components: ".build", UserToolchain.default.triple.platformBuildPathComponent(), "debug", "Foo").pathString

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

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

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

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

XCTAssertFileExists(moduleUser.appending(components: ".build", triple.tripleString, "debug", "SystemModuleUserClang"))
XCTAssertFileExists(moduleUser.appending(components: ".build", triple.platformBuildPathComponent(), "debug", "SystemModuleUserClang"))
}
}

Expand Down
6 changes: 3 additions & 3 deletions Tests/FunctionalTests/ModuleMapTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ModuleMapsTestCase: XCTestCase {
SPMTestSupport.fixture(name: name) { prefix in
let input = prefix.appending(components: cModuleName, "C", "foo.c")
let triple = UserToolchain.default.triple
let outdir = prefix.appending(components: rootpkg, ".build", triple.tripleString, "debug")
let outdir = prefix.appending(components: rootpkg, ".build", triple.platformBuildPathComponent(), "debug")
try makeDirectories(outdir)
let output = outdir.appending(component: "libfoo\(triple.dynamicLibraryExtension)")
try systemQuietly(["clang", "-shared", input.pathString, "-o", output.pathString])
Expand All @@ -42,7 +42,7 @@ class ModuleMapsTestCase: XCTestCase {
XCTAssertBuilds(prefix.appending(component: "App"), Xld: Xld)

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

func verify(_ conf: String, file: StaticString = #file, line: UInt = #line) throws {
let triple = UserToolchain.default.triple
let out = try Process.checkNonZeroExit(args: prefix.appending(components: "packageA", ".build", triple.tripleString, conf, "packageA").pathString)
let out = try Process.checkNonZeroExit(args: prefix.appending(components: "packageA", ".build", triple.platformBuildPathComponent(), conf, "packageA").pathString)
XCTAssertEqual(out, """
calling Y.bar()
Y.bar() called
Expand Down
Loading