blob: 310b7b934429fd4c3b285118bd7316c1c68280cb [file] [log] [blame]
mmoroz344a75ae2016-03-02 16:57:171#!/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
9Invoked by GN from fuzzer_test.gni.
10"""
11
12import argparse
13import os
14import sys
15
16
mmoroz062a4a62016-04-12 09:02:3317CONFIG_HEADER = '''# This is an automatically generated config for libFuzzer.
mmoroz344a75ae2016-03-02 16:57:1718[libfuzzer]
mmoroz344a75ae2016-03-02 16:57:1719'''
20
21def main():
22 parser = argparse.ArgumentParser(description="Generate fuzzer config.")
23 parser.add_argument('--config', required=True)
mmoroz062a4a62016-04-12 09:02:3324 parser.add_argument('--dict')
25 parser.add_argument('--libfuzzer_options', nargs='+', default=[])
mmoroz344a75ae2016-03-02 16:57:1726 args = parser.parse_args()
27
mmoroz062a4a62016-04-12 09:02:3328 # Script shouldn't be invoked without both arguments, but just in case.
29 if not args.dict and not args.libfuzzer_options:
mmoroz344a75ae2016-03-02 16:57:1730 return
31
mmoroz062a4a62016-04-12 09:02:3332 config_path = args.config
33 # Generate .options file.
mmoroz344a75ae2016-03-02 16:57:1734 with open(config_path, 'w') as options_file:
mmoroz062a4a62016-04-12 09:02:3335 options_file.write(CONFIG_HEADER)
mmoroz344a75ae2016-03-02 16:57:1736
mmoroz062a4a62016-04-12 09:02:3337 # 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')
mmoroz344a75ae2016-03-02 16:57:1744
45if __name__ == '__main__':
46 main()