Skip to content

Bazelisk 1.6.0 overwrites PATH #149

Closed
@spietras

Description

@spietras

I was writing some repository rules and I just couldn't get why the PATH variable stored only the path to the Bazel binary, no matter what combination of --action_envs or --repo_envs I used (and now I know they don't even matter in the case of repository rules and PATH).

After some time of feeling hopeless, my mind was struck by the idea of executing Bazel directly, not by Bazelisk. And... this timePATH was the same as the system one. That gave me just a little bit of hope that I'm not actually going insane.

So after that, I decided to try the previous version of Bazelisk, 1.5.0, and PATH was also the same as the system one.

Patch notes for 1.6.0 say:

Bazelisk now runs Bazel with a $PATH set so that running the bazel command resolves to the correct Bazel version. For example, this is useful if you have shell scripts or tests that invoke bazel - these will now pick the right version of Bazel. Thanks for the contribution @coeuvre! (#111)

and #111 says:

Bazelisk subprocesses should prepend the correct bazel to the $PATH

So it seems that instead of prepending, Bazelisk is overwriting PATH. Or I'm misunderstanding something.

I'm on Windows btw.

Activity

philwo

philwo commented on Aug 15, 2020

@philwo
Member

@coeuvre Could you have a look please?

coeuvre

coeuvre commented on Aug 17, 2020

@coeuvre
Member

I have tested with following setup in linux and mac and it works as expected. Will test it on windows soon.

$ touch WORKSPACE
$ cat > BUILD <<'EOF'
genrule(
  name = "test",
  srcs = [],
  cmd = "echo $$PATH > $@",
  outs = ["out.txt"],
)
EOF
$ bazelisk build :test
$ cat bazel-bin/out.txt # should contain the content of PATH

Can you also provide steps to reproduce the bug? Thanks!

spietras

spietras commented on Aug 17, 2020

@spietras
Author

Ok, I also tested it on Linux and it seems to work there. It's just not working on Windows:

  • defs.bzl:

    def _some_rule_impl(repo_ctx):
        print(repo_ctx.os.environ["PATH"])
        repo_ctx.file("test")
        repo_ctx.file("BUILD", 
                      content = """exports_files(["test"])""")
    
    _some_rule = repository_rule(_some_rule_impl)
    
    def some_rule():
        _some_rule(name="some")
    
  • WORKSPACE:

    load("defs.bzl", "some_rule")
    
    some_rule()
    
  • BUILD:

    filegroup(
        name = "test",
        srcs = ["@some//:test"]
    )
    

Now try bazelisk build test and compare with echo %PATH%.

Maybe it's some issue with path separators or slashes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type:bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Participants

    @philwo@coeuvre@spietras

    Issue actions

      Bazelisk 1.6.0 overwrites PATH · Issue #149 · bazelbuild/bazelisk