[llvm] d100747 - Fix update_cc_test_checks.py --llvm-bin after D78478
Alex Richardson via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 3 03:23:20 PDT 2020
Author: Alex Richardson
Date: 2020-08-03T11:18:01+01:00
New Revision: d1007478f19d3ff19a2ecd5ecb04b467933041e6
URL: https://github.com/llvm/llvm-project/commit/d1007478f19d3ff19a2ecd5ecb04b467933041e6
DIFF: https://github.com/llvm/llvm-project/commit/d1007478f19d3ff19a2ecd5ecb04b467933041e6.diff
LOG: 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
Added:
Modified:
llvm/utils/UpdateTestChecks/common.py
llvm/utils/update_cc_test_checks.py
Removed:
################################################################################
diff --git a/llvm/utils/UpdateTestChecks/common.py b/llvm/utils/UpdateTestChecks/common.py
index 17f738601f61..35b7ba648d36 100644
--- a/llvm/utils/UpdateTestChecks/common.py
+++ b/llvm/utils/UpdateTestChecks/common.py
@@ -44,8 +44,9 @@ def __init__(self, line, line_number, args, argv):
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 @@ def iterlines(self, output_lines):
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
diff --git a/llvm/utils/update_cc_test_checks.py b/llvm/utils/update_cc_test_checks.py
index fa7b4fa73b98..ba8a68b8669f 100755
--- a/llvm/utils/update_cc_test_checks.py
+++ b/llvm/utils/update_cc_test_checks.py
@@ -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)
More information about the llvm-commits
mailing list