Skip to content
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

Multiple genrules should allow outputs with the same name #7311

Closed
shs96c opened this issue Jan 31, 2019 · 8 comments
Closed

Multiple genrules should allow outputs with the same name #7311

shs96c opened this issue Jan 31, 2019 · 8 comments
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Configurability platforms, toolchains, cquery, select(), config transitions type: feature request

Comments

@shs96c
Copy link
Contributor

shs96c commented Jan 31, 2019

Description of the problem / feature request:

The given build file does not allow bazel to run as it complains about conflicting outputs.

genrule(
  name = "one",
  outs = ["bar"],
  srcs = ["foo"],
  cmd = "cp $(location foo) $@")

genrule(
  name = "two",
  outs = ["bar"],
  srcs = ["baz"],
  cmd = "cp $(location baz) $@")

While this is a pathological case, it's easy to reach this point accidentally by invoking macros. It seems like an unnecessary constraint.

Feature requests: what underlying problem are you trying to solve with this feature?

It should be possible for the outputs of different rules (particularly genrules) to have the same name. Buck allows this by creating an output directory named after the rule (buck-out/gen/one and buck-out/gen/two in this case) rather than the package as bazel does (bazel-genfiles/ in this case).

Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

See the build file above.

What operating system are you running Bazel on?

OS X, but this is reproducible everywhere

What's the output of bazel info release?

release 0.22.0

@dslomov dslomov added team-Configurability platforms, toolchains, cquery, select(), config transitions untriaged type: feature request labels Jan 31, 2019
@gregestren
Copy link
Contributor

Thanks for the report, Simon. This is close to some stuff I"m working on.

For many of Bazel's outputs I think we have options. But for something like the above example it isn't quite as simple. For example, what should

genrule(
    name = "consumer",
    srcs = ["//mypackage:bar"],
    outs = ["gg2.out"],
    cmd = "cat $< > $@")

do?

In others words, genrule outs use the same label naming logic as any rule. So by definition //mypackage:bar must match outs = ["bar"].

What macros are bothering you?

@gregestren gregestren added P2 We'll consider working on this in future. (Assignee optional) P3 We're not considering working on this, but happy to review a PR. (No assignee) and removed P2 We'll consider working on this in future. (Assignee optional) untriaged labels Jan 31, 2019
@shs96c
Copy link
Contributor Author

shs96c commented Jul 2, 2019

Apologies for the very slow reply. In the example you gave, I would expect the srcs to list either //:one or //:two, which unambiguously declares which output should be used. I think it's perfectly valid for bazel to stop the build if there's any ambiguity in the build graph.

@gregestren
Copy link
Contributor

Sure that makes sense. On what criteria would you want to disambiguate for this example?

So if I do $ bazel build //:gg2.out, I haven't provided enough information to determine if //:one or //:two should invoke.

@shs96c
Copy link
Contributor Author

shs96c commented Jul 10, 2019

I think it's perfectly valid for bazel to stop the build if there's any ambiguity.

In the case you've given, I'd expect bazel to request the user to select which rule they want the output of (obviously, this would mean editing the build file --- I don't envision an interactive process!). That is, the person constructing the build file (or the command line) is responsible for ensuring that the build is unambiguous.

From my understanding of bazel, this can be done as we build the action graph. We wouldn't need to perform a full build in order to check this.

@gregestren
Copy link
Contributor

gregestren commented Jul 10, 2019

For command line disambiguation, I think select() covers similar territory.

But it's an interesting idea to consider. I'd think of this as something like "annotated labels".

@shs96c
Copy link
Contributor Author

shs96c commented Jul 11, 2019

I think the disambiguation piece is interesting, but the important thing is the two outputs with the same file name :)

@laurentlb
Copy link
Contributor

It should be possible for the outputs of different rules (particularly genrules) to have the same name. Buck allows this by creating an output directory named after the rule (buck-out/gen/one and buck-out/gen/two in this case) rather than the package as bazel does (bazel-genfiles/ in this case).

So the workaround is to create the genrules in two subpackages?

@aiuto
Copy link
Contributor

aiuto commented Oct 6, 2021

I'm closing this because where are reasonable workarounds and implementing it is expensive. There is little chance our team will ever implement it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 We're not considering working on this, but happy to review a PR. (No assignee) team-Configurability platforms, toolchains, cquery, select(), config transitions type: feature request
Projects
None yet
Development

No branches or pull requests

5 participants