blob: e937a80ef02ef9ddbc07184d5b472ce04d54a1d9 [file] [log] [blame]
Caroline Ticebf02f9b2016-10-10 09:17:19 -07001#!/usr/bin/python
Yiran Wanga70724f2015-07-16 13:22:25 -07002
Nick Desaulniersbdb57362019-01-31 10:48:28 -08003from __future__ import print_function
Caroline Ticebf02f9b2016-10-10 09:17:19 -07004import os
5import sys
Yiran Wanga70724f2015-07-16 13:22:25 -07006
Caroline Ticebf02f9b2016-10-10 09:17:19 -07007class CompilerWrapper():
8 def __init__(self, argv):
9 self.args = argv
10 self.execargs = []
11 self.real_compiler = None
12 self.argv0 = None
13 self.append_flags = []
14 self.prepend_flags = []
15 self.custom_flags = {
16 '--gomacc-path': None
17 }
Yiran Wanga70724f2015-07-16 13:22:25 -070018
Caroline Ticebf02f9b2016-10-10 09:17:19 -070019 def set_real_compiler(self):
20 """Find the real compiler with the absolute path."""
21 compiler_path = os.path.dirname(os.path.abspath(__file__))
22 if os.path.islink(__file__):
23 compiler = os.path.basename(os.readlink(__file__))
24 else:
25 compiler = os.path.basename(os.path.abspath(__file__))
26 self.real_compiler = os.path.join(
27 compiler_path,
Nick Desaulniersbdb57362019-01-31 10:48:28 -080028 "7fefe5b2-2588-11e9-996b-2bbad94f2d53")
Caroline Ticebf02f9b2016-10-10 09:17:19 -070029 self.argv0 = self.real_compiler
Yiran Wanga70724f2015-07-16 13:22:25 -070030
Caroline Ticebf02f9b2016-10-10 09:17:19 -070031 def process_gomacc_command(self):
32 """Return the gomacc command if '--gomacc-path' is set."""
33 gomacc = self.custom_flags['--gomacc-path']
34 if gomacc and os.path.isfile(gomacc):
35 self.argv0 = gomacc
36 self.execargs += [gomacc]
Yiran Wanga70724f2015-07-16 13:22:25 -070037
Caroline Ticebf02f9b2016-10-10 09:17:19 -070038 def parse_custom_flags(self):
39 i = 0
40 args = []
41 while i < len(self.args):
42 if self.args[i] in self.custom_flags:
43 self.custom_flags[self.args[i]] = self.args[i + 1]
44 i = i + 2
45 else:
46 args.append(self.args[i])
47 i = i + 1
48 self.args = args
Yiran Wanga70724f2015-07-16 13:22:25 -070049
Caroline Ticebf02f9b2016-10-10 09:17:19 -070050 def add_flags(self):
51 self.args = self.prepend_flags + self.args + self.append_flags
Yiran Wanga70724f2015-07-16 13:22:25 -070052
Nick Desaulniersbdb57362019-01-31 10:48:28 -080053 def print_deprecation_warning(self):
54 print("Android GCC has been deprecated in favor of Clang, and will be removed from\n"
55 "Android in 2020-01 as per the deprecation plan in:\n"
56 "https://android.googlesource.com/platform/prebuilts/clang/host/linux-x86/+/master/GCC_4_9_DEPRECATION.md\n\n",
57 file=sys.stderr)
58
59
Caroline Ticebf02f9b2016-10-10 09:17:19 -070060 def invoke_compiler(self):
Nick Desaulniersbdb57362019-01-31 10:48:28 -080061 self.print_deprecation_warning()
Caroline Ticebf02f9b2016-10-10 09:17:19 -070062 self.set_real_compiler()
63 self.parse_custom_flags()
64 self.process_gomacc_command()
65 self.add_flags()
66 self.execargs += [self.real_compiler] + self.args
67 os.execv(self.argv0, self.execargs)
Rong Xu90135de2014-09-05 14:09:07 -070068
69
Caroline Ticebf02f9b2016-10-10 09:17:19 -070070def main(argv):
71 cw = CompilerWrapper(argv[1:])
72 cw.invoke_compiler()
Rong Xu90135de2014-09-05 14:09:07 -070073
Caroline Ticebf02f9b2016-10-10 09:17:19 -070074if __name__ == "__main__":
75 main(sys.argv)