Linux command
gn 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Generate
gn gen [out/Default]
Generate
gn gen [out/Default] --args='is_debug=true target_cpu="x64"'
Open
gn args [out/Default]
List
gn args [out/Default] --list
Describe
gn desc [out/Default] [//base:base]
List
gn ls [out/Default]
Check
gn check [out/Default]
Format
gn format [path/to/BUILD.gn]
说明
gn is a meta-build system used by Chromium, Fuchsia, V8, Skia, ANGLE, Dart, and other large native projects. It reads .gn dotfiles and BUILD.gn files written in a small declarative language, then emits Ninja build files for fast incremental builds. Targets are declared in BUILD.gn files using rules such as executable, static_library, shared_library, source_set, group, and action. Targets reference other targets via deps (private) and public_deps, and pull in compile flags via configs, public_configs, defines, include_dirs, and sources. Properties can be appended or removed per-target with += and -=. Build configuration lives in args.gn inside each output directory, allowing many parallel build configurations (debug, release, cross-compile, instrumented) without re-checking out the source tree. Cross-compilation is configured through target_os and target_cpu arguments.
参数
- gen _out_dir_ --args=_string_
- Generate Ninja build files for _out_dir_. --args sets build arguments inline; arguments are stored in _out_dir_/args.gn.
- args _out_dir_ --list[=_arg_] --short --overrides-only
- Open _out_dir_/args.gn in $EDITOR, or list arguments. --list shows defaults and help text; pass an argument name for a single entry.
- desc _out_dir_ _target_ _what_
- Print information about _target_. _what_ may be sources, deps, configs, public, defines, include_dirs, runtime_deps, etc.
- ls _out_dir_ _label_pattern_
- List matching targets. Pattern supports wildcards such as //base/\*.
- refs _out_dir_ _target_ --all
- Show targets that depend on _target_.
- path _out_dir_ _target1_ _target2_
- Show a dependency path between two targets.
- check _out_dir_ _label_pattern_
- Run include-rule checking. Equivalent to gn gen --check without writing build files.
- format --dry-run --stdin _file.gn_
- Reformat a GN file in canonical style.
- clean _out_dir_
- Delete the contents of _out_dir_ except args.gn, then re-run ninja to repopulate.
- help _command_
- Print general help, or detailed help for a single command, target type, or built-in.
- -q
- Suppress informational output.
- --root=_path_
- Override the source root (where the .gn file lives).
- --dotfile=_path_
- Use a non-default .gn dotfile.
- --script-executable=_path_
- Override the Python interpreter used by exec_script.
- --time
- Print timing information for build steps.
- --tracelog=_file_
- Write a Chrome-trace-format log of GN's execution.
FAQ
What is the gn command used for?
gn is a meta-build system used by Chromium, Fuchsia, V8, Skia, ANGLE, Dart, and other large native projects. It reads .gn dotfiles and BUILD.gn files written in a small declarative language, then emits Ninja build files for fast incremental builds. Targets are declared in BUILD.gn files using rules such as executable, static_library, shared_library, source_set, group, and action. Targets reference other targets via deps (private) and public_deps, and pull in compile flags via configs, public_configs, defines, include_dirs, and sources. Properties can be appended or removed per-target with += and -=. Build configuration lives in args.gn inside each output directory, allowing many parallel build configurations (debug, release, cross-compile, instrumented) without re-checking out the source tree. Cross-compilation is configured through target_os and target_cpu arguments.
How do I run a basic gn example?
Run `gn gen [out/Default]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does gen _out_dir_ --args=_string_ do in gn?
Generate Ninja build files for _out_dir_. --args sets build arguments inline; arguments are stored in _out_dir_/args.gn.