genrule to output file with the same file name - "as both an input and an output"

1,542 views
Skip to first unread message

stanimir...@gmail.com

unread,
Jan 25, 2016, 9:17:59 AM1/25/16
to bazel-discuss

How could I reference the out file in a filegroup for example?

genrule(
name = "mymodifiedFOOfile",
srcs = ["foo.js"],
outs = ["foo.js"],
cmd = "sed 's/xxx/yyy/g' $< > $@",
)

filegroup(
name = "toolFooSources",
srcs = [":mymodifiedFOOfile"],
)

The error for the above is:

rule 'mymodifiedFOOfile' has file 'foo.js' as both an input and an output.

Thiago Farina

unread,
Jan 25, 2016, 9:39:59 AM1/25/16
to stanimir...@gmail.com, bazel-discuss
On Mon, Jan 25, 2016 at 12:17 PM, <stanimir...@gmail.com> wrote:

How could I reference the out file in a filegroup for example?

genrule(
  name = "mymodifiedFOOfile",
  srcs = ["foo.js"],
  outs = ["foo.js"],
It is saying that srcs (input) is the same as outs (output). Maybe try changing outs to "foogenerated.js"? So it does not have duplicated names? There might be another solution that I'm not aware of though.

--
Thiago Farina

stanimir...@zoneprojects.com

unread,
Jan 25, 2016, 9:51:52 AM1/25/16
to bazel-discuss, stanimir...@gmail.com
The goal is to keep the same name. A concreate use case is to have uncompiled file foo.js, and the same foo.js with different content when build.

If the file has different name, then there must be changes to other files (to the include script in the html for example).

Brian Silverman

unread,
Jan 25, 2016, 12:52:27 PM1/25/16
to stanimir...@zoneprojects.com, bazel-discuss, stanimir...@gmail.com
Can you put the input and/or output file in a subdirectory (same package though)?


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/ccd26614-2991-481b-867c-b34074889c20%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

stanimir...@zoneprojects.com

unread,
Jan 25, 2016, 1:29:53 PM1/25/16
to bazel-discuss, stanimir...@zoneprojects.com, stanimir...@gmail.com
On Monday, January 25, 2016 at 7:52:27 PM UTC+2, Brian Silverman wrote:
> Can you put the input and/or output file in a subdirectory (same package though)?

Yes, I could, but it is essentially "rename" again. My first statement had to be more precise and instead of "file name" it had to be "file name and path".

Thanks a lot for your efforts to help me!

Now I can see better why Bazel chose to use outputs to be threaten as local files (relative paths) and the restrictions that this decision poses. Maybe this is the only one thing that is not possible :)

The solution to my question will be a workaround (rename) after all.

Brian Silverman

unread,
Jan 25, 2016, 1:35:14 PM1/25/16
to stanimir...@zoneprojects.com, bazel-discuss, stanimir...@gmail.com
Yea, having them with the exact same name and path isn't going to work. The issue is that they both have the same label, which means it would be ambiguous when (for example) you refer to //the/pkg:foo.js.

Good luck!

Reply all
Reply to author
Forward
0 new messages