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

Side by Side Diff: build/build_header.gni

Issue 1458653002: New build flag system, convert Google Now flag (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GYP Created 5 years 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
OLDNEW
(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.
6 # The GYP version of this (with instructions) is build/build_header.gypi.
7 #
8 # The flags are converted to function-style defines with mangled names and
9 # code uses an accessor macro to access the values. This is to try to
10 # minimize bugs where code checks whether something is defined or not, and
11 # the proper header isn't included, meaning the answer will always be silently
12 # false or might vary across the code base.
13 #
14 # In the GN template, specify build flags in the template as a list
15 # of strings that encode key/value pairs like this:
16 #
17 # flags = [ "ENABLE_FOO=1", "ENABLE_BAR=$enable_bar" ]
18 #
19 # The GN values "true" and "false" will be mapped to 0 and 1 for boolean
20 # #if flags to be expressed naturally. This means you can't directly make a
21 # define that generates C++ value of true or false for use in code. In this
22 # unusual case, it's probably best to have two declarations of the boolean
23 # guarded by an ifdef, but you can also use the string "(true)" and "(false)"
24 # to prevent the rewriting.
25
26 # To check the value of the flag in C code:
27 #
28 # #include "path/to/here/header_file.h"
29 #
30 # #if BUILDFLAG(ENABLE_FOO)
31 # ...
32 # #endif
33 #
34 # const char kSpamServerUrl[] = BUILDFLAG(SPAM_SERVER_URL);
35 #
36 # There will no #define called ENABLE_FOO so if you accidentally test for that
37 # in an ifdef it will always be negative.
38 #
39 #
40 # Template parameters
41 #
42 # flags [required, list of strings]
43 # Flag values as described above.
44 #
45 # header [required, string]
46 # File name for generated header. By default, this will go in the
47 # generated file directory for this target, and you would include it
48 # with:
49 # #include "<path_to_this_BUILD_file>/<header>"
50 #
51 # header_dir [optional, string]
52 # Override the default location of the generated header. The string will
53 # be treated as a subdirectory of the root_gen_dir. For example:
54 # header_dir = "foo/bar"
55 # Then you can include the header as:
56 # #include "foo/bar/baz.h"
57 #
58 # deps, public_deps, testonly, visibility
59 # Normal meaning.
60 #
61 #
62 # Grit defines
63 #
64 # If one .grd file uses a flag, just add to the grit target:
65 #
66 # defines = [
67 # "enable_doom_melon=$enable_doom_melon",
68 # ]
69 #
70 # If multiple .grd files use it, you'll want to put the defines in a .gni file
71 # so it can be shared. Generally this .gni file should include all grit defines
72 # for a given module (for some definition of "module"). Then do:
73 #
74 # defines = ui_grit_defines
75 #
76 # If you forget to do this, the flag will be implicitly false in the .grd file
77 # and those resources won't be compiled. You'll know because the resource
78 # #define won't be generated and any code that uses it won't compile. If you
79 # see a missing IDS_* string, this is probably the reason.
80 #
81 #
82 # Example
83 #
84 # build_header("foo_features") {
85 # header = "foo_features.h"
86 #
87 # flags = [
88 # # This uses the GN build flag enable_doom_melon as the definition.
89 # "ENABLE_DOOM_MELON=$enable_doom_melon",
90 #
91 # # This force-enables the flag.
92 # "ENABLE_SPACE_LASER=true",
93 #
94 # # This will expand to the quoted C string when used in source code.
95 # "SPAM_SERVER_URL=\"http://www.example.com/"",
Mark Mentovai 2015/11/24 14:33:33 Missing a backslash.
brettw 2015/11/24 23:36:01 Done.
96 # ]
97 # }
98 template("build_header") {
99 action(target_name) {
100 script = "//build/write_build_header.py"
101
102 if (defined(invoker.header_dir)) {
103 header_file = "${invoker.header_dir}/${invoker.header}"
104 } else {
105 # Compute the path from the root to this file.
106 header_file = rebase_path(".", "//") + "/${invoker.header}"
107 }
108
109 outputs = [
110 "$root_gen_dir/$header_file",
111 ]
112
113 # Always write --flags to the file so it's not empty. Empty will confuse GN
114 # into thinking the response file isn't used.
115 response_file_contents = [ "--flags" ]
116 if (defined(invoker.flags)) {
117 response_file_contents += invoker.flags
118 }
119
120 args = [
121 "--output",
122 header_file, # Not rebased, Python script puts it inside gen-dir.
123 "--rulename",
124 get_label_info(":$target_name", "label_no_toolchain"),
125 "--gen-dir",
126 rebase_path(root_gen_dir, root_out_dir),
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698