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