Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bazel macro fails with `name 'glob' is not defined`

Tags:

macros

bazel

I defined a Bazel macro. It looks something like this:

def my_macro():
    java_binary(
        srcs = glob(["*.java"])
        # ...
    )

When I run Bazel, it fails with an error

ERROR: /home/.../macros.bzl:105:19: name 'glob' is not defined

Is it possible to use glob in a macro?

like image 996
user7610 Avatar asked Oct 29 '25 09:10

user7610


1 Answers

The glob function is only available in BUILD.bazel files. In macro definitions in a .bzl file, access it as native.glob.

def my_macro():
    java_binary(
        srcs = native.glob(["*.java"])
        # ...
    )

References: https://groups.google.com/forum/#!topic/bazel-discuss/sXa60DnjxiA

like image 188
user7610 Avatar answered Nov 01 '25 06:11

user7610



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!