1import subprocess 2 3def getRoot(config): 4 if not config.parent: 5 return config 6 return getRoot(config.parent) 7 8 9def is_gold_linker_available(): 10 11 if not config.gold_executable: 12 return False 13 try: 14 ld_cmd = subprocess.Popen([config.gold_executable, '--help'], stdout = subprocess.PIPE) 15 ld_out = ld_cmd.stdout.read().decode() 16 ld_cmd.wait() 17 except: 18 return False 19 20 if not '-plugin' in ld_out: 21 return False 22 23 # config.clang is not guaranteed to be just the executable! 24 clang_cmd = subprocess.Popen(" ".join([config.clang, '-fuse-ld=gold', '-xc', '-']), 25 shell=True, 26 universal_newlines = True, 27 stdin = subprocess.PIPE, 28 stdout = subprocess.PIPE, 29 stderr = subprocess.PIPE) 30 clang_err = clang_cmd.communicate('int main() { return 0; }')[1] 31 32 if not 'invalid linker' in clang_err: 33 return True 34 35 return False 36 37root = getRoot(config) 38 39if root.host_os not in ['Linux'] or not is_gold_linker_available(): 40 config.unsupported = True 41