diff options
Diffstat (limited to 'core/Messages.zig')
| -rw-r--r-- | core/Messages.zig | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/core/Messages.zig b/core/Messages.zig index 35eb7f51..9b5b4265 100644 --- a/core/Messages.zig +++ b/core/Messages.zig @@ -440,15 +440,34 @@ pub fn inkOn(inks: anytype, kind: Kind) [3]u8 { } /// The places a compiler's report names put on `s`: each -/// `path:line:col: error|warning|note: words` row (a relative path is -/// `dir`'s), its words there, each place once, and the rows after the +/// `path:line:col: error|warning|note: words` row (a relative path read +/// against the directory the tool says it is in, as Emacs's compilation +/// mode and Vim's %D and %X read it: a make's `Entering directory 'X'` +/// until its `Leaving directory`, ninja's relative to `dir`; else `dir`, +/// the run's), its words there, each place once, and the rows after the /// first error, up to the next place, its detail. How many it found; none /// without an error. pub fn readPlaces(s: *Said, dir: []const u8, rows: []const []const u8) usize { var errors: usize = 0; var detailing = false; + // The directories entered, the innermost last; past its room the + // depth still counts, so each `Leaving` leaves its own. + var entered: [8][]const u8 = undefined; + var depth: usize = 0; for (rows) |raw| { const row = std.mem.trimEnd(u8, raw, " \t\r\n"); + if (std.mem.indexOf(u8, row, ": Entering directory ")) |from| { + // Quoted `'X'`, or `` `X' `` by an older make and ninja. + const quoted = row[from + ": Entering directory ".len ..]; + if (quoted.len < 3) continue; + if (depth < entered.len) entered[depth] = quoted[1 .. quoted.len - 1]; + depth += 1; + continue; + } + if (std.mem.indexOf(u8, row, ": Leaving directory ") != null) { + depth -|= 1; + continue; + } const found = placeOf(row) orelse { if (detailing and row.len > 0 and s.detail_len < Said.max_detail) { s.detail[s.detail_len] = .{}; @@ -466,7 +485,13 @@ pub fn readPlaces(s: *Said, dir: []const u8, rows: []const []const u8) usize { if (s.places_len == Said.max_places) continue; const place = &s.places[s.places_len]; place.* = .{ .line = found.line, .col = found.col }; - if (std.Io.Dir.path.isAbsolute(found.path)) place.path.set(found.path) else _ = place.path.print("{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), found.path }); + const in = if (depth > 0) entered[@min(depth, entered.len) - 1] else dir; + if (std.Io.Dir.path.isAbsolute(found.path)) + place.path.set(found.path) + else if (std.Io.Dir.path.isAbsolute(in)) + _ = place.path.print("{s}/{s}", .{ std.mem.trimEnd(u8, in, "/"), found.path }) + else + _ = place.path.print("{s}/{s}/{s}", .{ std.mem.trimEnd(u8, dir, "/"), std.mem.trimEnd(u8, in, "/"), found.path }); // A place named again (a note at its error's) is not a second one. const named = for (s.places[0..s.places_len]) |*was| { if (was.line == place.line and was.col == place.col and std.mem.eql(u8, was.path.slice(), place.path.slice())) break true; @@ -1504,6 +1529,10 @@ test "a compiler's report names its places: each place's words, the first error' try std.testing.expectEqual(@as(u8, 2), s.detail_len); try std.testing.expectEqualStrings(" const best = rank(q, name, 3) orelse continue;", s.detail[0].slice()); try std.testing.expectEqualStrings(" ^~~~", s.detail[1].slice()); + // ninja's directory, relative to the run's. + var ninja: Said = .{}; + try std.testing.expectEqual(@as(usize, 1), readPlaces(&ninja, "/src/v8", &.{ "ninja: Entering directory `out/x64'", "../../src/api.cc:4:2: error: boom" })); + try std.testing.expectEqualStrings("/src/v8/out/x64/../../src/api.cc", ninja.places[0].path.slice()); // No error among them: no places. var none: Said = .{}; try std.testing.expectEqual(@as(usize, 0), readPlaces(&none, "/", &.{ "x.zig:1:1: note: only a note", "grep: nothing" })); |
