| OLD | NEW |
| 1 #!/usr/bin/python2 | 1 #!/usr/bin/python2 |
| 2 # | 2 # |
| 3 # Copyright 2016 The Chromium Authors. All rights reserved. | 3 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Archive corpus file into zip and generate .d depfile. | 7 """Archive corpus file into zip and generate .d depfile. |
| 8 | 8 |
| 9 Invoked by GN from fuzzer_test.gni. | 9 Invoked by GN from fuzzer_test.gni. |
| 10 """ | 10 """ |
| 11 | 11 |
| 12 from __future__ import print_function | 12 from __future__ import print_function |
| 13 import argparse | 13 import argparse |
| 14 import os | 14 import os |
| 15 import sys | 15 import sys |
| 16 import warnings | 16 import warnings |
| 17 import zipfile | 17 import zipfile |
| 18 | 18 |
| 19 | 19 |
| 20 def main(): | 20 def main(): |
| 21 parser = argparse.ArgumentParser(description="Generate fuzzer config.") | 21 parser = argparse.ArgumentParser(description="Generate fuzzer config.") |
| 22 parser.add_argument('--corpus', required=True) | 22 parser.add_argument('corpus_directories', metavar='corpus_dir', type=str, |
| 23 parser.add_argument('--output', required=True) | 23 nargs='+') |
| 24 parser.add_argument('--output', metavar='output_archive_name.zip', |
| 25 required=True) |
| 24 args = parser.parse_args() | 26 args = parser.parse_args() |
| 25 | 27 |
| 26 corpus_files = [] | 28 corpus_files = [] |
| 27 | 29 |
| 28 for (dirpath, _, filenames) in os.walk(args.corpus): | 30 for directory in args.corpus_directories: |
| 29 for filename in filenames: | 31 for (dirpath, _, filenames) in os.walk(directory): |
| 30 full_filename = os.path.join(dirpath, filename) | 32 for filename in filenames: |
| 31 corpus_files.append(full_filename) | 33 full_filename = os.path.join(dirpath, filename) |
| 34 corpus_files.append(full_filename) |
| 32 | 35 |
| 33 with zipfile.ZipFile(args.output, 'w') as z: | 36 with zipfile.ZipFile(args.output, 'w') as z: |
| 34 # Turn warnings into errors to interrupt the build: crbug.com/653920. | 37 # Turn warnings into errors to interrupt the build: crbug.com/653920. |
| 35 with warnings.catch_warnings(): | 38 with warnings.catch_warnings(): |
| 36 warnings.simplefilter("error") | 39 warnings.simplefilter("error") |
| 37 for i, corpus_file in enumerate(corpus_files): | 40 for i, corpus_file in enumerate(corpus_files): |
| 38 # To avoid duplication of filenames inside the archive, use numbers. | 41 # To avoid duplication of filenames inside the archive, use numbers. |
| 39 arcname = '%016d' % i | 42 arcname = '%016d' % i |
| 40 z.write(corpus_file, arcname) | 43 z.write(corpus_file, arcname) |
| 41 | 44 |
| 42 | 45 |
| 43 if __name__ == '__main__': | 46 if __name__ == '__main__': |
| 44 main() | 47 main() |
| OLD | NEW |