1#
2# Copyright (C) 2017 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16"""Updates .bp, .mk, .xml files under test/vts-testcase/fuzz.
17
18Among files affected are:
19Build rules:
201. test/vts-testcase/fuzz/func_fuzzerAndroid.bp
212. files matching: test/vts-testcase/fuzz/func_fuzzer/Android.bp
223. files matching: test/vts-testcase/fuzz/func_fuzzer/<hal_name>/<hal_version>/Android.bp
23
24Config Files:
251. files matching: test/vts-testcase/fuzz/<hal_name>/<hal_version>/func_fuzzer/Android.mk
262. files matching: test/vts-testcase/fuzz/<hal_name>/<hal_version>/func_fuzzer/AndroidTest.xml
273. files matching: test/vts-testcase/fuzz/<hal_name>/<hal_version>/iface_fuzzer/Android.mk
284. files matching: test/vts-testcase/fuzz/<hal_name>/<hal_version>/iface_fuzzer/AndroidTest.xml
29
30
31Usage:
32    python test/vts-testcase/fuzz/update_makefiles.py
33"""
34
35import argparse
36import os
37import sys
38
39from build.func_fuzzer_build_rule_gen import FuncFuzzerBuildRuleGen
40from config.config_gen import ConfigGen
41
42if __name__ == '__main__':
43    parser = argparse.ArgumentParser()
44    parser.add_argument(
45        '--build',
46        dest='build',
47        action='store_true',
48        required=False,
49        help='Whether to create update build rules.')
50
51    parser.add_argument(
52        '--config',
53        dest='config',
54        action='store_true',
55        required=False,
56        help='Whether to create update config files.')
57    args = parser.parse_args()
58
59    if not args.build and not args.config:
60        print 'Updating build rules and config files.'
61        args.build = True
62        args.config = True
63
64    if args.build:
65        print 'Updating build rules.'
66        warning_header = (
67            '// This file was auto-generated by test/vts-testcase/fuzz/script/update_makefiles.py.\n'
68            '// Do not edit manually.\n')
69        build_rule_gen = FuncFuzzerBuildRuleGen(warning_header)
70        build_rule_gen.UpdateBuildRule()
71
72    if args.config:
73        print 'Updating config files.'
74        config_gen = ConfigGen()
75        config_gen.UpdateFuzzerConfigs()
76