aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYunlian Jiang <yunlian@google.com>2016-09-22 21:31:58 (GMT)
committerYunlian Jiang <yunlian@google.com>2016-10-03 17:11:00 (GMT)
commit5f2680086b7622cc877c82aafe3c973134a20ad4 (patch)
treef439ec3f7c75d3e1d34cc31d5009e87295484e34
parent535de7eb0179bdcd01fcd99f1dad6208250d3706 (diff)
downloadtoolchain_gcc-5f2680086b7622cc877c82aafe3c973134a20ad4.zip
toolchain_gcc-5f2680086b7622cc877c82aafe3c973134a20ad4.tar.gz
toolchain_gcc-5f2680086b7622cc877c82aafe3c973134a20ad4.tar.bz2
gcc: add a python wrapper for gcc.
This add a python wrapper for gcc to make goma do not need to hand gcc and clang separately. BUG 31444867 TEST= build new gcc. Call arm-linux-androideabi-c++ -v and arm-linux-androideabi-g++ -v in/out the directory of the gcc binary, it works. Change-Id: Ib02cff8f33306b089e13ade51033a3b0927b4308
-rwxr-xr-xbuild-gcc.sh18
-rwxr-xr-xcompiler_wrapper66
2 files changed, 84 insertions, 0 deletions
diff --git a/build-gcc.sh b/build-gcc.sh
index 4893461..c21accf 100755
--- a/build-gcc.sh
+++ b/build-gcc.sh
@@ -569,8 +569,26 @@ do_relink_bin () {
$ABI_CONFIGURE_TARGET-$DST_FILE$HOST_EXE
}
+# $1: The file to be replaced by wrapper.
+do_install_gcc_wrapper() {
+ WRAPPER=$SRC_DIR/gcc/compiler_wrapper
+ local DST_FILE=$TOOLCHAIN_INSTALL_PATH/bin/$ABI_CONFIGURE_TARGET-$1
+ local REAL_DST_FILE=$TOOLCHAIN_INSTALL_PATH/bin/real-$ABI_CONFIGURE_TARGET-$1
+ if [ ! -f "$WRAPPER" ]; then
+ echo "ERROR: Can't install wrapper because $WRAPPER doesn't exist"
+ exit 1
+ fi
+ if [ ! -f "$DST_FILE$HOST_EXE" ]; then
+ echo "ERROR: Can't install wrapper because $DST_FILE$HOST_EXE doesn't exist"
+ fi
+ mv $DST_FILE$HOST_EXE $REAL_DST_FILE
+ cp -p $WRAPPER $DST_FILE$HOST_EXE
+}
+
do_relink_bin c++ g++
do_relink_bin gcc-$GCC_VERSION gcc
+do_install_gcc_wrapper gcc
+do_install_gcc_wrapper g++
# symlink ld to either ld.gold or ld.bfd
case "$TOOLCHAIN" in
aarch64*)
diff --git a/compiler_wrapper b/compiler_wrapper
new file mode 100755
index 0000000..15d50f4
--- /dev/null
+++ b/compiler_wrapper
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+
+import os
+import sys
+
+class CompilerWrapper():
+ def __init__(self, argv):
+ self.args = argv
+ self.execargs = []
+ self.real_compiler = None
+ self.argv0 = None
+ self.append_flags = []
+ self.prepend_flags = []
+ self.custom_flags = {
+ '--gomacc-path': None
+ }
+
+ def set_real_compiler(self):
+ """Find the real compiler with the absolute path."""
+ compiler_path = os.path.dirname(os.path.abspath(__file__))
+ if os.path.islink(__file__):
+ compiler = os.path.basename(os.readlink(__file__))
+ else:
+ compiler = os.path.basename(os.path.abspath(__file__))
+ self.real_compiler = os.path.join(
+ compiler_path,
+ "real-" + compiler)
+ self.argv0 = self.real_compiler
+
+ def process_gomacc_command(self):
+ """Return the gomacc command if '--gomacc-path' is set."""
+ gomacc = self.custom_flag['--gomacc-path']
+ if gomacc and os.path.isfile(gomacc):
+ self.argv0 = gomacc
+ self.execargs += [gomacc]
+
+ def parse_custom_flags(self):
+ i = 0
+ args = []
+ while i < len(self.args):
+ if self.args[i] in self.custom_flag:
+ self.custom_flags[self.args[i]] = self.args[i + 1]
+ i = i + 2
+ else:
+ args.append(self.args[i])
+ i = i + 1
+ self.args = args
+
+ def add_flags(self):
+ self.args = self.prepend_flags + self.args + self.append_flags
+
+ def invoke_compiler(self):
+ self.set_real_compiler()
+ self.parse_custom_flags()
+ self.process_gomacc_command()
+ self.add_flags()
+ self.execargs += [self.real_compiler] + self.args
+ os.execv(self.argv0, self.execargs)
+
+
+def main(argv):
+ cw = CompilerWrapper(argv[1:])
+ cw.invoke_compiler()
+
+if __name__ == "__main__":
+ main(sys.argv)