1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

Fix update_cc_test_checks.py --llvm-bin after D78478

Not passing --clang would result in a python exception after this change:
(TypeError: expected str, bytes or os.PathLike object, not NoneType)
because the --clang argument default was only being populated in the
initial argument parsing pass but not later on.
Fix this by adding an argparse callback to set the default values.

Reviewed By: vitalybuka, MaskRay

Differential Revision: https://reviews.llvm.org/D84511
This commit is contained in:
Alex Richardson 2020-08-03 11:18:01 +01:00
parent 4bc03c3759
commit 8a7212b0e5
2 changed files with 27 additions and 17 deletions

View File

@ -44,8 +44,9 @@ class InputLineInfo(object):
class TestInfo(object):
def __init__(self, test, parser, script_name, input_lines, args, argv,
comment_prefix):
comment_prefix, argparse_callback):
self.parser = parser
self.argparse_callback = argparse_callback
self.path = test
self.args = args
self.argv = argv
@ -68,14 +69,14 @@ class TestInfo(object):
if input_line.startswith(self.autogenerated_note_prefix):
continue
self.args, self.argv = check_for_command(input_line, self.parser,
self.args, self.argv)
self.args, self.argv, self.argparse_callback)
if not self.args.enabled:
output_lines.append(input_line)
continue
yield InputLineInfo(input_line, line_num, self.args, self.argv)
def itertests(test_patterns, parser, script_name, comment_prefix=None):
def itertests(test_patterns, parser, script_name, comment_prefix=None, argparse_callback=None):
for pattern in test_patterns:
# On Windows we must expand the patterns ourselves.
tests_list = glob.glob(pattern)
@ -86,19 +87,21 @@ def itertests(test_patterns, parser, script_name, comment_prefix=None):
with open(test) as f:
input_lines = [l.rstrip() for l in f]
args = parser.parse_args()
if argparse_callback is not None:
argparse_callback(args)
argv = sys.argv[:]
first_line = input_lines[0] if input_lines else ""
if UTC_ADVERT in first_line:
if script_name not in first_line and not args.force_update:
warn("Skipping test which wasn't autogenerated by " + script_name, test)
continue
args, argv = check_for_command(first_line, parser, args, argv)
args, argv = check_for_command(first_line, parser, args, argv, argparse_callback)
elif args.update_only:
assert UTC_ADVERT not in first_line
warn("Skipping test which isn't autogenerated: " + test)
continue
yield TestInfo(test, parser, script_name, input_lines, args, argv,
comment_prefix)
comment_prefix, argparse_callback)
def should_add_line_to_output(input_line, prefix_set):
@ -510,10 +513,12 @@ def get_autogennote_suffix(parser, args):
return autogenerated_note_args
def check_for_command(line, parser, args, argv):
def check_for_command(line, parser, args, argv, argparse_callback):
cmd_m = UTC_ARGS_CMD.match(line)
if cmd_m:
cmd = cmd_m.group('cmd').strip().split(' ')
argv = argv + cmd
args = parser.parse_args(filter(lambda arg: arg not in args.tests, argv))
if argparse_callback is not None:
argparse_callback(args)
return args, argv

View File

@ -112,6 +112,20 @@ def str_to_commandline(value):
return []
return shlex.split(value)
def infer_dependent_args(args):
if not args.clang:
if not args.llvm_bin:
args.clang = 'clang'
else:
args.clang = os.path.join(args.llvm_bin, 'clang')
if not args.opt:
if not args.llvm_bin:
args.opt = 'opt'
else:
args.opt = os.path.join(args.llvm_bin, 'opt')
def config():
parser = argparse.ArgumentParser(
description=__doc__,
@ -135,12 +149,8 @@ def config():
help='Check "Function Attributes" for functions')
parser.add_argument('tests', nargs='+')
args = common.parse_commandline_args(parser)
infer_dependent_args(args)
if args.clang is None:
if args.llvm_bin is None:
args.clang = 'clang'
else:
args.clang = os.path.join(args.llvm_bin, 'clang')
if not distutils.spawn.find_executable(args.clang):
print('Please specify --llvm-bin or --clang', file=sys.stderr)
sys.exit(1)
@ -157,11 +167,6 @@ def config():
common.warn('Could not determine clang builtins directory, some tests '
'might not update correctly.')
if args.opt is None:
if args.llvm_bin is None:
args.opt = 'opt'
else:
args.opt = os.path.join(args.llvm_bin, 'opt')
if not distutils.spawn.find_executable(args.opt):
# Many uses of this tool will not need an opt binary, because it's only
# needed for updating a test that runs clang | opt | FileCheck. So we
@ -203,7 +208,7 @@ def main():
script_name = os.path.basename(__file__)
for ti in common.itertests(initial_args.tests, parser, 'utils/' + script_name,
comment_prefix='//'):
comment_prefix='//', argparse_callback=infer_dependent_args):
# Build a list of clang command lines and check prefixes from RUN lines.
run_list = []
line2spell_and_mangled_list = collections.defaultdict(list)