compiler_wrapper.py revision 28683f7dacd94801e9a0d4b28e5aa8a700fc3d6f
1#!/usr/bin/python2
2"""Prototype compiler wrapper.
3
4Only tested with: gcc, g++, clang, clang++
5Installation instructions:
6  1. Rename compiler from <compiler_name> to <compiler_name>.real
7  2. Create symlink from this script (compiler_wrapper.py), and name it
8     <compiler_name>. compiler_wrapper.py can live anywhere as long as it is
9     executable.
10
11Design doc:
12https://docs.google.com/document/d/1yDgaUIa2O5w6dc3sSTe1ry-1ehKajTGJGQCbyn0fcEM
13"""
14
15from __future__ import print_function
16
17import os
18import sys
19
20import bisect_driver
21
22WRAPPED = '%s.real' % sys.argv[0]
23BISECT_STAGE = os.environ.get('BISECT_STAGE')
24DEFAULT_BISECT_DIR = os.path.expanduser('~/ANDROID_BISECT')
25BISECT_DIR = os.environ.get('BISECT_DIR') or DEFAULT_BISECT_DIR
26
27
28def Main(_):
29  if not os.path.islink(sys.argv[0]):
30    print("Compiler wrapper can't be called directly!")
31    return 1
32
33  execargs = [WRAPPED] + sys.argv[1:]
34
35  if BISECT_STAGE not in bisect_driver.VALID_MODES:
36    os.execv(WRAPPED, [WRAPPED] + sys.argv[1:])
37
38  bisect_driver.bisect_driver(BISECT_STAGE, BISECT_DIR, execargs)
39
40
41if __name__ == '__main__':
42  sys.exit(Main(sys.argv[1:]))
43