1#!/usr/bin/env python3 2 3# Copyright (c) 2009 Google Inc. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7import os 8import sys 9import subprocess 10 11 12def IsCygwin(): 13 # Function copied from pylib/gyp/common.py 14 try: 15 out = subprocess.Popen( 16 "uname", stdout=subprocess.PIPE, stderr=subprocess.STDOUT 17 ) 18 stdout, _ = out.communicate() 19 return "CYGWIN" in stdout.decode("utf-8") 20 except Exception: 21 return False 22 23 24def UnixifyPath(path): 25 try: 26 if not IsCygwin(): 27 return path 28 out = subprocess.Popen( 29 ["cygpath", "-u", path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT 30 ) 31 stdout, _ = out.communicate() 32 return stdout.decode("utf-8") 33 except Exception: 34 return path 35 36 37# Make sure we're using the version of pylib in this repo, not one installed 38# elsewhere on the system. Also convert to Unix style path on Cygwin systems, 39# else the 'gyp' library will not be found 40path = UnixifyPath(sys.argv[0]) 41sys.path.insert(0, os.path.join(os.path.dirname(path), "pylib")) 42import gyp # noqa: E402 43 44if __name__ == "__main__": 45 sys.exit(gyp.script_main()) 46