| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 # Runs the version processing script over the given template file to produce | |
| 6 # an output file. This is used for generating various forms of files that | |
| 7 # incorporate the product name and version. | |
| 8 # | |
| 9 # Unlike GYP, this will actually compile the resulting file, so you don't need | |
| 10 # to add it separately to the sources, just depend on the target. | |
| 11 # | |
| 12 # In GYP this is a rule that runs once per ".ver" file. In GN this just | |
| 13 # processes one file per invocation of the template so you may have to have | |
| 14 # multiple targets. | |
| 15 # | |
| 16 # Parameters: | |
| 17 # sources (optional): | |
| 18 # List of file names to read. When converting a GYP target, this should | |
| 19 # list the 'source' (see above) as well as any extra_variable_files. | |
| 20 # The files will be passed to version.py in the order specified here. | |
| 21 # | |
| 22 # output: | |
| 23 # File name of file to write. In GYP this is unspecified and it will | |
| 24 # make up a file name for you based on the input name, and tack on | |
| 25 # "_version.rc" to the end. But in GN you need to specify the full name. | |
| 26 # | |
| 27 # template_file (optional): | |
| 28 # Template file to use (not a list). Most Windows uses for generating | |
| 29 # resources will want to use process_version_rc_template() instead. | |
| 30 # | |
| 31 # extra_args (optional): | |
| 32 # Extra arguments to pass to version.py. Any "-f <filename>" args should | |
| 33 # use sources instead. | |
| 34 # | |
| 35 # process_only (optional, defaults to false) | |
| 36 # Set to generate only one action that processes the version file and | |
| 37 # doesn't attempt to link the result into a source set. This is for if | |
| 38 # you are processing the version as data only. | |
| 39 # | |
| 40 # visibility (optional) | |
| 41 # | |
| 42 # Example: | |
| 43 # process_version("myversion") { | |
| 44 # sources = [ | |
| 45 # "//chrome/VERSION" | |
| 46 # "myfile.h.in" | |
| 47 # ] | |
| 48 # output = "$target_gen_dir/myfile.h" | |
| 49 # extra_args = [ "-e", "FOO=42" ] | |
| 50 # } | |
| 51 template("process_version") { | |
| 52 assert(defined(invoker.output), "Output must be defined for $target_name") | |
| 53 | |
| 54 process_only = defined(invoker.process_only) && invoker.process_only | |
| 55 | |
| 56 if (process_only) { | |
| 57 action_name = target_name | |
| 58 } else { | |
| 59 action_name = target_name + "_action" | |
| 60 source_set_name = target_name | |
| 61 } | |
| 62 | |
| 63 action(action_name) { | |
| 64 script = "//build/util/version.py" | |
| 65 | |
| 66 inputs = [] | |
| 67 if (defined(invoker.inputs)) { | |
| 68 inputs += invoker.inputs | |
| 69 } | |
| 70 if (defined(invoker.template_file)) { | |
| 71 inputs += [ invoker.template_file ] | |
| 72 } | |
| 73 | |
| 74 outputs = [ | |
| 75 invoker.output, | |
| 76 ] | |
| 77 | |
| 78 args = [] | |
| 79 | |
| 80 if (is_official_build) { | |
| 81 args += [ "--official" ] | |
| 82 } | |
| 83 | |
| 84 if (defined(invoker.sources)) { | |
| 85 inputs += invoker.sources | |
| 86 foreach(i, invoker.sources) { | |
| 87 args += [ | |
| 88 "-f", | |
| 89 rebase_path(i, root_build_dir), | |
| 90 ] | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 if (defined(invoker.extra_args)) { | |
| 95 args += invoker.extra_args | |
| 96 } | |
| 97 args += [ | |
| 98 "-o", | |
| 99 rebase_path(invoker.output, root_build_dir), | |
| 100 ] | |
| 101 if (defined(invoker.template_file)) { | |
| 102 args += [ rebase_path(invoker.template_file, root_build_dir) ] | |
| 103 } | |
| 104 | |
| 105 forward_variables_from(invoker, [ "deps" ]) | |
| 106 | |
| 107 if (process_only) { | |
| 108 # When processing only, visibility gets applied to this target. | |
| 109 forward_variables_from(invoker, [ "visibility" ]) | |
| 110 } else { | |
| 111 # When linking the result, only the source set can depend on the action. | |
| 112 visibility = [ ":$source_set_name" ] | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 if (!process_only) { | |
| 117 source_set(source_set_name) { | |
| 118 forward_variables_from(invoker, [ "visibility" ]) | |
| 119 sources = get_target_outputs(":$action_name") | |
| 120 public_deps = [ | |
| 121 ":$action_name", | |
| 122 ] | |
| 123 } | |
| 124 } | |
| 125 } | |
| OLD | NEW |