You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add new Make variable to genrule's cmd which always points to the output directory containing output from running genrule
Feature requests: what underlying problem are you trying to solve with this feature?
Currently, when writing a genrule, the cmd attribute gets some values substituted into it (see https://docs.bazel.build/versions/master/be/make-variables.html). One of these is the output directory (substituted for $(@D)), but where outs are nested in directories, what directory this refers to differs depending on whether there is one, or more than one, out. Specifically:
name = "gr",
outs = [
"foo/bar",
#"baz/bar",
],
cmd = "for out in $(OUTS); do echo hello > $(@D)/$$(basename $${out}); done",
)```
If only `foo/bar` is present as an output, `$(@D)` points to the directory which will contain bar and this genrule works with output like:
```$ tree bazel-genfiles/tools/test/
bazel-genfiles/tools/test/
└── foo
└── bar
1 directory, 1 file
If baz/bar is uncommented, $(@D) now points to the directory which will contain foo and baz:
and neither file is correctly generated and returns an error. The proposed improvement is a new Make variable named something like $(OUT_ROOT_DIR) which will always point at the directory that contains foo and baz, rather than having dynamic behaviour based on the number of outs.
Then the genrule would look like:
genrule(
name = "gr",
outs = [
"foo/bar",
"baz/bar",
],
cmd = "for out in foo baz; do echo hello > $(OUT_ROOT_DIR)/$${out}/bar; done",
)
Any other information, logs, or outputs that you want to share?
Attaching a draft wip PR with this issue to kickstart the work and happy to hear thoughts/ideas.
The text was updated successfully, but these errors were encountered:
###Description of the problem / feature request:
Add new Make variable to genrule's cmd which always points to the output directory containing output from running genrule. See #7248 for details.
Closes#7249.
RELNOTES[NEW]: genrules now support a $(RULEDIR) variable that resolves to the directory where the outputs of the rule are put.
PiperOrigin-RevId: 236612681
Description of the problem / feature request:
Add new Make variable to
genrule
'scmd
which always points to the output directory containing output from runninggenrule
Feature requests: what underlying problem are you trying to solve with this feature?
Currently, when writing a genrule, the
cmd
attribute gets some values substituted into it (see https://docs.bazel.build/versions/master/be/make-variables.html). One of these is the output directory (substituted for$(@D)
), but where outs are nested in directories, what directory this refers to differs depending on whether there is one, or more than one, out. Specifically:If
baz/bar
is uncommented,$(@D)
now points to the directory which will contain foo and baz:and neither file is correctly generated and returns an error. The proposed improvement is a new Make variable named something like
$(OUT_ROOT_DIR)
which will always point at the directory that containsfoo
andbaz
, rather than having dynamic behaviour based on the number of outs.Then the genrule would look like:$(OUT_ROOT_DIR)/$ ${out}/bar; done",
genrule(
name = "gr",
outs = [
"foo/bar",
"baz/bar",
],
cmd = "for out in foo baz; do echo hello >
)
Any other information, logs, or outputs that you want to share?
Attaching a draft wip PR with this issue to kickstart the work and happy to hear thoughts/ideas.
The text was updated successfully, but these errors were encountered: