dump_inputs.py 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env python3
  2. # Copyright 2022 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """Convenience script for running proguard.py with --dump-inputs."""
  6. import argparse
  7. import os
  8. import subprocess
  9. import sys
  10. def main():
  11. parser = argparse.ArgumentParser()
  12. parser.add_argument('mapping_file',
  13. help='Path to .mapping file within out/Release/apks.')
  14. args = parser.parse_args()
  15. if not args.mapping_file.endswith('.mapping'):
  16. sys.stderr.write('Expected argument to end with .mapping')
  17. sys.exit(1)
  18. # Find directory with "build.ninja" in it.
  19. build_dir = os.path.dirname(args.mapping_file) or '.'
  20. for _ in range(50): # Prevent infinite loop.
  21. if os.path.exists(os.path.join(build_dir, 'build.ninja')):
  22. break
  23. build_dir = os.path.dirname(build_dir) or '.'
  24. mapping_file = os.path.relpath(args.mapping_file, build_dir)
  25. command = subprocess.check_output(
  26. ['ninja', '-C', build_dir, '-t', 'commands', '-s', mapping_file],
  27. encoding='utf8').rstrip()
  28. if 'proguard.py' not in command:
  29. sys.stderr.write('Unexpected: {command}\n')
  30. sys.exit(1)
  31. command += ' --dump-inputs'
  32. print('Running:', command)
  33. sys.exit(os.system(command))
  34. if __name__ == '__main__':
  35. main()