gyp_main.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. def IsCygwin():
  10. # Function copied from pylib/gyp/common.py
  11. try:
  12. out = subprocess.Popen(
  13. "uname", stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  14. )
  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(
  26. ["cygpath", "-u", path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
  27. )
  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 # noqa: E402
  40. if __name__ == "__main__":
  41. sys.exit(gyp.script_main())