Debian Codegraph @

tools/sksl-minify/BUILD.bazel

raw
1 load("//bazel:macros.bzl", "py_binary")
2 load("//bazel:skia_rules.bzl", "skia_cc_binary")
3
4 package(
5 default_applicable_licenses = ["//:license"],
6 )
7
8 licenses(["notice"])
9
10 # Run these py_binary rules like bazel run //tools/sksl-minify:minify_srcs
11 # https://bazel.build/reference/be/python#py_binary
12 py_binary(
13 name = "minify_srcs",
14 srcs = [":sksl_minify_srcs.py"],
15 data = [
16 ":sksl_minify",
17 "//gn:minify_sksl",
18 "//src/sksl:sksl_data",
19 ],
20 main = ":sksl_minify_srcs.py",
21 # We can compile remotely, but because we are running the executable to modify files in
22 # the source tree, running it in a remote, sandboxed would have no effect locally.
23 tags = ["no-remote-exec"],
24 )
25
26 py_binary(
27 name = "minify_tests",
28 srcs = [":sksl_minify_tests.py"],
29 data = [
30 ":sksl_minify",
31 ":test_input_list.txt",
32 "//gn:minify_sksl_tests",
33 "//resources/sksl:sksl_minify_tests_sources",
34 ],
35 main = ":sksl_minify_tests.py",
36 tags = ["no-remote-exec"],
37 )
38
39 skia_cc_binary(
40 name = "sksl_minify",
41 srcs = ["SkSLMinify.cpp"],
42 deps = [
43 "//:core",
44 "//src/utils:get_executable_path",
45 "//tools/skslc:process_worklist",
46 ],
47 )
48
49 _SKSL_MINIFY_SRCS = """
50 import os
51 import subprocess
52 import glob
53
54 # Change into the Skia root directory
55 # https://bazel.build/docs/user-manual#running-executables
56 # Note: Bazel eats single quotes, so we must use double quotes.
57 os.chdir(os.environ["BUILD_WORKSPACE_DIRECTORY"])
58
59 # execpath returns the path to the given label relative to the Skia root.
60 # This will be something like:
61 # bazel-out/k8-opt-exec-81C6BA4F/bin/tools/sksl-minify/sksl_minify
62 # https://bazel.build/reference/be/make-variables#predefined_label_variables
63 # We then find the absolute path because this is easier to debug and more
64 # consistent if the script we are calling changes the working directory.
65 sksl_minify_exe = os.path.abspath("$(execpath //tools/sksl-minify:sksl_minify)")
66 minify_script = os.path.abspath("$(execpath //gn:minify_sksl)")
67
68 print(subprocess.check_output([
69 minify_script,
70 sksl_minify_exe,
71 "src/sksl/generated",
72 ] + glob.glob("src/sksl/*.sksl"), encoding="utf-8"))
73 """
74
75 genrule(
76 name = "create_sksl_minify_srcs_script",
77 srcs = [":sksl_minify"],
78 outs = ["sksl_minify_srcs.py"],
79 cmd = "echo '%s' > $@" % _SKSL_MINIFY_SRCS,
80 # note: tools are not transitive, so anything that depends on sksl_minify_srcs.sh
81 # should also specify these so they are properly built/available.
82 tools = [
83 "//gn:minify_sksl",
84 ],
85 )
86
87 _SKSL_MINIFY_TESTS = """
88 import os
89 import subprocess
90 import sys
91
92 # Change into the Skia root directory
93 # https://bazel.build/docs/user-manual#running-executables
94 # Note: Bazel eats single quotes, so we must use double quotes.
95 os.chdir(os.environ["BUILD_WORKSPACE_DIRECTORY"])
96
97 # execpath returns the path to the given label relative to the Skia root.
98 # This will be something like:
99 # bazel-out/k8-opt-exec-81C6BA4F/bin/tools/sksl-minify/sksl_minify
100 # https://bazel.build/reference/be/make-variables#predefined_label_variables
101 # We then find the absolute path because this is easier to debug and more
102 # consistent if the script we are calling changes the working directory.
103 sksl_minify_exe = os.path.abspath("$(execpath //tools/sksl-minify:sksl_minify)")
104 minify_script = os.path.abspath("$(execpath //gn:minify_sksl_tests)")
105 test_inputs = os.path.abspath("$(execpath :test_input_list.txt)")
106
107 result = subprocess.run([
108 minify_script,
109 sksl_minify_exe,
110 "src/sksl/sksl_shared.sksl",
111 "src/sksl/sksl_public.sksl",
112 "src/sksl/sksl_rt_shader.sksl",
113 "resources",
114 "tests",
115 test_inputs,
116 ], capture_output=True, encoding="utf-8")
117 if result.returncode != 0:
118 print(result.stdout)
119 print(result.stderr)
120 sys.exit(result.returncode)
121 """
122
123 genrule(
124 name = "create_sksl_minify_tests_script",
125 # By putting sksl_minify in srcs, this will be compiled for
126 # the target platform, not the exec platform. This shouldn't
127 # cause any problems unless the outputs of the minifying are
128 # used as the inputs to another step, because then cross-compiling
129 # would break (as we would be unable to, for example, run the
130 # "compiled for android sksl_minify" on the exec machine that
131 # is running the Python script.
132 srcs = [
133 ":sksl_minify",
134 ":test_input_list.txt",
135 ],
136 outs = ["sksl_minify_tests.py"],
137 cmd = "echo '%s' > $@" % _SKSL_MINIFY_TESTS,
138 tools = [
139 "//gn:minify_sksl_tests",
140 ],
141 )
142
143 genrule(
144 name = "enumerate_test_input_list",
145 srcs = ["//resources/sksl:sksl_minify_tests_sources"],
146 outs = ["test_input_list.txt"],
147 # Put a space seperated list of file names into the one output
148 # This is done because the list could be quite long and overflow
149 # the command line length
150 # https://bazel.build/reference/be/make-variables#predefined_genrule_variables
151 cmd = "echo $(SRCS) > $@",
152 )