[8.6.0] Add a target_type argument to ctx.actions.symlink.#28538
[8.6.0] Add a target_type argument to ctx.actions.symlink.#28538iancha1992 merged 1 commit intobazelbuild:release-8.6.0from
target_type argument to ctx.actions.symlink.#28538Conversation
There was a problem hiding this comment.
Code Review
This pull request adds a target_type argument to ctx.actions.symlink. This is useful on Windows for creating the correct type of filesystem object (junction or symlink) when the target does not yet exist. The changes correctly plumb this new argument through to the VFS layer and update the action key for caching. I've found a minor issue in one of the new tests that could cause it to fail.
| ctx.actions.symlink( | ||
| output = link, | ||
| target_path = ctx.attr.target_path, | ||
| target_type = ctx.attr.target_type or None, |
There was a problem hiding this comment.
The expression ctx.attr.target_type or None will evaluate to "" if ctx.attr.target_type is an empty string. Since target_type is a string attribute, its default value if not specified is "". This will cause ctx.actions.symlink to receive "" for the targetType parameter, which is not a valid value ("file" or "directory"), leading to an error.
To correctly handle the case where target_type is unspecified or empty and should be treated as None, please change the expression to ctx.attr.target_type if ctx.attr.target_type else None. This will ensure that None is passed to ctx.actions.symlink, which is correctly handled as SymlinkTargetType.UNSPECIFIED.
| target_type = ctx.attr.target_type or None, | |
| target_type = ctx.attr.target_type if ctx.attr.target_type else None, |
This is necessary to create the right kind of filesystem object on Windows (junction for directories, symlink for files) when the target does not yet exist. This argument is only allowed in conjunction with `target_path`. For `target_file`, I have a different plan (infer the type from the artifact) which will be implemented separately. Fixes bazelbuild#26701. Progress on bazelbuild#21747. RELNOTES: `ctx.actions.symlink` now accepts a `target_type` argument. PiperOrigin-RevId: 820670309 Change-Id: I2f29adfd074c404a0b15be369a97fcdfb84fbdad
133acba to
7bb43d4
Compare
The `target_type` argument for `ctx.actions.symlink` has been cherry-picked into the Bazel 8.6.0 release branch via bazelbuild/bazel#28538. Ref: bazelbuild/bazel#27949 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
### What does this PR do? Bump `.bazelversion` from 8.5.1 to 8.6.0. ### Motivation Selected changes between 8.5.1 and 8.6.0: - Fix visibility for implicit deps of parent rules (bazelbuild/bazel#28722) - Force rctx.{download_and,}extract to create user-readable files (bazelbuild/bazel#28551) - Fix disk cache failures on concurrent read-write access on Windows (bazelbuild/bazel#28529) - Add a target_type argument to ctx.actions.symlink (bazelbuild/bazel#28538) - Compensate for Windows filesystems lacking junction support (bazelbuild/bazel#28367) (our fix) - Add short_uncached and detailed_uncached options to --test_summary (bazelbuild/bazel#28343) - Add --experimental_strict_repo_env option (bazelbuild/bazel#28189) - Make overlaid files executable in http_archive (bazelbuild/bazel#28277) - Add bazel mod show_repo --all_repos and --all_visible_repos (bazelbuild/bazel#28012) - Enable --experimental_retain_test_configuration_across_testonly (bazelbuild/bazel#28115) - Add option to continue with local execution if remote cache is unavailable (bazelbuild/bazel#28001)
### What does this PR do? Bump `.bazelversion` from 8.5.1 to 8.6.0. ### Motivation Selected changes between 8.5.1 and 8.6.0: - Fix visibility for implicit deps of parent rules (bazelbuild/bazel#28722) - Force rctx.{download_and,}extract to create user-readable files (bazelbuild/bazel#28551) - Fix disk cache failures on concurrent read-write access on Windows (bazelbuild/bazel#28529) - Add a target_type argument to ctx.actions.symlink (bazelbuild/bazel#28538) - Compensate for Windows filesystems lacking junction support (bazelbuild/bazel#28367) (our fix) - Add short_uncached and detailed_uncached options to --test_summary (bazelbuild/bazel#28343) - Add --experimental_strict_repo_env option (bazelbuild/bazel#28189) - Make overlaid files executable in http_archive (bazelbuild/bazel#28277) - Add bazel mod show_repo --all_repos and --all_visible_repos (bazelbuild/bazel#28012) - Enable --experimental_retain_test_configuration_across_testonly (bazelbuild/bazel#28115) - Add option to continue with local execution if remote cache is unavailable (bazelbuild/bazel#28001)
### What does this PR do? Bump `bazel` version from 8.5.1 to 8.6.0 to benefit from a series of improvements and fixes. Ours (bazelbuild/bazel#28367) allows to re-enable "convenience symlinks" for Windows users and makes [`path.realpath`](https://bazel.build/rules/lib/builtins/path#realpath) succeed when sharing a folder between a Linux host and a Windows VM. ### Motivation Selected changes between 8.5.1 and 8.6.0: - 💡 bazelbuild/bazel#28001 - bazelbuild/bazel#28012 - 💡 bazelbuild/bazel#28189 - bazelbuild/bazel#28277 - bazelbuild/bazel#28343 - 🐕 bazelbuild/bazel#28367 - bazelbuild/bazel#28529 - bazelbuild/bazel#28538 - bazelbuild/bazel#28551 - bazelbuild/bazel#28722 Co-authored-by: regis.desgroppes <regis.desgroppes@datadoghq.com>
The `target_type` argument for `ctx.actions.symlink` has been cherry-picked into the Bazel 8.6.0 release branch via bazelbuild/bazel#28538. Bazel 8.6.0 milestone: bazelbuild/bazel#27949 Follow-up to #124. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
This is necessary to create the right kind of filesystem object on Windows (junction for directories, symlink for files) when the target does not yet exist.
This argument is only allowed in conjunction with
target_path. Fortarget_file, I have a different plan (infer the type from the artifact) which will be implemented separately.Fixes #26701.
Progress on #21747.
RELNOTES:
ctx.actions.symlinknow accepts atarget_typeargument.PiperOrigin-RevId: 820670309
Change-Id: I2f29adfd074c404a0b15be369a97fcdfb84fbdad