Why is Bazel ignoring my rule?

666 views
Skip to first unread message

Matthew Woehlke

unread,
May 8, 2017, 2:20:59 PM5/8/17
to bazel-discuss
I've spent the last two days trying to figure out why Bazel won't execute a simple rule:

foo.bzl:
  def _debug_impl(ctx):
    print("This rule does nothing")

  debug = rule(implementation=_debug_impl)

BUILD:
  load("@//foo.bzl", "debug")
  debug(name="foo")

This is taken almost straight from the examples, but no matter what I do, I can't get any logic in the rule (e.g. the print) to actually execute. What gives?

Ultimately, I'm trying to write a rule to do some interesting stuff, but for some inexplicable reason, no matter what the rule does, it is never executed.

Kristina Chodorow

unread,
May 8, 2017, 2:32:07 PM5/8/17
to Matthew Woehlke, bazel-discuss
The one bug I notice is @//foo.bzl doesn't have a colon, but it's unlikely you have a package named foo.bzl.  But it works for me regardless:

$ bazel build //:foo
WARNING: /home/kchodorow/test/a/foo.bzl/foo.bzl:2:3: This rule does nothing.
INFO: Found 1 target...
Target //:foo up-to-date (nothing to build)
INFO: Elapsed time: 0.261s, Critical Path: 0.00s

So, what version of bazel are you running (`bazel version`), what system are you on, any other info you could give about your setup?

--
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/a150ec8b-a8a0-46df-b173-c80ab661c684%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Matthew Woehlke

unread,
May 9, 2017, 11:43:44 AM5/9/17
to bazel-discuss, Kristina Chodorow
On 2017-05-08 14:31, Kristina Chodorow wrote:
> The one bug I notice is @//foo.bzl doesn't have a colon, but it's unlikely
> you have a package named foo.bzl.

Eh, that's a red herring... my actual .bzl is named something different
and *does* have a ':' in the `load`. (Also, it is surely loading `debug`
or it would be complaining about that...)

> But it works for me regardless:
>
> $ bazel build //:foo
> WARNING: /home/kchodorow/test/a/foo.bzl/foo.bzl:2:3: This rule does nothing.
> INFO: Found 1 target...
> Target //:foo up-to-date (nothing to build)
> INFO: Elapsed time: 0.261s, Critical Path: 0.00s
>
> So, what version of bazel are you running (`bazel version`), what system
> are you on, any other info you could give about your setup?

Build label: 0.4.5- (@non-git)
Build target:
bazel-out/local-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Wed Apr 5 15:28:13 2017 (1491406093)
Build timestamp: 1491406093
Build timestamp as int: 1491406093

Fedora 25

I am actually trying to implement some new stuff in
http://github.com/robotlocomotion/drake. There are other custom rules
that work (e.g. generate_export_header, drake_generate_file), but for
some reason I can't get new ones to work, even directly invoking the
target (`bazel build @package//:foo`).

Is it something to do with being in an "external" package?

--
Matthew

Kristina Chodorow

unread,
May 9, 2017, 2:18:41 PM5/9/17
to bazel-discuss
Um... maybe?  Since this is an open source repo, can you give me the actual code you're trying?

Matthew Woehlke

unread,
May 9, 2017, 2:22:53 PM5/9/17
to bazel-...@googlegroups.com
On 2017-05-09 14:18, 'Kristina Chodorow' via bazel-discuss wrote:
> Um... maybe? Since this is an open source repo, can you give me the actual
> code you're trying?

tools/debug.bzl (new file):

def _debug_impl(ctx):
print("This rule does nothing")

debug = rule(implementation=_debug_impl)

tools/lcm.BUILD:

load("@//tools:debug.bzl", "debug")

...

debug(name="hello")

--
Matthew

Kristina Chodorow

unread,
May 9, 2017, 2:32:43 PM5/9/17
to Matthew Woehlke, bazel-...@googlegroups.com
Drake's tools/bazel.rc is filtering out all non-main-repo debug messages:

# Only show warnings from Drake, not from externals.
build --output_filter="^//"

You can comment it out for development.

--
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.
Reply all
Reply to author
Forward
0 new messages