....
notes:
- post-order (children before parents) order is what makes sense for
default on attr.label (and attr.label_list, attr.string_keyed_label_dict) can be a function!
this includes things like "late bound defaults"
but also your own functions can ask for other (public) attributes of the rule as keyword args and use them to compute a default!
a neat alternative to initializers on rules
Previously we explored a way to have some degree of dynamic dependencies in Bazel (input "subsetting") using TreeArtifacts.
The particular use case modeled in the previous gist involved:
library and binary rules (i.e. each rule describes a collection of files and their collective dependencies — the default for most Bazel rulesets)...
observations:
//:your_target and then pull your repo into another bazel workspace as @foo and build @foo//:your_target:example_both)ctx.actions.run(_shell)'s inputs does influence path mapping and does appear to factor into how conflicts are detected but... if you try to add a path to the command line (i.e. via arguments) that you haven't listed in inputs it isn't an error — some path mapping heuristithe idea is to have testonly-esque checks
consider a project where we want to partition content (for an existing rule) into three categories:
ossprpdev| //! for a given `N`, how many unique shapes of `N` contiguous minos (all connected via at least one | |
| //! of the four cardinal directions) are possible? | |
| //! | |
| //! a shape is unique if no translation or rotation of a shape makes it the same as another shape | |
| use std::{collections::HashSet, fmt}; | |
| #[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] | |
| struct Coord<const N: usize> { | |
| x: u8, // 0 <= x < N |
see https://www.gnu.org/software/make/manual/html_node/General-Search.html
from the perspective of a recipe (i.e. automatic variables), prerequisites are "rewritten"; if they're resolved to a directory in VPATH, the prereq is prefixed with that directory