Skip to content

Commit e3b8bba

Browse files
committed
Silence warnings related to SWBMacroEvaluationScope deprecation
1 parent 28b29f3 commit e3b8bba

File tree

3 files changed

+13
-77
lines changed

3 files changed

+13
-77
lines changed

Sources/SwiftBuild/CompatibilityShims.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ 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")
1819
public typealias XCBMacroEvaluationScope = SWBMacroEvaluationScope
1920
public typealias XCBuildFileType = SwiftBuildFileType
2021
public typealias XCBBuildOperationTaskMetrics = SWBBuildOperationTaskMetrics

Sources/SwiftBuild/SWBBuildServiceSession.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public enum SwiftBuildServicePIFObjectType: Sendable {
3232
}
3333
}
3434

35+
private protocol InvalidateDeprecated {
36+
func invalidateDeprecated(isolated: (any Actor)?) async throws
37+
}
3538

3639
/// This class encapsulates a unique session connection to the inferior build service process.
3740
///
@@ -54,7 +57,8 @@ public final class SWBBuildServiceSession: Sendable {
5457
/// 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.
5558
///
5659
/// 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.
57-
private actor SessionResourceTracker {
60+
private actor SessionResourceTracker: InvalidateDeprecated {
61+
@available(*, deprecated, message: "SWBMacroEvaluationScope is deprecated and should not be used")
5862
private var macroEvaluationScopes: [String: SWBMacroEvaluationScope] = [:]
5963
private var awaitableBuildOperations: AsyncStreamController<SWBBuildOperation, Never>
6064
private let cancellableBuildOperationsHolder = CancellableBuildOperationsHolder()
@@ -90,10 +94,12 @@ public final class SWBBuildServiceSession: Sendable {
9094
}
9195
}
9296

97+
@available(*, deprecated, message: "SWBMacroEvaluationScope is deprecated and should not be used")
9398
func append(_ scope: SWBMacroEvaluationScope) {
9499
macroEvaluationScopes[scope.settingsHandle] = scope
95100
}
96101

102+
@available(*, deprecated, message: "SWBMacroEvaluationScope is deprecated and should not be used")
97103
func remove(_ scope: SWBMacroEvaluationScope) {
98104
macroEvaluationScopes.removeValue(forKey: scope.settingsHandle)
99105
}
@@ -123,6 +129,11 @@ public final class SWBBuildServiceSession: Sendable {
123129
await cancellableBuildOperationsHolder.cancelAll()
124130
await awaitableBuildOperations.wait()
125131

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 {
126137
let scopes = macroEvaluationScopes.values
127138
macroEvaluationScopes = [:]
128139
try await withThrowingTaskGroup(of: Void.self) { group in

Tests/SwiftBuildTests/MacroEvaluationTests.swift

Lines changed: 0 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -45,43 +45,6 @@ fileprivate struct MacroEvaluationTests {
4545

4646
let buildParameters = SWBBuildParameters()
4747

48-
// Evaluate using a scope.
49-
do {
50-
// Get the project macro scope.
51-
let scope = try await session.createMacroEvaluationScope(level: .project(testProject.guid), buildParameters: buildParameters)
52-
53-
expectEqual(try await scope.evaluateMacroAsString("PROJECT"), "aProject")
54-
#expect(try await !scope.evaluateMacroAsBool("PROJECT"))
55-
expectEqual(try await scope.evaluateMacroAsStringList("PROJECT"), ["aProject"])
56-
expectEqual(try await scope.evaluateMacroAsString("TARGET_NAME"), "")
57-
#expect(try await !scope.evaluateMacroAsBool("TARGET_NAME"))
58-
expectEqual(try await scope.evaluateMacroAsStringList("TARGET_NAME"), [""])
59-
expectEqual(try await scope.evaluateMacroAsStringList("HEADER_SEARCH_PATHS"), [])
60-
#expect(try await !scope.evaluateMacroAsBool("HEADER_SEARCH_PATHS"))
61-
expectEqual(try await scope.evaluateMacroAsString("HEADER_SEARCH_PATHS"), "")
62-
#expect(try await scope.evaluateMacroAsBool("INFOPLIST_EXPAND_BUILD_SETTINGS"))
63-
expectEqual(try await scope.evaluateMacroAsStringList("INFOPLIST_EXPAND_BUILD_SETTINGS"), ["YES"])
64-
expectEqual(try await scope.evaluateMacroAsString("INFOPLIST_EXPAND_BUILD_SETTINGS"), "YES")
65-
await #expect(throws: (any Error).self) {
66-
try await scope.evaluateMacroAsBool("DOES_NOT_EXIST")
67-
}
68-
await #expect(throws: (any Error).self) {
69-
try await scope.evaluateMacroAsString("DOES_NOT_EXIST")
70-
}
71-
await #expect(throws: (any Error).self) {
72-
try await scope.evaluateMacroAsStringList("DOES_NOT_EXIST")
73-
}
74-
}
75-
76-
do {
77-
// Get the target macro scope.
78-
let scope = try await session.createMacroEvaluationScope(level: .target(testTarget.guid), buildParameters: buildParameters)
79-
80-
expectEqual(try await scope.evaluateMacroAsString("TARGET_NAME"), "ExternalTarget")
81-
#expect(try await !scope.evaluateMacroAsBool("TARGET_NAME"))
82-
expectEqual(try await scope.evaluateMacroAsStringList("TARGET_NAME"), ["ExternalTarget"])
83-
}
84-
8548
// Evaluate directly against the model objects.
8649
do {
8750
let level = SWBMacroEvaluationLevel.project(testProject.guid)
@@ -240,45 +203,6 @@ fileprivate struct MacroEvaluationTests {
240203
parameters.action = "build"
241204
parameters.configurationName = "Config1"
242205

243-
// Evaluate using a scope.
244-
let scope = try await session.createMacroEvaluationScope(level: .target("T1"), buildParameters: parameters)
245-
246-
// Evaluate some macros as strings.
247-
await #expect(throws: (any Error).self) {
248-
try await scope.evaluateMacroAsString("UNDEFINED_MACRO", overrides: nil)
249-
}
250-
expectEqual(try await scope.evaluateMacroAsString("USER", overrides: nil), userInfo.userName)
251-
expectEqual(try await scope.evaluateMacroAsString("PRODUCT_NAME", overrides: nil), "MyApp")
252-
expectEqual(try await scope.evaluateMacroAsString("TARGET_NAME", overrides: nil), "Target1")
253-
expectEqual(try await scope.evaluateMacroAsString("CONFIGURATION", overrides: nil), "Config1")
254-
expectEqual(try await scope.evaluateMacroAsString("IS_TRUE", overrides: nil), "YES")
255-
expectEqual(try await scope.evaluateMacroAsString("IS_FALSE", overrides: nil), "NO")
256-
expectEqual(try await scope.evaluateMacroAsString("OTHER_CFLAGS", overrides: nil), " -DPROJECT -DTARGET")
257-
// Evaluate some macros as booleans.
258-
#expect(try await scope.evaluateMacroAsBool("IS_TRUE"))
259-
#expect(try await !scope.evaluateMacroAsBool("IS_FALSE"))
260-
await #expect(throws: (any Error).self) {
261-
try await scope.evaluateMacroAsBool("UNDEFINED_MACRO")
262-
}
263-
#expect(try await !scope.evaluateMacroAsBool("PRODUCT_NAME"))
264-
265-
// Evaluate some macros as string lists.
266-
expectEqual(try await scope.evaluateMacroAsStringList("OTHER_CFLAGS"), ["-DPROJECT", "-DTARGET"])
267-
// Evaluate some macro expressions as strings.
268-
expectEqual(try await scope.evaluateMacroExpressionAsString("The name of the product is $(FULL_PRODUCT_NAME)"), "The name of the product is MyApp.app")
269-
270-
#expect((try await scope.evaluateMacroExpressionAsString("$(TARGET_BUILD_DIR)/$(EXECUTABLE_PATH)")).hasSuffix("build/Config1/MyApp.app/Contents/MacOS/MyApp"))
271-
272-
// Evaluate some macro expressions as string lists.
273-
expectEqual(try await scope.evaluateMacroExpressionAsStringList("$(FULL_PRODUCT_NAME)"), ["MyApp.app"])
274-
expectEqual(try await scope.evaluateMacroExpressionArrayAsStringList(["$(A)", "$(B)"]), ["A", "B"])
275-
// Evaluate an array of macro expressions as individual strings.
276-
expectEqual(try await scope.evaluateMacroExpressionArrayAsStringList(["$(A)", "$(B)", "$(IS_TRUE)"]), ["A", "B", "YES"])
277-
// Test using overrides.
278-
expectEqual(try await scope.evaluateMacroAsString("FLEXIBLE"), "A B C")
279-
expectEqual(try await scope.evaluateMacroAsString("FLEXIBLE", overrides: ["A": "D"]), "D B C")
280-
expectEqual(try await scope.evaluateMacroAsString("FLEXIBLE", overrides: ["B": "$(PRODUCT_NAME)"]), "A MyApp C")
281-
expectEqual(try await scope.evaluateMacroExpressionAsStringList("$(FLEXIBLE)", overrides: ["C": "X Y"]), ["A", "B", "X", "Y"])
282206
// Evaluate directly against the target.
283207
let level = SWBMacroEvaluationLevel.target("T1")
284208

0 commit comments

Comments
 (0)