blob: 6a4e09078e74199e6bed9f9b5df42a83a1af14cf [file] [log] [blame]
Corentin Wallezabc753c2019-03-06 23:17:39 +00001# Copyright 2019 The Dawn Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15import("../scripts/dawn_overrides_with_defaults.gni")
David 'Digit' Turner5dee3e82019-06-24 14:31:06 +000016import("generator_lib.gni")
Corentin Wallezabc753c2019-03-06 23:17:39 +000017
Corentin Wallez031fbbb2019-06-11 18:03:05 +000018# Template to help invoking Dawn code generators based on generator_lib
Corentin Wallezabc753c2019-03-06 23:17:39 +000019#
20# dawn_generator("my_target_gen") {
Corentin Wallez031fbbb2019-06-11 18:03:05 +000021# # The script and generator specific arguments
22# script = [ "my_awesome_generator.py" ]
23# args = [
24# "--be-awesome",
25# "yes"
26# ]
27#
Corentin Wallezabc753c2019-03-06 23:17:39 +000028# # The list of expected outputs, generation fails if there's a mismatch
29# outputs = [
Corentin Wallez031fbbb2019-06-11 18:03:05 +000030# "MyAwesomeTarget.cpp",
31# "MyAwesomeTarget.h",
Corentin Wallezabc753c2019-03-06 23:17:39 +000032# ]
33# }
34#
35# Using the generated files is done like so:
36#
37# shared_library("my_target") {
38# deps = [ ":my_target_gen "]
39# sources = get_target_outputs(":my_target_gen")
40# }
41#
42template("dawn_generator") {
David 'Digit' Turner5dee3e82019-06-24 14:31:06 +000043 generator_lib_action(target_name) {
Corentin Wallezc94696a2022-11-22 11:07:27 +000044 forward_variables_from(invoker, "*", [ "script" ])
45 script = get_path_info(invoker.script, "abspath")
Corentin Walleza9a84df2019-09-19 23:30:42 +000046
47 # Set arguments required to find the python libraries for the generator
Corentin Wallezc94696a2022-11-22 11:07:27 +000048 generator_lib_dir = get_path_info("${dawn_root}/generator", "abspath")
David 'Digit' Turner5dee3e82019-06-24 14:31:06 +000049 jinja2_path = dawn_jinja2_dir
Corentin Walleza9a84df2019-09-19 23:30:42 +000050
51 # Force Dawn's autogenerated file structure to mirror exactly the source
52 # tree but start at ${dawn_gen_root} instead of ${dawn_root}
Corentin Walleza9a84df2019-09-19 23:30:42 +000053 custom_gen_dir = dawn_gen_root
Corentin Wallezabc753c2019-03-06 23:17:39 +000054 }
55}
Corentin Wallez031fbbb2019-06-11 18:03:05 +000056
57# Helper generator for calling the generator from dawn.json
58#
59# dawn_json_generator("my_target_gen") {
60# # Which generator target to output
61# target = "my_target"
62#
63# # Also supports `outputs` and `custom_gen_dir` like dawn_generator.
64# }
65template("dawn_json_generator") {
66 dawn_generator(target_name) {
Corentin Wallez031fbbb2019-06-11 18:03:05 +000067 script = "${dawn_root}/generator/dawn_json_generator.py"
68
69 # The base arguments for the generator: from this dawn.json, generate this
70 # target using templates in this directory.
71 args = [
72 "--dawn-json",
73 rebase_path("${dawn_root}/dawn.json", root_build_dir),
74 "--wire-json",
75 rebase_path("${dawn_root}/dawn_wire.json", root_build_dir),
Corentin Wallez031fbbb2019-06-11 18:03:05 +000076 "--targets",
77 invoker.target,
78 ]
79
Corentin Wallezdf69f242019-06-13 10:22:32 +000080 forward_variables_from(invoker, "*", [ "target" ])
Corentin Wallez031fbbb2019-06-11 18:03:05 +000081 }
82}
Brendon Tiszkad0b284b2023-02-08 20:43:18 +000083
84template("dawn_json_lpm_generator") {
85 dawn_generator(target_name) {
86 script = "${dawn_root}/generator/dawn_json_generator.py"
87
88 # The base arguments for the generator: from this dawn.json, generate this
89 # target using templates in this directory.
90 args = [
91 "--dawn-json",
92 rebase_path("${dawn_root}/dawn.json", root_build_dir),
93 "--wire-json",
94 rebase_path("${dawn_root}/dawn_wire.json", root_build_dir),
95 "--lpm-json",
96 rebase_path("${dawn_root}/src/dawn/fuzzers/lpmfuzz/dawn_lpm.json",
97 root_build_dir),
98 "--targets",
99 invoker.target,
100 ]
101
102 forward_variables_from(invoker, "*", [ "target" ])
103 }
104}