Skip to content

Commit 13162a8

Browse files
committed
Merge remote-tracking branch 'origin/main' into release/5.10
2 parents 73cb713 + 63e1787 commit 13162a8

File tree

6 files changed

+93
-11
lines changed

6 files changed

+93
-11
lines changed

.swiftpm/xcode/xcshareddata/xcschemes/SwiftPM-Package.xcscheme

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,16 @@
829829
ReferencedContainer = "container:">
830830
</BuildableReference>
831831
</TestableReference>
832+
<TestableReference
833+
skipped = "NO">
834+
<BuildableReference
835+
BuildableIdentifier = "primary"
836+
BlueprintIdentifier = "LLBuildManifestTests"
837+
BuildableName = "LLBuildManifestTests"
838+
BlueprintName = "LLBuildManifestTests"
839+
ReferencedContainer = "container:">
840+
</BuildableReference>
841+
</TestableReference>
832842
</Testables>
833843
</TestAction>
834844
<LaunchAction

Package.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,10 @@ let package = Package(
550550
name: "BuildTests",
551551
dependencies: ["Build", "PackageModel", "SPMTestSupport"]
552552
),
553+
.testTarget(
554+
name: "LLBuildManifestTests",
555+
dependencies: ["Basics", "LLBuildManifest", "SPMTestSupport"]
556+
),
553557
.testTarget(
554558
name: "WorkspaceTests",
555559
dependencies: ["Workspace", "SPMTestSupport"]

Sources/LLBuildManifest/BuildManifest.swift

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2014-2021 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -22,7 +22,37 @@ public protocol AuxiliaryFileType {
2222
}
2323

2424
public enum WriteAuxiliary {
25-
public static let fileTypes: [AuxiliaryFileType.Type] = [LinkFileList.self, SourcesFileList.self, SwiftGetVersion.self, XCTestInfoPlist.self]
25+
public static let fileTypes: [AuxiliaryFileType.Type] = [
26+
EntitlementPlist.self,
27+
LinkFileList.self,
28+
SourcesFileList.self,
29+
SwiftGetVersion.self,
30+
XCTestInfoPlist.self
31+
]
32+
33+
public struct EntitlementPlist: AuxiliaryFileType {
34+
public static let name = "entitlement-plist"
35+
36+
public static func computeInputs(entitlement: String) -> [Node] {
37+
[.virtual(Self.name), .virtual(entitlement)]
38+
}
39+
40+
public static func getFileContents(inputs: [Node]) throws -> String {
41+
guard let entitlementName = inputs.last?.extractedVirtualNodeName else {
42+
throw Error.undefinedEntitlementName
43+
}
44+
let encoder = PropertyListEncoder()
45+
encoder.outputFormat = .xml
46+
let result = try encoder.encode([entitlementName: true])
47+
48+
let contents = String(decoding: result, as: UTF8.self)
49+
return contents
50+
}
51+
52+
private enum Error: Swift.Error {
53+
case undefinedEntitlementName
54+
}
55+
}
2656

2757
public struct LinkFileList: AuxiliaryFileType {
2858
public static let name = "link-file-list"
@@ -108,7 +138,7 @@ public enum WriteAuxiliary {
108138
}
109139

110140
public static func getFileContents(inputs: [Node]) throws -> String {
111-
guard let principalClass = inputs.last?.name.dropFirst().dropLast() else {
141+
guard let principalClass = inputs.last?.extractedVirtualNodeName else {
112142
throw Error.undefinedPrincipalClass
113143
}
114144

@@ -206,6 +236,13 @@ public struct BuildManifest {
206236
commands[name] = Command(name: name, tool: tool)
207237
}
208238

239+
public mutating func addEntitlementPlistCommand(entitlement: String, outputPath: AbsolutePath) {
240+
let inputs = WriteAuxiliary.EntitlementPlist.computeInputs(entitlement: entitlement)
241+
let tool = WriteAuxiliaryFile(inputs: inputs, outputFilePath: outputPath)
242+
let name = outputPath.pathString
243+
commands[name] = Command(name: name, tool: tool)
244+
}
245+
209246
public mutating func addWriteLinkFileListCommand(
210247
objects: [AbsolutePath],
211248
linkFileListPath: AbsolutePath

Sources/LLBuildManifest/Node.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2014-2019 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -30,6 +30,12 @@ public struct Node: Hashable, Codable {
3030
self.name = name
3131
self.kind = kind
3232
}
33+
34+
/// Extracts `name` property if this node was constructed as `Node//virtual`.
35+
public var extractedVirtualNodeName: String {
36+
precondition(kind == .virtual)
37+
return String(self.name.dropFirst().dropLast())
38+
}
3339

3440
public static func virtual(_ name: String) -> Node {
3541
precondition(name.first != "<" && name.last != ">", "<> will be inserted automatically")

Sources/LLBuildManifest/Tools.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2014-2021 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
@@ -155,7 +155,7 @@ public struct ShellTool: ToolProtocol {
155155
}
156156
}
157157

158-
public struct WriteAuxiliaryFile: ToolProtocol {
158+
public struct WriteAuxiliaryFile: Equatable, ToolProtocol {
159159
public static let name: String = "write-auxiliary-file"
160160

161161
public let inputs: [Node]

Tests/BuildTests/LLBuildManifestTests.swift renamed to Tests/LLBuildManifestTests/LLBuildManifestTests.swift

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,47 @@
22
//
33
// This source file is part of the Swift open source project
44
//
5-
// Copyright (c) 2014-2021 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014-2023 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See http://swift.org/LICENSE.txt for license information
99
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import Basics
14-
import LLBuildManifest
13+
import struct Basics.AbsolutePath
14+
import class Foundation.PropertyListDecoder
15+
@testable import LLBuildManifest
16+
import SPMTestSupport
17+
import class TSCBasic.InMemoryFileSystem
1518
import XCTest
1619

17-
import class TSCBasic.InMemoryFileSystem
1820

19-
// FIXME: This should be in its own test target.
21+
private let testEntitlement = "test-entitlement"
22+
2023
final class LLBuildManifestTests: XCTestCase {
24+
func testEntitlementsPlist() throws {
25+
let FileType = WriteAuxiliary.EntitlementPlist.self
26+
let inputs = FileType.computeInputs(entitlement: testEntitlement)
27+
XCTAssertEqual(inputs, [.virtual(FileType.name), .virtual(testEntitlement)])
28+
29+
let contents = try FileType.getFileContents(inputs: inputs)
30+
let decoder = PropertyListDecoder()
31+
let decodedEntitlements = try decoder.decode([String: Bool].self, from: .init(contents.utf8))
32+
XCTAssertEqual(decodedEntitlements, [testEntitlement: true])
33+
34+
var manifest = BuildManifest()
35+
let outputPath = AbsolutePath("/test.plist")
36+
manifest.addEntitlementPlistCommand(entitlement: testEntitlement, outputPath: outputPath)
37+
38+
let commandName = outputPath.pathString
39+
XCTAssertEqual(manifest.commands.count, 1)
40+
41+
let command = try XCTUnwrap(manifest.commands[commandName]?.tool as? WriteAuxiliaryFile)
42+
43+
XCTAssertEqual(command, .init(inputs: inputs, outputFilePath: outputPath))
44+
}
45+
2146
func testBasics() throws {
2247
var manifest = BuildManifest()
2348

0 commit comments

Comments
 (0)