Debian Codegraph @

tools/skslc/compile_sksl.bzl

raw
1 """
2 This defines a macro to cut down on boiler plate for generating sksl test resources.
3 """
4
5 load("//bazel:macros.bzl", "py_binary")
6
7 def compile_sksl(name, lang, inputs, settings = "settings"):
8 """Creates a rule to compile the given sksl inputs
9
10 This macro creates a py_binary rule to invoke the //gn:compile_sksl_tests.py script and a
11 helper genrule which creates the list of all file names that should be processed by that
12 python script.
13
14 The generated py_binary rule is called compute_${name} and can be run via `bazel run`.
15
16 Args:
17 name: A string used to uniquely identify the generated compile and list rule.
18 lang: A string passed into the compile_sksl_tests.py script.
19 inputs: A filegroup label containing all the input files to be processed.
20 settings: A string passed into the compile_sksl_tests.py script.
21 """
22
23 # https://bazel.build/reference/be/python#py_binary
24 py_binary(
25 name = "compile_" + name,
26 main = ":sksl_compile_tests.py",
27 srcs = [":sksl_compile_tests.py"],
28 args = [
29 # comments are the variable names in compile_sksl_tests.py
30 "--" + lang, # lang
31 "--" + settings, # settings
32 "resources", # input_root_dir
33 "tests", # output_root_dir
34 "bazel-bin/tools/skslc/%s.txt" % name, # input_file
35 ],
36 data = [
37 ":%s.txt" % name,
38 inputs,
39 ":skslc",
40 "//gn:compile_sksl_tests",
41 ],
42 tags = ["no-remote-exec"],
43 )
44
45 native.genrule(
46 name = "enumerate_%s_list" % name, # This name does not really matter.
47 srcs = [inputs],
48 outs = [name + ".txt"],
49 # Put a space seperated list of file names into the one output
50 # This is done because the list could be quite long and overflow
51 # the command line length
52 # https://bazel.build/reference/be/make-variables#predefined_genrule_variables
53 cmd = "echo $(SRCS) > $@",
54 )