Skip to content

Commit e731d29

Browse files
committed
Remove client-side API for macro evaluation scopes.
This primarily involves removing the messages to create and discard the scope, and client-side methods for doing so. Clients no longer hold on to a scope directly but rather request the service perform evaluations using a set of build parameters, which eliminates the need to do bookkeeping for these objects. (There is still service-side caching of registered Settings objects in the Session, as it it used in PlanningOperation.) rdar://142511013
1 parent 7dde3c9 commit e731d29

File tree

9 files changed

+20
-292
lines changed

9 files changed

+20
-292
lines changed

Sources/SWBBuildService/Messages.swift

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,42 +1326,6 @@ private func getSettings(for session: Session, workspaceContext: WorkspaceContex
13261326
}
13271327
}
13281328

1329-
/// Handle a `CreateMacroEvaluationScopeRequest` message.
1330-
private struct CreateMacroEvaluationScopeMsg: MessageHandler {
1331-
func handle(request: Request, message: CreateMacroEvaluationScopeRequest) throws -> StringResponse {
1332-
// Look up the session, and create the build parameters.
1333-
let session = try request.session(for: message)
1334-
guard let workspaceContext = session.workspaceContext else {
1335-
throw MsgParserError.missingWorkspaceContext
1336-
}
1337-
let buildParameters = try BuildParameters(from: message.buildParameters)
1338-
1339-
// Create a settings object for the requested level and register it with the session.
1340-
let settings = try getSettings(for: session, workspaceContext: workspaceContext, level: message.level, buildParameters: buildParameters, purpose: .build)
1341-
let handle = session.registerSettings(settings)
1342-
1343-
// Return the handle to the client.
1344-
return StringResponse(handle)
1345-
}
1346-
}
1347-
1348-
private struct DiscardMacroEvaluationScopeMsg: MessageHandler {
1349-
func handle(request: Request, message: DiscardMacroEvaluationScope) throws -> VoidResponse {
1350-
// Look up the session.
1351-
let session = try request.session(for: message)
1352-
1353-
// Discard the settings.
1354-
do {
1355-
try session.unregisterSettings(for: message.settingsHandle)
1356-
}
1357-
catch {
1358-
throw MsgParserError.missingSettings
1359-
}
1360-
1361-
return VoidResponse()
1362-
}
1363-
}
1364-
13651329
private struct MacroEvaluationMsg: MessageHandler {
13661330
func handle(request: Request, message: MacroEvaluationRequest) async throws -> MacroEvaluationResponse {
13671331
// We get the Settings to use for evaluation from the session.
@@ -1641,8 +1605,6 @@ package struct ServiceMessageHandlers: ServiceExtension {
16411605
service.registerMessageHandler(ComputeDependencyGraphMsg.self)
16421606
service.registerMessageHandler(DumpBuildDependencyInfoMsg.self)
16431607

1644-
service.registerMessageHandler(CreateMacroEvaluationScopeMsg.self)
1645-
service.registerMessageHandler(DiscardMacroEvaluationScopeMsg.self)
16461608
service.registerMessageHandler(MacroEvaluationMsg.self)
16471609
service.registerMessageHandler(AllExportedMacrosAndValuesMsg.self)
16481610
service.registerMessageHandler(BuildSettingsEditorInfoMsg.self)

Sources/SWBBuildService/Session.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,12 @@ package final class Session {
204204
return startPIFTransfer(workspaceSignature: workspaceSignature)
205205
}
206206

207-
// MARK: Support for the client to request build setting evaluation
207+
208+
// MARK: Support for saving macro evaluation scopes to look up by a handle (UUID).
208209

209210

210211
/// The active Settings objects being vended for use by the client.
212+
/// - remark: This is presently only used in `PlanningOperation` to be able to evaluate some settings after receiving provisioning inputs from the client, without having to reconstruct the `ConfiguredTarget` in that asyncronous operation.
211213
var registeredSettings = Registry<String, Settings>()
212214

213215
/// Register a `Settings` object with the session. This returns a handle (a `UUID` string) to the caller which it can pass to the client and which can then be used to evaluate settings using this `Settings` object. The caller is responsible for removing this `Settings` object from the session when it is no longer needed.

Sources/SWBProtocol/MacroEvaluationMessages.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ public struct DiscardMacroEvaluationScope: SessionMessage, RequestMessage, Equat
6161

6262
/// The context within which a macro evaluation should occur.
6363
public enum MacroEvaluationRequestContext: Equatable, Sendable, SerializableCodable {
64-
/// A `Settings` handle, if called from a scope.
64+
/// A `Settings` handle, if called by something which is holding on to a handle.
65+
/// - remark: This was previously used when the client held a handle to a macro evaluation scope to use for evaluation. Presently it is unused, but could be revived if the handle-to-a-scope model is useful in the future.
6566
case settingsHandle(String)
6667
/// A level and build parameters, if called on the fly.
6768
case components(level: MacroEvaluationRequestLevel, buildParameters: BuildParametersMessagePayload)

Sources/SwiftBuild/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ add_library(SwiftBuild
4545
SWBIndexingSupport.swift
4646
SWBLocalizationSupport.swift
4747
SWBMacroEvaluation.swift
48-
SWBMacroEvaluationScope.swift
4948
SWBPreviewSupport.swift
5049
SWBProductPlannerSupport.swift
5150
SWBPropertyList.swift

Sources/SwiftBuild/CompatibilityShims.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ public typealias XCBBuildService = SWBBuildService
1515
public typealias XCBBuildServiceConsole = SWBBuildServiceConsole
1616
public typealias XCBServiceConsoleCommandRegistry = SWBServiceConsoleCommandRegistry
1717
public typealias XCBBuildServiceSession = SWBBuildServiceSession
18-
@available(*, deprecated, message: "SWBMacroEvaluationScope is deprecated and should not be used")
19-
public typealias XCBMacroEvaluationScope = SWBMacroEvaluationScope
2018
public typealias XCBuildFileType = SwiftBuildFileType
2119
public typealias XCBBuildOperationTaskMetrics = SWBBuildOperationTaskMetrics
2220
public typealias XCBBuildOperationBacktraceFrame = SWBBuildOperationBacktraceFrame

Sources/SwiftBuild/SWBBuildServiceSession.swift

Lines changed: 13 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@ public enum SwiftBuildServicePIFObjectType: Sendable {
3232
}
3333
}
3434

35-
private protocol InvalidateDeprecated {
36-
func invalidateDeprecated(isolated: (any Actor)?) async throws
37-
}
38-
3935
/// This class encapsulates a unique session connection to the inferior build service process.
4036
///
4137
/// The state for each individual session is separated, and generally a unique session is used for each separate workspace, project, etc. that a client may want to build
@@ -57,9 +53,7 @@ public final class SWBBuildServiceSession: Sendable {
5753
/// For macro evaluation scopes, the session will register each newly created scope with the tracker. If the client manually discards the scope, it will be removed from the tracker by the session. If the client does not manually discard their scopes, they will be cleaned up by the tracker when the session is closed.
5854
///
5955
/// For build operations, the tracker implements a generic background operation queue. Closures are enqueued to a stream, and consumed and awaited on a background task. Closing the session awaits that background taskto ensure all closures are awaited before continuing with teardown.
60-
private actor SessionResourceTracker: InvalidateDeprecated {
61-
@available(*, deprecated, message: "SWBMacroEvaluationScope is deprecated and should not be used")
62-
private var macroEvaluationScopes: [String: SWBMacroEvaluationScope] = [:]
56+
private actor SessionResourceTracker {
6357
private var awaitableBuildOperations: AsyncStreamController<SWBBuildOperation, Never>
6458
private let cancellableBuildOperationsHolder = CancellableBuildOperationsHolder()
6559

@@ -94,16 +88,6 @@ public final class SWBBuildServiceSession: Sendable {
9488
}
9589
}
9690

97-
@available(*, deprecated, message: "SWBMacroEvaluationScope is deprecated and should not be used")
98-
func append(_ scope: SWBMacroEvaluationScope) {
99-
macroEvaluationScopes[scope.settingsHandle] = scope
100-
}
101-
102-
@available(*, deprecated, message: "SWBMacroEvaluationScope is deprecated and should not be used")
103-
func remove(_ scope: SWBMacroEvaluationScope) {
104-
macroEvaluationScopes.removeValue(forKey: scope.settingsHandle)
105-
}
106-
10791
func enqueue(_ operation: SWBBuildOperation) async {
10892
let queuedResult = awaitableBuildOperations.yield(operation)
10993
switch queuedResult {
@@ -128,22 +112,6 @@ public final class SWBBuildServiceSession: Sendable {
128112
awaitableBuildOperations.finish()
129113
await cancellableBuildOperationsHolder.cancelAll()
130114
await awaitableBuildOperations.wait()
131-
132-
try await (self as (any InvalidateDeprecated)).invalidateDeprecated(isolated: #isolation)
133-
}
134-
135-
@available(*, deprecated, message: "SWBMacroEvaluationScope is deprecated and should not be used")
136-
func invalidateDeprecated(isolated: (any Actor)?) async throws {
137-
let scopes = macroEvaluationScopes.values
138-
macroEvaluationScopes = [:]
139-
try await withThrowingTaskGroup(of: Void.self) { group in
140-
for scope in scopes {
141-
group.addTask {
142-
try await scope.invalidate()
143-
}
144-
}
145-
try await group.waitForAll()
146-
}
147115
}
148116
}
149117

@@ -441,70 +409,42 @@ public final class SWBBuildServiceSession: Sendable {
441409
}
442410

443411

444-
// Helper methods to package up a request and send it to the service.
445-
// These methods are used both by the public methods below, and by those in SWBMacroEvaluationScope.
446-
447-
func evaluateMacroAsString(_ macro: String, context: MacroEvaluationRequestContext, overrides: [String : String]?) async throws -> String {
448-
let request = MacroEvaluationRequest(sessionHandle: uid, context: context, request: .macro(macro), overrides: overrides, resultType: .string)
449-
return try await sendMacroEvaluationStringRequest(self, request)
450-
}
451-
452-
func evaluateMacroAsStringList(_ macro: String, context: MacroEvaluationRequestContext, overrides: [String : String]?) async throws -> [String] {
453-
let request = MacroEvaluationRequest(sessionHandle: uid, context: context, request: .macro(macro), overrides: overrides, resultType: .stringList)
454-
return try await sendMacroEvaluationStringListRequest(self, request)
455-
}
456-
457-
func evaluateMacroAsBoolean(_ macro: String, context: MacroEvaluationRequestContext, overrides: [String : String]?) async throws -> Bool {
458-
let request = MacroEvaluationRequest(sessionHandle: uid, context: context, request: .macro(macro), overrides: overrides, resultType: .string)
459-
return try await sendMacroEvaluationStringRequest(self, request) == "YES"
460-
}
461-
462-
func evaluateMacroExpressionAsString(_ expr: String, context: MacroEvaluationRequestContext, overrides: [String : String]?) async throws -> String {
463-
let request = MacroEvaluationRequest(sessionHandle: uid, context: context, request: .stringExpression(expr), overrides: overrides, resultType: .string)
464-
return try await sendMacroEvaluationStringRequest(self, request)
465-
}
466-
467-
func evaluateMacroExpressionAsStringList(_ expr: String, context: MacroEvaluationRequestContext, overrides: [String : String]?) async throws -> [String] {
468-
let request = MacroEvaluationRequest(sessionHandle: uid, context: context, request: .stringExpression(expr), overrides: overrides, resultType: .stringList)
469-
return try await sendMacroEvaluationStringListRequest(self, request)
470-
}
471-
472-
func evaluateMacroExpressionArrayAsStringList(_ expr: [String], context: MacroEvaluationRequestContext, overrides: [String : String]?) async throws -> [String] {
473-
let request = MacroEvaluationRequest(sessionHandle: uid, context: context, request: .stringExpressionArray(expr), overrides: overrides, resultType: .stringList)
474-
return try await sendMacroEvaluationStringListRequest(self, request)
475-
}
476-
477-
478412
// Public methods to perform macro evaluations for a level and build parameters.
479413

480414
public func evaluateMacroAsString(_ macro: String, level: SWBMacroEvaluationLevel, buildParameters: SWBBuildParameters, overrides: [String : String]?) async throws -> String {
481415
let parameters = buildParameters.messagePayloadRepresentation
482-
return try await evaluateMacroAsString(macro, context: .components(level: level.toSWBRequest, buildParameters: parameters), overrides: overrides)
416+
let request = MacroEvaluationRequest(sessionHandle: uid, context: .components(level: level.toSWBRequest, buildParameters: parameters), request: .macro(macro), overrides: overrides, resultType: .string)
417+
return try await sendMacroEvaluationStringRequest(self, request)
483418
}
484419

485420
public func evaluateMacroAsStringList(_ macro: String, level: SWBMacroEvaluationLevel, buildParameters: SWBBuildParameters, overrides: [String : String]?) async throws -> [String] {
486421
let parameters = buildParameters.messagePayloadRepresentation
487-
return try await evaluateMacroAsStringList(macro, context: .components(level: level.toSWBRequest, buildParameters: parameters), overrides: overrides)
422+
let request = MacroEvaluationRequest(sessionHandle: uid, context: .components(level: level.toSWBRequest, buildParameters: parameters), request: .macro(macro), overrides: overrides, resultType: .stringList)
423+
return try await sendMacroEvaluationStringListRequest(self, request)
488424
}
489425

490426
public func evaluateMacroAsBoolean(_ macro: String, level: SWBMacroEvaluationLevel, buildParameters: SWBBuildParameters, overrides: [String : String]?) async throws -> Bool {
491427
let parameters = buildParameters.messagePayloadRepresentation
492-
return try await evaluateMacroAsBoolean(macro, context: .components(level: level.toSWBRequest, buildParameters: parameters), overrides: overrides)
428+
let request = MacroEvaluationRequest(sessionHandle: uid, context: .components(level: level.toSWBRequest, buildParameters: parameters), request: .macro(macro), overrides: overrides, resultType: .string)
429+
return try await sendMacroEvaluationStringRequest(self, request) == "YES"
493430
}
494431

495432
public func evaluateMacroExpressionAsString(_ expr: String, level: SWBMacroEvaluationLevel, buildParameters: SWBBuildParameters, overrides: [String : String]?) async throws -> String {
496433
let parameters = buildParameters.messagePayloadRepresentation
497-
return try await evaluateMacroExpressionAsString(expr, context: .components(level: level.toSWBRequest, buildParameters: parameters), overrides: overrides)
434+
let request = MacroEvaluationRequest(sessionHandle: uid, context: .components(level: level.toSWBRequest, buildParameters: parameters), request: .stringExpression(expr), overrides: overrides, resultType: .string)
435+
return try await sendMacroEvaluationStringRequest(self, request)
498436
}
499437

500438
public func evaluateMacroExpressionAsStringList(_ expr: String, level: SWBMacroEvaluationLevel, buildParameters: SWBBuildParameters, overrides: [String : String]?) async throws -> [String] {
501439
let parameters = buildParameters.messagePayloadRepresentation
502-
return try await evaluateMacroExpressionAsStringList(expr, context: .components(level: level.toSWBRequest, buildParameters: parameters), overrides: overrides)
440+
let request = MacroEvaluationRequest(sessionHandle: uid, context: .components(level: level.toSWBRequest, buildParameters: parameters), request: .stringExpression(expr), overrides: overrides, resultType: .stringList)
441+
return try await sendMacroEvaluationStringListRequest(self, request)
503442
}
504443

505444
public func evaluateMacroExpressionArrayAsStringList(_ expr: [String], level: SWBMacroEvaluationLevel, buildParameters: SWBBuildParameters, overrides: [String : String]?) async throws -> [String] {
506445
let parameters = buildParameters.messagePayloadRepresentation
507-
return try await evaluateMacroExpressionArrayAsStringList(expr, context: .components(level: level.toSWBRequest, buildParameters: parameters), overrides: overrides)
446+
let request = MacroEvaluationRequest(sessionHandle: uid, context: .components(level: level.toSWBRequest, buildParameters: parameters), request: .stringExpressionArray(expr), overrides: overrides, resultType: .stringList)
447+
return try await sendMacroEvaluationStringListRequest(self, request)
508448
}
509449

510450

@@ -525,61 +465,6 @@ public final class SWBBuildServiceSession: Sendable {
525465
}
526466

527467

528-
// MARK: Macro evaluation scopes
529-
530-
531-
// FIXME: rdar://142511013 (Remove deprecated macro evaluation scope logic from SWBuild)
532-
/// Request a macro evaluation scope for given level and build parameters.
533-
@available(*, deprecated, message: "SWBMacroEvaluationScope is deprecated and should not be used")
534-
public func createMacroEvaluationScope(level: SWBMacroEvaluationLevel, buildParameters: SWBBuildParameters) async throws -> SWBMacroEvaluationScope {
535-
let parameters = buildParameters.messagePayloadRepresentation
536-
let request = CreateMacroEvaluationScopeRequest(sessionHandle: uid, level: level.toSWBRequest, buildParameters: parameters)
537-
let scope = try await SWBMacroEvaluationScope(self, service.send(request: request).value)
538-
await sessionResourceTracker.append(scope)
539-
return scope
540-
}
541-
542-
// FIXME: rdar://142511013 (Remove deprecated macro evaluation scope logic from SWBuild)
543-
@available(*, deprecated, message: "SWBMacroEvaluationScope is deprecated and should not be used")
544-
public func createMacroEvaluationScope(_ level: MacroEvaluationScopeLevel, buildParameters: SWBBuildParameters) async throws -> SWBMacroEvaluationScope {
545-
switch level {
546-
case .defaults:
547-
return try await createMacroEvaluationScope(level: .defaults, buildParameters: buildParameters)
548-
case .project(let guid):
549-
return try await createMacroEvaluationScope(level: .project(guid), buildParameters: buildParameters)
550-
case .target(let guid):
551-
return try await createMacroEvaluationScope(level: .target(guid), buildParameters: buildParameters)
552-
}
553-
}
554-
555-
// FIXME: rdar://142511013 (Remove deprecated macro evaluation scope logic from SWBuild)
556-
@available(*, deprecated, message: "MacroEvaluationScopeLevel is deprecated and should not be used")
557-
public enum MacroEvaluationScopeLevel: Sendable {
558-
case defaults
559-
case project(_ guid: String)
560-
case target(_ guid: String)
561-
}
562-
563-
// FIXME: rdar://142511013 (Remove deprecated macro evaluation scope logic from SWBuild)
564-
@available(*, deprecated, message: "SWBMacroEvaluationScope is deprecated and should not be used")
565-
public func createMacroEvaluationScope(projectGUID: String, buildParameters: SWBBuildParameters) async throws -> SWBMacroEvaluationScope {
566-
return try await createMacroEvaluationScope(level: .project(projectGUID), buildParameters: buildParameters)
567-
}
568-
569-
// FIXME: rdar://142511013 (Remove deprecated macro evaluation scope logic from SWBuild)
570-
@available(*, deprecated, message: "SWBMacroEvaluationScope is deprecated and should not be used")
571-
public func createMacroEvaluationScope(targetGUID: String, buildParameters: SWBBuildParameters) async throws -> SWBMacroEvaluationScope {
572-
return try await createMacroEvaluationScope(level: .project(targetGUID), buildParameters: buildParameters)
573-
}
574-
575-
// FIXME: rdar://142511013 (Remove deprecated macro evaluation scope logic from SWBuild)
576-
/// Discard a macro evaluation scope.
577-
@available(*, deprecated, message: "SWBMacroEvaluationScope is deprecated and should not be used")
578-
public func discardMacroEvaluationScope(_ scope: SWBMacroEvaluationScope) async throws {
579-
await sessionResourceTracker.remove(scope)
580-
_ = try await service.send(request: DiscardMacroEvaluationScope(sessionHandle: uid, settingsHandle: scope.settingsHandle))
581-
}
582-
583468
/// Loads the workspace at the specified container path.
584469
///
585470
/// The container path may be:

Sources/SwiftBuild/SWBMacroEvaluation.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public import Foundation
1414

1515
import SWBProtocol
1616

17+
/// Errors resulting from macro evaluation.
1718
public struct SWBMacroEvaluationError: Error, LocalizedError {
1819
public let message: String
1920

0 commit comments

Comments
 (0)