From 29f9231bca74e87859527467c06c2ccc85b703e3 Mon Sep 17 00:00:00 2001 From: Ricardo Ribalda Delgado Date: Thu, 28 Jan 2021 19:35:22 +0000 Subject: [PATCH] Import generate-ninja_0.0~git20210128.09c9e5e.orig.tar.gz [dgit import orig generate-ninja_0.0~git20210128.09c9e5e.orig.tar.gz] --- .clang-format | 2 + .editorconfig | 3 + .gitignore | 62 + .style.yapf | 2 + AUTHORS | 49 + LICENSE | 27 + OWNERS | 3 + README.md | 204 + build/build_aix.ninja.template | 13 + build/build_haiku.ninja.template | 13 + build/build_linux.ninja.template | 13 + build/build_mac.ninja.template | 13 + build/build_openbsd.ninja.template | 13 + build/build_win.ninja.template | 12 + build/full_test.py | 81 + build/gen.py | 809 ++ docs/cross_compiles.md | 126 + docs/faq.md | 58 + docs/language.md | 535 ++ docs/quick_start.md | 344 + docs/reference.md | 7818 +++++++++++++++++ docs/standalone.md | 44 + docs/style_guide.md | 306 + examples/ios/.gitignore | 1 + examples/ios/.gn | 2 + examples/ios/BUILD.gn | 10 + examples/ios/app/AppDelegate.h | 9 + examples/ios/app/AppDelegate.m | 32 + examples/ios/app/BUILD.gn | 67 + examples/ios/app/Bar.swift | 8 + examples/ios/app/Baz.swift | 2 + examples/ios/app/Foo-Bridging-Header.h | 0 examples/ios/app/Foo.swift | 12 + examples/ios/app/FooWrapper.swift | 10 + examples/ios/app/SceneDelegate.h | 11 + examples/ios/app/SceneDelegate.m | 29 + examples/ios/app/ViewController.h | 9 + examples/ios/app/ViewController.m | 31 + examples/ios/app/main.m | 15 + examples/ios/app/resources/Info.plist | 64 + .../ios/app/resources/LaunchScreen.storyboard | 25 + examples/ios/app/resources/Main.storyboard | 24 + examples/ios/build/BUILD.gn | 88 + examples/ios/build/BUILDCONFIG.gn | 43 + examples/ios/build/config/ios/BUILD.gn | 24 + .../config/ios/bundle_identifier_prefix.gni | 8 + .../build/config/ios/deployment_target.gni | 9 + .../resources/Entitlements-Simulated.plist | 12 + .../ios/build/config/ios/resources/Info.plist | 22 + .../config/ios/resources/compiler-Info.plist | 33 + .../config/ios/scripts/compile_storyboard.py | 53 + .../ios/scripts/find_app_identifier_prefix.py | 119 + .../ios/scripts/generate_umbrella_header.py | 54 + .../build/config/ios/scripts/merge_plist.py | 134 + .../ios/build/config/ios/scripts/sdk_info.py | 147 + examples/ios/build/config/ios/sdk_info.gni | 14 + .../config/ios/templates/ios_app_bundle.gni | 147 + .../ios/templates/ios_binary_bundle.gni | 121 + .../ios/templates/ios_framework_bundle.gni | 152 + .../config/ios/templates/merge_plist.gni | 85 + .../config/ios/templates/storyboards.gni | 31 + examples/ios/build/toolchain/apple/swiftc.py | 183 + examples/ios/build/toolchain/ios/BUILD.gn | 167 + examples/ios/build/toolchain/mac/BUILD.gn | 119 + examples/ios/host/BUILD.gn | 13 + examples/ios/host/main.cc | 71 + examples/ios/shared/BUILD.gn | 18 + examples/ios/shared/hello_shared.h | 13 + examples/ios/shared/hello_shared.m | 22 + examples/rust_example/.gn | 1 + examples/rust_example/BUILD.gn | 3 + examples/rust_example/BUILDCONFIG.gn | 23 + examples/rust_example/README.txt | 4 + examples/rust_example/build/BUILD.gn | 47 + .../rust_example/hello_world/bar/src/BUILD.gn | 3 + .../rust_example/hello_world/bar/src/lib.rs | 23 + .../rust_example/hello_world/foo/src/BUILD.gn | 4 + .../rust_example/hello_world/foo/src/lib.rs | 11 + .../rust_example/hello_world/src/BUILD.gn | 7 + examples/rust_example/hello_world/src/main.rs | 5 + examples/simple_build/.gn | 2 + examples/simple_build/BUILD.gn | 28 + examples/simple_build/README.md | 12 + examples/simple_build/build/BUILD.gn | 21 + examples/simple_build/build/BUILDCONFIG.gn | 41 + .../simple_build/build/toolchain/BUILD.gn | 88 + examples/simple_build/hello.cc | 13 + examples/simple_build/hello_shared.cc | 9 + examples/simple_build/hello_shared.h | 32 + examples/simple_build/hello_static.cc | 9 + examples/simple_build/hello_static.h | 10 + examples/simple_build/tutorial/README.md | 4 + examples/simple_build/tutorial/tutorial.cc | 10 + infra/README.recipes.md | 124 + infra/config/recipes.cfg | 12 + infra/config/refs.cfg | 8 + infra/recipe_modules/macos_sdk/__init__.py | 44 + infra/recipe_modules/macos_sdk/api.py | 98 + .../examples/full.expected/linux.json | 22 + .../macos_sdk/examples/full.expected/mac.json | 82 + .../macos_sdk/examples/full.expected/win.json | 22 + .../recipe_modules/macos_sdk/examples/full.py | 23 + infra/recipe_modules/target/__init__.py | 7 + infra/recipe_modules/target/api.py | 98 + .../target/examples/full.expected/linux.json | 22 + .../target/examples/full.expected/mac.json | 22 + .../target/examples/full.expected/win.json | 22 + infra/recipe_modules/target/examples/full.py | 31 + infra/recipe_modules/windows_sdk/__init__.py | 31 + infra/recipe_modules/windows_sdk/api.py | 108 + .../examples/full.expected/linux.json | 22 + .../examples/full.expected/mac.json | 22 + .../examples/full.expected/win.json | 107 + .../windows_sdk/examples/full.py | 25 + infra/recipes.py | 228 + infra/recipes/gn.expected/ci_linux.json | 506 ++ infra/recipes/gn.expected/ci_mac.json | 513 ++ infra/recipes/gn.expected/ci_win.json | 342 + infra/recipes/gn.expected/cipd_exists.json | 584 ++ infra/recipes/gn.expected/cipd_register.json | 606 ++ infra/recipes/gn.expected/cq_linux.json | 453 + infra/recipes/gn.expected/cq_mac.json | 460 + infra/recipes/gn.expected/cq_win.json | 328 + infra/recipes/gn.py | 324 + misc/emacs/.gitignore | 1 + misc/emacs/gn-mode.el | 192 + misc/help_as_html.py | 105 + misc/tm/GN.tmLanguage | 102 + misc/tm/GN.tmPreferences | 22 + misc/vim/README.md | 65 + misc/vim/autoload/gn.vim | 26 + misc/vim/ftdetect/gnfiletype.vim | 27 + misc/vim/ftplugin/gn.vim | 12 + misc/vim/gn-format.py | 62 + misc/vim/syntax/gn.vim | 86 + src/base/atomic_ref_count.h | 67 + src/base/command_line.cc | 491 ++ src/base/command_line.h | 254 + src/base/compiler_specific.h | 76 + src/base/containers/circular_deque.h | 1111 +++ src/base/containers/flat_map.h | 362 + src/base/containers/flat_set.h | 141 + src/base/containers/flat_tree.h | 1004 +++ src/base/containers/queue.h | 23 + src/base/containers/span.h | 453 + src/base/containers/stack.h | 23 + src/base/containers/vector_buffer.h | 163 + src/base/environment.cc | 243 + src/base/environment.h | 86 + src/base/files/file.cc | 116 + src/base/files/file.h | 289 + src/base/files/file_enumerator.cc | 25 + src/base/files/file_enumerator.h | 171 + src/base/files/file_enumerator_posix.cc | 170 + src/base/files/file_enumerator_win.cc | 193 + src/base/files/file_path.cc | 639 ++ src/base/files/file_path.h | 394 + src/base/files/file_path_constants.cc | 27 + src/base/files/file_posix.cc | 392 + src/base/files/file_util.cc | 244 + src/base/files/file_util.h | 350 + src/base/files/file_util_linux.cc | 63 + src/base/files/file_util_posix.cc | 664 ++ src/base/files/file_util_win.cc | 635 ++ src/base/files/file_win.cc | 324 + src/base/files/platform_file.h | 43 + src/base/files/scoped_file.cc | 49 + src/base/files/scoped_file.h | 59 + src/base/files/scoped_temp_dir.cc | 97 + src/base/files/scoped_temp_dir.h | 70 + src/base/gtest_prod_util.h | 12 + src/base/json/json_parser.cc | 747 ++ src/base/json/json_parser.h | 260 + src/base/json/json_reader.cc | 118 + src/base/json/json_reader.h | 133 + src/base/json/json_value_converter.cc | 36 + src/base/json/json_value_converter.h | 515 ++ src/base/json/json_writer.cc | 175 + src/base/json/json_writer.h | 67 + src/base/json/string_escape.cc | 156 + src/base/json/string_escape.h | 54 + src/base/logging.cc | 325 + src/base/logging.h | 922 ++ src/base/mac/bundle_locations.h | 65 + src/base/mac/mac_logging.h | 74 + src/base/mac/mac_logging.mm | 42 + src/base/mac/scoped_cftyperef.h | 48 + src/base/mac/scoped_typeref.h | 138 + src/base/macros.h | 52 + src/base/md5.cc | 301 + src/base/md5.h | 77 + src/base/memory/free_deleter.h | 23 + src/base/memory/ptr_util.h | 23 + .../raw_scoped_refptr_mismatch_checker.h | 52 + src/base/memory/ref_counted.cc | 35 + src/base/memory/ref_counted.h | 317 + src/base/memory/scoped_policy.h | 25 + src/base/memory/scoped_refptr.h | 333 + src/base/memory/weak_ptr.cc | 75 + src/base/memory/weak_ptr.h | 378 + src/base/numerics/checked_math.h | 393 + src/base/numerics/checked_math_impl.h | 567 ++ src/base/numerics/clamped_math.h | 262 + src/base/numerics/clamped_math_impl.h | 341 + src/base/numerics/math_constants.h | 15 + src/base/numerics/ranges.h | 27 + src/base/numerics/safe_conversions.h | 339 + src/base/numerics/safe_conversions_impl.h | 848 ++ src/base/numerics/safe_math.h | 12 + src/base/numerics/safe_math_clang_gcc_impl.h | 152 + src/base/numerics/safe_math_shared_impl.h | 236 + src/base/posix/eintr_wrapper.h | 71 + src/base/posix/file_descriptor_shuffle.cc | 101 + src/base/posix/file_descriptor_shuffle.h | 82 + src/base/posix/safe_strerror.cc | 126 + src/base/posix/safe_strerror.h | 42 + src/base/scoped_clear_errno.h | 32 + src/base/scoped_generic.h | 185 + src/base/sha1.cc | 213 + src/base/sha1.h | 28 + src/base/stl_util.h | 272 + src/base/strings/string_number_conversions.cc | 458 + src/base/strings/string_number_conversions.h | 131 + src/base/strings/string_split.cc | 260 + src/base/strings/string_split.h | 122 + src/base/strings/string_tokenizer.h | 250 + src/base/strings/string_util.cc | 1047 +++ src/base/strings/string_util.h | 424 + src/base/strings/string_util_constants.cc | 57 + src/base/strings/string_util_posix.h | 25 + src/base/strings/string_util_win.h | 29 + src/base/strings/stringize_macros.h | 31 + src/base/strings/stringprintf.cc | 143 + src/base/strings/stringprintf.h | 42 + .../strings/utf_offset_string_conversions.cc | 266 + .../strings/utf_offset_string_conversions.h | 111 + .../strings/utf_string_conversion_utils.cc | 132 + .../strings/utf_string_conversion_utils.h | 81 + src/base/strings/utf_string_conversions.cc | 195 + src/base/strings/utf_string_conversions.h | 30 + src/base/sys_byteorder.h | 139 + src/base/template_util.h | 42 + src/base/third_party/icu/LICENSE | 76 + src/base/third_party/icu/README.chromium | 17 + src/base/third_party/icu/icu_utf.cc | 129 + src/base/third_party/icu/icu_utf.h | 464 + src/base/timer/elapsed_timer.cc | 25 + src/base/timer/elapsed_timer.h | 32 + src/base/value_iterators.cc | 228 + src/base/value_iterators.h | 191 + src/base/values.cc | 1309 +++ src/base/values.h | 763 ++ src/base/win/registry.cc | 623 ++ src/base/win/registry.h | 252 + src/base/win/scoped_handle.cc | 33 + src/base/win/scoped_handle.h | 172 + src/base/win/scoped_process_information.cc | 109 + src/base/win/scoped_process_information.h | 74 + src/base/win/win_util.h | 30 + src/gn/action_target_generator.cc | 223 + src/gn/action_target_generator.h | 41 + src/gn/action_target_generator_unittest.cc | 122 + src/gn/action_values.cc | 31 + src/gn/action_values.h | 70 + src/gn/analyzer.cc | 492 ++ src/gn/analyzer.h | 104 + src/gn/analyzer_unittest.cc | 755 ++ src/gn/args.cc | 437 + src/gn/args.h | 147 + src/gn/args_unittest.cc | 81 + src/gn/binary_target_generator.cc | 248 + src/gn/binary_target_generator.h | 41 + src/gn/build_settings.cc | 76 + src/gn/build_settings.h | 152 + src/gn/builder.cc | 602 ++ src/gn/builder.h | 146 + src/gn/builder_record.cc | 67 + src/gn/builder_record.h | 110 + src/gn/builder_unittest.cc | 247 + src/gn/bundle_data.cc | 195 + src/gn/bundle_data.h | 214 + src/gn/bundle_data_target_generator.cc | 95 + src/gn/bundle_data_target_generator.h | 32 + src/gn/bundle_file_rule.cc | 110 + src/gn/bundle_file_rule.h | 56 + src/gn/c_include_iterator.cc | 176 + src/gn/c_include_iterator.h | 61 + src/gn/c_include_iterator_unittest.cc | 181 + src/gn/c_substitution_type.cc | 140 + src/gn/c_substitution_type.h | 57 + src/gn/c_tool.cc | 266 + src/gn/c_tool.h | 126 + src/gn/command_analyze.cc | 148 + src/gn/command_args.cc | 511 ++ src/gn/command_check.cc | 285 + src/gn/command_clean.cc | 139 + src/gn/command_clean_stale.cc | 98 + src/gn/command_desc.cc | 716 ++ src/gn/command_format.cc | 1437 +++ src/gn/command_format.h | 36 + src/gn/command_format_unittest.cc | 138 + src/gn/command_gen.cc | 695 ++ src/gn/command_help.cc | 376 + src/gn/command_ls.cc | 104 + src/gn/command_meta.cc | 170 + src/gn/command_outputs.cc | 155 + src/gn/command_path.cc | 413 + src/gn/command_refs.cc | 453 + src/gn/commands.cc | 644 ++ src/gn/commands.h | 247 + src/gn/commands_unittest.cc | 35 + src/gn/compile_commands_writer.cc | 365 + src/gn/compile_commands_writer.h | 42 + src/gn/compile_commands_writer_unittest.cc | 640 ++ src/gn/config.cc | 50 + src/gn/config.h | 69 + src/gn/config_unittest.cc | 85 + src/gn/config_values.cc | 52 + src/gn/config_values.h | 108 + src/gn/config_values_extractors.cc | 34 + src/gn/config_values_extractors.h | 102 + src/gn/config_values_extractors_unittest.cc | 140 + src/gn/config_values_generator.cc | 170 + src/gn/config_values_generator.h | 46 + src/gn/copy_target_generator.cc | 44 + src/gn/copy_target_generator.h | 27 + src/gn/create_bundle_target_generator.cc | 318 + src/gn/create_bundle_target_generator.h | 46 + src/gn/deps_iterator.cc | 53 + src/gn/deps_iterator.h | 72 + src/gn/desc_builder.cc | 891 ++ src/gn/desc_builder.h | 27 + src/gn/eclipse_writer.cc | 171 + src/gn/eclipse_writer.h | 67 + src/gn/err.cc | 200 + src/gn/err.h | 105 + src/gn/escape.cc | 312 + src/gn/escape.h | 90 + src/gn/escape_unittest.cc | 112 + src/gn/exec_process.cc | 289 + src/gn/exec_process.h | 35 + src/gn/exec_process_unittest.cc | 123 + src/gn/file_writer.cc | 108 + src/gn/file_writer.h | 74 + src/gn/file_writer_unittest.cc | 44 + src/gn/filesystem_utils.cc | 1077 +++ src/gn/filesystem_utils.h | 305 + src/gn/filesystem_utils_unittest.cc | 868 ++ src/gn/format_test_data/001.gn | 2 + src/gn/format_test_data/001.golden | 3 + src/gn/format_test_data/002.gn | 6 + src/gn/format_test_data/002.golden | 6 + src/gn/format_test_data/003.gn | 10 + src/gn/format_test_data/003.golden | 8 + src/gn/format_test_data/004.gn | 10 + src/gn/format_test_data/004.golden | 11 + src/gn/format_test_data/005.gn | 5 + src/gn/format_test_data/005.golden | 5 + src/gn/format_test_data/006.gn | 9 + src/gn/format_test_data/006.golden | 5 + src/gn/format_test_data/007.gn | 9 + src/gn/format_test_data/007.golden | 9 + src/gn/format_test_data/008.gn | 1 + src/gn/format_test_data/008.golden | 3 + src/gn/format_test_data/009.gn | 2 + src/gn/format_test_data/009.golden | 5 + src/gn/format_test_data/010.gn | 2 + src/gn/format_test_data/010.golden | 5 + src/gn/format_test_data/011.gn | 4 + src/gn/format_test_data/011.golden | 7 + src/gn/format_test_data/012.gn | 16 + src/gn/format_test_data/012.golden | 16 + src/gn/format_test_data/013.gn | 7 + src/gn/format_test_data/013.golden | 7 + src/gn/format_test_data/014.gn | 6 + src/gn/format_test_data/014.golden | 5 + src/gn/format_test_data/015.gn | 4 + src/gn/format_test_data/015.golden | 4 + src/gn/format_test_data/016.gn | 1 + src/gn/format_test_data/016.golden | 1 + src/gn/format_test_data/017.gn | 15 + src/gn/format_test_data/017.golden | 16 + src/gn/format_test_data/018.gn | 3 + src/gn/format_test_data/018.golden | 3 + src/gn/format_test_data/019.gn | 23 + src/gn/format_test_data/019.golden | 23 + src/gn/format_test_data/020.gn | 5 + src/gn/format_test_data/020.golden | 5 + src/gn/format_test_data/021.gn | 33 + src/gn/format_test_data/021.golden | 61 + src/gn/format_test_data/022.gn | 6 + src/gn/format_test_data/022.golden | 6 + src/gn/format_test_data/023.gn | 38 + src/gn/format_test_data/023.golden | 88 + src/gn/format_test_data/024.gn | 1 + src/gn/format_test_data/024.golden | 2 + src/gn/format_test_data/025.gn | 5 + src/gn/format_test_data/025.golden | 9 + src/gn/format_test_data/026.gn | 6 + src/gn/format_test_data/026.golden | 7 + src/gn/format_test_data/027.gn | 3 + src/gn/format_test_data/027.golden | 5 + src/gn/format_test_data/028.gn | 9 + src/gn/format_test_data/028.golden | 7 + src/gn/format_test_data/029.gn | 9 + src/gn/format_test_data/029.golden | 9 + src/gn/format_test_data/030.gn | 12 + src/gn/format_test_data/030.golden | 12 + src/gn/format_test_data/031.gn | 8 + src/gn/format_test_data/031.golden | 8 + src/gn/format_test_data/032.gn | 6 + src/gn/format_test_data/032.golden | 7 + src/gn/format_test_data/033.gn | 8 + src/gn/format_test_data/033.golden | 8 + src/gn/format_test_data/034.gn | 13 + src/gn/format_test_data/035.gn | 1 + src/gn/format_test_data/035.golden | 1 + src/gn/format_test_data/036.gn | 9 + src/gn/format_test_data/036.golden | 9 + src/gn/format_test_data/037.gn | 5 + src/gn/format_test_data/037.golden | 6 + src/gn/format_test_data/038.gn | 4 + src/gn/format_test_data/038.golden | 3 + src/gn/format_test_data/039.gn | 6 + src/gn/format_test_data/039.golden | 4 + src/gn/format_test_data/040.gn | 9 + src/gn/format_test_data/040.golden | 10 + src/gn/format_test_data/041.gn | 12 + src/gn/format_test_data/041.golden | 12 + src/gn/format_test_data/042.gn | 44 + src/gn/format_test_data/042.golden | 96 + src/gn/format_test_data/043.gn | 6 + src/gn/format_test_data/043.golden | 7 + src/gn/format_test_data/044.gn | 11 + src/gn/format_test_data/044.golden | 11 + src/gn/format_test_data/045.gn | 10 + src/gn/format_test_data/045.golden | 14 + src/gn/format_test_data/046.gn | 22 + src/gn/format_test_data/046.golden | 19 + src/gn/format_test_data/047.gn | 7 + src/gn/format_test_data/047.golden | 10 + src/gn/format_test_data/048.gn | 19 + src/gn/format_test_data/048.golden | 19 + src/gn/format_test_data/049.gn | 14 + src/gn/format_test_data/050.gn | 10 + src/gn/format_test_data/050.golden | 27 + src/gn/format_test_data/051.gn | 6 + src/gn/format_test_data/051.golden | 7 + src/gn/format_test_data/052.gn | 11 + src/gn/format_test_data/052.golden | 12 + src/gn/format_test_data/053.gn | 7 + src/gn/format_test_data/053.golden | 8 + src/gn/format_test_data/054.gn | 7 + src/gn/format_test_data/054.golden | 8 + src/gn/format_test_data/055.gn | 10 + src/gn/format_test_data/055.golden | 11 + src/gn/format_test_data/056.gn | 45 + src/gn/format_test_data/056.golden | 45 + src/gn/format_test_data/057.gn | 24 + src/gn/format_test_data/057.golden | 24 + src/gn/format_test_data/058.gn | 2 + src/gn/format_test_data/058.golden | 2 + src/gn/format_test_data/059.gn | 10 + src/gn/format_test_data/059.golden | 11 + src/gn/format_test_data/060.gn | 2 + src/gn/format_test_data/060.golden | 2 + src/gn/format_test_data/061.gn | 9 + src/gn/format_test_data/061.golden | 9 + src/gn/format_test_data/062.gn | 128 + src/gn/format_test_data/062.golden | 136 + src/gn/format_test_data/063.gn | 50 + src/gn/format_test_data/063.golden | 50 + src/gn/format_test_data/064.gn | 3 + src/gn/format_test_data/064.golden | 3 + src/gn/format_test_data/065.gn | 4 + src/gn/format_test_data/065.golden | 8 + src/gn/format_test_data/066.gn | 32 + src/gn/format_test_data/066.golden | 28 + src/gn/format_test_data/067.gn | 8 + src/gn/format_test_data/067.golden | 17 + src/gn/format_test_data/068.gn | 3 + src/gn/format_test_data/068.golden | 3 + src/gn/format_test_data/069.gn | 3 + src/gn/format_test_data/069.golden | 5 + src/gn/format_test_data/070.gn | 15 + src/gn/format_test_data/070.golden | 14 + src/gn/format_test_data/071.gn | 26 + src/gn/format_test_data/071.golden | 25 + src/gn/format_test_data/072.gn | 8 + src/gn/format_test_data/072.golden | 21 + src/gn/format_test_data/073.gn | 23 + src/gn/format_test_data/073.golden | 34 + src/gn/format_test_data/074.gn | 7 + src/gn/format_test_data/074.golden | 7 + src/gn/format_test_data/075.gn | 11 + src/gn/format_test_data/075.golden | 12 + src/gn/format_test_data/076.gn | 12 + src/gn/format_test_data/076.golden | 14 + src/gn/format_test_data/077.gn | 6 + src/gn/format_test_data/077.golden | 6 + src/gn/format_test_data/078.gn | 15 + src/gn/format_test_data/078.golden | 16 + src/gn/format_test_data/079.gn | 14 + src/gn/format_test_data/079.golden | 18 + src/gn/format_test_data/080.gn | 33 + src/gn/format_test_data/080.golden | 34 + src/gn/format_test_data/081.gn | 18 + src/gn/format_test_data/081.golden | 21 + src/gn/format_test_data/082.gn | 34 + src/gn/format_test_data/082.golden | 34 + src/gn/format_test_data/083.gn | 7 + src/gn/format_test_data/083.golden | 7 + src/gn/frameworks_utils.cc | 25 + src/gn/frameworks_utils.h | 15 + src/gn/frameworks_utils_unittest.cc | 17 + src/gn/function_exec_script.cc | 278 + src/gn/function_filter.cc | 124 + src/gn/function_filter_unittest.cc | 244 + src/gn/function_foreach.cc | 112 + src/gn/function_foreach_unittest.cc | 100 + src/gn/function_forward_variables_from.cc | 246 + ...unction_forward_variables_from_unittest.cc | 244 + src/gn/function_get_label_info.cc | 144 + src/gn/function_get_label_info_unittest.cc | 107 + src/gn/function_get_path_info.cc | 251 + src/gn/function_get_path_info_unittest.cc | 120 + src/gn/function_get_target_outputs.cc | 139 + .../function_get_target_outputs_unittest.cc | 107 + src/gn/function_process_file_template.cc | 115 + ...function_process_file_template_unittest.cc | 64 + src/gn/function_read_file.cc | 78 + src/gn/function_rebase_path.cc | 288 + src/gn/function_rebase_path_unittest.cc | 183 + src/gn/function_set_default_toolchain.cc | 88 + src/gn/function_set_defaults.cc | 76 + src/gn/function_template.cc | 226 + src/gn/function_template_unittest.cc | 29 + src/gn/function_toolchain.cc | 928 ++ src/gn/function_toolchain_unittest.cc | 159 + src/gn/function_write_file.cc | 106 + src/gn/function_write_file_unittest.cc | 111 + src/gn/functions.cc | 1533 ++++ src/gn/functions.h | 562 ++ src/gn/functions_target.cc | 1015 +++ src/gn/functions_target_rust_unittest.cc | 324 + src/gn/functions_target_unittest.cc | 206 + src/gn/functions_unittest.cc | 459 + src/gn/general_tool.cc | 51 + src/gn/general_tool.h | 46 + src/gn/generated_file_target_generator.cc | 165 + src/gn/generated_file_target_generator.h | 49 + src/gn/gn_main.cc | 85 + src/gn/group_target_generator.cc | 23 + src/gn/group_target_generator.h | 27 + src/gn/hash_table_base.h | 503 ++ src/gn/hash_table_base_unittest.cc | 356 + src/gn/header_checker.cc | 642 ++ src/gn/header_checker.h | 208 + src/gn/header_checker_unittest.cc | 427 + src/gn/import_manager.cc | 162 + src/gn/import_manager.h | 54 + src/gn/inherited_libraries.cc | 74 + src/gn/inherited_libraries.h | 71 + src/gn/inherited_libraries_unittest.cc | 135 + src/gn/input_conversion.cc | 359 + src/gn/input_conversion.h | 30 + src/gn/input_conversion_unittest.cc | 275 + src/gn/input_file.cc | 26 + src/gn/input_file.h | 65 + src/gn/input_file_manager.cc | 341 + src/gn/input_file_manager.h | 175 + src/gn/item.cc | 60 + src/gn/item.h | 80 + src/gn/json_project_writer.cc | 514 ++ src/gn/json_project_writer.h | 39 + src/gn/json_project_writer_unittest.cc | 719 ++ src/gn/label.cc | 331 + src/gn/label.h | 143 + src/gn/label_pattern.cc | 275 + src/gn/label_pattern.h | 82 + src/gn/label_pattern_unittest.cc | 103 + src/gn/label_ptr.h | 79 + src/gn/label_unittest.cc | 140 + src/gn/lib_file.cc | 23 + src/gn/lib_file.h | 54 + src/gn/loader.cc | 448 + src/gn/loader.h | 187 + src/gn/loader_unittest.cc | 393 + src/gn/location.cc | 69 + src/gn/location.h | 60 + src/gn/metadata.cc | 273 + src/gn/metadata.h | 90 + src/gn/metadata_unittest.cc | 233 + src/gn/metadata_walk.cc | 24 + src/gn/metadata_walk.h | 26 + src/gn/metadata_walk_unittest.cc | 211 + src/gn/ninja_action_target_writer.cc | 250 + src/gn/ninja_action_target_writer.h | 62 + src/gn/ninja_action_target_writer_unittest.cc | 488 + src/gn/ninja_binary_target_writer.cc | 391 + src/gn/ninja_binary_target_writer.h | 88 + src/gn/ninja_binary_target_writer_unittest.cc | 183 + src/gn/ninja_build_writer.cc | 642 ++ src/gn/ninja_build_writer.h | 81 + src/gn/ninja_build_writer_unittest.cc | 255 + src/gn/ninja_bundle_data_target_writer.cc | 33 + src/gn/ninja_bundle_data_target_writer.h | 23 + ...inja_bundle_data_target_writer_unittest.cc | 56 + src/gn/ninja_c_binary_target_writer.cc | 909 ++ src/gn/ninja_c_binary_target_writer.h | 112 + .../ninja_c_binary_target_writer_unittest.cc | 1922 ++++ src/gn/ninja_copy_target_writer.cc | 124 + src/gn/ninja_copy_target_writer.h | 27 + src/gn/ninja_copy_target_writer_unittest.cc | 126 + src/gn/ninja_create_bundle_target_writer.cc | 373 + src/gn/ninja_create_bundle_target_writer.h | 71 + ...ja_create_bundle_target_writer_unittest.cc | 487 + src/gn/ninja_generated_file_target_writer.cc | 97 + src/gn/ninja_generated_file_target_writer.h | 25 + ...a_generated_file_target_writer_unittest.cc | 69 + src/gn/ninja_group_target_writer.cc | 37 + src/gn/ninja_group_target_writer.h | 23 + src/gn/ninja_group_target_writer_unittest.cc | 60 + src/gn/ninja_rust_binary_target_writer.cc | 323 + src/gn/ninja_rust_binary_target_writer.h | 42 + ...inja_rust_binary_target_writer_unittest.cc | 892 ++ src/gn/ninja_target_command_util.cc | 177 + src/gn/ninja_target_command_util.h | 114 + src/gn/ninja_target_command_util_unittest.cc | 96 + src/gn/ninja_target_writer.cc | 341 + src/gn/ninja_target_writer.h | 72 + src/gn/ninja_target_writer_unittest.cc | 163 + src/gn/ninja_toolchain_writer.cc | 141 + src/gn/ninja_toolchain_writer.h | 61 + src/gn/ninja_toolchain_writer_unittest.cc | 39 + src/gn/ninja_tools.cc | 82 + src/gn/ninja_tools.h | 44 + src/gn/ninja_utils.cc | 30 + src/gn/ninja_utils.h | 25 + src/gn/ninja_writer.cc | 51 + src/gn/ninja_writer.h | 49 + src/gn/operators.cc | 744 ++ src/gn/operators.h | 25 + src/gn/operators_unittest.cc | 413 + src/gn/ordered_set.h | 63 + src/gn/output_conversion.cc | 177 + src/gn/output_conversion.h | 26 + src/gn/output_conversion_unittest.cc | 351 + src/gn/output_file.cc | 39 + src/gn/output_file.h | 63 + src/gn/parse_node_value_adapter.cc | 44 + src/gn/parse_node_value_adapter.h | 55 + src/gn/parse_tree.cc | 1257 +++ src/gn/parse_tree.h | 613 ++ src/gn/parse_tree_unittest.cc | 307 + src/gn/parser.cc | 941 ++ src/gn/parser.h | 158 + src/gn/parser_unittest.cc | 734 ++ src/gn/path_output.cc | 176 + src/gn/path_output.h | 93 + src/gn/path_output_unittest.cc | 276 + src/gn/pattern.cc | 223 + src/gn/pattern.h | 92 + src/gn/pattern_unittest.cc | 66 + src/gn/pool.cc | 45 + src/gn/pool.h | 41 + src/gn/qt_creator_writer.cc | 296 + src/gn/qt_creator_writer.h | 56 + src/gn/runtime_deps.cc | 319 + src/gn/runtime_deps.h | 31 + src/gn/runtime_deps_unittest.cc | 448 + src/gn/rust_project_writer.cc | 451 + src/gn/rust_project_writer.h | 37 + src/gn/rust_project_writer_helpers.h | 140 + .../rust_project_writer_helpers_unittest.cc | 359 + src/gn/rust_project_writer_unittest.cc | 524 ++ src/gn/rust_substitution_type.cc | 42 + src/gn/rust_substitution_type.h | 27 + src/gn/rust_tool.cc | 123 + src/gn/rust_tool.h | 58 + src/gn/rust_values.cc | 9 + src/gn/rust_values.h | 68 + src/gn/rust_values_generator.cc | 191 + src/gn/rust_values_generator.h | 39 + src/gn/rust_variables.cc | 113 + src/gn/rust_variables.h | 38 + src/gn/scheduler.cc | 183 + src/gn/scheduler.h | 156 + src/gn/scope.cc | 573 ++ src/gn/scope.h | 387 + src/gn/scope_per_file_provider.cc | 128 + src/gn/scope_per_file_provider.h | 53 + src/gn/scope_per_file_provider_unittest.cc | 58 + src/gn/scope_unittest.cc | 335 + src/gn/settings.cc | 29 + src/gn/settings.h | 116 + src/gn/setup.cc | 1028 +++ src/gn/setup.h | 214 + src/gn/setup_unittest.cc | 94 + src/gn/source_dir.cc | 155 + src/gn/source_dir.h | 154 + src/gn/source_dir_unittest.cc | 208 + src/gn/source_file.cc | 140 + src/gn/source_file.h | 172 + src/gn/source_file_unittest.cc | 20 + src/gn/standard_out.cc | 342 + src/gn/standard_out.h | 61 + src/gn/string_atom.cc | 215 + src/gn/string_atom.h | 179 + src/gn/string_atom_unittest.cc | 148 + src/gn/string_output_buffer.cc | 117 + src/gn/string_output_buffer.h | 94 + src/gn/string_output_buffer_unittest.cc | 134 + src/gn/string_utils.cc | 356 + src/gn/string_utils.h | 56 + src/gn/string_utils_unittest.cc | 159 + src/gn/substitution_list.cc | 69 + src/gn/substitution_list.h | 46 + src/gn/substitution_pattern.cc | 144 + src/gn/substitution_pattern.h | 79 + src/gn/substitution_pattern_unittest.cc | 73 + src/gn/substitution_type.cc | 204 + src/gn/substitution_type.h | 120 + src/gn/substitution_writer.cc | 587 ++ src/gn/substitution_writer.h | 238 + src/gn/substitution_writer_unittest.cc | 325 + src/gn/swift_values.cc | 70 + src/gn/swift_values.h | 91 + src/gn/swift_values_generator.cc | 60 + src/gn/swift_values_generator.h | 34 + src/gn/swift_variables.cc | 44 + src/gn/swift_variables.h | 26 + src/gn/switches.cc | 356 + src/gn/switches.h | 131 + src/gn/target.cc | 1170 +++ src/gn/target.h | 518 ++ src/gn/target_generator.cc | 451 + src/gn/target_generator.h | 86 + src/gn/target_unittest.cc | 1539 ++++ src/gn/template.cc | 128 + src/gn/template.h | 67 + src/gn/template_unittest.cc | 93 + src/gn/test_with_scheduler.cc | 8 + src/gn/test_with_scheduler.h | 27 + src/gn/test_with_scope.cc | 349 + src/gn/test_with_scope.h | 128 + src/gn/token.cc | 29 + src/gn/token.h | 88 + src/gn/tokenizer.cc | 417 + src/gn/tokenizer.h | 108 + src/gn/tokenizer_unittest.cc | 237 + src/gn/tool.cc | 407 + src/gn/tool.h | 304 + src/gn/toolchain.cc | 140 + src/gn/toolchain.h | 129 + src/gn/trace.cc | 334 + src/gn/trace.h | 104 + src/gn/unique_vector.h | 143 + src/gn/unique_vector_unittest.cc | 45 + src/gn/value.cc | 262 + src/gn/value.h | 137 + src/gn/value_extractors.cc | 323 + src/gn/value_extractors.h | 100 + src/gn/value_unittest.cc | 60 + src/gn/variables.cc | 2342 +++++ src/gn/variables.h | 379 + src/gn/vector_utils.h | 103 + src/gn/vector_utils_unittest.cc | 47 + src/gn/version.cc | 80 + src/gn/version.h | 37 + src/gn/version_unittest.cc | 33 + src/gn/visibility.cc | 120 + src/gn/visibility.h | 72 + src/gn/visibility_unittest.cc | 71 + src/gn/visual_studio_utils.cc | 127 + src/gn/visual_studio_utils.h | 50 + src/gn/visual_studio_utils_unittest.cc | 102 + src/gn/visual_studio_writer.cc | 916 ++ src/gn/visual_studio_writer.h | 168 + src/gn/visual_studio_writer_unittest.cc | 200 + src/gn/xcode_object.cc | 1138 +++ src/gn/xcode_object.h | 522 ++ src/gn/xcode_object_unittest.cc | 435 + src/gn/xcode_writer.cc | 1047 +++ src/gn/xcode_writer.h | 83 + src/gn/xml_element_writer.cc | 114 + src/gn/xml_element_writer.h | 124 + src/gn/xml_element_writer_unittest.cc | 93 + src/util/auto_reset_event.h | 53 + src/util/build_config.h | 177 + src/util/exe_path.cc | 119 + src/util/exe_path.h | 12 + src/util/msg_loop.cc | 75 + src/util/msg_loop.h | 47 + src/util/semaphore.cc | 91 + src/util/semaphore.h | 53 + src/util/sys_info.cc | 85 + src/util/sys_info.h | 13 + src/util/test/gn_test.cc | 182 + src/util/test/test.h | 194 + src/util/ticks.cc | 95 + src/util/ticks.h | 45 + src/util/worker_pool.cc | 150 + src/util/worker_pool.h | 37 + tools/find_unreachable.py | 78 + 805 files changed, 134187 insertions(+) create mode 100644 .clang-format create mode 100644 .editorconfig create mode 100644 .gitignore create mode 100644 .style.yapf create mode 100644 AUTHORS create mode 100644 LICENSE create mode 100644 OWNERS create mode 100644 README.md create mode 100644 build/build_aix.ninja.template create mode 100644 build/build_haiku.ninja.template create mode 100644 build/build_linux.ninja.template create mode 100644 build/build_mac.ninja.template create mode 100644 build/build_openbsd.ninja.template create mode 100644 build/build_win.ninja.template create mode 100755 build/full_test.py create mode 100755 build/gen.py create mode 100644 docs/cross_compiles.md create mode 100644 docs/faq.md create mode 100644 docs/language.md create mode 100644 docs/quick_start.md create mode 100644 docs/reference.md create mode 100644 docs/standalone.md create mode 100644 docs/style_guide.md create mode 100644 examples/ios/.gitignore create mode 100644 examples/ios/.gn create mode 100644 examples/ios/BUILD.gn create mode 100644 examples/ios/app/AppDelegate.h create mode 100644 examples/ios/app/AppDelegate.m create mode 100644 examples/ios/app/BUILD.gn create mode 100644 examples/ios/app/Bar.swift create mode 100644 examples/ios/app/Baz.swift create mode 100644 examples/ios/app/Foo-Bridging-Header.h create mode 100644 examples/ios/app/Foo.swift create mode 100644 examples/ios/app/FooWrapper.swift create mode 100644 examples/ios/app/SceneDelegate.h create mode 100644 examples/ios/app/SceneDelegate.m create mode 100644 examples/ios/app/ViewController.h create mode 100644 examples/ios/app/ViewController.m create mode 100644 examples/ios/app/main.m create mode 100644 examples/ios/app/resources/Info.plist create mode 100644 examples/ios/app/resources/LaunchScreen.storyboard create mode 100644 examples/ios/app/resources/Main.storyboard create mode 100644 examples/ios/build/BUILD.gn create mode 100644 examples/ios/build/BUILDCONFIG.gn create mode 100644 examples/ios/build/config/ios/BUILD.gn create mode 100644 examples/ios/build/config/ios/bundle_identifier_prefix.gni create mode 100644 examples/ios/build/config/ios/deployment_target.gni create mode 100644 examples/ios/build/config/ios/resources/Entitlements-Simulated.plist create mode 100644 examples/ios/build/config/ios/resources/Info.plist create mode 100644 examples/ios/build/config/ios/resources/compiler-Info.plist create mode 100644 examples/ios/build/config/ios/scripts/compile_storyboard.py create mode 100644 examples/ios/build/config/ios/scripts/find_app_identifier_prefix.py create mode 100644 examples/ios/build/config/ios/scripts/generate_umbrella_header.py create mode 100644 examples/ios/build/config/ios/scripts/merge_plist.py create mode 100644 examples/ios/build/config/ios/scripts/sdk_info.py create mode 100644 examples/ios/build/config/ios/sdk_info.gni create mode 100644 examples/ios/build/config/ios/templates/ios_app_bundle.gni create mode 100644 examples/ios/build/config/ios/templates/ios_binary_bundle.gni create mode 100644 examples/ios/build/config/ios/templates/ios_framework_bundle.gni create mode 100644 examples/ios/build/config/ios/templates/merge_plist.gni create mode 100644 examples/ios/build/config/ios/templates/storyboards.gni create mode 100755 examples/ios/build/toolchain/apple/swiftc.py create mode 100644 examples/ios/build/toolchain/ios/BUILD.gn create mode 100644 examples/ios/build/toolchain/mac/BUILD.gn create mode 100644 examples/ios/host/BUILD.gn create mode 100644 examples/ios/host/main.cc create mode 100644 examples/ios/shared/BUILD.gn create mode 100644 examples/ios/shared/hello_shared.h create mode 100644 examples/ios/shared/hello_shared.m create mode 100644 examples/rust_example/.gn create mode 100644 examples/rust_example/BUILD.gn create mode 100644 examples/rust_example/BUILDCONFIG.gn create mode 100644 examples/rust_example/README.txt create mode 100644 examples/rust_example/build/BUILD.gn create mode 100644 examples/rust_example/hello_world/bar/src/BUILD.gn create mode 100644 examples/rust_example/hello_world/bar/src/lib.rs create mode 100644 examples/rust_example/hello_world/foo/src/BUILD.gn create mode 100644 examples/rust_example/hello_world/foo/src/lib.rs create mode 100644 examples/rust_example/hello_world/src/BUILD.gn create mode 100644 examples/rust_example/hello_world/src/main.rs create mode 100644 examples/simple_build/.gn create mode 100644 examples/simple_build/BUILD.gn create mode 100644 examples/simple_build/README.md create mode 100644 examples/simple_build/build/BUILD.gn create mode 100644 examples/simple_build/build/BUILDCONFIG.gn create mode 100644 examples/simple_build/build/toolchain/BUILD.gn create mode 100644 examples/simple_build/hello.cc create mode 100644 examples/simple_build/hello_shared.cc create mode 100644 examples/simple_build/hello_shared.h create mode 100644 examples/simple_build/hello_static.cc create mode 100644 examples/simple_build/hello_static.h create mode 100644 examples/simple_build/tutorial/README.md create mode 100644 examples/simple_build/tutorial/tutorial.cc create mode 100644 infra/README.recipes.md create mode 100644 infra/config/recipes.cfg create mode 100644 infra/config/refs.cfg create mode 100644 infra/recipe_modules/macos_sdk/__init__.py create mode 100644 infra/recipe_modules/macos_sdk/api.py create mode 100644 infra/recipe_modules/macos_sdk/examples/full.expected/linux.json create mode 100644 infra/recipe_modules/macos_sdk/examples/full.expected/mac.json create mode 100644 infra/recipe_modules/macos_sdk/examples/full.expected/win.json create mode 100644 infra/recipe_modules/macos_sdk/examples/full.py create mode 100644 infra/recipe_modules/target/__init__.py create mode 100644 infra/recipe_modules/target/api.py create mode 100644 infra/recipe_modules/target/examples/full.expected/linux.json create mode 100644 infra/recipe_modules/target/examples/full.expected/mac.json create mode 100644 infra/recipe_modules/target/examples/full.expected/win.json create mode 100644 infra/recipe_modules/target/examples/full.py create mode 100644 infra/recipe_modules/windows_sdk/__init__.py create mode 100644 infra/recipe_modules/windows_sdk/api.py create mode 100644 infra/recipe_modules/windows_sdk/examples/full.expected/linux.json create mode 100644 infra/recipe_modules/windows_sdk/examples/full.expected/mac.json create mode 100644 infra/recipe_modules/windows_sdk/examples/full.expected/win.json create mode 100644 infra/recipe_modules/windows_sdk/examples/full.py create mode 100755 infra/recipes.py create mode 100644 infra/recipes/gn.expected/ci_linux.json create mode 100644 infra/recipes/gn.expected/ci_mac.json create mode 100644 infra/recipes/gn.expected/ci_win.json create mode 100644 infra/recipes/gn.expected/cipd_exists.json create mode 100644 infra/recipes/gn.expected/cipd_register.json create mode 100644 infra/recipes/gn.expected/cq_linux.json create mode 100644 infra/recipes/gn.expected/cq_mac.json create mode 100644 infra/recipes/gn.expected/cq_win.json create mode 100644 infra/recipes/gn.py create mode 100644 misc/emacs/.gitignore create mode 100644 misc/emacs/gn-mode.el create mode 100755 misc/help_as_html.py create mode 100644 misc/tm/GN.tmLanguage create mode 100644 misc/tm/GN.tmPreferences create mode 100644 misc/vim/README.md create mode 100644 misc/vim/autoload/gn.vim create mode 100644 misc/vim/ftdetect/gnfiletype.vim create mode 100644 misc/vim/ftplugin/gn.vim create mode 100644 misc/vim/gn-format.py create mode 100644 misc/vim/syntax/gn.vim create mode 100644 src/base/atomic_ref_count.h create mode 100644 src/base/command_line.cc create mode 100644 src/base/command_line.h create mode 100644 src/base/compiler_specific.h create mode 100644 src/base/containers/circular_deque.h create mode 100644 src/base/containers/flat_map.h create mode 100644 src/base/containers/flat_set.h create mode 100644 src/base/containers/flat_tree.h create mode 100644 src/base/containers/queue.h create mode 100644 src/base/containers/span.h create mode 100644 src/base/containers/stack.h create mode 100644 src/base/containers/vector_buffer.h create mode 100644 src/base/environment.cc create mode 100644 src/base/environment.h create mode 100644 src/base/files/file.cc create mode 100644 src/base/files/file.h create mode 100644 src/base/files/file_enumerator.cc create mode 100644 src/base/files/file_enumerator.h create mode 100644 src/base/files/file_enumerator_posix.cc create mode 100644 src/base/files/file_enumerator_win.cc create mode 100644 src/base/files/file_path.cc create mode 100644 src/base/files/file_path.h create mode 100644 src/base/files/file_path_constants.cc create mode 100644 src/base/files/file_posix.cc create mode 100644 src/base/files/file_util.cc create mode 100644 src/base/files/file_util.h create mode 100644 src/base/files/file_util_linux.cc create mode 100644 src/base/files/file_util_posix.cc create mode 100644 src/base/files/file_util_win.cc create mode 100644 src/base/files/file_win.cc create mode 100644 src/base/files/platform_file.h create mode 100644 src/base/files/scoped_file.cc create mode 100644 src/base/files/scoped_file.h create mode 100644 src/base/files/scoped_temp_dir.cc create mode 100644 src/base/files/scoped_temp_dir.h create mode 100644 src/base/gtest_prod_util.h create mode 100644 src/base/json/json_parser.cc create mode 100644 src/base/json/json_parser.h create mode 100644 src/base/json/json_reader.cc create mode 100644 src/base/json/json_reader.h create mode 100644 src/base/json/json_value_converter.cc create mode 100644 src/base/json/json_value_converter.h create mode 100644 src/base/json/json_writer.cc create mode 100644 src/base/json/json_writer.h create mode 100644 src/base/json/string_escape.cc create mode 100644 src/base/json/string_escape.h create mode 100644 src/base/logging.cc create mode 100644 src/base/logging.h create mode 100644 src/base/mac/bundle_locations.h create mode 100644 src/base/mac/mac_logging.h create mode 100644 src/base/mac/mac_logging.mm create mode 100644 src/base/mac/scoped_cftyperef.h create mode 100644 src/base/mac/scoped_typeref.h create mode 100644 src/base/macros.h create mode 100644 src/base/md5.cc create mode 100644 src/base/md5.h create mode 100644 src/base/memory/free_deleter.h create mode 100644 src/base/memory/ptr_util.h create mode 100644 src/base/memory/raw_scoped_refptr_mismatch_checker.h create mode 100644 src/base/memory/ref_counted.cc create mode 100644 src/base/memory/ref_counted.h create mode 100644 src/base/memory/scoped_policy.h create mode 100644 src/base/memory/scoped_refptr.h create mode 100644 src/base/memory/weak_ptr.cc create mode 100644 src/base/memory/weak_ptr.h create mode 100644 src/base/numerics/checked_math.h create mode 100644 src/base/numerics/checked_math_impl.h create mode 100644 src/base/numerics/clamped_math.h create mode 100644 src/base/numerics/clamped_math_impl.h create mode 100644 src/base/numerics/math_constants.h create mode 100644 src/base/numerics/ranges.h create mode 100644 src/base/numerics/safe_conversions.h create mode 100644 src/base/numerics/safe_conversions_impl.h create mode 100644 src/base/numerics/safe_math.h create mode 100644 src/base/numerics/safe_math_clang_gcc_impl.h create mode 100644 src/base/numerics/safe_math_shared_impl.h create mode 100644 src/base/posix/eintr_wrapper.h create mode 100644 src/base/posix/file_descriptor_shuffle.cc create mode 100644 src/base/posix/file_descriptor_shuffle.h create mode 100644 src/base/posix/safe_strerror.cc create mode 100644 src/base/posix/safe_strerror.h create mode 100644 src/base/scoped_clear_errno.h create mode 100644 src/base/scoped_generic.h create mode 100644 src/base/sha1.cc create mode 100644 src/base/sha1.h create mode 100644 src/base/stl_util.h create mode 100644 src/base/strings/string_number_conversions.cc create mode 100644 src/base/strings/string_number_conversions.h create mode 100644 src/base/strings/string_split.cc create mode 100644 src/base/strings/string_split.h create mode 100644 src/base/strings/string_tokenizer.h create mode 100644 src/base/strings/string_util.cc create mode 100644 src/base/strings/string_util.h create mode 100644 src/base/strings/string_util_constants.cc create mode 100644 src/base/strings/string_util_posix.h create mode 100644 src/base/strings/string_util_win.h create mode 100644 src/base/strings/stringize_macros.h create mode 100644 src/base/strings/stringprintf.cc create mode 100644 src/base/strings/stringprintf.h create mode 100644 src/base/strings/utf_offset_string_conversions.cc create mode 100644 src/base/strings/utf_offset_string_conversions.h create mode 100644 src/base/strings/utf_string_conversion_utils.cc create mode 100644 src/base/strings/utf_string_conversion_utils.h create mode 100644 src/base/strings/utf_string_conversions.cc create mode 100644 src/base/strings/utf_string_conversions.h create mode 100644 src/base/sys_byteorder.h create mode 100644 src/base/template_util.h create mode 100644 src/base/third_party/icu/LICENSE create mode 100644 src/base/third_party/icu/README.chromium create mode 100644 src/base/third_party/icu/icu_utf.cc create mode 100644 src/base/third_party/icu/icu_utf.h create mode 100644 src/base/timer/elapsed_timer.cc create mode 100644 src/base/timer/elapsed_timer.h create mode 100644 src/base/value_iterators.cc create mode 100644 src/base/value_iterators.h create mode 100644 src/base/values.cc create mode 100644 src/base/values.h create mode 100644 src/base/win/registry.cc create mode 100644 src/base/win/registry.h create mode 100644 src/base/win/scoped_handle.cc create mode 100644 src/base/win/scoped_handle.h create mode 100644 src/base/win/scoped_process_information.cc create mode 100644 src/base/win/scoped_process_information.h create mode 100644 src/base/win/win_util.h create mode 100644 src/gn/action_target_generator.cc create mode 100644 src/gn/action_target_generator.h create mode 100644 src/gn/action_target_generator_unittest.cc create mode 100644 src/gn/action_values.cc create mode 100644 src/gn/action_values.h create mode 100644 src/gn/analyzer.cc create mode 100644 src/gn/analyzer.h create mode 100644 src/gn/analyzer_unittest.cc create mode 100644 src/gn/args.cc create mode 100644 src/gn/args.h create mode 100644 src/gn/args_unittest.cc create mode 100644 src/gn/binary_target_generator.cc create mode 100644 src/gn/binary_target_generator.h create mode 100644 src/gn/build_settings.cc create mode 100644 src/gn/build_settings.h create mode 100644 src/gn/builder.cc create mode 100644 src/gn/builder.h create mode 100644 src/gn/builder_record.cc create mode 100644 src/gn/builder_record.h create mode 100644 src/gn/builder_unittest.cc create mode 100644 src/gn/bundle_data.cc create mode 100644 src/gn/bundle_data.h create mode 100644 src/gn/bundle_data_target_generator.cc create mode 100644 src/gn/bundle_data_target_generator.h create mode 100644 src/gn/bundle_file_rule.cc create mode 100644 src/gn/bundle_file_rule.h create mode 100644 src/gn/c_include_iterator.cc create mode 100644 src/gn/c_include_iterator.h create mode 100644 src/gn/c_include_iterator_unittest.cc create mode 100644 src/gn/c_substitution_type.cc create mode 100644 src/gn/c_substitution_type.h create mode 100644 src/gn/c_tool.cc create mode 100644 src/gn/c_tool.h create mode 100644 src/gn/command_analyze.cc create mode 100644 src/gn/command_args.cc create mode 100644 src/gn/command_check.cc create mode 100644 src/gn/command_clean.cc create mode 100644 src/gn/command_clean_stale.cc create mode 100644 src/gn/command_desc.cc create mode 100644 src/gn/command_format.cc create mode 100644 src/gn/command_format.h create mode 100644 src/gn/command_format_unittest.cc create mode 100644 src/gn/command_gen.cc create mode 100644 src/gn/command_help.cc create mode 100644 src/gn/command_ls.cc create mode 100644 src/gn/command_meta.cc create mode 100644 src/gn/command_outputs.cc create mode 100644 src/gn/command_path.cc create mode 100644 src/gn/command_refs.cc create mode 100644 src/gn/commands.cc create mode 100644 src/gn/commands.h create mode 100644 src/gn/commands_unittest.cc create mode 100644 src/gn/compile_commands_writer.cc create mode 100644 src/gn/compile_commands_writer.h create mode 100644 src/gn/compile_commands_writer_unittest.cc create mode 100644 src/gn/config.cc create mode 100644 src/gn/config.h create mode 100644 src/gn/config_unittest.cc create mode 100644 src/gn/config_values.cc create mode 100644 src/gn/config_values.h create mode 100644 src/gn/config_values_extractors.cc create mode 100644 src/gn/config_values_extractors.h create mode 100644 src/gn/config_values_extractors_unittest.cc create mode 100644 src/gn/config_values_generator.cc create mode 100644 src/gn/config_values_generator.h create mode 100644 src/gn/copy_target_generator.cc create mode 100644 src/gn/copy_target_generator.h create mode 100644 src/gn/create_bundle_target_generator.cc create mode 100644 src/gn/create_bundle_target_generator.h create mode 100644 src/gn/deps_iterator.cc create mode 100644 src/gn/deps_iterator.h create mode 100644 src/gn/desc_builder.cc create mode 100644 src/gn/desc_builder.h create mode 100644 src/gn/eclipse_writer.cc create mode 100644 src/gn/eclipse_writer.h create mode 100644 src/gn/err.cc create mode 100644 src/gn/err.h create mode 100644 src/gn/escape.cc create mode 100644 src/gn/escape.h create mode 100644 src/gn/escape_unittest.cc create mode 100644 src/gn/exec_process.cc create mode 100644 src/gn/exec_process.h create mode 100644 src/gn/exec_process_unittest.cc create mode 100644 src/gn/file_writer.cc create mode 100644 src/gn/file_writer.h create mode 100644 src/gn/file_writer_unittest.cc create mode 100644 src/gn/filesystem_utils.cc create mode 100644 src/gn/filesystem_utils.h create mode 100644 src/gn/filesystem_utils_unittest.cc create mode 100644 src/gn/format_test_data/001.gn create mode 100644 src/gn/format_test_data/001.golden create mode 100644 src/gn/format_test_data/002.gn create mode 100644 src/gn/format_test_data/002.golden create mode 100644 src/gn/format_test_data/003.gn create mode 100644 src/gn/format_test_data/003.golden create mode 100644 src/gn/format_test_data/004.gn create mode 100644 src/gn/format_test_data/004.golden create mode 100644 src/gn/format_test_data/005.gn create mode 100644 src/gn/format_test_data/005.golden create mode 100644 src/gn/format_test_data/006.gn create mode 100644 src/gn/format_test_data/006.golden create mode 100644 src/gn/format_test_data/007.gn create mode 100644 src/gn/format_test_data/007.golden create mode 100644 src/gn/format_test_data/008.gn create mode 100644 src/gn/format_test_data/008.golden create mode 100644 src/gn/format_test_data/009.gn create mode 100644 src/gn/format_test_data/009.golden create mode 100644 src/gn/format_test_data/010.gn create mode 100644 src/gn/format_test_data/010.golden create mode 100644 src/gn/format_test_data/011.gn create mode 100644 src/gn/format_test_data/011.golden create mode 100644 src/gn/format_test_data/012.gn create mode 100644 src/gn/format_test_data/012.golden create mode 100644 src/gn/format_test_data/013.gn create mode 100644 src/gn/format_test_data/013.golden create mode 100644 src/gn/format_test_data/014.gn create mode 100644 src/gn/format_test_data/014.golden create mode 100644 src/gn/format_test_data/015.gn create mode 100644 src/gn/format_test_data/015.golden create mode 100644 src/gn/format_test_data/016.gn create mode 100644 src/gn/format_test_data/016.golden create mode 100644 src/gn/format_test_data/017.gn create mode 100644 src/gn/format_test_data/017.golden create mode 100644 src/gn/format_test_data/018.gn create mode 100644 src/gn/format_test_data/018.golden create mode 100644 src/gn/format_test_data/019.gn create mode 100644 src/gn/format_test_data/019.golden create mode 100644 src/gn/format_test_data/020.gn create mode 100644 src/gn/format_test_data/020.golden create mode 100644 src/gn/format_test_data/021.gn create mode 100644 src/gn/format_test_data/021.golden create mode 100644 src/gn/format_test_data/022.gn create mode 100644 src/gn/format_test_data/022.golden create mode 100644 src/gn/format_test_data/023.gn create mode 100644 src/gn/format_test_data/023.golden create mode 100644 src/gn/format_test_data/024.gn create mode 100644 src/gn/format_test_data/024.golden create mode 100644 src/gn/format_test_data/025.gn create mode 100644 src/gn/format_test_data/025.golden create mode 100644 src/gn/format_test_data/026.gn create mode 100644 src/gn/format_test_data/026.golden create mode 100644 src/gn/format_test_data/027.gn create mode 100644 src/gn/format_test_data/027.golden create mode 100644 src/gn/format_test_data/028.gn create mode 100644 src/gn/format_test_data/028.golden create mode 100644 src/gn/format_test_data/029.gn create mode 100644 src/gn/format_test_data/029.golden create mode 100644 src/gn/format_test_data/030.gn create mode 100644 src/gn/format_test_data/030.golden create mode 100644 src/gn/format_test_data/031.gn create mode 100644 src/gn/format_test_data/031.golden create mode 100644 src/gn/format_test_data/032.gn create mode 100644 src/gn/format_test_data/032.golden create mode 100644 src/gn/format_test_data/033.gn create mode 100644 src/gn/format_test_data/033.golden create mode 100644 src/gn/format_test_data/034.gn create mode 100644 src/gn/format_test_data/035.gn create mode 100644 src/gn/format_test_data/035.golden create mode 100644 src/gn/format_test_data/036.gn create mode 100644 src/gn/format_test_data/036.golden create mode 100644 src/gn/format_test_data/037.gn create mode 100644 src/gn/format_test_data/037.golden create mode 100644 src/gn/format_test_data/038.gn create mode 100644 src/gn/format_test_data/038.golden create mode 100644 src/gn/format_test_data/039.gn create mode 100644 src/gn/format_test_data/039.golden create mode 100644 src/gn/format_test_data/040.gn create mode 100644 src/gn/format_test_data/040.golden create mode 100644 src/gn/format_test_data/041.gn create mode 100644 src/gn/format_test_data/041.golden create mode 100644 src/gn/format_test_data/042.gn create mode 100644 src/gn/format_test_data/042.golden create mode 100644 src/gn/format_test_data/043.gn create mode 100644 src/gn/format_test_data/043.golden create mode 100644 src/gn/format_test_data/044.gn create mode 100644 src/gn/format_test_data/044.golden create mode 100644 src/gn/format_test_data/045.gn create mode 100644 src/gn/format_test_data/045.golden create mode 100644 src/gn/format_test_data/046.gn create mode 100644 src/gn/format_test_data/046.golden create mode 100644 src/gn/format_test_data/047.gn create mode 100644 src/gn/format_test_data/047.golden create mode 100644 src/gn/format_test_data/048.gn create mode 100644 src/gn/format_test_data/048.golden create mode 100644 src/gn/format_test_data/049.gn create mode 100644 src/gn/format_test_data/050.gn create mode 100644 src/gn/format_test_data/050.golden create mode 100644 src/gn/format_test_data/051.gn create mode 100644 src/gn/format_test_data/051.golden create mode 100644 src/gn/format_test_data/052.gn create mode 100644 src/gn/format_test_data/052.golden create mode 100644 src/gn/format_test_data/053.gn create mode 100644 src/gn/format_test_data/053.golden create mode 100644 src/gn/format_test_data/054.gn create mode 100644 src/gn/format_test_data/054.golden create mode 100644 src/gn/format_test_data/055.gn create mode 100644 src/gn/format_test_data/055.golden create mode 100644 src/gn/format_test_data/056.gn create mode 100644 src/gn/format_test_data/056.golden create mode 100644 src/gn/format_test_data/057.gn create mode 100644 src/gn/format_test_data/057.golden create mode 100644 src/gn/format_test_data/058.gn create mode 100644 src/gn/format_test_data/058.golden create mode 100644 src/gn/format_test_data/059.gn create mode 100644 src/gn/format_test_data/059.golden create mode 100644 src/gn/format_test_data/060.gn create mode 100644 src/gn/format_test_data/060.golden create mode 100644 src/gn/format_test_data/061.gn create mode 100644 src/gn/format_test_data/061.golden create mode 100644 src/gn/format_test_data/062.gn create mode 100644 src/gn/format_test_data/062.golden create mode 100644 src/gn/format_test_data/063.gn create mode 100644 src/gn/format_test_data/063.golden create mode 100644 src/gn/format_test_data/064.gn create mode 100644 src/gn/format_test_data/064.golden create mode 100644 src/gn/format_test_data/065.gn create mode 100644 src/gn/format_test_data/065.golden create mode 100644 src/gn/format_test_data/066.gn create mode 100644 src/gn/format_test_data/066.golden create mode 100644 src/gn/format_test_data/067.gn create mode 100644 src/gn/format_test_data/067.golden create mode 100644 src/gn/format_test_data/068.gn create mode 100644 src/gn/format_test_data/068.golden create mode 100644 src/gn/format_test_data/069.gn create mode 100644 src/gn/format_test_data/069.golden create mode 100644 src/gn/format_test_data/070.gn create mode 100644 src/gn/format_test_data/070.golden create mode 100644 src/gn/format_test_data/071.gn create mode 100644 src/gn/format_test_data/071.golden create mode 100644 src/gn/format_test_data/072.gn create mode 100644 src/gn/format_test_data/072.golden create mode 100644 src/gn/format_test_data/073.gn create mode 100644 src/gn/format_test_data/073.golden create mode 100644 src/gn/format_test_data/074.gn create mode 100644 src/gn/format_test_data/074.golden create mode 100644 src/gn/format_test_data/075.gn create mode 100644 src/gn/format_test_data/075.golden create mode 100644 src/gn/format_test_data/076.gn create mode 100644 src/gn/format_test_data/076.golden create mode 100644 src/gn/format_test_data/077.gn create mode 100644 src/gn/format_test_data/077.golden create mode 100644 src/gn/format_test_data/078.gn create mode 100644 src/gn/format_test_data/078.golden create mode 100644 src/gn/format_test_data/079.gn create mode 100644 src/gn/format_test_data/079.golden create mode 100644 src/gn/format_test_data/080.gn create mode 100644 src/gn/format_test_data/080.golden create mode 100644 src/gn/format_test_data/081.gn create mode 100644 src/gn/format_test_data/081.golden create mode 100644 src/gn/format_test_data/082.gn create mode 100644 src/gn/format_test_data/082.golden create mode 100644 src/gn/format_test_data/083.gn create mode 100644 src/gn/format_test_data/083.golden create mode 100644 src/gn/frameworks_utils.cc create mode 100644 src/gn/frameworks_utils.h create mode 100644 src/gn/frameworks_utils_unittest.cc create mode 100644 src/gn/function_exec_script.cc create mode 100644 src/gn/function_filter.cc create mode 100644 src/gn/function_filter_unittest.cc create mode 100644 src/gn/function_foreach.cc create mode 100644 src/gn/function_foreach_unittest.cc create mode 100644 src/gn/function_forward_variables_from.cc create mode 100644 src/gn/function_forward_variables_from_unittest.cc create mode 100644 src/gn/function_get_label_info.cc create mode 100644 src/gn/function_get_label_info_unittest.cc create mode 100644 src/gn/function_get_path_info.cc create mode 100644 src/gn/function_get_path_info_unittest.cc create mode 100644 src/gn/function_get_target_outputs.cc create mode 100644 src/gn/function_get_target_outputs_unittest.cc create mode 100644 src/gn/function_process_file_template.cc create mode 100644 src/gn/function_process_file_template_unittest.cc create mode 100644 src/gn/function_read_file.cc create mode 100644 src/gn/function_rebase_path.cc create mode 100644 src/gn/function_rebase_path_unittest.cc create mode 100644 src/gn/function_set_default_toolchain.cc create mode 100644 src/gn/function_set_defaults.cc create mode 100644 src/gn/function_template.cc create mode 100644 src/gn/function_template_unittest.cc create mode 100644 src/gn/function_toolchain.cc create mode 100644 src/gn/function_toolchain_unittest.cc create mode 100644 src/gn/function_write_file.cc create mode 100644 src/gn/function_write_file_unittest.cc create mode 100644 src/gn/functions.cc create mode 100644 src/gn/functions.h create mode 100644 src/gn/functions_target.cc create mode 100644 src/gn/functions_target_rust_unittest.cc create mode 100644 src/gn/functions_target_unittest.cc create mode 100644 src/gn/functions_unittest.cc create mode 100644 src/gn/general_tool.cc create mode 100644 src/gn/general_tool.h create mode 100644 src/gn/generated_file_target_generator.cc create mode 100644 src/gn/generated_file_target_generator.h create mode 100644 src/gn/gn_main.cc create mode 100644 src/gn/group_target_generator.cc create mode 100644 src/gn/group_target_generator.h create mode 100644 src/gn/hash_table_base.h create mode 100644 src/gn/hash_table_base_unittest.cc create mode 100644 src/gn/header_checker.cc create mode 100644 src/gn/header_checker.h create mode 100644 src/gn/header_checker_unittest.cc create mode 100644 src/gn/import_manager.cc create mode 100644 src/gn/import_manager.h create mode 100644 src/gn/inherited_libraries.cc create mode 100644 src/gn/inherited_libraries.h create mode 100644 src/gn/inherited_libraries_unittest.cc create mode 100644 src/gn/input_conversion.cc create mode 100644 src/gn/input_conversion.h create mode 100644 src/gn/input_conversion_unittest.cc create mode 100644 src/gn/input_file.cc create mode 100644 src/gn/input_file.h create mode 100644 src/gn/input_file_manager.cc create mode 100644 src/gn/input_file_manager.h create mode 100644 src/gn/item.cc create mode 100644 src/gn/item.h create mode 100644 src/gn/json_project_writer.cc create mode 100644 src/gn/json_project_writer.h create mode 100644 src/gn/json_project_writer_unittest.cc create mode 100644 src/gn/label.cc create mode 100644 src/gn/label.h create mode 100644 src/gn/label_pattern.cc create mode 100644 src/gn/label_pattern.h create mode 100644 src/gn/label_pattern_unittest.cc create mode 100644 src/gn/label_ptr.h create mode 100644 src/gn/label_unittest.cc create mode 100644 src/gn/lib_file.cc create mode 100644 src/gn/lib_file.h create mode 100644 src/gn/loader.cc create mode 100644 src/gn/loader.h create mode 100644 src/gn/loader_unittest.cc create mode 100644 src/gn/location.cc create mode 100644 src/gn/location.h create mode 100644 src/gn/metadata.cc create mode 100644 src/gn/metadata.h create mode 100644 src/gn/metadata_unittest.cc create mode 100644 src/gn/metadata_walk.cc create mode 100644 src/gn/metadata_walk.h create mode 100644 src/gn/metadata_walk_unittest.cc create mode 100644 src/gn/ninja_action_target_writer.cc create mode 100644 src/gn/ninja_action_target_writer.h create mode 100644 src/gn/ninja_action_target_writer_unittest.cc create mode 100644 src/gn/ninja_binary_target_writer.cc create mode 100644 src/gn/ninja_binary_target_writer.h create mode 100644 src/gn/ninja_binary_target_writer_unittest.cc create mode 100644 src/gn/ninja_build_writer.cc create mode 100644 src/gn/ninja_build_writer.h create mode 100644 src/gn/ninja_build_writer_unittest.cc create mode 100644 src/gn/ninja_bundle_data_target_writer.cc create mode 100644 src/gn/ninja_bundle_data_target_writer.h create mode 100644 src/gn/ninja_bundle_data_target_writer_unittest.cc create mode 100644 src/gn/ninja_c_binary_target_writer.cc create mode 100644 src/gn/ninja_c_binary_target_writer.h create mode 100644 src/gn/ninja_c_binary_target_writer_unittest.cc create mode 100644 src/gn/ninja_copy_target_writer.cc create mode 100644 src/gn/ninja_copy_target_writer.h create mode 100644 src/gn/ninja_copy_target_writer_unittest.cc create mode 100644 src/gn/ninja_create_bundle_target_writer.cc create mode 100644 src/gn/ninja_create_bundle_target_writer.h create mode 100644 src/gn/ninja_create_bundle_target_writer_unittest.cc create mode 100644 src/gn/ninja_generated_file_target_writer.cc create mode 100644 src/gn/ninja_generated_file_target_writer.h create mode 100644 src/gn/ninja_generated_file_target_writer_unittest.cc create mode 100644 src/gn/ninja_group_target_writer.cc create mode 100644 src/gn/ninja_group_target_writer.h create mode 100644 src/gn/ninja_group_target_writer_unittest.cc create mode 100644 src/gn/ninja_rust_binary_target_writer.cc create mode 100644 src/gn/ninja_rust_binary_target_writer.h create mode 100644 src/gn/ninja_rust_binary_target_writer_unittest.cc create mode 100644 src/gn/ninja_target_command_util.cc create mode 100644 src/gn/ninja_target_command_util.h create mode 100644 src/gn/ninja_target_command_util_unittest.cc create mode 100644 src/gn/ninja_target_writer.cc create mode 100644 src/gn/ninja_target_writer.h create mode 100644 src/gn/ninja_target_writer_unittest.cc create mode 100644 src/gn/ninja_toolchain_writer.cc create mode 100644 src/gn/ninja_toolchain_writer.h create mode 100644 src/gn/ninja_toolchain_writer_unittest.cc create mode 100644 src/gn/ninja_tools.cc create mode 100644 src/gn/ninja_tools.h create mode 100644 src/gn/ninja_utils.cc create mode 100644 src/gn/ninja_utils.h create mode 100644 src/gn/ninja_writer.cc create mode 100644 src/gn/ninja_writer.h create mode 100644 src/gn/operators.cc create mode 100644 src/gn/operators.h create mode 100644 src/gn/operators_unittest.cc create mode 100644 src/gn/ordered_set.h create mode 100644 src/gn/output_conversion.cc create mode 100644 src/gn/output_conversion.h create mode 100644 src/gn/output_conversion_unittest.cc create mode 100644 src/gn/output_file.cc create mode 100644 src/gn/output_file.h create mode 100644 src/gn/parse_node_value_adapter.cc create mode 100644 src/gn/parse_node_value_adapter.h create mode 100644 src/gn/parse_tree.cc create mode 100644 src/gn/parse_tree.h create mode 100644 src/gn/parse_tree_unittest.cc create mode 100644 src/gn/parser.cc create mode 100644 src/gn/parser.h create mode 100644 src/gn/parser_unittest.cc create mode 100644 src/gn/path_output.cc create mode 100644 src/gn/path_output.h create mode 100644 src/gn/path_output_unittest.cc create mode 100644 src/gn/pattern.cc create mode 100644 src/gn/pattern.h create mode 100644 src/gn/pattern_unittest.cc create mode 100644 src/gn/pool.cc create mode 100644 src/gn/pool.h create mode 100644 src/gn/qt_creator_writer.cc create mode 100644 src/gn/qt_creator_writer.h create mode 100644 src/gn/runtime_deps.cc create mode 100644 src/gn/runtime_deps.h create mode 100644 src/gn/runtime_deps_unittest.cc create mode 100644 src/gn/rust_project_writer.cc create mode 100644 src/gn/rust_project_writer.h create mode 100644 src/gn/rust_project_writer_helpers.h create mode 100644 src/gn/rust_project_writer_helpers_unittest.cc create mode 100644 src/gn/rust_project_writer_unittest.cc create mode 100644 src/gn/rust_substitution_type.cc create mode 100644 src/gn/rust_substitution_type.h create mode 100644 src/gn/rust_tool.cc create mode 100644 src/gn/rust_tool.h create mode 100644 src/gn/rust_values.cc create mode 100644 src/gn/rust_values.h create mode 100644 src/gn/rust_values_generator.cc create mode 100644 src/gn/rust_values_generator.h create mode 100644 src/gn/rust_variables.cc create mode 100644 src/gn/rust_variables.h create mode 100644 src/gn/scheduler.cc create mode 100644 src/gn/scheduler.h create mode 100644 src/gn/scope.cc create mode 100644 src/gn/scope.h create mode 100644 src/gn/scope_per_file_provider.cc create mode 100644 src/gn/scope_per_file_provider.h create mode 100644 src/gn/scope_per_file_provider_unittest.cc create mode 100644 src/gn/scope_unittest.cc create mode 100644 src/gn/settings.cc create mode 100644 src/gn/settings.h create mode 100644 src/gn/setup.cc create mode 100644 src/gn/setup.h create mode 100644 src/gn/setup_unittest.cc create mode 100644 src/gn/source_dir.cc create mode 100644 src/gn/source_dir.h create mode 100644 src/gn/source_dir_unittest.cc create mode 100644 src/gn/source_file.cc create mode 100644 src/gn/source_file.h create mode 100644 src/gn/source_file_unittest.cc create mode 100644 src/gn/standard_out.cc create mode 100644 src/gn/standard_out.h create mode 100644 src/gn/string_atom.cc create mode 100644 src/gn/string_atom.h create mode 100644 src/gn/string_atom_unittest.cc create mode 100644 src/gn/string_output_buffer.cc create mode 100644 src/gn/string_output_buffer.h create mode 100644 src/gn/string_output_buffer_unittest.cc create mode 100644 src/gn/string_utils.cc create mode 100644 src/gn/string_utils.h create mode 100644 src/gn/string_utils_unittest.cc create mode 100644 src/gn/substitution_list.cc create mode 100644 src/gn/substitution_list.h create mode 100644 src/gn/substitution_pattern.cc create mode 100644 src/gn/substitution_pattern.h create mode 100644 src/gn/substitution_pattern_unittest.cc create mode 100644 src/gn/substitution_type.cc create mode 100644 src/gn/substitution_type.h create mode 100644 src/gn/substitution_writer.cc create mode 100644 src/gn/substitution_writer.h create mode 100644 src/gn/substitution_writer_unittest.cc create mode 100644 src/gn/swift_values.cc create mode 100644 src/gn/swift_values.h create mode 100644 src/gn/swift_values_generator.cc create mode 100644 src/gn/swift_values_generator.h create mode 100644 src/gn/swift_variables.cc create mode 100644 src/gn/swift_variables.h create mode 100644 src/gn/switches.cc create mode 100644 src/gn/switches.h create mode 100644 src/gn/target.cc create mode 100644 src/gn/target.h create mode 100644 src/gn/target_generator.cc create mode 100644 src/gn/target_generator.h create mode 100644 src/gn/target_unittest.cc create mode 100644 src/gn/template.cc create mode 100644 src/gn/template.h create mode 100644 src/gn/template_unittest.cc create mode 100644 src/gn/test_with_scheduler.cc create mode 100644 src/gn/test_with_scheduler.h create mode 100644 src/gn/test_with_scope.cc create mode 100644 src/gn/test_with_scope.h create mode 100644 src/gn/token.cc create mode 100644 src/gn/token.h create mode 100644 src/gn/tokenizer.cc create mode 100644 src/gn/tokenizer.h create mode 100644 src/gn/tokenizer_unittest.cc create mode 100644 src/gn/tool.cc create mode 100644 src/gn/tool.h create mode 100644 src/gn/toolchain.cc create mode 100644 src/gn/toolchain.h create mode 100644 src/gn/trace.cc create mode 100644 src/gn/trace.h create mode 100644 src/gn/unique_vector.h create mode 100644 src/gn/unique_vector_unittest.cc create mode 100644 src/gn/value.cc create mode 100644 src/gn/value.h create mode 100644 src/gn/value_extractors.cc create mode 100644 src/gn/value_extractors.h create mode 100644 src/gn/value_unittest.cc create mode 100644 src/gn/variables.cc create mode 100644 src/gn/variables.h create mode 100644 src/gn/vector_utils.h create mode 100644 src/gn/vector_utils_unittest.cc create mode 100644 src/gn/version.cc create mode 100644 src/gn/version.h create mode 100644 src/gn/version_unittest.cc create mode 100644 src/gn/visibility.cc create mode 100644 src/gn/visibility.h create mode 100644 src/gn/visibility_unittest.cc create mode 100644 src/gn/visual_studio_utils.cc create mode 100644 src/gn/visual_studio_utils.h create mode 100644 src/gn/visual_studio_utils_unittest.cc create mode 100644 src/gn/visual_studio_writer.cc create mode 100644 src/gn/visual_studio_writer.h create mode 100644 src/gn/visual_studio_writer_unittest.cc create mode 100644 src/gn/xcode_object.cc create mode 100644 src/gn/xcode_object.h create mode 100644 src/gn/xcode_object_unittest.cc create mode 100644 src/gn/xcode_writer.cc create mode 100644 src/gn/xcode_writer.h create mode 100644 src/gn/xml_element_writer.cc create mode 100644 src/gn/xml_element_writer.h create mode 100644 src/gn/xml_element_writer_unittest.cc create mode 100644 src/util/auto_reset_event.h create mode 100644 src/util/build_config.h create mode 100644 src/util/exe_path.cc create mode 100644 src/util/exe_path.h create mode 100644 src/util/msg_loop.cc create mode 100644 src/util/msg_loop.h create mode 100644 src/util/semaphore.cc create mode 100644 src/util/semaphore.h create mode 100644 src/util/sys_info.cc create mode 100644 src/util/sys_info.h create mode 100644 src/util/test/gn_test.cc create mode 100644 src/util/test/test.h create mode 100644 src/util/ticks.cc create mode 100644 src/util/ticks.h create mode 100644 src/util/worker_pool.cc create mode 100644 src/util/worker_pool.h create mode 100755 tools/find_unreachable.py diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..b17a52a --- /dev/null +++ b/.clang-format @@ -0,0 +1,2 @@ +BasedOnStyle: Chromium +Standard: Cpp11 diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..2491fdf --- /dev/null +++ b/.editorconfig @@ -0,0 +1,3 @@ +[*.py] +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4c20aff --- /dev/null +++ b/.gitignore @@ -0,0 +1,62 @@ +*.bak +*.gypcmd +*.mk +*.ncb +*.opensdf +*.orig +*.pdb +*.props +*.pyc +*.pyproj +*.rules +*.sdf +*.sln +*.sublime-project +*.sublime-workspace +*.suo +*.targets +*.user +*.vc.opendb +*.vcproj +*.vcxproj +*.vcxproj.filters +*.vpj +*.vpw +*.vpwhistu +*.vtg +*.xcodeproj +*.xcworkspace +*.VC.db +*_proto.xml +*_proto_cpp.xml +*~ +!Android.mk +.*.sw? +.DS_Store +.cipd +.classpath +.cproject +.gdb_history +.gdbinit +.landmines +.metadata +.project +.pydevproject +.recipe_deps +.checkstyle +cscope.* +out/ +GPATH +GRTAGS +GSYMS +GTAGS +Session.vim +tags +Thumbs.db +# Settings directories for eclipse +/.externalToolBuilders/ +/.settings/ +/.vs/ +# Visual Studio Code +/.vscode/ +/_out diff --git a/.style.yapf b/.style.yapf new file mode 100644 index 0000000..de0c6a7 --- /dev/null +++ b/.style.yapf @@ -0,0 +1,2 @@ +[style] +based_on_style = chromium diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..2e9eb5a --- /dev/null +++ b/AUTHORS @@ -0,0 +1,49 @@ +# Names should be added to this file with this pattern: +# +# For individuals: +# Name +# +# For organizations: +# Organization +# +# See python fnmatch module documentation for more information. + +Google Inc. <*@google.com> +HyperConnect Inc. <*@hpcnt.com> +IBM Inc. <*@*.ibm.com> +Loongson Technology Corporation Limited. <*@loongson.cn> +MIPS Technologies, Inc. <*@mips.com> +NVIDIA Corporation <*@nvidia.com> +Opera Software ASA <*@opera.com> +The Chromium Authors <*@chromium.org> +Vewd Software AS <*@vewd.com> +Vivaldi Technologies AS <*@vivaldi.com> +Yandex LLC <*@yandex-team.ru> + +Alexis Menard +Alfredo Mazzinghi +Andrew Boyarshin +Anuj Kumar Sharma +DanCraft99 +Gergely Nagy +Ilia K +Ivan Naydonov +Joe Armstrong +Julien Brianceau +Kal Conley +Kamil Rytarowski +Martijn Croonen +Matej Knopp +Michael Gilbert +Milko Leporis +Mohan Reddy +Raphael Kubo da Costa +Riku Voipio +Saikrishna Arcot +Tim Niederhausen +Tomas Popela +Tripta Gupta +Wink Saville +Yuriy Taraday +Oleksandr Motsok +Ihor Karavan diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a32e00c --- /dev/null +++ b/LICENSE @@ -0,0 +1,27 @@ +// Copyright 2015 The Chromium Authors. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/OWNERS b/OWNERS new file mode 100644 index 0000000..d78697c --- /dev/null +++ b/OWNERS @@ -0,0 +1,3 @@ +brettw@chromium.org +phosek@chromium.org +scottmg@chromium.org diff --git a/README.md b/README.md new file mode 100644 index 0000000..6fa5edd --- /dev/null +++ b/README.md @@ -0,0 +1,204 @@ +# GN + +GN is a meta-build system that generates build files for +[Ninja](https://ninja-build.org). + +Related resources: + + * Documentation in [docs/](https://gn.googlesource.com/gn/+/master/docs/). In + particular [GN Quick Start + guide](https://gn.googlesource.com/gn/+/master/docs/quick_start.md) + and the [reference](https://gn.googlesource.com/gn/+/master/docs/reference.md) + (the latter is all builtin help converted to a single file). + * An introductory [presentation](https://docs.google.com/presentation/d/15Zwb53JcncHfEwHpnG_PoIbbzQ3GQi_cpujYwbpcbZo/edit?usp=sharing). + * The [mailing list](https://groups.google.com/a/chromium.org/forum/#!forum/gn-dev). + +## What GN is for + +GN is currently used as the build system for Chromium, Fuchsia, and related +projects. Some strengths of GN are: + + * It is designed for large projects and large teams. It scales efficiently to + many thousands of build files and tens of thousands of source files. + + * It has a readable, clean syntax. Once a build is set-up, it is generally + easy for people with no backround in GN to make basic edits to the build. + + * It is designed for multi-platform projects. It can cleanly express many + complicated build variants across different platforms. A single build + invocation can target multiple platforms. + + * It supports multiple parallel output directories, each with their own + configuration. This allows a developer to maintain builds targeting debug, + release, or different platforms in parallel without forced rebuilds when + switching. + + * It has a focus on correctness. GN checks for the correct dependencies, + inputs, and outputs to the extent possible, and has a number of tools to + allow developers to ensure the build evolves as desired (for example, `gn + check`, `testonly`, `assert_no_deps`). + + * It has comprehensive build-in help available from the command-line. + +Although small projects successfully use GN, the focus on large projects has +some disadvanages: + + * GN has the goal of being minimally expressive. Although it can be quite + flexible, a design goal is to direct members of a large team (who may not + have much knowledge about the build) down an easy-to-understand, well-lit + path. This isn't necessarily the correct trade-off for smaller projects. + + * The minimal build configuration is relatively heavyweight. There are several + files required and the exact way all compilers are linkers are run must be + specified in the configuration (see "Examples" below). There is no default + compiler configuration. + + * It is not easily composable. GN is designed to compile a single large + project with relatively uniform settings and rules. Projects like Chromium + do bring together multiple repositories from multiple teams, but the + projects must agree on some conventions in the build files to allow this to + work. + + * GN is designed with the expectation that the developers build a project want + to compile an identical configuration. So while builds can integrate + with the user's environment like the CXX and CFLAGS variables if they want, + this is not the default and most project's builds do not do this. The result + is that many GN projects do not integrate well with other systems like + ebuild. + + * There is no simple release scheme (see "Versioning and distribution" below). + Projects are expected to manage the version of GN they require. Getting an + appropriate GN binary can be a hurdle for new contributors to a project. + Since it is relatively uncommon, it can be more difficult to find + information and examples. + +GN can generate Ninja build files for C, C++, Rust, Objective C, and Swift +source on most popular platforms. Other languages can be compiled using the +general "action" rules (Google does this for Java and Go). But because this is +not as clean, generally GN is only used when the bulk of the build is in one of +the main built-in languages. + +## Getting a binary + +You can download the latest version of GN binary for +[Linux](https://chrome-infra-packages.appspot.com/dl/gn/gn/linux-amd64/+/latest), +[macOS](https://chrome-infra-packages.appspot.com/dl/gn/gn/mac-amd64/+/latest) and +[Windows](https://chrome-infra-packages.appspot.com/dl/gn/gn/windows-amd64/+/latest) +from Google's build infrastructure (see "Versioning and distribution" below for +how this is expected to work). + +Alternatively, you can build GN from source with a C++17 compiler: + + git clone https://gn.googlesource.com/gn + cd gn + python build/gen.py + ninja -C out + # To run tests: + out/gn_unittests + +On Windows, it is expected that `cl.exe`, `link.exe`, and `lib.exe` can be found +in `PATH`, so you'll want to run from a Visual Studio command prompt, or +similar. + +On Linux and Mac, the default compiler is `clang++`, a recent version is +expected to be found in `PATH`. This can be overridden by setting `CC`, `CXX`, +and `AR`. + +## Examples + +There is a simple example in [examples/simple_build](examples/simple_build) +directory that is a good place to get started with the minimal configuration. + +To build and run the simple example with the default gcc compiler: + + cd examples/simple_build + ../../out/gn gen -C out + ninja -C out + ./out/hello + +For a maximal configuration see the Chromium setup: + * [.gn](https://cs.chromium.org/chromium/src/.gn) + * [BUILDCONFIG.gn](https://cs.chromium.org/chromium/src/build/config/BUILDCONFIG.gn) + * [Toolchain setup](https://cs.chromium.org/chromium/src/build/toolchain/) + * [Compiler setup](https://cs.chromium.org/chromium/src/build/config/compiler/BUILD.gn) + +and the Fuchsia setup: + * [.gn](https://fuchsia.googlesource.com/fuchsia/+/refs/heads/master/.gn) + * [BUILDCONFIG.gn](https://fuchsia.googlesource.com/fuchsia/+/refs/heads/master/build/config/BUILDCONFIG.gn) + * [Toolchain setup](https://fuchsia.googlesource.com/fuchsia/+/refs/heads/master/build/toolchain/) + * [Compiler setup](https://fuchsia.googlesource.com/fuchsia/+/refs/heads/master/build/config/BUILD.gn) + +## Reporting bugs + +If you find a bug, you can see if it is known or report it in the [bug +database](https://bugs.chromium.org/p/gn/issues/list). + +## Sending patches + +GN uses [Gerrit](https://www.gerritcodereview.com/) for code review. The short +version of how to patch is: + + Register at https://gn-review.googlesource.com. + + ... edit code ... + ninja -C out && out/gn_unittests + +Then, to upload a change for review: + + git commit + git push origin HEAD:refs/for/master + +The first time you do this you'll get an error from the server about a missing +change-ID. Follow the directions in the error message to install the change-ID +hook and run `git commit --amend` to apply the hook to the current commit. + +When revising a change, use: + + git commit --amend + git push origin HEAD:refs/for/master + +which will add the new changes to the existing code review, rather than creating +a new one. + +We ask that all contributors +[sign Google's Contributor License Agreement](https://cla.developers.google.com/) +(either individual or corporate as appropriate, select 'any other Google +project'). + +## Community + +You may ask questions and follow along with GN's development on Chromium's +[gn-dev@](https://groups.google.com/a/chromium.org/forum/#!forum/gn-dev) +Google Group. + +## Versioning and distribution + +Most projects are designed to use the developer's computer's current toolchain +such as compiler, linker, and build tool. But the large projects that GN is +designed for typically want a more hermetic environment. They will ensure that +developers are using a specific compatible toolchain that is versioned with the +code + +As a result, GN expects that the project choose the appropriate version of GN +that will work with each version of the project. There is no "current stable +version" of GN that is expected to work for all projects. + +As a result, the GN developers to not maintain any packages in any of the +various packaging systems (Debian, RedHat, HomeBrew, etc.). Some of these +systems to have GN packages, but they are maintained by third parties and you +should use at your own risk. Instead, we recommend you refer your checkout +tooling to download binaries for a specific hash from [Google's build +infrastructure](https://chrome-infra-packages.appspot.com/p/gn/gn) or compile +your own. + +GN does not guarantee the backwards-compatibility of new versions and has no +branches or versioning scheme beyond the sequence of commits to the master git +branch (which is expected to be stable). + +In practice, however, GN is very backwards-compatible. The core functionality +has been stable for many years and there is enough GN code at Google alone to +make non-backwards-compatible changes very difficult, even if they were +desirable. + +There have been discussions about adding a versioning scheme with some +guarantees about backwards-compatibility, but nothing has yet been implemented. diff --git a/build/build_aix.ninja.template b/build/build_aix.ninja.template new file mode 100644 index 0000000..7d696b0 --- /dev/null +++ b/build/build_aix.ninja.template @@ -0,0 +1,13 @@ +rule cxx + command = $cxx -MMD -MF $out.d $includes $cflags -c $in -o $out + description = CXX $out + depfile = $out.d + deps = gcc + +rule alink_thin + command = rm -f $out && $ar rcsT $out $in + description = AR $out + +rule link + command = $ld $ldflags -o $out $in $libs $solibs + description = LINK $out diff --git a/build/build_haiku.ninja.template b/build/build_haiku.ninja.template new file mode 100644 index 0000000..ab117fb --- /dev/null +++ b/build/build_haiku.ninja.template @@ -0,0 +1,13 @@ +rule cxx + command = $cxx -MMD -MF $out.d $includes $cflags -c $in -o $out + description = CXX $out + depfile = $out.d + deps = gcc + +rule alink_thin + command = rm -f $out && $ar rcsT $out $in + description = AR $out + +rule link + command = $ld $ldflags -o $out -Wl,--start-group $in $libs -Wl,--end-group $solibs + description = LINK $out diff --git a/build/build_linux.ninja.template b/build/build_linux.ninja.template new file mode 100644 index 0000000..ab117fb --- /dev/null +++ b/build/build_linux.ninja.template @@ -0,0 +1,13 @@ +rule cxx + command = $cxx -MMD -MF $out.d $includes $cflags -c $in -o $out + description = CXX $out + depfile = $out.d + deps = gcc + +rule alink_thin + command = rm -f $out && $ar rcsT $out $in + description = AR $out + +rule link + command = $ld $ldflags -o $out -Wl,--start-group $in $libs -Wl,--end-group $solibs + description = LINK $out diff --git a/build/build_mac.ninja.template b/build/build_mac.ninja.template new file mode 100644 index 0000000..8d75a3c --- /dev/null +++ b/build/build_mac.ninja.template @@ -0,0 +1,13 @@ +rule cxx + command = $cxx -MMD -MF $out.d $includes $cflags -c $in -o $out + description = CXX $out + depfile = $out.d + deps = gcc + +rule alink_thin + command = rm -f $out && $ar rcs $out $in + description = AR $out + +rule link + command = $ld $ldflags -o $out $in $solibs $libs + description = LINK $out diff --git a/build/build_openbsd.ninja.template b/build/build_openbsd.ninja.template new file mode 100644 index 0000000..8466900 --- /dev/null +++ b/build/build_openbsd.ninja.template @@ -0,0 +1,13 @@ +rule cxx + command = $cxx -MMD -MF $out.d $includes $cflags -c $in -o $out + description = CXX $out + depfile = $out.d + deps = gcc + +rule alink_thin + command = rm -f $out && $ar rcs $out $in + description = AR $out + +rule link + command = $ld $ldflags -o $out -Wl,--start-group $in $libs -Wl,--end-group $solibs + description = LINK $out diff --git a/build/build_win.ninja.template b/build/build_win.ninja.template new file mode 100644 index 0000000..e2ca186 --- /dev/null +++ b/build/build_win.ninja.template @@ -0,0 +1,12 @@ +rule cxx + command = ninja -t msvc -- $cxx /nologo /showIncludes /FC $includes $cflags /c $in /Fo$out + description = CXX $out + deps = msvc + +rule alink_thin + command = ninja -t msvc -- $ar /nologo /ignore:4221 $libflags /OUT:$out $in + description = LIB $out + +rule link + command = ninja -t msvc -- $ld /nologo $ldflags /OUT:$out /PDB:$out.pdb $in $solibs $libs + description = LINK $out diff --git a/build/full_test.py b/build/full_test.py new file mode 100755 index 0000000..2095ddd --- /dev/null +++ b/build/full_test.py @@ -0,0 +1,81 @@ +#!/usr/bin/env python +# Copyright 2018 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. + +import os +import shutil +import subprocess +import sys +import timeit + + +IS_WIN = sys.platform.startswith('win') + + +def RemoveDir(d): + if os.path.isdir(d): + shutil.rmtree(d) + + +def Trial(gn_path_to_use, save_out_dir=None): + bin_path = os.path.join('out', 'gntrial') + if not os.path.isdir(bin_path): + os.makedirs(bin_path) + gn_to_run = os.path.join(bin_path, 'gn' + ('.exe' if IS_WIN else '')) + shutil.copy2(gn_path_to_use, gn_to_run) + comp_dir = os.path.join('out', 'COMP') + subprocess.check_call([gn_to_run, 'gen', comp_dir, '-q', '--check']) + if save_out_dir: + RemoveDir(save_out_dir) + shutil.move(comp_dir, save_out_dir) + + +def main(): + if len(sys.argv) < 3 or len(sys.argv) > 4: + print 'Usage: full_test.py /chrome/tree/at/762a25542878 rel_gn_path [clean]' + return 1 + + if len(sys.argv) == 4: + RemoveDir('out') + + subprocess.check_call([sys.executable, os.path.join('build', 'gen.py')]) + subprocess.check_call(['ninja', '-C', 'out']) + subprocess.check_call([os.path.join('out', 'gn_unittests')]) + orig_dir = os.getcwd() + + in_chrome_tree_gn = sys.argv[2] + our_gn = os.path.join(orig_dir, 'out', 'gn' + ('.exe' if IS_WIN else '')) + + os.chdir(sys.argv[1]) + + # Check in-tree vs. ours. Uses: + # - Chromium tree at 762a25542878 in argv[1] (this can be off by a bit, but + # is roughly when GN was moved out of the Chrome tree, so matches in case GN + # semantics/ordering change after that.) + # - relative path to argv[1] built gn binary in argv[2] + + # First, do a comparison to make sure the output between the two gn binaries + # actually matches. + print 'Confirming output matches...' + dir_a = os.path.join('out', 'a') + dir_b = os.path.join('out', 'b') + Trial(in_chrome_tree_gn, dir_a) + Trial(our_gn, dir_b) + subprocess.check_call(['diff', '-r', dir_a, dir_b]) + + # Then, some time trials. + TRIALS = 5 + print 'Comparing performance... (takes a while)' + time_a = timeit.timeit('Trial("%s")' % in_chrome_tree_gn, number=TRIALS, + setup='from __main__ import Trial') + time_b = timeit.timeit('Trial("%s")' % our_gn, number=TRIALS, + setup='from __main__ import Trial') + print 'In-tree gn avg: %.3fs' % (time_a / TRIALS) + print 'Our gn avg: %.3fs' % (time_b / TRIALS) + + return 0 + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/build/gen.py b/build/gen.py new file mode 100755 index 0000000..922bf46 --- /dev/null +++ b/build/gen.py @@ -0,0 +1,809 @@ +#!/usr/bin/env python +# Copyright 2014 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 build.ninja that will build GN.""" + +import contextlib +import errno +import optparse +import os +import platform +import re +import subprocess +import sys +import tempfile + +try: # py3 + from shlex import quote as shell_quote +except ImportError: # py2 + from pipes import quote as shell_quote + +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) +REPO_ROOT = os.path.dirname(SCRIPT_DIR) + + +class Platform(object): + """Represents a host/target platform.""" + def __init__(self, platform): + self._platform = platform + if self._platform is not None: + return + self._platform = sys.platform + if self._platform.startswith('linux'): + self._platform = 'linux' + elif self._platform.startswith('darwin'): + self._platform = 'darwin' + elif self._platform.startswith('mingw'): + self._platform = 'mingw' + elif self._platform.startswith('msys'): + self._platform = 'msys' + elif self._platform.startswith('win'): + self._platform = 'msvc' + elif self._platform.startswith('aix'): + self._platform = 'aix' + elif self._platform.startswith('fuchsia'): + self._platform = 'fuchsia' + elif self._platform.startswith('freebsd'): + self._platform = 'freebsd' + elif self._platform.startswith('netbsd'): + self._platform = 'netbsd' + elif self._platform.startswith('openbsd'): + self._platform = 'openbsd' + elif self._platform.startswith('haiku'): + self._platform = 'haiku' + elif self._platform.startswith('sunos'): + self._platform = 'solaris' + + @staticmethod + def known_platforms(): + return ['linux', 'darwin', 'mingw', 'msys', 'msvc', 'aix', 'fuchsia', 'freebsd', 'netbsd', 'openbsd', 'haiku', 'solaris'] + + def platform(self): + return self._platform + + def is_linux(self): + return self._platform == 'linux' + + def is_mingw(self): + return self._platform == 'mingw' + + def is_msys(self): + return self._platform == 'msys' + + def is_msvc(self): + return self._platform == 'msvc' + + def is_windows(self): + return self.is_mingw() or self.is_msvc() + + def is_darwin(self): + return self._platform == 'darwin' + + def is_aix(self): + return self._platform == 'aix' + + def is_haiku(self): + return self._platform == 'haiku' + + def is_solaris(self): + return self._platform == 'solaris' + + def is_posix(self): + return self._platform in ['linux', 'freebsd', 'darwin', 'aix', 'openbsd', 'haiku', 'solaris', 'msys', 'netbsd'] + + +def main(argv): + parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) + parser.add_option('-d', '--debug', action='store_true', + help='Do a debug build. Defaults to release build.') + parser.add_option('--platform', + help='target platform (' + + '/'.join(Platform.known_platforms()) + ')', + choices=Platform.known_platforms()) + parser.add_option('--host', + help='host platform (' + + '/'.join(Platform.known_platforms()) + ')', + choices=Platform.known_platforms()) + parser.add_option('--use-lto', action='store_true', + help='Enable the use of LTO') + parser.add_option('--use-icf', action='store_true', + help='Enable the use of Identical Code Folding') + parser.add_option('--no-last-commit-position', action='store_true', + help='Do not generate last_commit_position.h.') + parser.add_option('--out-path', + help='The path to generate the build files in.') + parser.add_option('--no-strip', action='store_true', + help='Don\'t strip release build. Useful for profiling.') + parser.add_option('--no-static-libstdc++', action='store_true', + default=False, dest='no_static_libstdcpp', + help='Don\'t link libstdc++ statically') + parser.add_option('--link-lib', + action='append', + metavar='LINK_LIB', + default=[], + dest='link_libs', + help=('Add a library to the final executable link. ' + + 'LINK_LIB must be the path to a static or shared ' + + 'library, or \'-l\' on POSIX systems. Can be ' + + 'used multiple times. Useful to link custom malloc ' + + 'or cpu profiling libraries.')) + options, args = parser.parse_args(argv) + + if args: + parser.error('Unrecognized command line arguments: %s.' % ', '.join(args)) + + platform = Platform(options.platform) + if options.host: + host = Platform(options.host) + else: + host = platform + + out_dir = options.out_path or os.path.join(REPO_ROOT, 'out') + if not os.path.isdir(out_dir): + os.makedirs(out_dir) + if not options.no_last_commit_position: + GenerateLastCommitPosition(host, + os.path.join(out_dir, 'last_commit_position.h')) + WriteGNNinja(os.path.join(out_dir, 'build.ninja'), platform, host, options) + return 0 + + +def GenerateLastCommitPosition(host, header): + ROOT_TAG = 'initial-commit' + describe_output = subprocess.check_output( + ['git', 'describe', 'HEAD', '--match', ROOT_TAG], shell=host.is_windows(), + cwd=REPO_ROOT) + mo = re.match(ROOT_TAG + '-(\d+)-g([0-9a-f]+)', describe_output.decode()) + if not mo: + raise ValueError( + 'Unexpected output from git describe when generating version header') + + contents = '''// Generated by build/gen.py. + +#ifndef OUT_LAST_COMMIT_POSITION_H_ +#define OUT_LAST_COMMIT_POSITION_H_ + +#define LAST_COMMIT_POSITION_NUM %s +#define LAST_COMMIT_POSITION "%s (%s)" + +#endif // OUT_LAST_COMMIT_POSITION_H_ +''' % (mo.group(1), mo.group(1), mo.group(2)) + + # Only write/touch this file if the commit position has changed. + old_contents = '' + if os.path.isfile(header): + with open(header, 'r') as f: + old_contents = f.read() + + if old_contents != contents: + with open(header, 'w') as f: + f.write(contents) + + +def WriteGenericNinja(path, static_libraries, executables, + cxx, ar, ld, platform, host, options, + cflags=[], ldflags=[], libflags=[], + include_dirs=[], solibs=[]): + args = ' -d' if options.debug else '' + for link_lib in options.link_libs: + args += ' --link-lib=' + shell_quote(link_lib) + + ninja_header_lines = [ + 'cxx = ' + cxx, + 'ar = ' + ar, + 'ld = ' + ld, + '', + 'rule regen', + ' command = %s ../build/gen.py%s' % (sys.executable, args), + ' description = Regenerating ninja files', + '', + 'build build.ninja: regen', + ' generator = 1', + ' depfile = build.ninja.d', + '', + ] + + + template_filename = os.path.join(SCRIPT_DIR, { + 'msvc': 'build_win.ninja.template', + 'mingw': 'build_linux.ninja.template', + 'msys': 'build_linux.ninja.template', + 'darwin': 'build_mac.ninja.template', + 'linux': 'build_linux.ninja.template', + 'freebsd': 'build_linux.ninja.template', + 'aix': 'build_aix.ninja.template', + 'openbsd': 'build_openbsd.ninja.template', + 'haiku': 'build_haiku.ninja.template', + 'solaris': 'build_linux.ninja.template', + 'netbsd': 'build_linux.ninja.template', + }[platform.platform()]) + + with open(template_filename) as f: + ninja_template = f.read() + + if platform.is_windows(): + executable_ext = '.exe' + library_ext = '.lib' + object_ext = '.obj' + else: + executable_ext = '' + library_ext = '.a' + object_ext = '.o' + + def escape_path_ninja(path): + return path.replace('$ ', '$$ ').replace(' ', '$ ').replace(':', '$:') + + def src_to_obj(path): + return escape_path_ninja('%s' % os.path.splitext(path)[0] + object_ext) + + def library_to_a(library): + return '%s%s' % (library, library_ext) + + ninja_lines = [] + def build_source(src_file, settings): + ninja_lines.extend([ + 'build %s: cxx %s' % (src_to_obj(src_file), + escape_path_ninja( + os.path.relpath( + os.path.join(REPO_ROOT, src_file), + os.path.dirname(path)))), + ' includes = %s' % ' '.join( + ['-I' + escape_path_ninja(dirname) for dirname in include_dirs]), + ' cflags = %s' % ' '.join(cflags), + ]) + + for library, settings in static_libraries.items(): + for src_file in settings['sources']: + build_source(src_file, settings) + + ninja_lines.append('build %s: alink_thin %s' % ( + library_to_a(library), + ' '.join([src_to_obj(src_file) for src_file in settings['sources']]))) + ninja_lines.append(' libflags = %s' % ' '.join(libflags)) + + + for executable, settings in executables.items(): + for src_file in settings['sources']: + build_source(src_file, settings) + + ninja_lines.extend([ + 'build %s%s: link %s | %s' % ( + executable, executable_ext, + ' '.join([src_to_obj(src_file) for src_file in settings['sources']]), + ' '.join([library_to_a(library) for library in settings['libs']])), + ' ldflags = %s' % ' '.join(ldflags), + ' solibs = %s' % ' '.join(solibs), + ' libs = %s' % ' '.join( + [library_to_a(library) for library in settings['libs']]), + ]) + + ninja_lines.append('') # Make sure the file ends with a newline. + + with open(path, 'w') as f: + f.write('\n'.join(ninja_header_lines)) + f.write(ninja_template) + f.write('\n'.join(ninja_lines)) + + with open(path + '.d', 'w') as f: + f.write('build.ninja: ' + + os.path.relpath(os.path.join(SCRIPT_DIR, 'gen.py'), + os.path.dirname(path)) + ' ' + + os.path.relpath(template_filename, os.path.dirname(path)) + '\n') + + +def WriteGNNinja(path, platform, host, options): + if platform.is_msvc(): + cxx = os.environ.get('CXX', 'cl.exe') + ld = os.environ.get('LD', 'link.exe') + ar = os.environ.get('AR', 'lib.exe') + elif platform.is_aix(): + cxx = os.environ.get('CXX', 'g++') + ld = os.environ.get('LD', 'g++') + ar = os.environ.get('AR', 'ar -X64') + elif platform.is_msys() or platform.is_mingw(): + cxx = os.environ.get('CXX', 'g++') + ld = os.environ.get('LD', 'g++') + ar = os.environ.get('AR', 'ar') + else: + cxx = os.environ.get('CXX', 'clang++') + ld = cxx + ar = os.environ.get('AR', 'ar') + + cflags = os.environ.get('CFLAGS', '').split() + cflags += os.environ.get('CXXFLAGS', '').split() + ldflags = os.environ.get('LDFLAGS', '').split() + libflags = os.environ.get('LIBFLAGS', '').split() + include_dirs = [ + os.path.relpath(os.path.join(REPO_ROOT, 'src'), os.path.dirname(path)), + '.', + ] + libs = [] + + if not platform.is_msvc(): + if options.debug: + cflags.extend(['-O0', '-g']) + else: + cflags.append('-DNDEBUG') + cflags.append('-O3') + if options.no_strip: + cflags.append('-g') + ldflags.append('-O3') + # Use -fdata-sections and -ffunction-sections to place each function + # or data item into its own section so --gc-sections can eliminate any + # unused functions and data items. + cflags.extend(['-fdata-sections', '-ffunction-sections']) + ldflags.extend(['-fdata-sections', '-ffunction-sections']) + if platform.is_darwin(): + ldflags.append('-Wl,-dead_strip') + elif not platform.is_aix() and not platform.is_solaris(): + # Garbage collection is done by default on aix. + ldflags.append('-Wl,--gc-sections') + + # Omit all symbol information from the output file. + if options.no_strip is None: + if platform.is_darwin(): + ldflags.append('-Wl,-S') + elif platform.is_aix(): + ldflags.append('-Wl,-s') + elif platform.is_solaris(): + ldflags.append('-Wl,--strip-all') + else: + ldflags.append('-Wl,-strip-all') + + # Enable identical code-folding. + if options.use_icf and not platform.is_darwin(): + ldflags.append('-Wl,--icf=all') + + if options.use_lto: + cflags.extend(['-flto', '-fwhole-program-vtables']) + ldflags.extend(['-flto', '-fwhole-program-vtables']) + + cflags.extend([ + '-D_FILE_OFFSET_BITS=64', + '-D__STDC_CONSTANT_MACROS', '-D__STDC_FORMAT_MACROS', + '-pthread', + '-pipe', + '-fno-exceptions', + '-fno-rtti', + '-fdiagnostics-color', + '-Wall', + '-Wextra', + '-Wno-unused-parameter', + '-std=c++17' + ]) + + if platform.is_linux() or platform.is_mingw() or platform.is_msys(): + ldflags.append('-Wl,--as-needed') + + if not options.no_static_libstdcpp: + ldflags.append('-static-libstdc++') + + if platform.is_mingw() or platform.is_msys(): + cflags.remove('-std=c++17') + cflags.extend([ + '-Wno-deprecated-copy', + '-Wno-implicit-fallthrough', + '-Wno-redundant-move', + '-Wno-unused-variable', + '-Wno-format', # Use of %llx, which is supported by _UCRT, false positive + '-Wno-strict-aliasing', # Dereferencing punned pointer + '-Wno-cast-function-type', # Casting FARPROC to RegDeleteKeyExPtr + '-std=gnu++17', + ]) + else: + # This is needed by libc++. + libs.append('-ldl') + elif platform.is_darwin(): + min_mac_version_flag = '-mmacosx-version-min=10.9' + cflags.append(min_mac_version_flag) + ldflags.append(min_mac_version_flag) + elif platform.is_aix(): + cflags.append('-maix64') + ldflags.append('-maix64') + elif platform.is_haiku(): + cflags.append('-fPIC') + cflags.extend(['-D_BSD_SOURCE']) + + if platform.is_posix() and not platform.is_haiku(): + ldflags.append('-pthread') + + if platform.is_mingw() or platform.is_msys(): + cflags.extend(['-DUNICODE', + '-DNOMINMAX', + '-DWIN32_LEAN_AND_MEAN', + '-DWINVER=0x0A00', + '-D_CRT_SECURE_NO_DEPRECATE', + '-D_SCL_SECURE_NO_DEPRECATE', + '-D_UNICODE', + '-D_WIN32_WINNT=0x0A00', + '-D_HAS_EXCEPTIONS=0' + ]) + elif platform.is_msvc(): + if not options.debug: + cflags.extend(['/O2', '/DNDEBUG', '/Zc:inline']) + ldflags.extend(['/OPT:REF']) + + if options.use_icf: + libflags.extend(['/OPT:ICF']) + if options.use_lto: + cflags.extend(['/GL']) + libflags.extend(['/LTCG']) + ldflags.extend(['/LTCG']) + + cflags.extend([ + '/DNOMINMAX', + '/DUNICODE', + '/DWIN32_LEAN_AND_MEAN', + '/DWINVER=0x0A00', + '/D_CRT_SECURE_NO_DEPRECATE', + '/D_SCL_SECURE_NO_DEPRECATE', + '/D_UNICODE', + '/D_WIN32_WINNT=0x0A00', + '/FS', + '/W4', + '/WX', + '/Zi', + '/wd4099', + '/wd4100', + '/wd4127', + '/wd4244', + '/wd4267', + '/wd4505', + '/wd4838', + '/wd4996', + '/std:c++17', + '/GR-', + '/D_HAS_EXCEPTIONS=0', + ]) + + ldflags.extend(['/DEBUG', '/MACHINE:x64']) + + static_libraries = { + 'base': {'sources': [ + 'src/base/command_line.cc', + 'src/base/environment.cc', + 'src/base/files/file.cc', + 'src/base/files/file_enumerator.cc', + 'src/base/files/file_path.cc', + 'src/base/files/file_path_constants.cc', + 'src/base/files/file_util.cc', + 'src/base/files/scoped_file.cc', + 'src/base/files/scoped_temp_dir.cc', + 'src/base/json/json_parser.cc', + 'src/base/json/json_reader.cc', + 'src/base/json/json_writer.cc', + 'src/base/json/string_escape.cc', + 'src/base/logging.cc', + 'src/base/md5.cc', + 'src/base/memory/ref_counted.cc', + 'src/base/memory/weak_ptr.cc', + 'src/base/sha1.cc', + 'src/base/strings/string_number_conversions.cc', + 'src/base/strings/string_split.cc', + 'src/base/strings/string_util.cc', + 'src/base/strings/string_util_constants.cc', + 'src/base/strings/stringprintf.cc', + 'src/base/strings/utf_string_conversion_utils.cc', + 'src/base/strings/utf_string_conversions.cc', + 'src/base/third_party/icu/icu_utf.cc', + 'src/base/timer/elapsed_timer.cc', + 'src/base/value_iterators.cc', + 'src/base/values.cc', + ]}, + 'gn_lib': {'sources': [ + 'src/gn/action_target_generator.cc', + 'src/gn/action_values.cc', + 'src/gn/analyzer.cc', + 'src/gn/args.cc', + 'src/gn/binary_target_generator.cc', + 'src/gn/build_settings.cc', + 'src/gn/builder.cc', + 'src/gn/builder_record.cc', + 'src/gn/bundle_data.cc', + 'src/gn/bundle_data_target_generator.cc', + 'src/gn/bundle_file_rule.cc', + 'src/gn/c_include_iterator.cc', + 'src/gn/c_substitution_type.cc', + 'src/gn/c_tool.cc', + 'src/gn/command_analyze.cc', + 'src/gn/command_args.cc', + 'src/gn/command_check.cc', + 'src/gn/command_clean.cc', + 'src/gn/command_clean_stale.cc', + 'src/gn/command_desc.cc', + 'src/gn/command_format.cc', + 'src/gn/command_gen.cc', + 'src/gn/command_help.cc', + 'src/gn/command_ls.cc', + 'src/gn/command_meta.cc', + 'src/gn/command_outputs.cc', + 'src/gn/command_path.cc', + 'src/gn/command_refs.cc', + 'src/gn/commands.cc', + 'src/gn/compile_commands_writer.cc', + 'src/gn/rust_project_writer.cc', + 'src/gn/config.cc', + 'src/gn/config_values.cc', + 'src/gn/config_values_extractors.cc', + 'src/gn/config_values_generator.cc', + 'src/gn/copy_target_generator.cc', + 'src/gn/create_bundle_target_generator.cc', + 'src/gn/deps_iterator.cc', + 'src/gn/desc_builder.cc', + 'src/gn/eclipse_writer.cc', + 'src/gn/err.cc', + 'src/gn/escape.cc', + 'src/gn/exec_process.cc', + 'src/gn/filesystem_utils.cc', + 'src/gn/file_writer.cc', + 'src/gn/frameworks_utils.cc', + 'src/gn/function_exec_script.cc', + 'src/gn/function_filter.cc', + 'src/gn/function_foreach.cc', + 'src/gn/function_forward_variables_from.cc', + 'src/gn/function_get_label_info.cc', + 'src/gn/function_get_path_info.cc', + 'src/gn/function_get_target_outputs.cc', + 'src/gn/function_process_file_template.cc', + 'src/gn/function_read_file.cc', + 'src/gn/function_rebase_path.cc', + 'src/gn/function_set_default_toolchain.cc', + 'src/gn/function_set_defaults.cc', + 'src/gn/function_template.cc', + 'src/gn/function_toolchain.cc', + 'src/gn/function_write_file.cc', + 'src/gn/functions.cc', + 'src/gn/functions_target.cc', + 'src/gn/general_tool.cc', + 'src/gn/generated_file_target_generator.cc', + 'src/gn/group_target_generator.cc', + 'src/gn/header_checker.cc', + 'src/gn/import_manager.cc', + 'src/gn/inherited_libraries.cc', + 'src/gn/input_conversion.cc', + 'src/gn/input_file.cc', + 'src/gn/input_file_manager.cc', + 'src/gn/item.cc', + 'src/gn/json_project_writer.cc', + 'src/gn/label.cc', + 'src/gn/label_pattern.cc', + 'src/gn/lib_file.cc', + 'src/gn/loader.cc', + 'src/gn/location.cc', + 'src/gn/metadata.cc', + 'src/gn/metadata_walk.cc', + 'src/gn/ninja_action_target_writer.cc', + 'src/gn/ninja_binary_target_writer.cc', + 'src/gn/ninja_build_writer.cc', + 'src/gn/ninja_bundle_data_target_writer.cc', + 'src/gn/ninja_c_binary_target_writer.cc', + 'src/gn/ninja_copy_target_writer.cc', + 'src/gn/ninja_create_bundle_target_writer.cc', + 'src/gn/ninja_generated_file_target_writer.cc', + 'src/gn/ninja_group_target_writer.cc', + 'src/gn/ninja_rust_binary_target_writer.cc', + 'src/gn/ninja_target_command_util.cc', + 'src/gn/ninja_target_writer.cc', + 'src/gn/ninja_toolchain_writer.cc', + 'src/gn/ninja_tools.cc', + 'src/gn/ninja_utils.cc', + 'src/gn/ninja_writer.cc', + 'src/gn/operators.cc', + 'src/gn/output_conversion.cc', + 'src/gn/output_file.cc', + 'src/gn/parse_node_value_adapter.cc', + 'src/gn/parse_tree.cc', + 'src/gn/parser.cc', + 'src/gn/path_output.cc', + 'src/gn/pattern.cc', + 'src/gn/pool.cc', + 'src/gn/qt_creator_writer.cc', + 'src/gn/runtime_deps.cc', + 'src/gn/rust_substitution_type.cc', + 'src/gn/rust_tool.cc', + 'src/gn/rust_values.cc', + 'src/gn/rust_values_generator.cc', + 'src/gn/rust_variables.cc', + 'src/gn/scheduler.cc', + 'src/gn/scope.cc', + 'src/gn/scope_per_file_provider.cc', + 'src/gn/settings.cc', + 'src/gn/setup.cc', + 'src/gn/source_dir.cc', + 'src/gn/source_file.cc', + 'src/gn/standard_out.cc', + 'src/gn/string_atom.cc', + 'src/gn/string_output_buffer.cc', + 'src/gn/string_utils.cc', + 'src/gn/substitution_list.cc', + 'src/gn/substitution_pattern.cc', + 'src/gn/substitution_type.cc', + 'src/gn/substitution_writer.cc', + 'src/gn/swift_values.cc', + 'src/gn/swift_values_generator.cc', + 'src/gn/swift_variables.cc', + 'src/gn/switches.cc', + 'src/gn/target.cc', + 'src/gn/target_generator.cc', + 'src/gn/template.cc', + 'src/gn/token.cc', + 'src/gn/tokenizer.cc', + 'src/gn/tool.cc', + 'src/gn/toolchain.cc', + 'src/gn/trace.cc', + 'src/gn/value.cc', + 'src/gn/value_extractors.cc', + 'src/gn/variables.cc', + 'src/gn/version.cc', + 'src/gn/visibility.cc', + 'src/gn/visual_studio_utils.cc', + 'src/gn/visual_studio_writer.cc', + 'src/gn/xcode_object.cc', + 'src/gn/xcode_writer.cc', + 'src/gn/xml_element_writer.cc', + 'src/util/exe_path.cc', + 'src/util/msg_loop.cc', + 'src/util/semaphore.cc', + 'src/util/sys_info.cc', + 'src/util/ticks.cc', + 'src/util/worker_pool.cc', + ]}, + } + + executables = { + 'gn': {'sources': [ 'src/gn/gn_main.cc' ], 'libs': []}, + + 'gn_unittests': { 'sources': [ + 'src/gn/action_target_generator_unittest.cc', + 'src/gn/analyzer_unittest.cc', + 'src/gn/args_unittest.cc', + 'src/gn/builder_unittest.cc', + 'src/gn/c_include_iterator_unittest.cc', + 'src/gn/command_format_unittest.cc', + 'src/gn/commands_unittest.cc', + 'src/gn/compile_commands_writer_unittest.cc', + 'src/gn/config_unittest.cc', + 'src/gn/config_values_extractors_unittest.cc', + 'src/gn/escape_unittest.cc', + 'src/gn/exec_process_unittest.cc', + 'src/gn/filesystem_utils_unittest.cc', + 'src/gn/file_writer_unittest.cc', + 'src/gn/frameworks_utils_unittest.cc', + 'src/gn/function_filter_unittest.cc', + 'src/gn/function_foreach_unittest.cc', + 'src/gn/function_forward_variables_from_unittest.cc', + 'src/gn/function_get_label_info_unittest.cc', + 'src/gn/function_get_path_info_unittest.cc', + 'src/gn/function_get_target_outputs_unittest.cc', + 'src/gn/function_process_file_template_unittest.cc', + 'src/gn/function_rebase_path_unittest.cc', + 'src/gn/function_template_unittest.cc', + 'src/gn/function_toolchain_unittest.cc', + 'src/gn/function_write_file_unittest.cc', + 'src/gn/functions_target_rust_unittest.cc', + 'src/gn/functions_target_unittest.cc', + 'src/gn/functions_unittest.cc', + 'src/gn/hash_table_base_unittest.cc', + 'src/gn/header_checker_unittest.cc', + 'src/gn/inherited_libraries_unittest.cc', + 'src/gn/input_conversion_unittest.cc', + 'src/gn/json_project_writer_unittest.cc', + 'src/gn/rust_project_writer_unittest.cc', + 'src/gn/rust_project_writer_helpers_unittest.cc', + 'src/gn/label_pattern_unittest.cc', + 'src/gn/label_unittest.cc', + 'src/gn/loader_unittest.cc', + 'src/gn/metadata_unittest.cc', + 'src/gn/metadata_walk_unittest.cc', + 'src/gn/ninja_action_target_writer_unittest.cc', + 'src/gn/ninja_binary_target_writer_unittest.cc', + 'src/gn/ninja_build_writer_unittest.cc', + 'src/gn/ninja_bundle_data_target_writer_unittest.cc', + 'src/gn/ninja_c_binary_target_writer_unittest.cc', + 'src/gn/ninja_copy_target_writer_unittest.cc', + 'src/gn/ninja_create_bundle_target_writer_unittest.cc', + 'src/gn/ninja_generated_file_target_writer_unittest.cc', + 'src/gn/ninja_group_target_writer_unittest.cc', + 'src/gn/ninja_rust_binary_target_writer_unittest.cc', + 'src/gn/ninja_target_command_util_unittest.cc', + 'src/gn/ninja_target_writer_unittest.cc', + 'src/gn/ninja_toolchain_writer_unittest.cc', + 'src/gn/operators_unittest.cc', + 'src/gn/output_conversion_unittest.cc', + 'src/gn/parse_tree_unittest.cc', + 'src/gn/parser_unittest.cc', + 'src/gn/path_output_unittest.cc', + 'src/gn/pattern_unittest.cc', + 'src/gn/runtime_deps_unittest.cc', + 'src/gn/scope_per_file_provider_unittest.cc', + 'src/gn/scope_unittest.cc', + 'src/gn/setup_unittest.cc', + 'src/gn/source_dir_unittest.cc', + 'src/gn/source_file_unittest.cc', + 'src/gn/string_atom_unittest.cc', + 'src/gn/string_output_buffer_unittest.cc', + 'src/gn/string_utils_unittest.cc', + 'src/gn/substitution_pattern_unittest.cc', + 'src/gn/substitution_writer_unittest.cc', + 'src/gn/target_unittest.cc', + 'src/gn/template_unittest.cc', + 'src/gn/test_with_scheduler.cc', + 'src/gn/test_with_scope.cc', + 'src/gn/tokenizer_unittest.cc', + 'src/gn/unique_vector_unittest.cc', + 'src/gn/value_unittest.cc', + 'src/gn/vector_utils_unittest.cc', + 'src/gn/version_unittest.cc', + 'src/gn/visibility_unittest.cc', + 'src/gn/visual_studio_utils_unittest.cc', + 'src/gn/visual_studio_writer_unittest.cc', + 'src/gn/xcode_object_unittest.cc', + 'src/gn/xml_element_writer_unittest.cc', + 'src/util/test/gn_test.cc', + ], 'libs': []}, + } + + if platform.is_posix(): + static_libraries['base']['sources'].extend([ + 'src/base/files/file_enumerator_posix.cc', + 'src/base/files/file_posix.cc', + 'src/base/files/file_util_posix.cc', + 'src/base/posix/file_descriptor_shuffle.cc', + 'src/base/posix/safe_strerror.cc', + ]) + + if platform.is_windows(): + static_libraries['base']['sources'].extend([ + 'src/base/files/file_enumerator_win.cc', + 'src/base/files/file_util_win.cc', + 'src/base/files/file_win.cc', + 'src/base/win/registry.cc', + 'src/base/win/scoped_handle.cc', + 'src/base/win/scoped_process_information.cc', + ]) + + if platform.is_msvc(): + libs.extend([ + 'advapi32.lib', + 'dbghelp.lib', + 'kernel32.lib', + 'ole32.lib', + 'shell32.lib', + 'user32.lib', + 'userenv.lib', + 'version.lib', + 'winmm.lib', + 'ws2_32.lib', + 'Shlwapi.lib', + ]) + else: + libs.extend([ + '-ladvapi32', + '-ldbghelp', + '-lkernel32', + '-lole32', + '-lshell32', + '-luser32', + '-luserenv', + '-lversion', + '-lwinmm', + '-lws2_32', + '-lshlwapi', + ]) + + + libs.extend(options.link_libs) + + # we just build static libraries that GN needs + executables['gn']['libs'].extend(static_libraries.keys()) + executables['gn_unittests']['libs'].extend(static_libraries.keys()) + + WriteGenericNinja(path, static_libraries, executables, cxx, ar, ld, + platform, host, options, cflags, ldflags, + libflags, include_dirs, libs) + + +if __name__ == '__main__': + sys.exit(main(sys.argv[1:])) diff --git a/docs/cross_compiles.md b/docs/cross_compiles.md new file mode 100644 index 0000000..ad71b94 --- /dev/null +++ b/docs/cross_compiles.md @@ -0,0 +1,126 @@ +# How GN handles cross-compiling + +## As a GN user + +GN has robust support for doing cross compiles and building things for +multiple architectures in a single build (e.g., to build some things to +run locally and some things to run on an embedded device). In fact, +there is no limit on the number of different architectures you can build +at once; the Chromium build uses at least four in some configurations. + +To start, GN has the concepts of a _host_ and a _target_. The host is +the platform that the build is run on, and the target is the platform +where the code will actually run (This is different from +[autotools](http://www.gnu.org/software/automake/manual/html_node/Cross_002dCompilation.html)' +terminology, but uses the more common terminology for cross +compiling). + +(Confusingly, GN also refers to each build artifact -- an executable, +library, etc. -- as a target. On this page, we will use "target" only to +refer to the system you want to run your code on, and use "rule" or some +other synonym to refer to a specific build artifact). + +When GN starts up, the `host_os` and `host_cpu` variables are set +automatically to match the operating system (they can be overridden in +args files, which can be useful in weird corner cases). The user can +specify that they want to do a cross-compile by setting either or both +of `target_os` and `target_cpu`; if they are not set, the build config +files will usually set them to the host's values, though the Chromium +build will set target\_cpu to "arm" if target\_os is set to "android"). + +So, for example, running on an x64 Linux machine: + +``` +gn gen out/Default +``` + +is equivalent to: + +``` +gn gen out/Default --args='target_os="linux" target_cpu="x64"' +``` + +To do an 32-bit ARM Android cross-compile, do: + +``` +gn gen out/Default --args='target_os="android"' +``` + +(We don't have to specify target\_cpu because of the conditionals +mentioned above). + +And, to do a 64-bit MIPS Chrome OS cross-compile: + +``` +gn gen out/Default --args='target_os="chromeos" target_cpu="mips64el"' +``` + +## As a BUILD.gn author + +If you are editing build files outside of the //build directory (i.e., +not directly working on toolchains, compiler configs, etc.), generally +you only need to worry about a few things: + +The `current_toolchain`, `current_cpu`, and `current_os` variables +reflect the settings that are **currently** in effect in a given rule. +The `is_linux`, `is_win` etc. variables are updated to reflect the +current settings, and changes to `cflags`, `ldflags` and so forth also +only apply to the current toolchain and the current thing being built. + +You can also refer to the `target_cpu` and `target_os` variables. This +is useful if you need to do something different on the host depending on +which target\_arch is requested; the values are constant across all +toolchains. You can do similar things for the `host_cpu` and `host_os` +variables, but should generally never need to. + +For the default toolchain, `target_cpu` and `current_cpu` are the same. For a +secondary toolchain, `current_cpu` is set based on the toolchain definition +and `target_cpu` remains the same. When writing rules, **`current_cpu` should +be used rather than `target_cpu` most of the time**. + +By default, dependencies listed in the `deps` variable of a rule use the +same (currently active) toolchain. You may specify a different toolchain +using the `foo(bar)` label notation as described in [the label section +of the reference doc](reference.md#Toolchains). + +Here's an example of when to use `target_cpu` vs `current_cpu`: + +``` +declare_args() { + # Applies only to toolchains targeting target_cpu. + sysroot = "" +} + +config("my_config") { + # Uses current_cpu because compile flags are toolchain-dependent. + if (current_cpu == "arm") { + defines = [ "CPU_IS_32_BIT" ] + } else { + defines = [ "CPU_IS_64_BIT" ] + } + # Compares current_cpu with target_cpu to see whether current_toolchain + # has the same architecture as target_toolchain. + if (sysroot != "" && current_cpu == target_cpu) { + cflags = [ + "-isysroot", + sysroot, + ] + } +} +``` + +## As a //build/config or //build/toolchain author + +The `default_toolchain` is declared in the `BUILDCONFIG.gn` file (in Google +projects this normally is in the `//build/config` directory). Usually the +`default_toolchain` should be the toolchain for the `target_os` and +`target_cpu`. The `current_toolchain` reflects the toolchain that is currently +in effect for a rule. + +Be sure you understand the differences between `host_cpu`, `target_cpu`, +`current_cpu`, and `toolchain_cpu` (and the os equivalents). The first +two are set as described above. You are responsible for making sure that +`current_cpu` is set appropriately in your toolchain definitions; if you +are using the stock templates like `gcc_toolchain` and `msvc_toolchain`, +that means you are responsible for making sure that `toolchain_cpu` and +`toolchain_os` are set as appropriate in the template invocations. diff --git a/docs/faq.md b/docs/faq.md new file mode 100644 index 0000000..699df3d --- /dev/null +++ b/docs/faq.md @@ -0,0 +1,58 @@ +# GN Frequently Asked Questions + +[TOC] + +## Where is the GN documentation? + +GN has extensive built-in help, so you can run `gn help`, but you can +also see all of the help on [the reference page](reference.md). See +also the [quick start](quick_start.md) guide and the [language and +operation details](language.md). + +## Can I generate XCode or Visual Studio projects? + +You can generate skeleton (or wrapper) projects for Xcode, Visual Studio, +QTCreator, and Eclipse that will list the files and targets in the +build, but use Ninja to do the actual build. You cannot generate "real" +projects that look like native ones like GYP could. + +Run `gn help gen` for more details. + +## How do I generate common build variants? + +In GN, args go with a build directory rather than being global in the +environment. To edit the args for your `out/Default` build directory: + +``` +gn args out/Default +``` + +You can set variables in that file: + + * The default is a debug build. To do a release build add + `is_debug = false` + * The default is a static build. To do a component build add + `is_component_build = true` + * The default is a developer build. To do an official build, set + `is_official_build = true` + * The default is Chromium branding. To do Chrome branding, set + `is_chrome_branded = true` + +## How do I do cross-compiles? + +GN has robust support for doing cross compiles and building things for +multiple architectures in a single build. + +See [GNCrossCompiles](cross_compiles.md) for more info. + +## Can I control what targets are built by default? + +Yes! If you create a group target called "default" in the top-level (root) +build file, i.e., "//:default", GN will tell Ninja to build that by +default, rather than building everything. + +## Are there any public presentations on GN? + +[There's at least one](https://docs.google.com/presentation/d/15Zwb53JcncHfEwHpnG_PoIbbzQ3GQi_cpujYwbpcbZo/edit?usp=sharing), from 2015. There +haven't been big changes since then apart from moving it to a standalone +repo, so it should still be relevant. diff --git a/docs/language.md b/docs/language.md new file mode 100644 index 0000000..137300a --- /dev/null +++ b/docs/language.md @@ -0,0 +1,535 @@ +# GN Language and Operation + +[TOC] + +## Introduction + +This page describes many of the language details and behaviors. + +### Use the built-in help! + +GN has an extensive built-in help system which provides a reference for +every function and built-in variable. This page is more high-level. + +``` +gn help +``` + +You can also see the +[slides](https://docs.google.com/presentation/d/15Zwb53JcncHfEwHpnG_PoIbbzQ3GQi_cpujYwbpcbZo/edit?usp=sharing) +from a March, 2016 introduction to GN. The speaker notes contain the full +content. + +### Design philosophy + + * Writing build files should not be a creative endeavour. Ideally two + people should produce the same buildfile given the same + requirements. There should be no flexibility unless it's absolutely + needed. As many things should be fatal errors as possible. + + * The definition should read more like code than rules. I don't want + to write or debug Prolog. But everybody on our team can write and + debug C++ and Python. + + * The build language should be opinionated as to how the build should + work. It should not necessarily be easy or even possible to express + arbitrary things. We should be changing source and tooling to make + the build simpler rather than making everything more complicated to + conform to external requirements (within reason). + + * Be like Blaze when it makes sense (see "Differences and similarities + to Blaze" below). + +## Language + +GN uses an extremely simple, dynamically typed language. The types are: + + * Boolean (`true`, `false`). + * 64-bit signed integers. + * Strings. + * Lists (of any other types). + * Scopes (sort of like a dictionary, only for built-in stuff). + +There are some built-in variables whose values depend on the current +environment. See `gn help` for more. + +There are purposefully many omissions in the language. There are no +user-defined function calls, for example (templates are the closest thing). As +per the above design philosophy, if you need this kind of thing you're probably +doing it wrong. + +The full grammar for language nerds is available in `gn help grammar`. + +### Strings + +Strings are enclosed in double-quotes and use backslash as the escape +character. The only escape sequences supported are: + + * `\"` (for literal quote) + * `\$` (for literal dollars sign) + * `\\` (for literal backslash) + +Any other use of a backslash is treated as a literal backslash. So, for +example, `\b` used in patterns does not need to be escaped, nor do most Windows +paths like `"C:\foo\bar.h"`. + +Simple variable substitution is supported via `$`, where the word +following the dollars sign is replaced with the value of the variable. +You can optionally surround the name with `{}` if there is not a +non-variable-name character to terminate the variable name. More complex +expressions are not supported, only variable name substitution. + +``` +a = "mypath" +b = "$a/foo.cc" # b -> "mypath/foo.cc" +c = "foo${a}bar.cc" # c -> "foomypathbar.cc" +``` + +You can encode 8-bit characters using "$0xFF" syntax, so a string with newlines +(hex 0A) would `"look$0x0Alike$0x0Athis"`. + +### Lists + +Aside from telling empty lists from non empty lists (`a == []`), there is no +way to get the length of a list. If you find yourself wanting to do this kind +of thing, you're trying to do too much work in the build. + +Lists support appending: + +``` +a = [ "first" ] +a += [ "second" ] # [ "first", "second" ] +a += [ "third", "fourth" ] # [ "first", "second", "third", "fourth" ] +b = a + [ "fifth" ] # [ "first", "second", "third", "fourth", "fifth" ] +``` + +Appending a list to another list appends the items in the second list +rather than appending the list as a nested member. + +You can remove items from a list: + +``` +a = [ "first", "second", "third", "first" ] +b = a - [ "first" ] # [ "second", "third" ] +a -= [ "second" ] # [ "first", "third", "first" ] +``` + +The - operator on a list searches for matches and removes all matching +items. Subtracting a list from another list will remove each item in the +second list. + +If no matching items are found, an error will be thrown, so you need to +know in advance that the item is there before removing it. Given that +there is no way to test for inclusion, the main use-case is to set up a +master list of files or flags, and to remove ones that don't apply to +the current build based on various conditions. + +Stylistically, prefer to only add to lists and have each source file or +dependency appear once. This is the opposite of the advice Chrome-team used to +give for GYP (GYP would prefer to list all files, and then remove the ones you +didn't want in conditionals). + +Lists support zero-based subscripting to extract values: + +``` +a = [ "first", "second", "third" ] +b = a[1] # -> "second" +``` + +The \[\] operator is read-only and can not be used to mutate the +list. The primary use-case of this is when an external script returns +several known values and you want to extract them. + +There are some cases where it's easy to overwrite a list when you mean +to append to it instead. To help catch this case, it is an error to +assign a nonempty list to a variable containing an existing nonempty +list. If you want to get around this restriction, first assign the +destination variable to the empty list. + +``` +a = [ "one" ] +a = [ "two" ] # Error: overwriting nonempty list with a nonempty list. +a = [] # OK +a = [ "two" ] # OK +``` + +Note that execution of the build script is done without intrinsic +knowledge of the meaning of the underlying data. This means that it +doesn't know that `sources` is a list of file names, for example. So if +you remove an item, it must match the literal string rather than +specifying a different name that will resolve to the same file name. + +### Conditionals + +Conditionals look like C: + +``` + if (is_linux || (is_win && target_cpu == "x86")) { + sources -= [ "something.cc" ] + } else if (...) { + ... + } else { + ... + } +``` + +You can use them in most places, even around entire targets if the +target should only be declared in certain circumstances. + +### Looping + +You can iterate over a list with `foreach`. This is discouraged. Most things +the build should do can normally be expressed without doing this, and if you +find it necessary it may be an indication you're doing too much work in the +metabuild. + +``` +foreach(i, mylist) { + print(i) # Note: i is a copy of each element, not a reference to it. +} +``` + +### Function calls + +Simple function calls look like most other languages: + +``` +print("hello, world") +assert(is_win, "This should only be executed on Windows") +``` + +Such functions are built-in and the user can not define new ones. + +Some functions take a block of code enclosed by `{ }` following them: + +``` +static_library("mylibrary") { + sources = [ "a.cc" ] +} +``` + +Most of these define targets. The user can define new functions like this +with the template mechanism discussed below. + +Precisely, this expression means that the block becomes an argument to the +function for the function to execute. Most of the block-style functions execute +the block and treat the resulting scope as a dictionary of variables to read. + +### Scoping and execution + +Files and function calls followed by `{ }` blocks introduce new scopes. Scopes +are nested. When you read a variable, the containing scopes will be searched in +reverse order until a matching name is found. Variable writes always go to the +innermost scope. + +There is no way to modify any enclosing scope other than the innermost +one. This means that when you define a target, for example, nothing you +do inside of the block will "leak out" into the rest of the file. + +`if`/`else`/`foreach` statements, even though they use `{ }`, do not introduce +a new scope so changes will persist outside of the statement. + +## Naming things + +### File and directory names + +File and directory names are strings and are interpreted as relative to +the current build file's directory. There are three possible forms: + +Relative names: + +``` +"foo.cc" +"src/foo.cc" +"../src/foo.cc" +``` + +Source-tree absolute names: + +``` +"//net/foo.cc" +"//base/test/foo.cc" +``` + +System absolute names (rare, normally used for include directories): + +``` +"/usr/local/include/" +"/C:/Program Files/Windows Kits/Include" +``` + +## Build configuration + +## Targets + +A target is a node in the build graph. It usually represents some kind +of executable or library file that will be generated. Targets depend on +other targets. The built-in target types (see `gn help ` for +more help) are: + + * `action`: Run a script to generate a file. + * `action_foreach`: Run a script once for each source file. + * `bundle_data`: Declare data to go into a Mac/iOS bundle. + * `create_bundle`: Creates a Mac/iOS bundle. + * `executable`: Generates an executable file. + * `group`: A virtual dependency node that refers to one or more other + targets. + * `shared_library`: A .dll or .so. + * `loadable_module`: A .dll or .so loadable only at runtime. + * `source_set`: A lightweight virtual static library (usually + preferrable over a real static library since it will build faster). + * `static_library`: A .lib or .a file (normally you'll want a + `source_set` instead). + +You can extend this to make custom target types using templates (see below). In +Chrome some of the more commonly-used templates are: + + * `component`: Either a source set or shared library, depending on the + build type. + * `test`: A test executable. On mobile this will create the appropriate + native app type for tests. + * `app`: Executable or Mac/iOS application. + * `android_apk`: Make an APK. There are a _lot_ of other Android ones, see + `//build/config/android/rules.gni`. + +## Configs + +Configs are named objects that specify sets of flags, include +directories, and defines. They can be applied to a target and pushed to +dependent targets. + +To define a config: + +``` +config("myconfig") { + includes = [ "src/include" ] + defines = [ "ENABLE_DOOM_MELON" ] +} +``` + +To apply a config to a target: + +``` +executable("doom_melon") { + configs = [ ":myconfig" ] +} +``` + +It is common for the build config file to specify target defaults that +set a default list of configs. Targets can add or remove to this list as +needed. So in practice you would usually use `configs += ":myconfig"` to +append to the list of defaults. + +See `gn help config` for more information about how configs are declared +and applied. + +### Public configs + +A target can apply settings to other targets that depend on it. The most +common example is a third party target that requires some defines or +include directories for its headers to compile properly. You want these +settings to apply both to the compile of the third party library itself, +as well as all targets that use the library. + +To do this, you write a config with the settings you want to apply: + +``` +config("my_external_library_config") { + includes = "." + defines = [ "DISABLE_JANK" ] +} +``` + +Then this config is added to the target as a "public" config. It will +apply both to the target as well as targets that directly depend on it. + +``` +shared_library("my_external_library") { + ... + # Targets that depend on this get this config applied. + public_configs = [ ":my_external_library_config" ] +} +``` + +Dependent targets can in turn forward this up the dependency tree +another level by adding your target as a "public" dependency. + +``` +static_library("intermediate_library") { + ... + # Targets that depend on this one also get the configs from "my external library". + public_deps = [ ":my_external_library" ] +} +``` + +A target can forward a config to all dependents until a link boundary is +reached by setting it as an `all_dependent_config`. This is strongly +discouraged as it can spray flags and defines over more of the build than +necessary. Instead, use public_deps to control which flags apply where. + +In Chrome, prefer the build flag header system (`build/buildflag_header.gni`) +for defines which prevents most screw-ups with compiler defines. + +## Templates + +Templates are GN's primary way to re-use code. Typically, a template +would expand to one or more other target types. + +``` +# Declares a script that compiles IDL files to source, and then compiles those +# source files. +template("idl") { + # Always base helper targets on target_name so they're unique. Target name + # will be the string passed as the name when the template is invoked. + idl_target_name = "${target_name}_generate" + action_foreach(idl_target_name) { + ... + } + + # Your template should always define a target with the name target_name. + # When other targets depend on your template invocation, this will be the + # destination of that dependency. + source_set(target_name) { + ... + deps = [ ":$idl_target_name" ] # Require the sources to be compiled. + } +} +``` + +Typically your template definition would go in a `.gni` file and users +would import that file to see the template definition: + +``` +import("//tools/idl_compiler.gni") + +idl("my_interfaces") { + sources = [ "a.idl", "b.idl" ] +} +``` + +Declaring a template creates a closure around the variables in scope at +that time. When the template is invoked, the magic variable `invoker` is +used to read variables out of the invoking scope. The template would +generally copy the values its interested in into its own scope: + +``` +template("idl") { + source_set(target_name) { + sources = invoker.sources + } +} +``` + +The current directory when a template executes will be that of the +invoking build file rather than the template source file. This is so +files passed in from the template invoker will be correct (this +generally accounts for most file handling in a template). However, if +the template has files itself (perhaps it generates an action that runs +a script), you will want to use absolute paths ("//foo/...") to refer to +these files to account for the fact that the current directory will be +unpredictable during invocation. See `gn help template` for more +information and more complete examples. + +## Other features + +### Imports + +You can import `.gni` files into the current scope with the `import` +function. This is _not_ an include in the C++ sense. The imported file is +executed independently and the resulting scope is copied into the current file +(C++ executes the included file in the current context of when the +include directive appeared). This allows the results of the import to be +cached, and also prevents some of the more "creative" uses of includes like +multiply-included files. + +Typically, a `.gni` would define build arguments and templates. See `gn +help import` for more. + +Your `.gni` file can define temporary variables that are not exported files +that include it by using a preceding underscore in the name like `_this`. + +### Path processing + +Often you will want to make a file name or a list of file names relative +to a different directory. This is especially common when running +scripts, which are executed with the build output directory as the +current directory, while build files usually refer to files relative to +their containing directory. + +You can use `rebase_path` to convert directories. See `gn help +rebase_path` for more help and examples. Typical usage to convert a file +name relative to the current directory to be relative to the root build +directory would be: ``` new_paths = rebase_path("myfile.c", +root_build_dir) ``` + +### Patterns + +Patterns are used to generate the output file names for a given set of +inputs for custom target types, and to automatically remove files from +the list values (see `gn help filter_include` and `gn help filter_exclude`). + +They are like simple regular expressions. See `gn help label_pattern` +for more. + +### Executing scripts + +There are two ways to execute scripts. All external scripts in GN are in +Python. The first way is as a build step. Such a script would take some +input and generate some output as part of the build. Targets that invoke +scripts are declared with the "action" target type (see `gn help +action`). + +The second way to execute scripts is synchronously during build file +execution. This is necessary in some cases to determine the set of files +to compile, or to get certain system configurations that the build file +might depend on. The build file can read the stdout of the script and +act on it in different ways. + +Synchronous script execution is done by the `exec_script` function (see +`gn help exec_script` for details and examples). Because synchronously +executing a script requires that the current buildfile execution be +suspended until a Python process completes execution, relying on +external scripts is slow and should be minimized. + +To prevent abuse, files permitted to call `exec_script` can be whitelisted in +the toplevel `.gn` file. Chrome does this to require additional code review +for such additions. See `gn help dotfile`. + +You can synchronously read and write files which is discouraged but +occasionally necessary when synchronously running scripts. The typical use-case +would be to pass a list of file names longer than the command-line limits of +the current platform. See `gn help read_file` and `gn help write_file` for how +to read and write files. These functions should be avoided if at all possible. + +Actions that exceed command-line length limits can use response files to +get around this limitation without synchronously writing files. See +`gn help response_file_contents`. + +# Differences and similarities to Blaze + +Blaze is Google's internal build system, now publicly released as +[Bazel](http://bazel.io/). It has inspired a number of other systems such as +[Pants](http://www.pantsbuild.org/) and [Buck](http://facebook.github.io/buck/). + +In Google's homogeneous environment, the need for conditionals is very +low and they can get by with a few hacks (`abi_deps`). Chrome uses +conditionals all over the place and the need to add these is the main +reason for the files looking different. + +GN also adds the concept of "configs" to manage some of the trickier +dependency and configuration problems which likewise don't arise on the +server. Blaze has a concept of a "configuration" which is like a GN +toolchain, but built into the tool itself. The way that toolchains work +in GN is a result of trying to separate this concept out into the build +files in a clean way. + +GN keeps some GYP concept like "all dependent" settings which work a bit +differently in Blaze. This is partially to make conversion from the existing +GYP code easier, and the GYP constructs generally offer more fine-grained +control (which is either good or bad, depending on the situation). + +GN also uses GYP names like "sources" instead of "srcs" since +abbreviating this seems needlessly obscure, although it uses Blaze's +"deps" since "dependencies" is so hard to type. Chromium also compiles +multiple languages in one target so specifying the language type on the +target name prefix was dropped (e.g. from `cc_library`). diff --git a/docs/quick_start.md b/docs/quick_start.md new file mode 100644 index 0000000..fc99e86 --- /dev/null +++ b/docs/quick_start.md @@ -0,0 +1,344 @@ +# GN Quick Start guide + +[TOC] + +## Running GN + +You just run `gn` from the command line. For large projects, GN is versioned +and distributed with the source checkout. + + * For Chromium and Chromium-based projects, there is a script in + `depot_tools`, which is presumably in your PATH, with this name. The script + will find the binary in the source tree containing the current directory and + run it. + + * For Fuchsia in-tree development, run `fx gn ...` which will find the right + GN binary and run it with the given arguments. + + * For other projects, see your project's documentation. + +## Setting up a build + +Unlike some other build systems, with GN you set up your own build directories +with the settings you want. This lets you maintain as many different builds in +parallel as you need. + +Once you set up a build directory, the Ninja files will be automatically +regenerated if they're out of date when you build in that directory so you +should not have to re-run GN. + +To make a build directory: + +``` +gn gen out/my_build +``` + +## Passing build arguments + +Set build arguments on your build directory by running: + +``` +gn args out/my_build +``` + +This will bring up an editor. Type build args into that file like this: + +``` +is_component_build = true +is_debug = false +``` + +The available variables will depend on your build (this example is from +Chromium). You can see the list of available arguments and their default values +by typing + +``` +gn args --list out/my_build +``` + +on the command line. Note that you have to specify the build directory +for this command because the available arguments can change according +to the build. + +Chrome developers can also read the [Chrome-specific build +configuration](http://www.chromium.org/developers/gn-build-configuration) +instructions for more information. + +## Cross-compiling to a target OS or architecture + +Run `gn args out/Default` (substituting your build directory as needed) and +add one or more of the following lines for common cross-compiling options. + +``` +target_os = "chromeos" +target_os = "android" + +target_cpu = "arm" +target_cpu = "x86" +target_cpu = "x64" +``` + +See [GN cross compiles](cross_compiles.md) for more info. + +## Step-by-step + +### Adding a build file + +Go to the directory `examples/simple_build`. This is the root of a minimal GN +repository. + +In that directory there is a `tutorial` directory. There is already a +`tutorial.cc` file that's not hooked up to the build. Create a new `BUILD.gn` +file in that directory for our new target. + +``` +executable("tutorial") { + sources = [ + "tutorial.cc", + ] +} +``` + +Now we just need to tell the build about this new target. Open the `BUILD.gn` +file in the parent (`simple_build`) directory. GN starts by loading this root +file, and then loads all dependencies ourward from here, so we just need to add +a reference to our new target from this file. + +You could add our new target as a dependency from one of the existing targets in +the `simple_build/BUILD.gn` file, but it usually doesn't make a lot of sense to +have an executable as a depdency of another executable (they can't be linked). +So let's make a "tools" group. In GN, a "group" is just a collection of +dependencies that's not complied or linked: + +``` +group("tools") { + deps = [ + # This will expand to the name "//tutorial:tutorial" which is the full name + # of our new target. Run "gn help labels" for more. + "//tutorial", + ] +} +``` + +### Testing your addition + +From the command line in the `simple_build` directory: + +``` +gn gen out +ninja -C out tutorial +out/tutorial +``` + +You should see "Hello, world." output to the console. + +Side note: GN encourages target names for static libraries that aren't globally +unique. To build one of these, you can pass the label with its path (but no leading +"//") to ninja: + +``` +ninja -C out some/path/to/target:my_target +``` + +### Declaring dependencies + +Let's look at the targets defined in +[examples/simple_build/BUILD.gn](../examples/simple_build/BUILD.gn). There is a +static library that defines one function, `GetStaticText()`: + +``` +static_library("hello_static") { + sources = [ + "hello_static.cc", + "hello_static.h", + ] +} +``` + +There is also a shared library that defines one function `GetSharedText()`: + +``` +shared_library("hello_shared") { + sources = [ + "hello_shared.cc", + "hello_shared.h", + ] + + defines = [ "HELLO_SHARED_IMPLEMENTATION" ] +} +``` + +This also illustrates how to set preprocessor defines for a target. To set more +than one or to assign values, use this form: + +``` +defines = [ + "HELLO_SHARED_IMPLEMENTATION", + "ENABLE_DOOM_MELON=0", +] +``` + +Now let's look at the executable that depends on these two libraries: + +``` +executable("hello") { + sources = [ + "hello.cc", + ] + + deps = [ + ":hello_shared", + ":hello_static", + ] +} +``` + +This executable includes one source file and depends on the previous +two libraries. Labels starting with a colon refer to a target with that name in +the current BUILD.gn file. + +### Test the binary + +From the command line in the `simple_build` directory: + +``` +ninja -C out hello +out/hello +``` + +Note that you **didn't** need to re-run GN. GN will automatically rebuild +the ninja files when any build file has changed. You know this happens +when ninja prints `[1/1] Regenerating ninja files` at the beginning of +execution. + +### Putting settings in a config + +Users of a library often need compiler flags, defines, and include directories +applied to them. To do this, put all such settings into a "config" which is a +named collection of settings (but not sources or dependencies): + +``` +config("my_lib_config") { + defines = [ "ENABLE_DOOM_MELON" ] + include_dirs = [ "//third_party/something" ] +} +``` + +To apply a config's settings to a target, add it to the `configs` list: + +``` +static_library("hello_shared") { + ... + # Note "+=" here is usually required, see "default configs" below. + configs += [ + ":my_lib_config", + ] +} +``` + +A config can be applied to all targets that depend on the current one by putting +its label in the `public_configs` list: + +``` +static_library("hello_shared") { + ... + public_configs = [ + ":my_lib_config", + ] +} +``` + +The `public_configs` also applies to the current target, so there's no need to +list a config in both places. + +### Default configs + +The build configuration will set up some settings that apply to every target by +default. These will normally be set as a default list of configs. You can see +this using the "print" command which is useful for debugging: + +``` +executable("hello") { + print(configs) +} +``` + +Running GN will print something like: + +``` +$ gn gen out +["//build:compiler_defaults", "//build:executable_ldconfig"] +Done. Made 5 targets from 5 files in 9ms +``` + +Targets can modify this list to change their defaults. For example, the build +setup might turn off exceptions by default by adding a `no_exceptions` config, +but a target might re-enable them by replacing it with a different one: + +``` +executable("hello") { + ... + configs -= [ "//build:no_exceptions" ] # Remove global default. + configs += [ "//build:exceptions" ] # Replace with a different one. +} +``` + +Our print command from above could also be expressed using string interpolation. +This is a way to convert values to strings. It uses the symbol "$" to refer to a +variable: + +``` +print("The configs for the target $target_name are $configs") +``` + +## Add a new build argument + +You declare which arguments you accept and specify default values via +`declare_args`. + +``` +declare_args() { + enable_teleporter = true + enable_doom_melon = false +} +``` + +See `gn help buildargs` for an overview of how this works. +See `gn help declare_args` for specifics on declaring them. + +It is an error to declare a given argument more than once in a given scope, so +care should be used in scoping and naming arguments. + +## Don't know what's going on? + +You can run GN in verbose mode to see lots of messages about what it's +doing. Use `-v` for this. + +### The "desc" command + +You can run `gn desc ` to get information about +a given target: + +``` +gn desc out/Default //foo/bar:say_hello +``` + +will print out lots of exciting information. You can also print just one +section. Lets say you wanted to know where your `TWO_PEOPLE` define +came from on the `say_hello` target: + +``` +> gn desc out/Default //foo/bar:say_hello defines --blame +...lots of other stuff omitted... + From //foo/bar:hello_config + (Added by //foo/bar/BUILD.gn:12) + TWO_PEOPLE +``` + +Another particularly interesting variation: + +``` +gn desc out/Default //base:base_i18n deps --tree +``` + +See `gn help desc` for more. diff --git a/docs/reference.md b/docs/reference.md new file mode 100644 index 0000000..ec19bfd --- /dev/null +++ b/docs/reference.md @@ -0,0 +1,7818 @@ +# GN Reference + +*This page is automatically generated from* `gn help --markdown all`. + +## Contents + +* [Commands](#commands) + * [analyze: Analyze which targets are affected by a list of files.](#cmd_analyze) + * [args: Display or configure arguments declared by the build.](#cmd_args) + * [check: Check header dependencies.](#cmd_check) + * [clean: Cleans the output directory.](#cmd_clean) + * [clean_stale: Cleans the stale output files from the output directory.](#cmd_clean_stale) + * [desc: Show lots of insightful information about a target or config.](#cmd_desc) + * [format: Format .gn files.](#cmd_format) + * [gen: Generate ninja files.](#cmd_gen) + * [help: Does what you think.](#cmd_help) + * [ls: List matching targets.](#cmd_ls) + * [meta: List target metadata collection results.](#cmd_meta) + * [outputs: Which files a source/target make.](#cmd_outputs) + * [path: Find paths between two targets.](#cmd_path) + * [refs: Find stuff referencing a target or file.](#cmd_refs) +* [Target declarations](#targets) + * [action: Declare a target that runs a script a single time.](#func_action) + * [action_foreach: Declare a target that runs a script over a set of files.](#func_action_foreach) + * [bundle_data: [iOS/macOS] Declare a target without output.](#func_bundle_data) + * [copy: Declare a target that copies files.](#func_copy) + * [create_bundle: [iOS/macOS] Build an iOS or macOS bundle.](#func_create_bundle) + * [executable: Declare an executable target.](#func_executable) + * [generated_file: Declare a generated_file target.](#func_generated_file) + * [group: Declare a named group of targets.](#func_group) + * [loadable_module: Declare a loadable module target.](#func_loadable_module) + * [rust_library: Declare a Rust library target.](#func_rust_library) + * [rust_proc_macro: Declare a Rust procedural macro target.](#func_rust_proc_macro) + * [shared_library: Declare a shared library target.](#func_shared_library) + * [source_set: Declare a source set target.](#func_source_set) + * [static_library: Declare a static library target.](#func_static_library) + * [target: Declare an target with the given programmatic type.](#func_target) +* [Buildfile functions](#functions) + * [assert: Assert an expression is true at generation time.](#func_assert) + * [config: Defines a configuration object.](#func_config) + * [declare_args: Declare build arguments.](#func_declare_args) + * [defined: Returns whether an identifier is defined.](#func_defined) + * [exec_script: Synchronously run a script and return the output.](#func_exec_script) + * [filter_exclude: Remove values that match a set of patterns.](#func_filter_exclude) + * [filter_include: Remove values that do not match a set of patterns.](#func_filter_include) + * [foreach: Iterate over a list.](#func_foreach) + * [forward_variables_from: Copies variables from a different scope.](#func_forward_variables_from) + * [get_label_info: Get an attribute from a target's label.](#func_get_label_info) + * [get_path_info: Extract parts of a file or directory name.](#func_get_path_info) + * [get_target_outputs: [file list] Get the list of outputs from a target.](#func_get_target_outputs) + * [getenv: Get an environment variable.](#func_getenv) + * [import: Import a file into the current scope.](#func_import) + * [not_needed: Mark variables from scope as not needed.](#func_not_needed) + * [pool: Defines a pool object.](#func_pool) + * [print: Prints to the console.](#func_print) + * [process_file_template: Do template expansion over a list of files.](#func_process_file_template) + * [read_file: Read a file into a variable.](#func_read_file) + * [rebase_path: Rebase a file or directory to another location.](#func_rebase_path) + * [set_default_toolchain: Sets the default toolchain name.](#func_set_default_toolchain) + * [set_defaults: Set default values for a target type.](#func_set_defaults) + * [set_sources_assignment_filter: Deprecated feature.](#func_set_sources_assignment_filter) + * [split_list: Splits a list into N different sub-lists.](#func_split_list) + * [string_join: Concatenates a list of strings with a separator.](#func_string_join) + * [string_replace: Replaces substring in the given string.](#func_string_replace) + * [string_split: Split string into a list of strings.](#func_string_split) + * [template: Define a template rule.](#func_template) + * [tool: Specify arguments to a toolchain tool.](#func_tool) + * [toolchain: Defines a toolchain.](#func_toolchain) + * [write_file: Write a file to disk.](#func_write_file) +* [Built-in predefined variables](#predefined_variables) + * [current_cpu: [string] The processor architecture of the current toolchain.](#var_current_cpu) + * [current_os: [string] The operating system of the current toolchain.](#var_current_os) + * [current_toolchain: [string] Label of the current toolchain.](#var_current_toolchain) + * [default_toolchain: [string] Label of the default toolchain.](#var_default_toolchain) + * [gn_version: [number] The version of gn.](#var_gn_version) + * [host_cpu: [string] The processor architecture that GN is running on.](#var_host_cpu) + * [host_os: [string] The operating system that GN is running on.](#var_host_os) + * [invoker: [string] The invoking scope inside a template.](#var_invoker) + * [python_path: [string] Absolute path of Python.](#var_python_path) + * [root_build_dir: [string] Directory where build commands are run.](#var_root_build_dir) + * [root_gen_dir: [string] Directory for the toolchain's generated files.](#var_root_gen_dir) + * [root_out_dir: [string] Root directory for toolchain output files.](#var_root_out_dir) + * [target_cpu: [string] The desired cpu architecture for the build.](#var_target_cpu) + * [target_gen_dir: [string] Directory for a target's generated files.](#var_target_gen_dir) + * [target_name: [string] The name of the current target.](#var_target_name) + * [target_os: [string] The desired operating system for the build.](#var_target_os) + * [target_out_dir: [string] Directory for target output files.](#var_target_out_dir) +* [Variables you set in targets](#target_variables) + * [aliased_deps: [scope] Set of crate-dependency pairs.](#var_aliased_deps) + * [all_dependent_configs: [label list] Configs to be forced on dependents.](#var_all_dependent_configs) + * [allow_circular_includes_from: [label list] Permit includes from deps.](#var_allow_circular_includes_from) + * [arflags: [string list] Arguments passed to static_library archiver.](#var_arflags) + * [args: [string list] Arguments passed to an action.](#var_args) + * [asmflags: [string list] Flags passed to the assembler.](#var_asmflags) + * [assert_no_deps: [label pattern list] Ensure no deps on these targets.](#var_assert_no_deps) + * [bridge_header: [string] Path to C/Objective-C compatibility header.](#var_bridge_header) + * [bundle_contents_dir: Expansion of {{bundle_contents_dir}} in create_bundle.](#var_bundle_contents_dir) + * [bundle_deps_filter: [label list] A list of labels that are filtered out.](#var_bundle_deps_filter) + * [bundle_executable_dir: Expansion of {{bundle_executable_dir}} in create_bundle](#var_bundle_executable_dir) + * [bundle_resources_dir: Expansion of {{bundle_resources_dir}} in create_bundle.](#var_bundle_resources_dir) + * [bundle_root_dir: Expansion of {{bundle_root_dir}} in create_bundle.](#var_bundle_root_dir) + * [cflags: [string list] Flags passed to all C compiler variants.](#var_cflags) + * [cflags_c: [string list] Flags passed to the C compiler.](#var_cflags_c) + * [cflags_cc: [string list] Flags passed to the C++ compiler.](#var_cflags_cc) + * [cflags_objc: [string list] Flags passed to the Objective C compiler.](#var_cflags_objc) + * [cflags_objcc: [string list] Flags passed to the Objective C++ compiler.](#var_cflags_objcc) + * [check_includes: [boolean] Controls whether a target's files are checked.](#var_check_includes) + * [code_signing_args: [string list] Arguments passed to code signing script.](#var_code_signing_args) + * [code_signing_outputs: [file list] Output files for code signing step.](#var_code_signing_outputs) + * [code_signing_script: [file name] Script for code signing.](#var_code_signing_script) + * [code_signing_sources: [file list] Sources for code signing step.](#var_code_signing_sources) + * [complete_static_lib: [boolean] Links all deps into a static library.](#var_complete_static_lib) + * [configs: [label list] Configs applying to this target or config.](#var_configs) + * [contents: Contents to write to file.](#var_contents) + * [crate_name: [string] The name for the compiled crate.](#var_crate_name) + * [crate_root: [string] The root source file for a binary or library.](#var_crate_root) + * [crate_type: [string] The type of linkage to use on a shared_library.](#var_crate_type) + * [data: [file list] Runtime data file dependencies.](#var_data) + * [data_deps: [label list] Non-linked dependencies.](#var_data_deps) + * [data_keys: [string list] Keys from which to collect metadata.](#var_data_keys) + * [defines: [string list] C preprocessor defines.](#var_defines) + * [depfile: [string] File name for input dependencies for actions.](#var_depfile) + * [deps: [label list] Private linked dependencies.](#var_deps) + * [externs: [scope] Set of Rust crate-dependency pairs.](#var_externs) + * [framework_dirs: [directory list] Additional framework search directories.](#var_framework_dirs) + * [frameworks: [name list] Name of frameworks that must be linked.](#var_frameworks) + * [friend: [label pattern list] Allow targets to include private headers.](#var_friend) + * [include_dirs: [directory list] Additional include directories.](#var_include_dirs) + * [inputs: [file list] Additional compile-time dependencies.](#var_inputs) + * [ldflags: [string list] Flags passed to the linker.](#var_ldflags) + * [lib_dirs: [directory list] Additional library directories.](#var_lib_dirs) + * [libs: [string list] Additional libraries to link.](#var_libs) + * [metadata: [scope] Metadata of this target.](#var_metadata) + * [module_name: [string] The name for the compiled module.](#var_module_name) + * [output_conversion: Data format for generated_file targets.](#var_output_conversion) + * [output_dir: [directory] Directory to put output file in.](#var_output_dir) + * [output_extension: [string] Value to use for the output's file extension.](#var_output_extension) + * [output_name: [string] Name for the output file other than the default.](#var_output_name) + * [output_prefix_override: [boolean] Don't use prefix for output name.](#var_output_prefix_override) + * [outputs: [file list] Output files for actions and copy targets.](#var_outputs) + * [partial_info_plist: [filename] Path plist from asset catalog compiler.](#var_partial_info_plist) + * [pool: [string] Label of the pool used by the action.](#var_pool) + * [precompiled_header: [string] Header file to precompile.](#var_precompiled_header) + * [precompiled_header_type: [string] "gcc" or "msvc".](#var_precompiled_header_type) + * [precompiled_source: [file name] Source file to precompile.](#var_precompiled_source) + * [product_type: [string] Product type for Xcode projects.](#var_product_type) + * [public: [file list] Declare public header files for a target.](#var_public) + * [public_configs: [label list] Configs applied to dependents.](#var_public_configs) + * [public_deps: [label list] Declare public dependencies.](#var_public_deps) + * [rebase: [boolean] Rebase collected metadata as files.](#var_rebase) + * [response_file_contents: [string list] Contents of .rsp file for actions.](#var_response_file_contents) + * [script: [file name] Script file for actions.](#var_script) + * [sources: [file list] Source files for a target.](#var_sources) + * [swiftflags: [string list] Flags passed to the swift compiler.](#var_swiftflags) + * [testonly: [boolean] Declares a target must only be used for testing.](#var_testonly) + * [visibility: [label list] A list of labels that can depend on a target.](#var_visibility) + * [walk_keys: [string list] Key(s) for managing the metadata collection walk.](#var_walk_keys) + * [weak_frameworks: [name list] Name of frameworks that must be weak linked.](#var_weak_frameworks) + * [write_runtime_deps: Writes the target's runtime_deps to the given path.](#var_write_runtime_deps) + * [xcasset_compiler_flags: [string list] Flags passed to xcassets compiler](#var_xcasset_compiler_flags) + * [xcode_extra_attributes: [scope] Extra attributes for Xcode projects.](#var_xcode_extra_attributes) + * [xcode_test_application_name: [string] Name for Xcode test target.](#var_xcode_test_application_name) +* [Other help topics](#other) + * all: Print all the help at once + * [buildargs: How build arguments work.](#buildargs) + * [dotfile: Info about the toplevel .gn file.](#dotfile) + * [execution: Build graph and execution overview.](#execution) + * [grammar: Language and grammar for GN build files.](#grammar) + * [input_conversion: Processing input from exec_script and read_file.](#io_conversion) + * [file_pattern: Matching more than one file.](#file_pattern) + * [label_pattern: Matching more than one label.](#label_pattern) + * [labels: About labels.](#labels) + * [metadata_collection: About metadata and its collection.](#metadata_collection) + * [ninja_rules: How Ninja build rules are named.](#ninja_rules) + * [nogncheck: Annotating includes for checking.](#nogncheck) + * [output_conversion: Specifies how to transform a value to output.](#io_conversion) + * [runtime_deps: How runtime dependency computation works.](#runtime_deps) + * [source_expansion: Map sources to outputs for scripts.](#source_expansion) + * [switches: Show available command-line switches.](#switch_list) + +## Commands + +### **gn analyze <out_dir> <input_path> <output_path>** + +``` + Analyze which targets are affected by a list of files. + + This command takes three arguments: + + out_dir is the path to the build directory. + + input_path is a path to a file containing a JSON object with three fields: + + - "files": A list of the filenames to check. + + - "test_targets": A list of the labels for targets that are needed to run + the tests we wish to run. + + - "additional_compile_targets": A list of the labels for targets that we + wish to rebuild, but aren't necessarily needed for testing. The important + difference between this field and "test_targets" is that if an item in + the additional_compile_targets list refers to a group, then any + dependencies of that group will be returned if they are out of date, but + the group itself does not need to be. If the dependencies themselves are + groups, the same filtering is repeated. This filtering can be used to + avoid rebuilding dependencies of a group that are unaffected by the input + files. The list may also contain the string "all" to refer to a + pseudo-group that contains every root target in the build graph. + + This filtering behavior is also known as "pruning" the list of compile + targets. + + If input_path is -, input is read from stdin. + + output_path is a path indicating where the results of the command are to be + written. The results will be a file containing a JSON object with one or more + of following fields: + + - "compile_targets": A list of the labels derived from the input + compile_targets list that are affected by the input files. Due to the way + the filtering works for compile targets as described above, this list may + contain targets that do not appear in the input list. + + - "test_targets": A list of the labels from the input test_targets list that + are affected by the input files. This list will be a proper subset of the + input list. + + - "invalid_targets": A list of any names from the input that do not exist in + the build graph. If this list is non-empty, the "error" field will also be + set to "Invalid targets". + + - "status": A string containing one of three values: + + - "Found dependency" + - "No dependency" + - "Found dependency (all)" + + In the first case, the lists returned in compile_targets and test_targets + should be passed to ninja to build. In the second case, nothing was + affected and no build is necessary. In the third case, GN could not + determine the correct answer and returned the input as the output in order + to be safe. + + - "error": This will only be present if an error occurred, and will contain + a string describing the error. This includes cases where the input file is + not in the right format, or contains invalid targets. + + If output_path is -, output is written to stdout. + + The command returns 1 if it is unable to read the input file or write the + output file, or if there is something wrong with the build such that gen + would also fail, and 0 otherwise. In particular, it returns 0 even if the + "error" key is non-empty and a non-fatal error occurred. In other words, it + tries really hard to always write something to the output JSON and convey + errors that way rather than via return codes. +``` +### **gn args**: (command-line tool) + +``` + Display or configure arguments declared by the build. + + gn args [--list] [--short] [--args] [--overrides-only] + + See also "gn help buildargs" for a more high-level overview of how + build arguments work. +``` + +#### **Usage** + +``` + gn args + Open the arguments for the given build directory in an editor. If the + given build directory doesn't exist, it will be created and an empty args + file will be opened in the editor. You would type something like this + into that file: + enable_doom_melon=false + os="android" + + To find your editor on Posix, GN will search the environment variables in + order: GN_EDITOR, VISUAL, and EDITOR. On Windows GN will open the command + associated with .txt files. + + Note: you can edit the build args manually by editing the file "args.gn" + in the build directory and then running "gn gen ". + + gn args --list[=] [--short] [--overrides-only] [--json] + Lists all build arguments available in the current configuration, or, if + an exact_arg is specified for the list flag, just that one build + argument. + + The output will list the declaration location, current value for the + build, default value (if different than the current value), and comment + preceding the declaration. + + If --short is specified, only the names and current values will be + printed. + + If --overrides-only is specified, only the names and current values of + arguments that have been overridden (i.e. non-default arguments) will + be printed. Overrides come from the /args.gn file and //.gn + + If --json is specified, the output will be emitted in json format. + JSON schema for output: + [ + { + "name": variable_name, + "current": { + "value": overridden_value, + "file": file_name, + "line": line_no + }, + "default": { + "value": default_value, + "file": file_name, + "line": line_no + }, + "comment": comment_string + }, + ... + ] +``` + +#### **Examples** + +``` + gn args out/Debug + Opens an editor with the args for out/Debug. + + gn args out/Debug --list --short + Prints all arguments with their default values for the out/Debug + build. + + gn args out/Debug --list --short --overrides-only + Prints overridden arguments for the out/Debug build. + + gn args out/Debug --list=target_cpu + Prints information about the "target_cpu" argument for the " + "out/Debug + build. + + gn args --list --args="os=\"android\" enable_doom_melon=true" + Prints all arguments with the default values for a build with the + given arguments set (which may affect the values of other + arguments). +``` +### **gn check <out_dir> [<label_pattern>] [\--force] [\--check-generated]** + +``` + GN's include header checker validates that the includes for C-like source + files match the build dependency graph. + + "gn check" is the same thing as "gn gen" with the "--check" flag except that + this command does not write out any build files. It's intended to be an easy + way to manually trigger include file checking. + + The can take exact labels or patterns that match more than + one (although not general regular expressions). If specified, only those + matching targets will be checked. See "gn help label_pattern" for details. +``` + +#### **Command-specific switches** + +``` + --check-generated + Generated files are normally not checked since they do not exist + until after a build. With this flag, those generated files that + can be found on disk are also checked. + + --check-system + Check system style includes (using ) in addition to + "double quote" includes. + + --default-toolchain + Normally wildcard targets are matched in all toolchains. This + switch makes wildcard labels with no explicit toolchain reference + only match targets in the default toolchain. + + Non-wildcard inputs with no explicit toolchain specification will + always match only a target in the default toolchain if one exists. + + --force + Ignores specifications of "check_includes = false" and checks all + target's files that match the target label. +``` + +#### **What gets checked** + +``` + The .gn file may specify a list of targets to be checked in the list + check_targets (see "gn help dotfile"). Alternatively, the .gn file may + specify a list of targets not to be checked in no_check_targets. If a label + pattern is specified on the command line, neither check_targets or + no_check_targets is used. + + Targets can opt-out from checking with "check_includes = false" (see + "gn help check_includes"). + + For targets being checked: + + - GN opens all C-like source files in the targets to be checked and scans + the top for includes. + + - Generated files (that might not exist yet) are ignored unless + the --check-generated flag is provided. + + - Includes with a "nogncheck" annotation are skipped (see + "gn help nogncheck"). + + - Includes using "quotes" are always checked. + If system style checking is enabled, includes using + are also checked. + + - Include paths are assumed to be relative to any of the "include_dirs" for + the target (including the implicit current dir). + + - GN does not run the preprocessor so will not understand conditional + includes. + + - Only includes matching known files in the build are checked: includes + matching unknown paths are ignored. + + For an include to be valid: + + - The included file must be in the current target, or there must be a path + following only public dependencies to a target with the file in it + ("gn path" is a good way to diagnose problems). + + - There can be multiple targets with an included file: only one needs to be + valid for the include to be allowed. + + - If there are only "sources" in a target, all are considered to be public + and can be included by other targets with a valid public dependency path. + + - If a target lists files as "public", only those files are able to be + included by other targets. Anything in the sources will be considered + private and will not be includable regardless of dependency paths. + + - Outputs from actions are treated like public sources on that target. + + - A target can include headers from a target that depends on it if the + other target is annotated accordingly. See "gn help + allow_circular_includes_from". +``` + +#### **Advice on fixing problems** + +``` + If you have a third party project that is difficult to fix or doesn't care + about include checks it's generally best to exclude that target from checking + altogether via "check_includes = false". + + If you have conditional includes, make sure the build conditions and the + preprocessor conditions match, and annotate the line with "nogncheck" (see + "gn help nogncheck" for an example). + + If two targets are hopelessly intertwined, use the + "allow_circular_includes_from" annotation. Ideally each should have identical + dependencies so configs inherited from those dependencies are consistent (see + "gn help allow_circular_includes_from"). + + If you have a standalone header file or files that need to be shared between + a few targets, you can consider making a source_set listing only those + headers as public sources. With only header files, the source set will be a + no-op from a build perspective, but will give a central place to refer to + those headers. That source set's files will still need to pass "gn check" in + isolation. + + In rare cases it makes sense to list a header in more than one target if it + could be considered conceptually a member of both. +``` + +#### **Examples** + +``` + gn check out/Debug + Check everything. + + gn check out/Default //foo:bar + Check only the files in the //foo:bar target. + + gn check out/Default "//foo/* + Check only the files in targets in the //foo directory tree. +``` +### **gn clean <out_dir>...** + +``` + Deletes the contents of the output directory except for args.gn and + creates a Ninja build environment sufficient to regenerate the build. +``` +### **gn clean_stale [\--ninja-executable=...] <out_dir>...** + +``` + Removes the no longer needed output files from the build directory and prunes + their records from the ninja build log and dependency database. These are + output files that were generated from previous builds, but the current build + graph no longer references them. + + This command requires a ninja executable of at least version 1.10.0. The + executable must be provided by the --ninja-executable switch. +``` + +#### **Options** + +``` + --ninja-executable= + Can be used to specify the ninja executable to use. +``` +### **gn desc** + +``` + gn desc