fix_java_command_file_cp.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import sys
  2. import os
  3. import argparse
  4. import subprocess
  5. import platform
  6. def fix_files(args):
  7. args = args[:]
  8. parser = argparse.ArgumentParser()
  9. parser.add_argument('--build-root', default=None)
  10. args, tail = parser.parse_known_args(args)
  11. for idx, arg in list(enumerate(tail)):
  12. if arg.startswith('@') and os.path.isfile(arg[1:]):
  13. with open(arg[1:]) as f:
  14. fixed = [i.strip() for i in f]
  15. if args.build_root:
  16. fixed = [os.path.join(args.build_root, i) for ln in fixed for i in ln.split(os.path.pathsep)]
  17. fixed = os.pathsep.join([i.strip() for i in fixed])
  18. fixed_name = list(os.path.splitext(arg))
  19. fixed_name[0] += '_fixed'
  20. fixed_name = ''.join(fixed_name)
  21. with open(fixed_name[1:], 'w') as f:
  22. f.write(fixed)
  23. tail[idx : idx + 1] = [fixed_name]
  24. return tail
  25. if __name__ == '__main__':
  26. args = fix_files(sys.argv[1:])
  27. if platform.system() == 'Windows':
  28. sys.exit(subprocess.Popen(args).wait())
  29. else:
  30. os.execv(args[0], args)