Chromium GN built using tools

Chromium GN built using tools

Chromium generally the entire construction process is as follows:

 

 

 

This process generally, first gn tool according .gn profile of each module, or tool according .gyp gyp profile of each module, generating .ninja file, then the file generated by the ultimate goal ninja tools, such as static library, dynamic library, exe executable file or the apk file, and so on. gyp tool is written in Python, gn is written in C, gn incremental build the fastest. Chromium entire project, in building the system, is gradually turning all gn building.

 

All other modules gn tool only when we build chromium can be used to generate .ninja file, it can help us project a map depicting the chromium, such as access to all other modules in a module dependent, dependent on a module, the build parameters and other information that can help us to build the effectiveness of configuration checks and so on. When chromium-based development module, gn tool can provide great help for us.

 

Here we look at the usage of tools gn, gn each command one by one to see provided.

 

gn args

 

This command has two functions, one generation .ninja build configuration file, the second is to view the current build configuration parameters for the environment.

 

Generate .ninja

 

.Ninja generation is the basic function gn tools. As in  Chromium Android compile guidelines  shown, to build chromium, or one of the modules, Mr. .ninja need to file configuration of the complete build environment. When is the Android version of chromium do build configuration, the command is executed:

 

buildtools/linux64/gn args out/Default

The parameters of this command is the path to the output directory. This command starts the system's default editor, create a out/Default/args.gnfile, we add our own entry in the configuration editor, such as:

 

target_os = "android"
target_cpu = "arm"  # (default)
is_debug = false  # (default)

# Other args you may want to set:
is_component_build = false
is_clang = false
symbol_level = 1  # Faster build with fewer symbols. -g1 rather than -g2
enable_incremental_javac = false  # Much faster; experimental
android_ndk_root = "~/dev_tools/Android/android-ndk-r10e"
android_sdk_root = "~/dev_tools/Android/sdk"
android_sdk_build_tools_version = "23.0.2"

disable_file_support = true
disable_ftp_support = true
enable_websockets = false

gn created according to out/Default/args.gnthe file, and other system configuration files generated ninja.

View current configuration and build environment

 

gn args command can also view the current parameters you can configure the build environment, and other parameters of the configuration file defaults and default values. chromium used in a number of configuration parameters. For most of these parameters in the configuration, even if the user is not specified, the system will build Chromium provides default values. When we do not know is what kind of configuration can be done to build, the meaning of each configuration item, or the location of the configuration item defaults and crazy, this command will be very valuable.

 

For Android Chromium build environment, can be arranged and parameter information substantially as follows:

 

$ buildtools/linux64/gn args --list out/Default/
......
android_ndk_root  Default = "//third_party/android_tools/ndk"
    //build/config/android/config.gni:66

android_ndk_version  Default = "r10e"
    //build/config/android/config.gni:67

android_sdk_build_tools_version  Default = "23.0.1"
    //build/config/android/config.gni:71

android_sdk_root  Default = "//third_party/android_tools/sdk"
    //build/config/android/config.gni:69
......
use_platform_icu_alternatives  Default = true
    //url/features.gni:10
    Enables the use of ICU alternatives in lieu of ICU. The flag is used
    for Cronet to reduce the size of the Cronet binary.
......

Gn args parameter to the function of the command --list [output_dir]. Gn visible to show us able to build customized for each parameter, parameter default values, and set the position parameter default values file. This tool shows the name of each tag configuration items, defaults, create a configuration file the tag configuration items, configuration items and instructions marked effect.

gn gen

 

This command is used to generate .ninja file, the following parameters:

 

usage:  gn gen [<ide options>] <out_dir>

According to this command the current code tree, and configuration file is generated ninja, and put them in a given directory. Output directory can be an absolute address of the source library, for example //out/foo, it may be relative to the current directory address, such as: out/foo. The above gn args out/Defaultis essentially equivalent to create a boot editor to edit the parameters out/Default/args.gnafter the file is executed gn gen <out_dir>.

 

When the actual construction of chromium and its sub-modules, the command will be more commonly used. For specific platform, we usually after completing the build configuration environment, you will not often need to modify the build configuration parameter file.

 

gn clean

 

This command is used to clean historic building.

 

usage:  gn clean <out_dir>

It removes the output directory in addition to args.gnall the contents of the documents, and to create a ninja can reproduce the build configuration of the build environment. This command is also more commonly used to eliminate the influence of the historical building.

 

gn desc

 

This command is used to display information about a given target or the config.

 

usage:  gn desc <out_dir> <label or pattern> [<what to show>] [--blame] [--format=json]

Build parameters and other related information, taken from given <out_dir>. <label or pattern>It may be a target tag, a config tag, or a tag mode (refer to "gn help label_pattern"). Tag mode only match targets.

 

For example, we want to see information related to the net chromium modules:

 

$ gn desc out/Default net
Target //net:net
Type: source_set
Toolchain: //build/toolchain/android:arm

visibility
*

testonly
false

check_includes
true

allow_circular_includes_from

sources
......
//net/spdy/spdy_buffer.cc
//net/spdy/spdy_buffer.h
//net/spdy/spdy_buffer_producer.cc
//net/spdy/spdy_buffer_producer.h
......

public
[All headers listed in the sources are public.]

configs (in order applying, try also --tree)
......
//third_party/boringssl:external_config
//net:net_resources_grit_config
//base:android_system_libs
//sdch:sdch_config
//third_party/zlib:zlib_config
//net:jni_includes_net_jni_headers

public_configs (in order applying, try also --tree)
//net:net_config
//third_party/protobuf:using_proto
//third_party/protobuf:protobuf_config
//build/config/compiler:no_size_t_to_int_warning
//third_party/boringssl:external_config

all_dependent_configs (in order applying, try also --tree)
//base/allocator:wrap_malloc_symbols

asmflags
-fno-strict-aliasing
--param=ssp-buffer-size=4
-fstack-protector
-funwind-tables
-fPIC
......

cflags
-fno-strict-aliasing
--param=ssp-buffer-size=4
-fstack-protector
-funwind-tables
-fPIC
......

cflags_cc
-fno-threadsafe-statics
-fvisibility-inlines-hidden
-std=gnu++11
-Wno-narrowing
-fno-rtti
-isystem../../../../../../~/dev_tools/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include
-isystem../../../../../../~/dev_tools/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++abi/libcxxabi/include
-isystem../../../../../../~/dev_tools/Android/android-ndk-r10e/sources/android/support/include
-fno-exceptions

cflags_objcc
-fno-threadsafe-statics
-fvisibility-inlines-hidden
-std=gnu++11
-fno-rtti
-fno-exceptions

defines
......
DISABLE_FTP_SUPPORT=1
GOOGLE_PROTOBUF_NO_RTTI
GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER
HAVE_PTHREAD

include_dirs
//
//out/Default/gen/
/usr/include/kerberosV/
//third_party/protobuf/src/
//out/Default/gen/protoc_out/
//third_party/protobuf/src/
......

ldflags
-Wl,--fatal-warnings
-fPIC
......

Direct dependencies (try also "--all", "--tree", or even "--all --tree")
//base:base
......

libs
c++_static
/home/~/dev_tools/Android/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9/libgcc.a
c
atomic
log

lib_dirs
~/dev_tools/Android/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a/

You can see gn desc command to show us, when compiling net module contains all the source files, the module published header files, libraries dependent, dependent header file path, the path-dependent library files, dependent on other modules The compiler parameters, link parameters, predefined macros, etc., etc., everything. When we do not like the project to build the system and its file organization structure chromium, and want to convert a module to other file organization structure, such as Eclipse IDE or other common organization of the project file, or you want to compile out so the dynamic link library file for use in other projects, the time difference is struggling with predefined macros, this command could come in handy.

 

By means of this tool, we can easily develop automated tools to extract the chromium alone modules to be used in other places, for example, we can extract the header files published net module, the module is used in android in net. We have done such a gadget before:

 

#!/usr/bin/env python

import os
import shutil
import sys

def print_usage_and_exit():
    print sys.argv[0] + " [chromium_src_root]" + "[out_dir]" + " [target_name]" + " [targetroot]"
    exit(1)

def copy_file(src_file_path, target_file_path):
    if os.path.exists(target_file_path):
        return
    if not os.path.exists(src_file_path):
        return
    target_dir_path = os.path.dirname(target_file_path)
    if not os.path.exists(target_dir_path):
        os.makedirs(target_dir_path)

    shutil.copy(src_file_path, target_dir_path)

def copy_all_files(source_dir, all_files, target_dir):
    for one_file in all_files:
        source_path = source_dir + os.path.sep + one_file
        target_path = target_dir + os.path.sep + one_file
        copy_file(source_path, target_path)

if __name__ == "__main__":
    if len(sys.argv) < 4 or len(sys.argv) > 5:
        print_usage_and_exit()
    chromium_src_root = sys.argv[1]
    out_dir = sys.argv[2]
    target_name = sys.argv[3]
    target_root_path = "."
    if len(sys.argv) == 5:
        target_root_path = sys.argv[4]
    target_root_path = os.path.abspath(target_root_path)

    os.chdir(chromium_src_root)

    cmd = "gn desc " + out_dir + " " + target_name
    outputs = os.popen(cmd).readlines()
    source_start = False
    all_headers = []

    public_start = False
    public_headers = []

    for output_line in outputs:
        output_line = output_line.strip()
        if output_line.startswith("sources"):
            source_start = True
            continue
        elif source_start and len(output_line) == 0:
            source_start = False
            continue
        elif source_start and output_line.endswith(".h"):
            output_line = output_line[1:]
            all_headers.append(output_line)
        elif output_line == "public":
            public_start = True
            continue
        elif public_start and len(output_line) == 0:
            public_start = False
            continue
        elif public_start:
            public_headers.append(output_line)

    if len(public_headers) == 1:
        public_headers = all_headers
    if len(public_headers) > 1:
        copy_all_files(chromium_src_root, public_headers, target_dir=target_root_path)

This command can also help us dump the entire dependency tree module, such as net module dependency tree:

$ gn desc out/Default //net deps --tree
//base:base
  //base:base_jni_headers
    //base:android_runtime_jni_headers
      //base:android_runtime_jni_headers__jni_Runtime
    //base:base_jni_headers__jni_gen
  //base:base_paths
  //base:base_static
  //base:build_date
......
//url:url_features

Each specific command can show different types of information to which we file from. The option information coding flag C (CFLAGS) of net module are as follows:

 

$ gn desc out/Default //net cflags --blame
From //build/config/compiler:compiler
     (Added by //build/config/BUILDCONFIG.gn:461)
  -fno-strict-aliasing
  --param=ssp-buffer-size=4
  -fstack-protector
  -funwind-tables
  -fPIC
......

gn ls

 

This command is to show to all targets set under the build directory that match a pattern.

 

usage: gn ls <out_dir> [<label_pattern>] [--all-toolchains] [--as=...] [--type=...] [--testonly=...]

By default, unless explicitly provides tools chain parameters, only the default tool chain target will be matched. If you do not specify a label argument, all targets will be displayed. Label mode is not normal regular expressions (refer to "gn help label_pattern"). The net under targets:

 

$ gn ls out/Default //net/*
......
//net:http_server
//net:net
......
//net:net_quic_proto
......
//net:quic_client
//net:quic_packet_printer
//net:quic_server
......

Gn ls command on some other examples:

 

  gn ls out/Debug
      这个命令会列出所有的targets。

  gn ls out/Debug "//base/*"
      Lists all targets in the directory base and all subdirectories.

  gn ls out/Debug "//base:*"
      Lists all targets defined in //base/BUILD.gn.

  gn ls out/Debug //base --as=output
      Lists the build output file for //base:base

  gn ls out/Debug --type=executable
      Lists all executables produced by the build.

  gn ls out/Debug "//base/*" --as=output | xargs ninja -C out/Debug
      Builds all targets in //base and all subdirectories.

  gn ls out/Debug //base --all-toolchains
      Lists all variants of the target //base:base (it may be referenced in multiple toolchains).

gn path

 

This command looks for dependent path between two taregets.

 

usage: gn path <out_dir> <target_one> <target_two>

Each output path is dependent on a group, with the new row is divided between the groups. Any parameter of the order of the two targets. By default, print only one path. If a path contains only public dependency, the shortest public route is output. Otherwise, output the shortest path to public or private. If you specify --with-data, it will consider the data dependency. If there are multiple shortest paths, which will elect a. Plus all dependent path between two targets --all is output.

 

$ gn path out/Default //base //net --all
//net:net --[private]-->
//base:base
......

gn refs

 

This command can be used to find the dependence of the reverse (that is, something's cited targets).

 

gn refs <out_dir> (<label_pattern>|<label>|<file>|@<response_file>)* [--all] [--all-toolchains] [--as=...] [--testonly=...] [--type=...]

These inputs may be as follows:

 

  • Target Label
  • Config tab
  • Tag mode
  • file name
  • The response file

 

This command output is dependent on input parameters have targets, such as:

 

$ gn refs out/Default/ net
//:both_gn_and_gyp
//components/cronet/android:cronet
//components/cronet/android:cronet_static
//net:balsa
//net:crypto_message_printer
//net:disk_cache_memory_test
//net:http_server
//net:quic_client
//net:quic_packet_printer
//net:quic_server
//net:simple_quic_tools
//net:stale_while_revalidate_experiment_domains

Other examples on gn refs command:

 

  gn refs out/Debug //tools/gn:gn
      Find all targets depending on the given exact target name.

  gn refs out/Debug //base:i18n --as=buildfiles | xargs gvim
      Edit all .gn files containing references to //base:i18n

  gn refs out/Debug //base --all
      List all targets depending directly or indirectly on //base:base.

  gn refs out/Debug "//base/*"
      List all targets depending directly on any target in //base or its subdirectories.

  gn refs out/Debug "//base:*"
      List all targets depending directly on any target in //base/BUILD.gn.

  gn refs out/Debug //base --tree
      Print a reverse dependency tree of //base:base

  gn refs out/Debug //base/macros.h
      Print target(s) listing //base/macros.h as a source.

  gn refs out/Debug //base/macros.h --tree
      Display a reverse dependency tree to get to the given file. This will show how dependencies will reference that file.

  gn refs out/Debug //base/macros.h //base/at_exit.h --all
      Display all unique targets with some dependency path to a target containing either of the given files as a source.

  gn refs out/Debug //base/macros.h --testonly=true --type=executable --all --as=output
      Display the executable file names of all test executables potentially affected by a change to the given file.

gn check

 

This command can be used to check the validity of the header file dependencies. The parameters are:

 

gn check <out_dir> [<label_pattern>] [--force]

Such as:

 

$ gn check out/Default/ net
Header dependency check OK

gn help

 

This command will display help information to us gn tool can be used to obtain all relevant information about all of the above gn command, and have built-in targets, built-in predefined variables. Such as:

 

$ gn help
Commands (type "gn help <command>" for more details):
  args: Display or configure arguments declared by the build.
  check: Check header dependencies.
  clean: Cleans the output directory.
  desc: Show lots of insightful information about a target or config.
  format: Format .gn file.
  gen: Generate ninja files.
  help: Does what you think.
  ls: List matching targets.
  path: Find paths between two targets.
  refs: Find stuff referencing a target or file.

Target declarations (type "gn help <function>" for more details):
  action: Declare a target that runs a script a single time.
  action_foreach: Declare a target that runs a script over a set of files.
  bundle_data: [iOS/OS X] Declare a target without output.
  copy: Declare a target that copies files.
  create_bundle: [iOS/OS X] Build an OS X / iOS bundle.
......

 

 

Guess you like

Origin www.cnblogs.com/bigben0123/p/12626012.html
Recommended