-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Do not force unresolved symlinks to be absolute #15982
Conversation
@gregmagolan Could you give this a try? It implements #15963 (comment), but with a catch: |
ab1ca26
to
028a59a
Compare
For sure. I'll try it out this morning. |
The documentation of `ctx.actions.symlink(target_path = ...)` states that the given path is used as the symlink target without any changes, but in reality this path has so far always been converted into an absolute path by prepending the exec root. This is changed by this commit, which gets very close to the documented behavior by preserving the target path as is except for the standard normalization applied by `PathFragment`. Improving the situation even further would require modifying or adding to Bazel's core file system API, which may be done in a follow-up PR. Since relative symlinks only resolve correctly at the location they were originally created, they have to be handled specially when staged as runfiles. This commit adds a new `declared_symlinks` parameter to the rule context's `runfiles` method that takes in symlink artifacts declared via `ctx.actions.declare_symlink`. These symlinks are staged at their runfiles path directly, with no further processing of their target and without any intermediate runfiles pointing back to the artifact's location under the exec root. This has to main benefits: * With local execution, symlinks are resolved within the runfiles tree, which is more hermetic than following the runfiles symlink back into the exec root and resolving the symlink artifact there. * Actions can expect symlink artifacts to be stages as is without intermediate symlinks with local and sandboxed execution, both inside and outside the runfiles tree. This is important for packaging actions as well as rulesets sensitive to symlinks (e.g. rules_js). As a side-effect of the switch to relative symlinks, this commit resolves a non-hermeticity issue observed in bazelbuild#10298 (comment) Integration tests are added to verify that symlinks staged in the sandbox are no longer resolved non-hermetically. Fixes bazelbuild#14224
028a59a
to
f6bef33
Compare
Hmmm. The distinction is going to be problematic I think as it will leak out beyond the point where declare_symlink is called and into other rules that will not know which input is a symlink and which is a file. When downstream rules create runfiles they'll hit errors such as,
Can the differentiate be done implicitly in the runfiles action by checking which is a symlink and which isn't? Perhaps an |
I have the changes to rules_js to go with this branch in a Draft PR here aspect-build/rules_js#313 if you wanted to try the out |
The documentation of
ctx.actions.symlink(target_path = ...)
statesthat the given path is used as the symlink target without any changes,
but in reality this path has so far always been converted into an
absolute path by prepending the exec root. This is changed by this
commit, which gets very close to the documented behavior by preserving
the target path as is except for the standard normalization applied by
PathFragment
. Improving the situation even further would requiremodifying or adding to Bazel's core file system API, which may be done
in a follow-up PR.
Since relative symlinks only resolve correctly at the location they were
originally created, they have to be handled specially when staged as
runfiles. This commit adds a new
declared_symlinks
parameter to therule context's
runfiles
method that takes in symlink artifactsdeclared via
ctx.actions.declare_symlink
. These symlinks are staged attheir runfiles path directly, with no further processing of their target
and without any intermediate runfiles pointing back to the artifact's
location under the exec root. This has to main benefits:
which is more hermetic than following the runfiles symlink back into
the exec root and resolving the symlink artifact there.
intermediate symlinks with local and sandboxed execution, both inside
and outside the runfiles tree. This is important for packaging actions
as well as rulesets sensitive to symlinks (e.g. rules_js).
As a side-effect of the switch to relative symlinks, this commit
resolves a non-hermeticity issue observed in
#10298 (comment)
Integration tests are added to verify that symlinks staged in the
sandbox are no longer resolved non-hermetically.
Fixes #14224