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