1# Copyright 2014 The Chromium Authors 2# Use of this source code is governed by a BSD-style license that can be 3# found in the LICENSE file. 4 5import("//build/util/lastchange.gni") 6 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. 10# 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. 13# 14# In GYP this is a rule that runs once per ".ver" file. In GN this just 15# processes one file per invocation of the template so you may have to have 16# multiple targets. 17# 18# Parameters: 19# sources (optional): 20# List of file names to read. When converting a GYP target, this should 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. 23# 24# output: 25# File name of file to write. In GYP this is unspecified and it will 26# make up a file name for you based on the input name, and tack on 27# "_version.rc" to the end. But in GN you need to specify the full name. 28# 29# template_file (optional): 30# Template file to use (not a list). Most Windows users that want to use 31# this to process a .rc template should use process_version_rc_template(), 32# defined in //chrome/process_version_rc_template.gni, instead. 33# 34# extra_args (optional): 35# Extra arguments to pass to version.py. Any "-f <filename>" args should 36# use sources instead. 37# 38# process_only (optional, defaults to false) 39# Set to generate only one action that processes the version file and 40# doesn't attempt to link the result into a source set. This is for if 41# you are processing the version as data only. 42# 43# executable (optional, defaults to false) 44# Sets the executable bit on the output file (POSIX only). 45# 46# visibility (optional) 47# 48# Example: 49# process_version("myversion") { 50# sources = [ 51# "//chrome/VERSION" 52# "myfile.h.in" 53# ] 54# output = "$target_gen_dir/myfile.h" 55# extra_args = [ "-e", "FOO=42" ] 56# } 57template("process_version") { 58 assert(defined(invoker.output), "Output must be defined for $target_name") 59 60 process_only = defined(invoker.process_only) && invoker.process_only 61 62 if (process_only) { 63 action_name = target_name 64 } else { 65 action_name = target_name + "_action" 66 source_set_name = target_name 67 } 68 69 action(action_name) { 70 script = "//build/util/version.py" 71 72 inputs = [ lastchange_file ] 73 if (defined(invoker.inputs)) { 74 inputs += invoker.inputs 75 } 76 if (defined(invoker.template_file)) { 77 inputs += [ invoker.template_file ] 78 } 79 80 outputs = [ invoker.output ] 81 82 args = [] 83 84 if (is_official_build) { 85 args += [ "--official" ] 86 } 87 88 if (defined(invoker.sources)) { 89 inputs += invoker.sources 90 foreach(i, invoker.sources) { 91 args += [ 92 "-f", 93 rebase_path(i, root_build_dir), 94 ] 95 } 96 } 97 98 if (defined(invoker.executable) && invoker.executable) { 99 args += [ "-x" ] 100 } 101 102 if (defined(invoker.extra_args)) { 103 args += invoker.extra_args 104 } 105 args += [ 106 "-o", 107 rebase_path(invoker.output, root_build_dir), 108 ] 109 if (defined(invoker.template_file)) { 110 args += [ rebase_path(invoker.template_file, root_build_dir) ] 111 } 112 113 forward_variables_from(invoker, [ "deps" ]) 114 115 if (process_only) { 116 # When processing only, visibility gets applied to this target. 117 forward_variables_from(invoker, [ "visibility" ]) 118 } else { 119 # When linking the result, only the source set can depend on the action. 120 visibility = [ ":$source_set_name" ] 121 } 122 } 123 124 if (!process_only) { 125 source_set(source_set_name) { 126 forward_variables_from(invoker, 127 [ 128 "visibility", 129 "deps", 130 ]) 131 sources = get_target_outputs(":$action_name") 132 public_deps = [ ":$action_name" ] 133 } 134 } 135} 136