Skip to content

Commit

Permalink
docs: there may be multiple BUILD files in a directory
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexTereshenkov committed Apr 19, 2024
1 parent 093d536 commit a1d61a4
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/docs/using-pants/key-concepts/targets-and-build-files.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,31 @@ python_distribution(
)
```

### Multiple BUILD files in a directory

Typically, there would be one BUILD file in every directory containing source code and any other resources you
may want to use as part of your builds. However, you can have multiple BUILD files in a single directory.
When running a Pants goal, the contents of the BUILD files will be merged making it possible to better group your
targets, if desired. For instance, you could store source code targets and
[macros](../../writing-plugins/macros.mdx) in different files to have better separation of concerns:

```python tab={"label":"BUILD"}
python_sources()
python_tests(name="tests")
```

```python tab={"label":"BUILD.macros"}
jinja_templates(sources=["*.j2"])
```

Storing targets in multiple BUILD files also makes it possible to dynamically include or exclude targets from your
builds. For example, you could include some experimental targets when running a Pants goal from a command line by
extending the list of recognized BUILD file patterns:

```bash
$ pants --build-patterns="+['BUILD.experimental']" package project:app
```

## Target addresses

A target is identified by its unique address, in the form `path/to/dir:name`. The above example has the addresses `helloworld/greet:tests` and `helloworld/greet:bin`.
Expand Down

0 comments on commit a1d61a4

Please sign in to comment.