Please commands

As you might expect, Please has a number of commands to invoke various behaviours. This is a more or less complete list.

Common flags

These flags are common to all (or nearly all) operations.

Options controlling what to build & how to build it:

  • -c, --config
    The build config to use. The effect this has depends on the language; typically it allows swapping between a debug or an optimised build.
    The default is opt to build optimised code; dbg is accepted for C++ and Go to build code with debugging symbols.
    This has no effect on Python or Java rules.
  • -r, --repo_root
    Sets the location of the repo root to use. Normally plz assumes it is within the repo somewhere and locates the root itself, this forces it to a specific location.
  • -k, --keep_going
    Continues after a build failure until it's not possible to proceed any further with the build. By default plz stops immediately as soon as one target fails.
  • -n, --num_threads
    Sets the number of parallel workers to use while building. The default is the number of logical CPUs of the current machine plus two.
  • -i, --include
    Labels of targets to include when selecting multiple targets with :all or /.... These apply to labels which can be set on individual targets; a number of them are predefined, most notably for each language (go, python, java, cc, etc).
    Only targets with this label will be built.
  • -e, --exclude
    The inverse of --include; labels of targets to exclude when selecting multiple targets with :all or /....
    Takes priority over --include.
    You can also pass build expressions to --exclude to exclude targets as well as by label.

Options controlling output & logging:

  • -v, --verbosity
    Sets the amount of output logged from plz; a number between 0 and 4.
    Each number shows all messages at the given level and above:
    1. Error
    2. Warning
    3. Notice
    4. Info
    5. Debug
    The default is 1, for warnings and errors only. If level 4 is requested then it will suppress interactive output.
  • --log_file
    Writes all logs out into the given file.
  • --log_file_level
    Level of logging to write to the file. Defaults to 2 (notice, warning and error).
  • --interactive_output
    Forces plz to show interactive output on stderr. By default it autodetects based on whether stderr appears to be an interactive terminal or not, but this flag can be used to force it on in cases where it might get it wrong.
  • -p, --plain_output
    Forces plz not to show interactive output on stderr. Can be useful in cases where it might obscure other messages or where the output isn't capable of interpreting the escape codes correctly.
  • --colour
    Forces coloured output from logging & shell output. Again, this is autodetected by default, but this can be used in cases where it would normally detect false but it will later be consumed by something that understands the codes (e.g. CI systems like Teamcity or Jenkins).
  • --nocolour
    Inverse of above, forces colourless output from logging & the shell.
  • --trace_file
    File to write Chrome tracing output into.
    This is a JSON format that contains the actions taken by plz during the build and their timings. You can load the file up in about:tracing and use that to see which parts of your build were slow.
  • --version
    Prints the version of the tool and exits immediately.

Options that enable / disable certain features:

  • --noupdate
    Disables Please attempting to auto-update itself.
  • --nocache
    Disables caches.
    Note that this does not disable incrementality, so targets that don't need rebuilding still won't be.
  • --nohash_verification
    Turns hash verification errors into non-fatal warnings.
    Obviously this is only for local development & testing, not for 'production' use.
  • --nolock
    Don't attempt to lock the repo exclusively while building.
    Use with care - if two instances of plz start building the same targets simultaneously they will likely fail with very strange errors.
  • --keep_workdirs
    Don't clean directories in plz-out/tmp after successfully building targets.
    They're always left in cases where targets fail.

plz build

This is the most common and obvious command; it builds one or more targets and all their dependencies. A plain plz build attempts to build everything, but more usually you can tell it to build a particular target or targets by passing them on the command line afterwards. For example:
plz build //src/core:core builds just the one target.
plz build //src/core:all builds every target in src/core/BUILD.
plz build //src/... builds every target in src and all subdirectories.

plz test

This is also a very commonly used command, it builds one or more targets and then runs their tests. Which tests to run are specified by positional arguments as described for plz build.

After successful completion a combined test output file will be written to plz-out/log/test_results.xml in something approximating xUnit XML format.

It takes a few special flags:

  • --num_runs
    Determines how many times to run each test. The default is 1, but can be more for tests marked as flaky.
  • --failing_tests_ok
    The return value is 0 regardless of whether any tests fail or not. It will only be nonzero if they fail to build completely.
    This is not commonly used, it's mostly useful for CI automation which will parse the results file to determine ultimate success / failure.
  • --test_results_file
    Specifies the location to write the combined test results to.

plz cover

Very similar to plz test, but also instruments tests for coverage and collects results. Tests normally run significantly slower in this mode (the exact amount depends on the language).

Coverage isn't available for C++ tests at present.

All the same flags from plz test apply here as well. In addition there are several more:

  • --no_coverage_report
    Suppresses the coverage report output to the shell.
  • --line_coverage_report
    Produces a line-by-line coverage display for all source files.
  • --include_all_files
    Includes any transitively dependent source files in the coverage report (the default is just files from relevant packages).
  • --include_file
    Files to include in the coverage report (the flag can be passed more than once for multiple).
  • --coverage_results_file
    Similar to --test_results_file, determines where to write the aggregated coverage results to.

plz run

This is essentially shorthand for calling plz build and then running the result of whatever target was built. It's often handy for iterating on a single target such that one command builds and reruns it.

Because of the way the target is run after, you have to provide exactly one target to this command. The target must be marked as binary in its rule definition (this is implicit for the various builtin _binary rules such as go_binary etc).

If you want to pass flags to the target rather than plz itself, you must pass them last on the command line, after a --. This tells Please not to attempt to parse them as its own flags.

plz query

This allows you to introspect various aspects of the build graph. There are a number of subcommands identifying what you want to query for:

  • affectedtargets: Prints any targets affected by a set of files.
  • alltargets: Lists all targets in the graph
  • completions: Prints possible completions for a string.
  • deps: Queries the dependencies of a target.
  • graph: Prints a JSON representation of the build graph.
  • input: Prints all transitive inputs of a target.
  • output: Prints all outputs of a target.
  • print: Prints a representation of a single target
  • reverseDeps: Queries all the reverse dependencies of a target.
  • somepath: Queries for a path between two targets

Note that this is not the same as the query language accepted by Bazel and Buck, if you're familiar with those; generally this is lighter weight but less flexible and powerful. We haven't ruled out adding that in the future but have no concrete plans to do so at present.

plz clean

Cleans up output build artifacts and caches.

This is not normally necessary since generally incrementality detection will ensure that targets are rebuilt if needed. It's possible though for particularly determined rules to do something they shouldn't in which case this might be needed, or (inconceivable though it is) a bug might exist that led to incorrect artifacts being cached.

If given no arguments this cleans the entire plz-out directory and the directory cache, if configured. It returns immediately with the actual removal proceeding in the background; you can invoke other plz commands freely while that continues.
You can pass the --nobackground flag if you'd prefer to wait though.

If it's given targets to clean, it will need to perform a parse to work out what to clean, and will not return until those targets have been cleaned.

The --nocache flag works like all other commands here, but bears mentioning since it will prevent artifacts from being removed from the cache (by default they're cleaned from there too).

plz hash

This command calculates the hash of outputs for one or more targets. These can then be passed in the hash or hashes attributes of those targets to verify their output is as expected - this is useful for fetching third-party dependencies to ensure they are not changing between builds.

The relevant targets will be built in order to calculate the hash, but if they fail because it doesn't match the one recorded in the BUILD file plz will still exit successfully (although the output files will still not be created).

One can of course achieve the same effect via running plz build and reading the actual hash when it fails, but this way is generally considered nicer.

plz init

Creates an initial (and pretty empty) .plzconfig file in the current directory (or, if the --dir flag is passed, somewhere else).

You'll be warned before overwriting an existing file.

It will also create a wrapper script, pleasew which runs plz if found on the local machine, and otherwise attempts to download a copy. This can be handy for users who don't have it installed already.

There is a --bazel_compat flag which initialises the config file for Bazel compatibility mode. This changes behaviour in various ways to make it easier to begin building an existing Bazel project - although more complex projects will still likely find things that don't translate easily.

plz update

Updates plz to the appropriate version. This is quite tightly governed by the .plzconfig file:

  • If selfupdate is true, then it's not normally necessary to run this since any invocation of plz will update before running. It will still behave as normal though if invoked explicitly.
  • If the version property is set then it will attempt to download exactly that version, and fail if it can't for some reason.
  • Otherwise it will try to find the latest available version and update to that.
  • The downloadlocation property determines where it tries to download from; by default it's the central plz site, but you could set this to a server of your own if you'd rather be more independent.

plz gc

Runs a basic "garbage collection" step, which attempts to identify targets that aren't in use. This is still fairly experimental since the definition of "not used" isn't always very clear (for example, ideally simply having a test on a library that isn't otherwise used would not be enough to keep both of those). Because of this it suggests a set of targets that it's pretty sure aren't used at all, and a secondary set that it's less sure on.

Right now the name is a bit misleading since it finds but doesn't collect the garbage; ideally it'd be able to rewrite the BUILD files itself. Deleting sources is a little trickier since you'd often want to couple that with a VC operation (i.e. git rm) and by design plz is unaware of the VCS in use.

There are a few flags controlling it:

  • -c, --conservative
    Uses a more conservative algorithm (specifically any tests will keep their targets).
  • -t, --targets_only
    Only prints the targets to be removed (not sources). Useful to pipe them into another program.
  • -t, --srcs_only
    Only prints the sources to be removed (not targets). Useful to pipe them into another program.

plz help

Displays help about a particular facet of Please. It knows about built-in build rules, config settings and a few other things. Mostly this is useful as an instant reference; you can run plz help topics to get a list of all the topics that it knows about.

plz op

Re-runs whatever the previous command was.