Repository navigation
Expand file tree
/
Copy pathdiagnostics.py
More file actions
68 lines (59 loc) · 2.39 KB
/
Copy pathdiagnostics.py
File metadata and controls
68 lines (59 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""Bounded compiler diagnostics and stable failure identities.
This extracts observations; it never prescribes a task-specific implementation.
"""
import re
_NVCC = re.compile(r"^(.+?)\((\d+)\): (?:fatal )?error(?: #\S+)?: (.*)$")
_GNU = re.compile(r"^(.+?):(\d+)(?::\d+)?: (?:fatal )?error: (.*)$")
def compiler_diagnostics(output, workspace, limit=3, *, namespace=None):
diagnostics = []
for line in (output or "").splitlines():
match = _NVCC.match(line) or _GNU.match(line)
if not match:
continue
path, number, message = match.groups()
number = int(number)
item = {"path": path, "line": number, "message": message[:600]}
try:
from pathlib import Path
if namespace is not None:
from infinicoder.planning.diagnostic_namespaces import relative_path
item["reported_path"] = path[:512]
path, mapping = relative_path(path, workspace, namespace)
item["mapping"] = mapping
else:
raw = Path(path)
if raw.is_absolute():
path = raw.resolve().relative_to(workspace.root).as_posix()
item["source"] = workspace.read(path, max(1, number - 3), 7)
if namespace is not None and not 1 <= number <= item["source"]["total_lines"]:
raise ValueError("reported line lies outside source")
item["path"] = path
except (ValueError, OSError, UnicodeError):
item["source_unavailable"] = True
diagnostics.append(item)
if len(diagnostics) == limit:
break
return diagnostics
def stable_failure(value):
"""Remove volatile timing/env values so equivalent failures can be counted."""
if isinstance(value, list):
return [stable_failure(v) for v in value]
if isinstance(value, dict):
return {
k: stable_failure(v)
for k, v in value.items()
if k
not in {
"duration",
"environment",
"revision",
"spool_bytes",
"elapsed_seconds",
"executed_argv",
"inspection_progress",
}
}
if isinstance(value, str):
value = re.sub(r"snap-\d+", "snap-<id>", value)
return re.sub(r"\b\d+(?:\.\d+)?s\b", "<time>", value)
return value