Skip to content

Commit

Permalink
Merge pull request buildbot#8267 from mokibit/fix-indexing-of-log-chunks
Browse files Browse the repository at this point in the history
www: Fix indexing of non-first log chunks
  • Loading branch information
p12tic authored Dec 11, 2024
2 parents 64b8374 + e4b3f04 commit e984f9e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix garbage output of ANSI escape codes sequences in builds steps logs (:bug:`7852`)
6 changes: 3 additions & 3 deletions www/base/src/util/LogChunkParsing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,19 @@ describe('LogChunkParsing', () => {

const chunkCssClasses = parseCssClassesForChunk(chunk, 20, 23);
expect(chunkCssClasses).toEqual({
20: ["DEBUG [plugin]: Loading plugin karma-jasmine.",
0: ["DEBUG [plugin]: Loading plugin karma-jasmine.",
[
{cssClasses: "ansi36", firstPos: 0, lastPos: 16},
{cssClasses: "", firstPos: 16, lastPos: 45},
],
],
21: [".F",
1: [".F",
[
{cssClasses: "ansi32", firstPos: 0, lastPos: 1},
{cssClasses: "ansi31", firstPos: 1, lastPos: 2},
],
],
22: ["..",
2: ["..",
[
{cssClasses: "ansi32", firstPos: 0, lastPos: 1},
{cssClasses: "ansi32", firstPos: 1, lastPos: 2},
Expand Down
17 changes: 8 additions & 9 deletions www/base/src/util/LogChunkParsing.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,10 @@ export function mergeChunks(chunk1: ParsedLogChunk, chunk2: ParsedLogChunk): Par
export type ChunkCssClasses = {[globalLine: number]: [string, LineCssClasses[]]};

// Parses ansi escape code information for a span of lines in a particular chunk. Returns a map
// containing key-value pairs, where each key-value pair represents a line with at least on escape
// code. The key is line number and value is a tuple containing the line text with escape
// sequences removed and a list of CSS classes to style the line. The line text and the
// text positions in the list exclude any trailing newlines.
// containing key-value pairs, where each key-value pair represents a line with at least one escape
// code. The key is line index relative to beginning of a specific chunk and value is a tuple
// containing the line text with escape sequences removed and a list of CSS classes to style the
// line. The line text and the text positions in the list exclude any trailing newlines.
export function parseCssClassesForChunk(chunk: ParsedLogChunk,
firstLine: number, lastLine: number) {
const cssClasses: ChunkCssClasses = {};
Expand All @@ -227,11 +227,11 @@ export function parseCssClassesForChunk(chunk: ParsedLogChunk,
if (lastLine > chunk.lastLine) {
lastLine = chunk.lastLine;
}
const chunkFirstLine = firstLine - chunk.firstLine;
const chunkLastLine = lastLine - chunk.firstLine;

if (chunk.linesWithEscapes !== null) {
// small number of escaped lines
const chunkFirstLine = firstLine - chunk.firstLine;
const chunkLastLine = lastLine - chunk.firstLine;
for (const chunkLineI of chunk.linesWithEscapes) {
if (chunkLineI < chunkFirstLine) {
// It probably makes sense to use binary search in this loop
Expand All @@ -250,10 +250,9 @@ export function parseCssClassesForChunk(chunk: ParsedLogChunk,
}
} else {
// large number of escape sequences
for (let lineI = firstLine; lineI < lastLine; ++lineI) {
const chunkLineI = lineI - chunk.firstLine;
for (let lineI = chunkFirstLine; lineI < chunkLastLine; ++lineI) {
const chunkLine = chunk.text.slice(
chunk.textLineBounds[chunkLineI], chunk.textLineBounds[chunkLineI + 1] - 1);
chunk.textLineBounds[lineI], chunk.textLineBounds[lineI + 1] - 1);

const [strippedLine, lineCssClasses] = parseEscapeCodesToClasses(chunkLine);
if (lineCssClasses !== null) {
Expand Down

0 comments on commit e984f9e

Please sign in to comment.