diff --git a/bzl_library.bzl b/bzl_library.bzl
index 9091894f..a139386e 100644
--- a/bzl_library.bzl
+++ b/bzl_library.bzl
@@ -54,10 +54,7 @@ bzl_library = rule(
),
"deps": attr.label_list(
allow_files = [".bzl", ".scl"],
- providers = [
- [StarlarkLibraryInfo],
- ],
- doc = """List of other `bzl_library` targets that are required by the
+ doc = """List of other `bzl_library` or `filegroup` targets that are required by the
Starlark files listed in `srcs`.""",
),
},
diff --git a/docs/bzl_library.md b/docs/bzl_library.md
index f4b0dc7e..b826e5f9 100755
--- a/docs/bzl_library.md
+++ b/docs/bzl_library.md
@@ -63,7 +63,7 @@ Example:
| Name | Description | Type | Mandatory | Default |
| :------------- | :------------- | :------------- | :------------- | :------------- |
| name | A unique name for this target. | Name | required | |
-| deps | List of other bzl_library
targets that are required by the Starlark files listed in srcs
. | List of labels | optional | []
|
+| deps | List of other bzl_library
or filegroup
targets that are required by the Starlark files listed in srcs
. | List of labels | optional | []
|
| srcs | List of .bzl
and .scl
files that are processed to create this target. | List of labels | optional | []
|
diff --git a/tests/bzl_library/BUILD b/tests/bzl_library/BUILD
new file mode 100644
index 00000000..6f8ae5cf
--- /dev/null
+++ b/tests/bzl_library/BUILD
@@ -0,0 +1,32 @@
+load("//:bzl_library.bzl", "bzl_library")
+load(":bzl_library_test.bzl", "bzl_library_test")
+
+filegroup(
+ name = "a",
+ srcs = ["a.bzl"],
+)
+
+bzl_library(
+ name = "b",
+ srcs = ["b.bzl"],
+)
+
+bzl_library(
+ name = "c",
+ srcs = ["c.bzl"],
+ deps = [
+ ":a",
+ ":b",
+ ],
+)
+
+bzl_library_test(
+ name = "bzl_library_test",
+ expected_srcs = ["c.bzl"],
+ expected_transitive_srcs = [
+ "a.bzl",
+ "b.bzl",
+ "c.bzl",
+ ],
+ target_under_test = ":c",
+)
diff --git a/tests/bzl_library/a.bzl b/tests/bzl_library/a.bzl
new file mode 100644
index 00000000..01be5e09
--- /dev/null
+++ b/tests/bzl_library/a.bzl
@@ -0,0 +1,3 @@
+"""a.bzl, livin' its best life"""
+
+A = 30
diff --git a/tests/bzl_library/b.bzl b/tests/bzl_library/b.bzl
new file mode 100644
index 00000000..254ca450
--- /dev/null
+++ b/tests/bzl_library/b.bzl
@@ -0,0 +1,3 @@
+"""b.bzl, havin' a grand time"""
+
+B = 70
diff --git a/tests/bzl_library/bzl_library_test.bzl b/tests/bzl_library/bzl_library_test.bzl
new file mode 100644
index 00000000..1e01a296
--- /dev/null
+++ b/tests/bzl_library/bzl_library_test.bzl
@@ -0,0 +1,40 @@
+"""Unit tests for bzl_library"""
+
+load("//:bzl_library.bzl", "StarlarkLibraryInfo")
+load("//lib:sets.bzl", "sets")
+load("//lib:unittest.bzl", "analysistest", "asserts")
+
+def _assert_same_files(env, expected_file_targets, actual_files):
+ """Assertion that a list of expected file targets and an actual list or depset of files contain the same files"""
+ expected_files = []
+ for target in expected_file_targets:
+ target_files = target[DefaultInfo].files.to_list()
+ asserts.true(env, len(target_files) == 1, "expected_file_targets must contain only file targets")
+ expected_files.append(target_files[0])
+ if type(actual_files) == "depset":
+ actual_files = actual_files.to_list()
+ asserts.set_equals(env = env, expected = sets.make(expected_files), actual = sets.make(actual_files))
+
+def _bzl_library_test_impl(ctx):
+ env = analysistest.begin(ctx)
+ target_under_test = analysistest.target_under_test(env)
+ _assert_same_files(env, ctx.attr.expected_srcs, target_under_test[StarlarkLibraryInfo].srcs)
+ _assert_same_files(env, ctx.attr.expected_transitive_srcs, target_under_test[StarlarkLibraryInfo].transitive_srcs)
+ _assert_same_files(env, ctx.attr.expected_transitive_srcs, target_under_test[DefaultInfo].files)
+ return analysistest.end(env)
+
+bzl_library_test = analysistest.make(
+ impl = _bzl_library_test_impl,
+ attrs = {
+ "expected_srcs": attr.label_list(
+ mandatory = True,
+ allow_files = True,
+ doc = "Expected direct srcs in target_under_test's providers",
+ ),
+ "expected_transitive_srcs": attr.label_list(
+ mandatory = True,
+ allow_files = True,
+ doc = "Expected transitive srcs in target_under_test's providers",
+ ),
+ },
+)
diff --git a/tests/bzl_library/c.bzl b/tests/bzl_library/c.bzl
new file mode 100644
index 00000000..1380ece5
--- /dev/null
+++ b/tests/bzl_library/c.bzl
@@ -0,0 +1,6 @@
+"""c.bzl, standin' on the shoulder of giants"""
+
+load(":a.bzl", "A")
+load(":b.bzl", "B")
+
+C = A + B
diff --git a/tests/subpackages_tests.bzl b/tests/subpackages_tests.bzl
index 3c494d68..885d4724 100644
--- a/tests/subpackages_tests.bzl
+++ b/tests/subpackages_tests.bzl
@@ -21,6 +21,7 @@ def _all_test(env):
"""Unit tests for subpackages.all."""
all_pkgs = [
+ "bzl_library",
"common_settings",
"copy_directory",
"copy_file",
@@ -39,6 +40,7 @@ def _all_test(env):
# These exist in all cases
filtered_pkgs = [
+ "bzl_library",
"common_settings",
"copy_directory",
"copy_file",