Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Side by Side Diff: build/util/process_version.gni

Issue 2308313003: gn: Generalize process_version() and move it to build/util (Closed)
Patch Set: Fix chromecast Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/config/chrome_build.gni ('k') | chrome/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 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 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import("//build/config/chrome_build.gni") 5 import("//build/config/chrome_build.gni")
6 6
7 # Runs the version processing script over the given template file to produce 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 8 # an output file. This is used for generating various forms of files that
9 # incorporate the product name and version. 9 # incorporate the product name and version.
10 # 10 #
11 # Unlike GYP, this will actually compile the resulting file, so you don't need 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. 12 # to add it separately to the sources, just depend on the target.
13 # 13 #
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
18 # optional argument.
19 #
20 # In GYP this is a rule that runs once per ".ver" file. In GN this just 14 # 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 15 # processes one file per invocation of the template so you may have to have
22 # multiple targets. 16 # multiple targets.
23 # 17 #
24 # Parameters: 18 # Parameters:
25 # sources (optional): 19 # sources (optional):
26 # List of file names to read. When converting a GYP target, this should 20 # List of file names to read. When converting a GYP target, this should
27 # list the 'source' (see above) as well as any extra_variable_files. 21 # list the 'source' (see above) as well as any extra_variable_files.
22 # The files will be passed to version.py in the order specified here.
28 # 23 #
29 # output: 24 # output:
30 # File name of file to write. In GYP this is unspecified and it will 25 # File name of file to write. In GYP this is unspecified and it will
31 # make up a file name for you based on the input name, and tack on 26 # make up a file name for you based on the input name, and tack on
32 # "_version.rc" to the end. But in GN you need to specify the full name. 27 # "_version.rc" to the end. But in GN you need to specify the full name.
33 # 28 #
34 # template_file (optional): 29 # template_file (optional):
35 # Template file to use (not a list). Most Windows uses for generating 30 # Template file to use (not a list). Most Windows uses for generating
36 # resources will want to specify the chrome_version_rc_template defined 31 # resources will want to use process_version_rc_template() instead.
37 # below.
38 # 32 #
39 # extra_args (optional): 33 # extra_args (optional):
40 # Extra arguments to pass to version.py. Any "-f <filename>" args should 34 # Extra arguments to pass to version.py. Any "-f <filename>" args should
41 # use sources instead. 35 # use sources instead.
42 # 36 #
43 # process_only (optional, defaults to false) 37 # process_only (optional, defaults to false)
44 # Set to generate only one action that processes the version file and 38 # Set to generate only one action that processes the version file and
45 # doesn't attempt to link the result into a source set. This is for if 39 # doesn't attempt to link the result into a source set. This is for if
46 # you are processing the version as data only. 40 # you are processing the version as data only.
47 # 41 #
48 # visibility (optional) 42 # visibility (optional)
49 # 43 #
50 # Example: 44 # Example:
51 # process_version("myversion") { 45 # process_version("myversion") {
52 # sources = [ "myfile.h.in" ] 46 # sources = [
47 # "//chrome/VERSION"
48 # "myfile.h.in"
49 # ]
53 # output = "$target_gen_dir/myfile.h" 50 # output = "$target_gen_dir/myfile.h"
54 # extra_args = ["-e", "FOO=42"] 51 # extra_args = [ "-e", "FOO=42" ]
55 # extra_files = [ "foo/BRANDING" ]
56 # } 52 # }
57 template("process_version") { 53 template("process_version") {
58 assert(defined(invoker.output), "Output must be defined for $target_name") 54 assert(defined(invoker.output), "Output must be defined for $target_name")
59 55
60 process_only = defined(invoker.process_only) && invoker.process_only 56 process_only = defined(invoker.process_only) && invoker.process_only
61 57
62 if (process_only) { 58 if (process_only) {
63 action_name = target_name 59 action_name = target_name
64 } else { 60 } else {
65 action_name = target_name + "_action" 61 action_name = target_name + "_action"
66 source_set_name = target_name 62 source_set_name = target_name
67 } 63 }
68 64
69 action(action_name) { 65 action(action_name) {
70 script = "//build/util/version.py" 66 script = "//build/util/version.py"
71 67
72 lastchange_path = "//build/util/LASTCHANGE" 68 inputs = []
73 version_path = "//chrome/VERSION"
74 if (is_chrome_branded) {
75 branding_path = "//chrome/app/theme/google_chrome/BRANDING"
76 } else {
77 branding_path = "//chrome/app/theme/chromium/BRANDING"
78 }
79
80 inputs = [
81 version_path,
82 lastchange_path,
83 branding_path,
84 ]
85 if (defined(invoker.inputs)) { 69 if (defined(invoker.inputs)) {
86 inputs += invoker.inputs 70 inputs += invoker.inputs
87 } 71 }
88 if (defined(invoker.template_file)) { 72 if (defined(invoker.template_file)) {
89 inputs += [ invoker.template_file ] 73 inputs += [ invoker.template_file ]
90 } 74 }
91 75
92 outputs = [ 76 outputs = [
93 invoker.output, 77 invoker.output,
94 ] 78 ]
95 79
96 args = [] 80 args = []
97 81
98 if (is_official_build) { 82 if (is_official_build) {
99 args += [ "--official" ] 83 args += [ "--official" ]
100 } 84 }
101 85
102 if (defined(invoker.sources)) { 86 if (defined(invoker.sources)) {
103 inputs += invoker.sources 87 inputs += invoker.sources
104 foreach(i, invoker.sources) { 88 foreach(i, invoker.sources) {
105 args += [ 89 args += [
106 "-f", 90 "-f",
107 rebase_path(i, root_build_dir), 91 rebase_path(i, root_build_dir),
108 ] 92 ]
109 } 93 }
110 } 94 }
111 95
112 args += [
113 "-f",
114 rebase_path(version_path, root_build_dir),
115 "-f",
116 rebase_path(branding_path, root_build_dir),
117 "-f",
118 rebase_path(lastchange_path, root_build_dir),
119 ]
120 if (defined(invoker.extra_args)) { 96 if (defined(invoker.extra_args)) {
121 args += invoker.extra_args 97 args += invoker.extra_args
122 } 98 }
123 args += [ 99 args += [
124 "-o", 100 "-o",
125 rebase_path(invoker.output, root_build_dir), 101 rebase_path(invoker.output, root_build_dir),
126 ] 102 ]
127 if (defined(invoker.template_file)) { 103 if (defined(invoker.template_file)) {
128 args += [ rebase_path(invoker.template_file, root_build_dir) ] 104 args += [ rebase_path(invoker.template_file, root_build_dir) ]
129 } 105 }
(...skipping 13 matching lines...) Expand all
143 source_set(source_set_name) { 119 source_set(source_set_name) {
144 forward_variables_from(invoker, [ "visibility" ]) 120 forward_variables_from(invoker, [ "visibility" ])
145 sources = get_target_outputs(":$action_name") 121 sources = get_target_outputs(":$action_name")
146 public_deps = [ 122 public_deps = [
147 ":$action_name", 123 ":$action_name",
148 ] 124 ]
149 } 125 }
150 } 126 }
151 } 127 }
152 128
153 chrome_version_rc_template = "//chrome/app/chrome_version.rc.version" 129 # This is a wrapper around process_version() that eases the task of processing
130 # a .rc.version file (used especially on Windows).
131 #
132 # This template automatically includes VERSION, LASTCHANGE and BRANDING, and
133 # any additional source files are passed after those (so their values can
134 # override the ones specified by those 3 files).
135 #
136 # Parameters:
137 # sources (optional):
138 # List of files with value definitions that will be passed in addition to
139 # VERSION, LASTCHANGE and BRANDING.
140 #
141 # template_file (optional):
142 # Template file to use (not a list). If not specified, a default value,
143 # //chrome/app/chrome_version.rc.version will be used.
144 #
145 # This template forwards all other parameters directly to process_version().
146 #
147 # Examples:
148 # process_version_rc_template("my_exe_version") {
149 # output = "$target_gen_dir/my_exe_version.rc"
150 # sources = [ "frob/my_exe.ver" ]
151 # extra_args = [ "-e", "FOO=42" ]
152 # }
153 #
154 # process_version_rc_template("my_dll_version") {
155 # output = "$target_gen_dir/my_dll_version.rc"
156 # template_file = [ "//foo/bar/my_dll_version.rc.version" ]
157 # }
158 template("process_version_rc_template") {
159 if (defined(invoker.template_file)) {
160 _template_file = invoker.template_file
161 } else {
162 _template_file = "//chrome/app/chrome_version.rc.version"
brettw 2016/09/06 22:52:31 Since this depends on files from //chrome, it shou
163 }
164 _sources = [
165 "//build/util/LASTCHANGE",
166 "//chrome/VERSION",
167 branding_file_path,
168 ]
169 if (defined(invoker.sources)) {
170 _sources += invoker.sources
171 }
172
173 process_version(target_name) {
174 template_file = _template_file
175 sources = _sources
176 forward_variables_from(invoker,
177 "*",
178 [
179 "sources",
180 "template_file",
181 ])
182 }
183 }
OLDNEW
« no previous file with comments | « build/config/chrome_build.gni ('k') | chrome/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698