OLD | NEW |
| (Empty) |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 # Generates native and HTML/JS supporting code for Web UI element from element's | |
6 # declaration JSON file. | |
7 # | |
8 # Parameters: | |
9 # | |
10 # source (required) | |
11 # Declaration file. | |
12 # | |
13 # deps (optional) | |
14 # visibility (optional) | |
15 # Normal meanings. | |
16 # | |
17 # Example: | |
18 # wug("some_type_wug_generated") { | |
19 # source = "some_type.json" | |
20 # } | |
21 # | |
22 # Target's name should be deduced from declaration file name by removing | |
23 # extension and adding '_wug_generated' prefix. This is needed to properly | |
24 # handle dependencies between declaration files and their imports. | |
25 # | |
26 # For declaration file with a full path 'src/full/path/some_type.json' 5 files | |
27 # will be generated and compiled: | |
28 # $root_gen_dir/wug/full/path/some_type_export.h | |
29 # $root_gen_dir/wug/full/path/some_type_view.h | |
30 # $root_gen_dir/wug/full/path/some_type_view_model.cc | |
31 # $root_gen_dir/wug/full/path/some_type_view_model.h | |
32 # $root_gen_dir/wug/full/path/some_type_webui_view.cc | |
33 | |
34 template("wug") { | |
35 declaration_path = invoker.source | |
36 generator_dir = "//components/webui_generator/generator" | |
37 generator_path = "$generator_dir/gen_sources.py" | |
38 src_root = rebase_path("//", root_build_dir) | |
39 | |
40 helper_path = "$generator_dir/build_helper.py" | |
41 target_name = "${target_name}" | |
42 action_name = target_name + "_gen" | |
43 group_name = target_name | |
44 out_dir = "$root_gen_dir/wug" | |
45 | |
46 helper_args = [ | |
47 rebase_path(declaration_path, root_build_dir), | |
48 "--destination", | |
49 rebase_path(out_dir, root_build_dir), | |
50 "--root", | |
51 src_root, | |
52 "--gn", | |
53 "--output", | |
54 ] | |
55 | |
56 expected_target_name = | |
57 exec_script(helper_path, helper_args + [ "target_name" ], "trim string") | |
58 assert(target_name == expected_target_name, | |
59 "Wrong target name. " + "Expected '" + expected_target_name + | |
60 "', got '" + target_name + "'.") | |
61 | |
62 action(action_name) { | |
63 visibility = [ ":$group_name" ] | |
64 | |
65 script = generator_path | |
66 sources = [ | |
67 "$generator_dir/declaration.py", | |
68 "$generator_dir/export_h.py", | |
69 "$generator_dir/html_view.py", | |
70 "$generator_dir/util.py", | |
71 "$generator_dir/view_model.py", | |
72 "$generator_dir/web_ui_view.py", | |
73 ] | |
74 inputs = [ | |
75 declaration_path, | |
76 ] | |
77 inputs += | |
78 exec_script(helper_path, helper_args + [ "imports" ], "list lines") | |
79 common_prefix = process_file_template( | |
80 [ declaration_path ], | |
81 "$out_dir/{{source_root_relative_dir}}/{{source_name_part}}_") | |
82 common_prefix = common_prefix[0] | |
83 outputs = [ | |
84 common_prefix + "export.h", | |
85 common_prefix + "view_model.h", | |
86 common_prefix + "view_model.cc", | |
87 common_prefix + "web_ui_view.h", | |
88 common_prefix + "web_ui_view.cc", | |
89 ] | |
90 args = [ | |
91 rebase_path(declaration_path, root_build_dir), | |
92 "--root", | |
93 src_root, | |
94 "--destination", | |
95 rebase_path(out_dir, root_build_dir), | |
96 ] | |
97 | |
98 if (defined(invoker.deps)) { | |
99 deps = invoker.deps | |
100 } | |
101 if (defined(invoker.public_deps)) { | |
102 public_deps = invoker.public_deps | |
103 } | |
104 } | |
105 | |
106 source_set(target_name) { | |
107 if (defined(invoker.visibility)) { | |
108 visibility = invoker.visibility | |
109 } | |
110 | |
111 sources = get_target_outputs(":$action_name") | |
112 defines = [ exec_script(helper_path, | |
113 helper_args + [ "impl_macro" ], | |
114 "trim string") ] | |
115 deps = [ | |
116 ":$action_name", | |
117 "//base", | |
118 "//components/login", | |
119 "//components/strings", | |
120 ] | |
121 deps += exec_script(helper_path, | |
122 helper_args + [ "import_dependencies" ], | |
123 "list lines") | |
124 public_deps = [ | |
125 "//components/webui_generator", | |
126 ] | |
127 | |
128 all_dependent_configs = | |
129 [ "//components/webui_generator:wug_generated_config" ] | |
130 } | |
131 } | |
OLD | NEW |