From e07f577a9cbffb1d2c3913f6f813ae59508aeeaf Mon Sep 17 00:00:00 2001 From: Richard Gibson Date: Tue, 27 Jul 2021 13:20:57 -0400 Subject: [PATCH] Default to not regenerate test files that are newer than their case and template --- tools/generation/generator.py | 9 +++++++++ tools/generation/lib/template.py | 3 ++- tools/generation/lib/test.py | 3 ++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/tools/generation/generator.py b/tools/generation/generator.py index e52aeffe78..d280357561 100755 --- a/tools/generation/generator.py +++ b/tools/generation/generator.py @@ -57,6 +57,13 @@ def create(args): 'Refusing to overwrite file: ' + test.file_name) exit(1) + if not args.regenerate: + test_file = os.path.join(args.out, test.file_name) + test_mtime = os.path.getmtime(test_file) + source_files = test.source_file_names + if all(test_mtime > os.path.getmtime(f) for f in source_files): + continue + if not existing.is_generated(): print_error( 'Refusing to overwrite non-generated file: ' + @@ -80,6 +87,8 @@ create_parser.add_argument('-p', '--parents', action='store_true', help='''Create non-existent directories as necessary.''') create_parser.add_argument('-n', '--no-clobber', action='store_true', help='''Abort if any test file already exists.''') +create_parser.add_argument('-r', '--regenerate', action='store_true', + help='''Regenerate test files that are already newer than their source data.''') create_parser.add_argument('cases', help='''Test cases to generate. May be a file or a directory.''') create_parser.set_defaults(func=create) diff --git a/tools/generation/lib/template.py b/tools/generation/lib/template.py index a0eb156037..ab6235e1a7 100644 --- a/tools/generation/lib/template.py +++ b/tools/generation/lib/template.py @@ -216,4 +216,5 @@ class Template: body = self.expand_regions(self.source, case_values) return codecs.encode(frontmatter + '\n' + body, encoding) return Test(self.attribs['meta']['path'] + case_name + '.js', - dynamic_source=get_source) + dynamic_source=get_source, + source_file_names=(self.filename, case_filename)) diff --git a/tools/generation/lib/test.py b/tools/generation/lib/test.py index ad2eb3dcde..ad26861dc9 100644 --- a/tools/generation/lib/test.py +++ b/tools/generation/lib/test.py @@ -17,9 +17,10 @@ def after_parse(fn): class Test: """Representation of a generated test. Specifies a file location which may or may not exist.""" - def __init__(self, file_name, dynamic_source=None): + def __init__(self, file_name, dynamic_source=None, source_file_names=None): self.file_name = file_name self.dynamic_source = dynamic_source + self.source_file_names = source_file_names self.source = None self.attribs = dict(meta=None)