Skip to content

Commit 204052c

Browse files
authored
Add build times to swiftbuild build system (#8397)
The native build system will output the time it took building. This can be useful for ad-hoc measurement of the time. Add the same kind of measurement for build times of the swiftbuild build system.
1 parent 2523ab7 commit 204052c

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

Sources/SwiftBuildSupport/SwiftBuildSystem.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,16 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
243243
try self.fileSystem.writeIfChanged(path: buildParameters.pifManifest, string: pif)
244244

245245
try await startSWBuildOperation(pifTargetName: subset.pifTargetName)
246+
246247
#else
247248
fatalError("Swift Build support is not linked in.")
248249
#endif
249250
}
250251

251252
#if canImport(SwiftBuild)
252253
private func startSWBuildOperation(pifTargetName: String) async throws {
254+
let buildStartTime = ContinuousClock.Instant.now
255+
253256
try await withService(connectionMode: .inProcessStatic(swiftbuildServiceEntryPoint)) { service in
254257
let parameters = try self.makeBuildParameters()
255258
let derivedDataPath = self.buildParameters.dataPath.pathString
@@ -386,7 +389,8 @@ public final class SwiftBuildSystem: SPMBuildCore.BuildSystem {
386389
case .succeeded:
387390
progressAnimation.update(step: 100, total: 100, text: "")
388391
progressAnimation.complete(success: true)
389-
self.outputStream.send("Build complete!\n")
392+
let duration = ContinuousClock.Instant.now - buildStartTime
393+
self.outputStream.send("Build complete! (\(duration))\n")
390394
self.outputStream.flush()
391395
case .failed:
392396
self.observabilityScope.emit(error: "Build failed")

Tests/CommandsTests/BuildCommandTests.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -416,14 +416,13 @@ class BuildCommandTestCases: CommandsBuildProviderTestCase {
416416
}
417417

418418
func testBuildCompleteMessage() async throws {
419-
try XCTSkipIf(true, "This test fails to match the 'Compiling' regex; rdar://101815761")
420-
421419
try await fixture(name: "DependencyResolution/Internal/Simple") { fixturePath in
422420
do {
423421
let result = try await execute(packagePath: fixturePath)
424-
XCTAssertMatch(result.stdout, .regex("\\[[1-9][0-9]*\\/[1-9][0-9]*\\] Compiling"))
422+
// This test fails to match the 'Compiling' regex; rdar://101815761
423+
// XCTAssertMatch(result.stdout, .regex("\\[[1-9][0-9]*\\/[1-9][0-9]*\\] Compiling"))
425424
let lines = result.stdout.split(whereSeparator: { $0.isNewline })
426-
XCTAssertMatch(String(lines.last!), .regex("Build complete! \\([0-9]*\\.[0-9]*s\\)"))
425+
XCTAssertMatch(String(lines.last!), .regex("Build complete! \\([0-9]*\\.[0-9]*\\s*s(econds)?\\)"))
427426
}
428427

429428
do {
@@ -434,9 +433,10 @@ class BuildCommandTestCases: CommandsBuildProviderTestCase {
434433
do {
435434
// test third time, to make sure message is presented even when nothing to build (cached)
436435
let result = try await execute(packagePath: fixturePath)
437-
XCTAssertNoMatch(result.stdout, .regex("\\[[1-9][0-9]*\\/[1-9][0-9]*\\] Compiling"))
436+
// This test fails to match the 'Compiling' regex; rdar://101815761
437+
// XCTAssertNoMatch(result.stdout, .regex("\\[[1-9][0-9]*\\/[1-9][0-9]*\\] Compiling"))
438438
let lines = result.stdout.split(whereSeparator: { $0.isNewline })
439-
XCTAssertMatch(String(lines.last!), .regex("Build complete! \\([0-9]*\\.[0-9]*s\\)"))
439+
XCTAssertMatch(String(lines.last!), .regex("Build complete! \\([0-9]*\\.[0-9]*\\s*s(econds)?\\)"))
440440
}
441441
}
442442
}
@@ -848,6 +848,10 @@ class BuildCommandXcodeTests: BuildCommandTestCases {
848848
override func testGetTaskAllowEntitlement() async throws {
849849
try XCTSkip("Test not implemented for xcode build system.")
850850
}
851+
852+
override func testBuildCompleteMessage() async throws {
853+
try XCTSkip("Test not implemented for xcode build system.")
854+
}
851855
}
852856
#endif
853857

0 commit comments

Comments
 (0)