fork/rust
git clone https://git.julia.blue/fork/rust
73528e339aa
1.40.0
1import sys 2import os 3from os import listdir 4from os.path import isfile, join 5from subprocess import PIPE, Popen 6 7 8# This is a whitelist 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 exec_command(command, to_input=None): 21 child = None 22 if to_input is None: 23 child = Popen(command, stdout=PIPE, stderr=PIPE) 24 else: 25 child = Popen(command, stdout=PIPE, stderr=PIPE, stdin=PIPE) 26 stdout, stderr = child.communicate(input=to_input) 27 return (convert_to_string(stdout), convert_to_string(stderr)) 28 29 30def check_lib(lib): 31 if lib['name'] in STABLE_CRATES: 32 return True 33 print('verifying if {} is an unstable crate'.format(lib['name'])) 34 stdout, stderr = exec_command([os.environ['RUSTC'], '-', '--crate-type', 'rlib', 35 '--extern', '{}={}'.format(lib['name'], lib['path'])], 36 to_input='extern crate {};'.format(lib['name'])) 37 if not 'use of unstable library feature' in '{}{}'.format(stdout, stderr): 38 print('crate {} "{}" is not unstable'.format(lib['name'], lib['path'])) 39 print('{}{}'.format(stdout, stderr)) 40 print('') 41 return False 42 return True 43 44# Generate a list of all crates in the sysroot. To do this we list all files in 45# rustc's sysroot, look at the filename, strip everything after the `-`, and 46# strip the leading `lib` (if present) 47def get_all_libs(dir_path): 48 return [{ 'path': join(dir_path, f), 'name': f[3:].split('-')[0] } 49 for f in listdir(dir_path) 50 if isfile(join(dir_path, f)) and f.endswith('.rlib') and f not in STABLE_CRATES] 51 52 53sysroot = exec_command([os.environ['RUSTC'], '--print', 'sysroot'])[0].replace('\n', '') 54libs = get_all_libs(join(sysroot, 'lib/rustlib/{}/lib'.format(os.environ['TARGET']))) 55 56ret = 0 57for lib in libs: 58 if not check_lib(lib): 59 # We continue so users can see all the not unstable crates. 60 ret = 1 61sys.exit(ret)