github.com/sercand/please@v13.4.0+incompatible/docs/commands.html (about) 1 2 <h1>Please commands</h1> 3 4 <p>As you might expect, Please has a number of commands 5 to invoke various behaviours. This is a more or less complete list.</p> 6 7 <h2>Common flags</h2> 8 9 <p>These flags are common to all (or nearly all) operations.</p> 10 11 <h3>Options controlling what to build & how to build it:</h3> 12 13 <p> 14 <ul> 15 <li><code>-c, --config</code><br/> 16 The build config to use. The effect this has depends on the language; typically 17 it allows swapping between a debug or an optimised build.<br/> 18 The default is <code>opt</code> to build optimised code; <code>dbg</code> is accepted 19 for C++ and Go to build code with debugging symbols.<br/> 20 This has no effect on Python or Java rules.</li> 21 22 <li><code>-r, --repo_root</code><br/> 23 Sets the location of the repo root to use. Normally plz assumes it is within the repo 24 somewhere and locates the root itself, this forces it to a specific location.</li> 25 26 <li><code>-k, --keep_going</code><br/> 27 Continues after a build failure until it's not possible to proceed any further with 28 the build. By default plz stops immediately as soon as one target fails.</li> 29 30 <li><code>-n, --num_threads</code><br/> 31 Sets the number of parallel workers to use while building. The default is the number 32 of logical CPUs of the current machine plus two.</li> 33 34 <li><code>-i, --include</code><br/> 35 Labels of targets to include when selecting multiple targets with <code>:all</code> 36 or <code>/...</code>. These apply to labels which can be set on individual targets; 37 a number of them are predefined, most notably for each language (<code>go</code>, 38 <code>python</code>, <code>java</code>, <code>cc</code>, etc).<br/> 39 Only targets with this label will be built.</li> 40 41 <li><code>-e, --exclude</code><br/> 42 The inverse of <code>--include</code>; labels of targets to exclude when 43 selecting multiple targets with <code>:all</code> or <code>/...</code>.<br/> 44 Takes priority over <code>--include</code>.<br/> 45 You can also pass build expressions to <code>--exclude</code> to exclude targets 46 as well as by label.</li> 47 48 <li><code>-a, --arch</code><br/> 49 Architecture to compile for. By default Please will build for the host architecture, 50 but has some support for targeting others. See <a href="cross_compiling.html">the 51 cross-compiling docs</a> for more information.</li> 52 53 <li><code>-o, --override</code><br/> 54 Allows overriding individual config settings on a temporary basis; for example 55 <code>-o python.testrunner:pytest</code>. See the <a href="config.html">config 56 reference</a> for more information on what can be overridden.</li> 57 58 <li><code>--profile</code><br/> 59 Defines a profile of config file to load from the repo. For example, 60 <code>--profile ci</code> will load <code>.plzconfig.ci</code>. This can be useful to 61 canonicalise certain settings for non-common or scripted configurations.</li> 62 </ul> 63 </p> 64 65 <h3>Options controlling output & logging:</h3> 66 67 <p> 68 <ul> 69 <li><code>-v, --verbosity</code><br/> 70 Sets the amount of output logged from plz; a number between 0 and 4.<br/> 71 Each number shows all messages at the given level and above: 72 <ol> 73 <li>Error</li> 74 <li>Warning</li> 75 <li>Notice</li> 76 <li>Info</li> 77 <li>Debug</li> 78 </ol> 79 The default is 1, for warnings and errors only. If level 4 is requested then it 80 will suppress interactive output. 81 </li> 82 83 <li><code>--log_file</code><br/> 84 Writes all logs out into the given file.</li> 85 86 <li><code>--log_file_level</code><br/> 87 Level of logging to write to the file. Defaults to 2 (notice, warning and error).</li> 88 89 <li><code>--interactive_output</code><br/> 90 Forces plz to show interactive output on stderr. By default it autodetects based on 91 whether stderr appears to be an interactive terminal or not, but this flag can be 92 used to force it on in cases where it might get it wrong.</li> 93 94 <li><code>-p, --plain_output</code><br/> 95 Forces plz not to show interactive output on stderr. Can be useful in cases where it 96 might obscure other messages or where the output isn't capable of interpreting the 97 escape codes correctly.</li> 98 99 <li><code>--colour</code><br/> 100 Forces coloured output from logging & shell output. Again, this is autodetected by 101 default, but this can be used in cases where it would normally detect false but it 102 will later be consumed by something that understands the codes (e.g. CI systems like 103 Teamcity or Jenkins).</li> 104 105 <li><code>--nocolour</code><br/> 106 Inverse of above, forces colourless output from logging & the shell.</li> 107 108 <li><code>--trace_file</code><br/> 109 File to write Chrome tracing output into.<br/> 110 This is a JSON format that contains the actions taken by plz during the build and 111 their timings. You can load the file up in <a href="about:tracing">about:tracing</a> 112 and use that to see which parts of your build were slow.</li> 113 114 <li><code>--version</code><br/> 115 Prints the version of the tool and exits immediately.</li> 116 117 <li><code>--show_all_output</code><br/> 118 Prints all output of each building process as they run. Implies <code>--plain_output</code>.</li> 119 120 <li><code>--completion_script</code><br/> 121 Prints the bash / zsh completion script to stdout. This can be used in a <code>.bashrc</code> 122 or <code>.zshrc</code>, e.g. <code>source <(plz --completion_script)</code>.</li> 123 </ul> 124 125 <h3>Options that enable / disable certain features:</h3> 126 127 <ul> 128 <li><code>--noupdate</code><br/> 129 Disables Please attempting to auto-update itself.</li> 130 131 <li><code>--nocache</code><br/> 132 Disables caches.<br/> 133 Note that this does not disable incrementality, so targets that don't need rebuilding 134 still won't be.</li> 135 136 <li><code>--nohash_verification</code><br/> 137 Turns hash verification errors into non-fatal warnings.<br/> 138 Obviously this is only for local development & testing, not for 'production' use.</li> 139 140 <li><code>--nolock</code><br/> 141 Don't attempt to lock the repo exclusively while building.<br/> 142 Use with care - if two instances of plz start building the same targets simultaneously 143 they will likely fail with very strange errors.</li> 144 145 <li><code>--keep_workdirs</code><br/> 146 Don't clean directories in plz-out/tmp after successfully building targets.<br/> 147 They're always left in cases where targets fail.</li> 148 </ul> 149 150 <h2><a name="build">plz build</a></h2> 151 152 <p>This is the most common and obvious command; it builds one or more targets 153 and all their dependencies. A plain <code>plz build</code> attempts to build 154 everything, but more usually you can tell it to build a particular target 155 or targets by passing them on the command line afterwards. For example:<br/> 156 157 <code>plz build //src/core:core</code> builds just the one target.<br/> 158 <code>plz build //src/core:all</code> builds every target in 159 <code>src/core/BUILD</code>.<br/> 160 <code>plz build //src/...</code> builds every target in <code>src</code> 161 and all subdirectories.</p> 162 163 <h2><a name="test">plz test</a></h2> 164 165 <p>This is also a very commonly used command, it builds one or more targets and 166 then runs their tests. Which tests to run are specified by positional arguments 167 as described for <code>plz build</code>.</p> 168 169 <p>After successful completion a combined test output file will be written to 170 <code>plz-out/log/test_results.xml</code> in something approximating xUnit 171 XML format.</p> 172 173 <p>It takes a few special flags: 174 <ul> 175 <li><code>--num_runs</code><br/> 176 Determines how many times to run each test. The default is 1, but can be 177 more for tests marked as flaky.</li> 178 <li><code>--failing_tests_ok</code><br/> 179 The return value is 0 regardless of whether any tests fail or not. It will 180 only be nonzero if they fail to build completely.<br/> 181 This is not commonly used, it's mostly useful for CI automation which will 182 parse the results file to determine ultimate success / failure.</li> 183 <li><code>--test_results_file</code><br/> 184 Specifies the location to write the combined test results to.</li> 185 <li><code>-d, --debug</code><br/> 186 Turns on interactive debug mode for this test. You can only specify one test 187 with this flag, because it attaches an interactive debugger to catch failures.<br/> 188 It only works for some test types, currently python (with pytest as the test runner), 189 C and C++.<br/> 190 It implies <code>-c dbg</code> unless that flag is explicitly passed.</li> 191 </ul> 192 </p> 193 194 <h2><a name="cover">plz cover</a></h2> 195 196 <p>Very similar to <code>plz test</code>, but also instruments tests for coverage 197 and collects results. Tests normally run significantly slower in this mode 198 (the exact amount depends on the language).</p> 199 200 <p>Coverage isn't available for C++ tests at present.</p> 201 202 <p>All the same flags from <code>plz test</code> apply here as well. In addition 203 there are several more: 204 <ul> 205 <li><code>--no_coverage_report</code><br/> 206 Suppresses the coverage report output to the shell.</li> 207 <li><code>--line_coverage_report</code><br/> 208 Produces a line-by-line coverage display for all source files.</li> 209 <li><code>--include_all_files</code><br/> 210 Includes any transitively dependent source files in the coverage report 211 (the default is just files from relevant packages).</li> 212 <li><code>--include_file</code><br/> 213 Files to include in the coverage report (the flag can be passed more 214 than once for multiple).</li> 215 <li><code>--coverage_results_file</code><br/> 216 Similar to <code>--test_results_file</code>, determines where to write 217 the aggregated coverage results to.</li> 218 <li><code>-d, --debug</code><br/> 219 Turns on interactive debug mode for this test. You can only specify one test 220 with this flag, because it attaches an interactive debugger to catch failures.<br/> 221 It only works for some test types, currently python (with pytest as the test runner), 222 C and C++.<br/> 223 It implies <code>-c dbg</code> unless that flag is explicitly passed.</li> 224 </ul> 225 </p> 226 227 <h2><a name="run">plz run</a></h2> 228 229 <p>This is essentially shorthand for calling <code>plz build</code> and then 230 running the result of whatever target was built. It's often handy for iterating 231 on a single target such that one command builds and reruns it.</p> 232 233 <p>Because of the way the target is run after, you have to provide exactly one 234 target to this command. The target must be marked as <code>binary</code> in its 235 rule definition (this is implicit for the various builtin <code>_binary</code> 236 rules such as <code>go_binary</code> etc).</p> 237 238 <p>If you want to pass flags to the target rather than plz itself, you must pass 239 them last on the command line, after a <code>--</code>. This tells Please not 240 to attempt to parse them as its own flags.</p> 241 242 <p>There are two optional subcommands <code>sequential</code> and <code>parallel</code> 243 which allow running multiple targets in one go. As the names suggest, they run targets 244 either one after the other or all in parallel.<br/> 245 In either case, the semantics are a little different to running a single target; arguments 246 must be passed one by one via the <code>-a</code> flag, and while stdout / stderr are 247 connected to the current terminal, stdin is not connected (because it'd not be clear 248 which process would consume it).</p> 249 250 <h2><a name="watch">plz watch</a></h2> 251 252 <p>Watches a set of targets for changes. Whenever any one of their source files (or that 253 of any dependency) is changed, the targets will be rebuilt. If any of them are tests, then 254 they will be run as well.</p> 255 256 <p>Optionally you can pass the <code>--run</code> flag if you'd like the targets to be run 257 (using <code>plz run</code>) instead of just built / tested.</p> 258 259 <h2><a name="query">plz query</a></h2> 260 261 <p>This allows you to introspect various aspects of the build graph. There are 262 a number of subcommands identifying what you want to query for: 263 <ul> 264 <li><code>affectedtargets</code>: Prints any targets affected by a set of files.</li> 265 <li><code>alltargets</code>: Lists all targets in the graph</li> 266 <li><code>completions</code>: Prints possible completions for a string.</li> 267 <li><code>deps</code>: Queries the dependencies of a target.</li> 268 <li><code>graph</code>: Prints a JSON representation of the build graph.</li> 269 <li><code>input</code>: Prints all transitive inputs of a target.</li> 270 <li><code>output</code>: Prints all outputs of a target.</li> 271 <li><code>print</code>: Prints a representation of a single target</li> 272 <li><code>reverseDeps</code>: Queries all the reverse dependencies of a target.</li> 273 <li><code>somepath</code>: Queries for a path between two targets</li> 274 <li><code>rules</code>: Prints out a machine-parseable description of all currently known build rules.</li> 275 </ul> 276 </p> 277 278 <p>Note that this is not the same as the query language accepted by Bazel and Buck, 279 if you're familiar with those; generally this is lighter weight but less flexible 280 and powerful. We haven't ruled out adding that in the future 281 but have no concrete plans to do so at present.</p> 282 283 <h2><a name="clean">plz clean</a></h2> 284 285 <p>Cleans up output build artifacts and caches.</p> 286 287 <p>This is not normally necessary since generally incrementality detection will ensure 288 that targets are rebuilt if needed. It's possible though for particularly determined 289 rules to do something they shouldn't in which case this might be needed, or 290 (inconceivable though it is) a bug might exist that led to incorrect artifacts being 291 cached.</p> 292 293 <p>If given no arguments this cleans the entire plz-out directory and the directory 294 cache, if configured. It returns immediately with the actual removal proceeding in 295 the background; you can invoke other plz commands freely while that continues.<br/> 296 You can pass the <code>--nobackground</code> flag if you'd prefer to wait though.</p> 297 298 <p>If it's given targets to clean, it will need to perform a parse to work out what 299 to clean, and will not return until those targets have been cleaned.</p> 300 301 <p>The <code>--nocache</code> flag works like all other commands here, but bears 302 mentioning since it will prevent artifacts from being removed from the cache 303 (by default they're cleaned from there too).</p> 304 305 <h2><a name="hash">plz hash</a></h2> 306 307 <p>This command calculates the hash of outputs for one or more targets. These can 308 then be passed in the <code>hash</code> or <code>hashes</code> attributes of 309 those targets to verify their output is as expected - this is useful for 310 fetching third-party dependencies to ensure they are not changing between builds.</p> 311 312 <p>The relevant targets will be built in order to calculate the hash, but if they fail 313 because it doesn't match the one recorded in the BUILD file plz will still exit 314 successfully (although the output files will still not be created).</p> 315 316 <p>One can of course achieve the same effect via running <code>plz build</code> and 317 reading the actual hash when it fails, but this way is generally considered nicer.</p> 318 319 <p>The <code>--update</code> flag will cause Please to rewrite the BUILD file with 320 any changed hashes that it can find.</p> 321 322 <h2><a name="init">plz init</a></h2> 323 324 <p>Creates an initial (and pretty empty) <code>.plzconfig</code> file in the current 325 directory (or, if the <code>--dir</code> flag is passed, somewhere else).</p> 326 327 <p>You'll be warned before overwriting an existing file.</p> 328 329 <p>It will also create a wrapper script, <code>pleasew</code> which runs plz if found 330 on the local machine, and otherwise attempts to download a copy. This can be handy 331 for users who don't have it installed already.</p> 332 333 <p>There is a <code>--bazel_compat</code> flag which initialises the config file for 334 Bazel compatibility mode. This changes behaviour in various ways to make it easier 335 to begin building an existing Bazel project - although more complex projects will 336 still likely find things that don't translate easily.</p> 337 338 <h2><a name="update">plz update</a></h2> 339 340 <p>Updates plz to the appropriate version. This is quite tightly governed by the 341 <code>.plzconfig</code> file: 342 <ul> 343 <li>If <code>selfupdate</code> is true, then it's not normally necessary to run this 344 since any invocation of plz will update before running. It will still behave as 345 normal though if invoked explicitly.</li> 346 <li>If the <code>version</code> property is set then it will attempt to download 347 exactly that version, and fail if it can't for some reason.</li> 348 <li>Otherwise it will try to find the latest available version and update to that.</li> 349 <li>The <code>downloadlocation</code> property determines where it tries to download 350 from; by default it's the central plz site, but you could set this to a server of 351 your own if you'd rather be more independent.</li> 352 </ul> 353 </p> 354 355 <h2><a name="gc">plz gc</a></h2> 356 357 <p>Runs a basic "garbage collection" step, which attempts to identify targets that 358 aren't in use. This is still fairly experimental since the definition of "not used" 359 isn't always very clear (for example, ideally simply having a test on a library that 360 isn't otherwise used would not be enough to keep both of those). Because of this it 361 suggests a set of targets that it's pretty sure aren't used at all, and a secondary 362 set that it's less sure on.</p> 363 364 <p>Right now the name is a bit misleading since it finds but doesn't collect the garbage; 365 ideally it'd be able to rewrite the BUILD files itself. Deleting sources is a little 366 trickier since you'd often want to couple that with a VC operation (i.e. <code>git rm</code>) 367 and by design plz is unaware of the VCS in use.</p> 368 369 <p>There are a few flags controlling it: 370 <ul> 371 <li><code>-c</code>, <code>--conservative</code><br/> 372 Uses a more conservative algorithm (specifically any tests will keep their targets).</li> 373 <li><code>-t</code>, <code>--targets_only</code><br/> 374 Only prints the targets to be removed (not sources). Useful to pipe them into another program.</li> 375 <li><code>-t</code>, <code>--srcs_only</code><br/> 376 Only prints the sources to be removed (not targets). Useful to pipe them into another program.</li> 377 </ul> 378 </p> 379 380 <h2><a name="follow">plz follow</a></h2> 381 382 <p>Connects to a remote instance of plz and follows its progress locally.<br/> 383 The remote process must have opened a port to stream events on (see the 384 <a href="config.html#events">events</a> section of the config), in which case the client 385 will connect and show what it's doing using the normal animated display.</p> 386 387 <h2><a name="help">plz help</a></h2> 388 389 <p>Displays help about a particular facet of Please. It knows about built-in build rules, config 390 settings and a few other things. Mostly this is useful as an instant reference; you can run 391 <code>plz help topics</code> to get a list of all the topics that it knows about.</p> 392 393 <h2><a name="op">plz op</a></h2> 394 395 <p>Re-runs whatever the previous command was.</p>