dawn-cmake/src/tint/fuzzers/generate_wgsl_corpus.py
Fumitoshi Ukai a5f5f5a1aa use stamp file for tint_generate_wgsl_corpus
using directory for actions output causes issue like
crbug.com/1315457

 ninja explain: output obj/third_party/dawn/src/tint/fuzzers/tint_generate_wgsl_corpus.stamp older than most recent input gen/third_party/dawn/src/tint/fuzzers/fuzzer_corpus_wgsl (1649712735 vs
1649712999)

Use stamp file instead of directory.

Bug: chromium:1315457, chromium:1314527
Change-Id: Ifdf0493e23dbab000513e8f2c0ae4aa8cd76444f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/86482
Auto-Submit: Fumitoshi Ukai <ukai@google.com>
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
2022-04-12 16:18:01 +00:00

66 lines
2.2 KiB
Python

#!/usr/bin/env python3
# Copyright 2021 The Tint Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Collect all .wgsl files under a given directory and copy them to a given
# corpus directory, flattening their file names by replacing path
# separators with underscores. If the output directory already exists, it
# will be deleted and re-created. Files ending with ".expected.spvasm" are
# skipped.
#
# The intended use of this script is to generate a corpus of WGSL shaders
# for fuzzing.
#
# Usage:
# generate_wgsl_corpus.py <input_dir> <corpus_dir>
import optparse
import os
import pathlib
import shutil
import sys
def list_wgsl_files(root_search_dir):
for root, folders, files in os.walk(root_search_dir):
for filename in folders + files:
if pathlib.Path(filename).suffix == '.wgsl':
yield os.path.join(root, filename)
def main():
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)
for in_file in list_wgsl_files(input_dir):
if in_file.endswith(".expected.wgsl"):
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__":
sys.exit(main())