Is it possible to get $pwd value from Bazel .bzl rule?

Viewed 3799

I am trying to get a value of the full current directory path from within .bzl rule. I have tried following:

  1. ctx.host_configuration.default_shell_env.PATH returns "/Users/[user_name]/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:...

  2. ctx.bin_dir.path returns bazel-out/local-fastbuild/bin

  3. pwd = ctx.expand_make_variables("cmd", "$$PWD", {}) returns string $PWD - I don't think this rule is helpful for me, but may be just using it wrong.

What I need is the directory under which the cmd that runs Bazel .bzl rule is running. For example: /Users/[user_name]/git/workspace/path/to/bazel/rule.bzl or at least first part of the path prior to the WORKSPACE directory.

I can't use pwd because I need this value before I call ctx.actions.run_shell()

Are there no attributes in Bazel configurations that hold this value?

1 Answers
Related