1*9880d681SAndroid Build Coastguard Workerimport os 2*9880d681SAndroid Build Coastguard Workerimport pipes 3*9880d681SAndroid Build Coastguard Workerimport shlex 4*9880d681SAndroid Build Coastguard Workerimport sys 5*9880d681SAndroid Build Coastguard Worker 6*9880d681SAndroid Build Coastguard Workerif not 'go' in config.root.llvm_bindings: 7*9880d681SAndroid Build Coastguard Worker config.unsupported = True 8*9880d681SAndroid Build Coastguard Worker 9*9880d681SAndroid Build Coastguard Workerif config.root.include_go_tests != 'ON': 10*9880d681SAndroid Build Coastguard Worker config.unsupported = True 11*9880d681SAndroid Build Coastguard Worker 12*9880d681SAndroid Build Coastguard Workerdef find_executable(executable, path=None): 13*9880d681SAndroid Build Coastguard Worker if path is None: 14*9880d681SAndroid Build Coastguard Worker path = os.environ['PATH'] 15*9880d681SAndroid Build Coastguard Worker paths = path.split(os.pathsep) 16*9880d681SAndroid Build Coastguard Worker base, ext = os.path.splitext(executable) 17*9880d681SAndroid Build Coastguard Worker 18*9880d681SAndroid Build Coastguard Worker if (sys.platform == 'win32' or os.name == 'os2') and (ext != '.exe'): 19*9880d681SAndroid Build Coastguard Worker executable = executable + '.exe' 20*9880d681SAndroid Build Coastguard Worker 21*9880d681SAndroid Build Coastguard Worker if not os.path.isfile(executable): 22*9880d681SAndroid Build Coastguard Worker for p in paths: 23*9880d681SAndroid Build Coastguard Worker f = os.path.join(p, executable) 24*9880d681SAndroid Build Coastguard Worker if os.path.isfile(f): 25*9880d681SAndroid Build Coastguard Worker return f 26*9880d681SAndroid Build Coastguard Worker return None 27*9880d681SAndroid Build Coastguard Worker else: 28*9880d681SAndroid Build Coastguard Worker return executable 29*9880d681SAndroid Build Coastguard Worker 30*9880d681SAndroid Build Coastguard Worker# Resolve certain symlinks in the first word of compiler. 31*9880d681SAndroid Build Coastguard Worker# 32*9880d681SAndroid Build Coastguard Worker# This is a Go-specific hack. cgo and other Go tools check $CC and $CXX for the 33*9880d681SAndroid Build Coastguard Worker# substring 'clang' to determine if the compiler is Clang. This won't work if 34*9880d681SAndroid Build Coastguard Worker# $CC is cc and cc is a symlink pointing to clang, as it is on Darwin. 35*9880d681SAndroid Build Coastguard Worker# 36*9880d681SAndroid Build Coastguard Worker# Go tools also have problems with ccache, so we disable it. 37*9880d681SAndroid Build Coastguard Workerdef fixup_compiler_path(compiler): 38*9880d681SAndroid Build Coastguard Worker args = shlex.split(compiler) 39*9880d681SAndroid Build Coastguard Worker if args[0].endswith('ccache'): 40*9880d681SAndroid Build Coastguard Worker args = args[1:] 41*9880d681SAndroid Build Coastguard Worker 42*9880d681SAndroid Build Coastguard Worker path = find_executable(args[0]) 43*9880d681SAndroid Build Coastguard Worker 44*9880d681SAndroid Build Coastguard Worker try: 45*9880d681SAndroid Build Coastguard Worker if path.endswith('/cc') and os.readlink(path) == 'clang': 46*9880d681SAndroid Build Coastguard Worker args[0] = path[:len(path)-2] + 'clang' 47*9880d681SAndroid Build Coastguard Worker except (AttributeError, OSError): 48*9880d681SAndroid Build Coastguard Worker pass 49*9880d681SAndroid Build Coastguard Worker 50*9880d681SAndroid Build Coastguard Worker try: 51*9880d681SAndroid Build Coastguard Worker if path.endswith('/c++') and os.readlink(path) == 'clang++': 52*9880d681SAndroid Build Coastguard Worker args[0] = path[:len(path)-3] + 'clang++' 53*9880d681SAndroid Build Coastguard Worker except (AttributeError, OSError): 54*9880d681SAndroid Build Coastguard Worker pass 55*9880d681SAndroid Build Coastguard Worker 56*9880d681SAndroid Build Coastguard Worker return ' '.join([pipes.quote(arg) for arg in args]) 57*9880d681SAndroid Build Coastguard Worker 58*9880d681SAndroid Build Coastguard Workerconfig.environment['CC'] = fixup_compiler_path(config.host_cc) 59*9880d681SAndroid Build Coastguard Workerconfig.environment['CXX'] = fixup_compiler_path(config.host_cxx) 60*9880d681SAndroid Build Coastguard Workerconfig.environment['CGO_LDFLAGS'] = config.host_ldflags 61