Commit 9b42c4c1 authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

[tools] Improve locs.py

- Detect errors during generation of compile_commands.json
  and building the target 'v8_generated_cc_files'.

- Change format of JSON output to have files as keys, which makes
  programmatic lookup by filename easier on the consumer side.

Change-Id: Ibc3d9cff64f82df7a3dbb76cb8d914b29460a48c
Notry: true
Reviewed-on: https://chromium-review.googlesource.com/c/1362041Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58263}
parent dde25872
...@@ -134,9 +134,17 @@ def GenerateCompileCommandsAndBuild(build_dir, compile_commands_file, out): ...@@ -134,9 +134,17 @@ def GenerateCompileCommandsAndBuild(build_dir, compile_commands_file, out):
ninja = "ninja -C {} -t compdb cxx cc > {}".format( ninja = "ninja -C {} -t compdb cxx cc > {}".format(
build_dir, compile_commands_file) build_dir, compile_commands_file)
subprocess.call(ninja, shell=True, stdout=out) if subprocess.call(ninja, shell=True, stdout=out) != 0:
autoninja = "autoninja -C {}".format(build_dir) print("Error: Cound not generate {} for {}.".format(
subprocess.call(autoninja, shell=True, stdout=out) compile_commands_file, build_dir), file=sys.stderr)
exit(1)
autoninja = "autoninja -C {} v8_generated_cc_files".format(build_dir)
if subprocess.call(autoninja, shell=True, stdout=out) != 0:
print("Error: Building target 'v8_generated_cc_files'"
" failed for {}.".format(build_dir), file=sys.stderr)
exit(1)
return compile_commands_file return compile_commands_file
...@@ -219,7 +227,7 @@ def SetupReportGroups(): ...@@ -219,7 +227,7 @@ def SetupReportGroups():
class Results: class Results:
def __init__(self): def __init__(self):
self.groups = SetupReportGroups() self.groups = SetupReportGroups()
self.units = [] self.units = {}
def track(self, filename): def track(self, filename):
is_tracked = False is_tracked = False
...@@ -230,7 +238,7 @@ class Results: ...@@ -230,7 +238,7 @@ class Results:
def recordFile(self, filename, loc, expanded): def recordFile(self, filename, loc, expanded):
unit = File(filename, loc, expanded) unit = File(filename, loc, expanded)
self.units.append(unit) self.units[filename] = unit
for group in self.groups.values(): for group in self.groups.values():
group.account(unit) group.account(unit)
...@@ -242,7 +250,7 @@ class Results: ...@@ -242,7 +250,7 @@ class Results:
print(self.groups[key].to_string(self.maxGroupWidth()), file=file) print(self.groups[key].to_string(self.maxGroupWidth()), file=file)
def printSorted(self, key, count, reverse, out): def printSorted(self, key, count, reverse, out):
for unit in sorted(self.units, key=key, reverse=reverse)[:count]: for unit in sorted(list(self.units.values()), key=key, reverse=reverse)[:count]:
print(unit.to_string(), file=out) print(unit.to_string(), file=out)
...@@ -263,7 +271,7 @@ class StatusLine: ...@@ -263,7 +271,7 @@ class StatusLine:
def print(self, statusline, end="\r", file=sys.stdout): def print(self, statusline, end="\r", file=sys.stdout):
self.max_width = max(self.max_width, len(statusline)) self.max_width = max(self.max_width, len(statusline))
print("{0:<{1}}".format(statusline, self.max_width), end=end, file=file) print("{0:<{1}}".format(statusline, self.max_width), end=end, file=file, flush=True)
class CommandSplitter: class CommandSplitter:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment