Description of the problem / feature request:
Using --repo_env to invalidate a repository rule has inconsistent behavior between a first-time run with vs. without --repo_env added.
Also there is strange behavior between bazel shutdown and re-running bazel build with the repo_env option where a download re-occurs everytime when repo_env was first used, but does not re-occur when it was not used (caching problem).
And finally changing values of repo_env for env vars that a repository rule does not declare it cares about with repository_ctx.environ will cause it to be reran anyway.
Feature requests: what underlying problem are you trying to solve with this feature?
I am trying to use --repo_env to make repository rules that declare a dependency via environ on an env var to be rerun only when the env var changes.
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
- Create an empty
BUILD.bazel file
- Create a
WORKSPACE file
load("//:my_repository_rule.bzl", "my_repository_rule")
my_repository_rule(
name = "my_repository_rule",
)
- Create a
my_repository_rule.bzl file
def _my_repository_rule_impl(rctx):
foo = rctx.os.environ.get("foo", default = "")
print('foo = ' + foo)
rctx.file("BUILD.bazel", """
genrule(
name = "test",
srcs = [],
outs = ["test.txt"],
cmd = "echo test > $@",
)
""")
rctx.download_and_extract(
url = "https://github.com/torvalds/linux/archive/v5.2.zip"
)
my_repository_rule = repository_rule(
environ = ["foo"],
implementation = _my_repository_rule_impl,
)
Enter a docker shell with the latest bazel release.
docker run -it -v $(pwd):/bazel -v $(pwd)/../bazel-cache:/root/.cache/bazel --workdir /bazel --entrypoint /bin/bash l.gcr.io/google/bazel:0.28.0
Run various bazel build commands and view inconsistent behaviors.
Make sure to exit the docker shell and do sudo rm -rf ../bazel-cache between below examples.
# First time run without --repo_env, downloads as expected
bazel build @my_repository_rule//...
# Now add --repo_env, does not redownload which is a problem
bazel build --repo_env=foo=bar @my_repository_rule//...
# First time run with --repo_env=foo=bar, downloads as expected
bazel build --repo_env=foo=bar @my_repository_rule//...
# Change --repo_env value, redownloads as expected
bazel build --repo_env=foo=baz @my_repository_rule//...
# Remove --repo_env, redownloads as expected
bazel build @my_repository_rule//...
# Now add --repo_env, does not redownload which is a problem
bazel build --repo_env=foo=bar @my_repository_rule//...
# First time run without --repo_env, downloads as expected
bazel build @my_repository_rule//...
bazel shutdown
# Re-run, does not redownload as expected
bazel build @my_repository_rule//...
# First time run with --repo_env=foo=bar, downloads as expected
bazel build --repo_env=foo=bar @my_repository_rule//...
bazel shutdown
# Re-run with same value of repo_env, it redownloads again which is a problem
bazel build --repo_env=foo=bar @my_repository_rule//...
# First time run with --repo_env=one=two, downloads as expected
# NOTE: my understanding is the repository rule should only care about values of foo because of environ = ["foo"]
bazel build --repo_env=one=two @my_repository_rule//...
# Change value to --repo_env=one=three, I expect it should not re-run because the rule does not declare that it cares about values of "one", however it redownloads which is a problem
bazel build --repo_env=one=three @my_repository_rule//...
What operating system are you running Bazel on?
Ubuntu 16.04
What's the output of bazel info release?
release 0.28.0
Any other information, logs, or outputs that you want to share?
#8074
cc @aehlig
Description of the problem / feature request:
Using
--repo_envto invalidate a repository rule has inconsistent behavior between a first-time run with vs. without--repo_envadded.Also there is strange behavior between
bazel shutdownand re-running bazel build with the repo_env option where a download re-occurs everytime when repo_env was first used, but does not re-occur when it was not used (caching problem).And finally changing values of repo_env for env vars that a repository rule does not declare it cares about with
repository_ctx.environwill cause it to be reran anyway.Feature requests: what underlying problem are you trying to solve with this feature?
I am trying to use
--repo_envto make repository rules that declare a dependency viaenvironon an env var to be rerun only when the env var changes.Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
BUILD.bazelfileWORKSPACEfilemy_repository_rule.bzlfileEnter a docker shell with the latest bazel release.
Run various bazel build commands and view inconsistent behaviors.
Make sure to exit the docker shell and do
sudo rm -rf ../bazel-cachebetween below examples.What operating system are you running Bazel on?
Ubuntu 16.04
What's the output of
bazel info release?release 0.28.0
Any other information, logs, or outputs that you want to share?
#8074
cc @aehlig