diff --git a/src/tint/fuzzers/BUILD.gn b/src/tint/fuzzers/BUILD.gn index 3253e94ce8..afd1e3a881 100644 --- a/src/tint/fuzzers/BUILD.gn +++ b/src/tint/fuzzers/BUILD.gn @@ -22,14 +22,16 @@ if (build_with_chromium) { import("//testing/libfuzzer/fuzzer_test.gni") fuzzer_corpus_wgsl_dir = "${target_gen_dir}/fuzzer_corpus_wgsl" + fuzzer_corpus_wgsl_stamp = "${fuzzer_corpus_wgsl_dir}.stamp" action("tint_generate_wgsl_corpus") { script = "generate_wgsl_corpus.py" sources = [ "generate_wgsl_corpus.py" ] args = [ + "--stamp=${fuzzer_corpus_wgsl_stamp}", rebase_path("${tint_root_dir}/test", root_build_dir), rebase_path(fuzzer_corpus_wgsl_dir, root_build_dir), ] - outputs = [ fuzzer_corpus_wgsl_dir ] + outputs = [ fuzzer_corpus_wgsl_stamp ] } tint_fuzzer_common_libfuzzer_options = [ diff --git a/src/tint/fuzzers/generate_wgsl_corpus.py b/src/tint/fuzzers/generate_wgsl_corpus.py index 65c564f904..983acd97b5 100644 --- a/src/tint/fuzzers/generate_wgsl_corpus.py +++ b/src/tint/fuzzers/generate_wgsl_corpus.py @@ -26,6 +26,7 @@ # Usage: # generate_wgsl_corpus.py +import optparse import os import pathlib import shutil @@ -40,11 +41,14 @@ def list_wgsl_files(root_search_dir): def main(): - if len(sys.argv) != 3: - print("Usage: " + sys.argv[0] + " ") - return 1 - input_dir: str = os.path.abspath(sys.argv[1].rstrip(os.sep)) - corpus_dir: str = os.path.abspath(sys.argv[2]) + parser = optparse.OptionParser( + usage="usage: %prog [option] input-dir output-dir") + parser.add_option('--stamp', dest='stamp', help='stamp file') + options, args = parser.parse_args(sys.argv[1:]) + if len(args) != 2: + parser.error("incorrect number of arguments") + input_dir: str = os.path.abspath(args[0].rstrip(os.sep)) + corpus_dir: str = os.path.abspath(args[1]) if os.path.exists(corpus_dir): shutil.rmtree(corpus_dir) os.makedirs(corpus_dir) @@ -53,6 +57,8 @@ def main(): continue out_file = in_file[len(input_dir) + 1:].replace(os.sep, '_') shutil.copy(in_file, corpus_dir + os.sep + out_file) + if options.stamp: + pathlib.Path(options.stamp).touch(mode=0o644, exist_ok=True) if __name__ == "__main__":