eclipse_make.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  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 print_function, division
  6. import sys, subprocess, os.path, re
  7. UNIX_PATH_RE = re.compile(r'(/[^ \'"]+)+')
  8. paths = {}
  9. def check_path(path):
  10. try:
  11. return paths[path]
  12. except KeyError:
  13. pass
  14. paths[path] = path # cache as failed, replace with success if it works
  15. try:
  16. winpath = subprocess.check_output(["cygpath", "-w", path]).strip()
  17. except subprocess.CalledProcessError:
  18. return path # something went wrong running cygpath, assume this is not a path!
  19. if not os.path.exists(winpath):
  20. return path # not actually a valid path
  21. winpath = winpath.replace("\\", "/") # make consistent with forward-slashes used elsewhere
  22. paths[path] = winpath
  23. return winpath
  24. def main():
  25. print("Running make in '%s'" % check_path(os.getcwd()))
  26. make = subprocess.Popen(["make"] + sys.argv[1:] + ["BATCH_BUILD=1"], stdout=subprocess.PIPE)
  27. for line in iter(make.stdout.readline, ''):
  28. line = re.sub(UNIX_PATH_RE, lambda m: check_path(m.group(0)), line)
  29. print(line.rstrip())
  30. sys.exit(make.wait())
  31. if __name__ == "__main__":
  32. main()