Commit 8a05b7f0 authored by brettw's avatar brettw Committed by Commit bot

Clarify and update GN build flags docs.

Some of the documentation was unclear and out-of-date, and also didn't really list what to do instead.

Review URL: https://codereview.chromium.org/1125033004

Cr-Commit-Position: refs/heads/master@{#330761}
parent 12945053
...@@ -2,21 +2,6 @@ ...@@ -2,21 +2,6 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
# =============================================================================
# BUILD FLAGS
# =============================================================================
#
# This block lists input arguments to the build, along with their default
# values. GN requires listing them explicitly so it can validate input and have
# a central place to manage the build flags.
#
# If a value is specified on the command line, it will overwrite the defaults
# given here, otherwise the default will be injected into the root scope.
#
# KEEP IN ALPHABETICAL ORDER and write a good description for everything.
# Use "is_*" names for intrinsic platform descriptions and build modes, and
# "use_*" names for optional features libraries, and configurations.
if (target_os == "") { if (target_os == "") {
target_os = host_os target_os = host_os
} }
...@@ -40,6 +25,59 @@ if (current_os == "") { ...@@ -40,6 +25,59 @@ if (current_os == "") {
current_os = target_os current_os = target_os
} }
# =============================================================================
# BUILD FLAGS
# =============================================================================
#
# This block lists input arguments to the build, along with their default
# values.
#
# If a value is specified on the command line, it will overwrite the defaults
# given in a declare_args block, otherwise the default will be used.
#
# YOU SHOULD ALMOST NEVER NEED TO ADD FLAGS TO THIS FILE. GN allows any file in
# the build to declare build flags. If you need a flag for a single component,
# you can just declare it in the corresponding BUILD.gn file. If you need a
# flag in multiple components, there are a few options:
#
# - If your feature is a single target, say //components/foo, and the targets
# depending on foo need to have some define set if foo is enabled: (1) Write
# a declare_args block in foo's BUILD.gn file listing your enable_foo build
# flag. (2) Write a config in that file listing the define, and list that
# config in foo's public_configs. This will propagate that define to all the
# targets depending on foo. (3) When foo is not enabled, just make it expand
# to an empty group (or whatever's appropriate for the "off" state of your
# feature.
#
# - If a semi-random set of targets need to know about a define: (1) In the
# lowest level of the build that knows about this feature, add a declare_args
# block in the build file for your enable flag. (2) Write a config that adds
# a define conditionally based on that build flags. (3) Manually add that
# config to the "configs" applying to the targets that need the define.
#
# - If a semi-random set of targets need to know about the build flag (to do
# file inclusion or exclusion, more than just defines): (1) Write a .gni file
# in the lowest-level directory that knows about the feature. (2) Put the
# declare_args block with your build flag in that .gni file. (3) Import that
# .gni file from the BUILD.gn files that need the flag.
#
# Other advice:
#
# - Use boolean values when possible. If you need a default value that expands
# to some complex thing in the default case (like the location of the
# compiler which would be computed by a script), use a default value of -1 or
# the empty string. Outside of the declare_args block, conditionally expand
# the default value as necessary.
#
# - Use a name like "use_foo" or "is_foo" (whatever is more appropriate for
# your feature) rather than just "foo".
#
# - Write good comments directly above the declaration with no blank line.
# These comments will appear as documentation in "gn args --list".
#
# - Don't call exec_script inside declare_args. This will execute the script
# even if the value is overridden, which is wasteful. See first bullet.
declare_args() { declare_args() {
# How many symbols to include in the build. This affects the performance of # How many symbols to include in the build. This affects the performance of
# the build since the symbols are large and dealing with them is slow. # the build since the symbols are large and dealing with them is slow.
...@@ -93,6 +131,8 @@ declare_args() { ...@@ -93,6 +131,8 @@ declare_args() {
# toolchains. # toolchains.
cros_use_custom_toolchain = false cros_use_custom_toolchain = false
} }
# DON'T ADD MORE FLAGS HERE. Read the comment above.
} }
# ============================================================================= # =============================================================================
......
...@@ -6,6 +6,10 @@ ...@@ -6,6 +6,10 @@
# #
# TODO(brettw) this should probably be moved to src/crypto or somewhere, and # TODO(brettw) this should probably be moved to src/crypto or somewhere, and
# the global build dependency on it should be removed. # the global build dependency on it should be removed.
#
# PLEASE TRY TO AVOID ADDING FLAGS TO THIS FILE in cases where grit isn't
# required. See the declare_args block of BUILDCONFIG.gn for advice on how
# to set up feature flags.
declare_args() { declare_args() {
# Use OpenSSL instead of NSS. This is used for Android, Mac, NaCl untrusted # Use OpenSSL instead of NSS. This is used for Android, Mac, NaCl untrusted
......
...@@ -2,14 +2,17 @@ ...@@ -2,14 +2,17 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
# This file contains UI-related build flags. It should theoretically be in the # This file contains Chrome-feature-related build flags (see ui.gni for
# src/ui directory and only things that depend on the ui module should get the # UI-related ones). These should theoretically be moved to the build files of
# definitions. # the features themselves.
# #
# However, today we have many "bad" dependencies on some of these flags from, # However, today we have many "bad" dependencies on some of these flags from,
# e.g. base, so they need to be global. # e.g. base, so they need to be global to match the GYP configuration. Also,
# anything that needs a grit define must be in either this file or ui.gni.
# #
# See also build/config/ui.gni # PLEASE TRY TO AVOID ADDING FLAGS TO THIS FILE in cases where grit isn't
# required. See the declare_args block of BUILDCONFIG.gn for advice on how
# to set up feature flags.
import("//build/config/chrome_build.gni") import("//build/config/chrome_build.gni")
if (is_android) { if (is_android) {
......
...@@ -2,14 +2,17 @@ ...@@ -2,14 +2,17 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
# This file contains UI-related build flags. It should theoretically be in the # This file contains UI-related build flags (see features.gni for Chrome
# src/ui directory and only things that depend on the ui module should get the # feature-related ones). These should theoretically be moved to the ui
# definitions. # directory.
# #
# However, today we have many "bad" dependencies on some of these flags from, # However, today we have many "bad" dependencies on some of these flags from,
# e.g. base, so they need to be global. # e.g. base, so they need to be global to match the GYP configuration. Also,
# anything that needs a grit define must be in either this file or features.gni.
# #
# See also build/config/features.gni # PLEASE TRY TO AVOID ADDING FLAGS TO THIS FILE in cases where grit isn't
# required. See the declare_args block of BUILDCONFIG.gn for advice on how
# to set up feature flags.
declare_args() { declare_args() {
# Indicates if Ash is enabled. Ash is the Aura Shell which provides a # Indicates if Ash is enabled. Ash is the Aura Shell which provides a
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment