1# Copyright 2024 Google, LLC 2# 3# Permission is hereby granted, free of charge, to any person obtaining a 4# copy of this software and associated documentation files (the "Software"), 5# to deal in the Software without restriction, including without limitation 6# the rights to use, copy, modify, merge, publish, distribute, sublicense, 7# and/or sell copies of the Software, and to permit persons to whom the 8# Software is furnished to do so, subject to the following conditions: 9# 10# The above copyright notice and this permission notice (including the next 11# paragraph) shall be included in all copies or substantial portions of the 12# Software. 13# 14# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 19# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 20# IN THE SOFTWARE. 21 22import("//build/python/python_binary.gni") 23import("../../../mesa.gni") 24 25format = "$mesa_source_root/src/util/format" 26 27config("format_config") { 28 include_dirs = [ 29 "$format", 30 "$target_gen_dir", 31 ] 32} 33 34mesa_source_set("format") { 35 public_configs = [ "..:util_public_config" ] 36 configs = [ ":format_config" ] 37 public_deps = [ "$mesa_build_root/include:c_compat" ] 38 sources = [ 39 "$format/u_format.c", 40 "$format/u_format.h", 41 "$format/u_format_bptc.c", 42 "$format/u_format_etc.c", 43 "$format/u_format_fxt1.c", 44 "$format/u_format_latc.c", 45 "$format/u_format_other.c", 46 "$format/u_format_rgtc.c", 47 "$format/u_format_s3tc.c", 48 "$format/u_format_tests.c", 49 "$format/u_format_yuv.c", 50 "$format/u_format_zs.c", 51 "$target_gen_dir/u_format_table.c", 52 ] 53 deps = [ 54 ":u_format_pack_h", 55 ":u_format_table_c", 56 ] 57} 58 59# Executes a python script and writes its output to a file. 60# 61# Example 62# 63# mesa_python_stdout_to_file_action("opcodes.c") { 64# output = "opcodes.c" 65# script = "opcodes_c.py" 66# sources = [ "opcodes_lib.py" ] 67# libraries = [ "//third_party/mako" ] 68# } 69# 70# Parameters 71# 72# script (required) 73# The .py file that will be interpreted. 74# Type: path 75# 76# output (required) 77# Path to the output file. Assumed to be relative to ${target_gen_dir}. 78# Type: path 79# 80# sources (optional) 81# Extra .py source files script imports. 82# Type: list(path) 83# Default: empty list 84# 85# libraries (optional) 86# Paths to python_libraries script imports. 87# Type: list(string) 88# Default: empty list 89# 90# args (optional) 91# Arguments to pass to the script. 92# Type: list(str) 93# Default: empty list 94# 95# deps 96# inputs 97# testonly 98# visibility 99template("mesa_python_stdout_to_file_action") { 100 assert(defined(invoker.script), "script is required") 101 assert(defined(invoker.output), "output is required") 102 103 py_binary_target = "${target_name}_py_binary" 104 python_binary(py_binary_target) { 105 forward_variables_from(invoker, 106 [ 107 "sources", 108 "testonly", 109 ]) 110 main_source = invoker.script 111 if (defined(invoker.libraries)) { 112 deps = invoker.libraries 113 } 114 visibility = [ ":*" ] 115 } 116 117 action(target_name) { 118 forward_variables_from(invoker, 119 [ 120 "testonly", 121 "visibility", 122 "inputs", 123 ]) 124 125 script = "gn_script_wrapper.sh" 126 outputs = [ "${target_gen_dir}/${invoker.output}" ] 127 128 py_binary = get_target_outputs(":${py_binary_target}") 129 assert(py_binary == [ py_binary[0] ], 130 "${py_binary_target} should only have one output") 131 py_binary = py_binary[0] 132 sources = [ py_binary ] 133 134 # Ensure scripts can import other scripts in the same directory 135 # Note - I'm not sure why the ../ is necessary. 136 python_path = 137 rebase_path(get_label_info(target_name, "dir") + "/..", root_build_dir) 138 139 args = [ 140 rebase_path(python_exe_src, root_build_dir), 141 142 # TODO(jayzhuang): remove this arg after migrating mesa_python_action. 143 python_path, 144 rebase_path(outputs[0], root_build_dir), 145 rebase_path(py_binary, root_build_dir), 146 ] 147 if (defined(invoker.args)) { 148 args += invoker.args 149 } 150 151 deps = [ ":${py_binary_target}" ] 152 if (defined(invoker.deps)) { 153 deps += invoker.deps 154 } 155 } 156} 157 158u_format_csv = "$format/u_format.csv" 159 160mesa_python_stdout_to_file_action("u_format_pack_h") { 161 output = "u_format_pack.h" 162 script = "$format/u_format_table.py" 163 sources = [ 164 "$format/u_format_pack.py", 165 "$format/u_format_parse.py", 166 ] 167 inputs = [ u_format_csv ] 168 args = [ 169 rebase_path(u_format_csv, root_build_dir), 170 "--header", 171 ] 172} 173 174mesa_python_stdout_to_file_action("u_format_table_c") { 175 output = "u_format_table.c" 176 script = "$format/u_format_table.py" 177 sources = [ 178 "$format/u_format_pack.py", 179 "$format/u_format_parse.py", 180 ] 181 inputs = [ u_format_csv ] 182 args = [ rebase_path(u_format_csv, root_build_dir) ] 183} 184