Comment out errors encountered when running cargo test.
A recent change to remove empty tests runs cargo test --list. A few crates produce build errors this way that they did not previously do. This currently causes cargo2android.py to produce illegal Android.bp files for these crates even though these should not be fatal errors. We thus detect these errors and emit them as comments in the Android.bp file, so developers can see them but the crate can still compile. Test: Run on crates with and without such errors. Change-Id: I8664d3ca9a6b4c513ce0ef35821aa64d22949fc7
This commit is contained in:
@@ -131,6 +131,8 @@ CARGO_TEST_LIST_START_PAT = re.compile('^\s*Running (.*) \(.*\)$')
|
||||
# cargo test --list output of the end of running a binary.
|
||||
CARGO_TEST_LIST_END_PAT = re.compile('^(\d+) tests, (\d+) benchmarks$')
|
||||
|
||||
CARGO2ANDROID_RUNNING_PAT = re.compile('^### Running: .*$')
|
||||
|
||||
# Rust package name with suffix -d1.d2.d3(+.*)?.
|
||||
VERSION_SUFFIX_PAT = re.compile(r'^(.*)-[0-9]+\.[0-9]+\.[0-9]+(?:\+.*)?$')
|
||||
|
||||
@@ -1140,6 +1142,7 @@ class Runner(object):
|
||||
self.name_owners = {}
|
||||
# Save and dump all errors from cargo to Android.bp.
|
||||
self.errors = ''
|
||||
self.test_errors = ''
|
||||
self.setup_cargo_path()
|
||||
# Default action is cargo clean, followed by build or user given actions.
|
||||
if args.cargo:
|
||||
@@ -1466,6 +1469,8 @@ class Runner(object):
|
||||
self.append_to_bp('\n' + f.read() + '\n')
|
||||
if self.errors:
|
||||
self.append_to_bp('\n' + ERRORS_LINE + '\n' + self.errors)
|
||||
if self.test_errors:
|
||||
self.append_to_bp('\n// Errors when listing tests:\n' + self.test_errors)
|
||||
return self
|
||||
|
||||
def add_ar_object(self, obj):
|
||||
@@ -1575,6 +1580,7 @@ class Runner(object):
|
||||
inf.seek(0)
|
||||
prev_warning = False # true if the previous line was warning: ...
|
||||
rustc_line = '' # previous line(s) matching RUSTC_VV_PAT
|
||||
in_tests = False
|
||||
for line in inf:
|
||||
n += 1
|
||||
if line.startswith('warning: '):
|
||||
@@ -1597,7 +1603,12 @@ class Runner(object):
|
||||
self.warning_files.add(fpath)
|
||||
elif line.startswith('error: ') or line.startswith('error[E'):
|
||||
if not self.args.ignore_cargo_errors:
|
||||
self.errors += line
|
||||
if in_tests:
|
||||
self.test_errors += '// ' + line
|
||||
else:
|
||||
self.errors += line
|
||||
elif CARGO2ANDROID_RUNNING_PAT.match(line):
|
||||
in_tests = "cargo test" in line and "--list" in line
|
||||
prev_warning = False
|
||||
rustc_line = new_rustc
|
||||
self.find_warning_owners()
|
||||
|
||||
Reference in New Issue
Block a user