summaryrefslogtreecommitdiffstats
path: root/chrome/version.gni
blob: 7781b1d0b9131ae46bc929cb8983361da18da4c8 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# Copyright 2014 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.

import("//build/config/chrome_build.gni")

# Runs the version processing script over the given template file to produce
# an output file. This is used for generating various forms of files that
# incorporate the product name and version.
#
# Unlike GYP, this will actually compile the resulting file, so you don't need
# to add it separately to the sources, just depend on the target.
#
# This template automatically includes VERSION, LASTCHANGE, and BRANDING. It
# automatically uses the template file .
# GYP parameterizes this template file but all current invocations use this
# same one. If in the future we need to set it, this should be added as an
# optional argument.
#
# In GYP this is a rule that runs once per ".ver" file. In GN this just
# processes one file per invocation of the template so you may have to have
# multiple targets.
#
# You must specify either sources or a template_file, or both.
#
# Parameters:
#   sources (optional):
#     List of file names to read. When converting a GYP target, this should
#     list the 'source' (see above) as well as any extra_variable_files.
#
#   output:
#     File name of file to write. In GYP this is unspecified and it will
#     make up a file name for you based on the input name, and tack on
#     "_version.rc" to the end. But in GN you need to specify the full name.
#
#   template_file (optional):
#     Template file to use (not a list). Defaults to
#     //chrome/app/chrome_version.rc.version if unspecified.
#
#   extra_args (optional):
#     Extra arguments to pass to version.py. Any "-f <filename>" args should
#     use sources instead.
#
#   visibility (optional)
#
# Example:
#   process_version("myversion") {
#     sources = [ "myfile.h.in" ]
#     output = "$target_gen_dir/myfile.h"
#     extra_args = ["-e", "FOO=42"]
#     extra_files = [ "foo/BRANDING" ]
#   }
template("process_version") {
  assert(defined(invoker.sources) || defined(invoker.template_file),
         "Either sources or template_file must be defined for $target_name")
  assert(defined(invoker.output), "Output must be defined for $target_name")

  action_name = target_name + "_action"
  source_set_name = target_name

  action(action_name) {
    visibility = [ ":$source_set_name" ]
    script = "//build/util/version.py"

    lastchange_path = "//build/util/LASTCHANGE"
    version_path = "//chrome/VERSION"
    if (is_chrome_branded) {
      branding_path = "//chrome/app/theme/google_chrome/BRANDING"
    } else {
      branding_path = "//chrome/app/theme/chromium/BRANDING"
    }
    if (defined(invoker.template_file)) {
      template_path = invoker.template_file
    } else {
      template_path = "//chrome/app/chrome_version.rc.version"
    }

    inputs = [
      version_path,
      lastchange_path,
      branding_path,
      template_path,
    ]

    outputs = [
      invoker.output,
    ]

    args = []

    if (defined(invoker.sources)) {
      inputs += invoker.sources
      foreach(i, invoker.sources) {
        args += [
          "-f",
          rebase_path(i, root_build_dir),
        ]
      }
    }

    args += [
      "-f",
      rebase_path(version_path, root_build_dir),
      "-f",
      rebase_path(branding_path, root_build_dir),
      "-f",
      rebase_path(lastchange_path, root_build_dir),
    ]
    if (defined(invoker.extra_args)) {
      args += invoker.extra_args
    }
    args += [
      rebase_path(template_path, root_build_dir),
      rebase_path(invoker.output, root_build_dir),
    ]
  }

  source_set(source_set_name) {
    if (defined(invoker.visibility)) {
      visibility = invoker.visibility
    }
    sources = get_target_outputs(":$action_name")
    public_deps = [
      ":$action_name",
    ]
  }
}