rules_itest icon indicating copy to clipboard operation
rules_itest copied to clipboard

feat: improved env substitutions

Open peakschris opened this issue 10 months ago • 1 comments

This PR supports additional substitutions on env values supplied in env parameter to itest rules. Substitutions are:

  1. $(location... etc as previously supported
  2. $(OTHERENV)/extra - substitute a different envvar from the input env parameter into this value
  3. $(TESTENV)/extra - substitute TESTENV supplied via bazel's --test_env parameter into this value
  4. $(BINDIR) - relative path to bazel's bin directory

This provides extra flexibility for configuring test cases.

To support this, I found a nicely designed implementation of envvar substitution in environment.bzl in rules_bats, and rather than adding a dependency on rules_bats, I have vendored the file into this repo. It seems that the author has tried to get this file added to bazel_skylib (https://github.com/bazelbuild/bazel-skylib/pull/486), and perhaps it has a future in bazel-lib. If this happened, this vendored copy could be deleted.

This PR is draft for now for feedback/guidance.

(there is also included a minor fix to windows path which prevents bazel run //service from working on windows at present)

peakschris avatar Feb 10 '25 22:02 peakschris

@peakschris I'm a bit worried about increasing analysis time work. If we passed the env vars through os.ExpandEnv on the execution side would that work for you? (See https://pkg.go.dev/os#example-ExpandEnv). We could also apply BINDIR substitution.

dzbarsky avatar Jun 19 '25 14:06 dzbarsky