OLD | NEW |
1 #!/usr/bin/python2 | 1 #!/usr/bin/python2 |
2 # | 2 # |
3 # Copyright (c) 2015 The Chromium Authors. All rights reserved. | 3 # Copyright (c) 2015 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 """Generate or update an existing config (.options file) for libfuzzer test. | 7 """Generate or update an existing config (.options file) for libfuzzer test. |
8 | 8 |
9 Invoked by GN from fuzzer_test.gni. | 9 Invoked by GN from fuzzer_test.gni. |
10 """ | 10 """ |
11 | 11 |
12 import argparse | 12 import argparse |
13 import os | 13 import os |
14 import sys | 14 import sys |
15 | 15 |
16 | 16 |
17 OPTIONS_FILE_TEMPLATE = '''# This is automatically generated fuzzer config. | 17 CONFIG_HEADER = '''# This is an automatically generated config for libFuzzer. |
18 [libfuzzer] | 18 [libfuzzer] |
19 dict = %(dict)s | |
20 ''' | 19 ''' |
21 | 20 |
22 def main(): | 21 def main(): |
23 parser = argparse.ArgumentParser(description="Generate fuzzer config.") | 22 parser = argparse.ArgumentParser(description="Generate fuzzer config.") |
24 parser.add_argument('--config', required=True) | 23 parser.add_argument('--config', required=True) |
25 parser.add_argument('--dict', required=True) | 24 parser.add_argument('--dict') |
26 parser.add_argument('--libfuzzer_options', required=False) | 25 parser.add_argument('--libfuzzer_options', nargs='+', default=[]) |
27 args = parser.parse_args() | 26 args = parser.parse_args() |
28 | 27 |
29 config_path = args.config | 28 # Script shouldn't be invoked without both arguments, but just in case. |
30 # Dict will be copied into build directory, use only its basename for config. | 29 if not args.dict and not args.libfuzzer_options: |
31 dict_name = os.path.basename(args.dict) | |
32 | |
33 if not args.libfuzzer_options: | |
34 # Generate .options file with initialized 'dict' option. | |
35 with open(config_path, 'w') as options_file: | |
36 options_file.write(OPTIONS_FILE_TEMPLATE % {'dict': dict_name}) | |
37 return | 30 return |
38 | 31 |
39 # Append 'dict' option to an existing .options file. | 32 config_path = args.config |
40 initial_config = open(args.libfuzzer_options).read() | 33 # Generate .options file. |
41 with open(config_path, 'w') as options_file: | 34 with open(config_path, 'w') as options_file: |
42 options_file.write(initial_config) | 35 options_file.write(CONFIG_HEADER) |
43 options_file.write('\ndict = %s\n' % dict_name) | |
44 | 36 |
| 37 # Dict will be copied into build directory, need only basename for config. |
| 38 if args.dict: |
| 39 options_file.write('dict = %s\n' % os.path.basename(args.dict)) |
| 40 |
| 41 for option in args.libfuzzer_options: |
| 42 options_file.write(option) |
| 43 options_file.write('\n') |
45 | 44 |
46 if __name__ == '__main__': | 45 if __name__ == '__main__': |
47 main() | 46 main() |
OLD | NEW |