github.com/sercand/please@v13.4.0+incompatible/docs/basics.html (about)

     1  
     2      <h1>Please basics</h1>
     3  
     4      <p>If you're familiar with Blaze / Bazel, Buck or Pants you will probably find Please very familiar.
     5        Otherwise, don't worry, it's not very complicated...</p>
     6  
     7      <h2>BUILD files</h2>
     8      <p>Please targets are defined in files named BUILD. These are analogous to Makefiles in that they define
     9        buildable targets for that directory. Fortunately, they do so in a rather nicer syntax.<br/>
    10        We refer to a directory containing a BUILD file as a <em>package</em>.
    11      </p>
    12  
    13      <h2>Build targets</h2>
    14      <p>Each BUILD file can contain a number of <em>build targets</em>. These are units of buildable code
    15        which can be reused by other build targets. An example is probably worth 1000 words at this point:
    16        <pre><code>
    17  	  <span class="build-rule">python_library</span>(
    18  	      name = 'my_library',
    19  	      srcs = ['file1.py', 'file2.py'],
    20  	  )
    21  
    22  	  <span class="build-rule">python_binary</span>(
    23  	      name = 'my_binary',
    24  	      main = 'my_main.py',
    25  	      deps = [':my_library'],
    26  	  )
    27  
    28  	  <span class="build-rule">python_test</span>(
    29  	      name = 'my_library_test',
    30  	      srcs = ['my_library_test.py'],
    31  	      deps = [':my_library'],
    32  	  )
    33        </code></pre>
    34        This snippet defines three build targets; a build target is simply a thing that can be built
    35        by Please and typically appear as a single object in the build file (as the
    36        <code>python_library</code>, <code>python_binary</code> and <code>python_test</code> are above).
    37        <ul>
    38  	<li><code>my_library</code> is simply a collection of <code>file1.py</code> and <code>file2.py</code>.<br/>
    39  	  For some languages these might be compiled, for Python of course they're simply made available for other rules.</li>
    40  	<li><code>my_binary</code> creates a deployable Python binary with an entry point in <code>my_main.py</code>.<br/>
    41  	  It also defines a <em>dependency</em> on <code>my_library</code> since it will use it internally.</li>
    42  	<li><code>my_library_test</code> defines a test on <code>my_library</code>. Tests are run by Please and their results
    43  	  are aggregated.</li>
    44        </ul>
    45        This illustrates the core points of Please; every rule clearly defines its inputs - its own sources and its dependencies -
    46        and since these are known Please can be aggressive about parallelising, caching and reusing build artifacts.
    47      </p>
    48  
    49      <h2>Okay, great, so how do I actually use them?</h2>
    50  
    51      <p>Let's assume the build rules given above are defined in a file in your repo named package/BUILD. You can do the following:
    52        <ul>
    53  	<li><code>plz build //package:my_library</code> builds the library. This isn't drastically useful on its own, of course...</li>
    54  	<li><code>plz build //package:my_binary</code> builds the binary and all needed libraries that it depends on. That produces a single output file which you could copy
    55  	  to another machine.</li>
    56  	<li><code>plz run //package:my_binary</code> builds and runs the binary immediately.</li>
    57  	<li><code>plz test //package:my_library_test</code> builds and runs the test and shows you the results.</li>
    58        </ul>
    59      </p>
    60  
    61      <h2>Build labels</h2>
    62  
    63      <p>That brings us to the topic of <em>build labels</em>, which are identifiers of build targets. As you've just seen,
    64        these are of the form <code>//package:target</code>, where <code>package</code> is the path from the repo root to that package,
    65        and <code>target</code> is the name of the target within that package.<br/>
    66        This is the most common form to identify targets absolutely, but there is also a convenient shorthand where we omit
    67        the part before the colon (as you saw earlier as well) to refer to a target within the current package.</p>
    68  
    69      <p>The convention is to use <code>lower_case_with_underscores</code> for both package names and target names.<br/>
    70        This is not just for looks; in many languages (eg. Python) the file path appears within the source files,
    71        and so it's important to choose something that's a valid lexical identifier.</p>
    72  
    73      <p>There are also some special pseudo-labels:
    74        <ul>
    75          <li><code>//mypackage:all</code> refers to all targets in 'mypackage'.</li>
    76          <li><code>//mypackage/...</code> refers to all targets in 'mypackage' and anywhere beneath it in the filesystem.</li>
    77        </ul>
    78        Build targets can't use these as dependencies; these are primarily for using on the command
    79        line or in the visibility specification for a target.
    80      </p>
    81  
    82      <h2>What now?</h2>
    83  
    84      <p>Jump in and get started! See the <a href="lexicon.html">please lexicon</a> if you want to see the set of built-in
    85        build rules for other languages.</p>
    86  
    87      <p>If that all sounds a bit easy so far, try the <a href="intermediate.html">intermediate topics</a> and start
    88        learning how to program the system and create your own build rules.</p>