Commit cf090073 authored by Mohamed Heikal's avatar Mohamed Heikal Committed by Commit Bot

[Build] Make filtering CheckOutput output easier

Add a new function to build_utils to make it easier to filter output
from CheckOutput if you just have a regular expression matching
silenceable lines.

Change-Id: I41f1c94fbe47405aae980a00df137439825a7f05
Reviewed-on: https://chromium-review.googlesource.com/c/1284751
Commit-Queue: Mohamed Heikal <mheikal@chromium.org>
Reviewed-by: default avatarEric Stevenson <estevenson@chromium.org>
Reviewed-by: default avataragrieve <agrieve@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602140}
parent 4ea14eb9
...@@ -171,40 +171,6 @@ def _EnvWithArtLibPath(binary_path): ...@@ -171,40 +171,6 @@ def _EnvWithArtLibPath(binary_path):
return env return env
def _FilterOutput(output, filter_strings):
"""Output filter from build_utils.CheckOutput.
Args:
output: Executable output as from build_utils.CheckOutput.
filter_strings: List of RE strings that will filter (remove) matching
lines from |output|.
Returns:
The filtered output, as a single string.
"""
filters = [re.compile(f) for f in filter_strings]
filtered_output = []
for line in output.splitlines():
if any(filter.search(line) for filter in filters):
continue
else:
filtered_output.append(line)
return '\n'.join(filtered_output)
def _FilterProfmanStderr(output):
return _FilterOutput(output, [
r'Could not find (method_id|proto_id|name):',
r'Could not create type list',
])
def _FilterDexlayoutStderr(output):
return _FilterOutput(output, [
r'Can.t mmap dex file.*please zipalign',
])
def _CreateBinaryProfile(text_profile, input_dex, profman_path, temp_dir): def _CreateBinaryProfile(text_profile, input_dex, profman_path, temp_dir):
"""Create a binary profile for dexlayout. """Create a binary profile for dexlayout.
...@@ -226,8 +192,13 @@ def _CreateBinaryProfile(text_profile, input_dex, profman_path, temp_dir): ...@@ -226,8 +192,13 @@ def _CreateBinaryProfile(text_profile, input_dex, profman_path, temp_dir):
'--dex-location=' + input_dex, '--dex-location=' + input_dex,
'--create-profile-from=' + text_profile, '--create-profile-from=' + text_profile,
'--reference-profile-file=' + binary_profile] '--reference-profile-file=' + binary_profile]
build_utils.CheckOutput(profman_cmd, env=_EnvWithArtLibPath(profman_path), build_utils.CheckOutput(
stderr_filter=_FilterProfmanStderr) profman_cmd,
env=_EnvWithArtLibPath(profman_path),
stderr_filter=lambda output:
build_utils.FilterLines(output, '|'.join(
[r'Could not find (method_id|proto_id|name):',
r'Could not create type list'])))
return binary_profile return binary_profile
...@@ -252,8 +223,12 @@ def _LayoutDex(binary_profile, input_dex, dexlayout_path, temp_dir): ...@@ -252,8 +223,12 @@ def _LayoutDex(binary_profile, input_dex, dexlayout_path, temp_dir):
'-p', binary_profile, '-p', binary_profile,
'-w', dexlayout_output_dir, '-w', dexlayout_output_dir,
input_dex ] input_dex ]
build_utils.CheckOutput(dexlayout_cmd, env=_EnvWithArtLibPath(dexlayout_path), build_utils.CheckOutput(
stderr_filter=_FilterDexlayoutStderr) dexlayout_cmd,
env=_EnvWithArtLibPath(dexlayout_path),
stderr_filter=lambda output:
build_utils.FilterLines(output,
r'Can.t mmap dex file.*please zipalign'))
output_files = os.listdir(dexlayout_output_dir) output_files = os.listdir(dexlayout_output_dir)
if not output_files: if not output_files:
raise Exception('dexlayout unexpectedly produced no output') raise Exception('dexlayout unexpectedly produced no output')
......
...@@ -177,6 +177,22 @@ class CalledProcessError(Exception): ...@@ -177,6 +177,22 @@ class CalledProcessError(Exception):
return 'Command failed: {}\n{}'.format(copyable_command, self.output) return 'Command failed: {}\n{}'.format(copyable_command, self.output)
def FilterLines(output, filter_string):
"""Output filter from build_utils.CheckOutput.
Args:
output: Executable output as from build_utils.CheckOutput.
filter_string: An RE string that will filter (remove) matching
lines from |output|.
Returns:
The filtered output, as a single string.
"""
re_filter = re.compile(filter_string)
return '\n'.join(
line for line in output.splitlines() if not re_filter.search(line))
# This can be used in most cases like subprocess.check_output(). The output, # This can be used in most cases like subprocess.check_output(). The output,
# particularly when the command fails, better highlights the command's failure. # particularly when the command fails, better highlights the command's failure.
# If the command fails, raises a build_utils.CalledProcessError. # If the command fails, raises a build_utils.CalledProcessError.
......
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