11cb0ef41Sopenharmony_ci#!/usr/bin/env python3 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci# Copyright (c) 2009 Google Inc. All rights reserved. 41cb0ef41Sopenharmony_ci# Use of this source code is governed by a BSD-style license that can be 51cb0ef41Sopenharmony_ci# found in the LICENSE file. 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciimport os 81cb0ef41Sopenharmony_ciimport sys 91cb0ef41Sopenharmony_ciimport subprocess 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_cidef IsCygwin(): 131cb0ef41Sopenharmony_ci # Function copied from pylib/gyp/common.py 141cb0ef41Sopenharmony_ci try: 151cb0ef41Sopenharmony_ci out = subprocess.Popen( 161cb0ef41Sopenharmony_ci "uname", stdout=subprocess.PIPE, stderr=subprocess.STDOUT 171cb0ef41Sopenharmony_ci ) 181cb0ef41Sopenharmony_ci stdout, _ = out.communicate() 191cb0ef41Sopenharmony_ci return "CYGWIN" in stdout.decode("utf-8") 201cb0ef41Sopenharmony_ci except Exception: 211cb0ef41Sopenharmony_ci return False 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_cidef UnixifyPath(path): 251cb0ef41Sopenharmony_ci try: 261cb0ef41Sopenharmony_ci if not IsCygwin(): 271cb0ef41Sopenharmony_ci return path 281cb0ef41Sopenharmony_ci out = subprocess.Popen( 291cb0ef41Sopenharmony_ci ["cygpath", "-u", path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT 301cb0ef41Sopenharmony_ci ) 311cb0ef41Sopenharmony_ci stdout, _ = out.communicate() 321cb0ef41Sopenharmony_ci return stdout.decode("utf-8") 331cb0ef41Sopenharmony_ci except Exception: 341cb0ef41Sopenharmony_ci return path 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci# Make sure we're using the version of pylib in this repo, not one installed 381cb0ef41Sopenharmony_ci# elsewhere on the system. Also convert to Unix style path on Cygwin systems, 391cb0ef41Sopenharmony_ci# else the 'gyp' library will not be found 401cb0ef41Sopenharmony_cipath = UnixifyPath(sys.argv[0]) 411cb0ef41Sopenharmony_cisys.path.insert(0, os.path.join(os.path.dirname(path), "pylib")) 421cb0ef41Sopenharmony_ciimport gyp # noqa: E402 431cb0ef41Sopenharmony_ci 441cb0ef41Sopenharmony_ciif __name__ == "__main__": 451cb0ef41Sopenharmony_ci sys.exit(gyp.script_main()) 46