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.
5 # Generates native and HTML/JS supporting code for Web UI element from element's
6 # declaration JSON file.
14 # wug("some_type_wug_generated") {
15 # source = "some_type.json"
18 # Target's name should be deduced from declaration file name by removing
19 # extension and adding '_wug_generated' prefix. This is needed to properly
20 # handle dependencies between declaration files and their imports.
22 # For declaration file with a full path 'src/full/path/some_type.json' 5 files
23 # will be generated and compiled:
24 # $root_gen_dir/wug/full/path/some_type_export.h
25 # $root_gen_dir/wug/full/path/some_type_view.h
26 # $root_gen_dir/wug/full/path/some_type_view_model.cc
27 # $root_gen_dir/wug/full/path/some_type_view_model.h
28 # $root_gen_dir/wug/full/path/some_type_webui_view.cc
31 declaration_path = invoker.source
32 generator_dir = "//components/webui_generator/generator"
33 generator_path = "$generator_dir/gen_sources.py"
34 src_root = rebase_path("//", root_build_dir)
36 helper_path = "$generator_dir/build_helper.py"
37 target_name = "${target_name}"
38 action_name = target_name + "_gen"
39 out_dir = "$root_gen_dir/wug"
42 rebase_path(declaration_path, root_build_dir),
44 rebase_path(out_dir, root_build_dir),
51 expected_target_name =
52 exec_script(helper_path, helper_args + [ "target_name" ], "trim string")
53 assert(target_name == expected_target_name,
54 "Wrong target name. " + "Expected '" + expected_target_name +
55 "', got '" + target_name + "'.")
58 script = generator_path
60 "$generator_dir/declaration.py",
61 "$generator_dir/export_h.py",
62 "$generator_dir/html_view.py",
63 "$generator_dir/util.py",
64 "$generator_dir/view_model.py",
65 "$generator_dir/web_ui_view.py",
71 exec_script(helper_path, helper_args + [ "imports" ], "list lines")
72 common_prefix = process_file_template(
74 "$out_dir/{{source_root_relative_dir}}/{{source_name_part}}_")
75 common_prefix = common_prefix[0]
77 common_prefix + "export.h",
78 common_prefix + "view_model.h",
79 common_prefix + "view_model.cc",
80 common_prefix + "web_ui_view.h",
81 common_prefix + "web_ui_view.cc",
84 rebase_path(declaration_path, root_build_dir),
88 rebase_path(out_dir, root_build_dir),
92 component(target_name) {
93 sources = get_target_outputs(":$action_name")
94 defines = [ exec_script(helper_path,
95 helper_args + [ "impl_macro" ],
100 "//components/strings",
102 deps += exec_script(helper_path,
103 helper_args + [ "import_dependencies" ],
106 "//components/webui_generator",
109 all_dependent_configs =
110 [ "//components/webui_generator:wug_generated_config" ]