Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015 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 # Generates a header with preprocessor defines specified by the build file. | |
|
Mark Mentovai
2015/11/19 21:52:55
The gypi version points to here, which is a good h
| |
| 6 # | |
| 7 # There are two categories of defines. The first are "flags" which are enable/ | |
| 8 # disable options that are either true or false. Specify these in the template | |
| 9 # as a list of strings that encode key/value pairs like this: | |
| 10 # | |
| 11 # flags = [ "ENABLE_FOO=1", ENABLE_BAR=$enable_bar" ] | |
| 12 # | |
| 13 # The value must either be 0/1 or true/false or an error will be thrown at | |
| 14 # build time. To check the value of the flag in C code: | |
| 15 # | |
| 16 # #include "path/to/here/header_file.h" | |
| 17 # | |
| 18 # #if BUILDFLAG(ENABLE_FOO) | |
| 19 # ... | |
| 20 # | |
| 21 # The second category are "variables" where the value of the define is | |
| 22 # important rather than just a true/false value. In this case, the value is | |
| 23 # just emitted in the header so should be in C format. | |
| 24 # | |
| 25 # variables = [ "FOO_PATH=\"/la/dee/da\" ] | |
| 26 # | |
| 27 # And then use like: | |
| 28 # | |
| 29 # #include "path/to/here/header_file.h" | |
| 30 # | |
| 31 # const char kMyPath[] = BUILDVAR(FOO_PATH) | |
| 32 # | |
| 33 # | |
| 34 # Template parameters | |
| 35 # | |
| 36 # header [required, string] | |
| 37 # File name for generated header. By default, this will go in the | |
| 38 # generated file directory for this target, and you would include it | |
| 39 # with: | |
| 40 # #include "<path_to_this_BUILD_file>/<header>" | |
| 41 # | |
| 42 # header_dir [string, optional] | |
| 43 # Override the default location of the generated header. The string will | |
| 44 # be treated as a subdirectory of the root_gen_dir. For example: | |
| 45 # header_dir = "foo/bar" | |
| 46 # Then you can include the header as: | |
| 47 # #include "foo/bar/baz.h" | |
| 48 # | |
| 49 # deps, public_deps, testonly, visibility | |
| 50 # Normal meaning. | |
| 51 # | |
| 52 # | |
| 53 # Grit defines | |
| 54 # | |
| 55 # If one .grd file uses a flag, just add to the grit target: | |
| 56 # | |
| 57 # defines = [ | |
| 58 # "enable_doom_melon=$enable_doom_melon", | |
| 59 # ] | |
| 60 # | |
| 61 # If multiple .grd files use it, you'll want to put the defines in a .gni file | |
| 62 # so it can be shared. Generally this .gni file should include all grit defines | |
| 63 # for a given module (for some definition of "module"). Then do: | |
| 64 # | |
| 65 # defines = ui_grit_defines | |
| 66 # | |
| 67 # If you forget to do this, the flag will be implicitly false in the .grd file | |
| 68 # and those resources won't be compiled. You'll know because the resource | |
| 69 # #define won't be generated and any code that uses it won't compile. If you | |
| 70 # see a missing IDS_* string, this is probably the reason. | |
| 71 # | |
| 72 # | |
| 73 # Example | |
| 74 # | |
| 75 # build_header("foo_features") { | |
| 76 # header = "foo_features.h" | |
| 77 # | |
| 78 # flags = [ | |
| 79 # # This uses the GN build flag enable_doom_melon as the definition. | |
| 80 # "ENABLE_DOOM_MELON=$enable_doom_melon", | |
| 81 # | |
| 82 # # This force-enables the flag. | |
| 83 # "ENABLE_SPACE_LASER=1", | |
| 84 # ] | |
| 85 # | |
| 86 # variables = [ | |
| 87 # "SPAM_SERVER_URL=\"http://www.example.com/", | |
|
Mark Mentovai
2015/11/19 21:52:55
You probably want a \" on the end too.
| |
| 88 # ] | |
| 89 # } | |
| 90 template("build_header") { | |
| 91 action(target_name) { | |
| 92 script = "//build/write_build_header.py" | |
| 93 | |
| 94 if (defined(invoker.header_dir)) { | |
| 95 header_dir = "$root_gen_dir/${invoker.header_dir}" | |
| 96 path_for_guard = "${invoker.header_dir}/${invoker.header}" | |
| 97 } else { | |
| 98 header_dir = target_gen_dir | |
| 99 | |
| 100 # Compute the path from teh root to this file. | |
|
Mark Mentovai
2015/11/19 21:52:55
teh
| |
| 101 path_for_guard = get_path_info(rebase_path(".", "//"), "dir") | |
| 102 path_for_guard += "/${invoker.header}" | |
| 103 } | |
| 104 | |
| 105 gen_header_file = "$header_dir/${invoker.header}" | |
| 106 | |
| 107 outputs = [ | |
| 108 gen_header_file, | |
| 109 ] | |
| 110 | |
| 111 # Always write --flags and --variables to the file so it's not empty. | |
| 112 # Empty will confuse GN into thinking the response file isn't used. | |
| 113 response_file_contents = [ "--flags" ] | |
| 114 if (defined(invoker.flags)) { | |
| 115 response_file_contents += invoker.flags | |
| 116 } | |
| 117 response_file_contents += [ "--variables" ] | |
| 118 if (defined(invoker.variables)) { | |
| 119 response_file_contents += invoker.variables | |
| 120 } | |
| 121 | |
| 122 args = [ | |
| 123 "--output", | |
| 124 rebase_path(gen_header_file, root_build_dir), | |
| 125 "--path-for-guard", | |
| 126 path_for_guard, | |
| 127 "--definitions", | |
| 128 "{{response_file_name}}", | |
| 129 ] | |
| 130 | |
| 131 forward_variables_from(invoker, | |
| 132 [ | |
| 133 "deps", | |
| 134 "public_deps", | |
| 135 "testonly", | |
| 136 "visibility", | |
| 137 ]) | |
| 138 } | |
| 139 } | |
| OLD | NEW |