blob: a3fd29fa36507d63ee57c6e7bcf42e2aef258225 [file] [log] [blame]
aizatsky198e3022016-03-08 21:33:461#!/usr/bin/python2
2#
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
5# found in the LICENSE file.
6
7"""Archive corpus file into zip and generate .d depfile.
8
9Invoked by GN from fuzzer_test.gni.
10"""
11
12from __future__ import print_function
13import argparse
14import os
15import sys
mmoroz0aa347932016-12-02 10:07:5916import warnings
aizatsky198e3022016-03-08 21:33:4617import zipfile
18
19
20def main():
21 parser = argparse.ArgumentParser(description="Generate fuzzer config.")
mmoroz902ef432017-02-07 17:03:3722 parser.add_argument('corpus_directories', metavar='corpus_dir', type=str,
23 nargs='+')
24 parser.add_argument('--output', metavar='output_archive_name.zip',
25 required=True)
aizatsky198e3022016-03-08 21:33:4626 args = parser.parse_args()
27
28 corpus_files = []
mmoroz146a2e82016-04-28 10:32:3529
mmoroz902ef432017-02-07 17:03:3730 for directory in args.corpus_directories:
Max Morozebe225802017-08-08 06:52:3331 if not os.path.exists(directory):
32 raise Exception('The given seed_corpus directory (%s) does not exist.' %
33 directory)
mmoroz902ef432017-02-07 17:03:3734 for (dirpath, _, filenames) in os.walk(directory):
35 for filename in filenames:
36 full_filename = os.path.join(dirpath, filename)
37 corpus_files.append(full_filename)
aizatsky198e3022016-03-08 21:33:4638
39 with zipfile.ZipFile(args.output, 'w') as z:
mmoroz0aa347932016-12-02 10:07:5940 # Turn warnings into errors to interrupt the build: crbug.com/653920.
41 with warnings.catch_warnings():
42 warnings.simplefilter("error")
43 for i, corpus_file in enumerate(corpus_files):
44 # To avoid duplication of filenames inside the archive, use numbers.
45 arcname = '%016d' % i
46 z.write(corpus_file, arcname)
aizatsky198e3022016-03-08 21:33:4647
48
49if __name__ == '__main__':
50 main()