gyp_main.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/usr/bin/env python
  2. # Copyright (c) 2009 Google Inc. 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. import os
  6. import sys
  7. import subprocess
  8. PY3 = bytes != str
  9. # Below IsCygwin() function copied from pylib/gyp/common.py
  10. def IsCygwin():
  11. try:
  12. out = subprocess.Popen("uname",
  13. stdout=subprocess.PIPE,
  14. stderr=subprocess.STDOUT)
  15. stdout, stderr = out.communicate()
  16. if PY3:
  17. stdout = stdout.decode("utf-8")
  18. return "CYGWIN" in str(stdout)
  19. except Exception:
  20. return False
  21. def UnixifyPath(path):
  22. try:
  23. if not IsCygwin():
  24. return path
  25. out = subprocess.Popen(["cygpath", "-u", path],
  26. stdout=subprocess.PIPE,
  27. stderr=subprocess.STDOUT)
  28. stdout, _ = out.communicate()
  29. if PY3:
  30. stdout = stdout.decode("utf-8")
  31. return str(stdout)
  32. except Exception:
  33. return path
  34. # Make sure we're using the version of pylib in this repo, not one installed
  35. # elsewhere on the system. Also convert to Unix style path on Cygwin systems,
  36. # else the 'gyp' library will not be found
  37. path = UnixifyPath(sys.argv[0])
  38. sys.path.insert(0, os.path.join(os.path.dirname(path), 'pylib'))
  39. import gyp
  40. if __name__ == '__main__':
  41. sys.exit(gyp.script_main())