Commit 31cc8f1e authored by Henrique Nakashima's avatar Henrique Nakashima Committed by Commit Bot

[Lorenz] Output errors of subprocesses during graph generation

Failures are not very informative without the stderr output. For
example:
https://logs.chromium.org/logs/chrome/buildbucket/cr-buildbucket.appspot.com/8871613511001211808/+/steps/Generate_dependency_graph_data/0/stdout

Bug: 1111056
Change-Id: I50142bd4d2c8fa9ee43dea572359c2c331f91186
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2363699
Commit-Queue: Henrique Nakashima <hnakashima@chromium.org>
Reviewed-by: default avatarMohamed Heikal <mheikal@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799865}
parent 351c90f7
...@@ -10,6 +10,7 @@ import math ...@@ -10,6 +10,7 @@ import math
import multiprocessing import multiprocessing
import pathlib import pathlib
import subprocess import subprocess
import sys
from typing import List, Tuple from typing import List, Tuple
...@@ -87,27 +88,34 @@ class JavaClassJdepsParser(object): ...@@ -87,27 +88,34 @@ class JavaClassJdepsParser(object):
from_node.add_build_target(build_target) from_node.add_build_target(build_target)
def _run_jdeps(jdeps_path: str, filepath: pathlib.Path): def _run_command(command: List[str]) -> str:
"""Runs a command and returns the output.
Raises an exception and prints the command output if the command fails."""
try:
run_result = subprocess.run(command,
capture_output=True,
text=True,
check=True)
except subprocess.CalledProcessError as e:
print(f'{command} failed with error:\n{e.output}', file=sys.stderr)
raise
return run_result.stdout
def _run_jdeps(jdeps_path: str, filepath: pathlib.Path) -> str:
"""Runs jdeps on the given filepath and returns the output.""" """Runs jdeps on the given filepath and returns the output."""
print(f'Running jdeps and parsing output for {filepath}') print(f'Running jdeps and parsing output for {filepath}')
jdeps_res = subprocess.run([jdeps_path, '-R', '-verbose:class', filepath], return _run_command([jdeps_path, '-R', '-verbose:class', filepath])
capture_output=True,
text=True,
check=True)
return jdeps_res.stdout
def _run_gn_desc_list_dependencies(build_output_dir: str, target: str, def _run_gn_desc_list_dependencies(build_output_dir: str, target: str,
gn_path: str): gn_path: str) -> str:
"""Runs gn desc to list all jars that a target depends on. """Runs gn desc to list all jars that a target depends on.
This includes direct and indirect dependencies.""" This includes direct and indirect dependencies."""
gn_desc_res = subprocess.run( return _run_command(
[gn_path, 'desc', '--all', build_output_dir, target, 'deps'], [gn_path, 'desc', '--all', build_output_dir, target, 'deps'])
capture_output=True,
text=True,
check=True)
return gn_desc_res.stdout
JarTargetList = List[Tuple[str, pathlib.Path]] JarTargetList = List[Tuple[str, pathlib.Path]]
......
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