2017-06-14 11:35:45 +00:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
from os import listdir
|
|
|
|
from os.path import isfile, join
|
|
|
|
from subprocess import PIPE, Popen
|
|
|
|
|
|
|
|
|
2020-07-07 15:12:44 +00:00
|
|
|
# This is n list of files which are stable crates or simply are not crates,
|
2017-06-14 11:35:45 +00:00
|
|
|
# we don't check for the instability of these crates as they're all stable!
|
2019-04-03 17:50:28 +00:00
|
|
|
STABLE_CRATES = ['std', 'alloc', 'core', 'proc_macro',
|
|
|
|
'rsbegin.o', 'rsend.o', 'dllcrt2.o', 'crt2.o', 'clang_rt']
|
2017-06-14 11:35:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
def convert_to_string(s):
|
|
|
|
if s.__class__.__name__ == 'bytes':
|
|
|
|
return s.decode('utf-8')
|
|
|
|
return s
|
|
|
|
|
|
|
|
|
2021-09-17 00:30:36 +00:00
|
|
|
def set_ld_lib_path():
|
|
|
|
var = os.environ.get("LD_LIB_PATH_ENVVAR")
|
|
|
|
rpath = os.environ.get("HOST_RPATH_DIR")
|
|
|
|
if var and rpath:
|
|
|
|
path = os.environ.get(var)
|
|
|
|
if path:
|
|
|
|
os.environ[var] = rpath + os.pathsep + path
|
|
|
|
else:
|
|
|
|
os.environ[var] = rpath
|
|
|
|
|
|
|
|
|
2017-06-14 11:35:45 +00:00
|
|
|
def exec_command(command, to_input=None):
|
|
|
|
child = None
|
|
|
|
if to_input is None:
|
|
|
|
child = Popen(command, stdout=PIPE, stderr=PIPE)
|
|
|
|
else:
|
|
|
|
child = Popen(command, stdout=PIPE, stderr=PIPE, stdin=PIPE)
|
|
|
|
stdout, stderr = child.communicate(input=to_input)
|
|
|
|
return (convert_to_string(stdout), convert_to_string(stderr))
|
|
|
|
|
|
|
|
|
|
|
|
def check_lib(lib):
|
|
|
|
if lib['name'] in STABLE_CRATES:
|
|
|
|
return True
|
|
|
|
print('verifying if {} is an unstable crate'.format(lib['name']))
|
|
|
|
stdout, stderr = exec_command([os.environ['RUSTC'], '-', '--crate-type', 'rlib',
|
2023-03-30 13:44:46 +00:00
|
|
|
'--target', os.environ['TARGET'],
|
2017-06-14 11:35:45 +00:00
|
|
|
'--extern', '{}={}'.format(lib['name'], lib['path'])],
|
2019-11-14 01:11:16 +00:00
|
|
|
to_input=('extern crate {};'.format(lib['name'])).encode('utf-8'))
|
2023-06-10 16:06:17 +00:00
|
|
|
if 'use of unstable library feature' not in '{}{}'.format(stdout, stderr):
|
2017-06-14 11:35:45 +00:00
|
|
|
print('crate {} "{}" is not unstable'.format(lib['name'], lib['path']))
|
|
|
|
print('{}{}'.format(stdout, stderr))
|
|
|
|
print('')
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
# Generate a list of all crates in the sysroot. To do this we list all files in
|
|
|
|
# rustc's sysroot, look at the filename, strip everything after the `-`, and
|
|
|
|
# strip the leading `lib` (if present)
|
|
|
|
def get_all_libs(dir_path):
|
|
|
|
return [{ 'path': join(dir_path, f), 'name': f[3:].split('-')[0] }
|
|
|
|
for f in listdir(dir_path)
|
|
|
|
if isfile(join(dir_path, f)) and f.endswith('.rlib') and f not in STABLE_CRATES]
|
|
|
|
|
|
|
|
|
2021-09-17 00:30:36 +00:00
|
|
|
set_ld_lib_path()
|
2017-06-14 11:35:45 +00:00
|
|
|
sysroot = exec_command([os.environ['RUSTC'], '--print', 'sysroot'])[0].replace('\n', '')
|
2021-09-17 00:30:36 +00:00
|
|
|
assert sysroot, "Could not read the rustc sysroot!"
|
2017-06-14 11:35:45 +00:00
|
|
|
libs = get_all_libs(join(sysroot, 'lib/rustlib/{}/lib'.format(os.environ['TARGET'])))
|
|
|
|
|
|
|
|
ret = 0
|
|
|
|
for lib in libs:
|
|
|
|
if not check_lib(lib):
|
|
|
|
# We continue so users can see all the not unstable crates.
|
|
|
|
ret = 1
|
|
|
|
sys.exit(ret)
|