since ctx.new_file() is deprecated ctx.actions.declare_file() should be a replacement.
with ctx.new_file() it was possible to generate files to genfiles_dir which I tried with ctx.actions.declare_file()
out = ctx.actions.declare_file(ctx.attr.out, sibling=ctx.genfiles_dir)
produces
Cannot convert parameter 'sibling' to type File or NoneType, in method declare_file(string, root sibling) of 'actions'
it must be possible to use a root dir (ctx.bin_dir and ctx.genfiles_dir) as sibling
or as different parameter e.g. root.
rule.bzl:
def _impl(ctx):
o = ctx.actions.declare_file('x.sh', sibling=ctx.bin_dir)
ctx.actions.write(o, 'echo Stuff', is_executable = True)
return [DefaultInfo(executable = o)]
my_rule = rule(_impl, executable = True)
BUILD:
load(':rule.bzl', 'my_rule')
my_rule(name = 'xxx')
bazel build xxx
macOS 10.12.6
bazel info release?release 0.11.1-homebrew
I would suggest declare_directory has the same issue
cc @laurentlb
Long-term plan is to get rid of the root and the distinction between bin_dir and genfiles_dir (cc @lberki).
We might add the feature for now, but it should be clear it will go away.
We can add that knob, but instead, can you get by by putting that file under bazel-bin instead?
Maybe try to build your code with --noexperimental_separate_genfiles_directory? This way, this will merge the bin and the genfiles directories. It hasn't been much tested yet, but I hope it can make things simpler.
I didn't know the plan to remove the genfiles directory. Wich version will remove the separation and did you report this anywhere?
It's unclear at the moment how we'll proceed. The separation is not useful and it adds complexity. I would be very happy if we could remove it. It's still here for legacy reasons, so we need to investigate and see how much work there is to do before we can switch the default.
@laurentlb a ticket to be able to follow regarding this long term plan would be very beneficial. For me it was also a little bit hard to find in this ticket that this is the long term plan
The genfiles directory will be removed in Bazel 0.25. See https://github.com/bazelbuild/bazel/issues/6761
Most helpful comment
It's unclear at the moment how we'll proceed. The separation is not useful and it adds complexity. I would be very happy if we could remove it. It's still here for legacy reasons, so we need to investigate and see how much work there is to do before we can switch the default.