mmoroz | 344a75ae | 2016-03-02 16:57:17 | [diff] [blame] | 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 | |
mmoroz | 062a4a6 | 2016-04-12 09:02:33 | [diff] [blame] | 17 | CONFIG_HEADER = '''# This is an automatically generated config for libFuzzer. |
mmoroz | 344a75ae | 2016-03-02 16:57:17 | [diff] [blame] | 18 | [libfuzzer] |
mmoroz | 344a75ae | 2016-03-02 16:57:17 | [diff] [blame] | 19 | ''' |
| 20 | |
| 21 | def main(): |
| 22 | parser = argparse.ArgumentParser(description="Generate fuzzer config.") |
| 23 | parser.add_argument('--config', required=True) |
mmoroz | 062a4a6 | 2016-04-12 09:02:33 | [diff] [blame] | 24 | parser.add_argument('--dict') |
| 25 | parser.add_argument('--libfuzzer_options', nargs='+', default=[]) |
mmoroz | 344a75ae | 2016-03-02 16:57:17 | [diff] [blame] | 26 | args = parser.parse_args() |
| 27 | |
mmoroz | 062a4a6 | 2016-04-12 09:02:33 | [diff] [blame] | 28 | # Script shouldn't be invoked without both arguments, but just in case. |
| 29 | if not args.dict and not args.libfuzzer_options: |
mmoroz | 344a75ae | 2016-03-02 16:57:17 | [diff] [blame] | 30 | return |
| 31 | |
mmoroz | 062a4a6 | 2016-04-12 09:02:33 | [diff] [blame] | 32 | config_path = args.config |
| 33 | # Generate .options file. |
mmoroz | 344a75ae | 2016-03-02 16:57:17 | [diff] [blame] | 34 | with open(config_path, 'w') as options_file: |
mmoroz | 062a4a6 | 2016-04-12 09:02:33 | [diff] [blame] | 35 | options_file.write(CONFIG_HEADER) |
mmoroz | 344a75ae | 2016-03-02 16:57:17 | [diff] [blame] | 36 | |
mmoroz | 062a4a6 | 2016-04-12 09:02:33 | [diff] [blame] | 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') |
mmoroz | 344a75ae | 2016-03-02 16:57:17 | [diff] [blame] | 44 | |
| 45 | if __name__ == '__main__': |
| 46 | main() |