diff --git a/llvm/utils/gn/gn.py b/llvm/utils/gn/gn.py --- a/llvm/utils/gn/gn.py +++ b/llvm/utils/gn/gn.py @@ -33,12 +33,23 @@ print('follow https://gn.googlesource.com/gn/#getting-started') return 1 +def system_binary_available(binary_name): + if sys.platform == 'win32': + if subprocess.call(['WHERE', '/q', binary_name], + stdout=open(os.devnull, 'w'), + stderr=subprocess.STDOUT) == 0: + return True + elif os.name == 'posix': + if subprocess.call(['which', binary_name], + stdout=open(os.devnull, 'w'), + stderr=subprocess.STDOUT) == 0: + return True + return False def main(): # Find real gn executable. gn = 'gn' - if subprocess.call([gn, '--version'], stdout=open(os.devnull, 'w'), - stderr=subprocess.STDOUT) != 0: + if not system_binary_available(gn): # Not on path. See if get.py downloaded a prebuilt binary and run that # if it's there, or suggest to run get.py if it isn't. platform = get_platform()