Explorar o código

post_build_ninja_summary.py: Gracefully handle empty .ninja_log files

These are currently produced by Siso, until b/298594790 is addressed.

Before:
$ post_build_ninja_summary.py -C out/fastbuild-siso-reclient
Traceback (most recent call last):
  File "/usr/local/google/home/philwo/depot_tools/post_build_ninja_summary.py", line 366, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/google/home/philwo/depot_tools/post_build_ninja_summary.py", line 356, in main
    entries = ReadTargets(log, False)
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/google/home/philwo/depot_tools/post_build_ninja_summary.py", line 123, in ReadTargets
    assert header == '# ninja log v5\n', \
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: unrecognized ninja log version ''

After:
$ post_build_ninja_summary.py -C out/fastbuild-siso-reclient
<nothing>

Bug: b/298594790
Fixed: b/297349353
Change-Id: I10d4613e7386707276003fe0fd05cb5b0914be46
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4846349
Reviewed-by: Takuto Ikuta <tikuta@chromium.org>
Auto-Submit: Philipp Wollermann <philwo@google.com>
Reviewed-by: Bruce Dawson <brucedawson@chromium.org>
Commit-Queue: Bruce Dawson <brucedawson@chromium.org>
Philipp Wollermann hai 1 ano
pai
achega
c3d210d605
Modificáronse 1 ficheiros con 7 adicións e 2 borrados
  1. 7 2
      post_build_ninja_summary.py

+ 7 - 2
post_build_ninja_summary.py

@@ -116,6 +116,10 @@ def ReadTargets(log, show_all):
 
     The result is a list of Target objects."""
     header = log.readline()
+    # TODO: b/298594790 - Siso currently generates empty .ninja_log files.
+    # Handle them gracefully by silently returning an empty list of targets.
+    if not header:
+        return []
     assert header == '# ninja log v5\n', \
            'unrecognized ninja log version %r' % header
     targets_dict = {}
@@ -350,8 +354,9 @@ def main():
     try:
         with open(log_file, 'r') as log:
             entries = ReadTargets(log, False)
-            SummarizeEntries(entries, args.step_types,
-                             args.elapsed_time_sorting)
+            if entries:
+                SummarizeEntries(entries, args.step_types,
+                                 args.elapsed_time_sorting)
     except IOError:
         print('Log file %r not found, no build summary created.' % log_file)
         return errno.ENOENT