Skip to content

Commit 4396e8a

Browse files
authored
Merge pull request #920 from owenv/owenv/incremental-signing-fixes
A couple incremental entitlements processing / signing fixes
2 parents a06f426 + df96201 commit 4396e8a

File tree

11 files changed

+195
-73
lines changed

11 files changed

+195
-73
lines changed

Sources/SWBCore/PlannedTaskAction.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ public protocol TaskActionCreationDelegate
331331
func createLinkAssetCatalogTaskAction() -> any PlannedTaskAction
332332
func createLSRegisterURLTaskAction() -> any PlannedTaskAction
333333
func createODRAssetPackManifestTaskAction() -> any PlannedTaskAction
334-
func createProcessProductEntitlementsTaskAction(scope: MacroEvaluationScope, mergedEntitlements: PropertyListItem, entitlementsVariant: EntitlementsVariant, destinationPlatformName: String, entitlementsFilePath: Path?, fs: any FSProxy) -> any PlannedTaskAction
334+
func createProcessProductEntitlementsTaskAction(mergedEntitlements: PropertyListItem, entitlementsVariant: EntitlementsVariant, allowEntitlementsModification: Bool, entitlementsDestination: EntitlementsDestination, destinationPlatformName: String, entitlementsFilePath: Path?, fs: any FSProxy) -> any PlannedTaskAction
335335
func createProcessProductProvisioningProfileTaskAction() -> any PlannedTaskAction
336336
func createRegisterExecutionPolicyExceptionTaskAction() -> any PlannedTaskAction
337337
func createSwiftHeaderToolTaskAction() -> any PlannedTaskAction

Sources/SWBCore/Settings/BuiltinMacros.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2876,7 +2876,7 @@ public enum StickerSharingLevel: String, Equatable, Hashable, EnumerationMacroTy
28762876
}
28772877

28782878
/// Enumeration macro type for the value of the `ENTITLEMENTS_DESTINATION` build setting.
2879-
public enum EntitlementsDestination: String, Equatable, Hashable, EnumerationMacroType {
2879+
public enum EntitlementsDestination: String, Equatable, Hashable, EnumerationMacroType, Serializable {
28802880
public static let defaultValue = EntitlementsDestination.none
28812881

28822882
case codeSignature = "Signature"

Sources/SWBCore/SpecImplementations/Tools/ProductPackaging.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ public final class ProductPackagingToolSpec : GenericCommandLineToolSpec, SpecId
169169
}
170170

171171
// Create the task action, and then the task.
172-
let action = delegate.taskActionCreationDelegate.createProcessProductEntitlementsTaskAction(scope: cbc.scope, mergedEntitlements: entitlements, entitlementsVariant: entitlementsVariant, destinationPlatformName: platform.name, entitlementsFilePath: codeSignEntitlementsInput?.absolutePath, fs: fs)
172+
let action = delegate.taskActionCreationDelegate.createProcessProductEntitlementsTaskAction(mergedEntitlements: entitlements, entitlementsVariant: entitlementsVariant, allowEntitlementsModification: cbc.scope.evaluate(BuiltinMacros.CODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION), entitlementsDestination: cbc.scope.evaluate(BuiltinMacros.ENTITLEMENTS_DESTINATION), 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
}

Sources/SWBTaskExecution/BuildDescriptionManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,8 @@ extension BuildSystemTaskPlanningDelegate: TaskActionCreationDelegate {
857857
return LSRegisterURLTaskAction()
858858
}
859859

860-
func createProcessProductEntitlementsTaskAction(scope: MacroEvaluationScope, mergedEntitlements: PropertyListItem, entitlementsVariant: EntitlementsVariant, destinationPlatformName: String, entitlementsFilePath: Path?, fs: any FSProxy) -> any PlannedTaskAction {
861-
return ProcessProductEntitlementsTaskAction(scope: scope, fs: fs, entitlements: mergedEntitlements, entitlementsVariant: entitlementsVariant, destinationPlatformName: destinationPlatformName, entitlementsFilePath: entitlementsFilePath)
860+
func createProcessProductEntitlementsTaskAction(mergedEntitlements: PropertyListItem, entitlementsVariant: EntitlementsVariant, allowEntitlementsModification: Bool, entitlementsDestination: EntitlementsDestination, destinationPlatformName: String, entitlementsFilePath: Path?, fs: any FSProxy) -> any PlannedTaskAction {
861+
return ProcessProductEntitlementsTaskAction(fs: fs, entitlements: mergedEntitlements, entitlementsVariant: entitlementsVariant, allowEntitlementsModification: allowEntitlementsModification, entitlementsDestination: entitlementsDestination, destinationPlatformName: destinationPlatformName, entitlementsFilePath: entitlementsFilePath)
862862
}
863863

864864
func createProcessProductProvisioningProfileTaskAction() -> any PlannedTaskAction {

Sources/SWBTaskExecution/TaskActions/ProcessProductEntitlementsTaskAction.swift

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,19 @@ public import SWBMacro
2121
/// Concrete implementation of task for processing product entitlements.
2222
public final class ProcessProductEntitlementsTaskAction: TaskAction
2323
{
24-
/// The scope the task should use to evaluate build settings.
25-
let scope: MacroEvaluationScope
26-
2724
/// The merged entitlements.
2825
let entitlements: PropertyListItem
2926

3027
/// When performing a simulator build, we will have both signed and simulated entitlements; this enum indicates which variant of entitlements this task action is processing.
3128
/// macOS and device builds will normally have only signed entitlements.
3229
let entitlementsVariant: EntitlementsVariant
3330

31+
/// Whether unsafe modification of entitlements during the build should be allowed.
32+
let allowEntitlementsModification: Bool
33+
34+
/// The destination of the processed entitlements.
35+
let entitlementsDestination: EntitlementsDestination
36+
3437
/// The platform we're building for.
3538
let destinationPlatformName: String
3639

@@ -42,12 +45,12 @@ public final class ProcessProductEntitlementsTaskAction: TaskAction
4245
/// The timestamp of the latest modification of the entitlements on `init`
4346
let entitlementsModificationTimestamp: Result<Date, StubError>?
4447

45-
public init(scope: MacroEvaluationScope, fs: any FSProxy, entitlements: PropertyListItem, entitlementsVariant: EntitlementsVariant, destinationPlatformName: String, entitlementsFilePath: Path?)
48+
public init(fs: any FSProxy, entitlements: PropertyListItem, entitlementsVariant: EntitlementsVariant, allowEntitlementsModification: Bool, entitlementsDestination: EntitlementsDestination, destinationPlatformName: String, entitlementsFilePath: Path?)
4649
{
47-
self.scope = scope
48-
4950
self.entitlements = entitlements
5051
self.entitlementsVariant = entitlementsVariant
52+
self.allowEntitlementsModification = allowEntitlementsModification
53+
self.entitlementsDestination = entitlementsDestination
5154
self.destinationPlatformName = destinationPlatformName
5255
self.entitlementsFilePath = entitlementsFilePath
5356
if let entitlementsFilePath, fs.exists(entitlementsFilePath) {
@@ -257,7 +260,7 @@ public final class ProcessProductEntitlementsTaskAction: TaskAction
257260
// Updating entitlements is not something that is actively encouraged or supported, however, this is a compatibility pain point for certain projects that we need to maintain some ability to do this. A better approach is to plumb this through the system so that we can track this as a proper dependency mechanism, potentially through our virtual task producers... however, until then, we enable this functionality for those existing clients.
258261

259262
// Also, we never modify the signed entitlements when building for simulators and ENTITLEMENTS_DESTINATION is __entitlements, since those are only expected to contain get-task-allow; see rdar://55324156.
260-
let entitlementsVariantToModify: EntitlementsVariant = scope.evaluate(BuiltinMacros.ENTITLEMENTS_DESTINATION) == .entitlementsSection ? .simulated : .signed
263+
let entitlementsVariantToModify: EntitlementsVariant = entitlementsDestination == .entitlementsSection ? .simulated : .signed
261264
let allowEntitlementsModification = entitlementsVariantToModify == entitlementsVariant
262265

263266
var userModifiedEntitlements: PropertyListItem?
@@ -279,7 +282,7 @@ public final class ProcessProductEntitlementsTaskAction: TaskAction
279282
}
280283

281284
if originalModificationTimestamp != currentModificationTimestamp {
282-
if scope.evaluate(BuiltinMacros.CODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION) == false {
285+
if !self.allowEntitlementsModification {
283286
outputDelegate.emitError("Entitlements file \"\(entitlementsFilePath.basename)\" was modified during the build, which is not supported. You can disable this error by setting 'CODE_SIGN_ALLOW_ENTITLEMENTS_MODIFICATION' to 'YES', however this may cause the built product's code signature or provisioning profile to contain incorrect entitlements.")
284287
return .failed
285288
}
@@ -391,12 +394,13 @@ public final class ProcessProductEntitlementsTaskAction: TaskAction
391394

392395
public override func serialize<T: Serializer>(to serializer: T)
393396
{
394-
serializer.serializeAggregate(7)
397+
serializer.serializeAggregate(8)
395398
{
396-
serializer.serialize(scope)
397399
// FIXME: <rdar://problem/40036582> We have no way to handle any errors in PropertyListItem.asBytes() here.
398400
serializer.serialize(try? entitlements.asBytes(.binary))
399401
serializer.serialize(entitlementsVariant)
402+
serializer.serialize(allowEntitlementsModification)
403+
serializer.serialize(entitlementsDestination)
400404
serializer.serialize(destinationPlatformName)
401405
serializer.serialize(entitlementsFilePath)
402406
serializer.serialize(entitlementsModificationTimestamp)
@@ -406,10 +410,11 @@ public final class ProcessProductEntitlementsTaskAction: TaskAction
406410

407411
public required init(from deserializer: any Deserializer) throws
408412
{
409-
try deserializer.beginAggregate(7)
410-
self.scope = try deserializer.deserialize()
413+
try deserializer.beginAggregate(8)
411414
self.entitlements = try PropertyList.fromBytes(try deserializer.deserialize())
412415
self.entitlementsVariant = try deserializer.deserialize()
416+
self.allowEntitlementsModification = try deserializer.deserialize()
417+
self.entitlementsDestination = try deserializer.deserialize()
413418
self.destinationPlatformName = try deserializer.deserialize()
414419
self.entitlementsFilePath = try deserializer.deserialize()
415420
self.entitlementsModificationTimestamp = try deserializer.deserialize()

Sources/SWBTestSupport/CapturingTaskGenerationDelegate.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,8 @@ extension CapturingTaskGenerationDelegate: TaskActionCreationDelegate {
180180
return LSRegisterURLTaskAction()
181181
}
182182

183-
package func createProcessProductEntitlementsTaskAction(scope: MacroEvaluationScope, mergedEntitlements: PropertyListItem, entitlementsVariant: EntitlementsVariant, destinationPlatformName: String, entitlementsFilePath: Path?, fs: any FSProxy) -> any PlannedTaskAction {
184-
return ProcessProductEntitlementsTaskAction(scope: scope, fs: fs, entitlements: mergedEntitlements, entitlementsVariant: entitlementsVariant, destinationPlatformName: destinationPlatformName, entitlementsFilePath: entitlementsFilePath)
183+
package func createProcessProductEntitlementsTaskAction(mergedEntitlements: PropertyListItem, entitlementsVariant: EntitlementsVariant, allowEntitlementsModification: Bool, entitlementsDestination: EntitlementsDestination, destinationPlatformName: String, entitlementsFilePath: Path?, fs: any FSProxy) -> any PlannedTaskAction {
184+
return ProcessProductEntitlementsTaskAction(fs: fs, entitlements: mergedEntitlements, entitlementsVariant: entitlementsVariant, allowEntitlementsModification: allowEntitlementsModification, entitlementsDestination: entitlementsDestination, destinationPlatformName: destinationPlatformName, entitlementsFilePath: entitlementsFilePath)
185185
}
186186

187187
package func createProcessProductProvisioningProfileTaskAction() -> any PlannedTaskAction {

Sources/SWBTestSupport/TaskPlanningTestSupport.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,8 @@ extension TestTaskPlanningDelegate: TaskActionCreationDelegate {
408408
return LSRegisterURLTaskAction()
409409
}
410410

411-
package func createProcessProductEntitlementsTaskAction(scope: MacroEvaluationScope, mergedEntitlements: PropertyListItem, entitlementsVariant: EntitlementsVariant, destinationPlatformName: String, entitlementsFilePath: Path?, fs: any FSProxy) -> any PlannedTaskAction {
412-
return ProcessProductEntitlementsTaskAction(scope: scope, fs: fs, entitlements: mergedEntitlements, entitlementsVariant: entitlementsVariant, destinationPlatformName: destinationPlatformName, entitlementsFilePath: entitlementsFilePath)
411+
package func createProcessProductEntitlementsTaskAction(mergedEntitlements: PropertyListItem, entitlementsVariant: EntitlementsVariant, allowEntitlementsModification: Bool, entitlementsDestination: EntitlementsDestination, destinationPlatformName: String, entitlementsFilePath: Path?, fs: any FSProxy) -> any PlannedTaskAction {
412+
return ProcessProductEntitlementsTaskAction(fs: fs, entitlements: mergedEntitlements, entitlementsVariant: entitlementsVariant, allowEntitlementsModification: allowEntitlementsModification, entitlementsDestination: entitlementsDestination, destinationPlatformName: destinationPlatformName, entitlementsFilePath: entitlementsFilePath)
413413
}
414414

415415
package func createProcessProductProvisioningProfileTaskAction() -> any PlannedTaskAction {

0 commit comments

Comments
 (0)