1# SPDX-License-Identifier: GPL-2.0+ 2# Copyright (c) 2014 Google, Inc 3# 4 5"""Handles parsing of buildman arguments 6 7This creates the argument parser and uses it to parse the arguments passed in 8""" 9 10import argparse 11import os 12import pathlib 13 14BUILDMAN_DIR = pathlib.Path(__file__).parent 15HAS_TESTS = os.path.exists(BUILDMAN_DIR / "test.py") 16 17def add_upto_m(parser): 18 """Add arguments up to 'M' 19 20 Args: 21 parser (ArgumentParser): Parse to add to 22 23 This is split out to avoid having too many statements in one function 24 """ 25 # Available JqzZ 26 parser.add_argument('-a', '--adjust-cfg', type=str, action='append', 27 help='Adjust the Kconfig settings in .config before building') 28 parser.add_argument('-A', '--print-prefix', action='store_true', 29 help='Print the tool-chain prefix for a board (CROSS_COMPILE=)') 30 parser.add_argument('-b', '--branch', type=str, 31 help='Branch name to build, or range of commits to build') 32 parser.add_argument('-B', '--bloat', dest='show_bloat', 33 action='store_true', default=False, 34 help='Show changes in function code size for each board') 35 parser.add_argument('--boards', type=str, action='append', 36 help='List of board names to build separated by comma') 37 parser.add_argument('-c', '--count', dest='count', type=int, 38 default=-1, help='Run build on the top n commits') 39 parser.add_argument('-C', '--force-reconfig', dest='force_reconfig', 40 action='store_true', default=False, 41 help='Reconfigure for every commit (disable incremental build)') 42 parser.add_argument('--config-only', action='store_true', 43 default=False, 44 help="Don't build, just configure each commit") 45 parser.add_argument('-d', '--detail', dest='show_detail', 46 action='store_true', default=False, 47 help='Show detailed size delta for each board in the -S summary') 48 parser.add_argument('-D', '--debug', action='store_true', 49 help='Enabling debugging (provides a full traceback on error)') 50 parser.add_argument('--dtc-skip', action='store_true', default=False, 51 help='Skip building of dtc and use the system version') 52 parser.add_argument('-e', '--show_errors', action='store_true', 53 default=False, help='Show errors and warnings') 54 parser.add_argument('-E', '--warnings-as-errors', action='store_true', 55 default=False, help='Treat all compiler warnings as errors') 56 parser.add_argument('-f', '--force-build', dest='force_build', 57 action='store_true', default=False, 58 help='Force build of boards even if already built') 59 parser.add_argument('-F', '--force-build-failures', dest='force_build_failures', 60 action='store_true', default=False, 61 help='Force build of previously-failed build') 62 parser.add_argument('--fetch-arch', type=str, 63 help="Fetch a toolchain for architecture FETCH_ARCH ('list' to list)." 64 ' You can also fetch several toolchains separate by comma, or' 65 " 'all' to download all") 66 parser.add_argument( 67 '--full-check', action='store_true', 68 help='Check maintainer entries and TARGET configs') 69 parser.add_argument('-g', '--git', type=str, 70 help='Git repo containing branch to build', default='.') 71 parser.add_argument('-G', '--config-file', type=str, 72 help='Path to buildman config file', default='') 73 parser.add_argument('-H', '--full-help', action='store_true', dest='full_help', 74 default=False, help='Display the README file') 75 parser.add_argument('-i', '--in-tree', dest='in_tree', 76 action='store_true', default=False, 77 help='Build in the source tree instead of a separate directory') 78 parser.add_argument('-I', '--ide', action='store_true', default=False, 79 help='Create build output that can be parsed by an IDE') 80 parser.add_argument('-j', '--jobs', dest='jobs', type=int, 81 default=None, help='Number of jobs to run at once (passed to make)') 82 parser.add_argument('-k', '--keep-outputs', action='store_true', 83 default=False, help='Keep all build output files (e.g. binaries)') 84 parser.add_argument('-K', '--show-config', action='store_true', 85 default=False, 86 help='Show configuration changes in summary (both board config files and Kconfig)') 87 parser.add_argument('--preserve-config-y', action='store_true', 88 default=False, help="Don't convert y to 1 in configs") 89 parser.add_argument('-l', '--list-error-boards', action='store_true', 90 default=False, help='Show a list of boards next to each error/warning') 91 parser.add_argument('-L', '--no-lto', action='store_true', 92 default=False, help='Disable Link-time Optimisation (LTO) for builds') 93 parser.add_argument('--list-tool-chains', action='store_true', default=False, 94 help='List available tool chains (use -v to see probing detail)') 95 parser.add_argument('-m', '--mrproper', action='store_true', 96 default=False, help="Run 'make mrproper' before reconfiguring") 97 parser.add_argument('--fallback-mrproper', action='store_true', 98 default=False, help="Run 'make mrproper' and retry on build failure") 99 parser.add_argument( 100 '-M', '--allow-missing', action='store_true', default=False, 101 help='Tell binman to allow missing blobs and generate fake ones as needed') 102 parser.add_argument( 103 '--maintainer-check', action='store_true', 104 help='Check that maintainer entries exist for each board') 105 parser.add_argument( 106 '--no-allow-missing', action='store_true', default=False, 107 help='Disable telling binman to allow missing blobs') 108 parser.add_argument('-n', '--dry-run', action='store_true', dest='dry_run', 109 default=False, help="Do a dry run (describe actions, but do nothing)") 110 parser.add_argument('-N', '--no-subdirs', action='store_true', dest='no_subdirs', 111 default=False, 112 help="Don't create subdirectories when building current source for a single board") 113 114 115def add_after_m(parser): 116 """Add arguments after 'M' 117 118 Args: 119 parser (ArgumentParser): Parse to add to 120 121 This is split out to avoid having too many statements in one function 122 """ 123 parser.add_argument('-o', '--output-dir', type=str, dest='output_dir', 124 help='Directory where all builds happen and buildman has its workspace (default is ../)') 125 parser.add_argument('-O', '--override-toolchain', type=str, 126 help="Override host toochain to use for sandbox (e.g. 'clang-7')") 127 parser.add_argument('-Q', '--quick', action='store_true', 128 default=False, help='Do a rough build, with limited warning resolution') 129 parser.add_argument('-p', '--full-path', action='store_true', 130 default=False, help="Use full toolchain path in CROSS_COMPILE") 131 parser.add_argument('-P', '--per-board-out-dir', action='store_true', 132 default=False, help="Use an O= (output) directory per board rather than per thread") 133 parser.add_argument('--print-arch', action='store_true', 134 default=False, help="Print the architecture for a board (ARCH=)") 135 parser.add_argument('--process-limit', type=int, 136 default=0, help='Limit to number of buildmans running at once') 137 parser.add_argument('-r', '--reproducible-builds', action='store_true', 138 help='Set SOURCE_DATE_EPOCH=0 to suuport a reproducible build') 139 parser.add_argument('-R', '--regen-board-list', type=str, 140 help='Force regeneration of the list of boards, like the old boards.cfg file') 141 parser.add_argument('-s', '--summary', action='store_true', 142 default=False, help='Show a build summary') 143 parser.add_argument('-S', '--show-sizes', action='store_true', 144 default=False, help='Show image size variation in summary') 145 parser.add_argument('--step', type=int, 146 default=1, help='Only build every n commits (0=just first and last)') 147 if HAS_TESTS: 148 parser.add_argument('--skip-net-tests', action='store_true', default=False, 149 help='Skip tests which need the network') 150 parser.add_argument('-t', '--test', action='store_true', dest='test', 151 default=False, help='run tests') 152 parser.add_argument('--coverage', action='store_true', 153 help='Calculated test coverage') 154 parser.add_argument('-T', '--threads', type=int, 155 default=None, 156 help='Number of builder threads to use (0=single-thread)') 157 parser.add_argument('--target', type=str, 158 default=None, help='Build target to use') 159 parser.add_argument('-u', '--show_unknown', action='store_true', 160 default=False, help='Show boards with unknown build result') 161 parser.add_argument('-U', '--show-environment', action='store_true', 162 default=False, help='Show environment changes in summary') 163 parser.add_argument('-v', '--verbose', action='store_true', 164 default=False, help='Show build results while the build progresses') 165 parser.add_argument('-V', '--verbose-build', action='store_true', 166 default=False, help='Run make with V=1, logging all output') 167 parser.add_argument('-w', '--work-in-output', action='store_true', 168 default=False, help='Use the output directory as the work directory') 169 parser.add_argument('-W', '--ignore-warnings', action='store_true', 170 default=False, help='Return success even if there are warnings') 171 parser.add_argument('-x', '--exclude', dest='exclude', 172 type=str, action='append', 173 help='Specify a list of boards to exclude, separated by comma') 174 parser.add_argument('-y', '--filter-dtb-warnings', action='store_true', 175 default=False, 176 help='Filter out device-tree-compiler warnings from output') 177 parser.add_argument('-Y', '--filter-migration-warnings', action='store_true', 178 default=False, 179 help='Filter out migration warnings from output') 180 181 182def parse_args(): 183 """Parse command line arguments from sys.argv[] 184 185 Returns: 186 tuple containing: 187 options: command line options 188 args: command lin arguments 189 """ 190 epilog = """ [list of target/arch/cpu/board/vendor/soc to build] 191 192 Build U-Boot for all commits in a branch. Use -n to do a dry run""" 193 194 parser = argparse.ArgumentParser(epilog=epilog) 195 add_upto_m(parser) 196 add_after_m(parser) 197 parser.add_argument('terms', type=str, nargs='*', 198 help='Board / SoC names to build') 199 200 return parser.parse_args() 201