Title: Theory / Important / CS / Programming / Build / GN
Tags: automatedNewLineAfterCommaSpace
On every note of this deck, unless a note says otherwise:
Page: https://gn.googlesource.com/gn/+/HEAD/docs/style_guide.md

Name: GN
Definition: Build system for some open source google project
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md

Question: How to obtain GN
Answer: It is usually packaged with source of large project
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md

Question: Advantage of gn over most build system
Answer: It let you generate many distinct build by allowing to configure the build directory
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md

Instruction: gn gen out/my_build
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Language: sh
Returns: Generate a folder out/my_build where the current gn is compiled to

Instruction: gn args out/my_build
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Effect: open an editor allowing to configure the project variables for build out/my_build
Language: sh

Instruction: gn args --list out/my_build
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Effect: List all configuration variables that can be configured for out/my_build
Language: sh

Instruction: group(
  name
) {
  deps = [
    dep_1,
  ...,
  dep_n
  ]
}
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Meaning: the dependency name is equivalent to dependencies to all of the dep_i
Language: GN
Identifier: name
Name: A group

Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Syntactic sugar: :foo
Implementation: current file's target foo
Language: GN
Context: deps

Variable: defines
Meaning: preprocessore defines for current target
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Language: GN

Instruction: executable(name) {
  ..
}
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Meaning: Introduce an executable that can be compiled with ninja
Language: GN
Identifier: name

Variable: sources
Meaning: List of source files for this executable
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Context: executable
Language: GN

Variable: deps
Meaning: List of targets that are dependeded upon by the current target
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Context: target
Language: GN

Instruction: ninja -C out target
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Effect: build target target of folder out into out/target
Language: GN

Instruction: ninja -C out path:target
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Effect: compile path:target from directory out
Language: GN
Intuition: when target is ambiguous

Instruction: group(
  group_name
) {
  deps = [
   dep_1,
   ...,
   dep_n
  ]
}
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Meaning: the set of dependencies dep_1, ... to dep_n
Language: GN
Identifier: group_name

Instruction: static_library(name) {
}
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Meaning: A static library
Language: GN

Instruction: shared_library(
  name
) {
  sources = [
   source_1,
   ...,
   sorce_n
  ]
  defines = [
  "output_1",
  ...,
  "output_n"]
}
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Meaning: A shared library outputting methods output_1,
  ...,
  outp_n
Language: gn

Instruction: config("config_name") {
  param_1 = value_1
  ...
  param_n = value_n
}
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
https://gn.googlesource.com/gn/+/HEAD/docs/language.md
Meaning: specify sets of flags, include directories, and defines
Language: gn
Identifier: config_name
Name: config

Variable: configs
Meaning: The set of configuration for the current group, that are not inherited by other group
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Context: some group
Language: gn

Variable: public_configs
Meaning: The set of configuration for the current group, that are inherited by group depending on the current one
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Context: some group
Language: gn

Instruction: print(group_name)
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Effect: print the definition of group_name in the terminal for debugging
Language: gn
Context: some executable

Instruction: declare_args() {
  arg_1 = default_1,
  ...
  arg_n = default_n
}
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Language: gn
Name: arg_i a build argument
Initialization: default_i

Fla: -v
Effect: Run in verbose mode
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Prefix: gn

Fla: desc build_dir target
Effect: print lot information about target
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Prefix: gn

Fla: depts --tree
Effect: print the tree of dependencies
Page: https://gn.googlesource.com/gn/+/HEAD/docs/quick_start.md
Prefix: gn desc build_dir target

Fla: --list
Effect: list of build arguments for <build_dir>
Page: https://www.chromium.org/developers/gn-build-configuration/
Prefix: gn args <build_dir>

Fla: --list=flag_name
Effect: documentation for flag_name
Page: https://www.chromium.org/developers/gn-build-configuration/
Prefix: gn args <build_dir>

Variable: is_debug
Meaning: whether to run in debug mode
Page: https://www.chromium.org/developers/gn-build-configuration/
Language: gn
Initialization: true

Variable: is_java_debug
Meaning: whethe r to toggle ProGuard
Page: https://www.chromium.org/developers/gn-build-configuration/
Language: gn
Initialization: true

Variable: dcheck_always_on
Meaning: whether to use dcheck
Page: https://www.chromium.org/developers/gn-build-configuration/
Language: gn
Initialization: true

Variable: is_component_build
Meaning: whether to use component_build
Page: https://www.chromium.org/developers/gn-build-configuration/
Language: gn
Initialization: true except for iOS

Variable: symbol_level
Meaning: more symbol for more debugging, but slower executable
Page: https://www.chromium.org/developers/gn-build-configuration/
Language: gn
Initialization: 0

Variable: enable_nacl
Meaning: Whether to enable native client
Page: https://www.chromium.org/developers/gn-build-configuration/
Language: gn

Name: native client
Page: https://www.chromium.org/developers/gn-build-configuration/
Chapter: gn
Abbreviation: nacl

Variable: blink_symbol_level
Meaning: Whether to add the debugging symbols of webcore
Page: https://www.chromium.org/developers/gn-build-configuration/
Language: gn

Variable: v8_symbol_level
Meaning: Whether to add the debugging symbols of v8
Page: https://www.chromium.org/developers/gn-build-configuration/
Language: gn

Variable: target_cpu
Meaning: The cpu to target
Page: https://www.chromium.org/developers/gn-build-configuration/
Language: gn

Variable: use_goma
Meaning: whether to use goma
Page: https://www.chromium.org/developers/gn-build-configuration/
Language: gn

Variable: goma_dir
Meaning: a goma directory if it differs from the one in the depot_tools
Page: https://www.chromium.org/developers/gn-build-configuration/
Language: gn

Variable: is_official_build
Meaning: Whether it's an official build
Page: https://www.chromium.org/developers/gn-build-configuration/
Language: gn
Assuming: having src-internal checked out

Variable: is_chrome_branded
Meaning: Whether to use the name chrome instead of chromium
Page: https://www.chromium.org/developers/gn-build-configuration/
Language: gn

Variable: chrome_pgo_phase
Meaning: whether to enable PGO phase
Page: https://www.chromium.org/developers/gn-build-configuration/
Language: gn

Fla: --ide=vs
Effect: producing Visual Studio project and solution files
Page: https://www.chromium.org/developers/gn-build-configuration/
Prefix: gn gen out\mybuild

Name: A component build
Definition: A build where chrome is composed of many static library instead of a single executable
Page: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/component_build.md
Chapter: chrome

Instruction: component("component name") {
  output_name = "output_name"
  sources = ...
}
Page: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/component_build.md
Meaning: a library that is static or shared depending on whether is_component_build is enabled or disabled
Language: GN
Context: chrome
Name: output_name

Instruction: COMPONENT_EXPORT(YOUR_COMPONENT)
Page: https://chromium.googlesource.com/chromium/src/+/HEAD/docs/component_build.md
Effect: Ensure that currently defined class/method is exported with the chrome component
Language: GN
Context: chrome
Name: output_name

Instruction: template("template_name") {
  foo
  target(target_name) {
    bar
  }
}
Page: https://gn.googlesource.com/gn/+/HEAD/docs/language.md
Meaning: A template which, when instantiated, execute foo and define target_name
Language: GN
Identifier: template_name
Name: template
Extra: There are a lot of other Android ones, see //build/config/android/rules.gni.

Extension: gni
Means: GN Interface
Other fields (not shown on cards):
Page: https://gn.googlesource.com/gn/+/HEAD/docs/language.md

Question: In which ordre should be targets and config in a .gn file?
Answer: First target has the name of the directory
Answer2: By order of decreasing importance
Answer3: Config should appear just before target taht use it

Question: how to make test support library in GN
Answer: should be static libraries named “test_support”. For example, “//ui/compositor:test_support”. Test support libraries should include as public deps the non-test-support version of the library so tests need only depend on the test_support target (rather than both).
Context: GN

Question: Which case to use for target name
Answer: lower_case_with_underscore
Context: GN

Question: Which case to use for config name
Answer: lower_case_with_underscore
Context: GN

Question: Preference for source set name
Answer: small and clear, no need for uniqueness
Context: GN

Question: Preference for group name
Answer: small and clear, no need for uniqueness
Context: GN

Question: Preference for static library name
Answer: small and clear, no need for uniqueness
Context: GN

Question: Preference for shared library name
Answer: Unique name (in output_name), short non-unique name in the target
Context: GN

Question: Preference for component name
Answer: Unique name (in output_name), short non-unique name in the target
Context: GN

Question: Preference for executable name
Answer: Unique name. Same for target name and output_name
Context: GN

Question: Preference for test name
Answer: Unique name. Same for target name and output_name
Context: GN

Question: Preference for config name
Answer: if its associated with a single target t, then t_config
Context: GN

Question: In which order are target element
Answer: output_name/visibility/testonly
Context: GN
Answer2: sources
Answer3: cflags, include_dirs, defines, configs
Answer4: public_deps
Answer5: deps

Question: style guide for condition
Answer: minimize the number of conditional block
Context: GN
Answer2: condition affecting a single variable are just after the variable
condition affecting many variable are at the bottom

Question: style guide for variables
Answer: lower_case_with_underscores
Context: GN

Question: style guide for comments
Answer: complete sentences with comma at the end
Context: GN

Question: style guide for compiler flag
Answer: should be commend with what they do and why the flag is needed
Context: GN

Question: style guide for source
Answer: Include each source once. That is, if they are used in a single case, add them in this case. Otherwise, add them by default and remove them in the case they are not needed
Context: GN

Question: style guide for deps order
Answer: Start with the current file
Context: GN
Answer2: Alphabetical order

Question: style guide for deps name
Answer: deps withing current deps should not qualified with the file name,
other deps use full name
Context: GN

Question: style guide for import name
Answer: use fully-qualified paths
Context: GN

Variable: use_foo
Meaning: Whether foo should be included
Page: https://gn.googlesource.com/gn/+/HEAD/docs/style_guide.md
Language: GN
Variables: foo dependency or major codepath

Variable: enable_foo
Meaning: Whether foo should be enabled
Page: https://gn.googlesource.com/gn/+/HEAD/docs/style_guide.md
Language: GN
Variables: foo a Chrome feature

Variable: is_foo
Meaning: Whether foo holds
Page: https://gn.googlesource.com/gn/+/HEAD/docs/style_guide.md
Language: GN
Variables: foo a global state descriptor

Variable: foo_use_bar
Meaning: indicate that argument bar has limited scope foo
Page: https://gn.googlesource.com/gn/+/HEAD/docs/style_guide.md
Language: GN

Variable: _variable_starting_with_underscore
Meaning: variable not exported
Page: https://gn.googlesource.com/gn/+/HEAD/docs/style_guide.md
Language: GNI