4 from os.path import isfile, join
5 from subprocess import PIPE, Popen
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!
10 STABLE_CRATES = ['std', 'alloc', 'core', 'proc_macro',
11 'rsbegin.o', 'rsend.o', 'dllcrt2.o', 'crt2.o', 'clang_rt']
14 def convert_to_string(s):
15 if s.__class__.__name__ == 'bytes':
16 return s.decode('utf-8')
20 def set_ld_lib_path():
21 var = os.environ.get("LD_LIB_PATH_ENVVAR")
22 rpath = os.environ.get("HOST_RPATH_DIR")
24 path = os.environ.get(var)
26 os.environ[var] = rpath + os.pathsep + path
28 os.environ[var] = rpath
31 def exec_command(command, to_input=None):
34 child = Popen(command, stdout=PIPE, stderr=PIPE)
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))
42 if lib['name'] in STABLE_CRATES:
44 print('verifying if {} is an unstable crate'.format(lib['name']))
45 stdout, stderr = exec_command([os.environ['RUSTC'], '-', '--crate-type', 'rlib',
46 '--extern', '{}={}'.format(lib['name'], lib['path'])],
47 to_input=('extern crate {};'.format(lib['name'])).encode('utf-8'))
48 if not 'use of unstable library feature' in '{}{}'.format(stdout, stderr):
49 print('crate {} "{}" is not unstable'.format(lib['name'], lib['path']))
50 print('{}{}'.format(stdout, stderr))
55 # Generate a list of all crates in the sysroot. To do this we list all files in
56 # rustc's sysroot, look at the filename, strip everything after the `-`, and
57 # strip the leading `lib` (if present)
58 def get_all_libs(dir_path):
59 return [{ 'path': join(dir_path, f), 'name': f[3:].split('-')[0] }
60 for f in listdir(dir_path)
61 if isfile(join(dir_path, f)) and f.endswith('.rlib') and f not in STABLE_CRATES]
65 sysroot = exec_command([os.environ['RUSTC'], '--print', 'sysroot'])[0].replace('\n', '')
66 assert sysroot, "Could not read the rustc sysroot!"
67 libs = get_all_libs(join(sysroot, 'lib/rustlib/{}/lib'.format(os.environ['TARGET'])))
71 if not check_lib(lib):
72 # We continue so users can see all the not unstable crates.