fix_android_mk_prebuilt: Add --in-place option Bug: 149715904 Test: fix_android_mk_prebuilt --in-place <path-to-Android.mk> Change-Id: I0238415d02cbcaa19a3b4b1c0ba3c24d9fabd682
diff --git a/vndk/tools/elfcheck/fix_android_mk_prebuilt.py b/vndk/tools/elfcheck/fix_android_mk_prebuilt.py index 0f4a52f..06fa914 100755 --- a/vndk/tools/elfcheck/fix_android_mk_prebuilt.py +++ b/vndk/tools/elfcheck/fix_android_mk_prebuilt.py
@@ -21,6 +21,7 @@ """ import argparse +import io from elfcheck.rewriter import Rewriter @@ -28,6 +29,8 @@ def _parse_args(): parser = argparse.ArgumentParser() parser.add_argument('android_mk', help='path to Android.mk') + parser.add_argument('--in-place', action='store_true', + help='update the input file in place') parser.add_argument('--var', action='append', default=[], metavar='KEY=VALUE', help='extra makefile variables') return parser.parse_args() @@ -48,7 +51,13 @@ """Main function""" args = _parse_args() rewriter = Rewriter(args.android_mk, _parse_arg_var(args.var)) - rewriter.rewrite() + if args.in_place: + output_buffer = io.StringIO() + rewriter.rewrite(output_buffer) + with open(args.android_mk, 'w') as output_file: + output_file.write(output_buffer.getvalue()) + else: + rewriter.rewrite() if __name__ == '__main__':