OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/python2 |
| 2 # |
| 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 |
| 5 # found in the LICENSE file. |
| 6 |
| 7 """Generate or update an existing config (.options file) for libfuzzer test. |
| 8 |
| 9 Invoked by GN from fuzzer_test.gni. |
| 10 """ |
| 11 |
| 12 import argparse |
| 13 import os |
| 14 import sys |
| 15 |
| 16 |
| 17 OPTIONS_FILE_TEMPLATE = '''# This is automatically generated fuzzer config. |
| 18 [libfuzzer] |
| 19 dict = %(dict)s |
| 20 ''' |
| 21 |
| 22 def main(): |
| 23 parser = argparse.ArgumentParser(description="Generate fuzzer config.") |
| 24 parser.add_argument('--config', required=True) |
| 25 parser.add_argument('--dict', required=True) |
| 26 parser.add_argument('--libfuzzer_options', required=False) |
| 27 args = parser.parse_args() |
| 28 |
| 29 config_path = args.config |
| 30 # Dict will be copied into build directory, use only its basename for config. |
| 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 |
| 38 |
| 39 # Append 'dict' option to an existing .options file. |
| 40 initial_config = open(args.libfuzzer_options).read() |
| 41 with open(config_path, 'w') as options_file: |
| 42 options_file.write(initial_config) |
| 43 options_file.write('\ndict = %s\n' % dict_name) |
| 44 |
| 45 |
| 46 if __name__ == '__main__': |
| 47 main() |
OLD | NEW |