Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions distribution/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,31 @@ box.sh_test(
],
)

# distribution.packages() adds the list of the family's key and the list of the release's key to the common
# packages. The arch family has no key, so arch.rolling gets the list of the `DEFAULT` key. The arguments
# are the packages that distribution.packages() returns, `--`, and the expected packages from a plain
# select().
box.sh_test(
name = "packages-test",
box = "//tools:dev.box",
script = 'actual=(); while [[ "$1" != -- ]]; do actual+=("$1"); shift; done; shift; [[ "${actual[*]}" == "$*" ]]',
args = distribution.packages(
["common"],
{
"DEFAULT": ["default"],
"debian": ["family"],
"fedora": ["family"],
"fedora.rawhide": ["release"],
},
)
+ ["--"]
+ select({
"catalog//:arch.rolling.distribution": ["common", "default"],
"catalog//:debian.testing.distribution": ["common", "family"],
"catalog//:fedora.rawhide.distribution": ["common", "family", "release"],
}),
)

# A box whose release is a select() on the distribution takes this as its incoming transition.
distribution.box_host(name = "release.host")

Expand Down
15 changes: 15 additions & 0 deletions distribution/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,20 @@ def by_distribution(values: dict[str, typing.Any]) -> Select:
"""
return select({_condition(key): value for key, value in values.items()})

def packages(common: list[str], selected: dict[str, list[str]]) -> Select:
"""Return `common` plus the packages that `selected` lists for the family and the release that a build chooses.

`selected` is keyed like `distribution.select()`. The packages of a release key add to the packages of
its family key. A distribution whose family has no key gets the packages of the `DEFAULT` key, if
`selected` has one.
"""

# Buck picks only the most specific matching key of one select(), so the family keys and the release
# keys go into separate selects.
families = {key: value for key, value in selected.items() if key == "DEFAULT" or key in FAMILIES}
releases = {key: value for key, value in selected.items() if key not in families}
return common + by_distribution({"DEFAULT": []} | families) + by_distribution({"DEFAULT": []} | releases)

def release_target(role: str) -> Select:
"""Return a `select()` of the catalog target `role`, such as `box`, of the release that a build chooses.

Expand Down Expand Up @@ -511,6 +525,7 @@ distribution = struct(
for_package = for_package,
new = new,
package_manager = package_manager,
packages = packages,
release_name = release_name,
release_target = release_target,
set_for_package = set_for_package,
Expand Down
21 changes: 21 additions & 0 deletions docs/user/box.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,24 @@ The box is configured for its release's distribution, so `distribution.select()`
release's family, as it does in an image. A key such as `debian.testing` names one release, and Buck picks it
over the key of its family. If no key matches, the build fails with an error that names the box and lists the
keys. If the release's repositories do not contain a listed package, resolving the box fails.

When most packages have the same name everywhere, `distribution.packages()` takes them as a common list. It
adds the packages of the family key and the packages of the release key, such as `debian.testing`. A
distribution whose family has no key gets no family packages:

```Starlark
box.new(
name = "dev.box",
packages = distribution.packages(
["git", "meson"],
{
"debian": ["python3-yaml"],
"fedora": ["python3-pyyaml"],
},
),
release = "catalog//:debian.testing.release",
)
```

A `.bzl` file can call `distribution.select()` and `distribution.packages()` too, so a project can keep its
package lists in a `.bzl` file and load them from its `BUCK` files.
Loading