| # Copyright 2022 The Chromium Authors |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| |
| template("html_to_wrapper") { |
| action(target_name) { |
| script = "//tools/polymer/html_to_wrapper.py" |
| |
| forward_variables_from(invoker, |
| [ |
| "deps", |
| "public_deps", |
| "visibility", |
| ]) |
| |
| inputs = [] |
| outputs = [] |
| |
| wrapper_extension = ".ts" |
| |
| if (defined(invoker.use_js) && invoker.use_js) { |
| wrapper_extension = ".js" |
| } |
| |
| in_folder = "." |
| if (defined(invoker.in_folder)) { |
| in_folder = invoker.in_folder |
| } |
| |
| out_folder = target_gen_dir |
| if (defined(invoker.out_folder)) { |
| out_folder = invoker.out_folder |
| } |
| |
| foreach(html_file, invoker.in_files) { |
| extension = get_path_info(html_file, "extension") |
| assert(extension == "html") |
| |
| wrapper_file = get_path_info(html_file, "dir") + "/" + |
| get_path_info(html_file, "file") + wrapper_extension |
| inputs += [ "$in_folder/" + html_file ] |
| |
| # When in "detect" mode, need to declare the file holding the web |
| # component's definition as an input dependency, since the script needs |
| # to look into it to determine the type of wrapper to use. |
| if (defined(invoker.template) && invoker.template == "detect") { |
| # Exclude non-web component "*_icons.html" or "icons.html" files. |
| is_icons_template = |
| get_path_info(html_file, "file") == "icons.html" || |
| string_replace(html_file, "_icons.html", "") != html_file |
| if (!is_icons_template) { |
| inputs += [ "$in_folder/" + |
| string_replace(html_file, ".html", wrapper_extension) ] |
| } |
| } |
| |
| outputs += [ "$out_folder/" + wrapper_file ] |
| } |
| |
| args = [ |
| "--in_folder", |
| rebase_path(in_folder, root_build_dir), |
| "--out_folder", |
| rebase_path(out_folder, root_build_dir), |
| "--in_files", |
| ] + invoker.in_files |
| |
| if (defined(invoker.template)) { |
| args += [ |
| "--template", |
| invoker.template, |
| ] |
| } |
| |
| if (defined(invoker.scheme)) { |
| assert(invoker.scheme == "chrome" || invoker.scheme == "relative") |
| args += [ |
| "--scheme", |
| invoker.scheme, |
| ] |
| } |
| |
| if (defined(invoker.use_js) && invoker.use_js) { |
| args += [ "--use_js" ] |
| } |
| |
| if (defined(invoker.minify) && invoker.minify) { |
| args += [ "--minify" ] |
| |
| # Declare additional dependency. |
| inputs += [ "//tools/polymer/html_minifier.js" ] |
| } |
| } |
| } |