Skip to content

Commit 4f21fb3

Browse files
committed
fix: show the C and Swift file counts on the HTML index page
The index page only loads the main step and the targets, so counting detail steps there always gave 0. Write the counts from the reporter instead.
1 parent e44832f commit 4f21fb3

5 files changed

Lines changed: 59 additions & 26 deletions

File tree

‎Resources/js/app.js‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,14 +195,9 @@ function loadMainData() {
195195
targets = buildData.filter(function (step) {
196196
return step.type === 'target' && step.fetchedFromCache === false;
197197
});
198-
cFiles = buildData.filter(function (step) {
199-
return step.type === 'detail' && step.detailStepType === cCompilation
200-
&& step.fetchedFromCache === false;
201-
});
202-
swiftFiles = buildData.filter(function (step) {
203-
return step.type === 'detail' && step.detailStepType === swiftCompilation
204-
&& step.fetchedFromCache === false;
205-
});
198+
// buildData only has the main step and the targets here, the counts come from top_files.js
199+
cFiles = new Array(cFilesCount);
200+
swiftFiles = new Array(swiftFilesCount);
206201
}
207202

208203
function loadTargetData(target) {

‎Sources/XCLogParser/generated/HtmlReporterResources.swift‎

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,14 +287,9 @@ function loadMainData() {
287287
targets = buildData.filter(function (step) {
288288
return step.type === 'target' && step.fetchedFromCache === false;
289289
});
290-
cFiles = buildData.filter(function (step) {
291-
return step.type === 'detail' && step.detailStepType === cCompilation
292-
&& step.fetchedFromCache === false;
293-
});
294-
swiftFiles = buildData.filter(function (step) {
295-
return step.type === 'detail' && step.detailStepType === swiftCompilation
296-
&& step.fetchedFromCache === false;
297-
});
290+
// buildData only has the main step and the targets here, the counts come from top_files.js
291+
cFiles = new Array(cFilesCount);
292+
swiftFiles = new Array(swiftFilesCount);
298293
}
299294
300295
function loadTargetData(target) {

‎Sources/XCLogParser/reporter/HtmlReporter.swift‎

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -243,26 +243,25 @@ public struct HtmlReporter: LogReporter {
243243
swiftTypeCheckTimes.sort { $0.durationMS > $1.durationMS }
244244
let topTypeChecks = Array(swiftTypeCheckTimes.prefix(Self.maxSwifTypeChecks))
245245

246-
try write(
247-
slowestSwiftFiles: Array(swiftSteps.prefix(Self.maxSlowestFiles)),
248-
slowestCFiles: Array(cSteps.prefix(Self.maxSlowestFiles)),
249-
swiftFunctionTimes: topFunctions,
250-
swiftTypeCheckTimes: topTypeChecks,
251-
toDir: buildDir)
246+
try write(swiftSteps: swiftSteps,
247+
cSteps: cSteps,
248+
swiftFunctionTimes: topFunctions,
249+
swiftTypeCheckTimes: topTypeChecks,
250+
toDir: buildDir)
252251

253252
}
254253

255-
private func write(slowestSwiftFiles: [BuildStep],
256-
slowestCFiles: [BuildStep],
254+
private func write(swiftSteps: [BuildStep],
255+
cSteps: [BuildStep],
257256
swiftFunctionTimes: [SwiftFunctionTime],
258257
swiftTypeCheckTimes: [SwiftTypeCheck],
259258
toDir buildDir: String) throws {
260259
let encoder = JSONEncoder()
261260
encoder.outputFormatting = .prettyPrinted
262261
let functionsJson = try encoder.encode(swiftFunctionTimes)
263262
let typeChecksJson = try encoder.encode(swiftTypeCheckTimes)
264-
let swiftJson = try encoder.encode(slowestSwiftFiles)
265-
let cJson = try encoder.encode(slowestCFiles)
263+
let swiftJson = try encoder.encode(Array(swiftSteps.prefix(Self.maxSlowestFiles)))
264+
let cJson = try encoder.encode(Array(cSteps.prefix(Self.maxSlowestFiles)))
266265
guard let functionsString = String(data: functionsJson, encoding: .utf8),
267266
let typeChecksString = String(data: typeChecksJson, encoding: .utf8),
268267
let swiftString = String(data: swiftJson, encoding: .utf8),
@@ -278,6 +277,10 @@ public struct HtmlReporter: LogReporter {
278277
const topSwiftFunctions = \(functionsString);
279278
280279
const topSwifTypeChecks = \(typeChecksString);
280+
281+
const swiftFilesCount = \(swiftSteps.count);
282+
283+
const cFilesCount = \(cSteps.count);
281284
""".write(toFile: "\(buildDir)/js/top_files.js", atomically: true, encoding: .utf8)
282285
}
283286
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import XCTest
2+
@testable import XCLogParser
3+
4+
class HtmlReporterTests: XCTestCase {
5+
6+
func testIndexFileCountsComeFromAllTargets() throws {
7+
let compile = { (title: String, type: DetailStepType) -> BuildStep in
8+
makeFakeBuildStep(title: title, type: .detail, detailStepType: type,
9+
startTimestamp: 0, fetchedFromCache: false)
10+
}
11+
let foo = makeFakeBuildStep(title: "Build target Foo", type: .target, detailStepType: .none,
12+
startTimestamp: 0, fetchedFromCache: false)
13+
.with(subSteps: [compile("Compile a.swift", .swiftCompilation),
14+
compile("Compile b.swift", .swiftCompilation),
15+
compile("Compile c.c", .cCompilation)])
16+
let bar = makeFakeBuildStep(title: "Build target Bar", type: .target, detailStepType: .none,
17+
startTimestamp: 0, fetchedFromCache: false)
18+
.with(subSteps: [compile("Compile d.swift", .swiftCompilation)])
19+
let build = makeFakeBuildStep(title: "Build", type: .main, detailStepType: .none,
20+
startTimestamp: 0, fetchedFromCache: false)
21+
.with(subSteps: [foo, bar])
22+
let dir = try TestUtils.createRandomTestDir()
23+
24+
try HtmlReporter().report(build: build, output: FileOutput(path: dir.path), rootOutput: dir.path)
25+
26+
let topFiles = try String(contentsOf: dir.appendingPathComponent("js/top_files.js"))
27+
XCTAssertTrue(topFiles.contains("const swiftFilesCount = 3;"))
28+
XCTAssertTrue(topFiles.contains("const cFilesCount = 1;"))
29+
}
30+
}

‎Tests/XCLogParserTests/XCTestManifests.swift‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,15 @@ extension GroupedByTargetTests {
3838
]
3939
}
4040

41+
extension HtmlReporterTests {
42+
// DO NOT MODIFY: This is autogenerated, use:
43+
// `swift test --generate-linuxmain`
44+
// to regenerate.
45+
static let __allTests__HtmlReporterTests = [
46+
("testIndexFileCountsComeFromAllTargets", testIndexFileCountsComeFromAllTargets),
47+
]
48+
}
49+
4150
extension IssuesReporterTests {
4251
// DO NOT MODIFY: This is autogenerated, use:
4352
// `swift test --generate-linuxmain`
@@ -157,6 +166,7 @@ public func __allTests() -> [XCTestCaseEntry] {
157166
testCase(ActivityParserTests.__allTests__ActivityParserTests),
158167
testCase(ChromeTracerOutputTests.__allTests__ChromeTracerOutputTests),
159168
testCase(GroupedByTargetTests.__allTests__GroupedByTargetTests),
169+
testCase(HtmlReporterTests.__allTests__HtmlReporterTests),
160170
testCase(IssuesReporterTests.__allTests__IssuesReporterTests),
161171
testCase(LexRedactorTests.__allTests__LexRedactorTests),
162172
testCase(LexerTests.__allTests__LexerTests),

0 commit comments

Comments
 (0)