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 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
|
//===----------------------------------------------------------------------===//
//
// This source file is part of the Swift open source project
//
// Copyright (c) 2015-2023 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
@testable import Build
import LLBuildManifest
import PackageGraph
import PackageModel
import struct SPMBuildCore.BuildParameters
@_spi(SwiftPMInternal)
import SPMTestSupport
import class TSCBasic.InMemoryFileSystem
import XCTest
final class LLBuildManifestBuilderTests: XCTestCase {
func testCreateProductCommand() throws {
let pkg = AbsolutePath("/pkg")
let fs = InMemoryFileSystem(
emptyFiles:
pkg.appending(components: "Sources", "exe", "main.swift").pathString
)
let observability = ObservabilitySystem.makeForTesting()
let graph = try loadModulesGraph(
fileSystem: fs,
manifests: [
Manifest.createRootManifest(
displayName: "Pkg",
path: .init(validating: pkg.pathString),
targets: [
TargetDescription(name: "exe"),
]
),
],
observabilityScope: observability.topScope
)
// macOS, release build
var plan = try mockBuildPlan(
environment: BuildEnvironment(
platform: .macOS,
configuration: .release
),
graph: graph,
fileSystem: fs,
observabilityScope: observability.topScope
)
var result = try BuildPlanResult(plan: plan)
var buildProduct = try result.buildProduct(for: "exe")
var llbuild = LLBuildManifestBuilder(
plan,
fileSystem: localFileSystem,
observabilityScope: observability.topScope
)
try llbuild.createProductCommand(buildProduct)
var basicReleaseCommandNames = [
AbsolutePath("/path/to/build/\(plan.destinationBuildParameters.triple)/release/exe.product/Objects.LinkFileList").pathString,
"<exe-\(plan.destinationBuildParameters.triple)-release.exe>",
"C.exe-\(plan.destinationBuildParameters.triple)-release.exe",
]
XCTAssertEqual(
llbuild.manifest.commands.map(\.key).sorted(),
basicReleaseCommandNames.sorted()
)
// macOS, debug build
plan = try mockBuildPlan(
environment: BuildEnvironment(
platform: .macOS,
configuration: .debug
),
graph: graph,
fileSystem: fs,
observabilityScope: observability.topScope
)
result = try BuildPlanResult(plan: plan)
buildProduct = try result.buildProduct(for: "exe")
llbuild = LLBuildManifestBuilder(plan, fileSystem: fs, observabilityScope: observability.topScope)
try llbuild.createProductCommand(buildProduct)
let entitlementsCommandName = "C.exe-\(plan.destinationBuildParameters.triple)-debug.exe-entitlements"
var basicDebugCommandNames = [
AbsolutePath("/path/to/build/\(plan.destinationBuildParameters.triple)/debug/exe.product/Objects.LinkFileList").pathString,
"<exe-\(plan.destinationBuildParameters.triple)-debug.exe>",
"C.exe-\(plan.destinationBuildParameters.triple)-debug.exe",
]
XCTAssertEqual(
llbuild.manifest.commands.map(\.key).sorted(),
(basicDebugCommandNames + [
AbsolutePath("/path/to/build/\(plan.destinationBuildParameters.triple)/debug/exe-entitlement.plist").pathString,
entitlementsCommandName,
]).sorted()
)
guard let entitlementsCommand = llbuild.manifest.commands[entitlementsCommandName]?.tool as? ShellTool else {
XCTFail("unexpected entitlements command type")
return
}
XCTAssertEqual(
entitlementsCommand.inputs,
[
.file("/path/to/build/\(plan.destinationBuildParameters.triple)/debug/exe", isMutated: true),
.file("/path/to/build/\(plan.destinationBuildParameters.triple)/debug/exe-entitlement.plist"),
]
)
XCTAssertEqual(
entitlementsCommand.outputs,
[
.virtual("exe-\(plan.destinationBuildParameters.triple)-debug.exe-CodeSigning"),
]
)
// Linux, release build
plan = try mockBuildPlan(
environment: BuildEnvironment(
platform: .linux,
configuration: .release
),
graph: graph,
fileSystem: fs,
observabilityScope: observability.topScope
)
result = try BuildPlanResult(plan: plan)
buildProduct = try result.buildProduct(for: "exe")
llbuild = LLBuildManifestBuilder(plan, fileSystem: localFileSystem, observabilityScope: observability.topScope)
try llbuild.createProductCommand(buildProduct)
basicReleaseCommandNames = [
AbsolutePath("/path/to/build/\(plan.destinationBuildParameters.triple)/release/exe.product/Objects.LinkFileList").pathString,
"<exe-\(plan.destinationBuildParameters.triple)-release.exe>",
"C.exe-\(plan.destinationBuildParameters.triple)-release.exe",
]
XCTAssertEqual(
llbuild.manifest.commands.map(\.key).sorted(),
basicReleaseCommandNames.sorted()
)
// Linux, debug build
plan = try mockBuildPlan(
environment: BuildEnvironment(
platform: .linux,
configuration: .debug
),
graph: graph,
fileSystem: fs,
observabilityScope: observability.topScope
)
result = try BuildPlanResult(plan: plan)
buildProduct = try result.buildProduct(for: "exe")
llbuild = LLBuildManifestBuilder(plan, fileSystem: fs, observabilityScope: observability.topScope)
try llbuild.createProductCommand(buildProduct)
basicDebugCommandNames = [
AbsolutePath("/path/to/build/\(plan.destinationBuildParameters.triple)/debug/exe.product/Objects.LinkFileList").pathString,
"<exe-\(plan.destinationBuildParameters.triple)-debug.exe>",
"C.exe-\(plan.destinationBuildParameters.triple)-debug.exe",
]
XCTAssertEqual(
llbuild.manifest.commands.map(\.key).sorted(),
basicDebugCommandNames.sorted()
)
}
/// Verifies that two modules with the same name but different triples don't share same build manifest keys.
func testToolsBuildTriple() throws {
let (graph, fs, scope) = try macrosPackageGraph()
let productsTriple = Triple.x86_64MacOS
let toolsTriple = Triple.arm64Linux
let plan = try BuildPlan(
destinationBuildParameters: mockBuildParameters(
destination: .target,
shouldLinkStaticSwiftStdlib: true,
triple: productsTriple
),
toolsBuildParameters: mockBuildParameters(
destination: .host,
triple: toolsTriple
),
graph: graph,
fileSystem: fs,
observabilityScope: scope
)
let builder = LLBuildManifestBuilder(plan, fileSystem: fs, observabilityScope: scope)
let manifest = try builder.generateManifest(at: "/manifest")
XCTAssertNotNil(manifest.commands["C.SwiftSyntax-aarch64-unknown-linux-gnu-debug-tool.module"])
// Ensure that Objects.LinkFileList is -tool suffixed.
XCTAssertNotNil(manifest.commands["/path/to/build/aarch64-unknown-linux-gnu/debug/MMIOMacros-tool.product/Objects.LinkFileList"])
}
}
|