New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Access absolute output path #61
Comments
Take a look at how rustdoc works. It also writes to an output directory. |
Generally you would declare an output directory, and write it out.
You will normally get an error about overlapping paths if you have defined that one output is in The above will given you a relative path, which I guess is probably fine (it will be relative to the root of the repo, which will also be the $PWD for the command). If you really need absolute, then use If you have to do |
With that approach I get an output directory. I'm using
def proto_library_impl(ctx: "context") -> ["provider"]:
headers = []
ccs = []
out = ctx.actions.declare_output("out", dir=True)
ctx.attrs.headers.append(out)
cmd = cmd_args(["protoc", "--cpp_out", out.as_output()])
for s in ctx.attrs.srcs:
name = paths.replace_extension(s.short_path, "")
h = ctx.actions.declare_output(out.short_path + "/" + name + ".pb.h") # conflict warning
cc = ctx.actions.declare_output(out.short_path + "/" + name + ".pb.cc") # conflict warning
cmd.hidden([h.as_output(), cc.as_output()])
ccs.extend([cc])
headers.extend([h])
cmd.add(ctx.attrs.srcs)
# replace sources because cxx_library_parameterized uses ctx.srcs
ctx.actions.run(cmd, category="protoc", identifier = "compile", no_outputs_cleanup = True)
ctx.attrs.srcs.clear()
ctx.attrs.srcs.extend(ccs)
# ... snip much more code to call cxx_library_parameterized |
After a bit more of trial and error I landed on the following solution which relies on the fact that rule out = ctx.actions.declare_output('out')
cmd = cmd_args("protoc")
# ... snip
cmd.add("--cpp_out")
cmd.add(cmd_args(out.as_output()).parent())
cmd.add(ctx.attrs.srcs) I don't know whether this is always true but works for now. |
Really liking buck2 so far, great work!
I've been trying to implement a
proto_library
rule in starlark but am stuck on a small thing - when creating the command I need access to the absolute directory of an artifact in order to pass it toprotoc
, i.e. what do I pass for???
in the snippet below? If I use e.g..
thenprotoc
just writes into my current git checkout.I've tried various combinations of
$(location)
=> does not get substituteddir=True
=> "conflicts with the following output paths"The closest thing I can find in the code is in
genrule.bzl
but also doesn't appear to work (nor would I expect it to work based on the Rust code)The text was updated successfully, but these errors were encountered: