blob: 6fcfe1a30bbd556acefd9fb04444eeba9afc22aa [file] [log] [blame]
Primiano Tuccieac5d712021-05-18 20:45:05 +01001#!/usr/bin/env python3
2# Copyright (C) 2021 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15""" A wrapper to run gn, ninja and other buildtools/ for all platforms. """
16
17from __future__ import print_function
18
19import os
20import subprocess
21import sys
22
23from platform import system, machine
24
25ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
26
27
28def run_buildtools_binary(args):
29 if len(args) < 1:
30 print('Usage %s command [args]\n' % sys.argv[0])
31 return 1
32
33 sys_name = system().lower()
34 os_dir = None
35 ext = ''
36 if sys_name == 'windows':
37 os_dir = 'win'
38 ext = '.exe'
39 elif sys_name == 'darwin':
40 os_dir = 'mac'
41 elif sys_name == 'linux':
42 os_dir = 'linux64'
43 else:
44 print('OS not supported: %s\n' % sys_name)
45 return 1
46
47 cmd = args[0]
48 args = args[1:]
49 exe_path = os.path.join(ROOT_DIR, 'buildtools', os_dir, cmd) + ext
50 if sys_name == 'windows':
51 # execl() behaves oddly on Windows: the spawned process doesn't seem to
52 # receive CTRL+C. Use subprocess instead.
53 return subprocess.call([exe_path] + args)
54 else:
55 os.execl(exe_path, os.path.basename(exe_path), *args)
56
57
58if __name__ == '__main__':
59 sys.exit(run_buildtools_binary(sys.argv[1:]))