Index: testing/libfuzzer/gen_fuzzer_config.py |
diff --git a/testing/libfuzzer/gen_fuzzer_config.py b/testing/libfuzzer/gen_fuzzer_config.py |
new file mode 100755 |
index 0000000000000000000000000000000000000000..5628a30f7b5d4ce2b977c81a05f209018ed9c97e |
--- /dev/null |
+++ b/testing/libfuzzer/gen_fuzzer_config.py |
@@ -0,0 +1,47 @@ |
+#!/usr/bin/python2 |
+# |
+# Copyright (c) 2015 The Chromium Authors. All rights reserved. |
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+"""Generate or update an existing config (.options file) for libfuzzer test. |
+ |
+Invoked by GN from fuzzer_test.gni. |
+""" |
+ |
+import argparse |
+import os |
+import sys |
+ |
+ |
+OPTIONS_FILE_TEMPLATE = '''# This is automatically generated fuzzer config. |
+[libfuzzer] |
+dict = %(dict)s |
+''' |
+ |
+def main(): |
+ parser = argparse.ArgumentParser(description="Generate fuzzer config.") |
+ parser.add_argument('--config', required=True) |
+ parser.add_argument('--dict', required=True) |
+ parser.add_argument('--libfuzzer_options', required=False) |
+ args = parser.parse_args() |
+ |
+ config_path = args.config |
+ # Dict will be copied into build directory, use only its basename for config. |
+ dict_name = os.path.basename(args.dict) |
+ |
+ if not args.libfuzzer_options: |
+ # Generate .options file with initialized 'dict' option. |
+ with open(config_path, 'w') as options_file: |
+ options_file.write(OPTIONS_FILE_TEMPLATE % {'dict': dict_name}) |
+ return |
+ |
+ # Append 'dict' option to an existing .options file. |
+ initial_config = open(args.libfuzzer_options).read() |
+ with open(config_path, 'w') as options_file: |
+ options_file.write(initial_config) |
+ options_file.write('\ndict = %s\n' % dict_name) |
+ |
+ |
+if __name__ == '__main__': |
+ main() |