-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Copy over runfiles library from Bazel (#13)
This uses `root_symlinks` to preserve the fixed runfiles path at which the library must be available and the private `skip_conflict_checking` attribute to preserve backwards compatibility by not enabling strict runfiles path conflict checking.
- Loading branch information
Showing
10 changed files
with
1,019 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ matrix: | |
- windows | ||
bazel: | ||
- 6.5.0 | ||
- 7.3.2 | ||
- 7.4.0 | ||
|
||
tasks: | ||
test_module_bzlmod: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
workspace(name = "rules_shell") | ||
|
||
load("//shell:repositories.bzl", "rules_shell_dependencies", "rules_shell_toolchains") | ||
|
||
rules_shell_dependencies() | ||
|
||
rules_shell_toolchains() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Copyright 2024 The Bazel Authors. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Helper rule to preserve the legacy runfiles path for the runfiles lib.""" | ||
|
||
# Requires the private skip_conflict_checking parameter on ctx.runfiles, which | ||
# is only available as of Bazel 7.4.0. We only use it when the native shell | ||
# rules are not available. | ||
ROOT_SYMLINKS_SUPPORTED = not hasattr(native, "sh_binary") | ||
|
||
def _single_file_or_fail(target): | ||
files = target[DefaultInfo].files.to_list() | ||
if len(files) != 1: | ||
fail("Expected exactly one file in {}, got {}".format(target.label, files)) | ||
return files[0] | ||
|
||
def _root_symlinks_impl(ctx): | ||
runfiles = ctx.runfiles( | ||
root_symlinks = { | ||
path: _single_file_or_fail(target) | ||
for target, path in ctx.attr.root_symlinks.items() | ||
}, | ||
# Adding root symlinks from Starlark usually enables conflict checking, | ||
# but that would break backwards compatibility as it affects all | ||
# runfiles, not just the symlinks. | ||
skip_conflict_checking = True, | ||
) | ||
return [ | ||
DefaultInfo( | ||
files = depset(), | ||
runfiles = runfiles, | ||
), | ||
] | ||
|
||
root_symlinks = rule( | ||
implementation = _root_symlinks_impl, | ||
attrs = { | ||
"root_symlinks": attr.label_keyed_string_dict( | ||
allow_files = True, | ||
mandatory = True, | ||
), | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
load("//shell:sh_library.bzl", "sh_library") | ||
load("//shell/private:root_symlinks.bzl", "ROOT_SYMLINKS_SUPPORTED", "root_symlinks") | ||
|
||
alias( | ||
name = "runfiles", | ||
actual = ":runfiles_impl" if ROOT_SYMLINKS_SUPPORTED else "@bazel_tools//tools/bash/runfiles", | ||
visibility = ["//visibility:public"], | ||
) | ||
|
||
sh_library( | ||
name = "runfiles_impl", | ||
data = [":runfiles_at_legacy_location"], | ||
tags = ["manual"], | ||
) | ||
|
||
root_symlinks( | ||
name = "runfiles_at_legacy_location", | ||
root_symlinks = { | ||
"runfiles.bash": "bazel_tools/tools/bash/runfiles/runfiles.bash", | ||
}, | ||
tags = ["manual"], | ||
) |
Oops, something went wrong.