Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 1 | # 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 | |
| 15 | import("../scripts/dawn_overrides_with_defaults.gni") |
David 'Digit' Turner | 5dee3e8 | 2019-06-24 14:31:06 +0000 | [diff] [blame] | 16 | import("generator_lib.gni") |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 17 | |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 18 | # Template to help invoking Dawn code generators based on generator_lib |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 19 | # |
| 20 | # dawn_generator("my_target_gen") { |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 21 | # # The script and generator specific arguments |
| 22 | # script = [ "my_awesome_generator.py" ] |
| 23 | # args = [ |
| 24 | # "--be-awesome", |
| 25 | # "yes" |
| 26 | # ] |
| 27 | # |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 28 | # # The list of expected outputs, generation fails if there's a mismatch |
| 29 | # outputs = [ |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 30 | # "MyAwesomeTarget.cpp", |
| 31 | # "MyAwesomeTarget.h", |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 32 | # ] |
| 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 | # |
| 42 | template("dawn_generator") { |
David 'Digit' Turner | 5dee3e8 | 2019-06-24 14:31:06 +0000 | [diff] [blame] | 43 | generator_lib_action(target_name) { |
Corentin Wallez | c94696a | 2022-11-22 11:07:27 +0000 | [diff] [blame] | 44 | forward_variables_from(invoker, "*", [ "script" ]) |
| 45 | script = get_path_info(invoker.script, "abspath") |
Corentin Wallez | a9a84df | 2019-09-19 23:30:42 +0000 | [diff] [blame] | 46 | |
| 47 | # Set arguments required to find the python libraries for the generator |
Corentin Wallez | c94696a | 2022-11-22 11:07:27 +0000 | [diff] [blame] | 48 | generator_lib_dir = get_path_info("${dawn_root}/generator", "abspath") |
David 'Digit' Turner | 5dee3e8 | 2019-06-24 14:31:06 +0000 | [diff] [blame] | 49 | jinja2_path = dawn_jinja2_dir |
Corentin Wallez | a9a84df | 2019-09-19 23:30:42 +0000 | [diff] [blame] | 50 | |
| 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 Wallez | a9a84df | 2019-09-19 23:30:42 +0000 | [diff] [blame] | 53 | custom_gen_dir = dawn_gen_root |
Corentin Wallez | abc753c | 2019-03-06 23:17:39 +0000 | [diff] [blame] | 54 | } |
| 55 | } |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 56 | |
| 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 | # } |
| 65 | template("dawn_json_generator") { |
| 66 | dawn_generator(target_name) { |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 67 | 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 Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 76 | "--targets", |
| 77 | invoker.target, |
| 78 | ] |
| 79 | |
Corentin Wallez | df69f24 | 2019-06-13 10:22:32 +0000 | [diff] [blame] | 80 | forward_variables_from(invoker, "*", [ "target" ]) |
Corentin Wallez | 031fbbb | 2019-06-11 18:03:05 +0000 | [diff] [blame] | 81 | } |
| 82 | } |
Brendon Tiszka | d0b284b | 2023-02-08 20:43:18 +0000 | [diff] [blame] | 83 | |
| 84 | template("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 | } |