Skip to content

Commit f8e9d6c

Browse files
committed
Ensure the build description is regenerated when entitlements change
This avoids incorrectly diagnosing an entitlements change during the build.
1 parent 3bdc19e commit f8e9d6c

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

Sources/SWBCore/SpecImplementations/Tools/ProductPackaging.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ public final class ProductPackagingToolSpec : GenericCommandLineToolSpec, SpecId
170170

171171
// Create the task action, and then the task.
172172
let action = delegate.taskActionCreationDelegate.createProcessProductEntitlementsTaskAction(scope: cbc.scope, mergedEntitlements: entitlements, entitlementsVariant: entitlementsVariant, destinationPlatformName: platform.name, entitlementsFilePath: codeSignEntitlementsInput?.absolutePath, fs: fs)
173+
// The action records a timestamp representing the last modification date of the entitlements file, so changes to the input must invalidate the build description.
174+
if let path = codeSignEntitlementsInput?.absolutePath {
175+
delegate.access(path: path)
176+
}
173177

174178
delegate.createTask(type: self, ruleInfo: ["ProcessProductPackaging", codeSignEntitlementsInput?.absolutePath.str ?? "", outputPath.str], commandLine: commandLine, additionalOutput: additionalOutput, environment: environmentFromSpec(cbc, delegate), workingDirectory: cbc.producer.defaultWorkingDirectory, inputs: inputs.map(\.absolutePath), outputs: [ outputPath ], action: action, execDescription: resolveExecutionDescription(cbc, delegate), enableSandboxing: enableSandboxing)
175179
}
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2025 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import SWBBuildSystem
14+
import SWBCore
15+
import SWBTaskExecution
16+
import SWBTestSupport
17+
import SWBUtil
18+
import Testing
19+
20+
@Suite
21+
fileprivate struct CodeSigningBuildOperationTests: CoreBasedTests {
22+
@Test(.requireSDKs(.macOS))
23+
func entitlementsModificationInvalidatesBuildDescription() async throws {
24+
try await withTemporaryDirectory { tmpDirPath in
25+
let testProject = TestProject(
26+
"aProject",
27+
sourceRoot: tmpDirPath,
28+
groupTree: TestGroup(
29+
"SomeFiles", path: "Sources",
30+
children: [
31+
TestFile("AppSource.m"),
32+
]),
33+
buildConfigurations: [
34+
TestBuildConfiguration( "Debug", buildSettings: [
35+
"COPY_PHASE_STRIP": "NO",
36+
"DEBUG_INFORMATION_FORMAT": "dwarf",
37+
"GENERATE_INFOPLIST_FILE": "YES",
38+
"PRODUCT_NAME": "$(TARGET_NAME)",
39+
"CODE_SIGN_IDENTITY": "-",
40+
"CODE_SIGN_ENTITLEMENTS": "Entitlements.entitlements",
41+
"SDKROOT": "macosx",
42+
"SUPPORTED_PLATFORMS": "macosx",
43+
]),
44+
],
45+
targets: [
46+
TestStandardTarget(
47+
"AppTarget",
48+
type: .application,
49+
buildPhases: [
50+
TestSourcesBuildPhase([
51+
"AppSource.m",
52+
]),
53+
],
54+
),
55+
]
56+
)
57+
58+
let tester = try await BuildOperationTester(getCore(), testProject, simulated: false)
59+
let SRCROOT = tester.workspace.projects[0].sourceRoot.str
60+
61+
try tester.fs.createDirectory(Path(SRCROOT).join("Sources"), recursive: true)
62+
try tester.fs.write(Path(SRCROOT).join("Sources/AppSource.m"), contents: "int main() { return 0; }")
63+
try await tester.fs.writePlist(Path(SRCROOT).join("Entitlements.entitlements"), .plDict([:]))
64+
65+
try await tester.checkBuild(parameters: BuildParameters(configuration: "Debug"), runDestination: .macOS, persistent: true, signableTargets: ["AppTarget"]) { results in
66+
results.checkNoDiagnostics()
67+
}
68+
69+
// Modify the entitlements in between builds, but make no other changes which would invalidate the build description.
70+
try tester.fs.touch(Path(SRCROOT).join("Entitlements.entitlements"))
71+
72+
// A subsequent build should succeed, and should NOT diagnose entitlements modification during the build.
73+
try await tester.checkBuild(parameters: BuildParameters(configuration: "Debug"), runDestination: .macOS, persistent: true, signableTargets: ["AppTarget"]) { results in
74+
results.checkNoDiagnostics()
75+
}
76+
}
77+
}
78+
}
79+

0 commit comments

Comments
 (0)