Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 1 | """This is the main tool for handling llvm builds, bisects etc.""" |
| 2 | |
| 3 | import os |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 4 | from sys import argv |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 5 | from sys import exit |
| 6 | |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 7 | from modules.llvm import LLVMBuildConfig |
Diana Picus | 95226d4 | 2017-11-01 13:16:54 +0100 | [diff] [blame] | 8 | from modules.llvm import LLVMSubproject |
| 9 | from modules.llvm import LLVMSourceConfig |
Diana Picus | b368cb6 | 2018-01-23 16:41:59 +0100 | [diff] [blame] | 10 | from modules.llvm import run_test_suite |
Diana Picus | f73abbf | 2018-01-26 07:06:20 +0100 | [diff] [blame] | 11 | from modules.llvm import setup_test_suite |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 12 | from modules.utils import CommandPrinter |
| 13 | from modules.utils import CommandRunner |
Diana Picus | 5ad5542 | 2017-12-14 17:57:10 +0100 | [diff] [blame] | 14 | from modules.utils import get_remote_branch |
| 15 | from modules.utils import push_branch |
Diana Picus | 95226d4 | 2017-11-01 13:16:54 +0100 | [diff] [blame] | 16 | |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 17 | from linaropy.cd import cd |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 18 | from linaropy.git.clone import Clone |
| 19 | from linaropy.proj import Proj |
| 20 | |
| 21 | from argparse import Action, ArgumentParser, RawTextHelpFormatter |
Diana Picus | efc7bda | 2017-06-09 19:14:08 +0200 | [diff] [blame] | 22 | from functools import partial |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 23 | |
| 24 | |
| 25 | def die(message, config_to_dump=None): |
| 26 | """Print an error message and exit.""" |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 27 | print(message) |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 28 | |
| 29 | if config_to_dump is not None: |
| 30 | dump_config(config_to_dump) |
| 31 | |
| 32 | exit(1) |
| 33 | |
Diana Picus | 3d1a301 | 2017-03-14 17:38:32 +0100 | [diff] [blame] | 34 | |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 35 | def dump_config(config): |
| 36 | """Dump the list of projects that are enabled in the given config.""" |
| 37 | |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 38 | print("Projects linked:") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 39 | enabled = config.get_enabled_subprojects() |
| 40 | if not enabled: |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 41 | print("none") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 42 | else: |
| 43 | for subproj in sorted(enabled): |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 44 | print(" + {}".format(subproj)) |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 45 | |
| 46 | |
| 47 | def projects(args): |
| 48 | """Add/remove subprojects based on the values in args.""" |
| 49 | |
| 50 | proj = Proj() |
Diana Picus | 3d1a301 | 2017-03-14 17:38:32 +0100 | [diff] [blame] | 51 | |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 52 | llvm_worktree_root = args.sources |
Diana Picus | 81089db | 2017-05-05 22:26:49 +0200 | [diff] [blame] | 53 | llvm_repos_root = args.repos |
Diana Picus | b1dbcba | 2018-02-07 01:33:17 +0100 | [diff] [blame] | 54 | config = LLVMSourceConfig(proj, llvm_worktree_root, dry=False) |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 55 | |
| 56 | if not args.add and not args.remove: |
| 57 | # Nothing to change, just print the current configuration |
| 58 | dump_config(config) |
| 59 | exit(0) |
| 60 | |
| 61 | to_add = {} |
| 62 | if args.add: |
| 63 | for subproj in args.add: |
| 64 | repo = Clone(proj, os.path.join(llvm_repos_root, subproj)) |
| 65 | to_add[subproj] = repo |
| 66 | |
| 67 | try: |
| 68 | config.update(to_add, args.remove) |
| 69 | except (EnvironmentError, ValueError) as exc: |
| 70 | die("Failed to update subprojects because:\n{}".format(str(exc))) |
| 71 | |
| 72 | dump_config(config) |
| 73 | |
Diana Picus | efc7bda | 2017-06-09 19:14:08 +0200 | [diff] [blame] | 74 | |
Diana Picus | 95226d4 | 2017-11-01 13:16:54 +0100 | [diff] [blame] | 75 | def push_current_branch(args): |
Diana Picus | efc7bda | 2017-06-09 19:14:08 +0200 | [diff] [blame] | 76 | """Push current branch to origin.""" |
| 77 | |
| 78 | proj = Proj() |
| 79 | |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 80 | llvm_worktree_root = args.sources |
Diana Picus | b1dbcba | 2018-02-07 01:33:17 +0100 | [diff] [blame] | 81 | config = LLVMSourceConfig(proj, llvm_worktree_root, dry=False) |
Diana Picus | efc7bda | 2017-06-09 19:14:08 +0200 | [diff] [blame] | 82 | |
Diana Picus | 95226d4 | 2017-11-01 13:16:54 +0100 | [diff] [blame] | 83 | llvm_worktree = Clone(proj, llvm_worktree_root) |
| 84 | local_branch = llvm_worktree.getbranch() |
Diana Picus | efc7bda | 2017-06-09 19:14:08 +0200 | [diff] [blame] | 85 | |
| 86 | try: |
Diana Picus | 95226d4 | 2017-11-01 13:16:54 +0100 | [diff] [blame] | 87 | remote_branch = get_remote_branch(llvm_worktree, local_branch) |
| 88 | config.for_each_enabled(partial(push_branch, proj, local_branch, |
| 89 | remote_branch)) |
| 90 | print("Pushed to {}".format(remote_branch)) |
| 91 | except (EnvironmentError, RuntimeError) as exc: |
Diana Picus | efc7bda | 2017-06-09 19:14:08 +0200 | [diff] [blame] | 92 | die("Failed to push branch because: " + str(exc) + str(exc.__cause__)) |
| 93 | |
Diana Picus | 95226d4 | 2017-11-01 13:16:54 +0100 | [diff] [blame] | 94 | |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 95 | def configure_build(args): |
| 96 | """Configure a given build directory.""" |
| 97 | |
| 98 | proj = Proj() |
| 99 | |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 100 | llvm_worktree_root = args.sources |
Diana Picus | b1dbcba | 2018-02-07 01:33:17 +0100 | [diff] [blame] | 101 | sourceConfig = LLVMSourceConfig(proj, llvm_worktree_root, args.dry) |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 102 | |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 103 | if args.dry: |
| 104 | consumer = CommandPrinter() |
| 105 | else: |
| 106 | if not os.path.exists(args.build): |
| 107 | os.makedirs(args.build) |
| 108 | consumer = CommandRunner() |
| 109 | |
Diana Picus | 6b1935f | 2018-02-07 16:44:11 +0100 | [diff] [blame] | 110 | buildConfig = LLVMBuildConfig(sourceConfig, args.build, consumer) |
| 111 | |
| 112 | if args.defs: |
| 113 | args.defs = ["-D{}".format(v) for v in args.defs] |
| 114 | |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 115 | try: |
Diana Picus | 6b1935f | 2018-02-07 16:44:11 +0100 | [diff] [blame] | 116 | buildConfig.cmake(args.defs, args.generator) |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 117 | except RuntimeError as exc: |
| 118 | die("Failed to configure {} because:\n{}".format(args.build, str(exc))) |
| 119 | |
| 120 | |
Diana Picus | 37126b8 | 2018-01-19 16:14:26 +0100 | [diff] [blame] | 121 | def run_build(args): |
| 122 | """Run a build command in a given directory.""" |
| 123 | build_dir = args.build |
| 124 | |
| 125 | if args.dry: |
| 126 | consumer = CommandPrinter() |
| 127 | else: |
| 128 | consumer = CommandRunner() |
| 129 | |
| 130 | try: |
Diana Picus | 6b1935f | 2018-02-07 16:44:11 +0100 | [diff] [blame] | 131 | LLVMBuildConfig(None, args.build, consumer).build(args.flags) |
Diana Picus | 37126b8 | 2018-01-19 16:14:26 +0100 | [diff] [blame] | 132 | except RuntimeError as exc: |
| 133 | die("Failed to build {} because:\n{}".format(args.build, str(exc))) |
| 134 | |
| 135 | |
Diana Picus | f73abbf | 2018-01-26 07:06:20 +0100 | [diff] [blame] | 136 | def setup_the_test_suite(args): |
| 137 | """Setup a sandbox for the test-suite.""" |
| 138 | if args.dry: |
| 139 | consumer = CommandPrinter() |
| 140 | else: |
| 141 | consumer = CommandRunner() |
| 142 | |
| 143 | try: |
| 144 | setup_test_suite(consumer, args.sandbox, args.lnt) |
| 145 | except RuntimeError as exc: |
| 146 | die("Failed to setup the test-suite because:\n{}".format(str(exc))) |
| 147 | |
| 148 | |
Diana Picus | b368cb6 | 2018-01-23 16:41:59 +0100 | [diff] [blame] | 149 | def run_the_test_suite(args): |
| 150 | """Run the test-suite in a given sandbox.""" |
| 151 | if args.dry: |
| 152 | consumer = CommandPrinter() |
| 153 | else: |
| 154 | consumer = CommandRunner() |
| 155 | |
| 156 | compilers = ["--cc={}".format(args.cc)] |
| 157 | if args.cxx: |
| 158 | compilers.append("--cxx={}".format(args.cxx)) |
| 159 | |
| 160 | try: |
| 161 | run_test_suite(consumer, args.sandbox, args.testsuite, args.lit, |
| 162 | compilers + args.flags) |
| 163 | except RuntimeError as exc: |
| 164 | die("Failed to run the test-suite because:\n{}".format(str(exc))) |
| 165 | |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 166 | |
| 167 | def build_and_test(args): |
| 168 | """ |
| 169 | Build a set of LLVM subprojects, in one or two stages, with or without a |
| 170 | test-suite run. |
| 171 | """ |
| 172 | |
| 173 | proj = Proj() |
| 174 | |
| 175 | dryRun = args.dry |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame^] | 176 | llvmRepos = args.repos |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 177 | llvmWorktreeRoot = args.sources |
| 178 | |
| 179 | stage1BuildDir = args.stage1 |
| 180 | stage2BuildDir = args.stage2 |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame^] | 181 | |
| 182 | enableTestSuite = args.enableTestSuite |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 183 | sandboxDir = args.sandbox |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 184 | |
| 185 | if dryRun: |
| 186 | consumer = CommandPrinter() |
| 187 | else: |
| 188 | consumer = CommandRunner() |
| 189 | |
| 190 | try: |
| 191 | sourceConfig = LLVMSourceConfig(proj, llvmWorktreeRoot, args.dry) |
| 192 | |
| 193 | if not dryRun and not os.path.exists(stage1BuildDir): |
| 194 | os.makedirs(stage1BuildDir) |
| 195 | |
| 196 | buildConfig1 = LLVMBuildConfig(sourceConfig, stage1BuildDir, consumer) |
| 197 | buildConfig1.cmake([], "Ninja") |
| 198 | buildConfig1.build() |
| 199 | testedBuildDir = stage1BuildDir |
| 200 | |
| 201 | if stage2BuildDir is not None: |
| 202 | if not dryRun and not os.path.exists(stage2BuildDir): |
| 203 | os.makedirs(stage2BuildDir) |
| 204 | |
| 205 | buildConfig2 = LLVMBuildConfig(sourceConfig, stage2BuildDir, |
| 206 | consumer) |
| 207 | |
| 208 | # TODO: Make sure clang is actually built in this config (preferably |
| 209 | # before reaching this point) |
| 210 | buildConfig2.cmake( |
| 211 | [ |
| 212 | "-DCMAKE_C_COMPILER={}/bin/clang".format(stage1BuildDir), |
| 213 | "-DCMAKE_CXX_COMPILER={}/bin/clang++".format(stage1BuildDir)], |
| 214 | "Ninja") |
| 215 | buildConfig2.build() |
| 216 | testedBuildDir = stage2BuildDir |
| 217 | |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame^] | 218 | if enableTestSuite: |
| 219 | testSuiteDir = os.path.join(llvmRepos, "test-suite") |
| 220 | lntDir = os.path.join(llvmRepos, "lnt") |
| 221 | |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 222 | setup_test_suite(consumer, sandboxDir, lntDir) |
| 223 | |
| 224 | # TODO: Make sure clang is actually built in this config (preferably |
| 225 | # before reaching this point) |
| 226 | lit = os.path.join(testedBuildDir, "bin", "llvm-lit") |
| 227 | clang = os.path.join(testedBuildDir, "bin", "clang") |
| 228 | run_test_suite(consumer, sandboxDir, testSuiteDir, lit, |
| 229 | ["--cc={}".format(clang)]) |
| 230 | |
| 231 | except RuntimeError as exc: |
| 232 | die("Failed because:\n{}".format(str(exc))) |
| 233 | |
| 234 | |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 235 | ########################################################################## |
| 236 | # Command line parsing # |
| 237 | ########################################################################## |
| 238 | |
| 239 | # If we decide we want shorthands for the subprojects, we can append to this |
| 240 | # list |
Diana Picus | b430760 | 2017-04-05 19:48:39 +0200 | [diff] [blame] | 241 | valid_subprojects = list(LLVMSubproject.get_all_subprojects().keys()) |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 242 | |
| 243 | options = ArgumentParser(formatter_class=RawTextHelpFormatter) |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 244 | subcommands = options.add_subparsers(dest="subcommand") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 245 | |
| 246 | # Subcommand for adding / removing subprojects |
Diana Picus | 36317e8 | 2017-10-31 15:35:24 +0100 | [diff] [blame] | 247 | projs = subcommands.add_parser( |
| 248 | "projects", help="Add/remove LLVM subprojects.\n" |
| 249 | "Adding a subproject will create a worktree for it " |
| 250 | "somewhere in the LLVM source tree, on the same git " |
| 251 | "branch as LLVM itself.\n" |
| 252 | "Removing a subproject will remove the worktree, but " |
| 253 | "not the underlying git branch.") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 254 | projs.set_defaults(run_command=projects) |
| 255 | |
| 256 | # TODO: Overwriting previous values is not necessarily what users expect (so for |
| 257 | # instance --add S1 S2 --remove S3 --add S4 would lead to adding only S4). We |
| 258 | # can do better by using action='append', which would create a list (of lists? |
| 259 | # or of lists and scalars?) that we can flatten to obtain all the values passed |
| 260 | # by the user. |
| 261 | projs.add_argument( |
| 262 | '-a', '--add', |
| 263 | nargs='+', |
| 264 | choices=valid_subprojects, |
| 265 | metavar='subproject', |
Diana Picus | 36317e8 | 2017-10-31 15:35:24 +0100 | [diff] [blame] | 266 | help="Enable given subprojects. Valid values are:\n\t{}\n".format( |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 267 | "\n\t".join(valid_subprojects))) |
| 268 | projs.add_argument( |
| 269 | '-r', '--remove', |
| 270 | nargs='+', |
| 271 | choices=valid_subprojects, |
| 272 | metavar='subproject', |
Diana Picus | 36317e8 | 2017-10-31 15:35:24 +0100 | [diff] [blame] | 273 | help="Disable given subprojects.") |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 274 | projs.add_argument( |
| 275 | '--repos', |
| 276 | help="Path to the directory containing the repositories for all LLVM " |
| 277 | "subprojects.") |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 278 | projs.add_argument( |
| 279 | '--source-dir', |
| 280 | dest='sources', |
| 281 | required=True, |
| 282 | help="Path to the directory containing the LLVM worktree that we're adding " |
| 283 | "or removing subprojects from.") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 284 | |
Diana Picus | efc7bda | 2017-06-09 19:14:08 +0200 | [diff] [blame] | 285 | # Subcommand for pushing the current branch to origin |
| 286 | push = subcommands.add_parser( |
| 287 | "push", |
Diana Picus | 36317e8 | 2017-10-31 15:35:24 +0100 | [diff] [blame] | 288 | help="Push current branch to origin linaro-local/<user>/<branch>, " |
| 289 | "for all enabled subprojects.") |
Diana Picus | 95226d4 | 2017-11-01 13:16:54 +0100 | [diff] [blame] | 290 | push.set_defaults(run_command=push_current_branch) |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 291 | push.add_argument( |
| 292 | '--source-dir', |
| 293 | dest='sources', |
| 294 | required=True, |
| 295 | help="Path to the directory containing the LLVM worktree.") |
Diana Picus | efc7bda | 2017-06-09 19:14:08 +0200 | [diff] [blame] | 296 | |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 297 | # Subcommand for configuring a build directory |
| 298 | configure = subcommands.add_parser( |
| 299 | 'configure', |
| 300 | help="Run CMake in the given build directory.") |
| 301 | configure.add_argument( |
Diana Picus | 9f75686 | 2017-12-20 10:35:08 +0100 | [diff] [blame] | 302 | '--source-dir', |
| 303 | dest='sources', |
| 304 | required=True, |
| 305 | help="Path to the sources directory. It should contain an LLVM worktree.") |
| 306 | configure.add_argument( |
Diana Picus | 052b7d3 | 2017-11-24 16:19:41 +0100 | [diff] [blame] | 307 | '--build-dir', |
| 308 | dest='build', |
| 309 | required=True, |
| 310 | help="Path to the build directory. It will be created if it does not exist") |
| 311 | configure.add_argument( |
| 312 | '--cmake-generator', |
| 313 | dest='generator', |
| 314 | default='Ninja', |
| 315 | help="CMake generator to use (default is Ninja).") |
| 316 | configure.add_argument( |
| 317 | '--cmake-def', |
| 318 | dest='defs', |
| 319 | metavar='VAR=VALUE', |
| 320 | default=[], |
| 321 | action='append', |
| 322 | # We add the -D in front of the variable ourselves because the argument |
| 323 | # parsing gets confused otherwise (and quoting doesn't help). |
| 324 | help="Additional CMake definitions, e.g. CMAKE_BUILD_TYPE=Release." |
| 325 | "May be passed several times. The -D is added automatically.") |
| 326 | configure.add_argument( |
| 327 | '-n', '--dry-run', |
| 328 | dest='dry', |
| 329 | action='store_true', |
| 330 | default=False, |
| 331 | help="Print the CMake command instead of executing it.") |
| 332 | configure.set_defaults(run_command=configure_build) |
| 333 | |
Diana Picus | 37126b8 | 2018-01-19 16:14:26 +0100 | [diff] [blame] | 334 | # Subcommand for building a target |
| 335 | build = subcommands.add_parser( |
| 336 | 'build', |
| 337 | help="Run a build command in the given directory." |
| 338 | "The build command can be either a 'ninja' or a 'make' command, depending " |
| 339 | "on what the build directory contains. First, we look for a 'build.ninja' " |
| 340 | "file. If that is not found, we look for a 'Makefile'. If that is not " |
| 341 | "found either, the script fails.") |
| 342 | build.add_argument( |
| 343 | '--build-dir', |
| 344 | dest='build', |
| 345 | required=True, |
| 346 | help="Path to the build directory. It must have already been configured.") |
| 347 | build.add_argument( |
| 348 | '-n', '--dry-run', |
| 349 | dest='dry', |
| 350 | action='store_true', |
| 351 | default=False, |
| 352 | help="Print the build command instead of executing it.") |
| 353 | build.add_argument( |
| 354 | '--build-flag', |
| 355 | dest='flags', |
| 356 | metavar='FLAG', |
| 357 | default=[], |
| 358 | action='append', |
| 359 | help="Additional flags for the build command (e.g. targets to build). " |
| 360 | "May be passed several times. If your flag starts with a '-', use " |
| 361 | "'--build-flag=-FLAG' to pass it.") |
| 362 | build.set_defaults(run_command=run_build) |
| 363 | |
Diana Picus | f73abbf | 2018-01-26 07:06:20 +0100 | [diff] [blame] | 364 | # Subcommand for setting up the test-suite |
| 365 | setupTestSuite = subcommands.add_parser( |
| 366 | 'setup-test-suite', |
| 367 | help="Prepare a sandbox for running the test-suite.") |
| 368 | setupTestSuite.add_argument( |
| 369 | '--sandbox', |
| 370 | required=True, |
| 371 | help="Path where we should setup the sandbox.") |
| 372 | setupTestSuite.add_argument( |
| 373 | '--lnt', |
| 374 | required=True, |
| 375 | help="Path to the LNT sources.") |
| 376 | setupTestSuite.add_argument( |
| 377 | '-n', '--dry-run', |
| 378 | dest='dry', |
| 379 | action='store_true', |
| 380 | default=False, |
| 381 | help="Print the commands instead of executing them.") |
| 382 | setupTestSuite.set_defaults(run_command=setup_the_test_suite) |
| 383 | |
Diana Picus | b368cb6 | 2018-01-23 16:41:59 +0100 | [diff] [blame] | 384 | # Subcommand for running the test-suite |
| 385 | runTestSuite = subcommands.add_parser( |
| 386 | 'run-test-suite', |
| 387 | help="Run the test-suite in the given sandbox.") |
| 388 | runTestSuite.add_argument( |
| 389 | '--sandbox', |
| 390 | required=True, |
| 391 | help="Path to the sandbox. It must point to a virtualenv with a LNT setup.") |
| 392 | runTestSuite.add_argument( |
| 393 | '--test-suite', |
| 394 | dest="testsuite", |
| 395 | required=True, |
| 396 | help="Path to the test-suite repo.") |
| 397 | runTestSuite.add_argument( |
| 398 | '--use-lit', |
| 399 | dest="lit", |
| 400 | required=True, |
| 401 | help="Path to llvm-lit.") |
| 402 | runTestSuite.add_argument( |
| 403 | '--lnt-flag', |
| 404 | dest='flags', |
| 405 | metavar='FLAG', |
| 406 | default=[], |
| 407 | action='append', |
| 408 | help="Additional flags to be passed to LNT when running the test-suite." |
| 409 | "May be passed several times. If your flag starts with a '-', use " |
| 410 | "'--lnt-flag=-FLAG' to pass it.") |
| 411 | runTestSuite.add_argument( |
| 412 | # We can pass --cc through the --lnt-flag interface, but we generally won't |
| 413 | # want to test the system compiler, so force the user to be specific. |
| 414 | '--cc', |
| 415 | required=True, |
| 416 | help="The path to the C compiler that we're testing.") |
| 417 | runTestSuite.add_argument( |
| 418 | # For symmetry, we also provide a --cxx argument, but this one isn't |
| 419 | # required since LNT tries to guess it based on the value of --cc. |
| 420 | '--cxx', |
| 421 | required=False, |
| 422 | help="The path to the C++ compiler that we're testing.") |
| 423 | runTestSuite.add_argument( |
| 424 | '-n', '--dry-run', |
| 425 | dest='dry', |
| 426 | action='store_true', |
| 427 | default=False, |
| 428 | help="Print the commands instead of executing them.") |
| 429 | runTestSuite.set_defaults(run_command=run_the_test_suite) |
| 430 | |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 431 | buildAndTest = subcommands.add_parser( |
| 432 | 'build-and-test', # TODO: This really needs a better name... |
| 433 | help="Run complex build scenarios with one or two stages of clang and " |
| 434 | "optionally a test-suite run. This should be flexible enough to allow " |
| 435 | "us to reproduce any buildbot configuration, but it can obviously be " |
| 436 | "used for other purposes as well.") |
| 437 | buildAndTest.set_defaults(run_command=build_and_test) |
| 438 | buildAndTest.add_argument( |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame^] | 439 | '--repos-dir', |
| 440 | dest='repos', |
| 441 | required=True, |
| 442 | help="Path to the root directory containing the repositories for LLVM and " |
| 443 | "the other subprojects.") |
| 444 | buildAndTest.add_argument( |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 445 | '--source-dir', |
| 446 | dest='sources', |
| 447 | required=True, |
| 448 | help="Path to the directory containing the LLVM worktree that we're going " |
| 449 | "to build from.") |
| 450 | buildAndTest.add_argument( |
| 451 | '--stage1-build-dir', |
| 452 | dest='stage1', |
| 453 | required=True, |
| 454 | help="Path to the build directory for stage 1.") |
| 455 | buildAndTest.add_argument( |
| 456 | '--stage2-build-dir', |
| 457 | dest='stage2', |
| 458 | help="Path to the build directory for stage 2.") |
| 459 | buildAndTest.add_argument( |
Diana Picus | fcfc628 | 2018-02-14 18:50:24 +0100 | [diff] [blame^] | 460 | "--enable-test-suite", |
| 461 | dest='enableTestSuite', |
| 462 | action='store_true', |
| 463 | default=False, |
| 464 | help="Whether or not to run the test-suite with the last compiler built.") |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 465 | buildAndTest.add_argument( |
| 466 | "--sandbox", |
| 467 | help="Path to the sandbox where the test-suite should be setup.") |
| 468 | buildAndTest.add_argument( |
Diana Picus | b03e508 | 2018-02-05 12:36:49 +0100 | [diff] [blame] | 469 | '-n', '--dry-run', |
| 470 | dest='dry', |
| 471 | action='store_true', |
| 472 | default=False, |
| 473 | help="Print the commands instead of executing them.") |
| 474 | |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 475 | args = options.parse_args() |
Diana Picus | adb07c4 | 2017-11-22 16:12:57 +0100 | [diff] [blame] | 476 | if args.subcommand == "projects" and args.add and not args.repos: |
| 477 | projs.error( |
| 478 | "When adding a subproject you must also pass the --repos argument") |
Diana Picus | 3b2ef82 | 2016-10-13 16:53:18 +0300 | [diff] [blame] | 479 | args.run_command(args) |