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