forcing a genrule to always run?

1,972 views
Skip to first unread message

JI Ioannidis

unread,
May 9, 2017, 3:01:10 PM5/9/17
to bazel-discuss
I have a genrule that runs a script which pulls some configuration from a database and generates a python file. How do I force it to always run, without having to do a bazel clean first? I found https://groups.google.com/forum/#!searchin/bazel-discuss/always$20build%7Csort:relevance/bazel-discuss/RxLIG44vTMo/z2PDKOZ0DQAJ and the suggestion to use tags = ["external"], but that did't do the trick; the generated file in bazel-build/ remains unchanged.

I doubt this matters, but I have build --genrule_strategy=standalone in my tools/bazel.rc (the aforementioned script needs to access ~/.pgpass)

Cheers,

/ji

Kristina Chodorow

unread,
May 9, 2017, 3:27:11 PM5/9/17
to JI Ioannidis, bazel-discuss
You should use the stamping mentioned in that thread.  I.e., add to your genrule:

genrule(
    name = "stomp",
    stamp = 1,
    ...
)

Then build the target with --stamp and --workspace_status_command=, e.g.,

bazel build --stamp --workspace_status_command=/bin/date //:stomp

The output of /bin/date (or whatever you put in there) will be stored in bazel-out/volatile-status.txt, so if you wanted you could read it from the genrule (e.g., if you wanted the script to contact the db).


--
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-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/59858c8d-0bff-437c-a76d-eb769ee4853d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

JI Ioannidis

unread,
May 9, 2017, 3:52:47 PM5/9/17
to bazel-discuss, jay...@gmail.com


On Tuesday, May 9, 2017 at 3:27:11 PM UTC-4, Kristina Chodorow wrote:
You should use the stamping mentioned in that thread.  I.e., add to your genrule:

genrule(
    name = "stomp",
    stamp = 1,
    ...
)

Then build the target with --stamp and --workspace_status_command=, e.g.,

bazel build --stamp --workspace_status_command=/bin/date //:stomp

The output of /bin/date (or whatever you put in there) will be stored in bazel-out/volatile-status.txt, so if you wanted you could read it from the genrule (e.g., if you wanted the script to contact the db).



I actually already had a workspace_status option (see: https://gist.github.com/jayeye/14c91816d10d5b899e1baaaaa9ba4848, posted here: https://groups.google.com/d/msg/bazel-discuss/4NtEubfZrC8/VPjoUWQNAwAJ), and it indeed updates volatile-status.txt, so that's not an issue.

My rule is still not run, whether I specify --stamp (or put stamp = 1 in the rule) or not



 
On Tue, May 9, 2017 at 3:01 PM, JI Ioannidis <jay...@gmail.com> wrote:
I have a genrule that runs a script which pulls some configuration from a database and generates a python file. How do I force it to always run, without having to do a bazel clean first? I found https://groups.google.com/forum/#!searchin/bazel-discuss/always$20build%7Csort:relevance/bazel-discuss/RxLIG44vTMo/z2PDKOZ0DQAJ and the suggestion to use tags = ["external"], but that did't do the trick; the generated file in bazel-build/ remains unchanged.

I doubt this matters, but I have build --genrule_strategy=standalone in my tools/bazel.rc (the aforementioned script needs to access ~/.pgpass)

Cheers,

/ji

--
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.

JI Ioannidis

unread,
May 13, 2017, 2:23:20 PM5/13/17
to bazel-discuss, jay...@gmail.com
*bump* anyone? anyone?

Paul Johnston

unread,
May 16, 2017, 11:45:56 PM5/16/17
to bazel-discuss, jay...@gmail.com
Tried it, I can't make it work either.


Best bet seems to be: run an external script to delete the generated file whenever you need it regenerated.  That might require wrapping your bazel command with a shell script for this particular purpose.

Kristina Chodorow

unread,
May 23, 2017, 10:27:41 AM5/23/17
to Paul Johnston, bazel-discuss, JI Ioannidis
I could have sworn I had this working but now it's not for me, either!  Filing a bug: https://github.com/bazelbuild/bazel/issues/3041, there really should be a way to do this.

To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discuss+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/c1a4f036-19e6-45e1-b1eb-e6c280f3c6a5%40googlegroups.com.

Lukács T. Berki

unread,
Jun 27, 2017, 9:38:23 AM6/27/17
to Kristina Chodorow, Paul Johnston, bazel-discuss, JI Ioannidis
I'd much rather we don't do this. Genrules talking to external systems is inimical to reproducibility, and I don't think we want to make Bazel a general purpose workflow system, do we? These "fetch from external system" things are much better implemented as either external repositories or outside of Bazel.


For more options, visit https://groups.google.com/d/optout.



--
Lukács T. Berki | Software Engineer | lbe...@google.com | 

Google Germany GmbH | Erika-Mann-Str. 33  | 80636 München | Germany | Geschäftsführer: Matthew Scott Sucherman, Paul Terence Manicle | Registergericht und -nummer: Hamburg, HRB 86891
Reply all
Reply to author
Forward
0 new messages