fork/rust
git clone https://git.julia.blue/fork/rust
3bcad65fbf6
master
1import sys 2import os 3from os import listdir 4from os.path import isfile, join 5from subprocess import PIPE, Popen 6 7 8# This is n list of files which are stable crates or simply are not crates, 9# we don't check for the instability of these crates as they're all stable! 10STABLE_CRATES = ['std', 'alloc', 'core', 'proc_macro', 11 'rsbegin.o', 'rsend.o', 'dllcrt2.o', 'crt2.o', 'clang_rt'] 12 13 14def convert_to_string(s): 15 if s.__class__.__name__ == 'bytes': 16 return s.decode('utf-8') 17 return s 18 19 20def set_ld_lib_path(): 21 var = os.environ.get("LD_LIB_PATH_ENVVAR") 22 rpath = os.environ.get("HOST_RPATH_DIR") 23 if var and rpath: 24 path = os.environ.get(var) 25 if path: 26 os.environ[var] = rpath + os.pathsep + path 27 else: 28 os.environ[var] = rpath 29 30 31def exec_command(command, to_input=None): 32 child = None 33 if to_input is None: 34 child = Popen(command, stdout=PIPE, stderr=PIPE) 35 else: 36 child = Popen(command, stdout=PIPE, stderr=PIPE, stdin=PIPE) 37 stdout, stderr = child.communicate(input=to_input) 38 return (convert_to_string(stdout), convert_to_string(stderr)) 39 40 41def check_lib(lib): 42 if lib['name'] in STABLE_CRATES: 43 return True 44 print('verifying if {} is an unstable crate'.format(lib['name'])) 45 stdout, stderr = exec_command([os.environ['RUSTC'], '-', '--crate-type', 'rlib', 46 '--target', os.environ['TARGET'], 47 '--extern', '{}={}'.format(lib['name'], lib['path'])], 48 to_input=('extern crate {};'.format(lib['name'])).encode('utf-8')) 49 if 'use of unstable library feature' not in '{}{}'.format(stdout, stderr): 50 print('crate {} "{}" is not unstable'.format(lib['name'], lib['path'])) 51 print('{}{}'.format(stdout, stderr)) 52 print('') 53 return False 54 return True 55 56# Generate a list of all crates in the sysroot. To do this we list all files in 57# rustc's sysroot, look at the filename, strip everything after the `-`, and 58# strip the leading `lib` (if present) 59def get_all_libs(dir_path): 60 return [{ 'path': join(dir_path, f), 'name': f[3:].split('-')[0] } 61 for f in listdir(dir_path) 62 if isfile(join(dir_path, f)) and f.endswith('.rlib') and f not in STABLE_CRATES] 63 64 65set_ld_lib_path() 66sysroot = exec_command([os.environ['RUSTC'], '--print', 'sysroot'])[0].replace('\n', '') 67assert sysroot, "Could not read the rustc sysroot!" 68libs = get_all_libs(join(sysroot, 'lib/rustlib/{}/lib'.format(os.environ['TARGET']))) 69 70ret = 0 71for lib in libs: 72 if not check_lib(lib): 73 # We continue so users can see all the not unstable crates. 74 ret = 1 75sys.exit(ret)