bazelbuild / bazel

a fast, scalable, multi-language and extensible build system
https://bazel.build
Apache License 2.0
23.21k stars 4.06k forks source link

Python: use execpath semantics for $(location) expansion #15294

Open rickeylev opened 2 years ago

rickeylev commented 2 years ago

Description of the feature request:

Today, the Python rules, because they're Java-implemented, use rootpath (runfiles-root relative) expansion semantics when expanding $(location) in e.g. env, etc. I came across this while re-implementing location expansion for the env attribute. (aside: i saw this for env, but i think args uses the same underlying code, but didn't actually check behavior for args).

This poses a few problems:

  1. $(location) is "discouraged", per https://docs.bazel.build/versions/main/be/make-variables.html#predefined_label_variables (Discouraging $(location) makes sense IMHO.)
  2. Starlark doesn't expose apis to make $(location) act like $(rootpath). The ctx.expand_location function acts like $(execpath).
  3. Changing from rootpath to execpath is a backwards incompatible change. This is because most everything put in srcs, deps, or data end up in runfiles (with a few exceptions), so address a file from them using runfile-relative paths is technically valid (it just changes how the binary accesses the file).

Because the main usage of location-expansion is for args and env, where some other input is being passed as an input to the test/binary, using execpath makes sense -- such inputs don't need to be part of the runfiles, and including them in the runfiles is just bloat for the underlying binary (fixing that is it's own change I think).

So I propose that the Python rules use execpath semantics for $location expansion.

What underlying problem are you trying to solve with this feature?

Making the rules more consistent and possible to implement in pure-starlark

Which operating system are you running Bazel on?

Linux

What is the output of bazel info release?

google build

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

google build

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

n/a

Have you found anything relevant by searching the web?

Not too much, really. There are sort of related discussions centering around genrule's behavior here, but that's a different rule.

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

No response

comius commented 2 years ago

So I propose that the Python rules use execpath semantics for $location expansion.

LGTM

github-actions[bot] commented 1 year ago

Thank you for contributing to the Bazel repository! This issue has been marked as stale since it has not had any activity in the last 1+ years. It will be closed in the next 14 days unless any other activity occurs or one of the following labels is added: "not stale", "awaiting-bazeler". Please reach out to the triage team (@bazelbuild/triage) if you think this issue is still relevant or you are interested in getting the issue resolved.