Merge "Add --patch and --ignore-cargo-errors options" am: 87b2d90748 am: dfa38d0e80

Original change: https://android-review.googlesource.com/c/platform/development/+/1483304

Change-Id: I083850f0d5f7912d721fde649020349117edd74c
This commit is contained in:
Chih-hung Hsieh
2020-11-03 05:38:21 +00:00
committed by Automerger Merge Worker

View File

@@ -1317,6 +1317,20 @@ class Runner(object):
outf.write('// ' + short_out_name(pkg, obj) + ' => ' + outf.write('// ' + short_out_name(pkg, obj) + ' => ' +
short_out_name(pkg, obj2cc[obj].src) + '\n') short_out_name(pkg, obj2cc[obj].src) + '\n')
def apply_patch(self):
"""Apply local patch file if it is given."""
if self.args.patch:
if self.dry_run:
print('Dry-run skip patch file:', self.args.patch)
else:
if not os.path.exists(self.args.patch):
self.append_to_bp('ERROR cannot find patch file: ' + self.args.patch)
return self
if self.args.verbose:
print('### INFO: applying local patch file:', self.args.patch)
os.system('patch -s --no-backup-if-mismatch ./Android.bp ' + self.args.patch)
return self
def gen_bp(self): def gen_bp(self):
"""Parse cargo.out and generate Android.bp files.""" """Parse cargo.out and generate Android.bp files."""
if self.dry_run: if self.dry_run:
@@ -1450,6 +1464,7 @@ class Runner(object):
if fpath[0] != '/': # ignore absolute path if fpath[0] != '/': # ignore absolute path
self.warning_files.add(fpath) self.warning_files.add(fpath)
elif line.startswith('error: ') or line.startswith('error[E'): elif line.startswith('error: ') or line.startswith('error[E'):
if not self.args.ignore_cargo_errors:
self.errors += line self.errors += line
prev_warning = False prev_warning = False
rustc_line = new_rustc rustc_line = new_rustc
@@ -1515,6 +1530,11 @@ def parse_args():
default=False, default=False,
help=('add a compile_multilib:"first" property ' + help=('add a compile_multilib:"first" property ' +
'to Android.bp host modules.')) 'to Android.bp host modules.'))
parser.add_argument(
'--ignore-cargo-errors',
action='store_true',
default=False,
help='do not append cargo/rustc error messages to Android.bp')
parser.add_argument( parser.add_argument(
'--no-host', '--no-host',
action='store_true', action='store_true',
@@ -1531,6 +1551,10 @@ def parse_args():
default=False, default=False,
help=('output all into one ./Android.bp, default will generate ' + help=('output all into one ./Android.bp, default will generate ' +
'one Android.bp per Cargo.toml in subdirectories')) 'one Android.bp per Cargo.toml in subdirectories'))
parser.add_argument(
'--patch',
type=str,
help='apply the given patch file to generated ./Android.bp')
parser.add_argument( parser.add_argument(
'--run', '--run',
action='store_true', action='store_true',
@@ -1570,7 +1594,7 @@ def main():
args = parse_args() args = parse_args()
if not args.run: # default is dry-run if not args.run: # default is dry-run
print(DRY_RUN_NOTE) print(DRY_RUN_NOTE)
Runner(args).run_cargo().gen_bp().dump_test_mapping_files() Runner(args).run_cargo().gen_bp().apply_patch().dump_test_mapping_files()
if __name__ == '__main__': if __name__ == '__main__':