Created
March 5, 2025 23:39
-
-
Save alexeagle/a7b9daa6c565318dd68f5c572fd4b82e to your computer and use it in GitHub Desktop.
Gazelle test fixture
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
{ "imports": ["b", "lib/l"], "testonly": 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
{ "imports": ["lib/l"], "testonly": false } |
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
# empty |
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
load("@deps-test//my:rules.bzl", "x_lib") | |
x_lib( | |
name = "a_lib", | |
testonly = True, | |
srcs = ["a.json"], | |
deps = [ | |
":b_lib", | |
"//lib:l_lib", | |
], | |
) | |
x_lib( | |
name = "b_lib", | |
testonly = False, | |
srcs = ["b.json"], | |
deps = ["//lib:l_lib"], | |
) |
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
aspect.register_rule_kind("x_lib", { | |
"From": "@deps-test//my:rules.bzl", | |
"MergeableAttrs": ["srcs"], | |
"ResolveAttrs": ["deps"], | |
}) | |
def prepare(_): | |
return aspect.PrepareResult( | |
# All source files to be processed | |
sources = aspect.SourceExtensions(".json"), | |
queries = { | |
# A query treated as an array of results | |
"imports": aspect.JsonQuery( | |
filter = "*.json", | |
query = ".imports[]?", | |
), | |
# A query treated as a singleton which may have 0 results | |
"is_test": aspect.JsonQuery( | |
filter = "*.json", | |
query = """.testonly?""", | |
), | |
}, | |
) | |
def declare(ctx): | |
for file in ctx.sources: | |
ctx.targets.add( | |
name = file.path[:file.path.rindex(".")] + "_lib", | |
kind = "x_lib", | |
attrs = { | |
"srcs": [file.path], | |
"testonly": file.query_results["is_test"][0] if len(file.query_results["is_test"]) else None, | |
"deps": [ | |
aspect.Import( | |
id = i, | |
provider = "x", | |
src = file.path, | |
) | |
for i in file.query_results["imports"] | |
if i | |
], | |
}, | |
symbols = [aspect.Symbol( | |
id = "/".join([ctx.rel, file.path.removesuffix(".json")]) if ctx.rel else file.path.removesuffix(".json"), | |
provider = "x", | |
)], | |
) | |
aspect.register_configure_extension( | |
id = "jsonq-test", | |
prepare = prepare, | |
declare = declare, | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment