import os
import sys
class TestingConfig(object):
@staticmethod
def fromdefaults(litConfig):
environment = {
'PATH' : os.pathsep.join(litConfig.path +
[os.environ.get('PATH','')]),
'LLVM_DISABLE_CRASH_REPORT' : '1',
}
pass_vars = [
'LIBRARY_PATH',
'LD_LIBRARY_PATH',
'SYSTEMROOT',
'TERM',
'CLANG',
'LLDB',
'LD_PRELOAD',
'LLVM_SYMBOLIZER_PATH',
'ASAN_SYMBOLIZER_PATH',
'LSAN_SYMBOLIZER_PATH',
'MSAN_SYMBOLIZER_PATH',
'TSAN_SYMBOLIZER_PATH',
'UBSAN_SYMBOLIZER_PATH',
'ASAN_OPTIONS',
'LSAN_OPTIONS',
'MSAN_OPTIONS',
'TSAN_OPTIONS',
'UBSAN_OPTIONS',
'ADB',
'ANDROID_SERIAL',
'SSH_AUTH_SOCK',
'SANITIZER_IGNORE_CVE_2016_2143',
'TMPDIR',
'TMP',
'TEMP',
'TEMPDIR',
'AVRLIT_BOARD',
'AVRLIT_PORT',
'FILECHECK_OPTS',
'VCINSTALLDIR',
'VCToolsinstallDir',
'VSINSTALLDIR',
'WindowsSdkDir',
'WindowsSDKLibVersion',
'SOURCE_DATE_EPOCH',
'GTEST_FILTER',
'DFLTCC',
]
if sys.platform == 'win32':
pass_vars += [
'COMSPEC',
'INCLUDE',
'LIB',
'PATHEXT',
'USERPROFILE',
]
environment['PYTHONBUFFERED'] = '1'
for var in pass_vars:
val = os.environ.get(var, '')
if val:
environment[var] = val
available_features = []
if litConfig.useValgrind:
available_features.append('valgrind')
if litConfig.valgrindLeakCheck:
available_features.append('vg_leak')
return TestingConfig(None,
name = '<unnamed>',
suffixes = set(),
test_format = None,
environment = environment,
substitutions = [],
unsupported = False,
test_exec_root = None,
test_source_root = None,
excludes = [],
available_features = available_features,
pipefail = True,
standalone_tests = False)
def load_from_path(self, path, litConfig):
data = None
f = open(path)
try:
data = f.read()
except:
litConfig.fatal('unable to load config file: %r' % (path,))
f.close()
cfg_globals = dict(globals())
cfg_globals['config'] = self
cfg_globals['lit_config'] = litConfig
cfg_globals['__file__'] = path
try:
exec(compile(data, path, 'exec'), cfg_globals, None)
if litConfig.debug:
litConfig.note('... loaded config %r' % path)
except SystemExit:
e = sys.exc_info()[1]
if e.args:
raise
except:
import traceback
litConfig.fatal(
'unable to parse config file %r, traceback: %s' % (
path, traceback.format_exc()))
self.finish(litConfig)
def __init__(self, parent, name, suffixes, test_format,
environment, substitutions, unsupported,
test_exec_root, test_source_root, excludes,
available_features, pipefail, limit_to_features = [],
is_early = False, parallelism_group = None,
standalone_tests = False):
self.parent = parent
self.name = str(name)
self.suffixes = set(suffixes)
self.test_format = test_format
self.environment = dict(environment)
self.substitutions = list(substitutions)
self.unsupported = unsupported
self.test_exec_root = test_exec_root
self.test_source_root = test_source_root
self.excludes = set(excludes)
self.available_features = set(available_features)
self.pipefail = pipefail
self.standalone_tests = standalone_tests
self.limit_to_features = set(limit_to_features)
self.parallelism_group = parallelism_group
self._recursiveExpansionLimit = None
@property
def recursiveExpansionLimit(self):
return self._recursiveExpansionLimit
@recursiveExpansionLimit.setter
def recursiveExpansionLimit(self, value):
if value is not None and not isinstance(value, int):
raise ValueError('recursiveExpansionLimit must be either None or an integer (got <{}>)'.format(value))
if isinstance(value, int) and value < 0:
raise ValueError('recursiveExpansionLimit must be a non-negative integer (got <{}>)'.format(value))
self._recursiveExpansionLimit = value
def finish(self, litConfig):
self.name = str(self.name)
self.suffixes = set(self.suffixes)
self.environment = dict(self.environment)
self.substitutions = list(self.substitutions)
if self.test_exec_root is not None:
self.test_exec_root = str(self.test_exec_root)
if self.test_source_root is not None:
self.test_source_root = str(self.test_source_root)
self.excludes = set(self.excludes)
@property
def root(self):
if self.parent is None:
return self
else:
return self.parent.root
class SubstituteCaptures:
def __init__(self, substitution):
self.substitution = substitution
def replace(self, pattern, replacement):
return self.substitution
def __str__(self):
return self.substitution
def __len__(self):
return len(self.substitution)
def __getitem__(self, item):
return self.substitution.__getitem__(item)