chromium/ios/chrome/tools/strings/generate_localizable_strings.gni

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

import("//build/compiled_action.gni")

# Help template to define a data_bundle with localized strings for use by
# the iOS system from packed locale.pak files.
#
# Arguments
#     config_file
#         string, path to the property list file containing the configuration
#         parameters for the invocation of generate_localizable_strings tool.
#
#     datapack_dir
#         string, path to the directory containing the packed locale.pak files
#         in use for the generate_localizable_strings tool.
#
#     locales
#         list of strings corresponding to all the locales that should be
#         generated and packed.
#
#     output_filenames
#         list of strings corresponding to the basename of the files generated
#         by the generate_localizable_strings tool (i.e. if it contains ["a"]
#         then the tool will generate ["$locale.lproj/a"] for each locale set
#         in locales argument).
#
#     deps
#         list of target labels.
#
template("generate_localizable_strings") {
  assert(defined(invoker.config_file),
         "config_file needs to be defined for ${target_name}")
  assert(defined(invoker.datapack_dir),
         "datapack_dir needs to be defined for ${target_name}")
  assert(defined(invoker.output_filenames),
         "output_filenames needs to be defined for ${target_name}")
  assert(defined(invoker.packed_locales),
         "packed_locales needs to be defined for ${target_name}")

  _target_name = target_name

  _bundle_targets = []
  foreach(locale, invoker.packed_locales) {
    _bundle_targets += [ ":${_target_name}_${locale}" ]

    bundle_data("${_target_name}_${locale}") {
      forward_variables_from(invoker, [ "testonly" ])

      visibility = [ ":${_target_name}" ]
      public_deps = [ ":${_target_name}_generate" ]
      sources = []
      foreach(filename, invoker.output_filenames) {
        sources += [ "${target_gen_dir}/${locale}.lproj/$filename" ]
      }
      outputs =
          [ "{{bundle_resources_dir}}/${locale}.lproj/{{source_file_part}}" ]
    }
  }

  compiled_action("${_target_name}_generate") {
    forward_variables_from(invoker, [ "testonly" ])

    visibility = _bundle_targets
    deps = invoker.deps
    tool = "//ios/chrome/tools/strings:generate_localizable_strings"

    outputs = []
    inputs = [ invoker.config_file ]

    foreach(locale, invoker.packed_locales) {
      inputs += [ "${invoker.datapack_dir}/${locale}.lproj/locale.pak" ]
      foreach(filename, invoker.output_filenames) {
        outputs += [ "${target_gen_dir}/${locale}.lproj/$filename" ]
      }
    }

    args = [
             "-c",
             rebase_path(invoker.config_file, root_build_dir),
             "-I",
             rebase_path(root_gen_dir, root_build_dir),
             "-p",
             rebase_path(invoker.datapack_dir, root_build_dir),
             "-o",
             rebase_path(target_gen_dir, root_build_dir),
           ] + invoker.packed_locales
  }

  group(_target_name) {
    forward_variables_from(invoker,
                           [
                             "testonly",
                             "visibility",
                           ])
    deps = _bundle_targets
  }
}