buildman: Convert camel case in bsettings.py
[platform/kernel/u-boot.git] / tools / buildman / main.py
1 #!/usr/bin/env python3
2 # SPDX-License-Identifier: GPL-2.0+
3 #
4 # Copyright (c) 2012 The Chromium OS Authors.
5 #
6
7 """See README for more information"""
8
9 try:
10     from importlib.resources import files
11 except ImportError:
12     # for Python 3.6
13     import importlib_resources
14 import os
15 import sys
16
17 # Bring in the patman libraries
18 # pylint: disable=C0413
19 our_path = os.path.dirname(os.path.realpath(__file__))
20 sys.path.insert(1, os.path.join(our_path, '..'))
21
22 # Our modules
23 from buildman import bsettings
24 from buildman import cmdline
25 from buildman import control
26 from u_boot_pylib import test_util
27 from u_boot_pylib import tools
28
29 def run_tests(skip_net_tests, debug, verbose, args):
30     """Run the buildman tests
31
32     Args:
33         skip_net_tests (bool): True to skip tests which need the network
34         debug (bool): True to run in debugging mode (full traceback)
35         verbosity (int): Verbosity level to use (0-4)
36         args (list of str): List of tests to run, empty to run all
37     """
38     # These imports are here since tests are not available when buildman is
39     # installed as a Python module
40     # pylint: disable=C0415
41     from buildman import func_test
42     from buildman import test
43
44     test_name = args.terms and args.terms[0] or None
45     if skip_net_tests:
46         test.use_network = False
47
48     # Run the entry tests first ,since these need to be the first to import the
49     # 'entry' module.
50     result = test_util.run_test_suites(
51         'buildman', debug, verbose, False, None, test_name, [],
52         [test.TestBuild, func_test.TestFunctional,
53          'buildman.toolchain', 'patman.gitutil'])
54
55     return (0 if result.wasSuccessful() else 1)
56
57 def run_buildman():
58     """Run bulidman
59
60     This is the main program. It collects arguments and runs either the tests or
61     the control module.
62     """
63     args = cmdline.parse_args()
64
65     if not args.debug:
66         sys.tracebacklimit = 0
67
68     # Run our meagre tests
69     if cmdline.HAS_TESTS and args.test:
70         return run_tests(args.skip_net_tests, args.debug, args.verbose, args)
71
72     elif args.full_help:
73         tools.print_full_help(str(files('buildman').joinpath('README.rst')))
74
75     # Build selected commits for selected boards
76     else:
77         bsettings.setup(args.config_file)
78         ret_code = control.do_buildman(args)
79         return ret_code
80
81
82 if __name__ == "__main__":
83     sys.exit(run_buildman())