Skip to content

module extension not re-evaluated when env variable is modified #22404

@laurentlb

Description

@laurentlb

Description of the bug:

TL;DR: Extension modules that use ctx.getenv are not re-evaluated when the env variable is modified.

Repro.

I have a simple MODULE file:

$ cat ../repro/MODULE.bazel
my_repo = use_extension("//:ext.bzl", "my_repo")
use_repo(my_repo, "repo")

and the extension ext.bzl:

def _impl(ctx):
  print("MYVAR", ctx.getenv("MYVAR"))
  # ...

my_repo = module_extension(implementation = _impl)

Steps:

  1. During the build, notice that the print statement is correctly evaluated.
  2. Modify the environment variable (e.g. MYVAR=abc bazel build ...)
  3. Notice that the print statement is not re-executed.

I've noticed that repository rules are re-evaluated if I use ctx.getenv, but module extensions are not. Is it working as intended?

To me, this seems error-prone and can lead to correctness issues. I fail to see how ctx.getenv can be used in a safe way.

Which category does this issue belong to?

External Dependency

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

No response

Which operating system are you running Bazel on?

MacOS

What is the output of bazel info release?

release 7.1.0

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse HEAD ?

No response

Is this a regression? If yes, please try to identify the Bazel commit where the bug was introduced.

No response

Have you found anything relevant by searching the web?

No response

Any other information, logs, or outputs that you want to share?

No response

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions