|
2 | 2 | //
|
3 | 3 | // This source file is part of the Swift open source project
|
4 | 4 | //
|
5 |
| -// Copyright (c) 2014-2024 Apple Inc. and the Swift project authors |
| 5 | +// Copyright (c) 2014-2025 Apple Inc. and the Swift project authors |
6 | 6 | // Licensed under Apache License v2.0 with Runtime Library Exception
|
7 | 7 | //
|
8 | 8 | // See http://swift.org/LICENSE.txt for license information
|
9 | 9 | // See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
10 | 10 | //
|
11 | 11 | //===----------------------------------------------------------------------===//
|
12 |
| - |
| 12 | +import Foundation |
13 | 13 | import Basics
|
14 |
| -import _InternalTestSupport |
15 |
| -@testable import SPMBuildCore |
16 |
| -import XCTest |
17 | 14 | import PackageModel
|
| 15 | +import Testing |
| 16 | +import _InternalTestSupport |
18 | 17 |
|
19 |
| -final class PluginsBuildPlanTests: XCTestCase { |
20 |
| - func testBuildToolsDatabasePath() async throws { |
21 |
| - try XCTSkipOnWindows(because: "Fails to build the project to due to incorrect Path handling. Possibly related to https://github.com/swiftlang/swift-package-manager/issues/8511") |
| 18 | +@testable import SPMBuildCore |
22 | 19 |
|
23 |
| - try await fixtureXCTest(name: "Miscellaneous/Plugins/MySourceGenPlugin") { fixturePath in |
24 |
| - let (stdout, _) = try await executeSwiftBuild(fixturePath, buildSystem: .native) |
25 |
| - XCTAssertMatch(stdout, .contains("Build complete!")) |
| 20 | +@Suite( |
| 21 | + .serialized, |
| 22 | + .tags( |
| 23 | + .TestSize.large, |
| 24 | + ), |
| 25 | +) |
| 26 | +struct PluginsBuildPlanTests { |
| 27 | + @Test( |
| 28 | + .tags( |
| 29 | + .Feature.Command.Build, |
| 30 | + ), |
| 31 | + .issue("https://github.com/swiftlang/swift-package-manager/issues/8511", relationship: .defect), // Fails to build the project to due to incorrect Path handling |
| 32 | + arguments: BuildConfiguration.allCases, |
| 33 | + ) |
| 34 | + func buildToolsDatabasePath( |
| 35 | + config: BuildConfiguration, |
| 36 | + ) async throws { |
| 37 | + try await withKnownIssue(isIntermittent: true) { |
| 38 | + try await fixture(name: "Miscellaneous/Plugins/MySourceGenPlugin") { fixturePath in |
| 39 | + let (stdout, _) = try await executeSwiftBuild( |
| 40 | + fixturePath, |
| 41 | + configuration: config, |
| 42 | + buildSystem: .native |
| 43 | + ) |
| 44 | + #expect(stdout.contains("Build complete!")) |
26 | 45 | // FIXME: This is temporary until build of plugin tools is extracted into its own command.
|
27 |
| - XCTAssertTrue(localFileSystem.exists(fixturePath.appending(RelativePath(".build/plugin-tools.db")))) |
28 |
| - XCTAssertTrue(localFileSystem.exists(fixturePath.appending(RelativePath(".build/build.db")))) |
| 46 | + #expect(localFileSystem.exists(fixturePath.appending(RelativePath(".build/plugin-tools.db")))) |
| 47 | + #expect(localFileSystem.exists(fixturePath.appending(RelativePath(".build/build.db")))) |
| 48 | + } |
| 49 | + } when: { |
| 50 | + ProcessInfo.hostOperatingSystem == .windows |
29 | 51 | }
|
30 | 52 | }
|
31 | 53 |
|
32 |
| - func testCommandPluginDependenciesWhenCrossCompiling() async throws { |
33 |
| - // Command Plugin dependencies must be built for the host. |
34 |
| - // This test is only supported on macOS because that is the only |
35 |
| - // platform on which we can currently be sure of having a viable |
36 |
| - // cross-compilation environment (arm64->x86_64 or vice versa). |
37 |
| - // On Linux it is typically only possible to build for the host |
38 |
| - // environment unless cross-compilation SDKs are being used. |
39 |
| - #if !os(macOS) |
40 |
| - try XCTSkipIf(true, "test is only supported on macOS") |
41 |
| - #endif |
42 |
| - |
43 |
| - let hostToolchain = try UserToolchain(swiftSDK: .hostSwiftSDK(environment: [:]), environment: [:]) |
| 54 | + @Test( |
| 55 | + .serialized, |
| 56 | + .tags( |
| 57 | + .Feature.Command.Package.CommandPlugin, |
| 58 | + ), |
| 59 | + .requireHostOS(.macOS), |
| 60 | + arguments: getBuildData(for: SupportedBuildSystemOnAllPlatforms), |
| 61 | + ) |
| 62 | + func commandPluginDependenciesWhenNotCrossCompiling( |
| 63 | + buildData: BuildData, |
| 64 | + ) async throws { |
| 65 | + let hostToolchain = try UserToolchain( |
| 66 | + swiftSDK: .hostSwiftSDK(environment: [:]), |
| 67 | + environment: [:] |
| 68 | + ) |
44 | 69 | let hostTriple = try! hostToolchain.targetTriple.withoutVersion().tripleString
|
45 | 70 |
|
46 |
| - let x86Triple = "x86_64-apple-macosx" |
47 |
| - let armTriple = "arm64-apple-macosx" |
48 |
| - let targetTriple = hostToolchain.targetTriple.arch == .aarch64 ? x86Triple : armTriple |
49 |
| - |
| 71 | + let hostBinPathSegments = try buildData.buildSystem.binPath( |
| 72 | + for: buildData.config, |
| 73 | + triple: hostTriple, |
| 74 | + ) |
| 75 | + let hostDebugBinPathSegments = try buildData.buildSystem.binPath( |
| 76 | + for: .debug, |
| 77 | + triple: hostTriple, |
| 78 | + ) |
50 | 79 | // By default, plugin dependencies are built for the host platform
|
51 |
| - try await fixtureXCTest(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in |
| 80 | + try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in |
| 81 | + let hostBinPath: AbsolutePath = fixturePath.appending(components: hostBinPathSegments) |
| 82 | + let hostDebugBinPath: AbsolutePath = fixturePath.appending(components: hostDebugBinPathSegments) |
52 | 83 | let (stdout, stderr) = try await executeSwiftPackage(
|
53 | 84 | fixturePath,
|
| 85 | + configuration: buildData.config, |
54 | 86 | extraArgs: ["-v", "build-plugin-dependency"],
|
55 |
| - buildSystem: .native, |
56 |
| - ) |
57 |
| - XCTAssertMatch(stdout, .contains("Hello from dependencies-stub")) |
58 |
| - XCTAssertMatch(stderr, .contains("Build of product 'plugintool' complete!")) |
59 |
| - XCTAssertTrue( |
60 |
| - localFileSystem.exists( |
61 |
| - fixturePath.appending(RelativePath(".build/\(hostTriple)/debug/plugintool-tool")) |
62 |
| - ) |
63 |
| - ) |
64 |
| - XCTAssertTrue( |
65 |
| - localFileSystem.exists( |
66 |
| - fixturePath.appending(RelativePath(".build/\(hostTriple)/debug/placeholder")) |
67 |
| - ) |
| 87 | + buildSystem: buildData.buildSystem, |
68 | 88 | )
|
| 89 | + #expect(stdout.contains("Hello from dependencies-stub")) |
| 90 | + if buildData.buildSystem == .native { |
| 91 | + #expect(stderr.contains("Build of product 'plugintool' complete!")) |
| 92 | + } |
| 93 | + let pluginToolName: String |
| 94 | + switch buildData.buildSystem { |
| 95 | + case .native: |
| 96 | + pluginToolName = "plugintool-tool" |
| 97 | + case .swiftbuild: |
| 98 | + pluginToolName = "plugintool" |
| 99 | + case .xcode: |
| 100 | + pluginToolName = "" |
| 101 | + Issue.record("Test has not been updated for this build system") |
| 102 | + } |
| 103 | + expectFileExists(at: hostBinPath.appending(pluginToolName)) |
| 104 | + expectFileExists(at: hostDebugBinPath.appending("placeholder")) |
69 | 105 | }
|
| 106 | + } |
| 107 | + |
| 108 | + @Test( |
| 109 | + .serialized, |
| 110 | + .tags( |
| 111 | + .Feature.Command.Package.CommandPlugin, |
| 112 | + ), |
| 113 | + .requireHostOS(.macOS), |
| 114 | + arguments: getBuildData(for: SupportedBuildSystemOnAllPlatforms), |
| 115 | + ) |
| 116 | + func commandPluginDependenciesWhenCrossCompiling( |
| 117 | + buildData: BuildData, |
| 118 | + ) async throws { |
| 119 | + let hostToolchain = try UserToolchain( |
| 120 | + swiftSDK: .hostSwiftSDK(environment: [:]), |
| 121 | + environment: [:] |
| 122 | + ) |
| 123 | + // let hostTriple = try! hostToolchain.targetTriple.withoutVersion().tripleString |
| 124 | + |
| 125 | + let x86Triple = "x86_64-apple-macosx" |
| 126 | + let armTriple = "arm64-apple-macosx" |
| 127 | + let targetTriple = hostToolchain.targetTriple.arch == .aarch64 ? x86Triple : armTriple |
| 128 | + |
| 129 | + let hostBinPathSegments = try buildData.buildSystem.binPath( |
| 130 | + for: buildData.config, |
| 131 | + ) |
| 132 | + let targetDebugBinPathSegments = try buildData.buildSystem.binPath( |
| 133 | + for: .debug, |
| 134 | + triple: targetTriple, |
| 135 | + ) |
70 | 136 |
|
71 | 137 | // When cross compiling the final product, plugin dependencies should still be built for the host
|
72 |
| - try await fixtureXCTest(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in |
73 |
| - let (stdout, stderr) = try await executeSwiftPackage( |
74 |
| - fixturePath, |
75 |
| - extraArgs: ["--triple", targetTriple, "-v", "build-plugin-dependency"], |
76 |
| - buildSystem: .native, |
77 |
| - ) |
78 |
| - XCTAssertMatch(stdout, .contains("Hello from dependencies-stub")) |
79 |
| - XCTAssertMatch(stderr, .contains("Build of product 'plugintool' complete!")) |
80 |
| - XCTAssertTrue( |
81 |
| - localFileSystem.exists( |
82 |
| - fixturePath.appending(RelativePath(".build/\(hostTriple)/debug/plugintool-tool")) |
| 138 | + try await fixture(name: "Miscellaneous/Plugins/CommandPluginTestStub") { fixturePath in |
| 139 | + // let hostBinPath: AbsolutePath = fixturePath.appending(components: hostBinPathSegments) |
| 140 | + let targetDebugBinPath: AbsolutePath = fixturePath.appending(components: targetDebugBinPathSegments) |
| 141 | + let hostBinPath = try fixturePath.appending( |
| 142 | + components: buildData.buildSystem.binPath( |
| 143 | + for: buildData.config, |
83 | 144 | )
|
84 | 145 | )
|
85 |
| - XCTAssertTrue( |
86 |
| - localFileSystem.exists( |
87 |
| - fixturePath.appending(RelativePath(".build/\(targetTriple)/debug/placeholder")) |
| 146 | + let targetBinPath = try fixturePath.appending( |
| 147 | + components: buildData.buildSystem.binPath( |
| 148 | + for: buildData.config, |
| 149 | + triple: targetTriple, |
88 | 150 | )
|
89 | 151 | )
|
| 152 | + let (stdout, stderr) = try await executeSwiftPackage( |
| 153 | + fixturePath, |
| 154 | + configuration: buildData.config, |
| 155 | + extraArgs: ["-v", "--triple", targetTriple, "build-plugin-dependency"], |
| 156 | + buildSystem: buildData.buildSystem, |
| 157 | + ) |
| 158 | + #expect(stdout.contains("Hello from dependencies-stub")) |
| 159 | + if buildData.buildSystem == .native { |
| 160 | + #expect(stderr.contains("Build of product 'plugintool' complete!")) |
| 161 | + } |
| 162 | + let pluginToolName: String |
| 163 | + let pluginToolBinPath: AbsolutePath |
| 164 | + switch buildData.buildSystem { |
| 165 | + case .native: |
| 166 | + pluginToolName = "plugintool-tool" |
| 167 | + pluginToolBinPath = hostBinPath |
| 168 | + case .swiftbuild: |
| 169 | + pluginToolName = "plugintool" |
| 170 | + pluginToolBinPath = targetBinPath |
| 171 | + case .xcode: |
| 172 | + pluginToolName = "" |
| 173 | + pluginToolBinPath = AbsolutePath("/") |
| 174 | + Issue.record("Test has not been updated for this build system") |
| 175 | + } |
| 176 | + |
| 177 | + expectFileExists(at: targetDebugBinPath.appending("placeholder")) |
| 178 | + expectFileExists(at: pluginToolBinPath.appending(pluginToolName)) |
90 | 179 | }
|
91 | 180 | }
|
| 181 | + |
92 | 182 | }
|
0 commit comments