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 # NOTE: target's name should be deduced from declaration file full path |
| 14 # (relative to 'src'), by replacing every nonalphanumeric character with '_', |
| 15 # e.g. for declaration file with full path 'full/path/to/file.json' target name |
| 16 # should be 'full_path_to_file_json'. This is needed to properly handle |
| 17 # dependencies between declaration files and their imports. |
| 18 # |
| 19 # Example: |
| 20 # wug("full_path_to_file_json") { |
| 21 # source = "file.json" |
| 22 # } |
| 23 |
| 24 template("wug") { |
| 25 declaration_path = invoker.source |
| 26 generator_dir = "//components/wug/generator" |
| 27 generator_path = "$generator_dir/gen_sources.py" |
| 28 src_root = rebase_path("//", root_build_dir) |
| 29 |
| 30 helper_path = "$generator_dir/build_helper.py" |
| 31 source_set_name = "${target_name}" |
| 32 action_name = source_set_name + "_gen" |
| 33 config_name = source_set_name + "_config" |
| 34 out_dir = "$root_gen_dir/wug" |
| 35 |
| 36 helper_args = [ |
| 37 rebase_path(declaration_path, root_build_dir), |
| 38 "--destination", |
| 39 out_dir, |
| 40 "--root", |
| 41 src_root, |
| 42 "--gn", |
| 43 "--output", |
| 44 ] |
| 45 |
| 46 expected_source_set_name = |
| 47 exec_script(helper_path, helper_args + [ "target_name" ], "trim string") |
| 48 assert(source_set_name == expected_source_set_name, |
| 49 "Wrong target name. " + "Expected '" + expected_source_set_name + |
| 50 "', got '" + source_set_name + "'.") |
| 51 |
| 52 action(action_name) { |
| 53 script = generator_path |
| 54 sources = [ |
| 55 "$generator_dir/declaration.py", |
| 56 "$generator_dir/html_view.py", |
| 57 "$generator_dir/util.py", |
| 58 "$generator_dir/view_model.py", |
| 59 "$generator_dir/web_ui_view.py", |
| 60 ] |
| 61 |
| 62 inputs = [ |
| 63 declaration_path, |
| 64 ] |
| 65 inputs += |
| 66 exec_script(helper_path, helper_args + [ "imports" ], "list lines") |
| 67 outputs = |
| 68 exec_script(helper_path, helper_args + [ "list_outputs" ], "list lines") |
| 69 args = [ |
| 70 rebase_path(declaration_path, root_build_dir), |
| 71 "--root", |
| 72 src_root, |
| 73 "--destination", |
| 74 out_dir, |
| 75 ] |
| 76 } |
| 77 |
| 78 config(config_name) { |
| 79 include_dirs = [ out_dir ] |
| 80 } |
| 81 |
| 82 source_set(source_set_name) { |
| 83 sources = get_target_outputs(":$action_name") |
| 84 deps = [ |
| 85 "//base", |
| 86 "//components/strings", |
| 87 "//components/wug", |
| 88 "//skia", |
| 89 ] |
| 90 deps += exec_script(helper_path, |
| 91 helper_args + [ "import_dependencies" ], |
| 92 "list lines") |
| 93 public_configs = [ ":" + config_name ] |
| 94 } |
| 95 } |
OLD | NEW |