Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ on:
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
bazel_version:
- "7.x"
- "8.x"
- "9.x"
- "latest"
- "rolling"
env:
USE_BAZEL_VERSION: ${{ matrix.bazel_version }}
steps:
- uses: actions/checkout@v4
- run: bazel build //...
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/bazel-*
/example/bazel-*
/example/producer/stlib_repo/MODULE.bazel*
/MODULE.bazel.lock
MODULE.bazel.lock
1 change: 1 addition & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ module(
name = "rules_runfiles_group",
)

bazel_dep(name = "bazel_features", version = "1.46.0")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
799 changes: 0 additions & 799 deletions example/MODULE.bazel.lock

This file was deleted.

5 changes: 3 additions & 2 deletions example/producer/rules/starlark_binary.bzl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Implementation of the starlark_binary rule."""

load("@hermetic_launcher//launcher:lib.bzl", "launcher")
load("@rules_runfiles_group//runfiles_group:lib.bzl", "lib")
load("@rules_runfiles_group//runfiles_group:providers.bzl", "RunfilesGroupInfo", "RunfilesGroupSelectionInfo")
load("//producer/providers:providers.bzl", "StarlarkInfo")

Expand Down Expand Up @@ -103,7 +104,7 @@ def _starlark_binary_impl(ctx):
ranks["entrypoint"] = 3
for dep in ctx.attr.deps:
if RunfilesGroupInfo in dep:
for name in dir(dep[RunfilesGroupInfo]):
for name in lib.group_names(dep[RunfilesGroupInfo]):
groups[name] = getattr(dep[RunfilesGroupInfo], name)
if _extract_repo(name) == current_repo:
ranks[name] = 3
Expand All @@ -115,7 +116,7 @@ def _starlark_binary_impl(ctx):
ranks[current_repo] = 3
for dep in ctx.attr.deps:
if RunfilesGroupInfo in dep:
for name in dir(dep[RunfilesGroupInfo]):
for name in lib.group_names(dep[RunfilesGroupInfo]):
repo = _extract_repo(name)
if repo not in repo_depsets:
repo_depsets[repo] = []
Expand Down
3 changes: 2 additions & 1 deletion example/producer/rules/starlark_library.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""Implementation of the starlark_library rule."""

load("@rules_runfiles_group//runfiles_group:lib.bzl", "lib")
load("@rules_runfiles_group//runfiles_group:providers.bzl", "RunfilesGroupInfo")
load("//producer/providers:providers.bzl", "StarlarkInfo")

Expand All @@ -26,7 +27,7 @@ def _starlark_library_impl(ctx):
groups = {}
for dep in ctx.attr.deps:
if RunfilesGroupInfo in dep:
for name in dir(dep[RunfilesGroupInfo]):
for name in lib.group_names(dep[RunfilesGroupInfo]):
groups[name] = getattr(dep[RunfilesGroupInfo], name)

groups[str(ctx.label)] = depset(direct_srcs + ctx.files.data)
Expand Down
1 change: 1 addition & 0 deletions runfiles_group/private/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ bzl_library(
visibility = ["//:__subpackages__"],
deps = [
"//runfiles_group/private/providers:runfiles_group_info",
"@bazel_features//:features",
],
)
16 changes: 14 additions & 2 deletions runfiles_group/private/lib.bzl
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
"""Library for consuming and transforming RunfilesGroupInfo.

lib.group_names(runfiles_group_info)
Returns the list of group names in a RunfilesGroupInfo instance.

lib.ordered_groups(runfiles_group_info, selection_info = None)
Returns a list of (group_name, depset[File]) tuples, filtered and
sorted according to the selection. If selection_info is None, all
Expand All @@ -25,10 +28,18 @@ lib.transform_groups(runfiles_group_info, transform_info = None)
Calls transform(runfiles_group_info) and returns the result.
"""

load("@bazel_features//:features.bzl", "bazel_features")
load("//runfiles_group/private/providers:runfiles_group_info.bzl", "RunfilesGroupInfo")

# Bazel < 9 includes to_json/to_proto in dir() results for providers.
_PROVIDER_BUILTINS = [] if bazel_features.rules.no_struct_field_denylist else ["to_json", "to_proto"]

def _group_names(runfiles_group_info):
"""Returns the list of group names in a RunfilesGroupInfo instance."""
return [n for n in dir(runfiles_group_info) if n not in _PROVIDER_BUILTINS]

def _ordered_groups(runfiles_group_info, runfiles_group_selection_info = None):
all_names = dir(runfiles_group_info)
all_names = _group_names(runfiles_group_info)
selection = runfiles_group_selection_info

if selection == None:
Expand Down Expand Up @@ -74,7 +85,7 @@ def _transform_groups(runfiles_group_info, runfiles_transform_info = None):

merge_groups = runfiles_transform_info.merge_groups
treatment = runfiles_transform_info.unmatched_group_treatment
all_names = dir(runfiles_group_info)
all_names = _group_names(runfiles_group_info)
all_names_set = {name: True for name in all_names}

matched = {}
Expand Down Expand Up @@ -105,6 +116,7 @@ def _transform_groups(runfiles_group_info, runfiles_transform_info = None):
return RunfilesGroupInfo(**result)

lib = struct(
group_names = _group_names,
ordered_groups = _ordered_groups,
transform_groups = _transform_groups,
)
1 change: 1 addition & 0 deletions runfiles_group/private/rules/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ bzl_library(
srcs = ["runfiles_group_analysis_test.bzl"],
visibility = ["//:__subpackages__"],
deps = [
"//runfiles_group/private:lib",
"//runfiles_group/private/providers:runfiles_group_info",
"@bazel_skylib//lib:sets",
],
Expand Down
12 changes: 6 additions & 6 deletions runfiles_group/private/rules/runfiles_group_analysis_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ runfiles_group_analysis_test(
"""

load("@bazel_skylib//lib:sets.bzl", "sets")
load("//runfiles_group/private:lib.bzl", "lib")
load("//runfiles_group/private/providers:runfiles_group_info.bzl", "RunfilesGroupInfo")

_INDENT = " "
Expand All @@ -32,12 +33,13 @@ def _test_one(ctx, binary_attr):
runfiles_group_info = binary_attr[RunfilesGroupInfo]
if default_runfiles == None:
return (False, ["doesn't have default_runfiles to compare to."])

# Note: the following calculations are expensive.
# This analysis test is only meant to be used to test the correctness of
# RunfilesGroupInfo emitting rules. Do not use for all of your *_binary targets in prod.
all_default_runfiles = sets.make(default_runfiles.files.to_list())
all_grouped_runfiles = sets.make()
for group_depset_name in dir(runfiles_group_info):
for group_depset_name in lib.group_names(runfiles_group_info):
group_depset = getattr(runfiles_group_info, group_depset_name)
for file_from_group in group_depset.to_list():
sets.insert(all_grouped_runfiles, file_from_group)
Expand All @@ -61,7 +63,7 @@ def _test_one(ctx, binary_attr):
)

if ctx.attr.overlapping_group_behavior != "ignore":
group_names = dir(runfiles_group_info)
group_names = lib.group_names(runfiles_group_info)
for i in range(len(group_names)):
group_i = sets.make(getattr(runfiles_group_info, group_names[i]).to_list())
for j in range(i + 1, len(group_names)):
Expand All @@ -84,15 +86,13 @@ def _test_one(ctx, binary_attr):

return (success, issues)



def _runfiles_group_analysis_test_impl(ctx):
if len(ctx.attr.binaries) == 0:
return [AnalysisTestResultInfo(
success = False,
message = "runfiles_group_analysis_test with no binaries.",
)]

results = []
for binary_attr in ctx.attr.binaries:
results.append((binary_attr.label, _test_one(ctx, binary_attr)))
Expand All @@ -109,7 +109,7 @@ def _runfiles_group_analysis_test_impl(ctx):
"\n".join([_indent(issue) for issue in result[1]]),
),
)

return [AnalysisTestResultInfo(
success = success,
message = "\n".join(sections),
Expand Down
Loading