main.py 3.0 KB

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