chromium/tools/grit/preprocess_if_expr.gni

# Copyright 2020 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import("//tools/grit/grit_args.gni")

template("preprocess_if_expr") {
  action(target_name) {
    script = "//tools/grit/preprocess_if_expr.py"

    # Declare deps of preprocess_if_expr.py as inputs as well, to re-trigger
    # preprocess_if_expr() targets whenever those change.
    inputs = [
      "//tools/grit/grit/node/base.py",
      "//tools/grit/grit/format/html_inline.py",
    ]

    forward_variables_from(invoker,
                           [
                             "deps",
                             "public_deps",
                             "visibility",
                           ])

    outputs = []

    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(in_file, invoker.in_files) {
      inputs += [ "$in_folder/" + in_file ]
      outputs += [ "$out_folder/" + in_file ]

      if (defined(invoker.enable_removal_comments) &&
          invoker.enable_removal_comments) {
        extension = get_path_info(in_file, "extension")
        assert(
            extension == "js" || extension == "ts",
            "enable_removal_comments requires .js or .ts input files. Found ${in_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 + grit_args

    if (defined(invoker.defines)) {
      foreach(define, invoker.defines) {
        args += [
          "-D",
          define,
        ]
      }
    }

    if (defined(invoker.out_manifest)) {
      args += [
        "--out-manifest",
        rebase_path(invoker.out_manifest, root_build_dir),
      ]
      outputs += [ invoker.out_manifest ]
    }

    if (defined(invoker.enable_removal_comments) &&
        invoker.enable_removal_comments) {
      args += [ "--enable_removal_comments" ]
    }
  }
}