Skip to content

Commit 5132dd4

Browse files
UebelAndrefmeum
andauthored
Add ShInfo and ShBinaryInfo providers (#47)
closes #16 --------- Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
1 parent 1e8bab6 commit 5132dd4

5 files changed

Lines changed: 85 additions & 2 deletions

File tree

shell/private/providers.bzl

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2026 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""rules_shell provider definitions."""
16+
17+
visibility("public")
18+
19+
ShInfo = provider(
20+
doc = "A provider for shell library rules.",
21+
fields = {},
22+
)
23+
24+
ShBinaryInfo = provider(
25+
doc = "A provider for shell binary rules.",
26+
fields = {},
27+
)

shell/private/sh_executable.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
"""Common code for sh_binary and sh_test rules."""
1616

17+
load(":providers.bzl", "ShBinaryInfo", "ShInfo")
18+
1719
visibility(["//shell"])
1820

1921
_SH_TOOLCHAIN_TYPE = Label("//shell:toolchain_type")
@@ -24,6 +26,9 @@ def _to_rlocation_path(ctx, file):
2426
else:
2527
return ctx.workspace_name + "/" + file.short_path
2628

29+
# A memory optimization for an empty provider
30+
_SHARED_PROVIDER = ShBinaryInfo()
31+
2732
def _sh_executable_impl(ctx):
2833
if len(ctx.files.srcs) != 1:
2934
fail("you must specify exactly one file in 'srcs'", attr = "srcs")
@@ -117,6 +122,7 @@ exec "$(rlocation "{src}")" "$@"
117122
default_info,
118123
instrumented_files_info,
119124
run_environment_info,
125+
_SHARED_PROVIDER,
120126
]
121127

122128
_WINDOWS_EXECUTABLE_EXTENSIONS = [
@@ -200,7 +206,7 @@ The file containing the shell script.
200206
flags = ["SKIP_CONSTRAINTS_OVERRIDE"],
201207
),
202208
"deps": attr.label_list(
203-
allow_rules = ["sh_library"],
209+
providers = [ShInfo],
204210
doc = """
205211
The list of "library" targets to be aggregated into this target.
206212
See general comments about <code>deps</code>
@@ -228,5 +234,6 @@ most build rules</a>.
228234
toolchains = [
229235
config_common.toolchain_type(_SH_TOOLCHAIN_TYPE, mandatory = False),
230236
],
237+
provides = [ShBinaryInfo],
231238
**kwargs
232239
)

shell/private/sh_library.bzl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,14 @@
1414

1515
"""sh_library rule definition."""
1616

17+
load(":providers.bzl", "ShInfo")
18+
1719
# For doc generation only.
1820
visibility("public")
1921

22+
# A memory optimization for an empty provider
23+
_SHARED_PROVIDER = ShInfo()
24+
2025
def _sh_library_impl(ctx):
2126
transitive_files = []
2227
for target in ctx.attr.srcs:
@@ -41,6 +46,7 @@ def _sh_library_impl(ctx):
4146
runfiles = runfiles,
4247
),
4348
instrumented_files_info,
49+
_SHARED_PROVIDER,
4450
]
4551

4652
sh_library = rule(
@@ -101,7 +107,7 @@ The list of input files.
101107
flags = ["SKIP_CONSTRAINTS_OVERRIDE"],
102108
),
103109
"deps": attr.label_list(
104-
allow_rules = ["sh_library"],
110+
providers = [ShInfo],
105111
doc = """
106112
The list of "library" targets to be aggregated into this target.
107113
See general comments about <code>deps</code>
@@ -115,4 +121,5 @@ most build rules</a>.
115121
""",
116122
),
117123
},
124+
provides = [ShInfo],
118125
)

shell/sh_binary_info.bzl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2026 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""ShInfo provider definition."""
16+
17+
load("//shell/private:providers.bzl", _ShBinaryInfo = "ShBinaryInfo")
18+
19+
visibility("public")
20+
21+
ShBinaryInfo = _ShBinaryInfo

shell/sh_info.bzl

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2026 The Bazel Authors. All rights reserved.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""ShInfo provider definition."""
16+
17+
load("//shell/private:providers.bzl", _ShInfo = "ShInfo")
18+
19+
visibility("public")
20+
21+
ShInfo = _ShInfo

0 commit comments

Comments
 (0)