1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2014-2024 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 the list of Swift project authors
//
//===----------------------------------------------------------------------===//
import Basics
import SPMTestSupport
@testable import SPMBuildCore
import XCTest
import PackageModel
final class PluginsBuildPlanTests: XCTestCase {
func testBuildToolsDatabasePath() async throws {
try await fixture(name: "Miscellaneous/Plugins/MySourceGenPlugin") { fixturePath in
let (stdout, _) = try await executeSwiftBuild(fixturePath)
XCTAssertMatch(stdout, .contains("Build complete!"))
XCTAssertTrue(localFileSystem.exists(fixturePath.appending(RelativePath(".build/plugins/tools/build.db"))))
}
}
func testCommandPluginDependenciesWhenCrossCompiling() async throws {
// Command Plugin dependencies must be built for the host.
// This test is only supported on macOS because that is the only
// platform on which we can currently be sure of having a viable
// cross-compilation environment (arm64->x86_64 or vice versa).
// On Linux it is typically only possible to build for the host
// environment unless cross-compilation SDKs are being used.
#if !os(macOS)
try XCTSkipIf(true, "test is only supported on macOS")
#endif
let hostToolchain = try UserToolchain(swiftSDK: .hostSwiftSDK(environment: [:]), environment: [:])
let hostTriple = try! hostToolchain.targetTriple.withoutVersion().tripleString
let x86Triple = "x86_64-apple-macosx"
let armTriple = "arm64-apple-macosx"
let targetTriple = hostToolchain.targetTriple.arch == .aarch64 ? x86Triple : armTriple
// By default, plugin dependencies are built for the host platform
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
let (stdout, stderr) = try await executeSwiftPackage(fixturePath, extraArgs: ["-v", "build-plugin-dependency"])
XCTAssertMatch(stdout, .contains("Hello from dependencies-stub"))
XCTAssertMatch(stderr, .contains("Build of product 'plugintool' complete!"))
XCTAssertTrue(
localFileSystem.exists(
fixturePath.appending(RelativePath(".build/\(hostTriple)/debug/plugintool-tool"))
)
)
XCTAssertTrue(
localFileSystem.exists(
fixturePath.appending(RelativePath(".build/\(hostTriple)/debug/placeholder"))
)
)
}
// When cross compiling the final product, plugin dependencies should still be built for the host
try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in
let (stdout, stderr) = try await executeSwiftPackage(fixturePath, extraArgs: ["--triple", targetTriple, "-v", "build-plugin-dependency"])
XCTAssertMatch(stdout, .contains("Hello from dependencies-stub"))
XCTAssertMatch(stderr, .contains("Build of product 'plugintool' complete!"))
XCTAssertTrue(
localFileSystem.exists(
fixturePath.appending(RelativePath(".build/\(hostTriple)/debug/plugintool-tool"))
)
)
XCTAssertTrue(
localFileSystem.exists(
fixturePath.appending(RelativePath(".build/\(targetTriple)/debug/placeholder"))
)
)
}
}
}
|