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

Unified 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: merge Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: build/build_header.gni
diff --git a/build/build_header.gni b/build/build_header.gni
new file mode 100644
index 0000000000000000000000000000000000000000..da6886c5e2c6e0749f819c6c4d2cdcd10a52329b
--- /dev/null
+++ b/build/build_header.gni
@@ -0,0 +1,139 @@
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+# 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
+#
+# There are two categories of defines. The first are "flags" which are enable/
+# disable options that are either true or false. Specify these in the template
+# as a list of strings that encode key/value pairs like this:
+#
+# flags = [ "ENABLE_FOO=1", ENABLE_BAR=$enable_bar" ]
+#
+# The value must either be 0/1 or true/false or an error will be thrown at
+# build time. To check the value of the flag in C code:
+#
+# #include "path/to/here/header_file.h"
+#
+# #if BUILDFLAG(ENABLE_FOO)
+# ...
+#
+# The second category are "variables" where the value of the define is
+# important rather than just a true/false value. In this case, the value is
+# just emitted in the header so should be in C format.
+#
+# variables = [ "FOO_PATH=\"/la/dee/da\" ]
+#
+# And then use like:
+#
+# #include "path/to/here/header_file.h"
+#
+# const char kMyPath[] = BUILDVAR(FOO_PATH)
+#
+#
+# Template parameters
+#
+# header [required, string]
+# File name for generated header. By default, this will go in the
+# generated file directory for this target, and you would include it
+# with:
+# #include "<path_to_this_BUILD_file>/<header>"
+#
+# header_dir [string, optional]
+# Override the default location of the generated header. The string will
+# be treated as a subdirectory of the root_gen_dir. For example:
+# header_dir = "foo/bar"
+# Then you can include the header as:
+# #include "foo/bar/baz.h"
+#
+# deps, public_deps, testonly, visibility
+# Normal meaning.
+#
+#
+# Grit defines
+#
+# If one .grd file uses a flag, just add to the grit target:
+#
+# defines = [
+# "enable_doom_melon=$enable_doom_melon",
+# ]
+#
+# If multiple .grd files use it, you'll want to put the defines in a .gni file
+# so it can be shared. Generally this .gni file should include all grit defines
+# for a given module (for some definition of "module"). Then do:
+#
+# defines = ui_grit_defines
+#
+# If you forget to do this, the flag will be implicitly false in the .grd file
+# and those resources won't be compiled. You'll know because the resource
+# #define won't be generated and any code that uses it won't compile. If you
+# see a missing IDS_* string, this is probably the reason.
+#
+#
+# Example
+#
+# build_header("foo_features") {
+# header = "foo_features.h"
+#
+# flags = [
+# # This uses the GN build flag enable_doom_melon as the definition.
+# "ENABLE_DOOM_MELON=$enable_doom_melon",
+#
+# # This force-enables the flag.
+# "ENABLE_SPACE_LASER=1",
+# ]
+#
+# variables = [
+# "SPAM_SERVER_URL=\"http://www.example.com/",
Mark Mentovai 2015/11/19 21:52:55 You probably want a \" on the end too.
+# ]
+# }
+template("build_header") {
+ action(target_name) {
+ script = "//build/write_build_header.py"
+
+ if (defined(invoker.header_dir)) {
+ header_dir = "$root_gen_dir/${invoker.header_dir}"
+ path_for_guard = "${invoker.header_dir}/${invoker.header}"
+ } else {
+ header_dir = target_gen_dir
+
+ # Compute the path from teh root to this file.
Mark Mentovai 2015/11/19 21:52:55 teh
+ path_for_guard = get_path_info(rebase_path(".", "//"), "dir")
+ path_for_guard += "/${invoker.header}"
+ }
+
+ gen_header_file = "$header_dir/${invoker.header}"
+
+ outputs = [
+ gen_header_file,
+ ]
+
+ # Always write --flags and --variables to the file so it's not empty.
+ # Empty will confuse GN into thinking the response file isn't used.
+ response_file_contents = [ "--flags" ]
+ if (defined(invoker.flags)) {
+ response_file_contents += invoker.flags
+ }
+ response_file_contents += [ "--variables" ]
+ if (defined(invoker.variables)) {
+ response_file_contents += invoker.variables
+ }
+
+ args = [
+ "--output",
+ rebase_path(gen_header_file, root_build_dir),
+ "--path-for-guard",
+ path_for_guard,
+ "--definitions",
+ "{{response_file_name}}",
+ ]
+
+ forward_variables_from(invoker,
+ [
+ "deps",
+ "public_deps",
+ "testonly",
+ "visibility",
+ ])
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698