1 # Copyright 2014 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.
5 import("//build/config/chrome_build.gni")
7 # Runs the version processing script over the given template file to produce
8 # an output file. This is used for generating various forms of files that
9 # incorporate the product name and version.
11 # Unlike GYP, this will actually compile the resulting file, so you don't need
12 # to add it separately to the sources, just depend on the target.
14 # This template automatically includes VERSION, LASTCHANGE, and BRANDING. It
15 # automatically uses the template file .
16 # GYP parameterizes this template file but all current invocations use this
17 # same one. If in the future we need to set it, this should be added as an
20 # In GYP this is a rule that runs once per ".ver" file. In GN this just
21 # processes one file per invocation of the template so you may have to have
24 # You must specify either sources or a template_file, or both.
28 # List of file names to read. When converting a GYP target, this should
29 # list the 'source' (see above) as well as any extra_variable_files.
32 # File name of file to write. In GYP this is unspecified and it will
33 # make up a file name for you based on the input name, and tack on
34 # "_version.rc" to the end. But in GN you need to specify the full name.
36 # template_file (optional):
37 # Template file to use (not a list). Defaults to
38 # //chrome/app/chrome_version.rc.version if unspecified.
40 # extra_args (optional):
41 # Extra arguments to pass to version.py. Any "-f <filename>" args should
42 # use sources instead.
44 # visibility (optional)
47 # process_version("myversion") {
48 # sources = [ "myfile.h.in" ]
49 # output = "$target_gen_dir/myfile.h"
50 # extra_args = ["-e", "FOO=42"]
51 # extra_files = [ "foo/BRANDING" ]
53 template("process_version") {
54 assert(defined(invoker.sources) || defined(invoker.template_file),
55 "Either sources or template_file must be defined for $target_name")
56 assert(defined(invoker.output), "Output must be defined for $target_name")
58 action_name = target_name + "_action"
59 source_set_name = target_name
62 visibility = [ ":$source_set_name" ]
63 script = "//build/util/version.py"
65 lastchange_path = "//build/util/LASTCHANGE"
66 version_path = "//chrome/VERSION"
67 if (is_chrome_branded) {
68 branding_path = "//chrome/app/theme/google_chrome/BRANDING"
70 branding_path = "//chrome/app/theme/chromium/BRANDING"
72 if (defined(invoker.template_file)) {
73 template_path = invoker.template_file
75 template_path = "//chrome/app/chrome_version.rc.version"
91 if (defined(invoker.sources)) {
92 inputs += invoker.sources
93 foreach(i, invoker.sources) {
96 rebase_path(i, root_build_dir),
103 rebase_path(version_path, root_build_dir),
105 rebase_path(branding_path, root_build_dir),
107 rebase_path(lastchange_path, root_build_dir),
109 if (defined(invoker.extra_args)) {
110 args += invoker.extra_args
113 rebase_path(template_path, root_build_dir),
114 rebase_path(invoker.output, root_build_dir),
118 source_set(source_set_name) {
119 if (defined(invoker.visibility)) {
120 visibility = invoker.visibility
122 sources = get_target_outputs(":$action_name")