summaryrefslogtreecommitdiffstats
path: root/remoting/tools/build/remoting_localize.gni
blob: 54ff46e27f829916e872dbd865f467d7ea1341a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# Copyright 2015 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

# Calls the remoting_localize script with a jinja2 template.
#
# Arguments
#
#   sources (required)
#     List of jinja2 files to load. This is the template.
#
#   locales (required)
#     List of locales.
#
#   locale_dir (optional)
#
#   defines (optional)
#     List of defines to pass to script.
#     Example: defines = [ "FOO_HOST_PATH=bar" ]
#
#   variables (optional)
#     List of variables to pass to script.
#
#   output (optiona)
#     Substitution pattern for the output. Defaults to a file in the target
#     gen dir with the extension stripped (normally the extension is ".jinja2"
#     which then leaves the non-tempaltized file name).
#   TODO(brettw) Need locale_output. This is a per-locale output file.
#
#   encoding (optional)
#     String.
#
#   deps (optional)
#   visibility (optional)
template("remoting_localize") {
  action_foreach(target_name) {
    if (defined(invoker.visibility)) {
      visibility = invoker.visibility
    }

    script = "//remoting/tools/build/remoting_localize.py"

    sources = invoker.sources

    if (defined(invoker.output)) {
      outputs = [
        invoker.output,
      ]
    } else {
      outputs = [
        "$target_gen_dir/{{source_name_part}}",
      ]
    }

    args = []

    if (defined(invoker.locale_dir)) {
      args += [
        "--locale_dir",
        rebase_path(invoker.locale_dir, root_build_dir),
      ]
    }

    # Add defines to command line.
    if (defined(invoker.defines)) {
      foreach(i, invoker.defines) {
        args += [
          "--define",
          i,
        ]
      }
    }

    # Add variables to command line.
    if (defined(invoker.variables)) {
      foreach(i, invoker.variables) {
        args += [
          "--variables",
          i,
        ]
      }
    }

    # The template file is required.
    args += [
      "--template",
      "{{source}}",
    ]

    args += [
      "--output",
      rebase_path(outputs[0], root_build_dir),
    ]

    if (defined(invoker.encoding)) {
      args += [
        "--encoding",
        invoker.encoding,
      ]
    }

    args += invoker.locales

    if (defined(invoker.deps)) {
      deps = invoker.deps
    } else {
      deps = []
    }

    # This script reads the messages strings from the generated resource files.
    deps += [ "//remoting/resources:strings" ]
  }
}