Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / tools / gn / secondary / tools / grit / grit_rule.gni
1 # Copyright (c) 2013 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 # Instantiate grit. This will produce a script target to run grit, and a
6 # static library that compiles the .cc files.
7 #
8 # Example:
9 #   grit("my_resources") {
10 #     source = "myfile.grd"  # source is required.
11 #     grit_flags = [ "-E", "foo=bar" ]  # Optional extra flags.
12 #     # You can also put deps here if the grit source depends on generated
13 #     # files.
14 #   }
15 template("grit") {
16   assert(defined(invoker.source),
17          "\"source\" must be defined for the grit template $target_name")
18   assert(!defined(invoker.sources) && !defined(invoker.outputs),
19          "Neither \"sources\" nor \"outputs\" can be defined for the grit " +
20          "template $target_name")
21
22   grit_info_script = "//tools/grit/grit_info.py"
23
24   # These are all passed as arguments to the script so have to be relative to
25   # the build directory.
26   resource_ids =
27     rebase_path("//tools/gritsettings/resource_ids", root_build_dir)
28   output_dir = rebase_path(target_gen_dir, root_build_dir)
29   source_path = rebase_path(invoker.source, root_build_dir)
30
31   if (defined(invoker.grit_flags)) {
32     grit_flags = invoker.grit_flags
33   } else {
34     grit_flags = []  # These are optional so default to empty list.
35   }
36
37   grit_inputs_build_rel = exec_script(grit_info_script,
38     [ "--inputs", source_path, "-f", resource_ids] + grit_flags, "list lines")
39   # The inputs are relative to the current (build) directory, rebase to
40   # the current one.
41   grit_inputs = rebase_path(grit_inputs_build_rel, ".", root_build_dir)
42
43   grit_outputs_build_rel = exec_script(grit_info_script,
44     [ "--outputs", "$output_dir", source_path, "-f", resource_ids ] +
45     grit_flags,
46     "list lines")
47
48   # The inputs are relative to the current (build) directory, rebase to
49   # the current one.
50   grit_outputs = rebase_path(grit_outputs_build_rel, ".", root_build_dir)
51
52   # The config and the action below get this visibility son only the generated
53   # source set can depend on them. The variable "target_name" will get
54   # overwritten inside the innter classes so we need to compute it here.
55   target_visibility = ":$target_name"
56
57   # The current grit setup makes an file in $target_gen_dir/grit/foo.h that
58   # the source code expects to include via "grit/foo.h". It would be nice to
59   # change this to including absolute paths relative to the root gen directory
60   # (like "mycomponent/foo.h"). This config sets up the include path.
61   grit_config = target_name + "_grit_config"
62   config(grit_config) {
63     include_dirs = [ target_gen_dir ]
64     visibility = target_visibility
65   }
66
67   grit_custom_target = target_name + "_grit"
68   action(grit_custom_target) {
69     script = "//tools/grit/grit.py"
70     hard_dep = true
71     source_prereqs = grit_inputs
72     outputs = grit_outputs
73
74     # TODO(brettw) grit_defines.
75     args = [
76       "-i", source_path, "build",
77       "-f", resource_ids,
78       "-o", output_dir,
79     ] + grit_flags
80
81     visibility = target_visibility
82   }
83
84   # This is the thing that people actually link with, it must be named the
85   # same as the argument the template was invoked with.
86   source_set(target_name) {
87     # Since we generate a file, we need to be run before the targets that
88     # depend on us.
89     hard_dep = true
90     sources = grit_outputs
91
92     # Deps set on the template invocation will go on the grit script running
93     # target rather than this library.
94     deps = [ ":$grit_custom_target" ]
95     direct_dependent_configs = [ ":$grit_config" ]
96
97     if (defined(invoker.visibility)) {
98       visibility = invoker.visibility
99     }
100     if (defined(invoker.output_name)) {
101       output_name = invoker.output_name
102     }
103   }
104 }