Skip to content

Commit 981bbda

Browse files
committed
Call into the BuildSystemManager from BSMDelegate in BuildSystemManagerTests to get build settings
1 parent 1606e73 commit 981bbda

File tree

2 files changed

+48
-33
lines changed

2 files changed

+48
-33
lines changed

Sources/SKCore/BuildSystemManager.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,21 @@ extension BuildSystemManager {
183183
}
184184
}
185185

186+
public func buildSettings(
187+
ofMainFileFor document: DocumentURI,
188+
language: Language
189+
) async -> (buildSettings: FileBuildSettings, isFallback: Bool)? {
190+
if let mainFile = mainFilesProvider?.mainFilesContainingFile(document).first {
191+
if let mainFileBuildSettings = await buildSettings(for: mainFile, language: language) {
192+
return (
193+
buildSettings: mainFileBuildSettings.buildSettings.patching(newFile: document.pseudoPath, originalFile: mainFile.pseudoPath),
194+
isFallback: mainFileBuildSettings.isFallback
195+
)
196+
}
197+
}
198+
return await buildSettings(for: document, language: language)
199+
}
200+
186201
public func registerForChangeNotifications(for uri: DocumentURI, language: Language) async {
187202
log("registerForChangeNotifications(\(uri.pseudoPath))")
188203
let mainFile: DocumentURI

Tests/SKCoreTests/BuildSystemManagerTests.swift

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ final class BuildSystemManagerTests: XCTestCase {
103103

104104
bs.map[a] = FileBuildSettings(compilerArguments: ["x"])
105105
let initial = expectation(description: "initial settings")
106-
await del.setExpected([(a, bs.map[a]!, initial, #file, #line)])
106+
await del.setExpected([(a, .swift, bs.map[a]!, initial, #file, #line)])
107107
await bsm.registerForChangeNotifications(for: a, language: .swift)
108108
try await fulfillmentOfOrThrow([initial])
109109

110110
bs.map[a] = nil
111111
let changed = expectation(description: "changed settings")
112-
await del.setExpected([(a, nil, changed, #file, #line)])
112+
await del.setExpected([(a, .swift, nil, changed, #file, #line)])
113113
bsm.fileBuildSettingsChanged([a: .removedOrUnavailable])
114114
try await fulfillmentOfOrThrow([changed])
115115
}
@@ -126,13 +126,13 @@ final class BuildSystemManagerTests: XCTestCase {
126126
defer { withExtendedLifetime(bsm) {} } // Keep BSM alive for callbacks.
127127
let del = await BSMDelegate(bsm)
128128
let initial = expectation(description: "initial settings")
129-
await del.setExpected([(a, nil, initial, #file, #line)])
129+
await del.setExpected([(a, .swift, nil, initial, #file, #line)])
130130
await bsm.registerForChangeNotifications(for: a, language: .swift)
131131
try await fulfillmentOfOrThrow([initial])
132132

133133
bs.map[a] = FileBuildSettings(compilerArguments: ["x"])
134134
let changed = expectation(description: "changed settings")
135-
await del.setExpected([(a, bs.map[a]!, changed, #file, #line)])
135+
await del.setExpected([(a, .swift, bs.map[a]!, changed, #file, #line)])
136136
bsm.fileBuildSettingsChanged([a: .modified(bs.map[a]!)])
137137
try await fulfillmentOfOrThrow([changed])
138138
}
@@ -151,19 +151,19 @@ final class BuildSystemManagerTests: XCTestCase {
151151
let del = await BSMDelegate(bsm)
152152
let fallbackSettings = fallback.buildSettings(for: a, language: .swift)
153153
let initial = expectation(description: "initial fallback settings")
154-
await del.setExpected([(a, fallbackSettings, initial, #file, #line)])
154+
await del.setExpected([(a, .swift, fallbackSettings, initial, #file, #line)])
155155
await bsm.registerForChangeNotifications(for: a, language: .swift)
156156
try await fulfillmentOfOrThrow([initial])
157157

158158
bs.map[a] = FileBuildSettings(compilerArguments: ["non-fallback", "args"])
159159
let changed = expectation(description: "changed settings")
160-
await del.setExpected([(a, bs.map[a]!, changed, #file, #line)])
160+
await del.setExpected([(a, .swift, bs.map[a]!, changed, #file, #line)])
161161
bsm.fileBuildSettingsChanged([a: .modified(bs.map[a]!)])
162162
try await fulfillmentOfOrThrow([changed])
163163

164164
bs.map[a] = nil
165165
let revert = expectation(description: "revert to fallback settings")
166-
await del.setExpected([(a, fallbackSettings, revert, #file, #line)])
166+
await del.setExpected([(a, .swift, fallbackSettings, revert, #file, #line)])
167167
bsm.fileBuildSettingsChanged([a: .removedOrUnavailable])
168168
try await fulfillmentOfOrThrow([revert])
169169
}
@@ -184,18 +184,18 @@ final class BuildSystemManagerTests: XCTestCase {
184184
bs.map[a] = FileBuildSettings(compilerArguments: ["x"])
185185
bs.map[b] = FileBuildSettings(compilerArguments: ["y"])
186186
let initial = expectation(description: "initial settings")
187-
await del.setExpected([(a, bs.map[a]!, initial, #file, #line)])
187+
await del.setExpected([(a, .swift, bs.map[a]!, initial, #file, #line)])
188188
await bsm.registerForChangeNotifications(for: a, language: .swift)
189189
try await fulfillmentOfOrThrow([initial])
190190
let initialB = expectation(description: "initial settings")
191-
await del.setExpected([(b, bs.map[b]!, initialB, #file, #line)])
191+
await del.setExpected([(b, .swift, bs.map[b]!, initialB, #file, #line)])
192192
await bsm.registerForChangeNotifications(for: b, language: .swift)
193193
try await fulfillmentOfOrThrow([initialB])
194194

195195
bs.map[a] = FileBuildSettings(compilerArguments: ["xx"])
196196
bs.map[b] = FileBuildSettings(compilerArguments: ["yy"])
197197
let changed = expectation(description: "changed settings")
198-
await del.setExpected([(a, bs.map[a]!, changed, #file, #line)])
198+
await del.setExpected([(a, .swift, bs.map[a]!, changed, #file, #line)])
199199
bsm.fileBuildSettingsChanged([a: .modified(bs.map[a]!)])
200200
try await fulfillmentOfOrThrow([changed])
201201

@@ -205,8 +205,8 @@ final class BuildSystemManagerTests: XCTestCase {
205205
let changedBothA = expectation(description: "changed setting a")
206206
let changedBothB = expectation(description: "changed setting b")
207207
await del.setExpected([
208-
(a, bs.map[a]!, changedBothA, #file, #line),
209-
(b, bs.map[b]!, changedBothB, #file, #line),
208+
(a, .swift, bs.map[a]!, changedBothA, #file, #line),
209+
(b, .swift, bs.map[b]!, changedBothB, #file, #line),
210210
])
211211
bsm.fileBuildSettingsChanged([
212212
a:. modified(bs.map[a]!),
@@ -232,19 +232,19 @@ final class BuildSystemManagerTests: XCTestCase {
232232
bs.map[b] = FileBuildSettings(compilerArguments: ["b"])
233233

234234
let initialA = expectation(description: "initial settings a")
235-
await del.setExpected([(a, bs.map[a]!, initialA, #file, #line)])
235+
await del.setExpected([(a, .swift, bs.map[a]!, initialA, #file, #line)])
236236
await bsm.registerForChangeNotifications(for: a, language: .swift)
237237
try await fulfillmentOfOrThrow([initialA])
238238

239239
let initialB = expectation(description: "initial settings b")
240-
await del.setExpected([(b, bs.map[b]!, initialB, #file, #line)])
240+
await del.setExpected([(b, .swift, bs.map[b]!, initialB, #file, #line)])
241241
await bsm.registerForChangeNotifications(for: b, language: .swift)
242242
try await fulfillmentOfOrThrow([initialB])
243243

244244
bs.map[a] = nil
245245
bs.map[b] = nil
246246
let changed = expectation(description: "changed settings")
247-
await del.setExpected([(b, nil, changed, #file, #line)])
247+
await del.setExpected([(b, .swift, nil, changed, #file, #line)])
248248
bsm.fileBuildSettingsChanged([
249249
b: .removedOrUnavailable
250250
])
@@ -274,35 +274,35 @@ final class BuildSystemManagerTests: XCTestCase {
274274
bs.map[cpp2] = FileBuildSettings(compilerArguments: ["C++ 2"])
275275

276276
let initial = expectation(description: "initial settings via cpp1")
277-
await del.setExpected([(h, bs.map[cpp1]!, initial, #file, #line)])
277+
await del.setExpected([(h, .c, bs.map[cpp1]!, initial, #file, #line)])
278278
await bsm.registerForChangeNotifications(for: h, language: .c)
279279
try await fulfillmentOfOrThrow([initial])
280280

281281
mainFiles.mainFiles[h] = Set([cpp2])
282282

283283
let changed = expectation(description: "changed settings to cpp2")
284-
await del.setExpected([(h, bs.map[cpp2]!, changed, #file, #line)])
284+
await del.setExpected([(h, .c, bs.map[cpp2]!, changed, #file, #line)])
285285
await bsm.mainFilesChangedImpl()
286286
try await fulfillmentOfOrThrow([changed])
287287

288288
let changed2 = expectation(description: "still cpp2, no update")
289289
changed2.isInverted = true
290-
await del.setExpected([(h, nil, changed2, #file, #line)])
290+
await del.setExpected([(h, .c, nil, changed2, #file, #line)])
291291
await bsm.mainFilesChangedImpl()
292292
try await fulfillmentOfOrThrow([changed2], timeout: 1)
293293

294294
mainFiles.mainFiles[h] = Set([cpp1, cpp2])
295295

296296
let changed3 = expectation(description: "added main file, no update")
297297
changed3.isInverted = true
298-
await del.setExpected([(h, nil, changed3, #file, #line)])
298+
await del.setExpected([(h, .c, nil, changed3, #file, #line)])
299299
await bsm.mainFilesChangedImpl()
300300
try await fulfillmentOfOrThrow([changed3], timeout: 1)
301301

302302
mainFiles.mainFiles[h] = Set([])
303303

304304
let changed4 = expectation(description: "changed settings to []")
305-
await del.setExpected([(h, nil, changed4, #file, #line)])
305+
await del.setExpected([(h, .c, nil, changed4, #file, #line)])
306306
await bsm.mainFilesChangedImpl()
307307
try await fulfillmentOfOrThrow([changed4])
308308
}
@@ -333,8 +333,8 @@ final class BuildSystemManagerTests: XCTestCase {
333333
let expectedArgsH1 = FileBuildSettings(compilerArguments: ["-xc++", cppArg, h1.pseudoPath])
334334
let expectedArgsH2 = FileBuildSettings(compilerArguments: ["-xc++", cppArg, h2.pseudoPath])
335335
await del.setExpected([
336-
(h1, expectedArgsH1, initial1, #file, #line),
337-
(h2, expectedArgsH2, initial2, #file, #line),
336+
(h1, .c, expectedArgsH1, initial1, #file, #line),
337+
(h2, .c, expectedArgsH2, initial2, #file, #line),
338338
])
339339

340340
await bsm.registerForChangeNotifications(for: h1, language: .c)
@@ -351,8 +351,8 @@ final class BuildSystemManagerTests: XCTestCase {
351351
let newArgsH1 = FileBuildSettings(compilerArguments: ["-xc++", newCppArg, h1.pseudoPath])
352352
let newArgsH2 = FileBuildSettings(compilerArguments: ["-xc++", newCppArg, h2.pseudoPath])
353353
await del.setExpected([
354-
(h1, newArgsH1, changed1, #file, #line),
355-
(h2, newArgsH2, changed2, #file, #line),
354+
(h1, .c, newArgsH1, changed1, #file, #line),
355+
(h2, .c, newArgsH2, changed2, #file, #line),
356356
])
357357
bsm.fileBuildSettingsChanged([cpp: .modified(bs.map[cpp]!)])
358358

@@ -381,9 +381,9 @@ final class BuildSystemManagerTests: XCTestCase {
381381
let initialB = expectation(description: "initial settings b")
382382
let initialC = expectation(description: "initial settings c")
383383
await del.setExpected([
384-
(a, bs.map[a]!, initialA, #file, #line),
385-
(b, bs.map[b]!, initialB, #file, #line),
386-
(c, bs.map[c]!, initialC, #file, #line),
384+
(a, .swift, bs.map[a]!, initialA, #file, #line),
385+
(b, .swift, bs.map[b]!, initialB, #file, #line),
386+
(c, .swift, bs.map[c]!, initialC, #file, #line),
387387
])
388388
await bsm.registerForChangeNotifications(for: a, language: .swift)
389389
await bsm.registerForChangeNotifications(for: b, language: .swift)
@@ -396,7 +396,7 @@ final class BuildSystemManagerTests: XCTestCase {
396396

397397
let changedB = expectation(description: "changed settings b")
398398
await del.setExpected([
399-
(b, bs.map[b]!, changedB, #file, #line),
399+
(b, .swift, bs.map[b]!, changedB, #file, #line),
400400
])
401401

402402
await bsm.unregisterForChangeNotifications(for: a)
@@ -434,7 +434,7 @@ final class BuildSystemManagerTests: XCTestCase {
434434

435435
bs.map[a] = FileBuildSettings(compilerArguments: ["x"])
436436
let initial = expectation(description: "initial settings")
437-
await del.setExpected([(a, bs.map[a]!, initial, #file, #line)])
437+
await del.setExpected([(a, .swift, bs.map[a]!, initial, #file, #line)])
438438

439439
let depUpdate1 = expectation(description: "dependencies update during registration")
440440
await del.setExpectedDependenciesUpdate([(a, depUpdate1, #file, #line)])
@@ -508,7 +508,7 @@ class ManualBuildSystem: BuildSystem {
508508

509509
/// A `BuildSystemDelegate` setup for testing.
510510
private actor BSMDelegate: BuildSystemDelegate {
511-
fileprivate typealias ExpectedBuildSettingChangedCall = (uri: DocumentURI, settings: FileBuildSettings?, expectation: XCTestExpectation, file: StaticString, line: UInt)
511+
fileprivate typealias ExpectedBuildSettingChangedCall = (uri: DocumentURI, language: Language, settings: FileBuildSettings?, expectation: XCTestExpectation, file: StaticString, line: UInt)
512512
fileprivate typealias ExpectedDependenciesUpdatedCall = (uri: DocumentURI, expectation: XCTestExpectation, file: StaticString, line: UInt)
513513

514514
let queue: DispatchQueue = DispatchQueue(label: "\(BSMDelegate.self)")
@@ -536,15 +536,15 @@ private actor BSMDelegate: BuildSystemDelegate {
536536
}()
537537
}
538538

539-
func fileBuildSettingsChanged(_ changes: [DocumentURI: FileBuildSettingsChange]) {
540-
for (uri, change) in changes {
539+
func fileBuildSettingsChanged(_ changes: [DocumentURI: FileBuildSettingsChange]) async {
540+
for (uri, _) in changes {
541541
guard let expected = expected.first(where: { $0.uri == uri }) else {
542542
XCTFail("unexpected settings change for \(uri)")
543543
continue
544544
}
545545

546546
XCTAssertEqual(uri, expected.uri, file: expected.file, line: expected.line)
547-
let settings = change.newSettings
547+
let settings = await bsm.buildSettings(ofMainFileFor: uri, language: expected.language)?.buildSettings
548548
XCTAssertEqual(settings, expected.settings, file: expected.file, line: expected.line)
549549
expected.expectation.fulfill()
550550
}

0 commit comments

Comments
 (0)