diff --git a/.gitmodules b/.gitmodules index 1e71bd4a..69934d0f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -803,3 +803,6 @@ [submodule "vendor/grammars/language-fontforge"] path = vendor/grammars/language-fontforge url = https://github.com/Alhadis/language-fontforge +[submodule "vendor/grammars/language-gn"] + path = vendor/grammars/language-gn + url = https://github.com/devoncarew/language-gn diff --git a/grammars.yml b/grammars.yml index 2c710cb2..18f9f069 100755 --- a/grammars.yml +++ b/grammars.yml @@ -368,6 +368,8 @@ vendor/grammars/language-fontforge: - text.sfd vendor/grammars/language-gfm: - source.gfm +vendor/grammars/language-gn: +- source.gn vendor/grammars/language-graphql: - source.graphql vendor/grammars/language-haml: diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index e4c02558..5af7884d 100755 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -19,7 +19,7 @@ # language_id - Integer used as a language-name-independent indexed field so that we can rename # languages in Linguist without reindexing all the code on GitHub. Must not be # changed for existing languages without the explicit permission of GitHub staff. -# color - CSS hex color to represent the language. Only used if type is "programming" or "prose" +# color - CSS hex color to represent the language. Only used if type is "programming" or "prose". # tm_scope - The TextMate scope that represents this programming # language. This should match one of the scopes listed in # the grammars.yml file. Use "none" if there is no grammar @@ -1393,6 +1393,18 @@ GLSL: - ".vshader" ace_mode: glsl language_id: 124 +GN: + type: data + extensions: + - ".gn" + - ".gni" + interpreters: + - gn + tm_scope: source.gn + ace_mode: python + codemirror_mode: python + codemirror_mime_type: text/x-python + language_id: 302957008 Game Maker Language: type: programming color: "#8fb200" @@ -3392,6 +3404,7 @@ Python: - ".cgi" - ".fcgi" - ".gyp" + - ".gypi" - ".lmi" - ".py3" - ".pyde" @@ -3404,6 +3417,7 @@ Python: - ".wsgi" - ".xpy" filenames: + - .gclient - BUCK - BUILD - SConscript diff --git a/samples/GN/BUILD.2.gn b/samples/GN/BUILD.2.gn new file mode 100644 index 00000000..4f97777a --- /dev/null +++ b/samples/GN/BUILD.2.gn @@ -0,0 +1,59 @@ +# Copyright 2016 the V8 project 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("../gni/isolate.gni") + +group("gn_all") { + testonly = true + + if (v8_test_isolation_mode != "noop") { + deps = [ + ":check-static-initializers_run", + ":jsfunfuzz_run", + ":run-deopt-fuzzer_run", + ":run-gcmole_run", + ":run-valgrind_run", + ] + } +} + +v8_isolate_run("check-static-initializers") { + deps = [ + "..:d8_run", + ] + + isolate = "check-static-initializers.isolate" +} + +v8_isolate_run("jsfunfuzz") { + deps = [ + "..:d8_run", + ] + + isolate = "jsfunfuzz/jsfunfuzz.isolate" +} + +v8_isolate_run("run-deopt-fuzzer") { + deps = [ + "..:d8_run", + ] + + isolate = "run-deopt-fuzzer.isolate" +} + +v8_isolate_run("run-gcmole") { + deps = [ + "..:d8_run", + ] + + isolate = "gcmole/run-gcmole.isolate" +} + +v8_isolate_run("run-valgrind") { + deps = [ + "..:d8_run", + ] + + isolate = "run-valgrind.isolate" +} diff --git a/samples/GN/BUILD.3.gn b/samples/GN/BUILD.3.gn new file mode 100644 index 00000000..d0765475 --- /dev/null +++ b/samples/GN/BUILD.3.gn @@ -0,0 +1,1646 @@ +# Copyright (c) 2013 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("//build/config/android/config.gni") +import("//build/config/chrome_build.gni") +import("//build/config/compiler/compiler.gni") +import("//build/config/nacl/config.gni") +import("//build/toolchain/cc_wrapper.gni") +import("//build/toolchain/toolchain.gni") +import("//build_overrides/build.gni") + +if (current_cpu == "arm" || current_cpu == "arm64") { + import("//build/config/arm.gni") +} +if (current_cpu == "mipsel" || current_cpu == "mips64el") { + import("//build/config/mips.gni") +} +if (is_mac) { + import("//build/config/mac/symbols.gni") +} + +declare_args() { + # Default to warnings as errors for default workflow, where we catch + # warnings with known toolchains. Allow overriding this e.g. for Chromium + # builds on Linux that could use a different version of the compiler. + # With GCC, warnings in no-Chromium code are always not treated as errors. + treat_warnings_as_errors = true + + # Normally, Android builds are lightly optimized, even for debug builds, to + # keep binary size down. Setting this flag to true disables such optimization + android_full_debug = false + + # Whether to use the binary binutils checked into third_party/binutils. + # These are not multi-arch so cannot be used except on x86 and x86-64 (the + # only two architectures that are currently checked in). Turn this off when + # you are using a custom toolchain and need to control -B in cflags. + linux_use_bundled_binutils = + linux_use_bundled_binutils_override && is_linux && + (current_cpu == "x64" || current_cpu == "x86") + binutils_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", + root_build_dir) + + # Compile in such a way as to make it possible for the profiler to unwind full + # stack frames. Setting this flag has a large effect on the performance of the + # generated code than just setting profiling, but gives the profiler more + # information to analyze. + # Requires profiling to be set to true. + enable_full_stack_frames_for_profiling = false + + # When we are going to use gold we need to find it. + # This is initialized below, after use_gold might have been overridden. + gold_path = false + + if (is_win) { + # Whether the VS xtree header has been patched to disable warning 4702. If + # it has, then we don't need to disable 4702 (unreachable code warning). + # The patch is preapplied to the internal toolchain and hence all bots. + msvs_xtree_patched = false + } + + # Omit unwind support in official builds to save space. + # We can use breakpad for these builds. + exclude_unwind_tables = is_chrome_branded && is_official_build + + # If true, gold linker will save symbol table inside object files. + # This speeds up gdb startup by 60% + gdb_index = false + + # If true, optimize for size. Does not affect windows builds. + # Linux & Mac favor speed over size. + # TODO(brettw) it's weird that Mac and desktop Linux are different. We should + # explore favoring size over speed in this case as well. + optimize_for_size = is_android || is_ios + + # Enable fatal linker warnings. Building Chromium with certain versions + # of binutils can cause linker warning. + # See: https://bugs.chromium.org/p/chromium/issues/detail?id=457359 + fatal_linker_warnings = true + + # AFDO (Automatic Feedback Directed Optimizer) is a form of profile-guided + # optimization that GCC supports. It used by ChromeOS in their official + # builds. To use it, set auto_profile_path to the path to a file containing + # the needed gcov profiling data. + auto_profile_path = "" + + # Optimize for coverage guided fuzzing (balance between speed and number of + # branches) + optimize_for_fuzzing = false +} + +if (is_clang && !is_nacl) { + update_args = [ "--print-revision" ] + if (llvm_force_head_revision) { + update_args += [ "--llvm-force-head-revision" ] + } + clang_revision = + exec_script("//tools/clang/scripts/update.py", update_args, "trim string") +} + +# Apply the default logic for these values if they were not set explicitly. +if (gold_path == false) { + if (use_gold) { + gold_path = rebase_path("//third_party/binutils/Linux_x64/Release/bin", + root_build_dir) + } else { + gold_path = "" + } +} + +if (use_debug_fission == "default") { + use_debug_fission = is_debug && !is_win && use_gold && + linux_use_bundled_binutils && cc_wrapper == "" +} + +# default_include_dirs --------------------------------------------------------- +# +# This is a separate config so that third_party code (which would not use the +# source root and might have conflicting versions of some headers) can remove +# this and specify their own include paths. +config("default_include_dirs") { + include_dirs = [ + "//", + root_gen_dir, + ] +} + +# compiler --------------------------------------------------------------------- +# +# Base compiler configuration. +# +# See also "runtime_library" below for related stuff and a discussion about +# where stuff should go. Put warning related stuff in the "warnings" config. + +config("compiler") { + asmflags = [] + cflags = [] + cflags_c = [] + cflags_cc = [] + cflags_objc = [] + cflags_objcc = [] + ldflags = [] + defines = [] + configs = [] + + # System-specific flags. If your compiler flags apply to one of the + # categories here, add it to the associated file to keep this shared config + # smaller. + if (is_win) { + configs += [ "//build/config/win:compiler" ] + } else if (is_android) { + configs += [ "//build/config/android:compiler" ] + } else if (is_linux) { + configs += [ "//build/config/linux:compiler" ] + } else if (is_nacl) { + configs += [ "//build/config/nacl:compiler" ] + } else if (is_ios || is_mac) { + configs += [ "//build/config/mac:compiler" ] + } + + # Applies to all Posix systems. + if (is_posix) { + configs += [ "//build/config/posix:compiler" ] + } + + # See the definitions below. + configs += [ + ":compiler_cpu_abi", + ":compiler_codegen", + ] + + # In general, Windows is totally different, but all the other builds share + # some common GCC configuration. + if (!is_win) { + # Common GCC compiler flags setup. + # -------------------------------- + cflags += [ "-fno-strict-aliasing" ] # See http://crbug.com/32204 + cflags_cc += [ + # If this is removed then remove the corresponding /Zc:threadSafeInit- for + # Windows. + "-fno-threadsafe-statics", + + # Not exporting C++ inline functions can generally be applied anywhere + # so we do so here. Normal function visibility is controlled by + # //build/config/gcc:symbol_visibility_hidden. + "-fvisibility-inlines-hidden", + ] + + # Stack protection. + if (is_mac) { + # The strong variant of the stack protector significantly increases + # binary size, so only enable it in debug mode. + if (is_debug) { + cflags += [ "-fstack-protector-strong" ] + } else { + cflags += [ "-fstack-protector" ] + } + } else if (is_posix && !is_chromeos && !is_nacl) { + # TODO(phajdan.jr): Use -fstack-protector-strong when our gcc supports it. + # See also https://crbug.com/533294 + cflags += [ "--param=ssp-buffer-size=4" ] + + # The x86 toolchain currently has problems with stack-protector. + if (is_android && current_cpu == "x86") { + cflags += [ "-fno-stack-protector" ] + } else { + cflags += [ "-fstack-protector" ] + } + } + + # Linker warnings. + if (fatal_linker_warnings && !(is_chromeos && current_cpu == "arm") && + !(is_android && use_order_profiling) && !is_mac && !is_ios) { + # TODO(jochen): Enable this on chromeos on arm. http://crbug.com/356580 + # TODO(lizeb,pasko): Fix link errors when linking with order_profiling=1 + # crbug.com/485542 + ldflags += [ "-Wl,--fatal-warnings" ] + } + } + + if (is_clang && is_debug) { + # Allow comparing the address of references and 'this' against 0 + # in debug builds. Technically, these can never be null in + # well-defined C/C++ and Clang can optimize such checks away in + # release builds, but they may be used in asserts in debug builds. + cflags_cc += [ + "-Wno-undefined-bool-conversion", + "-Wno-tautological-undefined-compare", + ] + } + + if (is_clang && !is_nacl) { + # This is here so that all files get recompiled after a clang roll and + # when turning clang on or off. (defines are passed via the command line, + # and build system rebuild things when their commandline changes). Nothing + # should ever read this define. + defines += [ "CR_CLANG_REVISION=$clang_revision" ] + } + + # Non-Mac Posix compiler flags setup. + # ----------------------------------- + if (is_posix && !(is_mac || is_ios)) { + if (enable_profiling) { + if (!is_debug) { + cflags += [ "-g" ] + + if (enable_full_stack_frames_for_profiling) { + cflags += [ + "-fno-inline", + "-fno-optimize-sibling-calls", + ] + } + } + } + + defines += [ "_FILE_OFFSET_BITS=64" ] + + if (!is_android) { + defines += [ + "_LARGEFILE_SOURCE", + "_LARGEFILE64_SOURCE", + ] + } + + if (!is_nacl) { + if (exclude_unwind_tables) { + cflags += [ + "-fno-unwind-tables", + "-fno-asynchronous-unwind-tables", + ] + defines += [ "NO_UNWIND_TABLES" ] + } else { + cflags += [ "-funwind-tables" ] + } + } + } + + # Linux/Android common flags setup. + # --------------------------------- + if (is_linux || is_android) { + cflags += [ + "-fPIC", + "-pipe", # Use pipes for communicating between sub-processes. Faster. + ] + + ldflags += [ + "-fPIC", + "-Wl,-z,noexecstack", + "-Wl,-z,now", + "-Wl,-z,relro", + ] + if (!using_sanitizer) { + if (!use_cfi_diag) { + ldflags += [ "-Wl,-z,defs" ] + } + + # Functions interposed by the sanitizers can make ld think + # that some libraries aren't needed when they actually are, + # http://crbug.com/234010. As workaround, disable --as-needed. + if (!is_nacl && !is_android) { + # TODO(pcc): Fix linker bug which requires us to link pthread + # unconditionally here (crbug.com/623236). + ldflags += [ + "-Wl,--no-as-needed", + "-lpthread", + ] + } + ldflags += [ "-Wl,--as-needed" ] + } + } + + # Linux-specific compiler flags setup. + # ------------------------------------ + if (is_android && is_clang) { + _rebased_android_toolchain_root = + rebase_path(android_toolchain_root, root_build_dir) + + # Let clang find the linker in the NDK. + ldflags += [ "--gcc-toolchain=$_rebased_android_toolchain_root" ] + } + + if (is_posix && use_lld && !is_nacl) { + ldflags += [ "-fuse-ld=lld" ] + } else if (use_gold) { + ldflags += [ "-fuse-ld=gold" ] + if (is_android) { + # Use -mstackrealign due to a bug on ia32 Jelly Bean. + # See crbug.com/521527 + if (current_cpu == "x86") { + cflags += [ "-mstackrealign" ] + } + } else { + # On Android, this isn't needed. gcc in the NDK knows to look next to + # it with -fuse-ld=gold, and clang gets a --gcc-toolchain flag passed + # above. + ldflags += [ "-B$gold_path" ] + + if (linux_use_bundled_binutils) { + ldflags += [ + # Experimentation found that using four linking threads + # saved ~20% of link time. + # https://groups.google.com/a/chromium.org/group/chromium-dev/browse_thread/thread/281527606915bb36 + # Only apply this to the target linker, since the host + # linker might not be gold, but isn't used much anyway. + "-Wl,--threads", + "-Wl,--thread-count=4", + ] + } + } + + if (gdb_index) { + ldflags += [ "-Wl,--gdb-index" ] + } + + # TODO(thestig): Make this flag work with GN. + #if (!is_official_build && !is_chromeos && !(is_asan || is_lsan || is_tsan || is_msan)) { + # ldflags += [ + # "-Wl,--detect-odr-violations", + # ] + #} + } else if (linux_use_bundled_binutils) { + # Gold is the default linker for the bundled binutils so we explicitly + # enable the bfd linker when use_gold is not set. + ldflags += [ "-fuse-ld=bfd" ] + } + + if (is_posix && (use_gold || (use_lld && !is_nacl)) && !using_sanitizer && + !(is_android && use_order_profiling)) { + # TODO(crbug.com/576197) - gcc on x86 platforms + gold + icf=all + # doesn't currently work on non-chromeos platforms. + # Additionally, on Android x86 --icf=safe seems to cause issues as well. + # Additionally, on cast Android x86, --icf=all causes issues. + if (is_android && current_cpu == "x86") { + ldflags += [ "-Wl,--icf=none" ] + } else if ((is_clang && !is_android) || is_chromeos || + (current_cpu != "x86" && current_cpu != "x64")) { + # TODO(thakis): Remove `!is_android` above once our gold has been rolled + # with the fix for https://sourceware.org/bugzilla/show_bug.cgi?id=17704 + # merged. See also https://crbug.com/663886 + ldflags += [ "-Wl,--icf=all" ] + } else if (!is_android || is_clang) { + ldflags += [ "-Wl,--icf=safe" ] + } + } + + if (linux_use_bundled_binutils) { + cflags += [ "-B$binutils_path" ] + } + + # Clang-specific compiler flags setup. + # ------------------------------------ + if (is_clang) { + cflags += [ "-fcolor-diagnostics" ] + } + + # Print absolute paths in diagnostics. There is no precedent for doing this + # on Linux/Mac (GCC doesn't support it), but MSVC does this with /FC and + # Windows developers rely on it (crbug.com/636109) so only do this on Windows. + if (is_clang && is_win) { + cflags += [ "-fdiagnostics-absolute-paths" ] + } + + # Makes builds independent of absolute file path. + # clang-cl (used if is_win) doesn't expose this flag. + # Currently disabled for nacl since its toolchain lacks this flag (too old). + # TODO(zforman): Once nacl's toolchain is updated, remove check. + if (is_clang && is_linux) { + absolute_path = rebase_path("//.") + cflags += [ "-fdebug-prefix-map=$absolute_path=." ] + } + + # C++11 compiler flags setup. + # --------------------------- + if (is_linux || is_android || (is_nacl && is_clang)) { + # gnu++11 instead of c++11 is needed because some code uses typeof() (a + # GNU extension). + # TODO(thakis): Eventually switch this to c++11 instead, + # http://crbug.com/427584 + cflags_cc += [ "-std=gnu++11" ] + } else if (!is_win && !is_nacl) { + # TODO(mcgrathr) - the NaCl GCC toolchain doesn't support either gnu++11 + # or c++11; we technically don't need this toolchain any more, but there + # are still a few buildbots using it, so until those are turned off + # we need the !is_nacl clause and the (is_nacl && is_clang) clause, above. + cflags_cc += [ "-std=c++11" ] + } + + if (is_mac) { + cflags_cc += [ "-stdlib=libc++" ] + ldflags += [ "-stdlib=libc++" ] + } + + # Add flags for link-time optimization. These flags enable + # optimizations/transformations that require whole-program visibility at link + # time, so they need to be applied to all translation units, and we may end up + # with miscompiles if only part of the program is compiled with LTO flags. For + # that reason, we cannot allow targets to enable or disable these flags, for + # example by disabling the optimize configuration. + # TODO(pcc): Make this conditional on is_official_build rather than on gn + # flags for specific features. + if (!is_debug && (allow_posix_link_time_opt || is_cfi) && !is_nacl) { + if (use_thin_lto) { + cflags += [ "-flto=thin" ] + ldflags += [ "-flto=thin" ] + + # Limit the parallelism to avoid too agressive competition between + # linker jobs. This is still suboptimal to a potential dynamic + # resource allocation scheme, but should be good enough. + if (use_lld) { + ldflags += [ "-Wl,--thinlto-jobs=8" ] + } else { + ldflags += [ "-Wl,-plugin-opt,jobs=8" ] + } + } else { + # Note: ThinLTO does not currently have this feature implemented + # For Full LTO, it provides a measurable runtime speedup of Chrome. + cflags += [ + "-flto", + "-fwhole-program-vtables", + ] + ldflags += [ + "-flto", + "-fwhole-program-vtables", + ] + + # Apply a lower LTO optimization level as the default is too slow. + if (is_linux) { + if (use_lld) { + ldflags += [ "-Wl,--lto-O1" ] + } else { + ldflags += [ "-Wl,-plugin-opt,O1" ] + } + } else if (is_mac) { + ldflags += [ "-Wl,-mllvm,-O1" ] + } + } + + # Work-around for http://openradar.appspot.com/20356002 + if (is_mac) { + ldflags += [ "-Wl,-all_load" ] + } + + # Allows the linker to apply ICF to the LTO object file. Also, when + # targeting ARM, without this flag, LTO produces a .text section that is + # larger than the maximum call displacement, preventing the linker from + # relocating calls (http://llvm.org/PR22999). + if (is_linux) { + ldflags += [ "-Wl,-plugin-opt,-function-sections" ] + } + } + + # Pass the same C/C++ flags to the objective C/C++ compiler. + cflags_objc += cflags_c + cflags_objcc += cflags_cc + + # Assign any flags set for the C compiler to asmflags so that they are sent + # to the assembler. The Windows assembler takes different types of flags + # so only do so for posix platforms. + if (is_posix) { + asmflags += cflags + asmflags += cflags_c + } +} + +# This is separate from :compiler (and not even a sub-config there) +# so that some targets can remove it from the list with: +# configs -= [ "//build/config/compiler:pthread" ] +config("pthread") { + if (is_linux) { + cflags = [ "-pthread" ] + ldflags = [ "-pthread" ] + } +} + +# This provides the basic options to select the target CPU and ABI. +# It is factored out of "compiler" so that special cases can use this +# without using everything that "compiler" brings in. Options that +# tweak code generation for a particular CPU do not belong here! +# See "compiler_codegen", below. +config("compiler_cpu_abi") { + cflags = [] + ldflags = [] + + if (is_posix && !(is_mac || is_ios)) { + # CPU architecture. We may or may not be doing a cross compile now, so for + # simplicity we always explicitly set the architecture. + if (current_cpu == "x64") { + cflags += [ + "-m64", + "-march=x86-64", + ] + ldflags += [ "-m64" ] + } else if (current_cpu == "x86") { + cflags += [ "-m32" ] + ldflags += [ "-m32" ] + if (!is_nacl) { + cflags += [ + "-msse2", + "-mfpmath=sse", + "-mmmx", + ] + } + } else if (current_cpu == "arm") { + if (is_clang && !is_android && !is_nacl) { + cflags += [ "--target=arm-linux-gnueabihf" ] + ldflags += [ "--target=arm-linux-gnueabihf" ] + } + if (!is_nacl) { + cflags += [ + "-march=$arm_arch", + "-mfloat-abi=$arm_float_abi", + ] + } + if (arm_tune != "") { + cflags += [ "-mtune=$arm_tune" ] + } + } else if (current_cpu == "arm64") { + if (is_clang && !is_android && !is_nacl) { + cflags += [ "--target=aarch64-linux-gnu" ] + ldflags += [ "--target=aarch64-linux-gnu" ] + } + } else if (current_cpu == "mipsel" && !is_nacl) { + if (mips_arch_variant == "r6") { + if (is_clang) { + cflags += [ + "--target=mipsel-linux-gnu", + "-march=mips32r6", + ] + ldflags += [ "--target=mipsel-linux-gnu" ] + } else { + cflags += [ + "-mips32r6", + "-Wa,-mips32r6", + ] + if (is_android) { + ldflags += [ + "-mips32r6", + "-Wl,-melf32ltsmip", + ] + } + } + if (mips_use_msa == true) { + cflags += [ + "-mmsa", + "-mfp64", + ] + } + } else if (mips_arch_variant == "r2") { + if (is_clang) { + if (is_android) { + cflags += [ + "--target=mipsel-linux-android", + "-march=mipsel", + "-mcpu=mips32r2", + ] + ldflags += [ "--target=mipsel-linux-android" ] + } else { + cflags += [ + "--target=mipsel-linux-gnu", + "-march=mipsel", + "-mcpu=mips32r2", + ] + ldflags += [ "--target=mipsel-linux-gnu" ] + } + } else { + cflags += [ + "-mips32r2", + "-Wa,-mips32r2", + ] + if (mips_float_abi == "hard" && mips_fpu_mode != "") { + cflags += [ "-m$mips_fpu_mode" ] + } + } + } else if (mips_arch_variant == "r1") { + if (is_clang) { + if (is_android) { + cflags += [ + "--target=mipsel-linux-android", + "-march=mipsel", + "-mcpu=mips32", + ] + ldflags += [ "--target=mipsel-linux-android" ] + } else { + cflags += [ + "--target=mipsel-linux-gnu", + "-march=mipsel", + "-mcpu=mips32", + ] + ldflags += [ "--target=mipsel-linux-gnu" ] + } + } else { + cflags += [ + "-mips32", + "-Wa,-mips32", + ] + } + } + + if (mips_dsp_rev == 1) { + cflags += [ "-mdsp" ] + } else if (mips_dsp_rev == 2) { + cflags += [ "-mdspr2" ] + } + + cflags += [ "-m${mips_float_abi}-float" ] + } else if (current_cpu == "mips64el") { + if (mips_arch_variant == "r6") { + if (is_clang) { + if (is_android) { + cflags += [ + "--target=mips64el-linux-android", + "-march=mips64el", + "-mcpu=mips64r6", + ] + ldflags += [ "--target=mips64el-linux-android" ] + } + } else { + cflags += [ + "-mips64r6", + "-Wa,-mips64r6", + ] + ldflags += [ "-mips64r6" ] + } + if (mips_use_msa == true) { + cflags += [ + "-mmsa", + "-mfp64", + ] + } + } else if (mips_arch_variant == "r2") { + cflags += [ + "-mips64r2", + "-Wa,-mips64r2", + ] + ldflags += [ "-mips64r2" ] + } + } else if (current_cpu == "pnacl" && is_nacl_nonsfi) { + if (target_cpu == "x86" || target_cpu == "x64") { + cflags += [ + "-arch", + "x86-32-nonsfi", + "--pnacl-bias=x86-32-nonsfi", + "--target=i686-unknown-nacl", + ] + ldflags += [ + "-arch", + "x86-32-nonsfi", + "--target=i686-unknown-nacl", + ] + } else if (target_cpu == "arm") { + cflags += [ + "-arch", + "arm-nonsfi", + "-mfloat-abi=hard", + "--pnacl-bias=arm-nonsfi", + "--target=armv7-unknown-nacl-gnueabihf", + ] + ldflags += [ + "-arch", + "arm-nonsfi", + "--target=armv7-unknown-nacl-gnueabihf", + ] + } + } + } + + asmflags = cflags +} + +# This provides options to tweak code generation that are necessary +# for particular Chromium code or for working around particular +# compiler bugs (or the combination of the two). +config("compiler_codegen") { + configs = [] + cflags = [] + + if (is_nacl) { + configs += [ "//build/config/nacl:compiler_codegen" ] + } else if (is_posix && !is_mac && !is_ios) { + if (current_cpu == "x86") { + if (is_clang) { + cflags += [ + # Else building libyuv gives clang's register allocator issues, + # see llvm.org/PR15798 / crbug.com/233709 + "-momit-leaf-frame-pointer", + ] + } + } else if (current_cpu == "arm") { + if (is_android && !is_clang) { + # Clang doesn't support these flags. + cflags += [ + # The tree-sra optimization (scalar replacement for + # aggregates enabling subsequent optimizations) leads to + # invalid code generation when using the Android NDK's + # compiler (r5-r7). This can be verified using + # webkit_unit_tests' WTF.Checked_int8_t test. + "-fno-tree-sra", + + # The following option is disabled to improve binary + # size and performance in gcc 4.9. + "-fno-caller-saves", + ] + } + } + } + + asmflags = cflags +} + +# This is separate from :compiler_codegen (and not even a sub-config there) +# so that some targets can remove it from the list with: +# configs -= [ "//build/config/compiler:clang_stackrealign" ] +# See https://crbug.com/556393 for details of where it must be avoided. +config("clang_stackrealign") { + if (is_clang && current_cpu == "x86" && is_linux) { + cflags = [ + # Align the stack on 16-byte boundaries, http://crbug.com/418554. + "-mstack-alignment=16", + "-mstackrealign", + ] + } +} + +config("compiler_arm_fpu") { + if (current_cpu == "arm" && !is_ios && !is_nacl) { + cflags = [ "-mfpu=$arm_fpu" ] + asmflags = cflags + } +} + +config("compiler_arm_thumb") { + if (current_cpu == "arm" && arm_use_thumb && is_posix && + !(is_mac || is_ios || is_nacl)) { + cflags = [ "-mthumb" ] + if (is_android && !is_clang) { + # Clang doesn't support this option. + cflags += [ "-mthumb-interwork" ] + } + } +} + +config("compiler_arm") { + if (current_cpu == "arm" && is_chromeos) { + # arm is normally the default mode for clang, but on chromeos a wrapper + # is used to pass -mthumb, and therefor change the default. + cflags = [ "-marm" ] + } +} + +# runtime_library ------------------------------------------------------------- +# +# Sets the runtime library and associated options. +# +# How do you determine what should go in here vs. "compiler" above? Consider if +# a target might choose to use a different runtime library (ignore for a moment +# if this is possible or reasonable on your system). If such a target would want +# to change or remove your option, put it in the runtime_library config. If a +# target wants the option regardless, put it in the compiler config. + +config("runtime_library") { + defines = [] + configs = [] + + # System-specific flags. If your compiler flags apply to one of the + # categories here, add it to the associated file to keep this shared config + # smaller. + if (is_win) { + configs += [ "//build/config/win:runtime_library" ] + } else if (is_linux) { + configs += [ "//build/config/linux:runtime_library" ] + } else if (is_ios) { + configs += [ "//build/config/ios:runtime_library" ] + } else if (is_mac) { + configs += [ "//build/config/mac:runtime_library" ] + } else if (is_android) { + configs += [ "//build/config/android:runtime_library" ] + } + + if (is_posix) { + configs += [ "//build/config/posix:runtime_library" ] + } + + if (is_component_build) { + defines += [ "COMPONENT_BUILD" ] + } +} + +# default_warnings ------------------------------------------------------------ +# +# Collects all warning flags that are used by default. This is used as a +# subconfig of both chromium_code and no_chromium_code. This way these +# flags are guaranteed to appear on the compile command line after -Wall. +config("default_warnings") { + cflags = [] + cflags_cc = [] + + if (is_win) { + if (treat_warnings_as_errors) { + cflags += [ "/WX" ] + } + + cflags += [ + # Warnings permanently disabled: + + # C4091: 'typedef ': ignored on left of 'X' when no variable is + # declared. + # This happens in a number of Windows headers. Dumb. + "/wd4091", + + # C4127: conditional expression is constant + # This warning can in theory catch dead code and other problems, but + # triggers in far too many desirable cases where the conditional + # expression is either set by macros or corresponds some legitimate + # compile-time constant expression (due to constant template args, + # conditionals comparing the sizes of different types, etc.). Some of + # these can be worked around, but it's not worth it. + "/wd4127", + + # C4251: 'identifier' : class 'type' needs to have dll-interface to be + # used by clients of class 'type2' + # This is necessary for the shared library build. + "/wd4251", + + # C4351: new behavior: elements of array 'array' will be default + # initialized + # This is a silly "warning" that basically just alerts you that the + # compiler is going to actually follow the language spec like it's + # supposed to, instead of not following it like old buggy versions did. + # There's absolutely no reason to turn this on. + "/wd4351", + + # C4355: 'this': used in base member initializer list + # It's commonly useful to pass |this| to objects in a class' initializer + # list. While this warning can catch real bugs, most of the time the + # constructors in question don't attempt to call methods on the passed-in + # pointer (until later), and annotating every legit usage of this is + # simply more hassle than the warning is worth. + "/wd4355", + + # C4503: 'identifier': decorated name length exceeded, name was + # truncated + # This only means that some long error messages might have truncated + # identifiers in the presence of lots of templates. It has no effect on + # program correctness and there's no real reason to waste time trying to + # prevent it. + "/wd4503", + + # Warning C4589 says: "Constructor of abstract class ignores + # initializer for virtual base class." Disable this warning because it + # is flaky in VS 2015 RTM. It triggers on compiler generated + # copy-constructors in some cases. + "/wd4589", + + # C4611: interaction between 'function' and C++ object destruction is + # non-portable + # This warning is unavoidable when using e.g. setjmp/longjmp. MSDN + # suggests using exceptions instead of setjmp/longjmp for C++, but + # Chromium code compiles without exception support. We therefore have to + # use setjmp/longjmp for e.g. JPEG decode error handling, which means we + # have to turn off this warning (and be careful about how object + # destruction happens in such cases). + "/wd4611", + + # Warnings to evaluate and possibly fix/reenable later: + + "/wd4100", # Unreferenced formal function parameter. + "/wd4121", # Alignment of a member was sensitive to packing. + "/wd4244", # Conversion: possible loss of data. + "/wd4505", # Unreferenced local function has been removed. + "/wd4510", # Default constructor could not be generated. + "/wd4512", # Assignment operator could not be generated. + "/wd4610", # Class can never be instantiated, constructor required. + "/wd4838", # Narrowing conversion. Doesn't seem to be very useful. + "/wd4995", # 'X': name was marked as #pragma deprecated + "/wd4996", # Deprecated function warning. + + # These are variable shadowing warnings that are new in VS2015. We + # should work through these at some point -- they may be removed from + # the RTM release in the /W4 set. + "/wd4456", + "/wd4457", + "/wd4458", + "/wd4459", + ] + + cflags += [ + # C4312 is a VS 2015 64-bit warning for integer to larger pointer. + # TODO(brucedawson): fix warnings, crbug.com/554200 + "/wd4312", + ] + + if (current_cpu == "x86") { + cflags += [ + # VC++ 2015 changes 32-bit size_t truncation warnings from 4244 to + # 4267. Example: short TruncTest(size_t x) { return x; } + # Since we disable 4244 we need to disable 4267 during migration. + # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. + "/wd4267", + ] + } + + # VS xtree header file needs to be patched or 4702 (unreachable code + # warning) is reported if _HAS_EXCEPTIONS=0. Disable the warning if xtree is + # not patched. + if (!msvs_xtree_patched && + exec_script("../../win_is_xtree_patched.py", [], "value") == 0) { + cflags += [ "/wd4702" ] # Unreachable code. + } + + # Building with Clang on Windows is a work in progress and very + # experimental. See crbug.com/82385. + if (is_clang) { + cflags += [ + # TODO(hans): Make this list shorter eventually, http://crbug.com/504657 + "-Wno-microsoft-enum-value", # http://crbug.com/505296 + "-Wno-unknown-pragmas", # http://crbug.com/505314 + "-Wno-microsoft-cast", # http://crbug.com/550065 + ] + } + } else { + if (is_mac && !is_nacl) { + # When compiling Objective-C, warns if a method is used whose + # availability is newer than the deployment target. This is not + # required when compiling Chrome for iOS. + cflags += [ "-Wpartial-availability" ] + } + + # Suppress warnings about ABI changes on ARM (Clang doesn't give this + # warning). + if (current_cpu == "arm" && !is_clang) { + cflags += [ "-Wno-psabi" ] + } + + if (!is_clang) { + cflags_cc += [ + # See comment for -Wno-c++11-narrowing. + "-Wno-narrowing", + ] + + # Don't warn about the "typedef 'foo' locally defined but not used" + # for gcc 4.8. + # TODO: remove this flag once all builds work. See crbug.com/227506 + cflags += [ "-Wno-unused-local-typedefs" ] + + # Don't warn about "maybe" uninitialized. Clang doesn't include this + # in -Wall but gcc does, and it gives false positives. + cflags += [ "-Wno-maybe-uninitialized" ] + } + } + + # Common Clang and GCC warning setup. + if (!is_win || is_clang) { + cflags += [ + # Disables. + "-Wno-missing-field-initializers", # "struct foo f = {0};" + "-Wno-unused-parameter", # Unused function parameters. + ] + } + + if (is_chromeos) { + # TODO(thakis): Remove, http://crbug.com/263960 + if (is_clang) { + cflags_cc += [ "-Wno-reserved-user-defined-literal" ] + } else { + cflags_cc += [ "-Wno-literal-suffix" ] + } + } + + if (is_clang) { + cflags += [ + # TODO(thakis): Consider -Wloop-analysis (turns on + # -Wrange-loop-analysis too). + + # This warns on using ints as initializers for floats in + # initializer lists (e.g. |int a = f(); CGSize s = { a, a };|), + # which happens in several places in chrome code. Not sure if + # this is worth fixing. + "-Wno-c++11-narrowing", + + # Warns on switches on enums that cover all enum values but + # also contain a default: branch. Chrome is full of that. + "-Wno-covered-switch-default", + + # Clang considers the `register` keyword as deprecated, but e.g. + # code generated by flex (used in angle) contains that keyword. + # http://crbug.com/255186 + "-Wno-deprecated-register", + + # TODO(thakis): This used to be implied by -Wno-unused-function, + # which we no longer use. Check if it makes sense to remove + # this as well. http://crbug.com/316352 + "-Wno-unneeded-internal-declaration", + + # TODO(hans): Get this cleaned up, http://crbug.com/428099 + "-Wno-inconsistent-missing-override", + ] + + # Chrome's hermetic Clang compiler, NaCl's Clang compiler and Xcode's Clang + # compiler will almost always have different versions. Certain flags may not + # be recognized by one version or the other. + if (!is_nacl) { + # Flags NaCl (Clang 3.7) does not recognize. + cflags += [ + # TODO(thakis): Enable this, crbug.com/507717 + "-Wno-shift-negative-value", + ] + } + if (!is_nacl && !use_xcode_clang) { + # Flags NaCl (Clang 3.7) and Xcode 7.3 (Clang clang-703.0.31) do not + # recognize. + cflags += [ + # TODO(thakis): https://crbug.com/604888 + "-Wno-undefined-var-template", + + # TODO(thakis): https://crbug.com/617318 + "-Wno-nonportable-include-path", + + # TODO(hans): https://crbug.com/637306 + "-Wno-address-of-packed-member", + ] + } + } +} + +# chromium_code --------------------------------------------------------------- +# +# Toggles between higher and lower warnings for code that is (or isn't) +# part of Chromium. + +config("chromium_code") { + if (is_win) { + cflags = [ "/W4" ] # Warning level 4. + + # Assume UTF-8 by default to avoid code page dependencies. + cflags += [ "/utf-8" ] + } else { + cflags = [ "-Wall" ] + if (treat_warnings_as_errors) { + cflags += [ "-Werror" ] + + # The compiler driver can sometimes (rarely) emit warnings before calling + # the actual linker. Make sure these warnings are treated as errors as + # well. + ldflags = [ "-Werror" ] + } + if (is_clang) { + # Enable -Wextra for chromium_code when we control the compiler. + cflags += [ "-Wextra" ] + } + + # In Chromium code, we define __STDC_foo_MACROS in order to get the + # C99 macros on Mac and Linux. + defines = [ + "__STDC_CONSTANT_MACROS", + "__STDC_FORMAT_MACROS", + ] + + if (!is_debug && !using_sanitizer && + (!is_linux || !is_clang || is_official_build)) { + # _FORTIFY_SOURCE isn't really supported by Clang now, see + # http://llvm.org/bugs/show_bug.cgi?id=16821. + # It seems to work fine with Ubuntu 12 headers though, so use it in + # official builds. + # + # Non-chromium code is not guaranteed to compile cleanly with + # _FORTIFY_SOURCE. Also, fortified build may fail when optimizations are + # disabled, so only do that for Release build. + defines += [ "_FORTIFY_SOURCE=2" ] + } + + if (is_mac || is_ios) { + cflags_objc = [ "-Wobjc-missing-property-synthesis" ] + cflags_objcc = [ "-Wobjc-missing-property-synthesis" ] + } + } + + configs = [ ":default_warnings" ] +} + +config("no_chromium_code") { + cflags = [] + cflags_cc = [] + defines = [] + + if (is_win) { + cflags += [ + "/W3", # Warning level 3. + "/wd4800", # Disable warning when forcing value to bool. + "/wd4267", # TODO(jschuh): size_t to int. + "/wd4996", # Deprecated function warning. + ] + defines += [ + "_CRT_NONSTDC_NO_WARNINGS", + "_CRT_NONSTDC_NO_DEPRECATE", + ] + } else { + # GCC may emit unsuppressible warnings so don't add -Werror for no chromium + # code. crbug.com/589724 + if (treat_warnings_as_errors && is_clang) { + cflags += [ "-Werror" ] + ldflags = [ "-Werror" ] + } + if (is_clang && !is_nacl) { + # TODO(thakis): Remove !is_nacl once + # https://codereview.webrtc.org/1552863002/ made its way into chromium. + cflags += [ "-Wall" ] + } + } + + if (is_clang) { + cflags += [ + # Lots of third-party libraries have unused variables. Instead of + # suppressing them individually, we just blanket suppress them here. + "-Wno-unused-variable", + ] + } + + if (is_linux || is_android) { + cflags_cc += [ + # Don't warn about hash_map in third-party code. + "-Wno-deprecated", + ] + } + + configs = [ ":default_warnings" ] +} + +# rtti ------------------------------------------------------------------------ +# +# Allows turning Run-Time Type Identification on or off. + +config("rtti") { + if (is_win) { + cflags_cc = [ "/GR" ] + } else { + cflags_cc = [ "-frtti" ] + } +} +config("no_rtti") { + # CFI diagnostics and UBsan vptr require RTTI. + if (!use_cfi_diag && !is_ubsan_vptr && !is_ubsan_security) { + if (is_win) { + cflags_cc = [ "/GR-" ] + } else { + cflags_cc = [ "-fno-rtti" ] + cflags_objcc = cflags_cc + } + } +} + +# Warnings --------------------------------------------------------------------- + +# This will generate warnings when using Clang if code generates exit-time +# destructors, which will slow down closing the program. +# TODO(thakis): Make this a blacklist instead, http://crbug.com/101600 +config("wexit_time_destructors") { + # TODO: Enable on Windows too, http://crbug.com/404525 + if (is_clang && !is_win) { + cflags = [ "-Wexit-time-destructors" ] + } +} + +# On Windows compiling on x64, VC will issue a warning when converting +# size_t to int because it will truncate the value. Our code should not have +# these warnings and one should use a static_cast or a checked_cast for the +# conversion depending on the case. However, a lot of code still needs to be +# fixed. Apply this config to such targets to disable the warning. +# +# Note that this can be applied regardless of platform and architecture to +# clean up the call sites. This will only apply the flag when necessary. +# +# TODO(jschuh): crbug.com/167187 fix this and delete this config. +config("no_size_t_to_int_warning") { + if (is_win && current_cpu == "x64") { + cflags = [ "/wd4267" ] + } +} + +# Some code presumes that pointers to structures/objects are compatible +# regardless of whether what they point to is already known to be valid. +# gcc 4.9 and earlier had no way of suppressing this warning without +# supressing the rest of them. Here we centralize the identification of +# the gcc 4.9 toolchains. +config("no_incompatible_pointer_warnings") { + cflags = [] + if (is_clang) { + cflags += [ "-Wno-incompatible-pointer-types" ] + } else if (current_cpu == "mipsel") { + cflags += [ "-w" ] + } else if (is_chromeos && current_cpu == "arm") { + cflags += [ "-w" ] + } +} + +# Optimization ----------------------------------------------------------------- +# +# The BUILDCONFIG file sets the "default_optimization" config on targets by +# default. It will be equivalent to either "optimize" (release) or +# "no_optimize" (debug) optimization configs. +# +# You can override the optimization level on a per-target basis by removing the +# default config and then adding the named one you want: +# +# configs -= [ "//build/config/compiler:default_optimization" ] +# configs += [ "//build/config/compiler:optimize_max" ] + +# Shared settings for both "optimize" and "optimize_max" configs. +# IMPORTANT: On Windows "/O1" and "/O2" must go before the common flags. +if (is_win) { + common_optimize_on_cflags = [ + "/Ob2", # Both explicit and auto inlining. + "/Oy-", # Disable omitting frame pointers, must be after /O2. + "/d2Zi+", # Improve debugging of optimized code. + "/Zc:inline", # Remove unreferenced COMDAT (faster links). + ] + if (!is_asan) { + common_optimize_on_cflags += [ + # Put data in separate COMDATs. This allows the linker + # to put bit-identical constants at the same address even if + # they're unrelated constants, which saves binary size. + # This optimization can't be used when ASan is enabled because + # it is not compatible with the ASan ODR checker. + "/Gw", + ] + } + common_optimize_on_ldflags = [] + if (!is_component_build) { + common_optimize_on_ldflags += [ "/OPT:ICF" ] # Redundant COMDAT folding. + } + if (is_official_build) { + common_optimize_on_ldflags += [ "/OPT:REF" ] # Remove unreferenced data. + if (!use_lld) { + common_optimize_on_ldflags += [ + # Set the number of LTCG code-gen threads to eight. The default is four. + # This gives a 5-10% link speedup. + "/cgthreads:8", + ] + if (use_incremental_wpo) { + # Incremental Link-time code generation. + common_optimize_on_ldflags += [ "/LTCG:INCREMENTAL" ] + } else { + common_optimize_on_ldflags += [ "/LTCG" ] # Link-time code generation. + } + } + if (full_wpo_on_official) { + if (use_incremental_wpo) { + arflags = [ "/LTCG:INCREMENTAL" ] + } else { + arflags = [ "/LTCG" ] + } + } + } +} else { + common_optimize_on_cflags = [] + common_optimize_on_ldflags = [] + + if (is_android) { + # TODO(jdduke) Re-enable on mips after resolving linking + # issues with libc++ (crbug.com/456380). + if (current_cpu != "mipsel" && current_cpu != "mips64el") { + common_optimize_on_ldflags += [ + # Warn in case of text relocations. + "-Wl,--warn-shared-textrel", + ] + } + } + + if (is_mac || is_ios) { + if (symbol_level == 2) { + # Mac dead code stripping requires symbols. + common_optimize_on_ldflags += [ "-Wl,-dead_strip" ] + } + } else { + # Non-Mac Posix flags. + + common_optimize_on_cflags += [ + # Don't emit the GCC version ident directives, they just end up in the + # .comment section taking up binary size. + "-fno-ident", + + # Put data and code in their own sections, so that unused symbols + # can be removed at link time with --gc-sections. + "-fdata-sections", + "-ffunction-sections", + ] + + common_optimize_on_ldflags += [ + # Specifically tell the linker to perform optimizations. + # See http://lwn.net/Articles/192624/ . + "-Wl,-O1", + "-Wl,--gc-sections", + ] + } +} + +config("default_stack_frames") { + if (is_posix && !(is_mac || is_ios)) { + if (using_sanitizer || enable_profiling || is_debug || + current_cpu == "arm64") { + # Explicitly ask for frame pointers, otherwise: + # * Stacks may be missing for sanitizer and profiling builds. + # * Debug tcmalloc can crash (crbug.com/636489). + # * Stacks may be missing for arm64 crash dumps (crbug.com/391706). + cflags = [ "-fno-omit-frame-pointer" ] + } else if (is_android) { + cflags = [ "-fomit-frame-pointer" ] + } + } +} + +# Default "optimization on" config. +config("optimize") { + if (is_win) { + # TODO(thakis): Remove is_clang here, https://crbug.com/598772 + if (is_official_build && full_wpo_on_official && !is_clang) { + common_optimize_on_cflags += [ + "/GL", # Whole program optimization. + + # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds. + # Probably anything that this would catch that wouldn't be caught in a + # normal build isn't going to actually be a bug, so the incremental + # value of C4702 for PGO builds is likely very small. + "/wd4702", + ] + } + + # Favor size over speed, /O1 must be before the common flags. The GYP + # build also specifies /Os and /GF but these are implied by /O1. + cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ] + } else if (optimize_for_size) { + # Favor size over speed. + cflags = [ "-Os" ] + common_optimize_on_cflags + } else { + cflags = [ "-O2" ] + common_optimize_on_cflags + } + ldflags = common_optimize_on_ldflags +} + +# Same config as 'optimize' but without the WPO flag. +config("optimize_no_wpo") { + if (is_win) { + # Favor size over speed, /O1 must be before the common flags. The GYP + # build also specifies /Os and /GF but these are implied by /O1. + cflags = [ "/O1" ] + common_optimize_on_cflags + [ "/Oi" ] + } else if (optimize_for_size) { + # Favor size over speed. + cflags = [ "-Os" ] + common_optimize_on_cflags + } else if (optimize_for_fuzzing) { + cflags = [ "-O1" ] + common_optimize_on_cflags + } else { + cflags = [ "-O2" ] + common_optimize_on_cflags + } + ldflags = common_optimize_on_ldflags +} + +# Turn off optimizations. +config("no_optimize") { + if (is_win) { + cflags = [ + "/Od", # Disable optimization. + "/Ob0", # Disable all inlining (on by default). + ] + } else if (is_android && !android_full_debug) { + # On Android we kind of optimize some things that don't affect debugging + # much even when optimization is disabled to get the binary size down. + cflags = [ "-Os" ] + } else { + cflags = [ "-O0" ] + ldflags = [] + } +} + +# Turns up the optimization level. On Windows, this implies whole program +# optimization and link-time code generation which is very expensive and should +# be used sparingly. +config("optimize_max") { + if (is_nacl_irt) { + # The NaCl IRT is a special case and always wants its own config. + # Various components do: + # if (!is_debug) { + # configs -= [ "//build/config/compiler:default_optimization" ] + # configs += [ "//build/config/compiler:optimize_max" ] + # } + # So this config has to have the selection logic just like + # "default_optimization", below. + configs = [ "//build/config/nacl:irt_optimize" ] + } else { + ldflags = common_optimize_on_ldflags + if (is_win) { + # Favor speed over size, /O2 must be before the common flags. The GYP + # build also specifies /Ot, /Oi, and /GF, but these are implied by /O2. + cflags = [ "/O2" ] + common_optimize_on_cflags + + if (is_official_build) { + if (!is_clang) { + cflags += [ + "/GL", # Whole program optimization. + + # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds. + # Probably anything that this would catch that wouldn't be caught + # in a normal build isn't going to actually be a bug, so the + # incremental value of C4702 for PGO builds is likely very small. + "/wd4702", + ] + } else if (is_clang && use_lld) { + cflags += [ "-flto" ] # Link-time optimization (whole program optimization). + } + } + } else if (optimize_for_fuzzing) { + cflags = [ "-O1" ] + common_optimize_on_cflags + } else { + cflags = [ "-O2" ] + common_optimize_on_cflags + } + } +} + +# This config can be used to override the default settings for per-component +# and whole-program optimization, optimizing the particular target for speed +# instead of code size. This config is exactly the same as "optimize_max" +# except that we use -O3 instead of -O2 on non-win, non-IRT platforms. +# +# TODO(crbug.com/621335) - rework how all of these configs are related +# so that we don't need this disclaimer. +config("optimize_speed") { + if (is_nacl_irt) { + # The NaCl IRT is a special case and always wants its own config. + # Various components do: + # if (!is_debug) { + # configs -= [ "//build/config/compiler:default_optimization" ] + # configs += [ "//build/config/compiler:optimize_max" ] + # } + # So this config has to have the selection logic just like + # "default_optimization", below. + configs = [ "//build/config/nacl:irt_optimize" ] + } else { + ldflags = common_optimize_on_ldflags + if (is_win) { + # Favor speed over size, /O2 must be before the common flags. The GYP + # build also specifies /Ot, /Oi, and /GF, but these are implied by /O2. + cflags = [ "/O2" ] + common_optimize_on_cflags + + # TODO(thakis): Remove is_clang here, https://crbug.com/598772 + if (is_official_build && !is_clang) { + cflags += [ + "/GL", # Whole program optimization. + + # Disable Warning 4702 ("Unreachable code") for the WPO/PGO builds. + # Probably anything that this would catch that wouldn't be caught in a + # normal build isn't going to actually be a bug, so the incremental + # value of C4702 for PGO builds is likely very small. + "/wd4702", + ] + } + } else if (optimize_for_fuzzing) { + cflags = [ "-O1" ] + common_optimize_on_cflags + } else { + cflags = [ "-O3" ] + common_optimize_on_cflags + } + } +} + +config("optimize_fuzzing") { + cflags = [ "-O1" ] + common_optimize_on_cflags + ldflags = common_optimize_on_ldflags + visibility = [ ":default_optimization" ] +} + +# The default optimization applied to all targets. This will be equivalent to +# either "optimize" or "no_optimize", depending on the build flags. +config("default_optimization") { + if (is_nacl_irt) { + # The NaCl IRT is a special case and always wants its own config. + # It gets optimized the same way regardless of the type of build. + configs = [ "//build/config/nacl:irt_optimize" ] + } else if (is_debug) { + configs = [ ":no_optimize" ] + } else if (optimize_for_fuzzing) { + assert(!is_win, "Fuzzing optimize level not supported on Windows") + configs = [ ":optimize_fuzzing" ] + } else { + configs = [ ":optimize" ] + } +} + +# GCC supports a form of profile-guided optimization called AFDO, which +# is used by ChromeOS in their official builds. However, +# //base/allocator:tcmalloc currently doesn't work correctly with AFDO +# so we provide separate config so that the flag can be disabled per-target. +# TODO(crbug.com/633719): Remove this config once tcmalloc works with AFDO +# or we remove tcmalloc or we stop using AFDO. +config("afdo") { + if (auto_profile_path != "" && current_toolchain == default_toolchain) { + cflags = [ "-fauto-profile=${auto_profile_path}" ] + } +} + +# Symbols ---------------------------------------------------------------------- + +# The BUILDCONFIG file sets the "default_symbols" config on targets by +# default. It will be equivalent to one the three specific symbol levels. +# +# You can override the symbol level on a per-target basis by removing the +# default config and then adding the named one you want: +# +# configs -= [ "//build/config/compiler:default_symbols" ] +# configs += [ "//build/config/compiler:symbols" ] + +# Full symbols. +config("symbols") { + if (is_win) { + cflags = [ "/Zi" ] # Produce PDB file, no edit and continue. + + if (is_win_fastlink) { + # Tell VS 2015+ to create a PDB that references debug + # information in .obj and .lib files instead of copying + # it all. This flag is incompatible with /PROFILE + ldflags = [ "/DEBUG:FASTLINK" ] + } else { + ldflags = [ "/DEBUG" ] + } + } else { + if (is_mac || is_ios) { + cflags = [ "-gdwarf-2" ] + if (is_mac && enable_dsyms) { + # If generating dSYMs, specify -fno-standalone-debug. This was + # originally specified for https://crbug.com/479841 because dsymutil + # could not handle a 4GB dSYM file. But dsymutil from Xcodes prior to + # version 7 also produces debug data that is incompatible with Breakpad + # dump_syms, so this is still required (https://crbug.com/622406). + cflags += [ "-fno-standalone-debug" ] + } + } else if (is_android) { + # Breakpad can't handle DWARF 4 symbols properly yet, so use DWARF 3 + # explicitly on android where we are hitting https://crbug.com/638485. + # The arguments MUST be in this order because of a gcc arg parsing bug. + cflags = [ + "-gdwarf-3", + "-g2", + ] + } else { + cflags = [ "-g2" ] + } + if (use_debug_fission) { + cflags += [ "-gsplit-dwarf" ] + } + asmflags = cflags + ldflags = [] + } +} + +# Minimal symbols. +config("minimal_symbols") { + if (is_win) { + # Linker symbols for backtraces only. + cflags = [] + ldflags = [ "/DEBUG" ] + } else { + if (is_android) { + # Breakpad can't handle DWARF 4 symbols properly yet, so use DWARF 3 + # explicitly on android where we are hitting https://crbug.com/638485. + # The arguments MUST be in this order because of a gcc arg parsing bug. + cflags = [ + "-gdwarf-3", + "-g1", + ] + } else { + cflags = [ "-g1" ] + } + if (use_debug_fission) { + cflags += [ "-gsplit-dwarf" ] + } + asmflags = cflags + ldflags = [] + } +} + +# No symbols. +config("no_symbols") { + if (!is_win) { + cflags = [ "-g0" ] + asmflags = cflags + } +} + +# Default symbols. +config("default_symbols") { + if (symbol_level == 0) { + configs = [ ":no_symbols" ] + } else if (symbol_level == 1) { + configs = [ ":minimal_symbols" ] + } else if (symbol_level == 2) { + configs = [ ":symbols" ] + } else { + assert(false) + } +} + +if (is_ios || is_mac) { + # On Mac and iOS, this enables support for ARC (automatic ref-counting). + # See http://clang.llvm.org/docs/AutomaticReferenceCounting.html. + config("enable_arc") { + common_flags = [ "-fobjc-arc" ] + cflags_objc = common_flags + cflags_objcc = common_flags + } +} diff --git a/samples/GN/BUILD.gn b/samples/GN/BUILD.gn new file mode 100644 index 00000000..dcefe370 --- /dev/null +++ b/samples/GN/BUILD.gn @@ -0,0 +1,2583 @@ +# 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. + +import("//build/config/android/config.gni") +import("//build/config/arm.gni") +import("//build/config/dcheck_always_on.gni") +import("//build/config/mips.gni") +import("//build/config/sanitizers/sanitizers.gni") + +if (is_android) { + import("//build/config/android/rules.gni") +} + +import("gni/v8.gni") +import("gni/isolate.gni") +import("//build_overrides/v8.gni") + +import("snapshot_toolchain.gni") + +declare_args() { + # Print to stdout on Android. + v8_android_log_stdout = false + + # Sets -DVERIFY_HEAP. + v8_enable_verify_heap = false + + # Enable compiler warnings when using V8_DEPRECATED apis. + v8_deprecation_warnings = false + + # Enable compiler warnings when using V8_DEPRECATE_SOON apis. + v8_imminent_deprecation_warnings = "" + + # Embeds the given script into the snapshot. + v8_embed_script = "" + + # Sets -dENABLE_DISASSEMBLER. + v8_enable_disassembler = "" + + # Sets -dENABLE_GDB_JIT_INTERFACE. + v8_enable_gdbjit = "" + + # Sets -dENABLE_HANDLE_ZAPPING. + v8_enable_handle_zapping = is_debug + + # Enable ECMAScript Internationalization API. Enabling this feature will + # add a dependency on the ICU library. + v8_enable_i18n_support = true + + # Enable slow dchecks. + v8_enable_slow_dchecks = false + + # Interpreted regexp engine exists as platform-independent alternative + # based where the regular expression is compiled to a bytecode. + v8_interpreted_regexp = false + + # Sets -dOBJECT_PRINT. + v8_object_print = "" + + # With post mortem support enabled, metadata is embedded into libv8 that + # describes various parameters of the VM for use by debuggers. See + # tools/gen-postmortem-metadata.py for details. + v8_postmortem_support = false + + # Similar to vfp but on MIPS. + v8_can_use_fpu_instructions = true + + # Similar to the ARM hard float ABI but on MIPS. + v8_use_mips_abi_hardfloat = true +} + +# Set project-specific defaults for some args if not provided in args.gn. The +# defaults can be set in the respective build_overrides files. +if (v8_imminent_deprecation_warnings == "") { + if (defined(v8_imminent_deprecation_warnings_default)) { + v8_imminent_deprecation_warnings = v8_imminent_deprecation_warnings_default + } else { + v8_imminent_deprecation_warnings = false + } +} +if (v8_enable_gdbjit == "") { + if (defined(v8_enable_gdbjit_default)) { + v8_enable_gdbjit = v8_enable_gdbjit_default + } else { + v8_enable_gdbjit = false + } +} + +# Derived defaults. +if (v8_object_print == "") { + v8_object_print = is_debug && !v8_optimized_debug +} +if (v8_enable_disassembler == "") { + v8_enable_disassembler = is_debug && !v8_optimized_debug +} + +v8_generated_peephole_source = "$target_gen_dir/bytecode-peephole-table.cc" +v8_random_seed = "314159265" +v8_toolset_for_shell = "host" + +############################################################################### +# Configurations +# +config("internal_config") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + include_dirs = [ "." ] + + if (is_component_build) { + defines = [ + "V8_SHARED", + "BUILDING_V8_SHARED", + ] + } +} + +config("internal_config_base") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + include_dirs = [ "." ] +} + +# This config should be applied to code using the libplatform. +config("libplatform_config") { + include_dirs = [ "include" ] +} + +# This config should be applied to code using the libsampler. +config("libsampler_config") { + include_dirs = [ "include" ] +} + +# This config should only be applied to code using V8 and not any V8 code +# itself. +config("external_config") { + if (is_component_build) { + defines = [ + "V8_SHARED", + "USING_V8_SHARED", + ] + } + include_dirs = [ "include" ] + libs = [] + if (is_android && current_toolchain != host_toolchain) { + libs += [ "log" ] + } +} + +# This config should only be applied to code that needs to be explicitly +# aware of whether we are using startup data or not. +config("external_startup_data") { + if (v8_use_external_startup_data) { + defines = [ "V8_USE_EXTERNAL_STARTUP_DATA" ] + } +} + +config("features") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + defines = [] + + if (v8_enable_disassembler) { + defines += [ "ENABLE_DISASSEMBLER" ] + } + if (v8_enable_gdbjit) { + defines += [ "ENABLE_GDB_JIT_INTERFACE" ] + } + if (v8_object_print) { + defines += [ "OBJECT_PRINT" ] + } + if (v8_enable_verify_heap) { + defines += [ "VERIFY_HEAP" ] + } + if (v8_interpreted_regexp) { + defines += [ "V8_INTERPRETED_REGEXP" ] + } + if (v8_deprecation_warnings) { + defines += [ "V8_DEPRECATION_WARNINGS" ] + } + if (v8_imminent_deprecation_warnings) { + defines += [ "V8_IMMINENT_DEPRECATION_WARNINGS" ] + } + if (v8_enable_i18n_support) { + defines += [ "V8_I18N_SUPPORT" ] + } + if (v8_enable_handle_zapping) { + defines += [ "ENABLE_HANDLE_ZAPPING" ] + } + if (v8_use_external_startup_data) { + defines += [ "V8_USE_EXTERNAL_STARTUP_DATA" ] + } +} + +config("toolchain") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + defines = [] + cflags = [] + ldflags = [] + + if (v8_current_cpu == "arm") { + defines += [ "V8_TARGET_ARCH_ARM" ] + if (arm_version == 7) { + defines += [ "CAN_USE_ARMV7_INSTRUCTIONS" ] + } + if (arm_fpu == "vfpv3-d16") { + defines += [ "CAN_USE_VFP3_INSTRUCTIONS" ] + } else if (arm_fpu == "vfpv3") { + defines += [ + "CAN_USE_VFP3_INSTRUCTIONS", + "CAN_USE_VFP32DREGS", + ] + } else if (arm_fpu == "neon") { + defines += [ + "CAN_USE_VFP3_INSTRUCTIONS", + "CAN_USE_VFP32DREGS", + "CAN_USE_NEON", + ] + } + + # TODO(jochen): Add support for arm_test_noprobe. + + if (current_cpu != "arm") { + # These defines ares used for the ARM simulator. + if (arm_float_abi == "hard") { + defines += [ "USE_EABI_HARDFLOAT=1" ] + } else if (arm_float_abi == "softfp") { + defines += [ "USE_EABI_HARDFLOAT=0" ] + } + } + } + if (v8_current_cpu == "arm64") { + defines += [ "V8_TARGET_ARCH_ARM64" ] + } + + # TODO(jochen): Add support for mips. + if (v8_current_cpu == "mipsel") { + defines += [ "V8_TARGET_ARCH_MIPS" ] + if (v8_can_use_fpu_instructions) { + defines += [ "CAN_USE_FPU_INSTRUCTIONS" ] + } + if (v8_use_mips_abi_hardfloat) { + defines += [ + "__mips_hard_float=1", + "CAN_USE_FPU_INSTRUCTIONS", + ] + } else { + defines += [ "__mips_soft_float=1" ] + } + if (mips_arch_variant == "r6") { + defines += [ + "_MIPS_ARCH_MIPS32R6", + "FPU_MODE_FP64", + ] + } else if (mips_arch_variant == "r2") { + defines += [ "_MIPS_ARCH_MIPS32R2" ] + if (mips_fpu_mode == "fp64") { + defines += [ "FPU_MODE_FP64" ] + } else if (mips_fpu_mode == "fpxx") { + defines += [ "FPU_MODE_FPXX" ] + } else if (mips_fpu_mode == "fp32") { + defines += [ "FPU_MODE_FP32" ] + } + } else if (mips_arch_variant == "r1") { + defines += [ "FPU_MODE_FP32" ] + } + + # TODO(jochen): Add support for mips_arch_variant rx and loongson. + } + + # TODO(jochen): Add support for mips64. + if (v8_current_cpu == "mips64el") { + defines += [ "V8_TARGET_ARCH_MIPS64" ] + if (v8_can_use_fpu_instructions) { + defines += [ "CAN_USE_FPU_INSTRUCTIONS" ] + } + + # TODO(jochen): Add support for big endian host byteorder. + defines += [ "V8_TARGET_ARCH_MIPS64_LE" ] + if (v8_use_mips_abi_hardfloat) { + defines += [ + "__mips_hard_float=1", + "CAN_USE_FPU_INSTRUCTIONS", + ] + } else { + defines += [ "__mips_soft_float=1" ] + } + if (mips_arch_variant == "r6") { + defines += [ "_MIPS_ARCH_MIPS64R6" ] + } else if (mips_arch_variant == "r2") { + defines += [ "_MIPS_ARCH_MIPS64R2" ] + } + } + if (v8_current_cpu == "s390" || v8_current_cpu == "s390x") { + defines += [ "V8_TARGET_ARCH_S390" ] + if (v8_current_cpu == "s390x") { + defines += [ "V8_TARGET_ARCH_S390X" ] + } + if (host_cpu == "x64" || host_cpu == "x86") { + defines += [ "V8_TARGET_ARCH_S390_LE_SIM" ] + } + } + if (v8_current_cpu == "x86") { + defines += [ "V8_TARGET_ARCH_IA32" ] + if (is_win) { + # Ensure no surprising artifacts from 80bit double math with x86. + cflags += [ "/arch:SSE2" ] + } + } + if (v8_current_cpu == "x64") { + defines += [ "V8_TARGET_ARCH_X64" ] + if (is_win) { + # Increase the initial stack size. The default is 1MB, this is 2MB. This + # applies only to executables and shared libraries produced by V8 since + # ldflags are not pushed to dependants. + ldflags += [ "/STACK:2097152" ] + } + } + if (is_android && v8_android_log_stdout) { + defines += [ "V8_ANDROID_LOG_STDOUT" ] + } + + # TODO(jochen): Support v8_enable_prof on Windows. + # TODO(jochen): Add support for compiling with simulators. + + if (is_debug) { + if (is_linux && v8_enable_backtrace) { + ldflags += [ "-rdynamic" ] + } + + # TODO(jochen): Add support for different debug optimization levels. + defines += [ + "ENABLE_DISASSEMBLER", + "V8_ENABLE_CHECKS", + "OBJECT_PRINT", + "VERIFY_HEAP", + "DEBUG", + "TRACE_MAPS", + ] + if (v8_enable_slow_dchecks) { + defines += [ "ENABLE_SLOW_DCHECKS" ] + } + } else if (dcheck_always_on) { + defines += [ "DEBUG" ] + } +} + +############################################################################### +# Actions +# + +action("js2c") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + script = "tools/js2c.py" + + # The script depends on this other script, this rule causes a rebuild if it + # changes. + inputs = [ + "tools/jsmin.py", + ] + + # NOSORT + sources = [ + "src/js/macros.py", + "src/messages.h", + "src/js/prologue.js", + "src/js/runtime.js", + "src/js/v8natives.js", + "src/js/symbol.js", + "src/js/array.js", + "src/js/string.js", + "src/js/math.js", + "src/js/regexp.js", + "src/js/arraybuffer.js", + "src/js/typedarray.js", + "src/js/iterator-prototype.js", + "src/js/collection.js", + "src/js/weak-collection.js", + "src/js/collection-iterator.js", + "src/js/promise.js", + "src/js/messages.js", + "src/js/array-iterator.js", + "src/js/string-iterator.js", + "src/js/templates.js", + "src/js/spread.js", + "src/js/proxy.js", + "src/debug/mirrors.js", + "src/debug/debug.js", + "src/debug/liveedit.js", + ] + + outputs = [ + "$target_gen_dir/libraries.cc", + ] + + if (v8_enable_i18n_support) { + sources += [ "src/js/i18n.js" ] + } + + args = [ + rebase_path("$target_gen_dir/libraries.cc", root_build_dir), + "CORE", + ] + rebase_path(sources, root_build_dir) + + if (v8_use_external_startup_data) { + outputs += [ "$target_gen_dir/libraries.bin" ] + args += [ + "--startup_blob", + rebase_path("$target_gen_dir/libraries.bin", root_build_dir), + ] + } +} + +action("js2c_experimental") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + script = "tools/js2c.py" + + # The script depends on this other script, this rule causes a rebuild if it + # changes. + inputs = [ + "tools/jsmin.py", + ] + + # NOSORT + sources = [ + "src/js/macros.py", + "src/messages.h", + "src/js/harmony-async-await.js", + "src/js/harmony-atomics.js", + "src/js/harmony-simd.js", + "src/js/harmony-string-padding.js", + ] + + outputs = [ + "$target_gen_dir/experimental-libraries.cc", + ] + + if (v8_enable_i18n_support) { + sources += [ + "src/js/icu-case-mapping.js", + "src/js/intl-extra.js", + ] + } + + args = [ + rebase_path("$target_gen_dir/experimental-libraries.cc", + root_build_dir), + "EXPERIMENTAL", + ] + rebase_path(sources, root_build_dir) + + if (v8_use_external_startup_data) { + outputs += [ "$target_gen_dir/libraries_experimental.bin" ] + args += [ + "--startup_blob", + rebase_path("$target_gen_dir/libraries_experimental.bin", root_build_dir), + ] + } +} + +action("js2c_extras") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + script = "tools/js2c.py" + + # The script depends on this other script, this rule causes a rebuild if it + # changes. + inputs = [ + "tools/jsmin.py", + ] + + sources = v8_extra_library_files + + outputs = [ + "$target_gen_dir/extras-libraries.cc", + ] + + args = [ + rebase_path("$target_gen_dir/extras-libraries.cc", root_build_dir), + "EXTRAS", + ] + rebase_path(sources, root_build_dir) + + if (v8_use_external_startup_data) { + outputs += [ "$target_gen_dir/libraries_extras.bin" ] + args += [ + "--startup_blob", + rebase_path("$target_gen_dir/libraries_extras.bin", root_build_dir), + ] + } +} + +action("js2c_experimental_extras") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + script = "tools/js2c.py" + + # The script depends on this other script, this rule causes a rebuild if it + # changes. + inputs = [ + "tools/jsmin.py", + ] + + sources = v8_experimental_extra_library_files + + outputs = [ + "$target_gen_dir/experimental-extras-libraries.cc", + ] + + args = [ + rebase_path("$target_gen_dir/experimental-extras-libraries.cc", + root_build_dir), + "EXPERIMENTAL_EXTRAS", + ] + rebase_path(sources, root_build_dir) + + if (v8_use_external_startup_data) { + outputs += [ "$target_gen_dir/libraries_experimental_extras.bin" ] + args += [ + "--startup_blob", + rebase_path("$target_gen_dir/libraries_experimental_extras.bin", + root_build_dir), + ] + } +} + +action("d8_js2c") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + script = "tools/js2c.py" + + # NOSORT + inputs = [ + "src/d8.js", + "src/js/macros.py", + ] + + outputs = [ + "$target_gen_dir/d8-js.cc", + ] + + args = rebase_path(outputs, root_build_dir) + [ "D8" ] + + rebase_path(inputs, root_build_dir) +} + +if (is_android && enable_java_templates) { + android_assets("v8_external_startup_data_assets") { + if (v8_use_external_startup_data) { + deps = [ + "//v8", + ] + sources = [ + "$root_out_dir/natives_blob.bin", + ] + renaming_sources = [ "$root_out_dir/snapshot_blob.bin" ] + if (current_cpu == "arm" || current_cpu == "x86" || + current_cpu == "mipsel") { + renaming_destinations = [ "snapshot_blob_32.bin" ] + } else { + renaming_destinations = [ "snapshot_blob_64.bin" ] + } + disable_compression = true + } + } +} + +if (v8_use_external_startup_data) { + action("natives_blob") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + deps = [ + ":js2c", + ":js2c_experimental", + ":js2c_experimental_extras", + ":js2c_extras", + ] + + # NOSORT + sources = [ + "$target_gen_dir/libraries.bin", + "$target_gen_dir/libraries_experimental.bin", + "$target_gen_dir/libraries_extras.bin", + "$target_gen_dir/libraries_experimental_extras.bin", + ] + + outputs = [ + "$root_out_dir/natives_blob.bin", + ] + + script = "tools/concatenate-files.py" + + args = rebase_path(sources + outputs, root_build_dir) + } +} + +action("postmortem-metadata") { + # Only targets in this file and the top-level visibility target can + # depend on this. + visibility = [ + ":*", + "//:gn_visibility", + ] + + script = "tools/gen-postmortem-metadata.py" + + # NOSORT + sources = [ + "src/objects.h", + "src/objects-inl.h", + ] + + outputs = [ + "$target_gen_dir/debug-support.cc", + ] + + args = rebase_path(outputs, root_build_dir) + + rebase_path(sources, root_build_dir) +} + +action("run_mksnapshot") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + deps = [ + ":mksnapshot($v8_snapshot_toolchain)", + ] + + script = "tools/run.py" + + sources = [] + + outputs = [ + "$target_gen_dir/snapshot.cc", + ] + + args = [ + "./" + rebase_path(get_label_info(":mksnapshot($v8_snapshot_toolchain)", + "root_out_dir") + "/mksnapshot", + root_build_dir), + "--startup_src", + rebase_path("$target_gen_dir/snapshot.cc", root_build_dir), + ] + + if (v8_random_seed != "0") { + args += [ + "--random-seed", + v8_random_seed, + ] + } + + if (v8_use_external_startup_data) { + outputs += [ "$root_out_dir/snapshot_blob.bin" ] + args += [ + "--startup_blob", + rebase_path("$root_out_dir/snapshot_blob.bin", root_build_dir), + ] + } + + if (v8_embed_script != "") { + sources += [ v8_embed_script ] + args += [ rebase_path(v8_embed_script, root_build_dir) ] + } +} + +action("run_mkpeephole") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + deps = [ + ":mkpeephole($v8_snapshot_toolchain)", + ] + + outputs = [ + v8_generated_peephole_source, + ] + + sources = [] + + script = "tools/run.py" + + args = [ + "./" + rebase_path(get_label_info(":mkpeephole($v8_snapshot_toolchain)", + "root_out_dir") + "/mkpeephole", + root_build_dir), + rebase_path(v8_generated_peephole_source, root_build_dir), + ] +} + +action("v8_dump_build_config") { + script = "tools/testrunner/utils/dump_build_config.py" + outputs = [ + "$root_out_dir/v8_build_config.json", + ] + args = [ + rebase_path("$root_out_dir/v8_build_config.json", root_build_dir), + "dcheck_always_on=$dcheck_always_on", + "is_asan=$is_asan", + "is_cfi=$is_cfi", + "is_component_build=$is_component_build", + "is_debug=$is_debug", + "is_msan=$is_msan", + "is_tsan=$is_tsan", + "target_cpu=\"$target_cpu\"", + "v8_enable_i18n_support=$v8_enable_i18n_support", + "v8_target_cpu=\"$v8_target_cpu\"", + "v8_use_snapshot=$v8_use_snapshot", + ] +} + +############################################################################### +# Source Sets (aka static libraries) +# + +source_set("v8_maybe_snapshot") { + if (v8_use_snapshot && v8_use_external_startup_data) { + public_deps = [ + ":v8_external_snapshot", + ] + } else if (v8_use_snapshot) { + public_deps = [ + ":v8_snapshot", + ] + } else { + # Ignore v8_use_external_startup_data setting if no snapshot is used. + public_deps = [ + ":v8_nosnapshot", + ] + } +} + +v8_source_set("v8_nosnapshot") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + deps = [ + ":js2c", + ":js2c_experimental", + ":js2c_experimental_extras", + ":js2c_extras", + ":v8_base", + ] + + sources = [ + "$target_gen_dir/experimental-extras-libraries.cc", + "$target_gen_dir/experimental-libraries.cc", + "$target_gen_dir/extras-libraries.cc", + "$target_gen_dir/libraries.cc", + "src/snapshot/snapshot-empty.cc", + ] + + configs = [ ":internal_config" ] +} + +v8_source_set("v8_snapshot") { + # Only targets in this file and the top-level visibility target can + # depend on this. + visibility = [ + ":*", + "//:gn_visibility", + ] + + deps = [ + ":js2c", + ":js2c_experimental", + ":js2c_experimental_extras", + ":js2c_extras", + ":v8_base", + ] + public_deps = [ + # This should be public so downstream targets can declare the snapshot + # output file as their inputs. + ":run_mksnapshot", + ] + + sources = [ + "$target_gen_dir/experimental-extras-libraries.cc", + "$target_gen_dir/experimental-libraries.cc", + "$target_gen_dir/extras-libraries.cc", + "$target_gen_dir/libraries.cc", + "$target_gen_dir/snapshot.cc", + ] + + configs = [ ":internal_config" ] +} + +if (v8_use_external_startup_data) { + v8_source_set("v8_external_snapshot") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + deps = [ + ":js2c", + ":js2c_experimental", + ":js2c_experimental_extras", + ":js2c_extras", + ":v8_base", + ] + public_deps = [ + ":natives_blob", + ":run_mksnapshot", + ] + + sources = [ + "src/snapshot/natives-external.cc", + "src/snapshot/snapshot-external.cc", + ] + + configs = [ ":internal_config" ] + } +} + +v8_source_set("v8_base") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + sources = [ + "//base/trace_event/common/trace_event_common.h", + "include/v8-debug.h", + "include/v8-experimental.h", + "include/v8-platform.h", + "include/v8-profiler.h", + "include/v8-testing.h", + "include/v8-util.h", + "include/v8-version.h", + "include/v8.h", + "include/v8config.h", + "src/accessors.cc", + "src/accessors.h", + "src/address-map.cc", + "src/address-map.h", + "src/allocation-site-scopes.cc", + "src/allocation-site-scopes.h", + "src/allocation.cc", + "src/allocation.h", + "src/api-arguments-inl.h", + "src/api-arguments.cc", + "src/api-arguments.h", + "src/api-experimental.cc", + "src/api-experimental.h", + "src/api-natives.cc", + "src/api-natives.h", + "src/api.cc", + "src/api.h", + "src/arguments.cc", + "src/arguments.h", + "src/asmjs/asm-js.cc", + "src/asmjs/asm-js.h", + "src/asmjs/asm-typer.cc", + "src/asmjs/asm-typer.h", + "src/asmjs/asm-types.cc", + "src/asmjs/asm-types.h", + "src/asmjs/asm-wasm-builder.cc", + "src/asmjs/asm-wasm-builder.h", + "src/assembler.cc", + "src/assembler.h", + "src/assert-scope.cc", + "src/assert-scope.h", + "src/ast/ast-expression-rewriter.cc", + "src/ast/ast-expression-rewriter.h", + "src/ast/ast-literal-reindexer.cc", + "src/ast/ast-literal-reindexer.h", + "src/ast/ast-numbering.cc", + "src/ast/ast-numbering.h", + "src/ast/ast-traversal-visitor.h", + "src/ast/ast-type-bounds.h", + "src/ast/ast-value-factory.cc", + "src/ast/ast-value-factory.h", + "src/ast/ast.cc", + "src/ast/ast.h", + "src/ast/context-slot-cache.cc", + "src/ast/context-slot-cache.h", + "src/ast/modules.cc", + "src/ast/modules.h", + "src/ast/prettyprinter.cc", + "src/ast/prettyprinter.h", + "src/ast/scopeinfo.cc", + "src/ast/scopeinfo.h", + "src/ast/scopes.cc", + "src/ast/scopes.h", + "src/ast/variables.cc", + "src/ast/variables.h", + "src/background-parsing-task.cc", + "src/background-parsing-task.h", + "src/bailout-reason.cc", + "src/bailout-reason.h", + "src/basic-block-profiler.cc", + "src/basic-block-profiler.h", + "src/bignum-dtoa.cc", + "src/bignum-dtoa.h", + "src/bignum.cc", + "src/bignum.h", + "src/bit-vector.cc", + "src/bit-vector.h", + "src/bootstrapper.cc", + "src/bootstrapper.h", + "src/builtins/builtins-api.cc", + "src/builtins/builtins-array.cc", + "src/builtins/builtins-arraybuffer.cc", + "src/builtins/builtins-boolean.cc", + "src/builtins/builtins-call.cc", + "src/builtins/builtins-callsite.cc", + "src/builtins/builtins-conversion.cc", + "src/builtins/builtins-dataview.cc", + "src/builtins/builtins-date.cc", + "src/builtins/builtins-debug.cc", + "src/builtins/builtins-error.cc", + "src/builtins/builtins-function.cc", + "src/builtins/builtins-generator.cc", + "src/builtins/builtins-global.cc", + "src/builtins/builtins-handler.cc", + "src/builtins/builtins-internal.cc", + "src/builtins/builtins-interpreter.cc", + "src/builtins/builtins-json.cc", + "src/builtins/builtins-math.cc", + "src/builtins/builtins-number.cc", + "src/builtins/builtins-object.cc", + "src/builtins/builtins-proxy.cc", + "src/builtins/builtins-reflect.cc", + "src/builtins/builtins-sharedarraybuffer.cc", + "src/builtins/builtins-string.cc", + "src/builtins/builtins-symbol.cc", + "src/builtins/builtins-typedarray.cc", + "src/builtins/builtins-utils.h", + "src/builtins/builtins.cc", + "src/builtins/builtins.h", + "src/cached-powers.cc", + "src/cached-powers.h", + "src/cancelable-task.cc", + "src/cancelable-task.h", + "src/char-predicates-inl.h", + "src/char-predicates.cc", + "src/char-predicates.h", + "src/checks.h", + "src/code-events.h", + "src/code-factory.cc", + "src/code-factory.h", + "src/code-stub-assembler.cc", + "src/code-stub-assembler.h", + "src/code-stubs-hydrogen.cc", + "src/code-stubs.cc", + "src/code-stubs.h", + "src/codegen.cc", + "src/codegen.h", + "src/collector.h", + "src/compilation-cache.cc", + "src/compilation-cache.h", + "src/compilation-dependencies.cc", + "src/compilation-dependencies.h", + "src/compilation-statistics.cc", + "src/compilation-statistics.h", + "src/compiler-dispatcher/compiler-dispatcher-job.cc", + "src/compiler-dispatcher/compiler-dispatcher-job.h", + "src/compiler-dispatcher/optimizing-compile-dispatcher.cc", + "src/compiler-dispatcher/optimizing-compile-dispatcher.h", + "src/compiler.cc", + "src/compiler.h", + "src/compiler/access-builder.cc", + "src/compiler/access-builder.h", + "src/compiler/access-info.cc", + "src/compiler/access-info.h", + "src/compiler/all-nodes.cc", + "src/compiler/all-nodes.h", + "src/compiler/ast-graph-builder.cc", + "src/compiler/ast-graph-builder.h", + "src/compiler/ast-loop-assignment-analyzer.cc", + "src/compiler/ast-loop-assignment-analyzer.h", + "src/compiler/basic-block-instrumentor.cc", + "src/compiler/basic-block-instrumentor.h", + "src/compiler/branch-elimination.cc", + "src/compiler/branch-elimination.h", + "src/compiler/bytecode-branch-analysis.cc", + "src/compiler/bytecode-branch-analysis.h", + "src/compiler/bytecode-graph-builder.cc", + "src/compiler/bytecode-graph-builder.h", + "src/compiler/bytecode-loop-analysis.cc", + "src/compiler/bytecode-loop-analysis.h", + "src/compiler/c-linkage.cc", + "src/compiler/checkpoint-elimination.cc", + "src/compiler/checkpoint-elimination.h", + "src/compiler/code-assembler.cc", + "src/compiler/code-assembler.h", + "src/compiler/code-generator-impl.h", + "src/compiler/code-generator.cc", + "src/compiler/code-generator.h", + "src/compiler/common-node-cache.cc", + "src/compiler/common-node-cache.h", + "src/compiler/common-operator-reducer.cc", + "src/compiler/common-operator-reducer.h", + "src/compiler/common-operator.cc", + "src/compiler/common-operator.h", + "src/compiler/control-builders.cc", + "src/compiler/control-builders.h", + "src/compiler/control-equivalence.cc", + "src/compiler/control-equivalence.h", + "src/compiler/control-flow-optimizer.cc", + "src/compiler/control-flow-optimizer.h", + "src/compiler/dead-code-elimination.cc", + "src/compiler/dead-code-elimination.h", + "src/compiler/diamond.h", + "src/compiler/effect-control-linearizer.cc", + "src/compiler/effect-control-linearizer.h", + "src/compiler/escape-analysis-reducer.cc", + "src/compiler/escape-analysis-reducer.h", + "src/compiler/escape-analysis.cc", + "src/compiler/escape-analysis.h", + "src/compiler/frame-elider.cc", + "src/compiler/frame-elider.h", + "src/compiler/frame-states.cc", + "src/compiler/frame-states.h", + "src/compiler/frame.cc", + "src/compiler/frame.h", + "src/compiler/gap-resolver.cc", + "src/compiler/gap-resolver.h", + "src/compiler/graph-reducer.cc", + "src/compiler/graph-reducer.h", + "src/compiler/graph-replay.cc", + "src/compiler/graph-replay.h", + "src/compiler/graph-trimmer.cc", + "src/compiler/graph-trimmer.h", + "src/compiler/graph-visualizer.cc", + "src/compiler/graph-visualizer.h", + "src/compiler/graph.cc", + "src/compiler/graph.h", + "src/compiler/instruction-codes.h", + "src/compiler/instruction-scheduler.cc", + "src/compiler/instruction-scheduler.h", + "src/compiler/instruction-selector-impl.h", + "src/compiler/instruction-selector.cc", + "src/compiler/instruction-selector.h", + "src/compiler/instruction.cc", + "src/compiler/instruction.h", + "src/compiler/int64-lowering.cc", + "src/compiler/int64-lowering.h", + "src/compiler/js-builtin-reducer.cc", + "src/compiler/js-builtin-reducer.h", + "src/compiler/js-call-reducer.cc", + "src/compiler/js-call-reducer.h", + "src/compiler/js-context-specialization.cc", + "src/compiler/js-context-specialization.h", + "src/compiler/js-create-lowering.cc", + "src/compiler/js-create-lowering.h", + "src/compiler/js-frame-specialization.cc", + "src/compiler/js-frame-specialization.h", + "src/compiler/js-generic-lowering.cc", + "src/compiler/js-generic-lowering.h", + "src/compiler/js-global-object-specialization.cc", + "src/compiler/js-global-object-specialization.h", + "src/compiler/js-graph.cc", + "src/compiler/js-graph.h", + "src/compiler/js-inlining-heuristic.cc", + "src/compiler/js-inlining-heuristic.h", + "src/compiler/js-inlining.cc", + "src/compiler/js-inlining.h", + "src/compiler/js-intrinsic-lowering.cc", + "src/compiler/js-intrinsic-lowering.h", + "src/compiler/js-native-context-specialization.cc", + "src/compiler/js-native-context-specialization.h", + "src/compiler/js-operator.cc", + "src/compiler/js-operator.h", + "src/compiler/js-typed-lowering.cc", + "src/compiler/js-typed-lowering.h", + "src/compiler/jump-threading.cc", + "src/compiler/jump-threading.h", + "src/compiler/linkage.cc", + "src/compiler/linkage.h", + "src/compiler/live-range-separator.cc", + "src/compiler/live-range-separator.h", + "src/compiler/liveness-analyzer.cc", + "src/compiler/liveness-analyzer.h", + "src/compiler/load-elimination.cc", + "src/compiler/load-elimination.h", + "src/compiler/loop-analysis.cc", + "src/compiler/loop-analysis.h", + "src/compiler/loop-peeling.cc", + "src/compiler/loop-peeling.h", + "src/compiler/loop-variable-optimizer.cc", + "src/compiler/loop-variable-optimizer.h", + "src/compiler/machine-operator-reducer.cc", + "src/compiler/machine-operator-reducer.h", + "src/compiler/machine-operator.cc", + "src/compiler/machine-operator.h", + "src/compiler/memory-optimizer.cc", + "src/compiler/memory-optimizer.h", + "src/compiler/move-optimizer.cc", + "src/compiler/move-optimizer.h", + "src/compiler/node-aux-data.h", + "src/compiler/node-cache.cc", + "src/compiler/node-cache.h", + "src/compiler/node-marker.cc", + "src/compiler/node-marker.h", + "src/compiler/node-matchers.cc", + "src/compiler/node-matchers.h", + "src/compiler/node-properties.cc", + "src/compiler/node-properties.h", + "src/compiler/node.cc", + "src/compiler/node.h", + "src/compiler/opcodes.cc", + "src/compiler/opcodes.h", + "src/compiler/operation-typer.cc", + "src/compiler/operation-typer.h", + "src/compiler/operator-properties.cc", + "src/compiler/operator-properties.h", + "src/compiler/operator.cc", + "src/compiler/operator.h", + "src/compiler/osr.cc", + "src/compiler/osr.h", + "src/compiler/pipeline-statistics.cc", + "src/compiler/pipeline-statistics.h", + "src/compiler/pipeline.cc", + "src/compiler/pipeline.h", + "src/compiler/raw-machine-assembler.cc", + "src/compiler/raw-machine-assembler.h", + "src/compiler/redundancy-elimination.cc", + "src/compiler/redundancy-elimination.h", + "src/compiler/register-allocator-verifier.cc", + "src/compiler/register-allocator-verifier.h", + "src/compiler/register-allocator.cc", + "src/compiler/register-allocator.h", + "src/compiler/representation-change.cc", + "src/compiler/representation-change.h", + "src/compiler/schedule.cc", + "src/compiler/schedule.h", + "src/compiler/scheduler.cc", + "src/compiler/scheduler.h", + "src/compiler/select-lowering.cc", + "src/compiler/select-lowering.h", + "src/compiler/simplified-lowering.cc", + "src/compiler/simplified-lowering.h", + "src/compiler/simplified-operator-reducer.cc", + "src/compiler/simplified-operator-reducer.h", + "src/compiler/simplified-operator.cc", + "src/compiler/simplified-operator.h", + "src/compiler/source-position.cc", + "src/compiler/source-position.h", + "src/compiler/state-values-utils.cc", + "src/compiler/state-values-utils.h", + "src/compiler/store-store-elimination.cc", + "src/compiler/store-store-elimination.h", + "src/compiler/tail-call-optimization.cc", + "src/compiler/tail-call-optimization.h", + "src/compiler/type-hint-analyzer.cc", + "src/compiler/type-hint-analyzer.h", + "src/compiler/type-hints.cc", + "src/compiler/type-hints.h", + "src/compiler/typer.cc", + "src/compiler/typer.h", + "src/compiler/unwinding-info-writer.h", + "src/compiler/value-numbering-reducer.cc", + "src/compiler/value-numbering-reducer.h", + "src/compiler/verifier.cc", + "src/compiler/verifier.h", + "src/compiler/wasm-compiler.cc", + "src/compiler/wasm-compiler.h", + "src/compiler/wasm-linkage.cc", + "src/compiler/zone-pool.cc", + "src/compiler/zone-pool.h", + "src/context-measure.cc", + "src/context-measure.h", + "src/contexts-inl.h", + "src/contexts.cc", + "src/contexts.h", + "src/conversions-inl.h", + "src/conversions.cc", + "src/conversions.h", + "src/counters-inl.h", + "src/counters.cc", + "src/counters.h", + "src/crankshaft/compilation-phase.cc", + "src/crankshaft/compilation-phase.h", + "src/crankshaft/hydrogen-alias-analysis.h", + "src/crankshaft/hydrogen-bce.cc", + "src/crankshaft/hydrogen-bce.h", + "src/crankshaft/hydrogen-canonicalize.cc", + "src/crankshaft/hydrogen-canonicalize.h", + "src/crankshaft/hydrogen-check-elimination.cc", + "src/crankshaft/hydrogen-check-elimination.h", + "src/crankshaft/hydrogen-dce.cc", + "src/crankshaft/hydrogen-dce.h", + "src/crankshaft/hydrogen-dehoist.cc", + "src/crankshaft/hydrogen-dehoist.h", + "src/crankshaft/hydrogen-environment-liveness.cc", + "src/crankshaft/hydrogen-environment-liveness.h", + "src/crankshaft/hydrogen-escape-analysis.cc", + "src/crankshaft/hydrogen-escape-analysis.h", + "src/crankshaft/hydrogen-flow-engine.h", + "src/crankshaft/hydrogen-gvn.cc", + "src/crankshaft/hydrogen-gvn.h", + "src/crankshaft/hydrogen-infer-representation.cc", + "src/crankshaft/hydrogen-infer-representation.h", + "src/crankshaft/hydrogen-infer-types.cc", + "src/crankshaft/hydrogen-infer-types.h", + "src/crankshaft/hydrogen-instructions.cc", + "src/crankshaft/hydrogen-instructions.h", + "src/crankshaft/hydrogen-load-elimination.cc", + "src/crankshaft/hydrogen-load-elimination.h", + "src/crankshaft/hydrogen-mark-deoptimize.cc", + "src/crankshaft/hydrogen-mark-deoptimize.h", + "src/crankshaft/hydrogen-mark-unreachable.cc", + "src/crankshaft/hydrogen-mark-unreachable.h", + "src/crankshaft/hydrogen-osr.cc", + "src/crankshaft/hydrogen-osr.h", + "src/crankshaft/hydrogen-range-analysis.cc", + "src/crankshaft/hydrogen-range-analysis.h", + "src/crankshaft/hydrogen-redundant-phi.cc", + "src/crankshaft/hydrogen-redundant-phi.h", + "src/crankshaft/hydrogen-removable-simulates.cc", + "src/crankshaft/hydrogen-removable-simulates.h", + "src/crankshaft/hydrogen-representation-changes.cc", + "src/crankshaft/hydrogen-representation-changes.h", + "src/crankshaft/hydrogen-sce.cc", + "src/crankshaft/hydrogen-sce.h", + "src/crankshaft/hydrogen-store-elimination.cc", + "src/crankshaft/hydrogen-store-elimination.h", + "src/crankshaft/hydrogen-types.cc", + "src/crankshaft/hydrogen-types.h", + "src/crankshaft/hydrogen-uint32-analysis.cc", + "src/crankshaft/hydrogen-uint32-analysis.h", + "src/crankshaft/hydrogen.cc", + "src/crankshaft/hydrogen.h", + "src/crankshaft/lithium-allocator-inl.h", + "src/crankshaft/lithium-allocator.cc", + "src/crankshaft/lithium-allocator.h", + "src/crankshaft/lithium-codegen.cc", + "src/crankshaft/lithium-codegen.h", + "src/crankshaft/lithium.cc", + "src/crankshaft/lithium.h", + "src/crankshaft/typing.cc", + "src/crankshaft/typing.h", + "src/crankshaft/unique.h", + "src/date.cc", + "src/date.h", + "src/dateparser-inl.h", + "src/dateparser.cc", + "src/dateparser.h", + "src/debug/debug-evaluate.cc", + "src/debug/debug-evaluate.h", + "src/debug/debug-frames.cc", + "src/debug/debug-frames.h", + "src/debug/debug-scopes.cc", + "src/debug/debug-scopes.h", + "src/debug/debug.cc", + "src/debug/debug.h", + "src/debug/liveedit.cc", + "src/debug/liveedit.h", + "src/deoptimize-reason.cc", + "src/deoptimize-reason.h", + "src/deoptimizer.cc", + "src/deoptimizer.h", + "src/disasm.h", + "src/disassembler.cc", + "src/disassembler.h", + "src/diy-fp.cc", + "src/diy-fp.h", + "src/double.h", + "src/dtoa.cc", + "src/dtoa.h", + "src/effects.h", + "src/eh-frame.cc", + "src/eh-frame.h", + "src/elements-kind.cc", + "src/elements-kind.h", + "src/elements.cc", + "src/elements.h", + "src/execution.cc", + "src/execution.h", + "src/extensions/externalize-string-extension.cc", + "src/extensions/externalize-string-extension.h", + "src/extensions/free-buffer-extension.cc", + "src/extensions/free-buffer-extension.h", + "src/extensions/gc-extension.cc", + "src/extensions/gc-extension.h", + "src/extensions/ignition-statistics-extension.cc", + "src/extensions/ignition-statistics-extension.h", + "src/extensions/statistics-extension.cc", + "src/extensions/statistics-extension.h", + "src/extensions/trigger-failure-extension.cc", + "src/extensions/trigger-failure-extension.h", + "src/external-reference-table.cc", + "src/external-reference-table.h", + "src/factory.cc", + "src/factory.h", + "src/fast-accessor-assembler.cc", + "src/fast-accessor-assembler.h", + "src/fast-dtoa.cc", + "src/fast-dtoa.h", + "src/field-index-inl.h", + "src/field-index.h", + "src/field-type.cc", + "src/field-type.h", + "src/fixed-dtoa.cc", + "src/fixed-dtoa.h", + "src/flag-definitions.h", + "src/flags.cc", + "src/flags.h", + "src/frames-inl.h", + "src/frames.cc", + "src/frames.h", + "src/full-codegen/full-codegen.cc", + "src/full-codegen/full-codegen.h", + "src/futex-emulation.cc", + "src/futex-emulation.h", + "src/gdb-jit.cc", + "src/gdb-jit.h", + "src/global-handles.cc", + "src/global-handles.h", + "src/globals.h", + "src/handles-inl.h", + "src/handles.cc", + "src/handles.h", + "src/heap-symbols.h", + "src/heap/array-buffer-tracker-inl.h", + "src/heap/array-buffer-tracker.cc", + "src/heap/array-buffer-tracker.h", + "src/heap/code-stats.cc", + "src/heap/code-stats.h", + "src/heap/gc-idle-time-handler.cc", + "src/heap/gc-idle-time-handler.h", + "src/heap/gc-tracer.cc", + "src/heap/gc-tracer.h", + "src/heap/heap-inl.h", + "src/heap/heap.cc", + "src/heap/heap.h", + "src/heap/incremental-marking-job.cc", + "src/heap/incremental-marking-job.h", + "src/heap/incremental-marking.cc", + "src/heap/incremental-marking.h", + "src/heap/mark-compact-inl.h", + "src/heap/mark-compact.cc", + "src/heap/mark-compact.h", + "src/heap/marking.h", + "src/heap/memory-reducer.cc", + "src/heap/memory-reducer.h", + "src/heap/object-stats.cc", + "src/heap/object-stats.h", + "src/heap/objects-visiting-inl.h", + "src/heap/objects-visiting.cc", + "src/heap/objects-visiting.h", + "src/heap/page-parallel-job.h", + "src/heap/remembered-set.cc", + "src/heap/remembered-set.h", + "src/heap/scavenge-job.cc", + "src/heap/scavenge-job.h", + "src/heap/scavenger-inl.h", + "src/heap/scavenger.cc", + "src/heap/scavenger.h", + "src/heap/slot-set.h", + "src/heap/spaces-inl.h", + "src/heap/spaces.cc", + "src/heap/spaces.h", + "src/heap/store-buffer.cc", + "src/heap/store-buffer.h", + "src/i18n.cc", + "src/i18n.h", + "src/ic/access-compiler.cc", + "src/ic/access-compiler.h", + "src/ic/call-optimization.cc", + "src/ic/call-optimization.h", + "src/ic/handler-compiler.cc", + "src/ic/handler-compiler.h", + "src/ic/ic-compiler.cc", + "src/ic/ic-compiler.h", + "src/ic/ic-inl.h", + "src/ic/ic-state.cc", + "src/ic/ic-state.h", + "src/ic/ic.cc", + "src/ic/ic.h", + "src/ic/stub-cache.cc", + "src/ic/stub-cache.h", + "src/icu_util.cc", + "src/icu_util.h", + "src/identity-map.cc", + "src/identity-map.h", + "src/interface-descriptors.cc", + "src/interface-descriptors.h", + "src/interpreter/bytecode-array-builder.cc", + "src/interpreter/bytecode-array-builder.h", + "src/interpreter/bytecode-array-iterator.cc", + "src/interpreter/bytecode-array-iterator.h", + "src/interpreter/bytecode-array-writer.cc", + "src/interpreter/bytecode-array-writer.h", + "src/interpreter/bytecode-dead-code-optimizer.cc", + "src/interpreter/bytecode-dead-code-optimizer.h", + "src/interpreter/bytecode-decoder.cc", + "src/interpreter/bytecode-decoder.h", + "src/interpreter/bytecode-flags.cc", + "src/interpreter/bytecode-flags.h", + "src/interpreter/bytecode-generator.cc", + "src/interpreter/bytecode-generator.h", + "src/interpreter/bytecode-label.cc", + "src/interpreter/bytecode-label.h", + "src/interpreter/bytecode-peephole-optimizer.cc", + "src/interpreter/bytecode-peephole-optimizer.h", + "src/interpreter/bytecode-peephole-table.h", + "src/interpreter/bytecode-pipeline.cc", + "src/interpreter/bytecode-pipeline.h", + "src/interpreter/bytecode-register-allocator.cc", + "src/interpreter/bytecode-register-allocator.h", + "src/interpreter/bytecode-register-optimizer.cc", + "src/interpreter/bytecode-register-optimizer.h", + "src/interpreter/bytecode-register.cc", + "src/interpreter/bytecode-register.h", + "src/interpreter/bytecode-traits.h", + "src/interpreter/bytecodes.cc", + "src/interpreter/bytecodes.h", + "src/interpreter/constant-array-builder.cc", + "src/interpreter/constant-array-builder.h", + "src/interpreter/control-flow-builders.cc", + "src/interpreter/control-flow-builders.h", + "src/interpreter/handler-table-builder.cc", + "src/interpreter/handler-table-builder.h", + "src/interpreter/interpreter-assembler.cc", + "src/interpreter/interpreter-assembler.h", + "src/interpreter/interpreter-intrinsics.cc", + "src/interpreter/interpreter-intrinsics.h", + "src/interpreter/interpreter.cc", + "src/interpreter/interpreter.h", + "src/isolate-inl.h", + "src/isolate.cc", + "src/isolate.h", + "src/json-parser.cc", + "src/json-parser.h", + "src/json-stringifier.cc", + "src/json-stringifier.h", + "src/keys.cc", + "src/keys.h", + "src/layout-descriptor-inl.h", + "src/layout-descriptor.cc", + "src/layout-descriptor.h", + "src/list-inl.h", + "src/list.h", + "src/log-inl.h", + "src/log-utils.cc", + "src/log-utils.h", + "src/log.cc", + "src/log.h", + "src/lookup.cc", + "src/lookup.h", + "src/machine-type.cc", + "src/machine-type.h", + "src/macro-assembler.h", + "src/messages.cc", + "src/messages.h", + "src/msan.h", + "src/objects-body-descriptors-inl.h", + "src/objects-body-descriptors.h", + "src/objects-debug.cc", + "src/objects-inl.h", + "src/objects-printer.cc", + "src/objects.cc", + "src/objects.h", + "src/ostreams.cc", + "src/ostreams.h", + "src/parsing/expression-classifier.h", + "src/parsing/func-name-inferrer.cc", + "src/parsing/func-name-inferrer.h", + "src/parsing/parameter-initializer-rewriter.cc", + "src/parsing/parameter-initializer-rewriter.h", + "src/parsing/parse-info.cc", + "src/parsing/parse-info.h", + "src/parsing/parser-base.h", + "src/parsing/parser.cc", + "src/parsing/parser.h", + "src/parsing/pattern-rewriter.cc", + "src/parsing/preparse-data-format.h", + "src/parsing/preparse-data.cc", + "src/parsing/preparse-data.h", + "src/parsing/preparser.cc", + "src/parsing/preparser.h", + "src/parsing/rewriter.cc", + "src/parsing/rewriter.h", + "src/parsing/scanner-character-streams.cc", + "src/parsing/scanner-character-streams.h", + "src/parsing/scanner.cc", + "src/parsing/scanner.h", + "src/parsing/token.cc", + "src/parsing/token.h", + "src/pending-compilation-error-handler.cc", + "src/pending-compilation-error-handler.h", + "src/perf-jit.cc", + "src/perf-jit.h", + "src/profiler/allocation-tracker.cc", + "src/profiler/allocation-tracker.h", + "src/profiler/circular-queue-inl.h", + "src/profiler/circular-queue.h", + "src/profiler/cpu-profiler-inl.h", + "src/profiler/cpu-profiler.cc", + "src/profiler/cpu-profiler.h", + "src/profiler/heap-profiler.cc", + "src/profiler/heap-profiler.h", + "src/profiler/heap-snapshot-generator-inl.h", + "src/profiler/heap-snapshot-generator.cc", + "src/profiler/heap-snapshot-generator.h", + "src/profiler/profile-generator-inl.h", + "src/profiler/profile-generator.cc", + "src/profiler/profile-generator.h", + "src/profiler/profiler-listener.cc", + "src/profiler/profiler-listener.h", + "src/profiler/sampling-heap-profiler.cc", + "src/profiler/sampling-heap-profiler.h", + "src/profiler/strings-storage.cc", + "src/profiler/strings-storage.h", + "src/profiler/tick-sample.cc", + "src/profiler/tick-sample.h", + "src/profiler/unbound-queue-inl.h", + "src/profiler/unbound-queue.h", + "src/property-descriptor.cc", + "src/property-descriptor.h", + "src/property-details.h", + "src/property.cc", + "src/property.h", + "src/prototype.h", + "src/regexp/bytecodes-irregexp.h", + "src/regexp/interpreter-irregexp.cc", + "src/regexp/interpreter-irregexp.h", + "src/regexp/jsregexp-inl.h", + "src/regexp/jsregexp.cc", + "src/regexp/jsregexp.h", + "src/regexp/regexp-ast.cc", + "src/regexp/regexp-ast.h", + "src/regexp/regexp-macro-assembler-irregexp-inl.h", + "src/regexp/regexp-macro-assembler-irregexp.cc", + "src/regexp/regexp-macro-assembler-irregexp.h", + "src/regexp/regexp-macro-assembler-tracer.cc", + "src/regexp/regexp-macro-assembler-tracer.h", + "src/regexp/regexp-macro-assembler.cc", + "src/regexp/regexp-macro-assembler.h", + "src/regexp/regexp-parser.cc", + "src/regexp/regexp-parser.h", + "src/regexp/regexp-stack.cc", + "src/regexp/regexp-stack.h", + "src/register-configuration.cc", + "src/register-configuration.h", + "src/runtime-profiler.cc", + "src/runtime-profiler.h", + "src/runtime/runtime-array.cc", + "src/runtime/runtime-atomics.cc", + "src/runtime/runtime-classes.cc", + "src/runtime/runtime-collections.cc", + "src/runtime/runtime-compiler.cc", + "src/runtime/runtime-date.cc", + "src/runtime/runtime-debug.cc", + "src/runtime/runtime-error.cc", + "src/runtime/runtime-forin.cc", + "src/runtime/runtime-function.cc", + "src/runtime/runtime-futex.cc", + "src/runtime/runtime-generator.cc", + "src/runtime/runtime-i18n.cc", + "src/runtime/runtime-internal.cc", + "src/runtime/runtime-interpreter.cc", + "src/runtime/runtime-literals.cc", + "src/runtime/runtime-liveedit.cc", + "src/runtime/runtime-maths.cc", + "src/runtime/runtime-numbers.cc", + "src/runtime/runtime-object.cc", + "src/runtime/runtime-operators.cc", + "src/runtime/runtime-proxy.cc", + "src/runtime/runtime-regexp.cc", + "src/runtime/runtime-scopes.cc", + "src/runtime/runtime-simd.cc", + "src/runtime/runtime-strings.cc", + "src/runtime/runtime-symbol.cc", + "src/runtime/runtime-test.cc", + "src/runtime/runtime-typedarray.cc", + "src/runtime/runtime-utils.h", + "src/runtime/runtime-wasm.cc", + "src/runtime/runtime.cc", + "src/runtime/runtime.h", + "src/safepoint-table.cc", + "src/safepoint-table.h", + "src/signature.h", + "src/simulator.h", + "src/small-pointer-list.h", + "src/snapshot/code-serializer.cc", + "src/snapshot/code-serializer.h", + "src/snapshot/deserializer.cc", + "src/snapshot/deserializer.h", + "src/snapshot/natives-common.cc", + "src/snapshot/natives.h", + "src/snapshot/partial-serializer.cc", + "src/snapshot/partial-serializer.h", + "src/snapshot/serializer-common.cc", + "src/snapshot/serializer-common.h", + "src/snapshot/serializer.cc", + "src/snapshot/serializer.h", + "src/snapshot/snapshot-common.cc", + "src/snapshot/snapshot-source-sink.cc", + "src/snapshot/snapshot-source-sink.h", + "src/snapshot/snapshot.h", + "src/snapshot/startup-serializer.cc", + "src/snapshot/startup-serializer.h", + "src/source-position-table.cc", + "src/source-position-table.h", + "src/source-position.h", + "src/splay-tree-inl.h", + "src/splay-tree.h", + "src/startup-data-util.cc", + "src/startup-data-util.h", + "src/string-builder.cc", + "src/string-builder.h", + "src/string-search.h", + "src/string-stream.cc", + "src/string-stream.h", + "src/strtod.cc", + "src/strtod.h", + "src/tracing/trace-event.cc", + "src/tracing/trace-event.h", + "src/transitions-inl.h", + "src/transitions.cc", + "src/transitions.h", + "src/type-cache.cc", + "src/type-cache.h", + "src/type-feedback-vector-inl.h", + "src/type-feedback-vector.cc", + "src/type-feedback-vector.h", + "src/type-info.cc", + "src/type-info.h", + "src/types.cc", + "src/types.h", + "src/unicode-cache-inl.h", + "src/unicode-cache.h", + "src/unicode-decoder.cc", + "src/unicode-decoder.h", + "src/unicode-inl.h", + "src/unicode.cc", + "src/unicode.h", + "src/uri.cc", + "src/uri.h", + "src/utils-inl.h", + "src/utils.cc", + "src/utils.h", + "src/v8.cc", + "src/v8.h", + "src/v8memory.h", + "src/v8threads.cc", + "src/v8threads.h", + "src/value-serializer.cc", + "src/value-serializer.h", + "src/version.cc", + "src/version.h", + "src/vm-state-inl.h", + "src/vm-state.h", + "src/wasm/ast-decoder.cc", + "src/wasm/ast-decoder.h", + "src/wasm/decoder.h", + "src/wasm/encoder.cc", + "src/wasm/encoder.h", + "src/wasm/leb-helper.h", + "src/wasm/module-decoder.cc", + "src/wasm/module-decoder.h", + "src/wasm/switch-logic.cc", + "src/wasm/switch-logic.h", + "src/wasm/wasm-debug.cc", + "src/wasm/wasm-debug.h", + "src/wasm/wasm-external-refs.cc", + "src/wasm/wasm-external-refs.h", + "src/wasm/wasm-function-name-table.cc", + "src/wasm/wasm-function-name-table.h", + "src/wasm/wasm-interpreter.cc", + "src/wasm/wasm-interpreter.h", + "src/wasm/wasm-js.cc", + "src/wasm/wasm-js.h", + "src/wasm/wasm-macro-gen.h", + "src/wasm/wasm-module.cc", + "src/wasm/wasm-module.h", + "src/wasm/wasm-opcodes.cc", + "src/wasm/wasm-opcodes.h", + "src/wasm/wasm-result.cc", + "src/wasm/wasm-result.h", + "src/zone-allocator.h", + "src/zone-containers.h", + "src/zone.cc", + "src/zone.h", + ] + + if (v8_current_cpu == "x86") { + sources += [ + "src/builtins/ia32/builtins-ia32.cc", + "src/compiler/ia32/code-generator-ia32.cc", + "src/compiler/ia32/instruction-codes-ia32.h", + "src/compiler/ia32/instruction-scheduler-ia32.cc", + "src/compiler/ia32/instruction-selector-ia32.cc", + "src/crankshaft/ia32/lithium-codegen-ia32.cc", + "src/crankshaft/ia32/lithium-codegen-ia32.h", + "src/crankshaft/ia32/lithium-gap-resolver-ia32.cc", + "src/crankshaft/ia32/lithium-gap-resolver-ia32.h", + "src/crankshaft/ia32/lithium-ia32.cc", + "src/crankshaft/ia32/lithium-ia32.h", + "src/debug/ia32/debug-ia32.cc", + "src/full-codegen/ia32/full-codegen-ia32.cc", + "src/ia32/assembler-ia32-inl.h", + "src/ia32/assembler-ia32.cc", + "src/ia32/assembler-ia32.h", + "src/ia32/code-stubs-ia32.cc", + "src/ia32/code-stubs-ia32.h", + "src/ia32/codegen-ia32.cc", + "src/ia32/codegen-ia32.h", + "src/ia32/cpu-ia32.cc", + "src/ia32/deoptimizer-ia32.cc", + "src/ia32/disasm-ia32.cc", + "src/ia32/frames-ia32.cc", + "src/ia32/frames-ia32.h", + "src/ia32/interface-descriptors-ia32.cc", + "src/ia32/macro-assembler-ia32.cc", + "src/ia32/macro-assembler-ia32.h", + "src/ic/ia32/access-compiler-ia32.cc", + "src/ic/ia32/handler-compiler-ia32.cc", + "src/ic/ia32/ic-compiler-ia32.cc", + "src/ic/ia32/ic-ia32.cc", + "src/ic/ia32/stub-cache-ia32.cc", + "src/regexp/ia32/regexp-macro-assembler-ia32.cc", + "src/regexp/ia32/regexp-macro-assembler-ia32.h", + ] + } else if (v8_current_cpu == "x64") { + sources += [ + "src/builtins/x64/builtins-x64.cc", + "src/compiler/x64/code-generator-x64.cc", + "src/compiler/x64/instruction-codes-x64.h", + "src/compiler/x64/instruction-scheduler-x64.cc", + "src/compiler/x64/instruction-selector-x64.cc", + "src/compiler/x64/unwinding-info-writer-x64.cc", + "src/compiler/x64/unwinding-info-writer-x64.h", + "src/crankshaft/x64/lithium-codegen-x64.cc", + "src/crankshaft/x64/lithium-codegen-x64.h", + "src/crankshaft/x64/lithium-gap-resolver-x64.cc", + "src/crankshaft/x64/lithium-gap-resolver-x64.h", + "src/crankshaft/x64/lithium-x64.cc", + "src/crankshaft/x64/lithium-x64.h", + "src/debug/x64/debug-x64.cc", + "src/full-codegen/x64/full-codegen-x64.cc", + "src/ic/x64/access-compiler-x64.cc", + "src/ic/x64/handler-compiler-x64.cc", + "src/ic/x64/ic-compiler-x64.cc", + "src/ic/x64/ic-x64.cc", + "src/ic/x64/stub-cache-x64.cc", + "src/regexp/x64/regexp-macro-assembler-x64.cc", + "src/regexp/x64/regexp-macro-assembler-x64.h", + "src/x64/assembler-x64-inl.h", + "src/x64/assembler-x64.cc", + "src/x64/assembler-x64.h", + "src/x64/code-stubs-x64.cc", + "src/x64/code-stubs-x64.h", + "src/x64/codegen-x64.cc", + "src/x64/codegen-x64.h", + "src/x64/cpu-x64.cc", + "src/x64/deoptimizer-x64.cc", + "src/x64/disasm-x64.cc", + "src/x64/eh-frame-x64.cc", + "src/x64/frames-x64.cc", + "src/x64/frames-x64.h", + "src/x64/interface-descriptors-x64.cc", + "src/x64/macro-assembler-x64.cc", + "src/x64/macro-assembler-x64.h", + ] + } else if (v8_current_cpu == "arm") { + sources += [ + "src/arm/assembler-arm-inl.h", + "src/arm/assembler-arm.cc", + "src/arm/assembler-arm.h", + "src/arm/code-stubs-arm.cc", + "src/arm/code-stubs-arm.h", + "src/arm/codegen-arm.cc", + "src/arm/codegen-arm.h", + "src/arm/constants-arm.cc", + "src/arm/constants-arm.h", + "src/arm/cpu-arm.cc", + "src/arm/deoptimizer-arm.cc", + "src/arm/disasm-arm.cc", + "src/arm/eh-frame-arm.cc", + "src/arm/frames-arm.cc", + "src/arm/frames-arm.h", + "src/arm/interface-descriptors-arm.cc", + "src/arm/interface-descriptors-arm.h", + "src/arm/macro-assembler-arm.cc", + "src/arm/macro-assembler-arm.h", + "src/arm/simulator-arm.cc", + "src/arm/simulator-arm.h", + "src/builtins/arm/builtins-arm.cc", + "src/compiler/arm/code-generator-arm.cc", + "src/compiler/arm/instruction-codes-arm.h", + "src/compiler/arm/instruction-scheduler-arm.cc", + "src/compiler/arm/instruction-selector-arm.cc", + "src/compiler/arm/unwinding-info-writer-arm.cc", + "src/compiler/arm/unwinding-info-writer-arm.h", + "src/crankshaft/arm/lithium-arm.cc", + "src/crankshaft/arm/lithium-arm.h", + "src/crankshaft/arm/lithium-codegen-arm.cc", + "src/crankshaft/arm/lithium-codegen-arm.h", + "src/crankshaft/arm/lithium-gap-resolver-arm.cc", + "src/crankshaft/arm/lithium-gap-resolver-arm.h", + "src/debug/arm/debug-arm.cc", + "src/full-codegen/arm/full-codegen-arm.cc", + "src/ic/arm/access-compiler-arm.cc", + "src/ic/arm/handler-compiler-arm.cc", + "src/ic/arm/ic-arm.cc", + "src/ic/arm/ic-compiler-arm.cc", + "src/ic/arm/stub-cache-arm.cc", + "src/regexp/arm/regexp-macro-assembler-arm.cc", + "src/regexp/arm/regexp-macro-assembler-arm.h", + ] + } else if (v8_current_cpu == "arm64") { + sources += [ + "src/arm64/assembler-arm64-inl.h", + "src/arm64/assembler-arm64.cc", + "src/arm64/assembler-arm64.h", + "src/arm64/code-stubs-arm64.cc", + "src/arm64/code-stubs-arm64.h", + "src/arm64/codegen-arm64.cc", + "src/arm64/codegen-arm64.h", + "src/arm64/constants-arm64.h", + "src/arm64/cpu-arm64.cc", + "src/arm64/decoder-arm64-inl.h", + "src/arm64/decoder-arm64.cc", + "src/arm64/decoder-arm64.h", + "src/arm64/deoptimizer-arm64.cc", + "src/arm64/disasm-arm64.cc", + "src/arm64/disasm-arm64.h", + "src/arm64/eh-frame-arm64.cc", + "src/arm64/frames-arm64.cc", + "src/arm64/frames-arm64.h", + "src/arm64/instructions-arm64.cc", + "src/arm64/instructions-arm64.h", + "src/arm64/instrument-arm64.cc", + "src/arm64/instrument-arm64.h", + "src/arm64/interface-descriptors-arm64.cc", + "src/arm64/interface-descriptors-arm64.h", + "src/arm64/macro-assembler-arm64-inl.h", + "src/arm64/macro-assembler-arm64.cc", + "src/arm64/macro-assembler-arm64.h", + "src/arm64/simulator-arm64.cc", + "src/arm64/simulator-arm64.h", + "src/arm64/utils-arm64.cc", + "src/arm64/utils-arm64.h", + "src/builtins/arm64/builtins-arm64.cc", + "src/compiler/arm64/code-generator-arm64.cc", + "src/compiler/arm64/instruction-codes-arm64.h", + "src/compiler/arm64/instruction-scheduler-arm64.cc", + "src/compiler/arm64/instruction-selector-arm64.cc", + "src/compiler/arm64/unwinding-info-writer-arm64.cc", + "src/compiler/arm64/unwinding-info-writer-arm64.h", + "src/crankshaft/arm64/delayed-masm-arm64-inl.h", + "src/crankshaft/arm64/delayed-masm-arm64.cc", + "src/crankshaft/arm64/delayed-masm-arm64.h", + "src/crankshaft/arm64/lithium-arm64.cc", + "src/crankshaft/arm64/lithium-arm64.h", + "src/crankshaft/arm64/lithium-codegen-arm64.cc", + "src/crankshaft/arm64/lithium-codegen-arm64.h", + "src/crankshaft/arm64/lithium-gap-resolver-arm64.cc", + "src/crankshaft/arm64/lithium-gap-resolver-arm64.h", + "src/debug/arm64/debug-arm64.cc", + "src/full-codegen/arm64/full-codegen-arm64.cc", + "src/ic/arm64/access-compiler-arm64.cc", + "src/ic/arm64/handler-compiler-arm64.cc", + "src/ic/arm64/ic-arm64.cc", + "src/ic/arm64/ic-compiler-arm64.cc", + "src/ic/arm64/stub-cache-arm64.cc", + "src/regexp/arm64/regexp-macro-assembler-arm64.cc", + "src/regexp/arm64/regexp-macro-assembler-arm64.h", + ] + } else if (v8_current_cpu == "mipsel") { + sources += [ + "src/builtins/mips/builtins-mips.cc", + "src/compiler/mips/code-generator-mips.cc", + "src/compiler/mips/instruction-codes-mips.h", + "src/compiler/mips/instruction-scheduler-mips.cc", + "src/compiler/mips/instruction-selector-mips.cc", + "src/crankshaft/mips/lithium-codegen-mips.cc", + "src/crankshaft/mips/lithium-codegen-mips.h", + "src/crankshaft/mips/lithium-gap-resolver-mips.cc", + "src/crankshaft/mips/lithium-gap-resolver-mips.h", + "src/crankshaft/mips/lithium-mips.cc", + "src/crankshaft/mips/lithium-mips.h", + "src/debug/mips/debug-mips.cc", + "src/full-codegen/mips/full-codegen-mips.cc", + "src/ic/mips/access-compiler-mips.cc", + "src/ic/mips/handler-compiler-mips.cc", + "src/ic/mips/ic-compiler-mips.cc", + "src/ic/mips/ic-mips.cc", + "src/ic/mips/stub-cache-mips.cc", + "src/mips/assembler-mips-inl.h", + "src/mips/assembler-mips.cc", + "src/mips/assembler-mips.h", + "src/mips/code-stubs-mips.cc", + "src/mips/code-stubs-mips.h", + "src/mips/codegen-mips.cc", + "src/mips/codegen-mips.h", + "src/mips/constants-mips.cc", + "src/mips/constants-mips.h", + "src/mips/cpu-mips.cc", + "src/mips/deoptimizer-mips.cc", + "src/mips/disasm-mips.cc", + "src/mips/frames-mips.cc", + "src/mips/frames-mips.h", + "src/mips/interface-descriptors-mips.cc", + "src/mips/macro-assembler-mips.cc", + "src/mips/macro-assembler-mips.h", + "src/mips/simulator-mips.cc", + "src/mips/simulator-mips.h", + "src/regexp/mips/regexp-macro-assembler-mips.cc", + "src/regexp/mips/regexp-macro-assembler-mips.h", + ] + } else if (v8_current_cpu == "mips64el") { + sources += [ + "src/builtins/mips64/builtins-mips64.cc", + "src/compiler/mips64/code-generator-mips64.cc", + "src/compiler/mips64/instruction-codes-mips64.h", + "src/compiler/mips64/instruction-scheduler-mips64.cc", + "src/compiler/mips64/instruction-selector-mips64.cc", + "src/crankshaft/mips64/lithium-codegen-mips64.cc", + "src/crankshaft/mips64/lithium-codegen-mips64.h", + "src/crankshaft/mips64/lithium-gap-resolver-mips64.cc", + "src/crankshaft/mips64/lithium-gap-resolver-mips64.h", + "src/crankshaft/mips64/lithium-mips64.cc", + "src/crankshaft/mips64/lithium-mips64.h", + "src/debug/mips64/debug-mips64.cc", + "src/full-codegen/mips64/full-codegen-mips64.cc", + "src/ic/mips64/access-compiler-mips64.cc", + "src/ic/mips64/handler-compiler-mips64.cc", + "src/ic/mips64/ic-compiler-mips64.cc", + "src/ic/mips64/ic-mips64.cc", + "src/ic/mips64/stub-cache-mips64.cc", + "src/mips64/assembler-mips64-inl.h", + "src/mips64/assembler-mips64.cc", + "src/mips64/assembler-mips64.h", + "src/mips64/code-stubs-mips64.cc", + "src/mips64/code-stubs-mips64.h", + "src/mips64/codegen-mips64.cc", + "src/mips64/codegen-mips64.h", + "src/mips64/constants-mips64.cc", + "src/mips64/constants-mips64.h", + "src/mips64/cpu-mips64.cc", + "src/mips64/deoptimizer-mips64.cc", + "src/mips64/disasm-mips64.cc", + "src/mips64/frames-mips64.cc", + "src/mips64/frames-mips64.h", + "src/mips64/interface-descriptors-mips64.cc", + "src/mips64/macro-assembler-mips64.cc", + "src/mips64/macro-assembler-mips64.h", + "src/mips64/simulator-mips64.cc", + "src/mips64/simulator-mips64.h", + "src/regexp/mips64/regexp-macro-assembler-mips64.cc", + "src/regexp/mips64/regexp-macro-assembler-mips64.h", + ] + } else if (v8_current_cpu == "s390" || v8_current_cpu == "s390x") { + sources += [ + "src/builtins/s390/builtins-s390.cc", + "src/compiler/s390/code-generator-s390.cc", + "src/compiler/s390/instruction-codes-s390.h", + "src/compiler/s390/instruction-scheduler-s390.cc", + "src/compiler/s390/instruction-selector-s390.cc", + "src/crankshaft/s390/lithium-codegen-s390.cc", + "src/crankshaft/s390/lithium-codegen-s390.h", + "src/crankshaft/s390/lithium-gap-resolver-s390.cc", + "src/crankshaft/s390/lithium-gap-resolver-s390.h", + "src/crankshaft/s390/lithium-s390.cc", + "src/crankshaft/s390/lithium-s390.h", + "src/debug/s390/debug-s390.cc", + "src/full-codegen/s390/full-codegen-s390.cc", + "src/ic/s390/access-compiler-s390.cc", + "src/ic/s390/handler-compiler-s390.cc", + "src/ic/s390/ic-compiler-s390.cc", + "src/ic/s390/ic-s390.cc", + "src/ic/s390/stub-cache-s390.cc", + "src/regexp/s390/regexp-macro-assembler-s390.cc", + "src/regexp/s390/regexp-macro-assembler-s390.h", + "src/s390/assembler-s390-inl.h", + "src/s390/assembler-s390.cc", + "src/s390/assembler-s390.h", + "src/s390/code-stubs-s390.cc", + "src/s390/code-stubs-s390.h", + "src/s390/codegen-s390.cc", + "src/s390/codegen-s390.h", + "src/s390/constants-s390.cc", + "src/s390/constants-s390.h", + "src/s390/cpu-s390.cc", + "src/s390/deoptimizer-s390.cc", + "src/s390/disasm-s390.cc", + "src/s390/frames-s390.cc", + "src/s390/frames-s390.h", + "src/s390/interface-descriptors-s390.cc", + "src/s390/macro-assembler-s390.cc", + "src/s390/macro-assembler-s390.h", + "src/s390/simulator-s390.cc", + "src/s390/simulator-s390.h", + ] + } + + configs = [ ":internal_config" ] + + defines = [] + deps = [ + ":v8_libbase", + ":v8_libsampler", + ] + + sources += [ v8_generated_peephole_source ] + deps += [ ":run_mkpeephole" ] + + if (is_win) { + # TODO(jschuh): crbug.com/167187 fix size_t to int truncations. + cflags = [ "/wd4267" ] + } + + if (v8_enable_i18n_support) { + deps += [ "//third_party/icu" ] + if (is_win) { + deps += [ "//third_party/icu:icudata" ] + } + } else { + sources -= [ + "src/i18n.cc", + "src/i18n.h", + ] + } + + if (v8_postmortem_support) { + sources += [ "$target_gen_dir/debug-support.cc" ] + deps += [ ":postmortem-metadata" ] + } +} + +v8_source_set("v8_libbase") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + sources = [ + "src/base/accounting-allocator.cc", + "src/base/accounting-allocator.h", + "src/base/adapters.h", + "src/base/atomic-utils.h", + "src/base/atomicops.h", + "src/base/atomicops_internals_arm64_gcc.h", + "src/base/atomicops_internals_arm_gcc.h", + "src/base/atomicops_internals_atomicword_compat.h", + "src/base/atomicops_internals_mac.h", + "src/base/atomicops_internals_mips64_gcc.h", + "src/base/atomicops_internals_mips_gcc.h", + "src/base/atomicops_internals_s390_gcc.h", + "src/base/atomicops_internals_tsan.h", + "src/base/atomicops_internals_x86_gcc.cc", + "src/base/atomicops_internals_x86_gcc.h", + "src/base/atomicops_internals_x86_msvc.h", + "src/base/bits.cc", + "src/base/bits.h", + "src/base/build_config.h", + "src/base/cpu.cc", + "src/base/cpu.h", + "src/base/debug/stack_trace.cc", + "src/base/debug/stack_trace.h", + "src/base/division-by-constant.cc", + "src/base/division-by-constant.h", + "src/base/file-utils.cc", + "src/base/file-utils.h", + "src/base/flags.h", + "src/base/format-macros.h", + "src/base/free_deleter.h", + "src/base/functional.cc", + "src/base/functional.h", + "src/base/hashmap.h", + "src/base/ieee754.cc", + "src/base/ieee754.h", + "src/base/iterator.h", + "src/base/lazy-instance.h", + "src/base/logging.cc", + "src/base/logging.h", + "src/base/macros.h", + "src/base/once.cc", + "src/base/once.h", + "src/base/platform/condition-variable.cc", + "src/base/platform/condition-variable.h", + "src/base/platform/elapsed-timer.h", + "src/base/platform/mutex.cc", + "src/base/platform/mutex.h", + "src/base/platform/platform.h", + "src/base/platform/semaphore.cc", + "src/base/platform/semaphore.h", + "src/base/platform/time.cc", + "src/base/platform/time.h", + "src/base/safe_conversions.h", + "src/base/safe_conversions_impl.h", + "src/base/safe_math.h", + "src/base/safe_math_impl.h", + "src/base/sys-info.cc", + "src/base/sys-info.h", + "src/base/utils/random-number-generator.cc", + "src/base/utils/random-number-generator.h", + ] + + configs = [ ":internal_config_base" ] + + defines = [] + + if (is_posix) { + sources += [ "src/base/platform/platform-posix.cc" ] + } + + if (is_linux) { + sources += [ + "src/base/debug/stack_trace_posix.cc", + "src/base/platform/platform-linux.cc", + ] + + libs = [ + "dl", + "rt", + ] + } else if (is_android) { + if (current_toolchain == host_toolchain) { + libs = [ + "dl", + "rt", + ] + if (host_os == "mac") { + sources += [ + "src/base/debug/stack_trace_posix.cc", + "src/base/platform/platform-macos.cc", + ] + } else { + sources += [ + "src/base/debug/stack_trace_posix.cc", + "src/base/platform/platform-linux.cc", + ] + } + } else { + sources += [ + "src/base/debug/stack_trace_android.cc", + "src/base/platform/platform-linux.cc", + ] + } + } else if (is_mac) { + sources += [ + "src/base/debug/stack_trace_posix.cc", + "src/base/platform/platform-macos.cc", + ] + } else if (is_win) { + # TODO(jochen): Add support for cygwin. + sources += [ + "src/base/debug/stack_trace_win.cc", + "src/base/platform/platform-win32.cc", + "src/base/win32-headers.h", + ] + + defines += [ "_CRT_RAND_S" ] # for rand_s() + + libs = [ + "dbghelp.lib", + "shlwapi.lib", + "winmm.lib", + "ws2_32.lib", + ] + } + + # TODO(jochen): Add support for qnx, freebsd, openbsd, netbsd, and solaris. +} + +v8_source_set("v8_libplatform") { + sources = [ + "//base/trace_event/common/trace_event_common.h", + "include/libplatform/libplatform.h", + "include/libplatform/v8-tracing.h", + "src/libplatform/default-platform.cc", + "src/libplatform/default-platform.h", + "src/libplatform/task-queue.cc", + "src/libplatform/task-queue.h", + "src/libplatform/tracing/trace-buffer.cc", + "src/libplatform/tracing/trace-buffer.h", + "src/libplatform/tracing/trace-config.cc", + "src/libplatform/tracing/trace-object.cc", + "src/libplatform/tracing/trace-writer.cc", + "src/libplatform/tracing/trace-writer.h", + "src/libplatform/tracing/tracing-controller.cc", + "src/libplatform/worker-thread.cc", + "src/libplatform/worker-thread.h", + ] + + configs = [ ":internal_config_base" ] + + public_configs = [ ":libplatform_config" ] + + deps = [ + ":v8_libbase", + ] +} + +v8_source_set("v8_libsampler") { + sources = [ + "src/libsampler/sampler.cc", + "src/libsampler/sampler.h", + ] + + configs = [ ":internal_config_base" ] + + public_configs = [ ":libsampler_config" ] + + deps = [ + ":v8_libbase", + ] +} + +v8_source_set("fuzzer_support") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + sources = [ + "test/fuzzer/fuzzer-support.cc", + "test/fuzzer/fuzzer-support.h", + ] + + configs = [ ":internal_config_base" ] + + deps = [ + ":v8_maybe_snapshot", + ] + + public_deps = [ + ":v8_libplatform", + ] +} + +v8_source_set("simple_fuzzer") { + sources = [ + "test/fuzzer/fuzzer.cc", + ] + + configs = [ ":internal_config_base" ] +} + +############################################################################### +# Executables +# + +if (current_toolchain == v8_snapshot_toolchain) { + v8_executable("mksnapshot") { + visibility = [ ":*" ] # Only targets in this file can depend on this. + + sources = [ + "src/snapshot/mksnapshot.cc", + ] + + configs = [ ":internal_config" ] + + deps = [ + ":v8_base", + ":v8_libplatform", + ":v8_nosnapshot", + "//build/config/sanitizers:deps", + "//build/win:default_exe_manifest", + ] + } +} + +v8_executable("mkpeephole") { + # mkpeephole needs to be built for the build host so the peephole lookup + # table can built during build. The table depends on the properties of + # bytecodes that are described in bytecodes.{cc,h}. + visibility = [ ":*" ] # Only targets in this file can depend on this. + + sources = [ + "src/interpreter/bytecode-peephole-optimizer.h", + "src/interpreter/bytecodes.cc", + "src/interpreter/bytecodes.h", + "src/interpreter/mkpeephole.cc", + ] + + configs = [ + ":external_config", + ":internal_config", + ] + + deps = [ + ":v8_libbase", + "//build/config/sanitizers:deps", + "//build/win:default_exe_manifest", + ] +} + +############################################################################### +# Public targets +# + +want_v8_shell = + (current_toolchain == host_toolchain && v8_toolset_for_shell == "host") || + (current_toolchain == v8_snapshot_toolchain && + v8_toolset_for_shell == "host") || + (current_toolchain != host_toolchain && v8_toolset_for_shell == "target") + +group("gn_all") { + testonly = true + + deps = [ + ":d8", + ":v8_hello_world", + ":v8_parser_shell", + ":v8_sample_process", + ":v8_simple_json_fuzzer", + ":v8_simple_parser_fuzzer", + ":v8_simple_regexp_fuzzer", + ":v8_simple_wasm_asmjs_fuzzer", + ":v8_simple_wasm_fuzzer", + "test:gn_all", + "tools:gn_all", + ] + + if (want_v8_shell) { + deps += [ ":v8_shell" ] + } + + if (v8_test_isolation_mode != "noop") { + deps += [ ":d8_run" ] + } +} + +if (is_component_build) { + v8_component("v8") { + sources = [ + "src/v8dll-main.cc", + ] + + deps = [ + ":v8_dump_build_config", + ] + + public_deps = [ + ":v8_base", + ":v8_maybe_snapshot", + ] + + configs = [ ":internal_config" ] + + public_configs = [ ":external_config" ] + } +} else { + group("v8") { + deps = [ + ":v8_dump_build_config", + ] + + public_deps = [ + ":v8_base", + ":v8_maybe_snapshot", + ] + public_configs = [ ":external_config" ] + } +} + +v8_executable("d8") { + sources = [ + "src/d8.cc", + "src/d8.h", + ] + + configs = [ + # Note: don't use :internal_config here because this target will get + # the :external_config applied to it by virtue of depending on :v8, and + # you can't have both applied to the same target. + ":internal_config_base", + ] + + deps = [ + ":d8_js2c", + ":v8", + ":v8_libplatform", + "//build/config/sanitizers:deps", + "//build/win:default_exe_manifest", + ] + + # TODO(jochen): Add support for vtunejit. + + if (is_posix) { + sources += [ "src/d8-posix.cc" ] + } else if (is_win) { + sources += [ "src/d8-windows.cc" ] + } + + if (!is_component_build) { + sources += [ "$target_gen_dir/d8-js.cc" ] + } + if (v8_enable_i18n_support) { + deps += [ "//third_party/icu" ] + } +} + +v8_isolate_run("d8") { + deps = [ + ":d8", + ] + + isolate = "//src/d8.isolate" +} + +v8_executable("v8_hello_world") { + sources = [ + "samples/hello-world.cc", + ] + + configs = [ + # Note: don't use :internal_config here because this target will get + # the :external_config applied to it by virtue of depending on :v8, and + # you can't have both applied to the same target. + ":internal_config_base", + ] + + deps = [ + ":v8", + ":v8_libplatform", + "//build/config/sanitizers:deps", + "//build/win:default_exe_manifest", + ] + + if (v8_enable_i18n_support) { + deps += [ "//third_party/icu" ] + } +} + +v8_executable("v8_sample_process") { + sources = [ + "samples/process.cc", + ] + + configs = [ + # Note: don't use :internal_config here because this target will get + # the :external_config applied to it by virtue of depending on :v8, and + # you can't have both applied to the same target. + ":internal_config_base", + ] + + deps = [ + ":v8", + ":v8_libplatform", + "//build/config/sanitizers:deps", + "//build/win:default_exe_manifest", + ] + + if (v8_enable_i18n_support) { + deps += [ "//third_party/icu" ] + } +} + +v8_executable("v8_parser_shell") { + sources = [ + "tools/parser-shell.cc", + "tools/shell-utils.h", + ] + + configs = [ + ":external_config", + ":internal_config_base", + ] + + deps = [ + ":v8_libplatform", + "//build/config/sanitizers:deps", + "//build/win:default_exe_manifest", + ] + + if (is_component_build) { + # v8_parser_shell can't be built against a shared library, so we + # need to depend on the underlying static target in that case. + deps += [ ":v8_maybe_snapshot" ] + } else { + deps += [ ":v8" ] + } + + if (v8_enable_i18n_support) { + deps += [ "//third_party/icu" ] + } + + if (is_win) { + # Suppress warnings about importing locally defined symbols. + if (is_component_build) { + ldflags = [ + "/ignore:4049", + "/ignore:4217", + ] + } + } +} + +if (want_v8_shell) { + v8_executable("v8_shell") { + sources = [ + "samples/shell.cc", + ] + + configs = [ + # Note: don't use :internal_config here because this target will get + # the :external_config applied to it by virtue of depending on :v8, and + # you can't have both applied to the same target. + ":internal_config_base", + ] + + deps = [ + ":v8", + ":v8_libplatform", + "//build/config/sanitizers:deps", + "//build/win:default_exe_manifest", + ] + + if (v8_enable_i18n_support) { + deps += [ "//third_party/icu" ] + } + } +} + +template("v8_fuzzer") { + name = target_name + forward_variables_from(invoker, "*") + v8_executable("v8_simple_" + name) { + deps = [ + ":" + name, + ":simple_fuzzer", + "//build/win:default_exe_manifest", + ] + + configs = [ ":external_config" ] + } +} + +v8_source_set("json_fuzzer") { + sources = [ + "test/fuzzer/json.cc", + ] + + deps = [ + ":fuzzer_support", + ] + + configs = [ ":internal_config" ] +} + +v8_fuzzer("json_fuzzer") { +} + +v8_source_set("parser_fuzzer") { + sources = [ + "test/fuzzer/parser.cc", + ] + + deps = [ + ":fuzzer_support", + ] + + configs = [ ":internal_config" ] +} + +v8_fuzzer("parser_fuzzer") { +} + +v8_source_set("regexp_fuzzer") { + sources = [ + "test/fuzzer/regexp.cc", + ] + + deps = [ + ":fuzzer_support", + ] + + configs = [ ":internal_config" ] +} + +v8_fuzzer("regexp_fuzzer") { +} + +v8_source_set("wasm_fuzzer") { + sources = [ + "test/fuzzer/wasm.cc", + ] + + deps = [ + ":fuzzer_support", + ] + + configs = [ ":internal_config" ] +} + +v8_fuzzer("wasm_fuzzer") { +} + +v8_source_set("wasm_asmjs_fuzzer") { + sources = [ + "test/fuzzer/wasm-asmjs.cc", + ] + + deps = [ + ":fuzzer_support", + ] + + configs = [ ":internal_config" ] +} + +v8_fuzzer("wasm_asmjs_fuzzer") { +} diff --git a/samples/GN/android-rules.gni b/samples/GN/android-rules.gni new file mode 100644 index 00000000..0f189143 --- /dev/null +++ b/samples/GN/android-rules.gni @@ -0,0 +1,2781 @@ +# 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. + +# Do not add any imports to non-//build directories here. +# Some projects (e.g. V8) do not have non-build directories DEPS'ed in. +import("//build/config/android/config.gni") +import("//build/config/android/internal_rules.gni") +import("//build/config/compiler/compiler.gni") +import("//build/config/dcheck_always_on.gni") +import("//build/toolchain/toolchain.gni") + +assert(is_android) + +# Creates a dist directory for a native executable. +# +# Running a native executable on a device requires all the shared library +# dependencies of that executable. To make it easier to install and run such an +# executable, this will create a directory containing the native exe and all +# it's library dependencies. +# +# Note: It's usually better to package things as an APK than as a native +# executable. +# +# Variables +# dist_dir: Directory for the exe and libraries. Everything in this directory +# will be deleted before copying in the exe and libraries. +# binary: Path to (stripped) executable. +# extra_files: List of extra files to copy in (optional). +# +# Example +# create_native_executable_dist("foo_dist") { +# dist_dir = "$root_build_dir/foo_dist" +# binary = "$root_build_dir/foo" +# deps = [ ":the_thing_that_makes_foo" ] +# } +template("create_native_executable_dist") { + forward_variables_from(invoker, [ "testonly" ]) + + _libraries_list = "${target_gen_dir}/${target_name}_library_dependencies.list" + + _find_deps_target_name = "${target_name}__find_library_dependencies" + + # TODO(agrieve): Extract dependent libs from GN rather than readelf. + action(_find_deps_target_name) { + forward_variables_from(invoker, [ "deps" ]) + + script = "//build/android/gyp/write_ordered_libraries.py" + depfile = "$target_gen_dir/$target_name.d" + inputs = [ + invoker.binary, + android_readelf, + ] + outputs = [ + _libraries_list, + ] + rebased_binaries = rebase_path([ invoker.binary ], root_build_dir) + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--input-libraries=$rebased_binaries", + "--libraries-dir", + rebase_path(root_shlib_dir, root_build_dir), + "--output", + rebase_path(_libraries_list, root_build_dir), + "--readelf", + rebase_path(android_readelf, root_build_dir), + ] + } + + copy_ex(target_name) { + clear_dir = true + + inputs = [ + _libraries_list, + invoker.binary, + ] + + dest = invoker.dist_dir + data = [ + "${invoker.dist_dir}/", + ] + + _rebased_libraries_list = rebase_path(_libraries_list, root_build_dir) + _rebased_binaries_list = rebase_path([ invoker.binary ], root_build_dir) + args = [ + "--files=@FileArg($_rebased_libraries_list:lib_paths)", + "--files=$_rebased_binaries_list", + ] + if (defined(invoker.extra_files)) { + _rebased_extra_files = rebase_path(invoker.extra_files, root_build_dir) + args += [ "--files=$_rebased_extra_files" ] + } + + deps = [ + ":$_find_deps_target_name", + ] + if (defined(invoker.deps)) { + deps += invoker.deps + } + } +} + +# Writes a script to root_out_dir/bin that passes --output-directory to the +# wrapped script, in addition to forwarding arguments. Most / all of these +# wrappers should be made deps of //tools/android:android_tools. +# +# Variables +# target: Script to wrap. +# flag_name: Default is "--output-directory" +# +# Example +# wrapper_script("foo_wrapper") { +# target = "//pkg/foo.py" +# } +template("wrapper_script") { + action(target_name) { + _name = get_path_info(invoker.target, "name") + _output = "$root_out_dir/bin/$_name" + + script = "//build/android/gyp/create_tool_wrapper.py" + outputs = [ + _output, + ] + + # The target isn't actually used by the script, but it's nice to have GN + # check that it exists. + inputs = [ + invoker.target, + ] + args = [ + "--output", + rebase_path(_output, root_build_dir), + "--target", + rebase_path(invoker.target, root_build_dir), + "--output-directory", + rebase_path(root_out_dir, root_build_dir), + ] + if (defined(invoker.flag_name)) { + args += [ "--flag-name=${invoker.flag_name}" ] + } + } +} + +if (enable_java_templates) { + import("//build/config/sanitizers/sanitizers.gni") + import("//tools/grit/grit_rule.gni") + + # Declare a jni target + # + # This target generates the native jni bindings for a set of .java files. + # + # See base/android/jni_generator/jni_generator.py for more info about the + # format of generating JNI bindings. + # + # Variables + # sources: list of .java files to generate jni for + # jni_package: subdirectory path for generated bindings + # + # Example + # generate_jni("foo_jni") { + # sources = [ + # "android/java/src/org/chromium/foo/Foo.java", + # "android/java/src/org/chromium/foo/FooUtil.java", + # ] + # jni_package = "foo" + # } + template("generate_jni") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + assert(defined(invoker.sources)) + assert(defined(invoker.jni_package)) + jni_package = invoker.jni_package + base_output_dir = "${target_gen_dir}/${target_name}" + package_output_dir = "${base_output_dir}/${jni_package}" + jni_output_dir = "${package_output_dir}/jni" + + jni_generator_include = + "//base/android/jni_generator/jni_generator_helper.h" + + foreach_target_name = "${target_name}__jni_gen" + action_foreach(foreach_target_name) { + script = "//base/android/jni_generator/jni_generator.py" + depfile = "$target_gen_dir/$target_name.{{source_name_part}}.d" + sources = invoker.sources + outputs = [ + "${jni_output_dir}/{{source_name_part}}_jni.h", + ] + + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--input_file={{source}}", + "--optimize_generation=1", + "--ptr_type=long", + "--output_dir", + rebase_path(jni_output_dir, root_build_dir), + "--includes", + rebase_path(jni_generator_include, jni_output_dir), + "--native_exports_optional", + ] + + if (enable_profiling) { + args += [ "--enable_profiling" ] + } + } + + config("jni_includes_${target_name}") { + # TODO(cjhopman): #includes should probably all be relative to + # base_output_dir. Remove that from this config once the includes are + # updated. + include_dirs = [ + base_output_dir, + package_output_dir, + ] + } + + group(target_name) { + forward_variables_from(invoker, + [ + "deps", + "public_deps", + "visibility", + ]) + if (!defined(public_deps)) { + public_deps = [] + } + public_deps += [ ":$foreach_target_name" ] + public_configs = [ ":jni_includes_${target_name}" ] + } + } + + # Declare a jni target for a prebuilt jar + # + # This target generates the native jni bindings for a set of classes in a .jar. + # + # See base/android/jni_generator/jni_generator.py for more info about the + # format of generating JNI bindings. + # + # Variables + # classes: list of .class files in the jar to generate jni for. These should + # include the full path to the .class file. + # jni_package: subdirectory path for generated bindings + # jar_file: the path to the .jar. If not provided, will default to the sdk's + # android.jar + # + # deps, public_deps: As normal + # + # Example + # generate_jar_jni("foo_jni") { + # classes = [ + # "android/view/Foo.class", + # ] + # jni_package = "foo" + # } + template("generate_jar_jni") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + assert(defined(invoker.classes)) + assert(defined(invoker.jni_package)) + + if (defined(invoker.jar_file)) { + jar_file = invoker.jar_file + } else { + jar_file = android_sdk_jar + } + + jni_package = invoker.jni_package + base_output_dir = "${root_gen_dir}/${target_name}/${jni_package}" + jni_output_dir = "${base_output_dir}/jni" + + jni_generator_include = + "//base/android/jni_generator/jni_generator_helper.h" + + # TODO(cjhopman): make jni_generator.py support generating jni for multiple + # .class files from a .jar. + jni_actions = [] + foreach(class, invoker.classes) { + _classname_list = [] + _classname_list = process_file_template([ class ], "{{source_name_part}}") + classname = _classname_list[0] + jni_target_name = "${target_name}__jni_${classname}" + jni_actions += [ ":$jni_target_name" ] + action(jni_target_name) { + # The sources aren't compiled so don't check their dependencies. + check_includes = false + depfile = "$target_gen_dir/$target_name.d" + script = "//base/android/jni_generator/jni_generator.py" + sources = [ + jar_file, + ] + outputs = [ + "${jni_output_dir}/${classname}_jni.h", + ] + + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--jar_file", + rebase_path(jar_file, root_build_dir), + "--input_file", + class, + "--optimize_generation=1", + "--ptr_type=long", + "--output_dir", + rebase_path(jni_output_dir, root_build_dir), + "--includes", + rebase_path(jni_generator_include, jni_output_dir), + "--native_exports_optional", + ] + + if (enable_profiling) { + args += [ "--enable_profiling" ] + } + } + } + + config("jni_includes_${target_name}") { + include_dirs = [ base_output_dir ] + } + + group(target_name) { + public_deps = [] + forward_variables_from(invoker, + [ + "deps", + "public_deps", + "visibility", + ]) + public_deps += jni_actions + public_configs = [ ":jni_includes_${target_name}" ] + } + } + + # Declare a target for c-preprocessor-generated java files + # + # NOTE: For generating Java conterparts to enums prefer using the java_cpp_enum + # rule instead. + # + # This target generates java files using the host C pre-processor. Each file in + # sources will be compiled using the C pre-processor. If include_path is + # specified, it will be passed (with --I) to the pre-processor. + # + # This target will create a single .srcjar. Adding this target to an + # android_library target's srcjar_deps will make the generated java files be + # included in that library's final outputs. + # + # Variables + # sources: list of files to be processed by the C pre-processor. For each + # file in sources, there will be one .java file in the final .srcjar. For a + # file named FooBar.template, a java file will be created with name + # FooBar.java. + # inputs: additional compile-time dependencies. Any files + # `#include`-ed in the templates should be listed here. + # package_name: this will be the subdirectory for each .java file in the + # .srcjar. + # + # Example + # java_cpp_template("foo_generated_enum") { + # sources = [ + # "android/java/templates/Foo.template", + # ] + # inputs = [ + # "android/java/templates/native_foo_header.h", + # ] + # + # package_name = "org/chromium/base/library_loader" + # include_path = "android/java/templates" + # } + template("java_cpp_template") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + _include_path = "//" + if (defined(invoker.include_path)) { + _include_path = invoker.include_path + } + + _apply_gcc_target_name = "${target_name}__apply_gcc" + _base_gen_dir = "${target_gen_dir}/${target_name}/java_cpp_template" + + action_foreach(_apply_gcc_target_name) { + forward_variables_from(invoker, + [ + "deps", + "public_deps", + "data_deps", + ]) + script = "//build/android/gyp/gcc_preprocess.py" + if (defined(invoker.inputs)) { + inputs = invoker.inputs + [] + } + depfile = + "${target_gen_dir}/${invoker.target_name}_{{source_name_part}}.d" + + sources = invoker.sources + + outputs = [ + "$_base_gen_dir/${invoker.package_name}/{{source_name_part}}.java", + ] + + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--include-path", + rebase_path(_include_path, root_build_dir), + "--output", + rebase_path(outputs[0], root_build_dir), + "--template={{source}}", + ] + + if (defined(invoker.defines)) { + foreach(def, invoker.defines) { + args += [ + "--defines", + def, + ] + } + } + } + + # Filter out .d files. + set_sources_assignment_filter([ "*.d" ]) + sources = get_target_outputs(":$_apply_gcc_target_name") + + zip(target_name) { + forward_variables_from(invoker, [ "visibility" ]) + inputs = sources + output = "${target_gen_dir}/${target_name}.srcjar" + base_dir = _base_gen_dir + deps = [ + ":$_apply_gcc_target_name", + ] + } + } + + # Declare a target for generating Java classes from C++ enums. + # + # This target generates Java files from C++ enums using a script. + # + # This target will create a single .srcjar. Adding this target to an + # android_library target's srcjar_deps will make the generated java files be + # included in that library's final outputs. + # + # Variables + # sources: list of files to be processed by the script. For each annotated + # enum contained in the sources files the script will generate a .java + # file with the same name as the name of the enum. + # + # Example + # java_cpp_enum("foo_generated_enum") { + # sources = [ + # "src/native_foo_header.h", + # ] + # } + template("java_cpp_enum") { + action(target_name) { + # The sources aren't compiled so don't check their dependencies. + check_includes = false + set_sources_assignment_filter([]) + + assert(defined(invoker.sources)) + forward_variables_from(invoker, + [ + "sources", + "testonly", + "visibility", + ]) + + script = "//build/android/gyp/java_cpp_enum.py" + depfile = "$target_gen_dir/$target_name.d" + + _srcjar_path = "${target_gen_dir}/${target_name}.srcjar" + _rebased_srcjar_path = rebase_path(_srcjar_path, root_build_dir) + _rebased_sources = rebase_path(invoker.sources, root_build_dir) + + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--srcjar=$_rebased_srcjar_path", + ] + _rebased_sources + outputs = [ + _srcjar_path, + ] + } + } + + # Declare a target for processing a Jinja template. + # + # Variables + # input: The template file to be processed. + # output: Where to save the result. + # variables: (Optional) A list of variables to make available to the template + # processing environment, e.g. ["name=foo", "color=red"]. + # + # Example + # jinja_template("chrome_public_manifest") { + # input = "java/AndroidManifest.xml" + # output = "$target_gen_dir/AndroidManifest.xml" + # } + template("jinja_template") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + assert(defined(invoker.input)) + assert(defined(invoker.output)) + + action(target_name) { + forward_variables_from(invoker, + [ + "visibility", + "deps", + ]) + + sources = [ + invoker.input, + ] + script = "//build/android/gyp/jinja_template.py" + depfile = "$target_gen_dir/$target_name.d" + + outputs = [ + invoker.output, + ] + + args = [ + "--loader-base-dir", + rebase_path("//", root_build_dir), + "--inputs", + rebase_path(invoker.input, root_build_dir), + "--output", + rebase_path(invoker.output, root_build_dir), + "--depfile", + rebase_path(depfile, root_build_dir), + ] + if (defined(invoker.variables)) { + variables = invoker.variables + args += [ "--variables=${variables}" ] + } + } + } + + # Declare a target for processing Android resources as Jinja templates. + # + # This takes an Android resource directory where each resource is a Jinja + # template, processes each template, then packages the results in a zip file + # which can be consumed by an android resources, library, or apk target. + # + # If this target is included in the deps of an android resources/library/apk, + # the resources will be included with that target. + # + # Variables + # resources: The list of resources files to process. + # res_dir: The resource directory containing the resources. + # variables: (Optional) A list of variables to make available to the template + # processing environment, e.g. ["name=foo", "color=red"]. + # + # Example + # jinja_template_resources("chrome_public_template_resources") { + # res_dir = "res_template" + # resources = ["res_template/xml/syncable.xml"] + # variables = ["color=red"] + # } + template("jinja_template_resources") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + assert(defined(invoker.resources)) + assert(defined(invoker.res_dir)) + + _base_path = "$target_gen_dir/$target_name" + _resources_zip = _base_path + ".resources.zip" + _build_config = _base_path + ".build_config" + + write_build_config("${target_name}__build_config") { + build_config = _build_config + resources_zip = _resources_zip + type = "android_resources" + if (defined(invoker.deps)) { + possible_config_deps = invoker.deps + } + } + + action("${target_name}__template") { + forward_variables_from(invoker, [ "deps" ]) + sources = invoker.resources + script = "//build/android/gyp/jinja_template.py" + depfile = "$target_gen_dir/$target_name.d" + + outputs = [ + _resources_zip, + ] + + rebased_resources = rebase_path(invoker.resources, root_build_dir) + args = [ + "--inputs=${rebased_resources}", + "--inputs-base-dir", + rebase_path(invoker.res_dir, root_build_dir), + "--outputs-zip", + rebase_path(_resources_zip, root_build_dir), + "--depfile", + rebase_path(depfile, root_build_dir), + ] + if (defined(invoker.variables)) { + variables = invoker.variables + args += [ "--variables=${variables}" ] + } + } + + group(target_name) { + public_deps = [ + ":${target_name}__build_config", + ":${target_name}__template", + ] + } + } + + # Declare an Android resources target + # + # This creates a resources zip file that will be used when building an Android + # library or apk and included into a final apk. + # + # To include these resources in a library/apk, this target should be listed in + # the library's deps. A library/apk will also include any resources used by its + # own dependencies. + # + # Variables + # deps: Specifies the dependencies of this target. Any Android resources + # listed in deps will be included by libraries/apks that depend on this + # target. + # resource_dirs: List of directories containing resources for this target. + # generated_resource_dirs: List of directories containing resources for this + # target which are *generated* by a dependency. |generated_resource_files| + # must be specified if |generated_resource_dirs| is specified. + # generated_resource_files: List of all files in |generated_resource_dirs|. + # |generated_resource_dirs| must be specified in |generated_resource_files| + # is specified. + # android_manifest: AndroidManifest.xml for this target. Defaults to + # //build/android/AndroidManifest.xml. + # android_manifest_dep: Target that generates AndroidManifest (if applicable) + # custom_package: java package for generated .java files. + # v14_skip: If true, don't run v14 resource generator on this. Defaults to + # false. (see build/android/gyp/generate_v14_compatible_resources.py) + # shared_resources: If true make a resource package that can be loaded by a + # different application at runtime to access the package's resources. + # app_as_shared_lib: If true make a resource package that can be loaded as + # both shared_resources and normal application. + + # Example: + # android_resources("foo_resources") { + # deps = [":foo_strings_grd"] + # resource_dirs = ["res"] + # custom_package = "org.chromium.foo" + # } + # + # android_resources("foo_resources_overrides") { + # deps = [":foo_resources"] + # resource_dirs = ["res_overrides"] + # } + template("android_resources") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + assert(defined(invoker.resource_dirs)) + + base_path = "$target_gen_dir/$target_name" + zip_path = base_path + ".resources.zip" + srcjar_path = base_path + ".srcjar" + r_text_path = base_path + "_R.txt" + build_config = base_path + ".build_config" + + build_config_target_name = "${target_name}__build_config" + process_resources_target_name = "${target_name}__process_resources" + final_target_name = target_name + + write_build_config(build_config_target_name) { + type = "android_resources" + forward_variables_from(invoker, + [ + "android_manifest", + "custom_package", + ]) + resource_dirs = [] + if (defined(invoker.resource_dirs)) { + resource_dirs += invoker.resource_dirs + } + if (defined(invoker.generated_resource_dirs)) { + resource_dirs += invoker.generated_resource_dirs + } + + if (defined(invoker.deps)) { + possible_config_deps = invoker.deps + } + if (defined(invoker.android_manifest_dep)) { + deps = [ + invoker.android_manifest_dep, + ] + } + + # No package means resources override their deps. + if (defined(custom_package) || defined(android_manifest)) { + r_text = r_text_path + } else { + assert(defined(invoker.deps), + "Must specify deps when custom_package is omitted.") + } + + resources_zip = zip_path + srcjar = srcjar_path + } + + process_resources(process_resources_target_name) { + forward_variables_from(invoker, + [ + "app_as_shared_lib", + "android_manifest", + "custom_package", + "deps", + "generated_resource_dirs", + "generated_resource_files", + "resource_dirs", + "shared_resources", + "v14_skip", + ]) + if (!defined(deps)) { + deps = [] + } + deps += [ ":$build_config_target_name" ] + if (defined(invoker.android_manifest_dep)) { + deps += [ invoker.android_manifest_dep ] + } + + # Always generate R.onResourcesLoaded() method, it is required for + # compiling ResourceRewriter, there is no side effect because the + # generated R.class isn't used in final apk. + shared_resources = true + if (!defined(android_manifest)) { + android_manifest = "//build/android/AndroidManifest.xml" + } + } + + group(final_target_name) { + forward_variables_from(invoker, [ "visibility" ]) + public_deps = [ + ":${target_name}__process_resources", + ] + } + } + + # Declare an Android assets target. + # + # Defines a set of files to include as assets in a dependent apk. + # + # To include these assets in an apk, this target should be listed in + # the apk's deps, or in the deps of a library target used by an apk. + # + # Variables + # deps: Specifies the dependencies of this target. Any Android assets + # listed in deps will be included by libraries/apks that depend on this + # target. + # sources: List of files to include as assets. + # renaming_sources: List of files to include as assets and be renamed. + # renaming_destinations: List of asset paths for files in renaming_sources. + # disable_compression: Whether to disable compression for files that are + # known to be compressable (default: false). + # + # Example: + # android_assets("content_shell_assets") { + # deps = [ + # ":generates_foo", + # ":other_assets", + # ] + # sources = [ + # "//path/asset1.png", + # "//path/asset2.png", + # "$target_gen_dir/foo.dat", + # ] + # } + # + # android_assets("overriding_content_shell_assets") { + # deps = [ ":content_shell_assets" ] + # # Override foo.dat from content_shell_assets. + # sources = [ "//custom/foo.dat" ] + # renaming_sources = [ "//path/asset2.png" ] + # renaming_destinations = [ "renamed/asset2.png" ] + # } + template("android_assets") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + _build_config = "$target_gen_dir/$target_name.build_config" + _build_config_target_name = "${target_name}__build_config" + + write_build_config(_build_config_target_name) { + type = "android_assets" + build_config = _build_config + + forward_variables_from(invoker, [ "disable_compression" ]) + + if (defined(invoker.deps)) { + possible_config_deps = invoker.deps + } + + if (defined(invoker.sources)) { + asset_sources = invoker.sources + } + if (defined(invoker.renaming_sources)) { + assert(defined(invoker.renaming_destinations)) + _source_count = 0 + foreach(_, invoker.renaming_sources) { + _source_count += 1 + } + _dest_count = 0 + foreach(_, invoker.renaming_destinations) { + _dest_count += 1 + } + assert( + _source_count == _dest_count, + "android_assets() renaming_sources.length != renaming_destinations.length") + asset_renaming_sources = invoker.renaming_sources + asset_renaming_destinations = invoker.renaming_destinations + } + } + + group(target_name) { + forward_variables_from(invoker, + [ + "deps", + "visibility", + ]) + public_deps = [ + ":$_build_config_target_name", + ] + } + } + + # Declare a group() that supports forwarding java dependency information. + # + # Example + # java_group("conditional_deps") { + # if (enable_foo) { + # deps = [":foo_java"] + # } + # } + template("java_group") { + forward_variables_from(invoker, [ "testonly" ]) + write_build_config("${target_name}__build_config") { + type = "group" + build_config = "$target_gen_dir/${invoker.target_name}.build_config" + if (defined(invoker.deps)) { + possible_config_deps = invoker.deps + } + } + group(target_name) { + forward_variables_from(invoker, "*") + if (!defined(deps)) { + deps = [] + } + deps += [ ":${target_name}__build_config" ] + } + } + + # Declare a target that generates localized strings.xml from a .grd file. + # + # If this target is included in the deps of an android resources/library/apk, + # the strings.xml will be included with that target. + # + # Variables + # deps: Specifies the dependencies of this target. + # grd_file: Path to the .grd file to generate strings.xml from. + # outputs: Expected grit outputs (see grit rule). + # + # Example + # java_strings_grd("foo_strings_grd") { + # grd_file = "foo_strings.grd" + # } + template("java_strings_grd") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + base_path = "$target_gen_dir/$target_name" + resources_zip = base_path + ".resources.zip" + build_config = base_path + ".build_config" + + write_build_config("${target_name}__build_config") { + type = "android_resources" + } + + # Put grit files into this subdirectory of target_gen_dir. + extra_output_path = target_name + "_grit_output" + + grit_target_name = "${target_name}__grit" + grit_output_dir = "$target_gen_dir/$extra_output_path" + grit(grit_target_name) { + forward_variables_from(invoker, [ "deps" ]) + grit_flags = [ + "-E", + "ANDROID_JAVA_TAGGED_ONLY=false", + ] + output_dir = grit_output_dir + resource_ids = "" + source = invoker.grd_file + outputs = invoker.outputs + } + + # This needs to get outputs from grit's internal target, not the final + # source_set. + generate_strings_outputs = get_target_outputs(":${grit_target_name}_grit") + + zip("${target_name}__zip") { + base_dir = grit_output_dir + inputs = generate_strings_outputs + output = resources_zip + deps = [ + ":$grit_target_name", + ] + } + + group(target_name) { + public_deps = [ + ":${target_name}__build_config", + ":${target_name}__zip", + ] + } + } + + # Declare a target that packages strings.xml generated from a grd file. + # + # If this target is included in the deps of an android resources/library/apk, + # the strings.xml will be included with that target. + # + # Variables + # grit_output_dir: directory containing grit-generated files. + # generated_files: list of android resource files to package. + # + # Example + # java_strings_grd_prebuilt("foo_strings_grd") { + # grit_output_dir = "$root_gen_dir/foo/grit" + # generated_files = [ + # "values/strings.xml" + # ] + # } + template("java_strings_grd_prebuilt") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + base_path = "$target_gen_dir/$target_name" + resources_zip = base_path + ".resources.zip" + build_config = base_path + ".build_config" + + build_config_target_name = "${target_name}__build_config" + zip_target_name = "${target_name}__zip" + final_target_name = target_name + + write_build_config(build_config_target_name) { + type = "android_resources" + } + + zip(zip_target_name) { + visibility = [ ":$final_target_name" ] + + base_dir = invoker.grit_output_dir + inputs = rebase_path(invoker.generated_files, ".", base_dir) + output = resources_zip + deps = [ + ":$build_config_target_name", + ] + if (defined(invoker.deps)) { + deps += invoker.deps + } + } + + group(final_target_name) { + forward_variables_from(invoker, [ "visibility" ]) + public_deps = [ + ":$zip_target_name", + ] + } + } + + # Declare a Java executable target + # + # This target creates an executable from java code and libraries. The executable + # will be in the output folder's /bin/ directory. + # + # Variables + # deps: Specifies the dependencies of this target. Java targets in this list + # will be included in the executable (and the javac classpath). + # java_files: List of .java files included in this library. + # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars + # will be added to java_files and be included in this library. + # srcjars: List of srcjars to be included in this library, together with the + # ones obtained from srcjar_deps. + # bypass_platform_checks: Disables checks about cross-platform (Java/Android) + # dependencies for this target. This will allow depending on an + # android_library target, for example. + # chromium_code: If true, extra analysis warning/errors will be enabled. + # enable_errorprone: If true, enables the errorprone compiler. + # enable_incremental_javac_override: Overrides the + # global enable_incremental_javac. + # main_class: When specified, a wrapper script is created within + # $root_build_dir/bin to launch the binary with the given class as the + # entrypoint. + # wrapper_script_args: List of additional arguments for the wrapper script. + # + # data_deps, testonly + # + # Example + # java_binary("foo") { + # java_files = [ "org/chromium/foo/FooMain.java" ] + # deps = [ ":bar_java" ] + # main_class = "org.chromium.foo.FooMain" + # } + template("java_binary") { + set_sources_assignment_filter([]) + + java_library_impl(target_name) { + forward_variables_from(invoker, "*") + supports_android = false + main_class = invoker.main_class + is_java_binary = true + } + } + + # Declare a Junit executable target + # + # This target creates an executable from java code for running as a junit test + # suite. The executable will be in the output folder's /bin/ directory. + # + # Variables + # deps: Specifies the dependencies of this target. Java targets in this list + # will be included in the executable (and the javac classpath). + # + # java_files: List of .java files included in this library. + # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars + # will be added to java_files and be included in this library. + # srcjars: List of srcjars to be included in this library, together with the + # ones obtained from srcjar_deps. + # + # chromium_code: If true, extra analysis warning/errors will be enabled. + # + # Example + # junit_binary("foo") { + # java_files = [ "org/chromium/foo/FooTest.java" ] + # deps = [ ":bar_java" ] + # } + template("junit_binary") { + set_sources_assignment_filter([]) + testonly = true + + _java_binary_target_name = "${target_name}__java_binary" + _test_runner_target_name = "${target_name}__test_runner_script" + + test_runner_script(_test_runner_target_name) { + test_name = invoker.target_name + test_suite = invoker.target_name + test_type = "junit" + ignore_all_data_deps = true + } + + java_binary(_java_binary_target_name) { + deps = [] + output_name = invoker.target_name + forward_variables_from(invoker, "*") + testonly = true + bypass_platform_checks = true + main_class = "org.chromium.testing.local.JunitTestMain" + wrapper_script_name = "helper/$target_name" + deps += [ + "//testing/android/junit:junit_test_support", + "//third_party/junit", + "//third_party/mockito:mockito_java", + "//third_party/robolectric:robolectric_all_java", + ] + } + group(target_name) { + public_deps = [ + ":$_java_binary_target_name", + ":$_test_runner_target_name", + ] + } + } + + # Declare a java library target + # + # Variables + # deps: Specifies the dependencies of this target. Java targets in this list + # will be added to the javac classpath. + # + # java_files: List of .java files included in this library. + # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars + # will be added to java_files and be included in this library. + # srcjars: List of srcjars to be included in this library, together with the + # ones obtained from srcjar_deps. + # + # input_jars_paths: A list of paths to the jars that should be included + # in the classpath. These are in addition to library .jars that + # appear in deps. + # + # chromium_code: If true, extra analysis warning/errors will be enabled. + # enable_errorprone: If true, enables the errorprone compiler. + # enable_incremental_javac_override: Overrides the global + # enable_incremental_javac. + # + # jar_excluded_patterns: List of patterns of .class files to exclude from the + # final jar. + # + # output_name: File name for the output .jar (not including extension). + # Defaults to the input .jar file name. + # + # proguard_preprocess: If true, proguard preprocessing will be run. This can + # be used to remove unwanted parts of the library. + # proguard_preprocess_config: Path to the proguard config for preprocessing. + # proguard_configs: List of proguard configs to use in final apk step for + # any apk that depends on this library. + # + # supports_android: If true, Android targets (android_library, android_apk) + # may depend on this target. Note: if true, this target must only use the + # subset of Java available on Android. + # bypass_platform_checks: Disables checks about cross-platform (Java/Android) + # dependencies for this target. This will allow depending on an + # android_library target, for example. + # + # additional_jar_files: Use to package additional files into the output jar. + # Pass a list of length-2 lists with format + # [ [ path_to_file, path_to_put_in_jar ] ] + # + # + # data_deps, testonly + # + # Example + # java_library("foo_java") { + # java_files = [ + # "org/chromium/foo/Foo.java", + # "org/chromium/foo/FooInterface.java", + # "org/chromium/foo/FooService.java", + # ] + # deps = [ + # ":bar_java" + # ] + # srcjar_deps = [ + # ":foo_generated_enum" + # ] + # jar_excluded_patterns = [ + # "*/FooService.class", "*/FooService\$*.class" + # ] + # } + template("java_library") { + set_sources_assignment_filter([]) + java_library_impl(target_name) { + forward_variables_from(invoker, "*") + } + } + + # Declare a java library target for a prebuilt jar + # + # Variables + # deps: Specifies the dependencies of this target. Java targets in this list + # will be added to the javac classpath. + # jar_path: Path to the prebuilt jar. + # jar_dep: Target that builds jar_path (optional). + # main_class: When specified, a wrapper script is created within + # $root_build_dir/bin to launch the binary with the given class as the + # entrypoint. + # output_name: File name for the output .jar (not including extension). + # Defaults to the input .jar file name. + # proguard_preprocess: If true, proguard preprocessing will be run. This can + # be used to remove unwanted parts of the library. + # proguard_preprocess_config: Path to the proguard config for preprocessing. + # proguard_configs: List of proguard configs to use in final apk step for + # any apk that depends on this library. + # supports_android: If true, Android targets (android_library, android_apk) + # may depend on this target. Note: if true, this target must only use the + # subset of Java available on Android. + # + # Example + # java_prebuilt("foo_java") { + # jar_path = "foo.jar" + # deps = [ + # ":foo_resources", + # ":bar_java" + # ] + # } + template("java_prebuilt") { + set_sources_assignment_filter([]) + java_prebuilt_impl(target_name) { + forward_variables_from(invoker, "*") + } + } + + # Declare an Android library target + # + # This target creates an Android library containing java code and Android + # resources. + # + # Variables + # deps: Specifies the dependencies of this target. Java targets in this list + # will be added to the javac classpath. Android resources in dependencies + # will be used when building this library. + # + # java_files: List of .java files included in this library. + # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars + # will be added to java_files and be included in this library. + # srcjars: List of srcjars to be included in this library, together with the + # ones obtained from srcjar_deps. + # + # input_jars_paths: A list of paths to the jars that should be included + # in the classpath. These are in addition to library .jars that + # appear in deps. + # + # chromium_code: If true, extra analysis warning/errors will be enabled. + # enable_errorprone: If true, enables the errorprone compiler. + # enable_incremental_javac_override: Overrides the global + # enable_incremental_javac. + # + # jar_excluded_patterns: List of patterns of .class files to exclude from the + # final jar. + # + # proguard_preprocess: If true, proguard preprocessing will be run. This can + # be used to remove unwanted parts of the library. + # proguard_preprocess_config: Path to the proguard config for preprocessing. + # proguard_configs: List of proguard configs to use in final apk step for + # any apk that depends on this library. + # + # output_name: File name for the output .jar (not including extension). + # Defaults to the input .jar file name. + # dex_path: If set, the resulting .dex.jar file will be placed under this + # path. + # + # alternative_android_sdk_ijar: if set, the given android_sdk_ijar file + # replaces the default android_sdk_ijar. + # + # alternative_android_sdk_ijar_dep: the target that generates + # alternative_android_sdk_ijar, must be set if alternative_android_sdk_ijar + # is used. + # + # emma_never_instrument: Disables EMMA Java code coverage for this target. + # + # Example + # android_library("foo_java") { + # java_files = [ + # "android/org/chromium/foo/Foo.java", + # "android/org/chromium/foo/FooInterface.java", + # "android/org/chromium/foo/FooService.java", + # ] + # deps = [ + # ":bar_java" + # ] + # srcjar_deps = [ + # ":foo_generated_enum" + # ] + # jar_excluded_patterns = [ + # "*/FooService.class", "*/FooService\$*.class" + # ] + # } + template("android_library") { + set_sources_assignment_filter([]) + assert(!defined(invoker.jar_path), + "android_library does not support a custom jar path") + + if (defined(invoker.alternative_android_sdk_ijar)) { + assert(defined(invoker.alternative_android_sdk_ijar_dep)) + } + + java_library_impl(target_name) { + forward_variables_from(invoker, "*") + + supports_android = true + requires_android = true + + if (!defined(jar_excluded_patterns)) { + jar_excluded_patterns = [] + } + jar_excluded_patterns += [ + "*/R.class", + "*/R\$*.class", + "*/Manifest.class", + "*/Manifest\$*.class", + ] + } + } + + # Declare a target that packages a set of Java dependencies into a standalone + # .dex.jar. + # + # Variables + # deps: specifies the dependencies of this target. Android libraries in deps + # will be packaged into the resulting .dex.jar file. + # dex_path: location at which the output file will be put + template("android_standalone_library") { + set_sources_assignment_filter([]) + deps_dex(target_name) { + forward_variables_from(invoker, + [ + "deps", + "dex_path", + "excluded_jars", + ]) + } + } + + # Declare an Android library target for a prebuilt jar + # + # This target creates an Android library containing java code and Android + # resources. + # + # Variables + # deps: Specifies the dependencies of this target. Java targets in this list + # will be added to the javac classpath. Android resources in dependencies + # will be used when building this library. + # jar_path: Path to the prebuilt jar. + # output_name: File name for the output .jar (not including extension). + # Defaults to the input .jar file name. + # proguard_preprocess: If true, proguard preprocessing will be run. This can + # be used to remove unwanted parts of the library. + # proguard_preprocess_config: Path to the proguard config for preprocessing. + # proguard_configs: List of proguard configs to use in final apk step for + # any apk that depends on this library. + # + # Example + # android_java_prebuilt("foo_java") { + # jar_path = "foo.jar" + # deps = [ + # ":foo_resources", + # ":bar_java" + # ] + # } + template("android_java_prebuilt") { + set_sources_assignment_filter([]) + java_prebuilt_impl(target_name) { + forward_variables_from(invoker, "*") + supports_android = true + requires_android = true + strip_resource_classes = true + } + } + + # Declare an Android apk target + # + # This target creates an Android APK containing java code, resources, assets, + # and (possibly) native libraries. + # + # Variables + # alternative_android_sdk_jar: The alternative android sdk jar used in + # proguard. + # android_aapt_path: Android aapt tool to replace default one to build + # resource. + # android_manifest: Path to AndroidManifest.xml. + # android_manifest_dep: Target that generates AndroidManifest (if applicable) + # chromium_code: If true, extra analysis warning/errors will be enabled. + # dist_ijar_path: Path to create "${target_name}_dist_ijar" target + # (used by instrumentation_test_apk). + # data_deps: List of dependencies needed at runtime. These will be built but + # won't change the generated .apk in any way (in fact they may be built + # after the .apk is). + # deps: List of dependencies. All Android java resources and libraries in the + # "transitive closure" of these dependencies will be included in the apk. + # Note: this "transitive closure" actually only includes such targets if + # they are depended on through android_library or android_resources targets + # (and so not through builtin targets like 'action', 'group', etc). + # install_script_name: Name of wrapper script (default=target_name). + # java_files: List of .java files to include in the apk. + # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars + # will be added to java_files and be included in this apk. + # apk_name: Name for final apk. + # final_apk_path: Path to final built apk. Default is + # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name. + # loadable_modules: List of paths to native libraries to include. Different + # from |shared_libraries| in that: + # * dependencies of this .so are not automatically included + # * ".cr.so" is never added + # * they are not side-loaded for _incremental targets. + # * load_library_from_apk, use_chromium_linker, + # and enable_relocation_packing do not apply + # Use this instead of shared_libraries when you are going to load the library + # conditionally, and only when shared_libraries doesn't work for you. + # shared_libraries: List shared_library targets to bundle. If these + # libraries depend on other shared_library targets, those dependencies will + # also be included in the apk (e.g. for is_component_build). + # secondary_abi_shared_libraries: secondary abi shared_library targets to + # bundle. If these libraries depend on other shared_library targets, those + # dependencies will also be included in the apk (e.g. for is_component_build). + # native_lib_placeholders: List of placeholder filenames to add to the apk + # (optional). + # apk_under_test: For an instrumentation test apk, this is the target of the + # tested apk. + # include_all_resources - If true include all resource IDs in all generated + # R.java files. + # testonly: Marks this target as "test-only". + # write_asset_list: Adds an extra file to the assets, which contains a list of + # all other asset files. + # requires_sdk_api_level_23: If defined and true, the apk is intended for + # installation only on Android M or later. In these releases the system + # linker does relocation unpacking, so we can enable it unconditionally. + # secondary_native_libs (deprecated): The path of native libraries for secondary + # app abi. + # run_findbugs_override: Forces run_findbugs on or off. If undefined, the + # default will use the build arg run_findbugs. + # proguard_jar_path: The path to proguard.jar you wish to use. If undefined, + # the proguard used will be the checked in one in //third_party/proguard. + # + # Example + # android_apk("foo_apk") { + # android_manifest = "AndroidManifest.xml" + # java_files = [ + # "android/org/chromium/foo/FooApplication.java", + # "android/org/chromium/foo/FooActivity.java", + # ] + # deps = [ + # ":foo_support_java" + # ":foo_resources" + # ] + # srcjar_deps = [ + # ":foo_generated_enum" + # ] + # shared_libraries = [ + # ":my_shared_lib", + # ] + # } + template("android_apk") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + assert(defined(invoker.final_apk_path) || defined(invoker.apk_name)) + assert(defined(invoker.android_manifest)) + gen_dir = "$target_gen_dir/$target_name" + base_path = "$gen_dir/$target_name" + _build_config = "$target_gen_dir/$target_name.build_config" + resources_zip_path = "$base_path.resources.zip" + _all_resources_zip_path = "$base_path.resources.all.zip" + _jar_path = "$base_path.jar" + _lib_dex_path = "$base_path.dex.jar" + _rebased_lib_dex_path = rebase_path(_lib_dex_path, root_build_dir) + _template_name = target_name + + enable_multidex = + defined(invoker.enable_multidex) && invoker.enable_multidex + if (enable_multidex) { + final_dex_path = "$gen_dir/classes.dex.zip" + } else { + final_dex_path = "$gen_dir/classes.dex" + } + final_dex_target_name = "${_template_name}__final_dex" + + _final_apk_path = "" + if (defined(invoker.final_apk_path)) { + _final_apk_path = invoker.final_apk_path + } else if (defined(invoker.apk_name)) { + _final_apk_path = "$root_build_dir/apks/" + invoker.apk_name + ".apk" + } + _final_apk_path_no_ext_list = + process_file_template([ _final_apk_path ], + "{{source_dir}}/{{source_name_part}}") + _final_apk_path_no_ext = _final_apk_path_no_ext_list[0] + assert(_final_apk_path_no_ext != "") # Mark as used. + + _install_script_name = "install_$_template_name" + if (defined(invoker.install_script_name)) { + _install_script_name = invoker.install_script_name + } + _incremental_install_script_path = + "${root_out_dir}/bin/${_install_script_name}_incremental" + + _version_code = android_default_version_code + if (defined(invoker.version_code)) { + _version_code = invoker.version_code + } + + _version_name = android_default_version_name + if (defined(invoker.version_name)) { + _version_name = invoker.version_name + } + _keystore_path = android_keystore_path + _keystore_name = android_keystore_name + _keystore_password = android_keystore_password + + if (defined(invoker.keystore_path)) { + _keystore_path = invoker.keystore_path + _keystore_name = invoker.keystore_name + _keystore_password = invoker.keystore_password + } + + _srcjar_deps = [] + if (defined(invoker.srcjar_deps)) { + _srcjar_deps += invoker.srcjar_deps + } + + _use_chromium_linker = + defined(invoker.use_chromium_linker) && invoker.use_chromium_linker + _enable_relocation_packing = defined(invoker.enable_relocation_packing) && + invoker.enable_relocation_packing + _load_library_from_apk = + defined(invoker.load_library_from_apk) && invoker.load_library_from_apk + _requires_sdk_api_level_23 = defined(invoker.requires_sdk_api_level_23) && + invoker.requires_sdk_api_level_23 + + assert(_use_chromium_linker || true) # Mark as used. + assert(_requires_sdk_api_level_23 || true) + if (_enable_relocation_packing) { + assert(_use_chromium_linker || _requires_sdk_api_level_23, + "enable_relocation_packing requires either use_chromium_linker " + + "or requires_sdk_api_level_23") + } + if (_load_library_from_apk) { + assert(_use_chromium_linker || _requires_sdk_api_level_23, + "load_library_from_apk requires use_chromium_linker " + + "or requires_sdk_api_level_23") + } + + # The dependency that makes the chromium linker, if any is needed. + _native_libs_deps = [] + _shared_libraries_is_valid = + defined(invoker.shared_libraries) && invoker.shared_libraries != [] + _secondary_abi_native_libs_deps = [] + assert(_secondary_abi_native_libs_deps == []) # mark as used. + _secondary_abi_shared_libraries_is_valid = + defined(invoker.secondary_abi_shared_libraries) && + invoker.secondary_abi_shared_libraries != [] + + if (is_component_build || is_asan) { + if (_shared_libraries_is_valid) { + _native_libs_deps += [ "//build/android:cpplib_stripped" ] + } + if (_secondary_abi_shared_libraries_is_valid) { + _secondary_abi_native_libs_deps += [ "//build/android:cpplib_stripped($android_secondary_abi_toolchain)" ] + } + } + + if (_shared_libraries_is_valid) { + _native_libs_deps += invoker.shared_libraries + + # To determine the filenames of all dependent shared libraries, write the + # runtime deps of |shared_libraries| to a file during "gn gen". + # write_build_config.py will then grep this file for *.so to obtain the + # complete list. + _runtime_deps_file = + "$target_gen_dir/${_template_name}.native.runtimedeps" + group("${_template_name}__runtime_deps") { + deps = _native_libs_deps + write_runtime_deps = _runtime_deps_file + } + + _native_lib_version_rule = "" + if (defined(invoker.native_lib_version_rule)) { + _native_lib_version_rule = invoker.native_lib_version_rule + } + _native_lib_version_arg = "\"\"" + if (defined(invoker.native_lib_version_arg)) { + _native_lib_version_arg = invoker.native_lib_version_arg + } + } + + if (_secondary_abi_shared_libraries_is_valid) { + _secondary_abi_native_libs_deps += invoker.secondary_abi_shared_libraries + + # To determine the filenames of all dependent shared libraries, write the + # runtime deps of |shared_libraries| to a file during "gn gen". + # write_build_config.py will then grep this file for *.so to obtain the + # complete list. + _secondary_abi_runtime_deps_file = + "$target_gen_dir/${_template_name}.secondary.abi.native.runtimedeps" + group("${_template_name}_secondary_abi__runtime_deps") { + deps = _secondary_abi_native_libs_deps + write_runtime_deps = _secondary_abi_runtime_deps_file + } + } + + if (defined(invoker.deps)) { + set_sources_assignment_filter([ "*manifest*" ]) + sources = invoker.deps + set_sources_assignment_filter([]) + if (sources != invoker.deps) { + _bad_deps = invoker.deps - sources + assert( + false, + "Possible manifest-generating dep found in deps. Use android_manifest_dep for this instead. Found: $_bad_deps") + } + sources = [] + } + _android_manifest_deps = [] + if (defined(invoker.android_manifest_dep)) { + _android_manifest_deps = [ invoker.android_manifest_dep ] + } + _android_manifest = invoker.android_manifest + + _rebased_build_config = rebase_path(_build_config, root_build_dir) + _create_abi_split = + defined(invoker.create_abi_split) && invoker.create_abi_split + _create_density_splits = + defined(invoker.create_density_splits) && invoker.create_density_splits + _create_language_splits = + defined(invoker.language_splits) && invoker.language_splits != [] + + # Help GN understand that _create_abi_split is not unused (bug in GN). + assert(_create_abi_split || true) + + _proguard_enabled = + defined(invoker.proguard_enabled) && invoker.proguard_enabled + if (_proguard_enabled) { + _proguard_output_jar_path = "$base_path.proguard.jar" + } + + _emma_never_instrument = defined(invoker.testonly) && invoker.testonly + + build_config_target = "${_template_name}__build_config" + write_build_config(build_config_target) { + forward_variables_from(invoker, [ "apk_under_test" ]) + type = "android_apk" + jar_path = _jar_path + dex_path = final_dex_path + apk_path = _final_apk_path + incremental_apk_path = "${_final_apk_path_no_ext}_incremental.apk" + incremental_install_script_path = _incremental_install_script_path + resources_zip = resources_zip_path + build_config = _build_config + android_manifest = _android_manifest + + deps = _android_manifest_deps + + if (defined(invoker.deps)) { + possible_config_deps = invoker.deps + } + + # Added emma to the target's classpath via its .build_config. + if (emma_coverage && !_emma_never_instrument) { + possible_config_deps += + [ "//third_party/android_tools:emma_device_java" ] + } + + proguard_enabled = _proguard_enabled + if (_proguard_enabled) { + proguard_info = "$_proguard_output_jar_path.info" + } + + # Don't depend on the runtime_deps target in order to avoid having to + # build the native libraries just to create the .build_config file. + # The dep is unnecessary since the runtime_deps file is created by gn gen + # and the runtime_deps file is added to write_build_config.py's depfile. + if (_native_libs_deps != []) { + shared_libraries_runtime_deps_file = _runtime_deps_file + } + if (_secondary_abi_native_libs_deps != []) { + secondary_abi_shared_libraries_runtime_deps_file = + _secondary_abi_runtime_deps_file + } + } + + _final_deps = [] + + _generated_proguard_config = "$base_path.resources.proguard.txt" + process_resources_target = "${_template_name}__process_resources" + process_resources(process_resources_target) { + forward_variables_from(invoker, + [ + "alternative_android_sdk_jar", + "android_aapt_path", + "app_as_shared_lib", + "include_all_resources", + "shared_resources", + ]) + srcjar_path = "${target_gen_dir}/${target_name}.srcjar" + r_text_path = "${target_gen_dir}/${target_name}_R.txt" + android_manifest = _android_manifest + resource_dirs = [ "//build/android/ant/empty/res" ] + zip_path = resources_zip_path + all_resources_zip_path = _all_resources_zip_path + generate_constant_ids = true + proguard_file = _generated_proguard_config + + build_config = _build_config + deps = _android_manifest_deps + [ ":$build_config_target" ] + if (defined(invoker.deps)) { + deps += invoker.deps + } + } + _srcjar_deps += [ ":$process_resources_target" ] + + if (_native_libs_deps != []) { + _enable_chromium_linker_tests = false + if (defined(invoker.enable_chromium_linker_tests)) { + _enable_chromium_linker_tests = invoker.enable_chromium_linker_tests + } + _ordered_libraries_json = + "$target_gen_dir/$target_name.ordered_libararies.json" + _rebased_ordered_libraries_json = + rebase_path(_ordered_libraries_json, root_build_dir) + _ordered_libraries_target = "${_template_name}__write_ordered_libraries" + + # TODO(agrieve): Make GN write runtime deps in dependency order so as to + # not need this manual sorting step. + action(_ordered_libraries_target) { + script = "//build/android/gyp/write_ordered_libraries.py" + deps = _native_libs_deps + [ ":$build_config_target" ] + outputs = [ + _ordered_libraries_json, + ] + _rebased_android_readelf = rebase_path(android_readelf, root_build_dir) + args = [ + "--readelf=$_rebased_android_readelf", + "--output=$_rebased_ordered_libraries_json", + "--libraries-dir=.", + "--input-libraries=@FileArg($_rebased_build_config:native:libraries)", + ] + } + + java_cpp_template("${_template_name}__native_libraries_java") { + package_name = "org/chromium/base/library_loader" + sources = [ + "//base/android/java/templates/NativeLibraries.template", + ] + inputs = [ + _ordered_libraries_json, + ] + deps = [ + ":${_ordered_libraries_target}", + ] + if (_native_lib_version_rule != "") { + deps += [ _native_lib_version_rule ] + } + + defines = [ + "NATIVE_LIBRARIES_LIST=" + + "@FileArg($_rebased_ordered_libraries_json:java_libraries_list)", + "NATIVE_LIBRARIES_VERSION_NUMBER=$_native_lib_version_arg", + ] + if (_use_chromium_linker) { + defines += [ "ENABLE_CHROMIUM_LINKER" ] + } + if (_load_library_from_apk) { + defines += [ "ENABLE_CHROMIUM_LINKER_LIBRARY_IN_ZIP_FILE" ] + } + if (_enable_chromium_linker_tests) { + defines += [ "ENABLE_CHROMIUM_LINKER_TESTS" ] + } + } + _srcjar_deps += [ ":${_template_name}__native_libraries_java" ] + } + + if (!defined(invoker.apk_under_test)) { + java_cpp_template("${_template_name}__build_config_java") { + package_name = "org/chromium/base" + sources = [ + "//base/android/java/templates/BuildConfig.template", + ] + deps = [ + ":$build_config_target", + ] + + defines = [] + if (enable_multidex) { + defines += [ "ENABLE_MULTIDEX" ] + } + if (is_java_debug || dcheck_always_on) { + defines += [ "_DCHECK_IS_ON" ] + } + defines += [ + "COMPRESSED_LOCALE_LIST=" + + "@FileArg($_rebased_build_config:compressed_locales_java_list)", + "UNCOMPRESSED_LOCALE_LIST=" + + "@FileArg($_rebased_build_config:uncompressed_locales_java_list)", + ] + } + _srcjar_deps += [ ":${_template_name}__build_config_java" ] + } + + java_target = "${_template_name}__java" + java_library_impl(java_target) { + forward_variables_from(invoker, + [ + "chromium_code", + "java_files", + "run_findbugs_override", + ]) + supports_android = true + requires_android = true + override_build_config = _build_config + deps = _android_manifest_deps + [ ":$build_config_target" ] + + android_manifest = _android_manifest + srcjar_deps = _srcjar_deps + jar_path = _jar_path + dex_path = _lib_dex_path + emma_never_instrument = _emma_never_instrument + + if (defined(invoker.deps)) { + deps += invoker.deps + } + if (defined(invoker.apk_under_test)) { + deps += [ "${invoker.apk_under_test}__java" ] + } + if (emma_coverage && !_emma_never_instrument) { + deps += [ "//third_party/android_tools:emma_device_java" ] + } + } + + # TODO(cjhopman): This is only ever needed to calculate the list of tests to + # run. See build/android/pylib/instrumentation/test_jar.py. We should be + # able to just do that calculation at build time instead. + if (defined(invoker.dist_ijar_path)) { + _dist_ijar_path = invoker.dist_ijar_path + action("${_template_name}_dist_ijar") { + script = "//build/android/gyp/create_dist_jar.py" + depfile = "$target_gen_dir/$target_name.d" + inputs = [ + _build_config, + ] + outputs = [ + "${_dist_ijar_path}", + ] + data = [ + _dist_ijar_path, + ] + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--output", + rebase_path("${_dist_ijar_path}", root_build_dir), + "--inputs=@FileArg($_rebased_build_config:dist_jar:all_interface_jars)", + ] + deps = [ + ":$build_config_target", # Generates the build config file. + ":$java_target", # Generates the jar file. + ] + } + } + + if (_proguard_enabled) { + _proguard_configs = [ _generated_proguard_config ] + if (defined(invoker.proguard_configs)) { + _proguard_configs += invoker.proguard_configs + } + assert(_proguard_configs != []) # Mark as used. + _proguard_target = "${_template_name}__proguard" + proguard(_proguard_target) { + forward_variables_from(invoker, + [ + "alternative_android_sdk_jar", + "deps", + "proguard_jar_path", + ]) + if (!defined(deps)) { + deps = [] + } + deps += [ + ":$build_config_target", + ":$java_target", + ":$process_resources_target", + ] + inputs = [ + _build_config, + _jar_path, + ] + _proguard_configs + + output_jar_path = _proguard_output_jar_path + _rebased_proguard_configs = + rebase_path(_proguard_configs, root_build_dir) + args = [ + "--proguard-configs=$_rebased_proguard_configs", + "--proguard-configs=@FileArg($_rebased_build_config:proguard:lib_configs)", + "--input-paths=@FileArg($_rebased_build_config:proguard:input_paths)", + "--classpath=@FileArg($_rebased_build_config:proguard:lib_paths)", + ] + if (defined(invoker.apk_under_test)) { + deps += [ + "${invoker.apk_under_test}__build_config", + "${invoker.apk_under_test}__proguard", + ] + _apk_under_test_build_config = + get_label_info(invoker.apk_under_test, "target_gen_dir") + "/" + + get_label_info(invoker.apk_under_test, "name") + ".build_config" + _rebased_apk_under_test_build_config = + rebase_path(_apk_under_test_build_config, root_build_dir) + args += [ "--tested-apk-info=@FileArg($_rebased_apk_under_test_build_config:deps_info:proguard_info)" ] + } + } + _dex_sources = [ _proguard_output_jar_path ] + _dex_deps = [ ":$_proguard_target" ] + + _copy_proguard_mapping_target = "${_template_name}__copy_proguard_mapping" + copy(_copy_proguard_mapping_target) { + sources = [ + "$_proguard_output_jar_path.mapping", + ] + outputs = [ + "$_final_apk_path.mapping", + ] + deps = [ + ":$_proguard_target", + ] + } + } else { + if (enable_multidex) { + _dex_sources = [ _jar_path ] + } else { + _dex_sources = [ _lib_dex_path ] + } + _dex_deps = [ ":$java_target" ] + } + + dex("$final_dex_target_name") { + deps = _dex_deps + [ ":$build_config_target" ] + inputs = [ + _build_config, + ] + sources = _dex_sources + output = final_dex_path + + # All deps are already included in _dex_sources when proguard is used. + if (!_proguard_enabled) { + if (enable_multidex) { + _dex_arg_key = "${_rebased_build_config}:dist_jar:dependency_jars" + } else { + _dex_arg_key = + "${_rebased_build_config}:final_dex:dependency_dex_files" + } + args = [ "--inputs=@FileArg($_dex_arg_key)" ] + } + } + + _native_libs_file_arg_dep = ":$build_config_target" + _native_libs_file_arg = "@FileArg($_rebased_build_config:native:libraries)" + _secondary_abi_native_libs_file_arg_dep = ":$build_config_target" + _secondary_abi_native_libs_file_arg = + "@FileArg($_rebased_build_config:native:secondary_abi_libraries)" + assert(_secondary_abi_native_libs_file_arg != "" && + _secondary_abi_native_libs_file_arg_dep != "") # Mark as used. + + if (_native_libs_deps != [] && _enable_relocation_packing) { + _prepare_native_target_name = "${_template_name}__prepare_native" + _native_libs_json = "$gen_dir/packed-libs/filelist.json" + _rebased_native_libs_json = rebase_path(_native_libs_json, root_build_dir) + _native_libs_file_arg_dep = ":$_prepare_native_target_name" + _native_libs_file_arg = "@FileArg($_rebased_native_libs_json:files)" + + pack_relocation_section(_prepare_native_target_name) { + forward_variables_from(invoker, + [ + "deps", + "public_deps", + ]) + file_list_json = _native_libs_json + libraries_filearg = + "@FileArg(${_rebased_build_config}:native:libraries)" + inputs = [ + _build_config, + ] + + deps += _native_libs_deps + deps += [ ":$build_config_target" ] + } + if (_secondary_abi_native_libs_deps != []) { + _prepare_native_target_name = + "${_template_name}_secondary_abi__prepare_native" + _native_libs_json = + "$gen_dir/packed-libs/$android_secondary_abi_cpu/filelist.json" + _rebased_native_libs_json = + rebase_path(_native_libs_json, root_build_dir) + _secondary_abi_native_libs_file_arg_dep = + ":$_prepare_native_target_name" + _secondary_abi_native_libs_file_arg = + "@FileArg($_rebased_native_libs_json:files)" + + pack_relocation_section(_prepare_native_target_name) { + forward_variables_from(invoker, + [ + "deps", + "public_deps", + ]) + file_list_json = _native_libs_json + libraries_filearg = "@FileArg(${_rebased_build_config}:native:secondary_abi_libraries)" + inputs = [ + _build_config, + ] + + deps += _secondary_abi_native_libs_deps + deps += [ ":$build_config_target" ] + } + } + } + + _extra_native_libs = [] + _extra_native_libs_deps = [] + _extra_native_libs_even_when_incremental = [] + _extra_native_libs_even_when_incremental_deps = [] + assert(_extra_native_libs_even_when_incremental_deps == []) # Mark as used. + if (_native_libs_deps != []) { + # zipalign can't align gdb_server, don't pack gdbserver temporarily. + if (is_debug && (!defined(invoker.page_align_shared_libraries) || + !invoker.page_align_shared_libraries)) { + _extra_native_libs_even_when_incremental = [ android_gdbserver ] + } + + if (_use_chromium_linker) { + _extra_native_libs = + [ "$root_shlib_dir/libchromium_android_linker$shlib_extension" ] + _extra_native_libs_deps += + [ "//base/android/linker:chromium_android_linker" ] + } + } + if (defined(invoker.loadable_modules) && invoker.loadable_modules != []) { + _extra_native_libs_even_when_incremental += invoker.loadable_modules + } + + _final_deps += [ ":${_template_name}__create" ] + create_apk("${_template_name}__create") { + forward_variables_from(invoker, + [ + "alternative_android_sdk_jar", + "android_aapt_path", + "app_as_shared_lib", + "deps", + "extensions_to_not_compress", + "language_splits", + "page_align_shared_libraries", + "public_deps", + "secondary_native_libs", + "shared_resources", + "uncompress_shared_libraries", + "write_asset_list", + ]) + if (!defined(deps)) { + deps = [] + } + apk_path = _final_apk_path + android_manifest = _android_manifest + assets_build_config = _build_config + resources_zip = _all_resources_zip_path + dex_path = final_dex_path + load_library_from_apk = _load_library_from_apk + create_density_splits = _create_density_splits + emma_instrument = emma_coverage && !_emma_never_instrument + + if (!defined(extensions_to_not_compress)) { + # Allow icu data, v8 snapshots, and pak files to be loaded directly from + # the .apk. + # Note: These are actually suffix matches, not necessarily extensions. + extensions_to_not_compress = ".dat,.bin,.pak" + } + + version_code = _version_code + version_name = _version_name + + keystore_name = _keystore_name + keystore_path = _keystore_path + keystore_password = _keystore_password + + # Incremental apk does not use native libs nor final dex. + incremental_deps = deps + _android_manifest_deps + [ + ":$build_config_target", + ":$process_resources_target", + ] + + # This target generates the input file _all_resources_zip_path. + deps += _android_manifest_deps + [ + ":$build_config_target", + ":$process_resources_target", + ":$final_dex_target_name", + ] + + if ((_native_libs_deps != [] || + _extra_native_libs_even_when_incremental != []) && + !_create_abi_split) { + deps += _native_libs_deps + _extra_native_libs_deps + + _extra_native_libs_even_when_incremental_deps + + [ _native_libs_file_arg_dep ] + native_libs_filearg = _native_libs_file_arg + native_libs = _extra_native_libs + native_libs_even_when_incremental = + _extra_native_libs_even_when_incremental + } + + if (_secondary_abi_native_libs_deps != [] && !_create_abi_split) { + deps += _secondary_abi_native_libs_deps + + [ _secondary_abi_native_libs_file_arg_dep ] + secondary_abi_native_libs_filearg = _secondary_abi_native_libs_file_arg + } + + # Placeholders necessary for some older devices. + # http://crbug.com/395038 + forward_variables_from(invoker, [ "native_lib_placeholders" ]) + } + + if ((_native_libs_deps != [] || + _extra_native_libs_even_when_incremental != []) && _create_abi_split) { + _manifest_rule = + "${_template_name}__split_manifest_abi_${android_app_abi}" + generate_split_manifest(_manifest_rule) { + main_manifest = _android_manifest + out_manifest = + "$gen_dir/split-manifests/${android_app_abi}/AndroidManifest.xml" + split_name = "abi_${android_app_abi}" + deps = _android_manifest_deps + } + + _apk_rule = "${_template_name}__split_apk_abi_${android_app_abi}" + _final_deps += [ ":$_apk_rule" ] + + create_apk(_apk_rule) { + apk_path = "${_final_apk_path_no_ext}-abi-${android_app_abi}.apk" + base_path = "$gen_dir/$_apk_rule" + + manifest_outputs = get_target_outputs(":${_manifest_rule}") + android_manifest = manifest_outputs[1] + load_library_from_apk = _load_library_from_apk + + version_code = _version_code + version_name = _version_name + + keystore_name = _keystore_name + keystore_path = _keystore_path + keystore_password = _keystore_password + + # Placeholders necessary for some older devices. + # http://crbug.com/395038 + deps = [] + forward_variables_from(invoker, + [ + "alternative_android_sdk_jar", + "android_aapt_path", + "deps", + "native_lib_placeholders", + "public_deps", + ]) + + incremental_deps = + deps + _extra_native_libs_even_when_incremental_deps + + [ ":$_manifest_rule" ] + deps = [] + deps = incremental_deps + _native_libs_deps + _extra_native_libs_deps + + [ _native_libs_file_arg_dep ] + native_libs_filearg = _native_libs_file_arg + native_libs = _extra_native_libs + native_libs_even_when_incremental = + _extra_native_libs_even_when_incremental + } + } + + _create_incremental_script_rule_name = + "${_template_name}__incremental_script" + action(_create_incremental_script_rule_name) { + script = "//build/android/incremental_install/create_install_script.py" + depfile = "$target_gen_dir/$target_name.d" + deps = [ + _native_libs_file_arg_dep, + ] + + outputs = [ + _incremental_install_script_path, + ] + + _rebased_apk_path_no_ext = + rebase_path(_final_apk_path_no_ext, root_build_dir) + _rebased_incremental_install_script_path = + rebase_path(_incremental_install_script_path, root_build_dir) + _rebased_depfile = rebase_path(depfile, root_build_dir) + _dex_arg_key = "${_rebased_build_config}:final_dex:dependency_dex_files" + args = [ + "--apk-path=${_rebased_apk_path_no_ext}_incremental.apk", + "--script-output-path=$_rebased_incremental_install_script_path", + "--dex-file=$_rebased_lib_dex_path", + "--dex-file-list=@FileArg($_dex_arg_key)", + "--depfile=$_rebased_depfile", + ] + if (_proguard_enabled) { + args += [ "--show-proguard-warning" ] + } + if (defined(_native_libs_file_arg)) { + args += [ "--native-libs=$_native_libs_file_arg" ] + } + if (_extra_native_libs != []) { + # Don't pass in _extra_native_libs_even_when_incremental, since these are + # end up in the apk and are not side-loaded. + _rebased_extra_native_libs = + rebase_path(_extra_native_libs, root_build_dir) + args += [ "--native-libs=$_rebased_extra_native_libs" ] + } + if (_create_density_splits) { + args += [ "--split=${_rebased_apk_path_no_ext}-density-*.apk" ] + } + if (_create_language_splits) { + args += [ "--split=${_rebased_apk_path_no_ext}-language-*.apk" ] + } + if (_load_library_from_apk) { + args += [ "--dont-even-try=Incremental builds do not work with load_library_from_apk. Try setting is_component_build=true in your GN args." ] + } + } + + group(target_name) { + forward_variables_from(invoker, + [ + "data", + "data_deps", + ]) + public_deps = _final_deps + + # Make the proguard .mapping file easy to find by putting it beside the .apk. + if (_proguard_enabled) { + deps = [ + ":$_copy_proguard_mapping_target", + ] + } + } + group("${target_name}_incremental") { + forward_variables_from(invoker, + [ + "data", + "data_deps", + ]) + if (!defined(data_deps)) { + data_deps = [] + } + + # device/commands is used by the installer script to push files via .zip. + data_deps += [ "//build/android/pylib/device/commands" ] + + _native_libs_deps + _extra_native_libs_deps + + # Since the _incremental.apk does not include use .so nor .dex from the + # actual target, but instead loads them at runtime, we need to explicitly + # depend on them here. + public_deps = [ + ":${_create_incremental_script_rule_name}", + ":${_template_name}__create_incremental", + ":${java_target}", + ] + } + } + + # Declare an Android instrumentation test apk + # + # This target creates an Android instrumentation test apk. + # + # Variables + # android_manifest: Path to AndroidManifest.xml. + # data_deps: List of dependencies needed at runtime. These will be built but + # won't change the generated .apk in any way (in fact they may be built + # after the .apk is). + # deps: List of dependencies. All Android java resources and libraries in the + # "transitive closure" of these dependencies will be included in the apk. + # Note: this "transitive closure" actually only includes such targets if + # they are depended on through android_library or android_resources targets + # (and so not through builtin targets like 'action', 'group', etc). + # java_files: List of .java files to include in the apk. + # srcjar_deps: List of srcjar dependencies. The .java files in the srcjars + # will be added to java_files and be included in this apk. + # apk_name: Name for final apk. + # final_apk_path: Path to final built apk. Default is + # $root_out_dir/apks/$apk_name.apk. Setting this will override apk_name. + # shared_libraries: List shared_library targets to bundle. If these + # libraries depend on other shared_library targets, those dependencies will + # also be included in the apk (e.g. for is_component_build). + # apk_under_test: The apk being tested. + # + # Example + # instrumentation_test_apk("foo_test_apk") { + # android_manifest = "AndroidManifest.xml" + # apk_name = "FooTest" + # apk_under_test = "Foo" + # java_files = [ + # "android/org/chromium/foo/FooTestCase.java", + # "android/org/chromium/foo/FooExampleTest.java", + # ] + # deps = [ + # ":foo_test_support_java" + # ] + # } + template("instrumentation_test_apk") { + assert(defined(invoker.apk_name)) + testonly = true + _apk_target_name = "${target_name}__apk" + _test_runner_target_name = "${target_name}__test_runner_script" + _install_script_name = "install_$target_name" + _dist_ijar_path = + "$root_build_dir/test.lib.java/" + invoker.apk_name + ".jar" + + test_runner_script(_test_runner_target_name) { + forward_variables_from(invoker, + [ + "additional_apks", + "apk_under_test", + "data", + "data_deps", + "deps", + "ignore_all_data_deps", + "public_deps", + ]) + test_name = invoker.target_name + test_type = "instrumentation" + apk_target = ":$_apk_target_name" + test_jar = _dist_ijar_path + } + + test_runner_script("${_test_runner_target_name}_incremental") { + forward_variables_from(invoker, + [ + "additional_apks", + "apk_under_test", + "data", + "data_deps", + "deps", + "ignore_all_data_deps", + "public_deps", + ]) + test_name = "${invoker.target_name}_incremental" + test_type = "instrumentation" + apk_target = ":$_apk_target_name" + test_jar = _dist_ijar_path + incremental_install = true + } + + android_apk(_apk_target_name) { + deps = [] + data_deps = [] + forward_variables_from(invoker, "*") + install_script_name = _install_script_name + deps += [ "//testing/android/broker:broker_java" ] + data_deps += [ + "//build/android/pylib/device/commands", + "//tools/android/forwarder2", + "//tools/android/md5sum", + ] + if (defined(invoker.additional_apks)) { + data_deps += invoker.additional_apks + } + + if (defined(invoker.proguard_enabled) && invoker.proguard_enabled) { + # When ProGuard is on, we use ProGuard to combine the under test java + # code and the test java code. This is to allow us to apply all ProGuard + # optimizations that we ship with, but not have them break tests. The + # apk under test will still have the same resources, assets, and + # manifest, all of which are the ones used in the tests. + if (!defined(invoker.proguard_configs)) { + proguard_configs = [] + } + proguard_configs += [ "//testing/android/proguard_for_test.flags" ] + } + + dist_ijar_path = _dist_ijar_path + if (defined(invoker.run_findbugs_override)) { + # Only allow findbugs when there are java files. + run_findbugs_override = + invoker.run_findbugs_override && defined(invoker.java_files) + } + } + + group(target_name) { + public_deps = [ + ":$_apk_target_name", + ":$_test_runner_target_name", + + # Required by test runner to enumerate test list. + ":${_apk_target_name}_dist_ijar", + ] + if (defined(invoker.apk_under_test)) { + public_deps += [ invoker.apk_under_test ] + } + } + + # TODO: Delete once recipes no longer use this target. + group("${target_name}_run") { + public_deps = [ + ":${invoker.target_name}", + ] + } + group("${target_name}_incremental") { + public_deps = [ + ":${_apk_target_name}_dist_ijar", + ":${_apk_target_name}_incremental", + ":${_test_runner_target_name}_incremental", + ] + if (defined(invoker.apk_under_test)) { + public_deps += [ "${invoker.apk_under_test}_incremental" ] + } + } + } + + # Declare an Android gtest apk + # + # This target creates an Android apk for running gtest-based unittests. + # + # Variables + # deps: Specifies the dependencies of this target. These will be passed to + # the underlying android_apk invocation and should include the java and + # resource dependencies of the apk. + # shared_library: shared_library target that contains the unit tests. + # apk_name: The name of the produced apk. If unspecified, it uses the name + # of the shared_library target suffixed with "_apk" + # use_default_launcher: Whether the default activity (NativeUnitTestActivity) + # should be used for launching tests. + # use_native_activity: Test implements ANativeActivity_onCreate(). + # + # Example + # unittest_apk("foo_unittests_apk") { + # deps = [ ":foo_java", ":foo_resources" ] + # shared_library = ":foo_unittests" + # } + template("unittest_apk") { + _use_native_activity = + defined(invoker.use_native_activity) && invoker.use_native_activity + _android_manifest = "$target_gen_dir/$target_name/AndroidManifest.xml" + assert(invoker.shared_library != "") + + # This trivial assert is needed in case android_manifest is defined, + # as otherwise _use_native_activity and _android_manifest would not be used. + assert(_use_native_activity != "" && _android_manifest != "") + + if (!defined(invoker.android_manifest)) { + jinja_template("${target_name}_manifest") { + _native_library_name = get_label_info(invoker.shared_library, "name") + input = "//testing/android/native_test/java/AndroidManifest.xml.jinja2" + output = _android_manifest + variables = [ + "is_component_build=${is_component_build}", + "native_library_name=${_native_library_name}", + "use_native_activity=${_use_native_activity}", + ] + } + } + + android_apk(target_name) { + set_sources_assignment_filter([]) + data_deps = [] + deps = [] + forward_variables_from(invoker, "*") + testonly = true + + assert(!defined(invoker.proguard_enabled) || !invoker.proguard_enabled || + invoker.proguard_configs != []) + + if (!defined(apk_name)) { + apk_name = get_label_info(invoker.shared_library, "name") + } + + if (!defined(android_manifest)) { + android_manifest_dep = ":${target_name}_manifest" + android_manifest = _android_manifest + } + + final_apk_path = "$root_build_dir/${apk_name}_apk/${apk_name}-debug.apk" + + if (!defined(use_default_launcher) || use_default_launcher) { + deps += [ "//testing/android/native_test:native_test_java" ] + } + shared_libraries = [ invoker.shared_library ] + deps += [ + "//base:base_java", + "//testing/android/appurify_support:appurify_support_java", + "//testing/android/reporter:reporter_java", + ] + data_deps += [ + "//build/android/pylib/device/commands", + "//tools/android/md5sum", + ] + if (host_os == "linux") { + data_deps += [ "//tools/android/forwarder2" ] + } + } + } + + # Generate .java files from .aidl files. + # + # This target will store the .java files in a srcjar and should be included in + # an android_library or android_apk's srcjar_deps. + # + # Variables + # sources: Paths to .aidl files to compile. + # import_include: Path to directory containing .java files imported by the + # .aidl files. + # interface_file: Preprocessed aidl file to import. + # + # Example + # android_aidl("foo_aidl") { + # import_include = "java/src" + # sources = [ + # "java/src/com/foo/bar/FooBarService.aidl", + # "java/src/com/foo/bar/FooBarServiceCallback.aidl", + # ] + # } + template("android_aidl") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + srcjar_path = "${target_gen_dir}/${target_name}.srcjar" + aidl_path = "${android_sdk_build_tools}/aidl" + framework_aidl = "$android_sdk/framework.aidl" + + action(target_name) { + script = "//build/android/gyp/aidl.py" + sources = invoker.sources + + imports = [ framework_aidl ] + if (defined(invoker.interface_file)) { + assert(invoker.interface_file != "") + imports += [ invoker.interface_file ] + } + + inputs = [ aidl_path ] + imports + + depfile = "${target_gen_dir}/${target_name}.d" + outputs = [ + srcjar_path, + ] + rebased_imports = rebase_path(imports, root_build_dir) + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--aidl-path", + rebase_path(aidl_path, root_build_dir), + "--imports=$rebased_imports", + "--srcjar", + rebase_path(srcjar_path, root_build_dir), + ] + if (defined(invoker.import_include) && invoker.import_include != "") { + # TODO(cjhopman): aidl supports creating a depfile. We should be able to + # switch to constructing a depfile for the overall action from that + # instead of having all the .java files in the include paths as inputs. + rebased_import_includes = + rebase_path([ invoker.import_include ], root_build_dir) + args += [ "--includes=$rebased_import_includes" ] + + _java_files_build_rel = + exec_script("//build/android/gyp/find.py", + rebase_path([ invoker.import_include ], root_build_dir), + "list lines") + _java_files = rebase_path(_java_files_build_rel, ".", root_build_dir) + inputs += _java_files + } + args += rebase_path(sources, root_build_dir) + } + } + + # Compile a protocol buffer to java. + # + # This generates java files from protocol buffers and creates an Android library + # containing the classes. + # + # Variables + # sources: Paths to .proto files to compile. + # proto_path: Root directory of .proto files. + # + # Example: + # proto_java_library("foo_proto_java") { + # proto_path = "src/foo" + # sources = [ "$proto_path/foo.proto" ] + # } + template("proto_java_library") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + _protoc_dep = + "//third_party/android_protobuf:android_protoc($host_toolchain)" + _protoc_out_dir = get_label_info(_protoc_dep, "root_out_dir") + _protoc_bin = "$_protoc_out_dir/android_protoc" + _proto_path = invoker.proto_path + + _template_name = target_name + + action("${_template_name}__protoc_java") { + srcjar_path = "$target_gen_dir/$target_name.srcjar" + script = "//build/protoc_java.py" + + deps = [ + _protoc_dep, + ] + if (defined(invoker.deps)) { + deps += invoker.deps + } + + sources = invoker.sources + depfile = "$target_gen_dir/$target_name.d" + outputs = [ + srcjar_path, + ] + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--protoc", + rebase_path(_protoc_bin, root_build_dir), + "--proto-path", + rebase_path(_proto_path, root_build_dir), + "--srcjar", + rebase_path(srcjar_path, root_build_dir), + ] + rebase_path(sources, root_build_dir) + } + + android_library(target_name) { + chromium_code = false + java_files = [] + srcjar_deps = [ ":${_template_name}__protoc_java" ] + deps = [ + "//third_party/android_protobuf:protobuf_nano_javalib", + ] + } + } + + # Declare an Android library target for a prebuilt AAR. + # + # This target creates an Android library containing java code and Android + # resources. For libraries without resources, it will not generate + # corresponding android_resources targets. + # + # Variables + # aar_path: Path to the AAR. + # proguard_configs: List of proguard configs to use in final apk step for + # any apk that depends on this library. + # ignore_aidl: Whether to ignore .aidl files found with the .aar. + # ignore_assets: Whether to ignore assets found in the .aar. + # ignore_manifest: Whether to ignore merging of AndroidManifest.xml. + # ignore_native_libraries: Whether to ignore .so files found in the .aar. + # TODO(jbudorick@): remove this arguments after crbug.com/522043 is fixed. + # requires_android: Whether this target can only be used for compiling Android related targets. + # + # Example + # android_aar_prebuilt("foo_java") { + # aar_path = "foo.aar" + # } + template("android_aar_prebuilt") { + _output_path = "${target_gen_dir}/${target_name}" + _unpack_target_name = "${target_name}__unpack_aar" + _ignore_aidl = defined(invoker.ignore_aidl) && invoker.ignore_aidl + _ignore_assets = defined(invoker.ignore_assets) && invoker.ignore_assets + _ignore_manifest = + defined(invoker.ignore_manifest) && invoker.ignore_manifest + _ignore_native_libraries = defined(invoker.ignore_native_libraries) && + invoker.ignore_native_libraries + + # Scan the AAR file and determine the resources and jar files. + # Some libraries might not have resources; others might have two jars. + _scanned_files = + exec_script("//build/android/gyp/aar.py", + [ + "--input-file", + rebase_path(invoker.aar_path, root_build_dir), + "--list", + ], + "scope") + + assert(_ignore_aidl || _scanned_files.aidl == [], + "android_aar_prebuilt() aidl not yet supported." + + " Implement or use ignore_aidl = true." + + " http://crbug.com/644439") + assert(_ignore_assets || _scanned_files.assets == [], + "android_aar_prebuilt() assets not yet supported." + + " Implement or use ignore_assets = true." + + " http://crbug.com/643966") + assert(_ignore_native_libraries || !_scanned_files.has_native_libraries, + "android_aar_prebuilt() with .so files is not supported." + + " Use ignore_native_libraries = true to silence this error.") + assert(_ignore_manifest || _scanned_files.is_manifest_empty, + "android_aar_prebuilt() manifest merging not yet supported and" + + " non-trivial AndroidManifest.xml detected." + + " Implement or use ignore_manifest = true." + + " http://crbug.com/643967") + assert(_scanned_files.has_classes_jar || _scanned_files.subjars == []) + + action(_unpack_target_name) { + script = "//build/android/gyp/aar.py" # Unzips the AAR + args = [ + "--input-file", + rebase_path(invoker.aar_path, root_build_dir), + "--output-dir", + rebase_path(_output_path, root_build_dir), + "--extract", + ] + inputs = [ + invoker.aar_path, + ] + outputs = [ + "${_output_path}/AndroidManifest.xml", + ] + + if (_scanned_files.resources != []) { + outputs += [ "${_output_path}/R.txt" ] + outputs += get_path_info( + rebase_path(_scanned_files.resources, "", _output_path), + "abspath") + } + if (_scanned_files.has_classes_jar) { + outputs += [ "${_output_path}/classes.jar" ] + } + outputs += + get_path_info(rebase_path(_scanned_files.subjars, "", _output_path), + "abspath") + if (_scanned_files.has_proguard_flags) { + outputs += [ "${_output_path}/proguard.txt" ] + } + } + + # Create the android_resources target for resources. + if (_scanned_files.resources != []) { + _res_target_name = "${target_name}__res" + android_resources(_res_target_name) { + forward_variables_from(invoker, [ "deps" ]) + if (!defined(deps)) { + deps = [] + } + deps += [ ":$_unpack_target_name" ] + resource_dirs = [] + generated_resource_dirs = [ "${_output_path}/res" ] + generated_resource_files = + rebase_path(_scanned_files.resources, "", _output_path) + android_manifest_dep = ":$_unpack_target_name" + android_manifest = "${_output_path}/AndroidManifest.xml" + v14_skip = true + } + } + + # Create android_java_prebuilt target for extra jars within jars/. + _subjar_targets = [] + foreach(_tuple, _scanned_files.subjar_tuples) { + _current_target = "${target_name}__subjar_${_tuple[0]}" + _subjar_targets += [ ":$_current_target" ] + java_prebuilt(_current_target) { + forward_variables_from(invoker, + [ + "jar_excluded_patterns", + "requires_android", + ]) + deps = [ + ":$_unpack_target_name", + ] + if (!defined(requires_android)) { + requires_android = true + } + supports_android = true + jar_path = "$_output_path/${_tuple[1]}" + _base_output_name = get_path_info(jar_path, "name") + output_name = "${invoker.target_name}-$_base_output_name" + } + } + + # Create android_java_prebuilt target for classes.jar. + if (_scanned_files.has_classes_jar) { + _jar_target_name = "${target_name}__classes" + java_prebuilt(_jar_target_name) { + forward_variables_from(invoker, + [ + "deps", + "input_jars_paths", + "jar_excluded_patterns", + "proguard_configs", + "requires_android", + ]) + if (!defined(deps)) { + deps = [] + } + deps += _subjar_targets + [ ":$_unpack_target_name" ] + if (defined(_res_target_name)) { + deps += [ ":$_res_target_name" ] + } + if (!defined(requires_android)) { + requires_android = true + } + supports_android = true + jar_path = "$_output_path/classes.jar" + output_name = invoker.target_name + + if (_scanned_files.has_proguard_flags) { + if (!defined(proguard_configs)) { + proguard_configs = [] + } + proguard_configs += [ "$_output_path/proguard.txt" ] + } + } + } + + java_group(target_name) { + deps = [] + if (defined(_jar_target_name)) { + deps += [ ":$_jar_target_name" ] + + # Although subjars are meant to be private, we add them as deps here + # because in practice they seem to contain classes required to be in the + # classpath. + deps += _subjar_targets + } + if (defined(_res_target_name)) { + deps += [ ":$_res_target_name" ] + } + } + } +} diff --git a/samples/GN/clang.gni b/samples/GN/clang.gni new file mode 100644 index 00000000..7026f652 --- /dev/null +++ b/samples/GN/clang.gni @@ -0,0 +1,13 @@ +# 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. + +import("//build/toolchain/toolchain.gni") + +declare_args() { + # Indicates if the build should use the Chrome-specific plugins for enforcing + # coding guidelines, etc. Only used when compiling with Clang. + clang_use_chrome_plugins = is_clang && !is_nacl && !use_xcode_clang + + clang_base_path = "//third_party/llvm-build/Release+Asserts" +} diff --git a/samples/GN/filenames/.gn b/samples/GN/filenames/.gn new file mode 100644 index 00000000..c80980ea --- /dev/null +++ b/samples/GN/filenames/.gn @@ -0,0 +1,25 @@ +# This file is used by the GN meta build system to find the root of the source +# tree and to set startup options. For documentation on the values set in this +# file, run "gn help dotfile" at the command line. + +import("//build/dotfile_settings.gni") + +# The location of the build configuration file. +buildconfig = "//build/config/BUILDCONFIG.gn" + +# The secondary source root is a parallel directory tree where +# GN build files are placed when they can not be placed directly +# in the source tree, e.g. for third party source trees. +secondary_source = "//build/secondary/" + +# These are the targets to check headers for by default. The files in targets +# matching these patterns (see "gn help label_pattern" for format) will have +# their includes checked for proper dependencies when you run either +# "gn check" or "gn gen --check". +check_targets = [] + +# These are the list of GN files that run exec_script. This whitelist exists +# to force additional review for new uses of exec_script, which is strongly +# discouraged except for gypi_to_gn calls. +exec_script_whitelist = + build_dotfile_settings.exec_script_whitelist + [ "//test/test262/BUILD.gn" ] diff --git a/samples/GN/gcc_toolchain.gni b/samples/GN/gcc_toolchain.gni new file mode 100644 index 00000000..7ee2b6ad --- /dev/null +++ b/samples/GN/gcc_toolchain.gni @@ -0,0 +1,503 @@ +# Copyright (c) 2013 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("//build/config/android/config.gni") +import("//build/config/clang/clang.gni") +import("//build/config/nacl/config.gni") +import("//build/config/sanitizers/sanitizers.gni") +import("//build/config/v8_target_cpu.gni") +import("//build/toolchain/cc_wrapper.gni") +import("//build/toolchain/goma.gni") +import("//build/toolchain/toolchain.gni") + +# This template defines a toolchain for something that works like gcc +# (including clang). +# +# It requires the following variables specifying the executables to run: +# - ar +# - cc +# - cxx +# - ld +# +# Optional parameters that control the tools: +# +# - extra_cflags +# Extra flags to be appended when compiling C files (but not C++ files). +# - extra_cppflags +# Extra flags to be appended when compiling both C and C++ files. "CPP" +# stands for "C PreProcessor" in this context, although it can be +# used for non-preprocessor flags as well. Not to be confused with +# "CXX" (which follows). +# - extra_cxxflags +# Extra flags to be appended when compiling C++ files (but not C files). +# - extra_ldflags +# Extra flags to be appended when linking +# +# - libs_section_prefix +# - libs_section_postfix +# The contents of these strings, if specified, will be placed around +# the libs section of the linker line. It allows one to inject libraries +# at the beginning and end for all targets in a toolchain. +# - solink_libs_section_prefix +# - solink_libs_section_postfix +# Same as libs_section_{pre,post}fix except used for solink instead of link. +# - link_outputs +# The content of this array, if specified, will be added to the list of +# outputs from the link command. This can be useful in conjunction with +# the post_link parameter. +# - post_link +# The content of this string, if specified, will be run as a separate +# command following the the link command. +# - deps +# Just forwarded to the toolchain definition. +# - executable_extension +# If this string is specified it will be used for the file extension +# for an executable, rather than using no extension; targets will +# still be able to override the extension using the output_extension +# variable. +# - rebuild_define +# The contents of this string, if specified, will be passed as a #define +# to the toolchain. It can be used to force recompiles whenever a +# toolchain is updated. +# - shlib_extension +# If this string is specified it will be used for the file extension +# for a shared library, rather than default value specified in +# toolchain.gni +# - strip +# Location of the strip executable. When specified, strip will be run on +# all shared libraries and executables as they are built. The pre-stripped +# artifacts will be put in lib.unstripped/ and exe.unstripped/. +template("gcc_toolchain") { + toolchain(target_name) { + assert(defined(invoker.ar), "gcc_toolchain() must specify a \"ar\" value") + assert(defined(invoker.cc), "gcc_toolchain() must specify a \"cc\" value") + assert(defined(invoker.cxx), "gcc_toolchain() must specify a \"cxx\" value") + assert(defined(invoker.ld), "gcc_toolchain() must specify a \"ld\" value") + + # This define changes when the toolchain changes, forcing a rebuild. + # Nothing should ever use this define. + if (defined(invoker.rebuild_define)) { + rebuild_string = "-D" + invoker.rebuild_define + " " + } else { + rebuild_string = "" + } + + # GN's syntax can't handle more than one scope dereference at once, like + # "invoker.toolchain_args.foo", so make a temporary to hold the toolchain + # args so we can do "invoker_toolchain_args.foo". + assert(defined(invoker.toolchain_args), + "Toolchains must specify toolchain_args") + invoker_toolchain_args = invoker.toolchain_args + assert(defined(invoker_toolchain_args.current_cpu), + "toolchain_args must specify a current_cpu") + assert(defined(invoker_toolchain_args.current_os), + "toolchain_args must specify a current_os") + + # When invoking this toolchain not as the default one, these args will be + # passed to the build. They are ignored when this is the default toolchain. + toolchain_args = { + # Populate toolchain args from the invoker. + forward_variables_from(invoker_toolchain_args, "*") + + # The host toolchain value computed by the default toolchain's setup + # needs to be passed through unchanged to all secondary toolchains to + # ensure that it's always the same, regardless of the values that may be + # set on those toolchains. + host_toolchain = host_toolchain + + if (!defined(invoker_toolchain_args.v8_current_cpu)) { + v8_current_cpu = invoker_toolchain_args.current_cpu + } + } + + # When the invoker has explicitly overridden use_goma or cc_wrapper in the + # toolchain args, use those values, otherwise default to the global one. + # This works because the only reasonable override that toolchains might + # supply for these values are to force-disable them. + if (defined(toolchain_args.use_goma)) { + toolchain_uses_goma = toolchain_args.use_goma + } else { + toolchain_uses_goma = use_goma + } + if (defined(toolchain_args.cc_wrapper)) { + toolchain_cc_wrapper = toolchain_args.cc_wrapper + } else { + toolchain_cc_wrapper = cc_wrapper + } + + # Compute the compiler prefix. + if (toolchain_uses_goma) { + assert(toolchain_cc_wrapper == "", + "Goma and cc_wrapper can't be used together.") + compiler_prefix = "$goma_dir/gomacc " + } else if (toolchain_cc_wrapper != "") { + compiler_prefix = toolchain_cc_wrapper + " " + } else { + compiler_prefix = "" + } + + cc = compiler_prefix + invoker.cc + cxx = compiler_prefix + invoker.cxx + ar = invoker.ar + ld = invoker.ld + if (defined(invoker.readelf)) { + readelf = invoker.readelf + } else { + readelf = "readelf" + } + if (defined(invoker.nm)) { + nm = invoker.nm + } else { + nm = "nm" + } + + if (defined(invoker.shlib_extension)) { + default_shlib_extension = invoker.shlib_extension + } else { + default_shlib_extension = shlib_extension + } + + if (defined(invoker.executable_extension)) { + default_executable_extension = invoker.executable_extension + } else { + default_executable_extension = "" + } + + # Bring these into our scope for string interpolation with default values. + if (defined(invoker.libs_section_prefix)) { + libs_section_prefix = invoker.libs_section_prefix + } else { + libs_section_prefix = "" + } + + if (defined(invoker.libs_section_postfix)) { + libs_section_postfix = invoker.libs_section_postfix + } else { + libs_section_postfix = "" + } + + if (defined(invoker.solink_libs_section_prefix)) { + solink_libs_section_prefix = invoker.solink_libs_section_prefix + } else { + solink_libs_section_prefix = "" + } + + if (defined(invoker.solink_libs_section_postfix)) { + solink_libs_section_postfix = invoker.solink_libs_section_postfix + } else { + solink_libs_section_postfix = "" + } + + if (defined(invoker.extra_cflags) && invoker.extra_cflags != "") { + extra_cflags = " " + invoker.extra_cflags + } else { + extra_cflags = "" + } + + if (defined(invoker.extra_cppflags) && invoker.extra_cppflags != "") { + extra_cppflags = " " + invoker.extra_cppflags + } else { + extra_cppflags = "" + } + + if (defined(invoker.extra_cxxflags) && invoker.extra_cxxflags != "") { + extra_cxxflags = " " + invoker.extra_cxxflags + } else { + extra_cxxflags = "" + } + + if (defined(invoker.extra_ldflags) && invoker.extra_ldflags != "") { + extra_ldflags = " " + invoker.extra_ldflags + } else { + extra_ldflags = "" + } + + # These library switches can apply to all tools below. + lib_switch = "-l" + lib_dir_switch = "-L" + + # Object files go in this directory. + object_subdir = "{{target_out_dir}}/{{label_name}}" + + tool("cc") { + depfile = "{{output}}.d" + command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{cflags}} {{cflags_c}}${extra_cppflags}${extra_cflags} -c {{source}} -o {{output}}" + depsformat = "gcc" + description = "CC {{output}}" + outputs = [ + # The whitelist file is also an output, but ninja does not + # currently support multiple outputs for tool("cc"). + "$object_subdir/{{source_name_part}}.o", + ] + if (enable_resource_whitelist_generation) { + compile_wrapper = + rebase_path("//build/toolchain/gcc_compile_wrapper.py", + root_build_dir) + command = "$python_path \"$compile_wrapper\" --resource-whitelist=\"{{output}}.whitelist\" $command" + } + } + + tool("cxx") { + depfile = "{{output}}.d" + command = "$cxx -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{cflags}} {{cflags_cc}}${extra_cppflags}${extra_cxxflags} -c {{source}} -o {{output}}" + depsformat = "gcc" + description = "CXX {{output}}" + outputs = [ + # The whitelist file is also an output, but ninja does not + # currently support multiple outputs for tool("cxx"). + "$object_subdir/{{source_name_part}}.o", + ] + if (enable_resource_whitelist_generation) { + compile_wrapper = + rebase_path("//build/toolchain/gcc_compile_wrapper.py", + root_build_dir) + command = "$python_path \"$compile_wrapper\" --resource-whitelist=\"{{output}}.whitelist\" $command" + } + } + + tool("asm") { + # For GCC we can just use the C compiler to compile assembly. + depfile = "{{output}}.d" + command = "$cc -MMD -MF $depfile ${rebuild_string}{{defines}} {{include_dirs}} {{asmflags}} -c {{source}} -o {{output}}" + depsformat = "gcc" + description = "ASM {{output}}" + outputs = [ + "$object_subdir/{{source_name_part}}.o", + ] + } + + tool("alink") { + rspfile = "{{output}}.rsp" + whitelist_flag = " " + if (enable_resource_whitelist_generation) { + whitelist_flag = " --resource-whitelist=\"{{output}}.whitelist\"" + } + + # This needs a Python script to avoid using simple sh features in this + # command, in case the host does not use a POSIX shell (e.g. compiling + # POSIX-like toolchains such as NaCl on Windows). + ar_wrapper = + rebase_path("//build/toolchain/gcc_ar_wrapper.py", root_build_dir) + command = "$python_path \"$ar_wrapper\"$whitelist_flag --output={{output}} --ar=\"$ar\" {{arflags}} rcsD @\"$rspfile\"" + description = "AR {{output}}" + rspfile_content = "{{inputs}}" + outputs = [ + "{{output_dir}}/{{target_output_name}}{{output_extension}}", + ] + + # Shared libraries go in the target out directory by default so we can + # generate different targets with the same name and not have them collide. + default_output_dir = "{{target_out_dir}}" + default_output_extension = ".a" + output_prefix = "lib" + } + + tool("solink") { + soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". + sofile = "{{output_dir}}/$soname" # Possibly including toolchain dir. + rspfile = sofile + ".rsp" + pool = "//build/toolchain:link_pool($default_toolchain)" + whitelist_flag = " " + if (enable_resource_whitelist_generation) { + whitelist_file = "$sofile.whitelist" + whitelist_flag = " --resource-whitelist=\"$whitelist_file\"" + } + + if (defined(invoker.strip)) { + unstripped_sofile = "{{root_out_dir}}/lib.unstripped/$soname" + } else { + unstripped_sofile = sofile + } + + # These variables are not built into GN but are helpers that + # implement (1) linking to produce a .so, (2) extracting the symbols + # from that file (3) if the extracted list differs from the existing + # .TOC file, overwrite it, otherwise, don't change it. + tocfile = sofile + ".TOC" + + link_command = "$ld -shared {{ldflags}}${extra_ldflags} -o \"$unstripped_sofile\" -Wl,-soname=\"$soname\" @\"$rspfile\"" + + assert(defined(readelf), "to solink you must have a readelf") + assert(defined(nm), "to solink you must have an nm") + strip_switch = "" + if (defined(invoker.strip)) { + strip_switch = "--strip=${invoker.strip}" + } + + # This needs a Python script to avoid using a complex shell command + # requiring sh control structures, pipelines, and POSIX utilities. + # The host might not have a POSIX shell and utilities (e.g. Windows). + solink_wrapper = rebase_path("//build/toolchain/gcc_solink_wrapper.py") + command = "$python_path \"$solink_wrapper\" --readelf=\"$readelf\" --nm=\"$nm\" $strip_switch --sofile=\"$unstripped_sofile\" --tocfile=\"$tocfile\" --output=\"$sofile\"$whitelist_flag -- $link_command" + + rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" + + description = "SOLINK $sofile" + + # Use this for {{output_extension}} expansions unless a target manually + # overrides it (in which case {{output_extension}} will be what the target + # specifies). + default_output_extension = default_shlib_extension + + default_output_dir = "{{root_out_dir}}" + if (shlib_subdir != ".") { + default_output_dir += "/$shlib_subdir" + } + + output_prefix = "lib" + + # Since the above commands only updates the .TOC file when it changes, ask + # Ninja to check if the timestamp actually changed to know if downstream + # dependencies should be recompiled. + restat = true + + # Tell GN about the output files. It will link to the sofile but use the + # tocfile for dependency management. + outputs = [ + sofile, + tocfile, + ] + if (enable_resource_whitelist_generation) { + outputs += [ whitelist_file ] + } + if (sofile != unstripped_sofile) { + outputs += [ unstripped_sofile ] + } + link_output = sofile + depend_output = tocfile + } + + tool("solink_module") { + soname = "{{target_output_name}}{{output_extension}}" # e.g. "libfoo.so". + sofile = "{{output_dir}}/$soname" + rspfile = sofile + ".rsp" + pool = "//build/toolchain:link_pool($default_toolchain)" + + if (defined(invoker.strip)) { + unstripped_sofile = "{{root_out_dir}}/lib.unstripped/$soname" + } else { + unstripped_sofile = sofile + } + + command = "$ld -shared {{ldflags}}${extra_ldflags} -o \"$unstripped_sofile\" -Wl,-soname=\"$soname\" @\"$rspfile\"" + + if (defined(invoker.strip)) { + strip_command = "${invoker.strip} --strip-unneeded -o \"$sofile\" \"$unstripped_sofile\"" + command += " && " + strip_command + } + rspfile_content = "-Wl,--whole-archive {{inputs}} {{solibs}} -Wl,--no-whole-archive $solink_libs_section_prefix {{libs}} $solink_libs_section_postfix" + + description = "SOLINK_MODULE $sofile" + + # Use this for {{output_extension}} expansions unless a target manually + # overrides it (in which case {{output_extension}} will be what the target + # specifies). + if (defined(invoker.loadable_module_extension)) { + default_output_extension = invoker.loadable_module_extension + } else { + default_output_extension = default_shlib_extension + } + + default_output_dir = "{{root_out_dir}}" + if (shlib_subdir != ".") { + default_output_dir += "/$shlib_subdir" + } + + output_prefix = "lib" + + outputs = [ + sofile, + ] + if (sofile != unstripped_sofile) { + outputs += [ unstripped_sofile ] + } + } + + tool("link") { + exename = "{{target_output_name}}{{output_extension}}" + outfile = "{{output_dir}}/$exename" + rspfile = "$outfile.rsp" + unstripped_outfile = outfile + pool = "//build/toolchain:link_pool($default_toolchain)" + + # Use this for {{output_extension}} expansions unless a target manually + # overrides it (in which case {{output_extension}} will be what the target + # specifies). + default_output_extension = default_executable_extension + + default_output_dir = "{{root_out_dir}}" + + if (defined(invoker.strip)) { + unstripped_outfile = "{{root_out_dir}}/exe.unstripped/$exename" + } + + command = "$ld {{ldflags}}${extra_ldflags} -o \"$unstripped_outfile\" -Wl,--start-group @\"$rspfile\" {{solibs}} -Wl,--end-group $libs_section_prefix {{libs}} $libs_section_postfix" + if (defined(invoker.strip)) { + link_wrapper = + rebase_path("//build/toolchain/gcc_link_wrapper.py", root_build_dir) + command = "$python_path \"$link_wrapper\" --strip=\"${invoker.strip}\" --unstripped-file=\"$unstripped_outfile\" --output=\"$outfile\" -- $command" + } + description = "LINK $outfile" + rspfile_content = "{{inputs}}" + outputs = [ + outfile, + ] + if (outfile != unstripped_outfile) { + outputs += [ unstripped_outfile ] + } + if (defined(invoker.link_outputs)) { + outputs += invoker.link_outputs + } + } + + # These two are really entirely generic, but have to be repeated in + # each toolchain because GN doesn't allow a template to be used here. + # See //build/toolchain/toolchain.gni for details. + tool("stamp") { + command = stamp_command + description = stamp_description + } + tool("copy") { + command = copy_command + description = copy_description + } + + forward_variables_from(invoker, [ "deps" ]) + } +} + +# This is a shorthand for gcc_toolchain instances based on the Chromium-built +# version of Clang. Only the toolchain_cpu and toolchain_os variables need to +# be specified by the invoker, and optionally toolprefix if it's a +# cross-compile case. Note that for a cross-compile case this toolchain +# requires a config to pass the appropriate -target option, or else it will +# actually just be doing a native compile. The invoker can optionally override +# use_gold too. +template("clang_toolchain") { + if (defined(invoker.toolprefix)) { + toolprefix = invoker.toolprefix + } else { + toolprefix = "" + } + + gcc_toolchain(target_name) { + prefix = rebase_path("$clang_base_path/bin", root_build_dir) + cc = "$prefix/clang" + cxx = "$prefix/clang++" + ld = cxx + + readelf = "${toolprefix}readelf" + ar = "${toolprefix}ar" + nm = "${toolprefix}nm" + + forward_variables_from(invoker, [ "strip" ]) + + toolchain_args = { + if (defined(invoker.toolchain_args)) { + forward_variables_from(invoker.toolchain_args, "*") + } + is_clang = true + } + } +} diff --git a/samples/GN/icu.gn b/samples/GN/icu.gn new file mode 100644 index 00000000..f3734b7a --- /dev/null +++ b/samples/GN/icu.gn @@ -0,0 +1,235 @@ +# Copyright 2016 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("//build/config/linux/pkg_config.gni") +import("//build/shim_headers.gni") + +group("icu") { + public_deps = [ + ":icui18n", + ":icuuc", + ] +} + +config("icu_config") { + defines = [ + "USING_SYSTEM_ICU=1", + "ICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_STATIC", + ] +} + +pkg_config("system_icui18n") { + packages = [ "icu-i18n" ] +} + +pkg_config("system_icuuc") { + packages = [ "icu-uc" ] +} + +source_set("icui18n") { + deps = [ + ":icui18n_shim", + ] + public_configs = [ + ":icu_config", + ":system_icui18n", + ] +} + +source_set("icuuc") { + deps = [ + ":icuuc_shim", + ] + public_configs = [ + ":icu_config", + ":system_icuuc", + ] +} + +shim_headers("icui18n_shim") { + root_path = "source/i18n" + headers = [ + # This list can easily be updated using the command below: + # find third_party/icu/source/i18n/unicode \ + # -iname '*.h' -printf '"%p",\n' | \ + # sed -e 's|third_party/icu/i18n/common/||' | sort -u + "unicode/alphaindex.h", + "unicode/basictz.h", + "unicode/calendar.h", + "unicode/choicfmt.h", + "unicode/coleitr.h", + "unicode/coll.h", + "unicode/compactdecimalformat.h", + "unicode/curramt.h", + "unicode/currpinf.h", + "unicode/currunit.h", + "unicode/datefmt.h", + "unicode/dcfmtsym.h", + "unicode/decimfmt.h", + "unicode/dtfmtsym.h", + "unicode/dtitvfmt.h", + "unicode/dtitvinf.h", + "unicode/dtptngen.h", + "unicode/dtrule.h", + "unicode/fieldpos.h", + "unicode/fmtable.h", + "unicode/format.h", + "unicode/fpositer.h", + "unicode/gender.h", + "unicode/gregocal.h", + "unicode/locdspnm.h", + "unicode/measfmt.h", + "unicode/measunit.h", + "unicode/measure.h", + "unicode/msgfmt.h", + "unicode/numfmt.h", + "unicode/numsys.h", + "unicode/plurfmt.h", + "unicode/plurrule.h", + "unicode/rbnf.h", + "unicode/rbtz.h", + "unicode/regex.h", + "unicode/region.h", + "unicode/reldatefmt.h", + "unicode/scientificnumberformatter.h", + "unicode/search.h", + "unicode/selfmt.h", + "unicode/simpletz.h", + "unicode/smpdtfmt.h", + "unicode/sortkey.h", + "unicode/stsearch.h", + "unicode/tblcoll.h", + "unicode/timezone.h", + "unicode/tmunit.h", + "unicode/tmutamt.h", + "unicode/tmutfmt.h", + "unicode/translit.h", + "unicode/tzfmt.h", + "unicode/tznames.h", + "unicode/tzrule.h", + "unicode/tztrans.h", + "unicode/ucal.h", + "unicode/ucol.h", + "unicode/ucoleitr.h", + "unicode/ucsdet.h", + "unicode/ucurr.h", + "unicode/udat.h", + "unicode/udateintervalformat.h", + "unicode/udatpg.h", + "unicode/udisplaycontext.h", + "unicode/ufieldpositer.h", + "unicode/uformattable.h", + "unicode/ugender.h", + "unicode/uldnames.h", + "unicode/ulocdata.h", + "unicode/umsg.h", + "unicode/unirepl.h", + "unicode/unum.h", + "unicode/unumsys.h", + "unicode/upluralrules.h", + "unicode/uregex.h", + "unicode/uregion.h", + "unicode/usearch.h", + "unicode/uspoof.h", + "unicode/utmscale.h", + "unicode/utrans.h", + "unicode/vtzone.h", + ] +} + +shim_headers("icuuc_shim") { + root_path = "source/common" + headers = [ + # This list can easily be updated using the command below: + # find third_party/icu/source/common/unicode \ + # -iname '*.h' -printf '"%p",\n' | \ + # sed -e 's|third_party/icu/source/common/||' | sort -u + "unicode/appendable.h", + "unicode/brkiter.h", + "unicode/bytestream.h", + "unicode/bytestrie.h", + "unicode/bytestriebuilder.h", + "unicode/caniter.h", + "unicode/chariter.h", + "unicode/dbbi.h", + "unicode/docmain.h", + "unicode/dtintrv.h", + "unicode/enumset.h", + "unicode/errorcode.h", + "unicode/filteredbrk.h", + "unicode/icudataver.h", + "unicode/icuplug.h", + "unicode/idna.h", + "unicode/listformatter.h", + "unicode/localpointer.h", + "unicode/locid.h", + "unicode/messagepattern.h", + "unicode/normalizer2.h", + "unicode/normlzr.h", + "unicode/parseerr.h", + "unicode/parsepos.h", + "unicode/platform.h", + "unicode/ptypes.h", + "unicode/putil.h", + "unicode/rbbi.h", + "unicode/rep.h", + "unicode/resbund.h", + "unicode/schriter.h", + "unicode/std_string.h", + "unicode/strenum.h", + "unicode/stringpiece.h", + "unicode/stringtriebuilder.h", + "unicode/symtable.h", + "unicode/ubidi.h", + "unicode/ubrk.h", + "unicode/ucasemap.h", + "unicode/ucat.h", + "unicode/uchar.h", + "unicode/ucharstrie.h", + "unicode/ucharstriebuilder.h", + "unicode/uchriter.h", + "unicode/uclean.h", + "unicode/ucnv.h", + "unicode/ucnv_cb.h", + "unicode/ucnv_err.h", + "unicode/ucnvsel.h", + "unicode/uconfig.h", + "unicode/udata.h", + "unicode/uenum.h", + "unicode/uidna.h", + "unicode/uiter.h", + "unicode/ulistformatter.h", + "unicode/uloc.h", + "unicode/umachine.h", + "unicode/umisc.h", + "unicode/unifilt.h", + "unicode/unifunct.h", + "unicode/unimatch.h", + "unicode/uniset.h", + "unicode/unistr.h", + "unicode/unorm.h", + "unicode/unorm2.h", + "unicode/uobject.h", + "unicode/urename.h", + "unicode/urep.h", + "unicode/ures.h", + "unicode/uscript.h", + "unicode/uset.h", + "unicode/usetiter.h", + "unicode/ushape.h", + "unicode/usprep.h", + "unicode/ustring.h", + "unicode/ustringtrie.h", + "unicode/utext.h", + "unicode/utf.h", + "unicode/utf16.h", + "unicode/utf32.h", + "unicode/utf8.h", + "unicode/utf_old.h", + "unicode/utrace.h", + "unicode/utypes.h", + "unicode/uvernum.h", + "unicode/uversion.h", + ] +} diff --git a/samples/GN/internal_rules.gni b/samples/GN/internal_rules.gni new file mode 100644 index 00000000..27b736f3 --- /dev/null +++ b/samples/GN/internal_rules.gni @@ -0,0 +1,2788 @@ +# 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. + +# Do not add any imports to non-//build directories here. +# Some projects (e.g. V8) do not have non-build directories DEPS'ed in. +import("//build_overrides/build.gni") +import("//build/config/android/config.gni") +import("//build/config/dcheck_always_on.gni") +import("//build/config/sanitizers/sanitizers.gni") + +assert(is_android) + +# These identify targets that have .build_config files (except for android_apk, +# java_binary, resource_rewriter, since we never need to depend on these). +_java_target_whitelist = [ + "*:*_java", + "*:*_javalib", + "*:*_java_*", # e.g. java_test_support + "*:java", + "*:junit", + "*:junit_*", + "*:*_junit_*", + "*:*javatests", + "*:*_assets", + "*android*:assets", + "*:*_apk_*resources", + "*android*:resources", + "*:*_resources", + "*:*_grd", + "*:*locale_paks", + + # TODO(agrieve): Rename targets below to match above patterns. + "*android_webview/glue:glue", + "//build/android/rezip:rezip", + "//chrome/test/android/cast_emulator:cast_emulator", +] + +# Targets that match the whitelist but are not actually java targets. +_java_target_blacklist = [ + "//chrome:packed_resources", + "//remoting/android:remoting_android_raw_resources", + "*:*_unpack_aar", +] + +# Write the target's .build_config file. This is a json file that contains a +# dictionary of information about how to build this target (things that +# require knowledge about this target's dependencies and cannot be calculated +# at gn-time). There is a special syntax to add a value in that dictionary to +# an action/action_foreachs args: +# --python-arg=@FileArg($rebased_build_config_path:key0:key1) +# At runtime, such an arg will be replaced by the value in the build_config. +# See build/android/gyp/write_build_config.py and +# build/android/gyp/util/build_utils.py:ExpandFileArgs +template("write_build_config") { + type = invoker.type + _is_prebuilt_binary = + defined(invoker.is_prebuilt_binary) && invoker.is_prebuilt_binary + + # Don't need to enforce naming scheme for these targets since we never + # consider them in dependency chains. + if (!_is_prebuilt_binary && type != "android_apk" && type != "java_binary" && + type != "resource_rewriter") { + set_sources_assignment_filter(_java_target_whitelist) + _parent_invoker = invoker.invoker + _target_label = + get_label_info(":${_parent_invoker.target_name}", "label_no_toolchain") + sources = [ + _target_label, + ] + if (sources != []) { + set_sources_assignment_filter(_java_target_blacklist) + sources = [] + sources = [ + _target_label, + ] + if (sources != []) { + assert(false, "Invalid java target name: $_target_label") + } + } + sources = [] + } + + action(target_name) { + set_sources_assignment_filter([]) + build_config = invoker.build_config + + assert(type == "android_apk" || type == "java_library" || + type == "android_resources" || type == "deps_dex" || + type == "android_assets" || type == "resource_rewriter" || + type == "java_binary" || type == "group" || type == "java_prebuilt") + + forward_variables_from(invoker, + [ + "deps", + "testonly", + ]) + if (!defined(deps)) { + deps = [] + } + + script = "//build/android/gyp/write_build_config.py" + depfile = "$target_gen_dir/$target_name.d" + inputs = [] + + _deps_configs = [] + if (defined(invoker.possible_config_deps)) { + foreach(_possible_dep, invoker.possible_config_deps) { + set_sources_assignment_filter(_java_target_whitelist) + _target_label = get_label_info(_possible_dep, "label_no_toolchain") + sources = [ + _target_label, + ] + if (sources == []) { + set_sources_assignment_filter(_java_target_blacklist) + sources = [] + sources = [ + _target_label, + ] + if (sources != []) { + deps += [ "${_target_label}__build_config" ] + _dep_gen_dir = get_label_info(_possible_dep, "target_gen_dir") + _dep_name = get_label_info(_possible_dep, "name") + _deps_configs += [ "$_dep_gen_dir/$_dep_name.build_config" ] + } + } + sources = [] + } + set_sources_assignment_filter([]) + } + _rebased_deps_configs = rebase_path(_deps_configs, root_build_dir) + + outputs = [ + build_config, + ] + + args = [ + "--type", + type, + "--depfile", + rebase_path(depfile, root_build_dir), + "--deps-configs=$_rebased_deps_configs", + "--build-config", + rebase_path(build_config, root_build_dir), + ] + + is_java = type == "java_library" || type == "java_binary" || + type == "java_prebuilt" + is_apk = type == "android_apk" + is_android_assets = type == "android_assets" + is_android_resources = type == "android_resources" + is_deps_dex = type == "deps_dex" + is_group = type == "group" + + supports_android = is_apk || is_android_assets || is_android_resources || + is_deps_dex || is_group || + (is_java && defined(invoker.supports_android) && + invoker.supports_android) + requires_android = + is_apk || is_android_assets || is_android_resources || is_deps_dex || + (is_java && defined(invoker.requires_android) && + invoker.requires_android) + + assert(!requires_android || supports_android, + "requires_android requires" + " supports_android") + + # Mark these variables as used. + assert(is_java || true) + assert(is_apk || true) + assert(is_android_resources || true) + assert(is_deps_dex || true) + assert(is_group || true) + + if (is_java || is_apk) { + args += [ + "--jar-path", + rebase_path(invoker.jar_path, root_build_dir), + ] + } + + if (is_apk || is_deps_dex || (is_java && supports_android)) { + args += [ + "--dex-path", + rebase_path(invoker.dex_path, root_build_dir), + ] + } + if (supports_android) { + args += [ "--supports-android" ] + } + if (requires_android) { + args += [ "--requires-android" ] + } + if (defined(invoker.bypass_platform_checks) && + invoker.bypass_platform_checks) { + args += [ "--bypass-platform-checks" ] + } + + if (defined(invoker.apk_under_test)) { + deps += [ "${invoker.apk_under_test}__build_config" ] + apk_under_test_gen_dir = + get_label_info(invoker.apk_under_test, "target_gen_dir") + apk_under_test_name = get_label_info(invoker.apk_under_test, "name") + apk_under_test_config = + "$apk_under_test_gen_dir/$apk_under_test_name.build_config" + args += [ + "--tested-apk-config", + rebase_path(apk_under_test_config, root_build_dir), + ] + } + + if (is_android_assets) { + if (defined(invoker.asset_sources)) { + _rebased_asset_sources = + rebase_path(invoker.asset_sources, root_build_dir) + args += [ "--asset-sources=$_rebased_asset_sources" ] + } + if (defined(invoker.asset_renaming_sources)) { + _rebased_asset_renaming_sources = + rebase_path(invoker.asset_renaming_sources, root_build_dir) + args += [ "--asset-renaming-sources=$_rebased_asset_renaming_sources" ] + + # These are zip paths, so no need to rebase. + args += [ "--asset-renaming-destinations=${invoker.asset_renaming_destinations}" ] + } + if (defined(invoker.disable_compression) && invoker.disable_compression) { + args += [ "--disable-asset-compression" ] + } + } + + if (is_android_resources || is_apk) { + assert(defined(invoker.resources_zip)) + args += [ + "--resources-zip", + rebase_path(invoker.resources_zip, root_build_dir), + ] + if (defined(invoker.android_manifest)) { + inputs += [ invoker.android_manifest ] + args += [ + "--android-manifest", + rebase_path(invoker.android_manifest, root_build_dir), + ] + } else { + assert(!is_apk, "apk build configs require an android_manifest") + } + if (defined(invoker.custom_package)) { + args += [ + "--package-name", + invoker.custom_package, + ] + } + if (defined(invoker.r_text)) { + args += [ + "--r-text", + rebase_path(invoker.r_text, root_build_dir), + ] + } + } + + if (is_android_resources && defined(invoker.resource_dirs)) { + resource_dirs = rebase_path(invoker.resource_dirs, root_build_dir) + args += [ "--resource-dirs=$resource_dirs" ] + } + + if (is_apk) { + if (defined(invoker.shared_libraries_runtime_deps_file)) { + # Don't list shared_libraries_runtime_deps_file as an input in order to + # avoid having to depend on the runtime_deps target. See comment in + # rules.gni for why we do this. + args += [ + "--shared-libraries-runtime-deps", + rebase_path(invoker.shared_libraries_runtime_deps_file, + root_build_dir), + ] + } + + if (defined(invoker.secondary_abi_shared_libraries_runtime_deps_file)) { + # Don't list secondary_abi_shared_libraries_runtime_deps_file as an + # input in order to avoid having to depend on the runtime_deps target. + # See comment in rules.gni for why we do this. + args += [ + "--secondary-abi-shared-libraries-runtime-deps", + rebase_path(invoker.secondary_abi_shared_libraries_runtime_deps_file, + root_build_dir), + ] + } + + if (defined(invoker.proguard_enabled) && invoker.proguard_enabled) { + args += [ + "--proguard-enabled", + "--proguard-info", + rebase_path(invoker.proguard_info, root_build_dir), + ] + } + + if (defined(invoker.apk_path)) { + _rebased_apk_path = rebase_path(invoker.apk_path, root_build_dir) + _rebased_incremental_apk_path = + rebase_path(invoker.incremental_apk_path, root_build_dir) + _rebased_incremental_install_script_path = + rebase_path(invoker.incremental_install_script_path, root_build_dir) + args += [ "--apk-path=$_rebased_apk_path" ] + args += [ "--incremental-apk-path=$_rebased_incremental_apk_path" ] + args += [ "--incremental-install-script-path=$_rebased_incremental_install_script_path" ] + } + } + + if (defined(invoker.java_sources_file)) { + args += [ + "--java-sources-file", + rebase_path(invoker.java_sources_file, root_build_dir), + ] + } + if (defined(invoker.srcjar)) { + args += [ + "--srcjar", + rebase_path(invoker.srcjar, root_build_dir), + ] + } + if (defined(invoker.bundled_srcjars)) { + _rebased_bundled_srcjars = + rebase_path(invoker.bundled_srcjars, root_build_dir) + args += [ "--bundled-srcjars=$_rebased_bundled_srcjars" ] + } + if (defined(invoker.input_jars_paths)) { + _rebased_input_jars_paths = + rebase_path(invoker.input_jars_paths, root_build_dir) + args += [ "--extra-classpath-jars=$_rebased_input_jars_paths" ] + } + if (defined(invoker.proguard_configs)) { + _rebased_proguard_configs = + rebase_path(invoker.proguard_configs, root_build_dir) + args += [ "--proguard-configs=$_rebased_proguard_configs" ] + } + if (defined(invoker.gradle_treat_as_prebuilt) && + invoker.gradle_treat_as_prebuilt) { + args += [ "--gradle-treat-as-prebuilt" ] + } + if (defined(invoker.main_class)) { + args += [ + "--main-class", + invoker.main_class, + ] + } + if (current_toolchain != default_toolchain) { + # This has to be a built-time error rather than a GN assert because many + # packages have a mix of java and non-java targets. For example, the + # following would fail even though nothing depends on :bar(//baz): + # + # shared_library("foo") { + # } + # + # android_library("bar") { + # deps = [ ":foo(//baz)" ] + # assert(current_toolchain == default_toolchain) + # } + _msg = [ + "Tried to build an Android target in a non-default toolchain.", + "target: " + get_label_info(":$target_name", "label_with_toolchain"), + "default_toolchain: $default_toolchain", + ] + args += [ "--fail=$_msg" ] + } + } +} + +template("copy_ex") { + set_sources_assignment_filter([]) + action(target_name) { + forward_variables_from(invoker, + [ + "data", + "deps", + "inputs", + "sources", + "testonly", + "visibility", + ]) + if (!defined(sources)) { + sources = [] + } + script = "//build/android/gyp/copy_ex.py" + depfile = "$target_gen_dir/$target_name.d" + + _stamp_file = "$target_gen_dir/$target_name.stamp" + outputs = [ + _stamp_file, + ] + + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--stamp", + rebase_path(_stamp_file, root_build_dir), + "--dest", + rebase_path(invoker.dest, root_build_dir), + ] + rebased_sources = rebase_path(sources, root_build_dir) + args += [ "--files=$rebased_sources" ] + + if (defined(invoker.clear_dir) && invoker.clear_dir) { + args += [ "--clear" ] + } + + if (defined(invoker.args)) { + args += invoker.args + } + + if (defined(invoker.renaming_sources) && + defined(invoker.renaming_destinations)) { + sources += invoker.renaming_sources + rebased_renaming_sources = + rebase_path(invoker.renaming_sources, root_build_dir) + args += [ "--renaming-sources=$rebased_renaming_sources" ] + + renaming_destinations = invoker.renaming_destinations + args += [ "--renaming-destinations=$renaming_destinations" ] + } + } +} + +# Generates a script in the build bin directory which runs the test +# target using the test runner script in build/android/test_runner.py. +template("test_runner_script") { + testonly = true + _test_name = invoker.test_name + _test_type = invoker.test_type + _incremental_install = + defined(invoker.incremental_install) && invoker.incremental_install + + _runtime_deps = + !defined(invoker.ignore_all_data_deps) || !invoker.ignore_all_data_deps + + if (_runtime_deps) { + # This runtime_deps file is used at runtime and thus cannot go in + # target_gen_dir. + _target_dir_name = get_label_info(":$target_name", "dir") + _runtime_deps_file = + "$root_out_dir/gen.runtime/$_target_dir_name/$target_name.runtime_deps" + _runtime_deps_target = "${target_name}__write_deps" + group(_runtime_deps_target) { + forward_variables_from(invoker, + [ + "data", + "data_deps", + "deps", + "public_deps", + ]) + write_runtime_deps = _runtime_deps_file + } + } + + action(target_name) { + forward_variables_from(invoker, + [ + "data_deps", + "deps", + ]) + if (!defined(deps)) { + deps = [] + } + if (!defined(data_deps)) { + data_deps = [] + } + + script = "//build/android/gyp/create_test_runner_script.py" + depfile = "$target_gen_dir/$target_name.d" + + data_deps += [ "//build/android:test_runner_py" ] + data = [] + + test_runner_args = [ + _test_type, + "--output-directory", + rebase_path(root_build_dir, root_build_dir), + ] + + if (_runtime_deps) { + deps += [ ":$_runtime_deps_target" ] + data += [ _runtime_deps_file ] + test_runner_args += [ + "--runtime-deps-path", + rebase_path(_runtime_deps_file, root_build_dir), + ] + } + + # apk_target is not used for native executable tests + # (e.g. breakpad_unittests). + if (defined(invoker.apk_target)) { + assert(!defined(invoker.executable_dist_dir)) + deps += [ "${invoker.apk_target}__build_config" ] + _apk_build_config = + get_label_info(invoker.apk_target, "target_gen_dir") + "/" + + get_label_info(invoker.apk_target, "name") + ".build_config" + _rebased_apk_build_config = rebase_path(_apk_build_config, root_build_dir) + assert(_rebased_apk_build_config != "") # Mark as used. + } else if (_test_type == "gtest") { + assert( + defined(invoker.executable_dist_dir), + "Must define either apk_target or executable_dist_dir for test_runner_script()") + test_runner_args += [ + "--executable-dist-dir", + rebase_path(invoker.executable_dist_dir, root_build_dir), + ] + } + + if (_test_type == "gtest") { + assert(defined(invoker.test_suite)) + test_runner_args += [ + "--suite", + invoker.test_suite, + ] + } else if (_test_type == "instrumentation") { + _test_apk = "@FileArg($_rebased_apk_build_config:deps_info:apk_path)" + if (_incremental_install) { + _test_apk = "@FileArg($_rebased_apk_build_config:deps_info:incremental_apk_path)" + } + test_runner_args += [ + "--test-apk=$_test_apk", + "--test-jar", + rebase_path(invoker.test_jar, root_build_dir), + ] + if (defined(invoker.apk_under_test)) { + deps += [ "${invoker.apk_under_test}__build_config" ] + _apk_under_test_build_config = + get_label_info(invoker.apk_under_test, "target_gen_dir") + "/" + + get_label_info(invoker.apk_under_test, "name") + ".build_config" + _rebased_apk_under_test_build_config = + rebase_path(_apk_under_test_build_config, root_build_dir) + _apk_under_test = + "@FileArg($_rebased_apk_under_test_build_config:deps_info:apk_path)" + if (_incremental_install) { + _apk_under_test = "@FileArg($_rebased_apk_under_test_build_config:deps_info:incremental_apk_path)" + } + test_runner_args += [ "--apk-under-test=$_apk_under_test" ] + } + if (emma_coverage) { + # Set a default coverage output directory (can be overridden by user + # passing the same flag). + test_runner_args += [ + "--coverage-dir", + rebase_path("$root_out_dir/coverage", root_build_dir), + ] + } + } else if (_test_type == "junit") { + assert(defined(invoker.test_suite)) + test_runner_args += [ + "--test-suite", + invoker.test_suite, + ] + } else { + assert(false, "Invalid test type: $_test_type.") + } + + if (defined(invoker.additional_apks)) { + foreach(additional_apk, invoker.additional_apks) { + deps += [ "${additional_apk}__build_config" ] + _build_config = get_label_info(additional_apk, "target_gen_dir") + "/" + + get_label_info(additional_apk, "name") + ".build_config" + _rebased_build_config = rebase_path(_build_config, root_build_dir) + test_runner_args += [ + "--additional-apk", + "@FileArg($_rebased_build_config:deps_info:apk_path)", + ] + } + } + if (defined(invoker.shard_timeout)) { + test_runner_args += [ "--shard-timeout=${invoker.shard_timeout}" ] + } + if (_incremental_install) { + test_runner_args += [ + "--test-apk-incremental-install-script", + "@FileArg($_rebased_apk_build_config:deps_info:incremental_install_script_path)", + ] + if (defined(invoker.apk_under_test)) { + test_runner_args += [ + "--apk-under-test-incremental-install-script", + "@FileArg($_rebased_apk_under_test_build_config:deps_info:incremental_install_script_path)", + ] + } + test_runner_args += [ "--fast-local-dev" ] + } + if (is_asan) { + test_runner_args += [ "--tool=asan" ] + } + + generated_script = "$root_build_dir/bin/run_${_test_name}" + outputs = [ + generated_script, + ] + data += [ generated_script ] + + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--script-output-path", + rebase_path(generated_script, root_build_dir), + ] + if (defined(android_test_runner_script)) { + args += [ + "--test-runner-path", + android_test_runner_script, + ] + } + + args += test_runner_args + } +} + +if (enable_java_templates) { + import("//build/config/zip.gni") + import("//third_party/ijar/ijar.gni") + import("//third_party/android_platform/config.gni") + + rebased_android_sdk = rebase_path(android_sdk, root_build_dir) + rebased_android_sdk_build_tools = + rebase_path(android_sdk_build_tools, root_build_dir) + + android_sdk_jar = "$android_sdk/android.jar" + rebased_android_sdk_jar = rebase_path(android_sdk_jar, root_build_dir) + android_default_aapt_path = "$rebased_android_sdk_build_tools/aapt" + + android_configuration_name = "Release" + if (is_debug) { + android_configuration_name = "Debug" + } + + template("android_lint") { + action(target_name) { + forward_variables_from(invoker, + [ + "deps", + "data_deps", + "public_deps", + "testonly", + ]) + if (!defined(deps)) { + deps = [] + } + + if (!defined(lint_suppressions_file)) { + lint_suppressions_file = "//build/android/lint/suppressions.xml" + } + + _cache_dir = "$root_build_dir/android_lint_cache" + _result_path = "$target_gen_dir/$target_name/result.xml" + _config_path = "$target_gen_dir/$target_name/config.xml" + _suppressions_file = lint_suppressions_file + _platform_xml_path = + "${android_sdk_root}/platform-tools/api/api-versions.xml" + _rebased_lint_android_sdk_root = + rebase_path(lint_android_sdk_root, root_build_dir) + + script = "//build/android/gyp/lint.py" + depfile = "$target_gen_dir/$target_name.d" + inputs = [ + _platform_xml_path, + _suppressions_file, + invoker.android_manifest, + ] + + outputs = [ + _result_path, + _config_path, + ] + + args = [ + "--lint-path=$_rebased_lint_android_sdk_root/tools/lint", + "--cache-dir", + rebase_path(_cache_dir, root_build_dir), + "--platform-xml-path", + rebase_path(_platform_xml_path, root_build_dir), + "--android-sdk-version=${lint_android_sdk_version}", + "--depfile", + rebase_path(depfile, root_build_dir), + "--config-path", + rebase_path(_suppressions_file, root_build_dir), + "--manifest-path", + rebase_path(invoker.android_manifest, root_build_dir), + "--product-dir=.", + "--processed-config-path", + rebase_path(_config_path, root_build_dir), + "--result-path", + rebase_path(_result_path, root_build_dir), + "--enable", + ] + + if (defined(invoker.create_cache) && invoker.create_cache) { + args += [ + "--create-cache", + "--silent", + ] + } else { + inputs += invoker.java_files + inputs += [ + invoker.jar_path, + invoker.build_config, + ] + if (invoker.java_files != []) { + inputs += [ invoker.java_sources_file ] + _rebased_java_sources_file = + rebase_path(invoker.java_sources_file, root_build_dir) + args += [ "--java-sources-file=$_rebased_java_sources_file" ] + } + deps += [ "//build/android:prepare_android_lint_cache" ] + + _rebased_build_config = + rebase_path(invoker.build_config, root_build_dir) + args += [ + "--jar-path", + rebase_path(invoker.jar_path, root_build_dir), + "--classpath=@FileArg($_rebased_build_config:javac:interface_classpath)", + "--resource-sources=@FileArg($_rebased_build_config:deps_info:owned_resources_dirs)", + "--resource-sources=@FileArg($_rebased_build_config:deps_info:owned_resources_zips)", + "--can-fail-build", + ] + } + } + } + + template("proguard") { + action(target_name) { + set_sources_assignment_filter([]) + forward_variables_from(invoker, + [ + "deps", + "data_deps", + "public_deps", + "testonly", + ]) + script = "//build/android/gyp/proguard.py" + if (defined(invoker.proguard_jar_path)) { + _proguard_jar_path = invoker.proguard_jar_path + } else { + _proguard_jar_path = "//third_party/proguard/lib/proguard.jar" + } + _output_jar_path = invoker.output_jar_path + inputs = [ + _proguard_jar_path, + ] + if (defined(invoker.alternative_android_sdk_jar)) { + inputs += [ invoker.alternative_android_sdk_jar ] + _rebased_android_sdk_jar = + rebase_path(invoker.alternative_android_sdk_jar) + } else { + inputs += [ android_sdk_jar ] + _rebased_android_sdk_jar = rebased_android_sdk_jar + } + if (defined(invoker.inputs)) { + inputs += invoker.inputs + } + depfile = "${target_gen_dir}/${target_name}.d" + outputs = [ + _output_jar_path, + "$_output_jar_path.dump", + "$_output_jar_path.seeds", + "$_output_jar_path.mapping", + "$_output_jar_path.usage", + ] + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--proguard-path", + rebase_path(_proguard_jar_path, root_build_dir), + "--output-path", + rebase_path(_output_jar_path, root_build_dir), + "--classpath", + _rebased_android_sdk_jar, + ] + if (proguard_verbose) { + args += [ "--verbose" ] + } + if (defined(invoker.args)) { + args += invoker.args + } + if (defined(invoker.proguard_jar_path)) { + # We assume that if we are using a different ProGuard, this new version + # can handle the 'dangerous' optimizaions. + args += [ "--enable-dangerous-optimizations" ] + } + } + } + + template("findbugs") { + action(target_name) { + forward_variables_from(invoker, + [ + "deps", + "testonly", + ]) + script = "//build/android/findbugs_diff.py" + depfile = "$target_gen_dir/$target_name.d" + _result_path = "$target_gen_dir/$target_name/result.xml" + _exclusions_file = "//build/android/findbugs_filter/findbugs_exclude.xml" + + _rebased_build_config = rebase_path(invoker.build_config, root_build_dir) + + inputs = [ + "//build/android/pylib/utils/findbugs.py", + _exclusions_file, + invoker.jar_path, + invoker.build_config, + ] + + outputs = [ + _result_path, + ] + + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--exclude", + rebase_path(_exclusions_file, root_build_dir), + "--auxclasspath-gyp", + "@FileArg($_rebased_build_config:javac:classpath)", + "--output-file", + rebase_path(_result_path, root_build_dir), + rebase_path(invoker.jar_path, root_build_dir), + ] + + if (findbugs_verbose) { + args += [ "-vv" ] + } + } + } + + # Generates a script in the build bin directory to run a java binary. + # + # Variables + # main_class: The class containing the program entry point. + # jar_path: The path to the jar to run. + # script_name: Name of the script to generate. + # build_config: Path to .build_config for the jar (contains classpath). + # wrapper_script_args: List of extra arguments to pass to the executable. + # + template("java_binary_script") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + _main_class = invoker.main_class + _build_config = invoker.build_config + _jar_path = invoker.jar_path + _script_name = invoker.script_name + + action(target_name) { + script = "//build/android/gyp/create_java_binary_script.py" + depfile = "$target_gen_dir/$_script_name.d" + java_script = "$root_build_dir/bin/$_script_name" + inputs = [ + _build_config, + ] + outputs = [ + java_script, + ] + forward_variables_from(invoker, [ "deps" ]) + _rebased_build_config = rebase_path(_build_config, root_build_dir) + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--output", + rebase_path(java_script, root_build_dir), + "--classpath=@FileArg($_rebased_build_config:deps_info:java:full_classpath)", + "--jar-path", + rebase_path(_jar_path, root_build_dir), + "--main-class", + _main_class, + ] + if (emma_coverage) { + args += [ + "--classpath", + rebase_path("//third_party/android_tools/sdk/tools/lib/emma.jar", + root_build_dir), + ] + args += [ "--noverify" ] + } + if (defined(invoker.wrapper_script_args)) { + args += [ "--" ] + invoker.wrapper_script_args + } + if (defined(invoker.bootclasspath)) { + args += [ + "--bootclasspath", + rebase_path(invoker.bootclasspath, root_build_dir), + ] + } + } + } + + template("dex") { + set_sources_assignment_filter([]) + + _enable_multidex = + defined(invoker.enable_multidex) && invoker.enable_multidex + + if (_enable_multidex) { + _main_dex_list_path = invoker.output + ".main_dex_list" + _main_dex_list_target_name = "${target_name}__main_dex_list" + action(_main_dex_list_target_name) { + forward_variables_from(invoker, + [ + "deps", + "inputs", + "sources", + "testonly", + ]) + + script = "//build/android/gyp/main_dex_list.py" + depfile = "$target_gen_dir/$target_name.d" + + main_dex_rules = "//build/android/main_dex_classes.flags" + + if (!defined(inputs)) { + inputs = [] + } + inputs += [ main_dex_rules ] + + outputs = [ + _main_dex_list_path, + ] + + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--android-sdk-tools", + rebased_android_sdk_build_tools, + "--main-dex-list-path", + rebase_path(_main_dex_list_path, root_build_dir), + "--main-dex-rules-path", + rebase_path(main_dex_rules, root_build_dir), + ] + + if (defined(invoker.args)) { + args += invoker.args + } + + if (defined(invoker.sources)) { + args += rebase_path(invoker.sources, root_build_dir) + } + } + } + + assert(defined(invoker.output)) + action(target_name) { + forward_variables_from(invoker, + [ + "deps", + "inputs", + "sources", + "testonly", + ]) + script = "//build/android/gyp/dex.py" + depfile = "$target_gen_dir/$target_name.d" + outputs = [ + invoker.output, + ] + + rebased_output = rebase_path(invoker.output, root_build_dir) + + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--android-sdk-tools", + rebased_android_sdk_build_tools, + "--dex-path", + rebased_output, + ] + + if (enable_incremental_dx) { + args += [ "--incremental" ] + } + + # EMMA requires --no-locals. + if (emma_coverage) { + args += [ "--no-locals=1" ] + } + + if (_enable_multidex) { + args += [ + "--multi-dex", + "--main-dex-list-path", + rebase_path(_main_dex_list_path, root_build_dir), + ] + deps += [ ":${_main_dex_list_target_name}" ] + inputs += [ _main_dex_list_path ] + } + + if (defined(invoker.args)) { + args += invoker.args + } + + if (defined(invoker.sources)) { + args += rebase_path(invoker.sources, root_build_dir) + } + } + } + + template("process_java_prebuilt") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + assert(invoker.build_config != "") + _build_config = invoker.build_config + _rebased_build_config = rebase_path(_build_config, root_build_dir) + assert(_rebased_build_config != "" || true) # Mark used. + + _input_jar_path = invoker.input_jar_path + _output_jar_path = invoker.output_jar_path + + _jar_excluded_patterns = [] + if (defined(invoker.jar_excluded_patterns)) { + _jar_excluded_patterns = invoker.jar_excluded_patterns + } + _strip_resource_classes = defined(invoker.strip_resource_classes) && + invoker.strip_resource_classes + _filter_jar = _jar_excluded_patterns != [] || _strip_resource_classes + + _proguard_preprocess = + defined(invoker.proguard_preprocess) && invoker.proguard_preprocess + + _enable_assert = + defined(invoker.supports_android) && invoker.supports_android && + (is_java_debug || dcheck_always_on) + + _retrolambda = defined(invoker.supports_android) && + invoker.supports_android && use_java8 + + _deps = [] + _previous_output_jar = _input_jar_path + + if (_filter_jar) { + _filter_target = "${target_name}__filter" + _filter_input_jar = _previous_output_jar + _filter_output_jar = "$target_out_dir/$target_name-filtered.jar" + + action(_filter_target) { + script = "//build/android/gyp/jar.py" + deps = _deps + if (defined(invoker.deps)) { + deps += invoker.deps + } + if (defined(invoker.public_deps)) { + public_deps = invoker.public_deps + } + inputs = [ + _build_config, + _filter_input_jar, + ] + outputs = [ + _filter_output_jar, + ] + args = [ + "--input-jar", + rebase_path(_filter_input_jar, root_build_dir), + "--jar-path", + rebase_path(_filter_output_jar, root_build_dir), + "--excluded-classes=$_jar_excluded_patterns", + ] + if (_strip_resource_classes) { + args += [ "--strip-resource-classes-for=@FileArg($_rebased_build_config:javac:resource_packages)" ] + } + } + + _deps = [] + _deps = [ ":$_filter_target" ] + _previous_output_jar = _filter_output_jar + } + + if (_proguard_preprocess) { + _proguard_target = "${target_name}__proguard_process" + _proguard_input_jar = _previous_output_jar + _proguard_output_jar = "$target_out_dir/$target_name-proguarded.jar" + _proguard_config_path = invoker.proguard_preprocess_config + + proguard(_proguard_target) { + deps = _deps + if (defined(invoker.deps)) { + deps += invoker.deps + } + if (defined(invoker.public_deps)) { + public_deps = invoker.public_deps + } + inputs = [ + _build_config, + _proguard_config_path, + _proguard_input_jar, + ] + output_jar_path = _proguard_output_jar + + _rebased_input_paths = + [ rebase_path(_proguard_input_jar, root_build_dir) ] + _rebased_proguard_configs = + [ rebase_path(_proguard_config_path, root_build_dir) ] + args = [ + "--input-paths=$_rebased_input_paths", + "--proguard-configs=$_rebased_proguard_configs", + "--classpath=@FileArg($_rebased_build_config:javac:classpath)", + ] + } + + _deps = [] + _deps = [ ":$_proguard_target" ] + _previous_output_jar = _proguard_output_jar + } + + if (_enable_assert) { + _assert_target = "${target_name}__assert" + _assert_input_jar = _previous_output_jar + _assert_output_jar = "$target_out_dir/$target_name-asserted.jar" + + action(_assert_target) { + script = "$root_build_dir/bin/helper/java_assertion_enabler" + deps = [ + "//build/android/java_assertion_enabler($default_toolchain)", + ] + deps += _deps + if (defined(invoker.deps)) { + deps += invoker.deps + } + if (defined(invoker.public_deps)) { + public_deps = invoker.public_deps + } + inputs = [ + _assert_input_jar, + ] + outputs = [ + _assert_output_jar, + ] + args = [ + rebase_path(_assert_input_jar, root_build_dir), + rebase_path(_assert_output_jar, root_build_dir), + ] + } + + _deps = [] + _deps = [ ":$_assert_target" ] + _previous_output_jar = _assert_output_jar + } + + if (_retrolambda) { + _retrolambda_target = "${target_name}__retrolambda" + _retrolambda_input_jar = _previous_output_jar + _retrolambda_output_jar = "$target_out_dir/$target_name-retrolambda.jar" + + android_sdk_jar = "$android_sdk/android.jar" + action(_retrolambda_target) { + script = "//build/android/gyp/retrolambda.py" + deps = _deps + if (defined(invoker.deps)) { + deps += invoker.deps + } + if (defined(invoker.public_deps)) { + public_deps = invoker.public_deps + } + inputs = [ + _build_config, + _retrolambda_input_jar, + ] + outputs = [ + _retrolambda_output_jar, + ] + args = [ + "--input-jar", + rebase_path(_retrolambda_input_jar, root_build_dir), + "--output-jar", + rebase_path(_retrolambda_output_jar, root_build_dir), + "--classpath=@FileArg($_rebased_build_config:javac:classpath)", + "--android-sdk-jar", + rebase_path(android_sdk_jar, root_build_dir), + ] + } + + _deps = [] + _deps = [ ":$_retrolambda_target" ] + _previous_output_jar = _retrolambda_output_jar + } + + _output_jar_target = "${target_name}__copy" + copy(_output_jar_target) { + deps = _deps + if (defined(invoker.deps)) { + deps += invoker.deps + } + if (defined(invoker.public_deps)) { + public_deps = invoker.public_deps + } + sources = [ + _previous_output_jar, + ] + outputs = [ + _output_jar_path, + ] + } + + group(target_name) { + forward_variables_from(invoker, + [ + "data_deps", + "visibility", + ]) + public_deps = [ + ":$_output_jar_target", + ] + } + } + + template("emma_instr") { + action(target_name) { + forward_variables_from(invoker, + [ + "deps", + "testonly", + ]) + + _coverage_file = "$target_out_dir/${target_name}.em" + _source_dirs_listing_file = "$target_out_dir/${target_name}_sources.txt" + _emma_jar = "${android_sdk_root}/tools/lib/emma.jar" + + script = "//build/android/gyp/emma_instr.py" + depfile = "${target_gen_dir}/${target_name}.d" + inputs = invoker.java_files + [ + _emma_jar, + invoker.input_jar_path, + ] + outputs = [ + _coverage_file, + _source_dirs_listing_file, + invoker.output_jar_path, + ] + args = [ + "instrument_jar", + "--input-path", + rebase_path(invoker.input_jar_path, root_build_dir), + "--output-path", + rebase_path(invoker.output_jar_path, root_build_dir), + "--depfile", + rebase_path(depfile, root_build_dir), + "--coverage-file", + rebase_path(_coverage_file, root_build_dir), + "--sources-list-file", + rebase_path(_source_dirs_listing_file, root_build_dir), + "--src-root", + rebase_path("//", root_build_dir), + "--emma-jar", + rebase_path(_emma_jar, root_build_dir), + ] + _rebased_java_sources_file = + rebase_path(invoker.java_sources_file, root_build_dir) + args += [ "--java-sources-file=$_rebased_java_sources_file" ] + + if (emma_filter != "") { + args += [ + "--filter-string", + emma_filter, + ] + } + } + } + + # Creates an unsigned .apk. + # + # Variables + # assets_build_config: Path to android_apk .build_config containing merged + # asset information. + # deps: Specifies the dependencies of this target. + # dex_path: Path to classes.dex file to include (optional). + # resource_packaged_apk_path: Path to .ap_ to use. + # output_apk_path: Output path for the generated .apk. + # native_lib_placeholders: List of placeholder filenames to add to the apk + # (optional). + # native_libs: List of native libraries. + # native_libs_filearg: @FileArg() of additionaly native libraries. + # write_asset_list: Adds an extra file to the assets, which contains a list of + # all other asset files. + template("package_apk") { + action(target_name) { + forward_variables_from(invoker, + [ + "deps", + "public_deps", + "testonly", + ]) + _native_lib_placeholders = [] + if (defined(invoker.native_lib_placeholders)) { + _native_lib_placeholders = invoker.native_lib_placeholders + } + + script = "//build/android/gyp/apkbuilder.py" + depfile = "$target_gen_dir/$target_name.d" + data_deps = [ + "//tools/android/md5sum", + ] # Used when deploying APKs + + inputs = invoker.native_libs + [ invoker.resource_packaged_apk_path ] + if (defined(invoker.dex_path)) { + inputs += [ invoker.dex_path ] + } + + outputs = [ + invoker.output_apk_path, + ] + + _rebased_resource_packaged_apk_path = + rebase_path(invoker.resource_packaged_apk_path, root_build_dir) + _rebased_packaged_apk_path = + rebase_path(invoker.output_apk_path, root_build_dir) + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--resource-apk=$_rebased_resource_packaged_apk_path", + "--output-apk=$_rebased_packaged_apk_path", + ] + if (defined(invoker.assets_build_config)) { + inputs += [ invoker.assets_build_config ] + _rebased_build_config = + rebase_path(invoker.assets_build_config, root_build_dir) + args += [ + "--assets=@FileArg($_rebased_build_config:assets)", + "--uncompressed-assets=@FileArg($_rebased_build_config:uncompressed_assets)", + ] + } + if (defined(invoker.write_asset_list) && invoker.write_asset_list) { + args += [ "--write-asset-list" ] + } + if (defined(invoker.dex_path)) { + _rebased_dex_path = rebase_path(invoker.dex_path, root_build_dir) + args += [ "--dex-file=$_rebased_dex_path" ] + } + if (invoker.native_libs != [] || defined(invoker.native_libs_filearg) || + _native_lib_placeholders != []) { + args += [ "--android-abi=$android_app_abi" ] + } + if (invoker.native_libs != []) { + _rebased_native_libs = rebase_path(invoker.native_libs, root_build_dir) + args += [ "--native-libs=$_rebased_native_libs" ] + } + if (defined(invoker.native_libs_filearg)) { + args += [ "--native-libs=${invoker.native_libs_filearg}" ] + } + if (_native_lib_placeholders != []) { + args += [ "--native-lib-placeholders=$_native_lib_placeholders" ] + } + + # TODO (michaelbai): Remove the secondary_native_libs variable. + if (defined(invoker.secondary_abi_native_libs_filearg)) { + assert(defined(android_app_secondary_abi)) + args += [ + "--secondary-native-libs=${invoker.secondary_abi_native_libs_filearg}", + "--secondary-android-abi=$android_app_secondary_abi", + ] + } else if (defined(invoker.secondary_native_libs) && + invoker.secondary_native_libs != []) { + assert(defined(android_app_secondary_abi)) + inputs += invoker.secondary_native_libs + _secondary_native_libs = rebase_path(invoker.secondary_native_libs) + args += [ + "--secondary-native-libs=$_secondary_native_libs", + "--secondary-android-abi=$android_app_secondary_abi", + ] + } + + if (defined(invoker.emma_instrument) && invoker.emma_instrument) { + _emma_device_jar = "$android_sdk_root/tools/lib/emma_device.jar" + _rebased_emma_device_jar = rebase_path(_emma_device_jar, root_build_dir) + args += [ "--emma-device-jar=$_rebased_emma_device_jar" ] + } + + if (defined(invoker.uncompress_shared_libraries) && + invoker.uncompress_shared_libraries) { + args += [ "--uncompress-shared-libraries" ] + } + } + } + + # Signs & zipaligns an apk. + # + # Variables + # input_apk_path: Path of the .apk to be finalized. + # output_apk_path: Output path for the generated .apk. + # keystore_path: Path to keystore to use for signing. + # keystore_name: Key alias to use. + # keystore_password: Keystore password. + # rezip_apk: Whether to add crazy-linker alignment. + template("finalize_apk") { + action(target_name) { + deps = [] + script = "//build/android/gyp/finalize_apk.py" + depfile = "$target_gen_dir/$target_name.d" + forward_variables_from(invoker, + [ + "deps", + "data_deps", + "public_deps", + "testonly", + ]) + + sources = [ + invoker.input_apk_path, + ] + inputs = [ + invoker.keystore_path, + ] + outputs = [ + invoker.output_apk_path, + ] + data = [ + invoker.output_apk_path, + ] + + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--zipalign-path", + rebase_path(zipalign_path, root_build_dir), + "--unsigned-apk-path", + rebase_path(invoker.input_apk_path, root_build_dir), + "--final-apk-path", + rebase_path(invoker.output_apk_path, root_build_dir), + "--key-path", + rebase_path(invoker.keystore_path, root_build_dir), + "--key-name", + invoker.keystore_name, + "--key-passwd", + invoker.keystore_password, + ] + if (defined(invoker.rezip_apk) && invoker.rezip_apk) { + deps += [ "//build/android/rezip" ] + _rezip_jar_path = "$root_build_dir/lib.java/rezip_apk.jar" + args += [ + "--load-library-from-zip=1", + "--rezip-apk-jar-path", + rebase_path(_rezip_jar_path, root_build_dir), + ] + } + + if (defined(invoker.page_align_shared_libraries) && + invoker.page_align_shared_libraries) { + args += [ "--page-align-shared-libraries" ] + } + } + } + + # Packages resources, assets, dex, and native libraries into an apk. Signs and + # zipaligns the apk. + template("create_apk") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + _android_manifest = invoker.android_manifest + _base_path = invoker.base_path + _final_apk_path = invoker.apk_path + _incremental_final_apk_path_helper = + process_file_template( + [ _final_apk_path ], + "{{source_dir}}/{{source_name_part}}_incremental.apk") + _incremental_final_apk_path = _incremental_final_apk_path_helper[0] + + if (defined(invoker.resources_zip)) { + _resources_zip = invoker.resources_zip + assert(_resources_zip != "") # Mark as used. + } + if (defined(invoker.dex_path)) { + _dex_path = invoker.dex_path + } + _load_library_from_apk = invoker.load_library_from_apk + + _deps = [] + if (defined(invoker.deps)) { + _deps = invoker.deps + } + _incremental_deps = [] + if (defined(invoker.incremental_deps)) { + _incremental_deps = invoker.incremental_deps + } + _native_libs = [] + if (defined(invoker.native_libs)) { + _native_libs = invoker.native_libs + } + _native_libs_even_when_incremental = [] + if (defined(invoker.native_libs_even_when_incremental)) { + _native_libs_even_when_incremental = + invoker.native_libs_even_when_incremental + } + + _version_code = invoker.version_code + _version_name = invoker.version_name + assert(_version_code != -1) # Mark as used. + assert(_version_name != "") # Mark as used. + + _base_apk_path = _base_path + ".apk_intermediates" + + _resource_packaged_apk_path = _base_apk_path + ".ap_" + _incremental_resource_packaged_apk_path = + _base_apk_path + "_incremental.ap_" + _packaged_apk_path = _base_apk_path + ".unfinished.apk" + _incremental_packaged_apk_path = + _base_apk_path + "_incremental.unfinished.apk" + _shared_resources = + defined(invoker.shared_resources) && invoker.shared_resources + assert(_shared_resources || true) # Mark as used. + _app_as_shared_lib = + defined(invoker.app_as_shared_lib) && invoker.app_as_shared_lib + assert(_app_as_shared_lib || true) # Mark as used. + assert(!(_shared_resources && _app_as_shared_lib)) + + _keystore_path = invoker.keystore_path + _keystore_name = invoker.keystore_name + _keystore_password = invoker.keystore_password + + _split_densities = [] + if (defined(invoker.create_density_splits) && + invoker.create_density_splits) { + _split_densities = [ + "hdpi", + "xhdpi", + "xxhdpi", + "xxxhdpi", + "tvdpi", + ] + } + + _split_languages = [] + if (defined(invoker.language_splits)) { + _split_languages = invoker.language_splits + } + + template("package_resources_helper") { + action(target_name) { + deps = invoker.deps + + script = "//build/android/gyp/package_resources.py" + depfile = "${target_gen_dir}/${target_name}.d" + inputs = [ + invoker.android_manifest, + ] + if (defined(_resources_zip)) { + inputs += [ _resources_zip ] + } + outputs = [ + invoker.resource_packaged_apk_path, + ] + + if (defined(invoker.android_aapt_path)) { + _android_aapt_path = invoker.android_aapt_path + } else { + _android_aapt_path = android_default_aapt_path + } + + if (defined(invoker.alternative_android_sdk_jar)) { + _rebased_android_sdk_jar = + rebase_path(invoker.alternative_android_sdk_jar) + } else { + _rebased_android_sdk_jar = rebased_android_sdk_jar + } + + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--android-sdk-jar", + _rebased_android_sdk_jar, + "--aapt-path", + _android_aapt_path, + "--configuration-name=$android_configuration_name", + "--android-manifest", + rebase_path(invoker.android_manifest, root_build_dir), + "--version-code", + _version_code, + "--version-name", + _version_name, + "--apk-path", + rebase_path(invoker.resource_packaged_apk_path, root_build_dir), + ] + + if (defined(_resources_zip)) { + args += [ + "--resource-zips", + rebase_path(_resources_zip, root_build_dir), + ] + } + if (_shared_resources) { + args += [ "--shared-resources" ] + } + if (_app_as_shared_lib) { + args += [ "--app-as-shared-lib" ] + } + if (_split_densities != []) { + args += [ "--create-density-splits" ] + foreach(_density, _split_densities) { + outputs += [ "${invoker.resource_packaged_apk_path}_${_density}" ] + } + } + if (_split_languages != []) { + args += [ "--language-splits=$_split_languages" ] + foreach(_language, _split_languages) { + outputs += [ "${invoker.resource_packaged_apk_path}_${_language}" ] + } + } + if (defined(invoker.extensions_to_not_compress)) { + args += [ + "--no-compress", + invoker.extensions_to_not_compress, + ] + } + } + } + + _package_resources_target_name = "${target_name}__package_resources" + package_resources_helper(_package_resources_target_name) { + forward_variables_from(invoker, + [ + "alternative_android_sdk_jar", + "android_aapt_path", + "extensions_to_not_compress", + ]) + deps = _deps + android_manifest = _android_manifest + resource_packaged_apk_path = _resource_packaged_apk_path + } + + _generate_incremental_manifest_target_name = + "${target_name}_incremental_generate_manifest" + _incremental_android_manifest = + get_label_info(_generate_incremental_manifest_target_name, + "target_gen_dir") + "/AndroidManifest.xml" + action(_generate_incremental_manifest_target_name) { + deps = _incremental_deps + script = + "//build/android/incremental_install/generate_android_manifest.py" + depfile = "${target_gen_dir}/${target_name}.d" + inputs = [ + _android_manifest, + ] + outputs = [ + _incremental_android_manifest, + ] + + _rebased_src_manifest = rebase_path(_android_manifest, root_build_dir) + _rebased_incremental_manifest = + rebase_path(_incremental_android_manifest, root_build_dir) + _rebased_depfile = rebase_path(depfile, root_build_dir) + args = [ + "--src-manifest=$_rebased_src_manifest", + "--out-manifest=$_rebased_incremental_manifest", + "--depfile=$_rebased_depfile", + ] + if (disable_incremental_isolated_processes) { + args += [ "--disable-isolated-processes" ] + } + } + + _incremental_package_resources_target_name = + "${target_name}_incremental__package_resources" + + # TODO(agrieve): See if we can speed up this step by swapping the manifest + # from the result of the main package_resources step. + package_resources_helper(_incremental_package_resources_target_name) { + forward_variables_from(invoker, + [ + "alternative_android_sdk_jar", + "android_aapt_path", + "extensions_to_not_compress", + ]) + deps = + _incremental_deps + [ ":$_generate_incremental_manifest_target_name" ] + android_manifest = _incremental_android_manifest + resource_packaged_apk_path = _incremental_resource_packaged_apk_path + } + + package_target = "${target_name}__package" + package_apk(package_target) { + forward_variables_from(invoker, + [ + "assets_build_config", + "emma_instrument", + "native_lib_placeholders", + "native_libs_filearg", + "secondary_abi_native_libs_filearg", + "secondary_native_libs", + "uncompress_shared_libraries", + "write_asset_list", + ]) + deps = _deps + [ ":${_package_resources_target_name}" ] + native_libs = _native_libs + _native_libs_even_when_incremental + + if (defined(_dex_path)) { + dex_path = _dex_path + } + + output_apk_path = _packaged_apk_path + resource_packaged_apk_path = _resource_packaged_apk_path + } + + _incremental_package_target = "${target_name}_incremental__package" + package_apk(_incremental_package_target) { + forward_variables_from(invoker, + [ + "assets_build_config", + "emma_instrument", + "secondary_native_libs", + "uncompress_shared_libraries", + ]) + _dex_target = "//build/android/incremental_install:bootstrap_java__dex" + deps = _incremental_deps + [ + ":${_incremental_package_resources_target_name}", + _dex_target, + ] + + if (defined(_dex_path)) { + dex_path = + get_label_info(_dex_target, "target_gen_dir") + "/bootstrap.dex" + } + + native_libs = _native_libs_even_when_incremental + + # http://crbug.com/384638 + _has_native_libs = + defined(invoker.native_libs_filearg) || _native_libs != [] + if (_has_native_libs && _native_libs_even_when_incremental == []) { + native_lib_placeholders = [ "libfix.crbug.384638.so" ] + } + + output_apk_path = _incremental_packaged_apk_path + resource_packaged_apk_path = _incremental_resource_packaged_apk_path + } + + _finalize_apk_rule_name = "${target_name}__finalize" + finalize_apk(_finalize_apk_rule_name) { + forward_variables_from(invoker, [ "page_align_shared_libraries" ]) + + input_apk_path = _packaged_apk_path + output_apk_path = _final_apk_path + keystore_path = _keystore_path + keystore_name = _keystore_name + keystore_password = _keystore_password + rezip_apk = _load_library_from_apk + + public_deps = [ + # Generator of the _packaged_apk_path this target takes as input. + ":$package_target", + ] + } + + _incremental_finalize_apk_rule_name = "${target_name}_incremental__finalize" + finalize_apk(_incremental_finalize_apk_rule_name) { + input_apk_path = _incremental_packaged_apk_path + output_apk_path = _incremental_final_apk_path + keystore_path = _keystore_path + keystore_name = _keystore_name + keystore_password = _keystore_password + + public_deps = [ + ":$_incremental_package_target", + ] + } + + _split_deps = [] + + template("finalize_split") { + finalize_apk(target_name) { + _config = invoker.split_config + _type = invoker.split_type + input_apk_path = "${_resource_packaged_apk_path}_${_config}" + _output_paths = process_file_template( + [ _final_apk_path ], + "{{source_dir}}/{{source_name_part}}-${_type}-${_config}.apk") + output_apk_path = _output_paths[0] + keystore_path = _keystore_path + keystore_name = _keystore_name + keystore_password = _keystore_password + deps = [ + ":${_package_resources_target_name}", + ] + } + } + + foreach(_split, _split_densities) { + _split_rule = "${target_name}__finalize_${_split}_split" + finalize_split(_split_rule) { + split_type = "density" + split_config = _split + } + _split_deps += [ ":$_split_rule" ] + } + foreach(_split, _split_languages) { + _split_rule = "${target_name}__finalize_${_split}_split" + finalize_split(_split_rule) { + split_type = "lang" + split_config = _split + } + _split_deps += [ ":$_split_rule" ] + } + + group(target_name) { + public_deps = [ ":${_finalize_apk_rule_name}" ] + _split_deps + } + group("${target_name}_incremental") { + public_deps = [ ":${_incremental_finalize_apk_rule_name}" ] + _split_deps + } + } + + template("java_prebuilt_impl") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + _supports_android = + defined(invoker.supports_android) && invoker.supports_android + + assert(defined(invoker.jar_path)) + if (defined(invoker.output_name)) { + _output_name = invoker.output_name + } else { + _output_name = get_path_info(invoker.jar_path, "name") + } + _base_path = "${target_gen_dir}/$target_name" + + # Jar files can be needed at runtime (by Robolectric tests or java binaries), + # so do not put them under gen/. + _target_dir_name = get_label_info(":$target_name", "dir") + _jar_path = "$root_out_dir/lib.java$_target_dir_name/$_output_name.jar" + _ijar_path = + "$root_out_dir/lib.java$_target_dir_name/$_output_name.interface.jar" + _build_config = _base_path + ".build_config" + + if (_supports_android) { + _dex_path = _base_path + ".dex.jar" + } + _deps = [] + if (defined(invoker.deps)) { + _deps = invoker.deps + } + _jar_deps = [] + if (defined(invoker.jar_dep)) { + _jar_deps = [ invoker.jar_dep ] + } + + _template_name = target_name + + _build_config_target_name = "${_template_name}__build_config" + _process_jar_target_name = "${_template_name}__process_jar" + _ijar_target_name = "${_template_name}__ijar" + if (_supports_android) { + _dex_target_name = "${_template_name}__dex" + } + + write_build_config(_build_config_target_name) { + type = "java_prebuilt" + is_prebuilt_binary = defined(invoker.main_class) + forward_variables_from(invoker, + [ + "input_jars_paths", + "proguard_configs", + ]) + supports_android = _supports_android + requires_android = + defined(invoker.requires_android) && invoker.requires_android + + if (defined(invoker.deps)) { + possible_config_deps = _deps + } + build_config = _build_config + jar_path = _jar_path + if (_supports_android) { + dex_path = _dex_path + } + } + + process_java_prebuilt(_process_jar_target_name) { + forward_variables_from(invoker, + [ + "jar_excluded_patterns", + "proguard_preprocess", + "proguard_preprocess_config", + "strip_resource_classes", + ]) + + visibility = [ + ":$_ijar_target_name", + ":$_template_name", + ] + if (_supports_android) { + visibility += [ ":$_dex_target_name" ] + } + + supports_android = _supports_android + build_config = _build_config + input_jar_path = invoker.jar_path + output_jar_path = _jar_path + + deps = [ ":$_build_config_target_name" ] + _deps + _jar_deps + } + + generate_interface_jar(_ijar_target_name) { + if (!defined(invoker.proguard_preprocess) || + !invoker.proguard_preprocess) { + # Always used the unfiltered .jar to create the interface jar so that + # other targets will resolve filtered classes when depending on + # BuildConfig, NativeLibraries, etc. + input_jar = invoker.jar_path + deps = _deps + _jar_deps + } else { + # However, still apply pre-proguarding, since ignoring that can break + # compiles. + input_jar = _jar_path + deps = [ + ":$_process_jar_target_name", + ] + } + + output_jar = _ijar_path + } + + if (_supports_android) { + dex(_dex_target_name) { + sources = [ + _jar_path, + ] + output = _dex_path + deps = [ ":$_process_jar_target_name" ] + _deps + _jar_deps + } + } + + if (defined(invoker.main_class)) { + _binary_script_target_name = "${_template_name}__java_binary_script" + java_binary_script(_binary_script_target_name) { + forward_variables_from(invoker, + [ + "bootclasspath", + "deps", + "main_class", + "wrapper_script_args", + ]) + if (!defined(deps)) { + deps = [] + } + build_config = _build_config + jar_path = _jar_path + script_name = _template_name + if (defined(invoker.wrapper_script_name)) { + script_name = invoker.wrapper_script_name + } + deps += [ ":$_build_config_target_name" ] + } + } + + group(target_name) { + forward_variables_from(invoker, [ "data_deps" ]) + public_deps = [ + ":$_ijar_target_name", + ":$_process_jar_target_name", + ] + if (_supports_android) { + public_deps += [ ":$_dex_target_name" ] + } + if (defined(invoker.main_class)) { + # Some targets use the generated script while building, so make it a dep + # rather than a data_dep. + public_deps += [ ":$_binary_script_target_name" ] + } + } + } + + # Compiles and jars a set of java files. + # + # Outputs: + # $jar_path.jar + # $jar_path.interface.jar + # + # Variables + # java_files: List of .java files to compile (same as exists in java_sources_file) + # java_sources_file: Path to file containing list of files to compile. + # chromium_code: If true, enable extra warnings. + # srcjar_deps: List of srcjar dependencies. The .java files contained in the + # dependencies srcjar outputs will be compiled and added to the output jar. + # jar_path: Use this to explicitly set the output jar path. Defaults to + # "${target_gen_dir}/${target_name}.jar. + template("compile_java") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + assert(defined(invoker.build_config)) + assert(defined(invoker.jar_path)) + + _build_config = invoker.build_config + + _chromium_code = false + if (defined(invoker.chromium_code)) { + _chromium_code = invoker.chromium_code + } + + _supports_android = true + if (defined(invoker.supports_android)) { + _supports_android = invoker.supports_android + } + + _requires_android = + defined(invoker.requires_android) && invoker.requires_android + + _enable_errorprone = use_errorprone_java_compiler + if (!_chromium_code) { + _enable_errorprone = false + } else if (defined(invoker.enable_errorprone)) { + _enable_errorprone = invoker.enable_errorprone + } + + _provider_configurations = [] + if (defined(invoker.provider_configurations)) { + _provider_configurations = invoker.provider_configurations + } + + _processors = [] + _enable_interface_jars_javac = true + if (defined(invoker.processors_javac)) { + _processors = invoker.processors_javac + _enable_interface_jars_javac = _processors == [] + } + + _processor_args = [] + if (defined(invoker.processor_args_javac)) { + _processor_args = invoker.processor_args_javac + } + + _additional_jar_files = [] + if (defined(invoker.additional_jar_files)) { + _additional_jar_files = invoker.additional_jar_files + } + + if (defined(invoker.enable_incremental_javac_override)) { + # Use invoker-specified override. + _enable_incremental_javac = invoker.enable_incremental_javac_override + } else { + # Default to build arg if not overridden. + _enable_incremental_javac = enable_incremental_javac + } + + _manifest_entries = [] + if (defined(invoker.manifest_entries)) { + _manifest_entries = invoker.manifest_entries + } + + _srcjar_deps = [] + if (defined(invoker.srcjar_deps)) { + _srcjar_deps += invoker.srcjar_deps + } + + _java_srcjars = [] + if (defined(invoker.srcjars)) { + _java_srcjars = invoker.srcjars + } + foreach(dep, _srcjar_deps) { + _dep_gen_dir = get_label_info(dep, "target_gen_dir") + _dep_name = get_label_info(dep, "name") + _java_srcjars += [ "$_dep_gen_dir/$_dep_name.srcjar" ] + } + + # Mark srcjar_deps as used. + assert(_srcjar_deps == [] || true) + + _javac_target_name = "${target_name}__javac" + _process_prebuilt_target_name = "${target_name}__process_prebuilt" + _ijar_target_name = "${target_name}__ijar" + _final_target_name = target_name + + _final_jar_path = invoker.jar_path + _javac_jar_path = "$target_gen_dir/$target_name.javac.jar" + _process_prebuilt_jar_path = _final_jar_path + _final_ijar_path = get_path_info(_final_jar_path, "dir") + "/" + + get_path_info(_final_jar_path, "name") + ".interface.jar" + + _emma_instrument = defined(invoker.emma_instrument) && + invoker.emma_instrument && invoker.java_files != [] + if (_emma_instrument) { + _emma_instr_target_name = "${target_name}__emma_instr" + _process_prebuilt_jar_path = + "$target_gen_dir/$target_name.process_prebuilt.jar" + } + + _rebased_build_config = rebase_path(_build_config, root_build_dir) + _rebased_jar_path = rebase_path(_javac_jar_path, root_build_dir) + + action(_javac_target_name) { + script = "//build/android/gyp/javac.py" + depfile = "$target_gen_dir/$target_name.d" + deps = _srcjar_deps + if (defined(invoker.deps)) { + deps += invoker.deps + } + + outputs = [ + _javac_jar_path, + _javac_jar_path + ".md5.stamp", + ] + sources = invoker.java_files + _java_srcjars + inputs = [ + _build_config, + ] + if (invoker.java_files != []) { + inputs += [ invoker.java_sources_file ] + } + + _rebased_java_srcjars = rebase_path(_java_srcjars, root_build_dir) + _rebased_depfile = rebase_path(depfile, root_build_dir) + args = [ + "--depfile=$_rebased_depfile", + "--jar-path=$_rebased_jar_path", + "--java-srcjars=$_rebased_java_srcjars", + "--java-srcjars=@FileArg($_rebased_build_config:javac:srcjars)", + ] + if (_enable_interface_jars_javac) { + args += [ "--classpath=@FileArg($_rebased_build_config:javac:interface_classpath)" ] + } else { + args += + [ "--classpath=@FileArg($_rebased_build_config:javac:classpath)" ] + } + if (_enable_incremental_javac) { + args += [ "--incremental" ] + deps += [ "//third_party/jmake($default_toolchain)" ] + inputs += [ "$root_build_dir/bin/jmake" ] + outputs += [ "${_javac_jar_path}.pdb" ] + } + if (_requires_android) { + if (defined(invoker.alternative_android_sdk_ijar)) { + deps += [ invoker.alternative_android_sdk_ijar_dep ] + _android_sdk_ijar = invoker.alternative_android_sdk_ijar + } else { + deps += [ "//build/android:android_ijar" ] + _android_sdk_ijar = "$root_out_dir/lib.java/android.interface.jar" + } + inputs += [ _android_sdk_ijar ] + _rebased_android_sdk_ijar = + rebase_path(_android_sdk_ijar, root_build_dir) + args += [ "--bootclasspath=$_rebased_android_sdk_ijar" ] + } + if (use_java8) { + args += [ "--java-version=1.8" ] + } else if (_supports_android) { + args += [ "--java-version=1.7" ] + } + foreach(e, _manifest_entries) { + args += [ "--manifest-entry=" + e ] + } + if (_chromium_code) { + args += [ "--chromium-code=1" ] + } + if (_enable_errorprone) { + deps += [ "//third_party/errorprone:chromium_errorprone" ] + args += [ + "--use-errorprone-path", + "bin/chromium_errorprone", + ] + } + foreach(e, _provider_configurations) { + args += [ "--provider-configuration=" + rebase_path(e, root_build_dir) ] + } + foreach(e, _processors) { + args += [ "--processor=" + e ] + } + foreach(e, _processor_args) { + args += [ "--processor-arg=" + e ] + } + foreach(file_tuple, _additional_jar_files) { + # Each element is of length two, [ path_to_file, path_to_put_in_jar ] + inputs += [ file_tuple[0] ] + args += + [ "--additional-jar-file=" + file_tuple[0] + ":" + file_tuple[1] ] + } + if (invoker.java_files != []) { + args += [ "@" + rebase_path(invoker.java_sources_file, root_build_dir) ] + } + } + + process_java_prebuilt(_process_prebuilt_target_name) { + forward_variables_from(invoker, + [ + "jar_excluded_patterns", + "proguard_preprocess", + "proguard_preprocess_config", + ]) + supports_android = _supports_android + build_config = _build_config + input_jar_path = _javac_jar_path + output_jar_path = _process_prebuilt_jar_path + + deps = [ + ":$_javac_target_name", + ] + if (defined(invoker.deps)) { + deps += invoker.deps + } + } + + if (_emma_instrument) { + emma_instr(_emma_instr_target_name) { + forward_variables_from(invoker, + [ + "deps", + "java_files", + "java_sources_file", + ]) + + input_jar_path = _process_prebuilt_jar_path + output_jar_path = _final_jar_path + + if (!defined(deps)) { + deps = [] + } + deps += [ ":$_process_prebuilt_target_name" ] + } + } + + generate_interface_jar(_ijar_target_name) { + if (!defined(invoker.proguard_preprocess) || + !invoker.proguard_preprocess) { + # Always used the unfiltered .jar to create the interface jar so that + # other targets will resolve filtered classes when depending on + # BuildConfig, NativeLibraries, etc. + input_jar = _javac_jar_path + deps = [ + ":$_javac_target_name", + ] + } else { + # However, still apply pre-proguarding, since ignoring that can break + # compiles. + input_jar = _process_prebuilt_jar_path + deps = [ + ":$_process_prebuilt_target_name", + ] + } + output_jar = _final_ijar_path + } + + group(_final_target_name) { + forward_variables_from(invoker, [ "visibility" ]) + public_deps = [ + ":$_ijar_target_name", + ] + if (_emma_instrument) { + public_deps += [ ":$_emma_instr_target_name" ] + } else { + public_deps += [ ":$_process_prebuilt_target_name" ] + } + } + } + + template("java_library_impl") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + _accumulated_deps = [] + if (defined(invoker.deps)) { + _accumulated_deps = invoker.deps + } + + assert(defined(invoker.java_files) || defined(invoker.srcjars) || + defined(invoker.srcjar_deps)) + _base_path = "$target_gen_dir/$target_name" + + if (defined(invoker.output_name)) { + _output_name = invoker.output_name + } else { + _output_name = target_name + } + + # Jar files can be needed at runtime (by Robolectric tests or java binaries), + # so do not put them under gen/. + target_dir_name = get_label_info(":$target_name", "dir") + _jar_path = "$root_out_dir/lib.java$target_dir_name/$_output_name.jar" + if (defined(invoker.jar_path)) { + _jar_path = invoker.jar_path + } + _template_name = target_name + + _final_deps = [] + + _supports_android = + defined(invoker.supports_android) && invoker.supports_android + _requires_android = + defined(invoker.requires_android) && invoker.requires_android + assert(_requires_android || true) # Mark as used. + _android_manifest = "//build/android/AndroidManifest.xml" + if (defined(invoker.android_manifest)) { + _android_manifest = invoker.android_manifest + } + assert(_android_manifest != "") # Mark as used. + + if (defined(invoker.run_findbugs_override)) { + _run_findbugs = invoker.run_findbugs_override + } else { + _run_findbugs = run_findbugs # Default to build arg if not overridden. + } + assert(_run_findbugs || true) # Mark as used. + + # Don't enable coverage, lint, findbugs unless the target has some + # non-generated files. + if (defined(invoker.chromium_code)) { + _chromium_code = invoker.chromium_code + } else { + _chromium_code = defined(invoker.java_files) && invoker.java_files != [] + if (_chromium_code) { + # Make chromium_code = false be the default for targets within + # third_party which contain no chromium-namespaced java files. + set_sources_assignment_filter([ "*\bthird_party\b*" ]) + sources = [ + get_label_info(":$target_name", "dir"), + ] + if (sources == []) { + set_sources_assignment_filter([ "*\bchromium\b*" ]) + sources = invoker.java_files + _chromium_code = invoker.java_files != sources + } + set_sources_assignment_filter([]) + sources = [] + } + } + + _emma_never_instrument = !_chromium_code + if (defined(invoker.emma_never_instrument)) { + _emma_never_instrument = invoker.emma_never_instrument + } + assert(_emma_never_instrument || true) # Mark as used + _emma_instrument = emma_coverage && !_emma_never_instrument + + if (_supports_android) { + _dex_path = _base_path + ".dex.jar" + if (defined(invoker.dex_path)) { + _dex_path = invoker.dex_path + } + } + + _java_files = [] + if (defined(invoker.java_files)) { + _java_files += invoker.java_files + } + if (_java_files != []) { + _java_sources_file = "$_base_path.sources" + write_file(_java_sources_file, rebase_path(_java_files, root_build_dir)) + } + + # Define build_config_deps which will be a list of targets required to + # build the _build_config. + if (defined(invoker.override_build_config)) { + _build_config = invoker.override_build_config + } else { + _build_config = _base_path + ".build_config" + build_config_target_name = "${_template_name}__build_config" + + write_build_config(build_config_target_name) { + forward_variables_from(invoker, + [ + "gradle_treat_as_prebuilt", + "input_jars_paths", + "main_class", + "proguard_configs", + ]) + if (defined(invoker.is_java_binary) && invoker.is_java_binary) { + type = "java_binary" + } else { + type = "java_library" + } + if (defined(invoker.deps)) { + possible_config_deps = invoker.deps + } + supports_android = _supports_android + requires_android = _requires_android + bypass_platform_checks = defined(invoker.bypass_platform_checks) && + invoker.bypass_platform_checks + + build_config = _build_config + jar_path = _jar_path + if (_supports_android) { + dex_path = _dex_path + } + if (_java_files != []) { + java_sources_file = _java_sources_file + } + + if (defined(invoker.srcjar_deps)) { + bundled_srcjars = [] + foreach(d, invoker.srcjar_deps) { + _dep_gen_dir = get_label_info(d, "target_gen_dir") + _dep_name = get_label_info(d, "name") + bundled_srcjars += [ "$_dep_gen_dir/$_dep_name.srcjar" ] + } + } + } + _accumulated_deps += [ ":$build_config_target_name" ] + } + + _srcjar_deps = [] + if (defined(invoker.srcjar_deps)) { + _srcjar_deps = invoker.srcjar_deps + } + + _srcjars = [] + if (defined(invoker.srcjars)) { + _srcjars = invoker.srcjars + } + + assert(_java_files != [] || _srcjar_deps != [] || _srcjars != []) + + _compile_java_target = "${_template_name}__compile_java" + _final_deps += [ ":$_compile_java_target" ] + compile_java(_compile_java_target) { + forward_variables_from(invoker, + [ + "additional_jar_files", + "alternative_android_sdk_ijar", + "alternative_android_sdk_ijar_dep", + "dist_jar_path", + "enable_errorprone", + "enable_incremental_javac_override", + "jar_excluded_patterns", + "manifest_entries", + "processors_javac", + "processor_args_javac", + "proguard_preprocess_config", + "proguard_preprocess", + "provider_configurations", + ]) + jar_path = _jar_path + build_config = _build_config + java_files = _java_files + if (_java_files != []) { + java_sources_file = _java_sources_file + } + srcjar_deps = _srcjar_deps + srcjars = _srcjars + chromium_code = _chromium_code + supports_android = _supports_android + requires_android = _requires_android + emma_instrument = _emma_instrument + deps = _accumulated_deps + } + _accumulated_deps += [ ":$_compile_java_target" ] + assert(_accumulated_deps != []) # Mark used. + + if (defined(invoker.main_class)) { + # Targets might use the generated script while building, so make it a dep + # rather than a data_dep. + _final_deps += [ ":${_template_name}__java_binary_script" ] + java_binary_script("${_template_name}__java_binary_script") { + forward_variables_from(invoker, + [ + "bootclasspath", + "main_class", + "wrapper_script_args", + ]) + build_config = _build_config + jar_path = _jar_path + script_name = _template_name + if (defined(invoker.wrapper_script_name)) { + script_name = invoker.wrapper_script_name + } + deps = _accumulated_deps + } + } + + _has_lint_target = false + if (_supports_android) { + if (_chromium_code) { + _has_lint_target = true + android_lint("${_template_name}__lint") { + android_manifest = _android_manifest + build_config = _build_config + jar_path = _jar_path + java_files = _java_files + if (_java_files != []) { + java_sources_file = _java_sources_file + } + deps = _accumulated_deps + } + + if (_run_findbugs) { + findbugs("${_template_name}__findbugs") { + build_config = _build_config + jar_path = _jar_path + deps = _accumulated_deps + } + } + + # Use an intermediate group() rather as the data_deps target in order to + # avoid lint artifacts showing up as runtime_deps (while still having lint + # run in parallel to other targets). + group("${_template_name}__analysis") { + public_deps = [ + ":${_template_name}__lint", + ] + if (_run_findbugs) { + public_deps += [ ":${_template_name}__findbugs" ] + } + } + } + + _final_deps += [ ":${_template_name}__dex" ] + dex("${_template_name}__dex") { + sources = [ + _jar_path, + ] + output = _dex_path + deps = [ + ":$_compile_java_target", + ] + } + } + + group(target_name) { + forward_variables_from(invoker, + [ + "data", + "data_deps", + "visibility", + ]) + if (!defined(data_deps)) { + data_deps = [] + } + public_deps = _final_deps + if (_has_lint_target) { + data_deps += [ ":${_template_name}__analysis" ] + } + } + } + + # Runs process_resources.py + template("process_resources") { + set_sources_assignment_filter([]) + forward_variables_from(invoker, [ "testonly" ]) + + zip_path = invoker.zip_path + srcjar_path = invoker.srcjar_path + r_text_path = invoker.r_text_path + build_config = invoker.build_config + android_manifest = invoker.android_manifest + + non_constant_id = true + if (defined(invoker.generate_constant_ids) && + invoker.generate_constant_ids) { + non_constant_id = false + } + + action(target_name) { + forward_variables_from(invoker, + [ + "deps", + "visibility", + ]) + script = "//build/android/gyp/process_resources.py" + + depfile = "$target_gen_dir/$target_name.d" + outputs = [ + zip_path, + srcjar_path, + r_text_path, + ] + + _all_resource_dirs = [] + sources = [] + + if (defined(invoker.resource_dirs)) { + _all_resource_dirs += invoker.resource_dirs + + # Speed up "gn gen" by short-circuiting the empty directory. + if (invoker.resource_dirs != [ "//build/android/ant/empty/res" ] && + invoker.resource_dirs != []) { + _sources_build_rel = + exec_script("//build/android/gyp/find.py", + rebase_path(invoker.resource_dirs, root_build_dir), + "list lines") + sources += rebase_path(_sources_build_rel, ".", root_build_dir) + } + } + + if (defined(invoker.generated_resource_dirs)) { + assert(defined(invoker.generated_resource_files)) + _all_resource_dirs += invoker.generated_resource_dirs + sources += invoker.generated_resource_files + } + + inputs = [ + build_config, + android_manifest, + ] + + _rebased_all_resource_dirs = + rebase_path(_all_resource_dirs, root_build_dir) + rebase_build_config = rebase_path(build_config, root_build_dir) + + if (defined(invoker.android_aapt_path)) { + _android_aapt_path = invoker.android_aapt_path + } else { + _android_aapt_path = android_default_aapt_path + } + + if (defined(invoker.alternative_android_sdk_jar)) { + _rebased_android_sdk_jar = + rebase_path(invoker.alternative_android_sdk_jar) + } else { + _rebased_android_sdk_jar = rebased_android_sdk_jar + } + + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--android-sdk-jar", + _rebased_android_sdk_jar, + "--aapt-path", + _android_aapt_path, + "--android-manifest", + rebase_path(android_manifest, root_build_dir), + "--resource-dirs=$_rebased_all_resource_dirs", + "--srcjar-out", + rebase_path(srcjar_path, root_build_dir), + "--resource-zip-out", + rebase_path(zip_path, root_build_dir), + "--r-text-out", + rebase_path(r_text_path, root_build_dir), + "--dependencies-res-zips=@FileArg($rebase_build_config:resources:dependency_zips)", + "--extra-res-packages=@FileArg($rebase_build_config:resources:extra_package_names)", + "--extra-r-text-files=@FileArg($rebase_build_config:resources:extra_r_text_files)", + ] + + if (non_constant_id) { + args += [ "--non-constant-id" ] + } + + if (defined(invoker.custom_package)) { + args += [ + "--custom-package", + invoker.custom_package, + ] + } + + if (defined(invoker.v14_skip) && invoker.v14_skip) { + args += [ "--v14-skip" ] + } + + if (defined(invoker.shared_resources) && invoker.shared_resources) { + args += [ "--shared-resources" ] + } + + if (defined(invoker.app_as_shared_lib) && invoker.app_as_shared_lib) { + args += [ "--app-as-shared-lib" ] + } + + if (defined(invoker.include_all_resources) && + invoker.include_all_resources) { + args += [ "--include-all-resources" ] + } + + if (defined(invoker.all_resources_zip_path)) { + all_resources_zip = invoker.all_resources_zip_path + outputs += [ all_resources_zip ] + args += [ + "--all-resources-zip-out", + rebase_path(all_resources_zip, root_build_dir), + ] + } + + if (defined(invoker.proguard_file)) { + outputs += [ invoker.proguard_file ] + args += [ + "--proguard-file", + rebase_path(invoker.proguard_file, root_build_dir), + ] + } + + if (defined(invoker.args)) { + args += invoker.args + } + } + } + + # Produces a single .dex.jar out of a set of Java dependencies. + template("deps_dex") { + set_sources_assignment_filter([]) + build_config = "$target_gen_dir/${target_name}.build_config" + build_config_target_name = "${target_name}__build_config" + + write_build_config(build_config_target_name) { + forward_variables_from(invoker, [ "dex_path" ]) + if (defined(invoker.deps)) { + possible_config_deps = invoker.deps + } + type = "deps_dex" + build_config = build_config + } + + rebased_build_config = rebase_path(build_config, root_build_dir) + dex(target_name) { + inputs = [ + build_config, + ] + output = invoker.dex_path + dex_arg_key = "${rebased_build_config}:final_dex:dependency_dex_files" + args = [ "--inputs=@FileArg($dex_arg_key)" ] + if (defined(invoker.excluded_jars)) { + excluded_jars = rebase_path(invoker.excluded_jars, root_build_dir) + args += [ "--excluded-paths=${excluded_jars}" ] + } + deps = [ + ":$build_config_target_name", + ] + } + } + + # Creates an AndroidManifest.xml for an APK split. + template("generate_split_manifest") { + assert(defined(invoker.main_manifest)) + assert(defined(invoker.out_manifest)) + assert(defined(invoker.split_name)) + + action(target_name) { + forward_variables_from(invoker, + [ + "deps", + "testonly", + ]) + depfile = "$target_gen_dir/$target_name.d" + args = [ + "--main-manifest", + rebase_path(invoker.main_manifest, root_build_dir), + "--out-manifest", + rebase_path(invoker.out_manifest, root_build_dir), + "--split", + invoker.split_name, + ] + if (defined(invoker.version_code)) { + args += [ + "--version-code", + invoker.version_code, + ] + } + if (defined(invoker.version_name)) { + args += [ + "--version-name", + invoker.version_name, + ] + } + if (defined(invoker.has_code)) { + args += [ + "--has-code", + invoker.has_code, + ] + } + args += [ + "--depfile", + rebase_path(depfile, root_build_dir), + ] + + script = "//build/android/gyp/generate_split_manifest.py" + outputs = [ + invoker.out_manifest, + ] + inputs = [ + invoker.main_manifest, + ] + } + } + + template("pack_relocation_section") { + assert(defined(invoker.file_list_json)) + assert(defined(invoker.libraries_filearg)) + action(target_name) { + forward_variables_from(invoker, + [ + "deps", + "public_deps", + "inputs", + "testonly", + ]) + script = "//build/android/gyp/pack_relocations.py" + depfile = "$target_gen_dir/$target_name.d" + _packed_libraries_dir = "$target_gen_dir/$target_name/packed-libs" + outputs = [ + invoker.file_list_json, + ] + deps += [ relocation_packer_target ] + + args = [ + "--depfile", + rebase_path(depfile, root_build_dir), + "--enable-packing=1", + "--android-pack-relocations", + rebase_path(relocation_packer_exe, root_build_dir), + "--stripped-libraries-dir", + rebase_path(root_build_dir, root_build_dir), + "--packed-libraries-dir", + rebase_path(_packed_libraries_dir, root_build_dir), + "--libraries=${invoker.libraries_filearg}", + "--filelistjson", + rebase_path(invoker.file_list_json, root_build_dir), + ] + } + } +} diff --git a/samples/GN/ios-rules.gni b/samples/GN/ios-rules.gni new file mode 100644 index 00000000..d6413633 --- /dev/null +++ b/samples/GN/ios-rules.gni @@ -0,0 +1,1422 @@ +# Copyright 2015 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("//build/config/ios/ios_sdk.gni") +import("//build/config/mac/base_rules.gni") +import("//build/config/mac/symbols.gni") +import("//build/toolchain/toolchain.gni") + +# Invokes lipo on multiple arch-specific binaries to create a fat binary. +# +# Arguments +# +# arch_binary_target +# name of the target generating the arch-specific binaries, they must +# be named $target_out_dir/$toolchain_cpu/$arch_binary_output. +# +# arch_binary_output +# (optional, defaults to the name of $arch_binary_target) base name of +# the arch-specific binary generated by arch_binary_target. +# +# output_name +# (optional, defaults to $target_name) base name of the target output, +# the full path will be $target_out_dir/$output_name. +# +# configs +# (optional) a list of configurations, this is used to check whether +# the binary should be stripped, when "enable_stripping" is true. +# +template("lipo_binary") { + assert(defined(invoker.arch_binary_target), + "arch_binary_target must be defined for $target_name") + + _target_name = target_name + _output_name = target_name + if (defined(invoker.output_name)) { + _output_name = invoker.output_name + } + + _all_target_cpu = [ current_cpu ] + additional_target_cpus + _all_toolchains = [ current_toolchain ] + additional_toolchains + + _arch_binary_target = invoker.arch_binary_target + _arch_binary_output = get_label_info(_arch_binary_target, "name") + if (defined(invoker.arch_binary_output)) { + _arch_binary_output = invoker.arch_binary_output + } + + action(_target_name) { + forward_variables_from(invoker, + "*", + [ + "arch_binary_output", + "arch_binary_target", + "configs", + "output_name", + ]) + + script = "//build/toolchain/mac/linker_driver.py" + + outputs = [ + "$target_out_dir/$_output_name", + ] + + deps = [] + _index = 0 + inputs = [] + foreach(_cpu, _all_target_cpu) { + _toolchain = _all_toolchains[_index] + _index = _index + 1 + + inputs += + [ get_label_info("$_arch_binary_target($_toolchain)", + "target_out_dir") + "/$_cpu/$_arch_binary_output" ] + + deps += [ "$_arch_binary_target($_toolchain)" ] + } + + args = [] + if (!use_system_xcode) { + args += [ + "--developer_dir", + hermetic_xcode_path, + ] + } + args += [ + "xcrun", + "lipo", + "-create", + "-output", + rebase_path("$target_out_dir/$_output_name", root_build_dir), + ] + rebase_path(inputs, root_build_dir) + + if (enable_dsyms) { + _dsyms_output_dir = "$root_out_dir/$_output_name.dSYM" + outputs += [ + "$_dsyms_output_dir/", + "$_dsyms_output_dir/Contents/Info.plist", + "$_dsyms_output_dir/Contents/Resources/DWARF/$_output_name", + ] + args += [ "-Wcrl,dsym," + rebase_path("$root_out_dir/.", root_build_dir) ] + } + + if (enable_stripping) { + # Check whether //build/config/mac:strip_all has been removed from the + # configs variables (as this is how stripping is disabled for a single + # target). + _strip_all_in_config = false + if (defined(invoker.configs)) { + foreach(_config, invoker.configs) { + if (_config == "//build/config/mac:strip_all") { + _strip_all_in_config = true + } + } + } + + if (_strip_all_in_config) { + args += [ "-Wcrl,strip,-x,-S" ] + if (save_unstripped_output) { + outputs += [ "$root_out_dir/$_output_name.unstripped" ] + args += [ "-Wcrl,unstripped," + + rebase_path("$root_out_dir/.", root_build_dir) ] + } + } + } + } +} + +# Wrapper around create_bundle taking care of code signature settings. +# +# Arguments +# +# product_type +# string, product type for the generated Xcode project. +# +# bundle_deps +# (optional) list of additional dependencies +# +# bundle_deps_filter +# (optional) list of dependencies to filter (for more information +# see "gn help bundle_deps_filter") +# +# bundle_extension +# string, extension of the bundle, used to generate bundle name. +# +# bundle_binary_target +# string, label of the target generating the bundle main binary. +# +# bundle_binary_output +# (optional) string, base name of the binary generated by the +# bundle_binary_target target, defaults to the target name. +# +# extra_system_frameworks +# (optional) list of system framework to copy to the bundle. +# +# enable_code_signing +# (optional) boolean, control whether code signing is enabled or not, +# default to ios_enable_code_signing if not defined. +# +# entitlements_path: +# (optional) path to the template to use to generate the application +# entitlements by performing variable substitutions, defaults to +# //build/config/ios/entitlements.plist. +# +# entitlements_target: +# (optional) label of the target generating the application +# entitlements (must generate a single file as output); cannot be +# defined if entitlements_path is set. +# +template("create_signed_bundle") { + assert(defined(invoker.product_type), + "product_type must be defined for $target_name") + assert(defined(invoker.bundle_extension), + "bundle_extension must be defined for $target_name") + assert(defined(invoker.bundle_binary_target), + "bundle_binary_target must be defined for $target_name") + + _target_name = target_name + _output_name = target_name + if (defined(invoker.output_name)) { + _output_name = invoker.output_name + } + + _bundle_binary_target = invoker.bundle_binary_target + _bundle_binary_output = get_label_info(_bundle_binary_target, "name") + if (defined(invoker.bundle_binary_output)) { + _bundle_binary_output = invoker.bundle_binary_output + } + + _bundle_extension = invoker.bundle_extension + _bundle_root_dir = "$root_out_dir/$_output_name$_bundle_extension" + + if (!defined(invoker.entitlements_target)) { + _entitlements_path = "//build/config/ios/entitlements.plist" + if (defined(invoker.entitlements_path)) { + _entitlements_path = invoker.entitlements_path + } + } else { + assert(!defined(invoker.entitlements_path), + "Cannot define both entitlements_path and entitlements_target " + + "for $target_name") + + _entitlements_target_outputs = + get_target_outputs(invoker.entitlements_target) + _entitlements_path = _entitlements_target_outputs[0] + } + + _enable_code_signing = ios_enable_code_signing + if (defined(invoker.enable_code_signing)) { + _enable_code_signing = invoker.enable_code_signing + } + + create_bundle(_target_name) { + forward_variables_from(invoker, + [ + "bundle_deps_filter", + "data_deps", + "deps", + "product_type", + "public_configs", + "public_deps", + "testonly", + "visibility", + ]) + + bundle_root_dir = _bundle_root_dir + bundle_resources_dir = _bundle_root_dir + bundle_executable_dir = _bundle_root_dir + bundle_plugins_dir = "$_bundle_root_dir/PlugIns" + + if (!defined(public_deps)) { + public_deps = [] + } + public_deps += [ _bundle_binary_target ] + + if (defined(invoker.bundle_deps)) { + if (!defined(deps)) { + deps = [] + } + deps += invoker.bundle_deps + } + if (defined(invoker.entitlements_target)) { + if (!defined(deps)) { + deps = [] + } + deps += [ invoker.entitlements_target ] + } + + code_signing_script = "//build/config/ios/codesign.py" + code_signing_sources = [ + _entitlements_path, + get_label_info(_bundle_binary_target, "target_out_dir") + + "/$_bundle_binary_output", + ] + code_signing_outputs = [ "$_bundle_root_dir/$_output_name" ] + if (_enable_code_signing) { + code_signing_outputs += + [ "$_bundle_root_dir/_CodeSignature/CodeResources" ] + } + if (ios_code_signing_identity != "" && !use_ios_simulator) { + code_signing_outputs += [ "$_bundle_root_dir/embedded.mobileprovision" ] + } + + if (defined(invoker.extra_system_frameworks)) { + foreach(_framework, invoker.extra_system_frameworks) { + code_signing_outputs += [ "$bundle_root_dir/Frameworks/" + + get_path_info(_framework, "file") ] + } + } + + code_signing_args = [] + if (!use_system_xcode) { + code_signing_args += [ + "--developer_dir", + hermetic_xcode_path, + ] + } + code_signing_args += [ + "code-sign-bundle", + "-t=" + ios_sdk_name, + "-i=" + ios_code_signing_identity, + "-e=" + rebase_path(_entitlements_path, root_build_dir), + "-b=" + rebase_path("$target_out_dir/$_output_name", root_build_dir), + rebase_path(bundle_root_dir, root_build_dir), + ] + if (!_enable_code_signing) { + code_signing_args += [ "--disable-code-signature" ] + } + if (defined(invoker.extra_system_frameworks)) { + # All framework in extra_system_frameworks are expected to be + # system framework and the path to be already system absolute + # so do not use rebase_path here. + foreach(_framework, invoker.extra_system_frameworks) { + code_signing_args += [ "-F=" + _framework ] + } + } + } +} + +# Generates Info.plist files for Mac apps and frameworks. +# +# Arguments +# +# info_plist: +# (optional) string, path to the Info.plist file that will be used for +# the bundle. +# +# info_plist_target: +# (optional) string, if the info_plist is generated from an action, +# rather than a regular source file, specify the target name in lieu +# of info_plist. The two arguments are mutually exclusive. +# +# executable_name: +# string, name of the generated target used for the product +# and executable name as specified in the output Info.plist. +# +# extra_substitutions: +# (optional) string array, 'key=value' pairs for extra fields which are +# specified in a source Info.plist template. +template("ios_info_plist") { + assert(defined(invoker.info_plist) != defined(invoker.info_plist_target), + "Only one of info_plist or info_plist_target may be specified in " + + target_name) + + if (defined(invoker.info_plist)) { + _info_plist = invoker.info_plist + } else { + _info_plist_target_output = get_target_outputs(invoker.info_plist_target) + _info_plist = _info_plist_target_output[0] + } + + info_plist(target_name) { + format = "binary1" + extra_substitutions = [] + if (defined(invoker.extra_substitutions)) { + extra_substitutions = invoker.extra_substitutions + } + extra_substitutions += [ + "IOS_BUNDLE_ID_PREFIX=$ios_app_bundle_id_prefix", + "IOS_DEPLOYMENT_TARGET=$ios_deployment_target", + "IOS_PLATFORM_BUILD=$ios_platform_build", + "IOS_PLATFORM_NAME=$ios_sdk_name", + "IOS_PLATFORM_VERSION=$ios_sdk_version", + "IOS_SDK_BUILD=$ios_sdk_build", + "IOS_SDK_NAME=$ios_sdk_name$ios_sdk_version", + "IOS_SUPPORTED_PLATFORM=$ios_sdk_platform", + ] + plist_templates = [ + "//build/config/ios/BuildInfo.plist", + _info_plist, + ] + if (defined(invoker.info_plist_target)) { + deps = [ + invoker.info_plist_target, + ] + } + forward_variables_from(invoker, + [ + "executable_name", + "output_name", + "visibility", + ]) + } +} + +# Template to build an application bundle for iOS. +# +# This should be used instead of "executable" built-in target type on iOS. +# As the template forward the generation of the application executable to +# an "executable" target, all arguments supported by "executable" targets +# are also supported by this template. +# +# Arguments +# +# output_name: +# (optional) string, name of the generated application, if omitted, +# defaults to the target_name. +# +# extra_substitutions: +# (optional) list of string in "key=value" format, each value will +# be used as an additional variable substitution rule when generating +# the application Info.plist +# +# info_plist: +# (optional) string, path to the Info.plist file that will be used for +# the bundle. +# +# info_plist_target: +# (optional) string, if the info_plist is generated from an action, +# rather than a regular source file, specify the target name in lieu +# of info_plist. The two arguments are mutually exclusive. +# +# entitlements_path: +# (optional) path to the template to use to generate the application +# entitlements by performing variable substitutions, defaults to +# //build/config/ios/entitlements.plist. +# +# entitlements_target: +# (optional) label of the target generating the application +# entitlements (must generate a single file as output); cannot be +# defined if entitlements_path is set. +# +# bundle_extension: +# (optional) bundle extension including the dot, default to ".app". +# +# product_type +# (optional) string, product type for the generated Xcode project, +# default to "com.apple.product-type.application". Should generally +# not be overridden. +# +# enable_code_signing +# (optional) boolean, control whether code signing is enabled or not, +# default to ios_enable_code_signing if not defined. +# +# For more information, see "gn help executable". +template("ios_app_bundle") { + _output_name = target_name + _target_name = target_name + if (defined(invoker.output_name)) { + _output_name = invoker.output_name + } + + _arch_executable_source = _target_name + "_arch_executable_sources" + _arch_executable_target = _target_name + "_arch_executable" + _lipo_executable_target = _target_name + "_executable" + + source_set(_arch_executable_source) { + forward_variables_from(invoker, + "*", + [ + "bundle_deps", + "bundle_deps_filter", + "bundle_extension", + "enable_code_signing", + "entitlements_path", + "entitlements_target", + "extra_substitutions", + "extra_system_frameworks", + "info_plist", + "info_plist_target", + "output_name", + "product_type", + "visibility", + ]) + + visibility = [ ":$_arch_executable_target" ] + } + + if (current_toolchain == default_toolchain || use_ios_simulator) { + _generate_entitlements_target = _target_name + "_gen_entitlements" + _generate_entitlements_output = + get_label_info(":$_generate_entitlements_target($default_toolchain)", + "target_out_dir") + "/$_output_name.xcent" + } + + executable(_arch_executable_target) { + forward_variables_from(invoker, + "*", + [ + "bundle_deps", + "bundle_deps_filter", + "bundle_extension", + "enable_code_signing", + "entitlements_path", + "entitlements_target", + "extra_substitutions", + "extra_system_frameworks", + "info_plist", + "info_plist_target", + "output_name", + "product_type", + "sources", + "visibility", + ]) + + visibility = [ ":$_lipo_executable_target($default_toolchain)" ] + if (current_toolchain != default_toolchain) { + visibility += [ ":$_target_name" ] + } + + if (!defined(deps)) { + deps = [] + } + deps += [ ":$_arch_executable_source" ] + + if (!defined(libs)) { + libs = [] + } + libs += [ "UIKit.framework" ] + + if (!defined(ldflags)) { + ldflags = [] + } + ldflags += [ + "-Xlinker", + "-rpath", + "-Xlinker", + "@executable_path/Frameworks", + "-Xlinker", + "-objc_abi_version", + "-Xlinker", + "2", + ] + + if (use_ios_simulator) { + deps += [ ":$_generate_entitlements_target($default_toolchain)" ] + + if (!defined(inputs)) { + inputs = [] + } + inputs += [ _generate_entitlements_output ] + + if (!defined(ldflags)) { + ldflags = [] + } + ldflags += [ + "-Xlinker", + "-sectcreate", + "-Xlinker", + "__TEXT", + "-Xlinker", + "__entitlements", + "-Xlinker", + rebase_path(_generate_entitlements_output, root_build_dir), + ] + } + + output_name = _output_name + output_prefix_override = true + output_dir = "$target_out_dir/$current_cpu" + } + + if (current_toolchain != default_toolchain) { + # For fat builds, only the default toolchain will generate an application + # bundle. For the other toolchains, the template is only used for building + # the arch-specific binary, thus the default target is just a group(). + + group(_target_name) { + forward_variables_from(invoker, + [ + "visibility", + "testonly", + ]) + public_deps = [ + ":$_arch_executable_target", + ] + } + } else { + lipo_binary(_lipo_executable_target) { + forward_variables_from(invoker, + [ + "configs", + "testonly", + ]) + + visibility = [ ":$_target_name" ] + output_name = _output_name + arch_binary_target = ":$_arch_executable_target" + arch_binary_output = _output_name + } + + _generate_info_plist = target_name + "_generate_info_plist" + ios_info_plist(_generate_info_plist) { + forward_variables_from(invoker, + [ + "extra_substitutions", + "info_plist", + "info_plist_target", + ]) + + executable_name = _output_name + } + + if (current_toolchain == default_toolchain) { + if (!defined(invoker.entitlements_target)) { + _entitlements_path = "//build/config/ios/entitlements.plist" + if (defined(invoker.entitlements_path)) { + _entitlements_path = invoker.entitlements_path + } + } else { + assert(!defined(invoker.entitlements_path), + "Cannot define both entitlements_path and entitlements_target" + + "for $_target_name") + + _entitlements_target_outputs = + get_target_outputs(invoker.entitlements_target) + _entitlements_path = _entitlements_target_outputs[0] + } + + action(_generate_entitlements_target) { + _gen_info_plist_outputs = get_target_outputs(":$_generate_info_plist") + _info_plist_path = _gen_info_plist_outputs[0] + + script = "//build/config/ios/codesign.py" + deps = [ + ":$_generate_info_plist", + ] + if (defined(invoker.entitlements_target)) { + deps += [ invoker.entitlements_target ] + } + sources = [ + _entitlements_path, + _info_plist_path, + ] + outputs = [ + _generate_entitlements_output, + ] + + args = [] + if (!use_system_xcode) { + args += [ + "--developer_dir", + hermetic_xcode_path, + ] + } + args += [ + "generate-entitlements", + "-e=" + rebase_path(_entitlements_path, root_build_dir), + "-p=" + rebase_path(_info_plist_path, root_build_dir), + ] + rebase_path(outputs, root_build_dir) + } + } + + _bundle_data_info_plist = target_name + "_bundle_data_info_plist" + bundle_data(_bundle_data_info_plist) { + forward_variables_from(invoker, [ "testonly" ]) + + sources = get_target_outputs(":$_generate_info_plist") + outputs = [ + "{{bundle_root_dir}}/Info.plist", + ] + public_deps = [ + ":$_generate_info_plist", + ] + } + + create_signed_bundle(_target_name) { + forward_variables_from(invoker, + [ + "bundle_deps", + "bundle_deps_filter", + "bundle_extension", + "data_deps", + "deps", + "enable_code_signing", + "entitlements_path", + "entitlements_target", + "extra_system_frameworks", + "product_type", + "public_configs", + "public_deps", + "testonly", + "visibility", + ]) + + output_name = _output_name + bundle_binary_target = ":$_lipo_executable_target" + bundle_binary_output = _output_name + + if (!defined(bundle_deps)) { + bundle_deps = [] + } + bundle_deps += [ ":$_bundle_data_info_plist" ] + + if (use_ios_simulator) { + if (!defined(data_deps)) { + data_deps = [] + } + data_deps += [ "//testing/iossim" ] + } + + if (!defined(product_type)) { + product_type = "com.apple.product-type.application" + } + + if (!defined(bundle_extension)) { + bundle_extension = ".app" + } + } + } +} + +set_defaults("ios_app_bundle") { + configs = default_executable_configs +} + +# Template to build an application extension bundle for iOS. +# +# This should be used instead of "executable" built-in target type on iOS. +# As the template forward the generation of the application executable to +# an "executable" target, all arguments supported by "executable" targets +# are also supported by this template. +# +# Arguments +# +# output_name: +# (optional) string, name of the generated application, if omitted, +# defaults to the target_name. +# +# extra_substitutions: +# (optional) list of string in "key=value" format, each value will +# be used as an additional variable substitution rule when generating +# the application Info.plist +# +# info_plist: +# (optional) string, path to the Info.plist file that will be used for +# the bundle. +# +# info_plist_target: +# (optional) string, if the info_plist is generated from an action, +# rather than a regular source file, specify the target name in lieu +# of info_plist. The two arguments are mutually exclusive. +# +# For more information, see "gn help executable". +template("ios_appex_bundle") { + ios_app_bundle(target_name) { + forward_variables_from(invoker, + "*", + [ + "bundle_extension", + "product_type", + ]) + bundle_extension = ".appex" + product_type = "com.apple.product-type.app-extension" + + # Add linker flags required for an application extension (determined by + # inspecting the link command-line when using Xcode 9.0+). + if (!defined(ldflags)) { + ldflags = [] + } + ldflags += [ + "-e", + "_NSExtensionMain", + "-fapplication-extension", + ] + } +} + +set_defaults("ios_appex_bundle") { + configs = default_executable_configs +} + +# Compile a xib or storyboard file and add it to a bundle_data so that it is +# available at runtime in the bundle. +# +# Arguments +# +# source: +# string, path of the xib or storyboard to compile. +# +# Forwards all variables to the bundle_data target. +template("bundle_data_xib") { + assert(defined(invoker.source), "source needs to be defined for $target_name") + + _source_extension = get_path_info(invoker.source, "extension") + assert(_source_extension == "xib" || _source_extension == "storyboard", + "source must be a .xib or .storyboard for $target_name") + + _target_name = target_name + _compile_xib = target_name + "_compile_xib" + + compile_xibs(_compile_xib) { + sources = [ + invoker.source, + ] + visibility = [ ":$_target_name" ] + ibtool_flags = [ + "--minimum-deployment-target", + ios_deployment_target, + "--auto-activate-custom-fonts", + "--target-device", + "iphone", + "--target-device", + "ipad", + ] + } + + bundle_data(_target_name) { + forward_variables_from(invoker, "*", [ "source" ]) + + if (!defined(public_deps)) { + public_deps = [] + } + public_deps += [ ":$_compile_xib" ] + + sources = get_target_outputs(":$_compile_xib") + + outputs = [ + "{{bundle_resources_dir}}/{{source_file_part}}", + ] + } +} + +# Compile a strings file and add it to a bundle_data so that it is available +# at runtime in the bundle. +# +# Arguments +# +# source: +# string, path of the strings file to compile. +# +# output: +# string, path of the compiled file in the final bundle. +# +# Forwards all variables to the bundle_data target. +template("bundle_data_strings") { + assert(defined(invoker.source), "source needs to be defined for $target_name") + assert(defined(invoker.output), "output needs to be defined for $target_name") + + _source_extension = get_path_info(invoker.source, "extension") + assert(_source_extension == "strings", + "source must be a .strings for $target_name") + + _target_name = target_name + _convert_target = target_name + "_compile_strings" + + convert_plist(_convert_target) { + visibility = [ ":$_target_name" ] + source = invoker.source + output = + "$target_gen_dir/$_target_name/" + get_path_info(invoker.source, "file") + format = "binary1" + } + + bundle_data(_target_name) { + forward_variables_from(invoker, + "*", + [ + "source", + "output", + ]) + + if (!defined(public_deps)) { + public_deps = [] + } + public_deps += [ ":$_convert_target" ] + + sources = get_target_outputs(":$_convert_target") + + outputs = [ + invoker.output, + ] + } +} + +# Template to package a shared library into an iOS framework bundle. +# +# By default, the bundle target this template generates does not link the +# resulting framework into anything that depends on it. If a dependency wants +# a link-time (as well as build-time) dependency on the framework bundle, +# depend against "$target_name+link". If only the build-time dependency is +# required (e.g., for copying into another bundle), then use "$target_name". +# +# Arguments +# +# output_name: +# (optional) string, name of the generated framework without the +# .framework suffix. If omitted, defaults to target_name. +# +# public_headers: +# (optional) list of paths to header file that needs to be copied +# into the framework bundle Headers subdirectory. If omitted or +# empty then the Headers subdirectory is not created. +# +# sources +# (optional) list of files. Needs to be defined and non-empty if +# public_headers is defined and non-empty. +# +# enable_code_signing +# (optional) boolean, control whether code signing is enabled or not, +# default to ios_enable_code_signing if not defined. +# +# This template provides two targets for the resulting framework bundle. The +# link-time behavior varies depending on which of the two targets below is +# added as a dependency: +# - $target_name only adds a build-time dependency. Targets that depend on +# it will not link against the framework. +# - $target_name+link adds a build-time and link-time dependency. Targets +# that depend on it will link against the framework. +# +# The build-time-only dependency is used for when a target needs to use the +# framework either only for resources, or because the target loads it at run- +# time, via dlopen() or NSBundle. The link-time dependency will cause the +# dependee to have the framework loaded by dyld at launch. +# +# Example of build-time only dependency: +# +# framework_bundle("CoreTeleportation") { +# sources = [ ... ] +# } +# +# bundle_data("core_teleportation_bundle_data") { +# deps = [ ":CoreTeleportation" ] +# sources = [ "$root_out_dir/CoreTeleportation.framework" ] +# outputs = [ "{{bundle_root_dir}}/Frameworks/{{source_file_part}}" ] +# } +# +# app_bundle("GoatTeleporter") { +# sources = [ ... ] +# deps = [ +# ":core_teleportation_bundle_data", +# ] +# } +# +# The GoatTeleporter.app will not directly link against +# CoreTeleportation.framework, but it will be included in the bundle's +# Frameworks directory. +# +# Example of link-time dependency: +# +# framework_bundle("CoreTeleportation") { +# sources = [ ... ] +# ldflags = [ +# "-install_name", +# "@executable_path/../Frameworks/$target_name.framework" +# ] +# } +# +# bundle_data("core_teleportation_bundle_data") { +# deps = [ ":CoreTeleportation+link" ] +# sources = [ "$root_out_dir/CoreTeleportation.framework" ] +# outputs = [ "{{bundle_root_dir}}/Frameworks/{{source_file_part}}" ] +# } +# +# app_bundle("GoatTeleporter") { +# sources = [ ... ] +# deps = [ +# ":core_teleportation_bundle_data", +# ] +# } +# +# Note that the framework is still copied to the app's bundle, but dyld will +# load this library when the app is launched because it uses the "+link" +# target as a dependency. This also requires that the framework set its +# install_name so that dyld can locate it. +# +# See "gn help shared_library" for more information on arguments supported +# by shared library target. +template("ios_framework_bundle") { + _target_name = target_name + _output_name = target_name + if (defined(invoker.output_name)) { + _output_name = invoker.output_name + } + + _has_public_headers = + defined(invoker.public_headers) && invoker.public_headers != [] + + if (_has_public_headers) { + _framework_headers_target = _target_name + "_framework_headers" + _framework_headers_config = _target_name + "_framework_headers_config" + _headers_map_config = _target_name + "_headers_map" + } + + _arch_shared_library_source = _target_name + "_arch_shared_library_sources" + _arch_shared_library_target = _target_name + "_arch_shared_library" + _lipo_shared_library_target = _target_name + "_shared_library" + + source_set(_arch_shared_library_source) { + forward_variables_from(invoker, + "*", + [ + "bundle_deps", + "bundle_deps_filter", + "data_deps", + "enable_code_signing", + "info_plist", + "info_plist_target", + "output_name", + "visibility", + ]) + + visibility = [ ":$_arch_shared_library_target" ] + + if (_has_public_headers) { + configs += [ + ":$_framework_headers_config($default_toolchain)", + ":$_headers_map_config($default_toolchain)", + ] + + if (!defined(deps)) { + deps = [] + } + deps += [ ":$_framework_headers_target($default_toolchain)" ] + } + } + + shared_library(_arch_shared_library_target) { + forward_variables_from(invoker, + "*", + [ + "bundle_deps", + "bundle_deps_filter", + "data_deps", + "enable_code_signing", + "info_plist", + "info_plist_target", + "output_name", + "sources", + "visibility", + ]) + + visibility = [ ":$_lipo_shared_library_target($default_toolchain)" ] + if (current_toolchain != default_toolchain) { + visibility += [ ":$_target_name" ] + } + + if (!defined(deps)) { + deps = [] + } + deps += [ ":$_arch_shared_library_source" ] + + if (!defined(ldflags)) { + ldflags = [] + } + ldflags += [ + "-Xlinker", + "-install_name", + "-Xlinker", + "@rpath/$_output_name.framework/$_output_name", + "-Xlinker", + "-objc_abi_version", + "-Xlinker", + "2", + ] + + output_extension = "" + output_name = _output_name + output_prefix_override = true + output_dir = "$target_out_dir/$current_cpu" + } + + if (current_toolchain != default_toolchain) { + # For fat builds, only the default toolchain will generate a framework + # bundle. For the other toolchains, the template is only used for building + # the arch-specific binary, thus the default target is just a group(). + + group(_target_name) { + forward_variables_from(invoker, + [ + "visibility", + "testonly", + ]) + public_deps = [ + ":$_arch_shared_library_target", + ] + } + + group(_target_name + "+link") { + forward_variables_from(invoker, + [ + "visibility", + "testonly", + ]) + public_deps = [ + ":$_target_name+link($default_toolchain)", + ] + } + + if (defined(invoker.bundle_deps)) { + assert(invoker.bundle_deps != [], "mark bundle_deps as used") + } + } else { + if (_has_public_headers) { + _public_headers = invoker.public_headers + _framework_root = "$root_out_dir/$_output_name.framework" + + _header_map_filename = "$target_gen_dir/$_output_name.headers.hmap" + + _compile_headers_map_target = _target_name + "_compile_headers_map" + action(_compile_headers_map_target) { + visibility = [ ":$_framework_headers_target" ] + script = "//build/config/ios/write_framework_hmap.py" + outputs = [ + _header_map_filename, + ] + + # The header map generation only wants the list of headers, not all of + # sources, so filter any non-header source files from "sources". It is + # less error prone that having the developer duplicate the list of all + # headers in addition to "sources". + set_sources_assignment_filter([ + "*.c", + "*.cc", + "*.cpp", + "*.m", + "*.mm", + ]) + sources = invoker.sources + set_sources_assignment_filter([]) + + args = [ + rebase_path(_header_map_filename), + rebase_path(_framework_root, root_build_dir), + ] + rebase_path(sources, root_build_dir) + } + + _create_module_map_target = _target_name + "_module_map" + action(_create_module_map_target) { + visibility = [ ":$_framework_headers_target" ] + script = "//build/config/ios/write_framework_modulemap.py" + outputs = [ + "$_framework_root/Modules/module.modulemap", + ] + args = [ rebase_path("$_framework_root", root_build_dir) ] + } + + _copy_public_headers_target = _target_name + "_copy_public_headers" + copy(_copy_public_headers_target) { + visibility = [ ":$_framework_headers_target" ] + sources = _public_headers + outputs = [ + "$_framework_root/Headers/{{source_file_part}}", + ] + } + + config(_headers_map_config) { + visibility = [ ":$_target_name" ] + include_dirs = [ _header_map_filename ] + } + + group(_framework_headers_target) { + deps = [ + ":$_compile_headers_map_target", + ":$_copy_public_headers_target", + ":$_create_module_map_target", + ] + } + + config(_framework_headers_config) { + # The link settings are inherited from the framework_bundle config. + cflags = [ + "-F", + rebase_path("$root_out_dir/.", root_build_dir), + ] + } + } + + lipo_binary(_lipo_shared_library_target) { + forward_variables_from(invoker, + [ + "configs", + "testonly", + ]) + + visibility = [ ":$_target_name" ] + output_name = _output_name + arch_binary_target = ":$_arch_shared_library_target" + arch_binary_output = _output_name + } + + _framework_public_config = _target_name + "_public_config" + config(_framework_public_config) { + # TODO(sdefresne): should we have a framework_dirs similar to lib_dirs + # and include_dirs to avoid duplicate values on the command-line. + visibility = [ ":$_target_name" ] + ldflags = [ + "-F", + rebase_path("$root_out_dir/.", root_build_dir), + ] + lib_dirs = [ root_out_dir ] + libs = [ "$_output_name.framework" ] + } + + _info_plist_target = _target_name + "_info_plist" + _info_plist_bundle = _target_name + "_info_plist_bundle" + ios_info_plist(_info_plist_target) { + visibility = [ ":$_info_plist_bundle" ] + executable_name = _output_name + forward_variables_from(invoker, + [ + "extra_substitutions", + "info_plist", + "info_plist_target", + ]) + } + + bundle_data(_info_plist_bundle) { + visibility = [ ":$_target_name" ] + forward_variables_from(invoker, [ "testonly" ]) + sources = get_target_outputs(":$_info_plist_target") + outputs = [ + "{{bundle_root_dir}}/Info.plist", + ] + public_deps = [ + ":$_info_plist_target", + ] + } + + create_signed_bundle(_target_name) { + forward_variables_from(invoker, + [ + "bundle_deps", + "bundle_deps_filter", + "data_deps", + "deps", + "enable_code_signing", + "public_configs", + "public_deps", + "testonly", + "visibility", + ]) + + product_type = "com.apple.product-type.framework" + bundle_extension = ".framework" + + output_name = _output_name + bundle_binary_target = ":$_lipo_shared_library_target" + bundle_binary_output = _output_name + + if (!defined(deps)) { + deps = [] + } + deps += [ ":$_info_plist_bundle" ] + } + + group(_target_name + "+link") { + forward_variables_from(invoker, + [ + "public_deps", + "public_configs", + "testonly", + "visibility", + ]) + if (!defined(public_deps)) { + public_deps = [] + } + public_deps += [ ":$_target_name" ] + if (!defined(public_configs)) { + public_configs = [] + } + public_configs += [ ":$_framework_public_config" ] + + if (_has_public_headers) { + public_configs += [ ":$_framework_headers_config" ] + } + } + + bundle_data(_target_name + "+bundle") { + forward_variables_from(invoker, + [ + "testonly", + "visibility", + ]) + public_deps = [ + ":$_target_name", + ] + sources = [ + "$root_out_dir/$_output_name.framework", + ] + outputs = [ + "{{bundle_resources_dir}}/Frameworks/$_output_name.framework", + ] + } + } +} + +set_defaults("ios_framework_bundle") { + configs = default_shared_library_configs +} + +# For Chrome on iOS we want to run XCTests for all our build configurations +# (Debug, Release, ...). In addition, the symbols visibility is configured to +# private by default. To simplify testing with those constraints, our tests are +# compiled in the TEST_HOST target instead of the .xctest bundle. +template("ios_xctest_test") { + _target_name = target_name + _output_name = target_name + if (defined(invoker.output_name)) { + _output_name = invoker.output_name + } + + _xctest_target = _target_name + "_module" + _xctest_output = _output_name + "_module" + + _host_target = _target_name + _host_output = _output_name + + _xctest_arch_loadable_module_target = _xctest_target + "_arch_loadable_module" + _xctest_lipo_loadable_module_target = _xctest_target + "_loadable_module" + + loadable_module(_xctest_arch_loadable_module_target) { + visibility = [ ":$_xctest_lipo_loadable_module_target($default_toolchain)" ] + if (current_toolchain != default_toolchain) { + visibility += [ ":$_xctest_target" ] + } + + sources = [ + "//build/config/ios/xctest_shell.mm", + ] + configs += [ "//build/config/ios:xctest_config" ] + + output_dir = "$target_out_dir/$current_cpu" + output_name = _xctest_output + output_prefix_override = true + output_extension = "" + } + + if (current_toolchain != default_toolchain) { + # For fat builds, only the default toolchain will generate a test bundle. + # For the other toolchains, the template is only used for building the + # arch-specific binary, thus the default target is just a group(). + group(_xctest_target) { + forward_variables_from(invoker, + [ + "visibility", + "testonly", + ]) + public_deps = [ + ":$_xctest_arch_loadable_module_target", + ] + } + } else { + _xctest_info_plist_target = _xctest_target + "_info_plist" + _xctest_info_plist_bundle = _xctest_target + "_info_plist_bundle" + ios_info_plist(_xctest_info_plist_target) { + visibility = [ ":$_xctest_info_plist_bundle" ] + info_plist = "//build/config/ios/Module-Info.plist" + extra_substitutions = [ "MODULE_NAME=$_xctest_output" ] + executable_name = _host_output + } + + bundle_data(_xctest_info_plist_bundle) { + visibility = [ ":$_xctest_target" ] + public_deps = [ + ":$_xctest_info_plist_target", + ] + sources = get_target_outputs(":$_xctest_info_plist_target") + outputs = [ + "{{bundle_root_dir}}/Info.plist", + ] + } + + lipo_binary(_xctest_lipo_loadable_module_target) { + forward_variables_from(invoker, + [ + "configs", + "testonly", + ]) + + visibility = [ ":$_xctest_target" ] + output_name = _xctest_output + arch_binary_target = ":$_xctest_arch_loadable_module_target" + arch_binary_output = _xctest_output + } + + _xctest_bundle = _xctest_target + "_bundle" + create_signed_bundle(_xctest_target) { + forward_variables_from(invoker, [ "enable_code_signing" ]) + visibility = [ ":$_xctest_bundle" ] + + product_type = "com.apple.product-type.bundle.unit-test" + bundle_extension = ".xctest" + + output_name = _xctest_output + bundle_binary_target = ":$_xctest_lipo_loadable_module_target" + bundle_binary_output = _xctest_output + + deps = [ + ":$_xctest_info_plist_bundle", + ] + } + + bundle_data(_xctest_bundle) { + visibility = [ ":$_host_target" ] + public_deps = [ + ":$_xctest_target", + ] + sources = [ + "$root_out_dir/$_xctest_output.xctest", + ] + outputs = [ + "{{bundle_plugins_dir}}/$_xctest_output.xctest", + ] + } + } + + ios_app_bundle(_host_target) { + forward_variables_from(invoker, "*", [ "testonly" ]) + + testonly = true + output_name = _host_output + configs += [ "//build/config/ios:xctest_config" ] + + if (!defined(invoker.info_plist) && !defined(invoker.info_plist_target)) { + info_plist = "//build/config/ios/Host-Info.plist" + } + + # Xcode needs those two framework installed in the application (and signed) + # for the XCTest to run, so install them using extra_system_frameworks. + _ios_platform_library = "$ios_sdk_platform_path/Developer/Library" + extra_system_frameworks = [ + "$_ios_platform_library/Frameworks/XCTest.framework", + "$_ios_platform_library/PrivateFrameworks/IDEBundleInjection.framework", + ] + + if (current_toolchain == default_toolchain) { + if (!defined(bundle_deps)) { + bundle_deps = [] + } + bundle_deps += [ ":$_xctest_bundle" ] + } + + if (!defined(ldflags)) { + ldflags = [] + } + ldflags += [ + "-Xlinker", + "-rpath", + "-Xlinker", + "@executable_path/Frameworks", + "-Xlinker", + "-rpath", + "-Xlinker", + "@loader_path/Frameworks", + ] + } +} + +set_defaults("ios_xctest_test") { + configs = default_executable_configs +} diff --git a/samples/GN/isolate.gni b/samples/GN/isolate.gni new file mode 100644 index 00000000..3906cf60 --- /dev/null +++ b/samples/GN/isolate.gni @@ -0,0 +1,193 @@ +# Copyright 2016 the V8 project 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("//build/config/sanitizers/sanitizers.gni") +import("//third_party/icu/config.gni") +import("v8.gni") + +declare_args() { + # Sets the test isolation mode (noop|prepare|check). + v8_test_isolation_mode = "noop" +} + +template("v8_isolate_run") { + forward_variables_from(invoker, + "*", + [ + "deps", + "isolate", + ]) + + # Remember target name as within the action scope the target name will be + # different. + name = target_name + + assert(defined(invoker.deps)) + assert(defined(invoker.isolate)) + + if (name != "" && v8_test_isolation_mode != "noop") { + action(name + "_run") { + testonly = true + + deps = invoker.deps + + script = "//tools/isolate_driver.py" + + sources = [ + invoker.isolate, + ] + + inputs = [ + # Files that are known to be involved in this step. + "//tools/swarming_client/isolate.py", + "//tools/swarming_client/run_isolated.py", + ] + + if (v8_test_isolation_mode == "prepare") { + outputs = [ + "$root_out_dir/$name.isolated.gen.json", + ] + } else if (v8_test_isolation_mode == "check") { + outputs = [ + "$root_out_dir/$name.isolated", + "$root_out_dir/$name.isolated.state", + ] + } + + # Translate gn to gyp variables. + if (is_asan) { + asan = "1" + } else { + asan = "0" + } + if (is_msan) { + msan = "1" + } else { + msan = "0" + } + if (is_tsan) { + tsan = "1" + } else { + tsan = "0" + } + if (is_cfi) { + cfi_vptr = "1" + } else { + cfi_vptr = "0" + } + if (target_cpu == "x86") { + target_arch = "ia32" + } else { + target_arch = target_cpu + } + if (is_debug) { + configuration_name = "Debug" + } else { + configuration_name = "Release" + } + if (is_component_build) { + component = "shared_library" + } else { + component = "static_library" + } + if (icu_use_data_file) { + icu_use_data_file_flag = "1" + } else { + icu_use_data_file_flag = "0" + } + if (v8_enable_inspector) { + enable_inspector = "1" + } else { + enable_inspector = "0" + } + if (v8_use_external_startup_data) { + use_external_startup_data = "1" + } else { + use_external_startup_data = "0" + } + if (v8_use_snapshot) { + use_snapshot = "true" + } else { + use_snapshot = "false" + } + if (v8_has_valgrind) { + has_valgrind = "1" + } else { + has_valgrind = "0" + } + if (v8_gcmole) { + gcmole = "1" + } else { + gcmole = "0" + } + + # Note, all paths will be rebased in isolate_driver.py to be relative to + # the isolate file. + args = [ + v8_test_isolation_mode, + "--isolated", + rebase_path("$root_out_dir/$name.isolated", root_build_dir), + "--isolate", + rebase_path(invoker.isolate, root_build_dir), + + # Path variables are used to replace file paths when loading a .isolate + # file + "--path-variable", + "DEPTH", + rebase_path("//", root_build_dir), + "--path-variable", + "PRODUCT_DIR", + rebase_path(root_out_dir, root_build_dir), + + # TODO(machenbach): Set variables for remaining features. + "--config-variable", + "CONFIGURATION_NAME=$configuration_name", + "--config-variable", + "OS=$target_os", + "--config-variable", + "asan=$asan", + "--config-variable", + "cfi_vptr=$cfi_vptr", + "--config-variable", + "gcmole=$gcmole", + "--config-variable", + "has_valgrind=$has_valgrind", + "--config-variable", + "icu_use_data_file_flag=$icu_use_data_file_flag", + "--config-variable", + "is_gn=1", + "--config-variable", + "msan=$msan", + "--config-variable", + "tsan=$tsan", + "--config-variable", + "coverage=0", + "--config-variable", + "sanitizer_coverage=0", + "--config-variable", + "component=$component", + "--config-variable", + "target_arch=$target_arch", + "--config-variable", + "v8_enable_inspector=$enable_inspector", + "--config-variable", + "v8_use_external_startup_data=$use_external_startup_data", + "--config-variable", + "v8_use_snapshot=$use_snapshot", + ] + + if (is_win) { + args += [ + "--config-variable", + "msvs_version=2015", + ] + } else { + args += [ + "--config-variable", + "msvs_version=0", + ] + } + } + } +} diff --git a/samples/Python/filenames/.gclient b/samples/Python/filenames/.gclient new file mode 100644 index 00000000..4d21324d --- /dev/null +++ b/samples/Python/filenames/.gclient @@ -0,0 +1,9 @@ +solutions = [ + { + "url": "https://chromium.googlesource.com/v8/v8.git", + "managed": False, + "name": "v8", + "deps_file": "DEPS", + "custom_deps": {}, + }, +] diff --git a/samples/Python/standalone.gypi b/samples/Python/standalone.gypi new file mode 100644 index 00000000..d438a5ae --- /dev/null +++ b/samples/Python/standalone.gypi @@ -0,0 +1,1522 @@ +# Copyright 2012 the V8 project 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. + +# Definitions to be used when building stand-alone V8 binaries. + +{ + # We need to include toolchain.gypi here for third-party sources that don't + # directly include it themselves. + 'includes': ['toolchain.gypi'], + 'variables': { + 'component%': 'static_library', + 'clang_xcode%': 0, + # Track where uninitialized memory originates from. From fastest to + # slowest: 0 - no tracking, 1 - track only the initial allocation site, 2 + # - track the chain of stores leading from allocation site to use site. + 'msan_track_origins%': 2, + 'visibility%': 'hidden', + 'v8_enable_backtrace%': 0, + 'v8_enable_i18n_support%': 1, + 'v8_deprecation_warnings': 1, + 'v8_imminent_deprecation_warnings': 1, + 'msvs_multi_core_compile%': '1', + 'mac_deployment_target%': '10.7', + 'release_extra_cflags%': '', + 'v8_enable_inspector%': 0, + 'variables': { + 'variables': { + 'variables': { + 'variables': { + 'conditions': [ + ['OS=="linux" or OS=="freebsd" or OS=="openbsd" or \ + OS=="netbsd" or OS=="mac" or OS=="qnx" or OS=="aix"', { + # This handles the Unix platforms we generally deal with. + # Anything else gets passed through, which probably won't work + # very well; such hosts should pass an explicit target_arch + # to gyp. + 'host_arch%': '