eclipse_make.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env python
  2. #
  3. # Wrapper to run make and preprocess any paths in the output from MSYS Unix-style paths
  4. # to Windows paths, for Eclipse
  5. from __future__ import division, print_function
  6. import os.path
  7. import re
  8. import subprocess
  9. import sys
  10. UNIX_PATH_RE = re.compile(r'(/[^ \'"]+)+')
  11. paths = {}
  12. def check_path(path):
  13. try:
  14. return paths[path]
  15. except KeyError:
  16. pass
  17. paths[path] = path # cache as failed, replace with success if it works
  18. try:
  19. winpath = subprocess.check_output(['cygpath', '-w', path]).decode('utf-8').strip()
  20. except subprocess.CalledProcessError:
  21. return path # something went wrong running cygpath, assume this is not a path!
  22. if not os.path.exists(winpath):
  23. return path # not actually a valid path
  24. winpath = winpath.replace('\\', '/') # make consistent with forward-slashes used elsewhere
  25. paths[path] = winpath
  26. return winpath
  27. def main():
  28. print("Running make in '%s'" % check_path(os.getcwd()))
  29. make = subprocess.Popen(['make'] + sys.argv[1:] + ['BATCH_BUILD=1'], stdout=subprocess.PIPE)
  30. for line in iter(make.stdout.readline, ''):
  31. line = re.sub(UNIX_PATH_RE, lambda m: check_path(m.group(0)), line)
  32. print(line.rstrip())
  33. sys.exit(make.wait())
  34. if __name__ == '__main__':
  35. main()