| # Copyright (C) 2021 The Android Open Source Project |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| |
| load("@bazel_skylib//lib:paths.bzl", "paths") |
| load("@rules_devicetree//devicetree:toolchain.bzl", "devicetree_toolchain") |
| load("@rules_pkg//pkg:tar.bzl", "pkg_tar") |
| load("@rules_python//python:defs.bzl", "py_binary", "py_library", "py_test") |
| load("@rules_shell//shell:sh_library.bzl", "sh_library") |
| load("//build/kernel/kleaf:hermetic_tools.bzl", "hermetic_tools") |
| load("//build/kernel/kleaf/impl:executable_dispatcher.bzl", "executable_dispatcher") |
| |
| ## External tools that requires special handling |
| |
| executable_dispatcher( |
| name = "rsync", |
| src = "@kleaf_host_tools//:rsync", |
| append_args = ["--no-group"], |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "toybox", |
| src = "@toybox", |
| data = [ |
| # Prevents --notoolchain_from_sources from being set, and print a nice error message if so. |
| "//build/kernel/kleaf:toolchain_from_sources", |
| # Prevents --workaround_btrfs_b292212788 from being set, and print a nice error message if so. |
| "//build/kernel/kleaf:workaround_btrfs_b292212788", |
| # Prevents --debug_cache_dir_conflict from being set, and print a nice error message if so. |
| "//build/kernel/kleaf:debug_cache_dir_conflict", |
| ], |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "gzip", |
| src = "@pigz", |
| # Prevents --nogzip_is_pigz from being set, and print a nice error message if so. |
| data = ["//build/kernel/kleaf:gzip_is_pigz"], |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "tar", |
| src = ":toybox", |
| append_args = [ |
| "--mtime=@0", |
| "--owner=0", |
| "--group=0", |
| "--numeric-owner", |
| "--sort=name", |
| ], |
| visibility = ["//visibility:private"], |
| ) |
| |
| # Also used in bootstrap_hermetic_tools, so use a executable_dispatcher to ensure |
| # the name of the binary is correct. |
| executable_dispatcher( |
| name = "sed", |
| src = ":toybox", |
| visibility = ["//build/kernel/kleaf/bootstrap_hermetic_tools:__pkg__"], |
| ) |
| |
| executable_dispatcher( |
| name = "bison", |
| src = "//prebuilts/build-tools:bison", |
| data = [ |
| "//prebuilts/build-tools:bison.runfiles", |
| "//prebuilts/build-tools:m4", |
| ], |
| reversed_env = { |
| "//prebuilts/build-tools:m4": "M4", |
| "//prebuilts/build-tools:bison.runfiles_dir": "BISON_PKGDATADIR", |
| }, |
| visibility = ["//build/kernel/kleaf/bootstrap_hermetic_tools:__pkg__"], |
| ) |
| |
| executable_dispatcher( |
| name = "flex", |
| src = "//prebuilts/build-tools:flex", |
| data = [ |
| "//prebuilts/build-tools:m4", |
| ], |
| reversed_env = { |
| "//prebuilts/build-tools:m4": "M4", |
| }, |
| visibility = ["//build/kernel/kleaf/bootstrap_hermetic_tools:__pkg__"], |
| ) |
| |
| executable_dispatcher( |
| name = "swig", |
| src = "//prebuilts/kernel-build-tools:swig", |
| reversed_env = { |
| "//prebuilts/kernel-build-tools:swig_lib_dir": "SWIG_LIB", |
| }, |
| # content of swig_lib_dir is already in runfiles of |
| # //prebuilts/kernel-build-tools:swig. |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "lz4", |
| src = "@lz4", |
| # Prevents --notoolchain_from_sources from being set, and print a nice error message if so. |
| data = ["//build/kernel/kleaf:toolchain_from_sources"], |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "depmod", |
| src = "@kmod//:depmod", |
| # Prevents --nodepmod_from_sources from being set, and print a nice error message if so. |
| data = ["//build/kernel/kleaf:depmod_from_sources"], |
| visibility = ["//build/kernel:__subpackages__"], |
| ) |
| |
| executable_dispatcher( |
| name = "modinfo", |
| src = ":depmod", |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "dtc", |
| src = "@dtc", |
| # Prevents --nodtc_from_sources from being set, and print a nice error message if so. |
| data = ["//build/kernel/kleaf:dtc_from_sources"], |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "avbtool", |
| src = "//prebuilts/kernel-build-tools:avbtool", |
| visibility = ["//visibility:public"], |
| ) |
| |
| executable_dispatcher( |
| name = "mkbootimg", |
| src = "//prebuilts/kernel-build-tools:mkbootimg", |
| visibility = ["//visibility:public"], |
| ) |
| |
| executable_dispatcher( |
| name = "unpack_bootimg", |
| src = "//prebuilts/kernel-build-tools:unpack_bootimg", |
| visibility = ["//visibility:public"], |
| ) |
| |
| executable_dispatcher( |
| name = "bzcat", |
| src = ":bzip2", |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "lzma", |
| src = ":xz", |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "xzcat", |
| src = ":xz", |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "unzip", |
| src = "//prebuilts/build-tools:ziptool", |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "zipinfo", |
| src = "//prebuilts/build-tools:ziptool", |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "python3", |
| src = "//build/kernel/kleaf/impl:python_runtime_files", |
| forward_argv0 = False, |
| python_hack = True, |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "python", |
| src = ":python3", |
| forward_argv0 = False, |
| python_hack = True, |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "zstd", |
| src = "@zstd//:zstd_cli", |
| visibility = ["//visibility:private"], |
| ) |
| |
| executable_dispatcher( |
| name = "bindgen", |
| src = "//prebuilts/clang-tools:bindgen", |
| visibility = ["//visibility:public"], |
| ) |
| |
| # List of the above that goes into the hermetic toolchain, |
| # where label.name is the tool name |
| _SPECIAL_TOOLS_SAME_NAME = [ |
| # keep sorted |
| ":avbtool", |
| ":bison", |
| ":bzcat", |
| ":depmod", |
| ":dtc", |
| ":flex", |
| ":gzip", |
| ":lz4", |
| ":lzma", |
| ":modinfo", |
| ":python", |
| ":python3", |
| ":rsync", |
| ":sed", |
| ":swig", |
| ":tar", |
| ":unzip", |
| ":xzcat", |
| ":zipinfo", |
| ":zstd", |
| ] |
| |
| # External tools that requires no special handling and goes into the hermetic toolchain, |
| # where basename(label.name) is the tool name |
| _SIMPLE_TOOLS_SAME_NAME = [ |
| # keep sorted |
| "//prebuilts/build-tools:awk", |
| "//prebuilts/build-tools:bc", |
| "//prebuilts/build-tools:bzip2", |
| "//prebuilts/build-tools:m4", |
| "//prebuilts/build-tools:make", |
| "//prebuilts/build-tools:openssl", |
| "//prebuilts/build-tools:runextractor", |
| "//prebuilts/build-tools:soong_zip", |
| "//prebuilts/build-tools:xz", |
| "//prebuilts/kernel-build-tools:blk_alloc_to_base_fs", |
| "//prebuilts/kernel-build-tools:build_image", |
| "//prebuilts/kernel-build-tools:build_super_image", |
| "//prebuilts/kernel-build-tools:certify_bootimg", |
| "//prebuilts/kernel-build-tools:e2fsck", |
| "//prebuilts/kernel-build-tools:e2fsdroid", |
| "//prebuilts/kernel-build-tools:fec", |
| "//prebuilts/kernel-build-tools:fsck.erofs", |
| "//prebuilts/kernel-build-tools:img2simg", |
| "//prebuilts/kernel-build-tools:lpmake", |
| "//prebuilts/kernel-build-tools:mkbootfs", |
| "//prebuilts/kernel-build-tools:mkdtboimg", |
| "//prebuilts/kernel-build-tools:mkdtimg", |
| "//prebuilts/kernel-build-tools:mke2fs", |
| "//prebuilts/kernel-build-tools:mkfs.erofs", |
| "//prebuilts/kernel-build-tools:mkuserimg_mke2fs", |
| "//prebuilts/kernel-build-tools:simg2img", |
| "//prebuilts/kernel-build-tools:tune2fs", |
| "//prebuilts/kernel-build-tools:ufdt_apply_overlay", |
| "@kleaf_host_tools//:bash", |
| "@kleaf_host_tools//:perl", |
| "@kleaf_host_tools//:sh", |
| # TODO: This is only used by abi_stgdiff. It should be fine to be removed from hermetic_tools. |
| "//build/kernel/kleaf/impl:stgdiff", |
| ] + glob( |
| [ |
| # Intentionally glob here to test for existance of alias destination |
| # buildifier: disable=constant-glob |
| "build-tools/kleaf_internal_do_not_use_path/linux-x86/cxx_extractor", |
| ], |
| allow_empty = True, |
| ) |
| |
| [executable_dispatcher( |
| name = paths.basename(package_relative_label(tool).name), |
| src = tool, |
| visibility = ["//visibility:private"], |
| ) for tool in _SIMPLE_TOOLS_SAME_NAME] |
| |
| # List of toybox aliases |
| _TOYS = [ |
| # keep sorted |
| "basename", |
| "cat", |
| "chmod", |
| "cmp", |
| "comm", |
| "cp", |
| "cpio", |
| "cut", |
| "date", |
| "dd", |
| "diff", |
| "dirname", |
| "du", |
| "echo", |
| "egrep", |
| "env", |
| "expr", |
| "find", |
| "getconf", |
| "grep", |
| "head", |
| "hostname", |
| "id", |
| "install", |
| "ln", |
| "ls", |
| "md5sum", |
| "mkdir", |
| "mktemp", |
| "mount", |
| "mv", |
| "nproc", |
| "od", |
| "paste", |
| "pgrep", |
| "pkill", |
| "ps", |
| "pwd", |
| "readlink", |
| "realpath", |
| "rm", |
| "rmdir", |
| "seq", |
| "setsid", |
| "sha1sum", |
| "sha256sum", |
| "sha512sum", |
| "sleep", |
| "sort", |
| "stat", |
| "tail", |
| "tee", |
| "test", |
| "timeout", |
| "touch", |
| "tr", |
| "true", |
| "truncate", |
| "umount", |
| "uname", |
| "uniq", |
| "unix2dos", |
| "unshare", |
| "wc", |
| "which", |
| "whoami", |
| "xargs", |
| "xxd", |
| ] |
| |
| [executable_dispatcher( |
| name = toy, |
| src = ":toybox", |
| visibility = ["//visibility:private"], |
| ) for toy in _TOYS] |
| |
| # List of tools where label.name is the tool name |
| _TOOLS_SAME_NAME = _SPECIAL_TOOLS_SAME_NAME + \ |
| [":" + paths.basename(package_relative_label(tool).name) for tool in _SIMPLE_TOOLS_SAME_NAME + |
| _TOYS] |
| |
| hermetic_tools( |
| name = "hermetic-tools", |
| symlinks = { |
| tool: package_relative_label(tool).name |
| for tool in _TOOLS_SAME_NAME |
| }, |
| visibility = ["//visibility:public"], |
| ) |
| |
| toolchain_type( |
| name = "hermetic_tools_toolchain_type", |
| visibility = ["//visibility:private"], |
| ) |
| |
| toolchain( |
| name = "hermetic_tools_toolchain", |
| exec_compatible_with = [ |
| "@platforms//os:linux", |
| "@platforms//cpu:x86_64", |
| ], |
| toolchain = ":hermetic-tools", |
| toolchain_type = ":hermetic_tools_toolchain_type", |
| visibility = ["//visibility:private"], |
| ) |
| |
| devicetree_toolchain( |
| name = "devicetree_toolchain_impl", |
| default_dtcopts = [ |
| "-Wno-unique_unit_address", |
| # Assume no KBUILD_EXTRA_WARN |
| "-Wno-unit_address_vs_reg", |
| "-Wno-avoid_unnecessary_addr_size", |
| "-Wno-alias_paths", |
| "-Wno-graph_child_address", |
| "-Wno-simple_bus_reg", |
| ], |
| dtc = ":dtc", |
| fdtoverlay = "@dtc//:fdtoverlay", |
| preprocess = True, |
| ) |
| |
| toolchain( |
| name = "devicetree_toolchain", |
| toolchain = ":devicetree_toolchain_impl", |
| toolchain_type = "@rules_devicetree//devicetree:toolchain_type", |
| ) |
| |
| # Tools visible to all packages that uses kernel_build. |
| # Implementation detail of kernel_build; do not use directly. |
| sh_library( |
| name = "_setup_env", |
| srcs = ["_setup_env.sh"], |
| visibility = ["//visibility:public"], |
| ) |
| |
| # Tools visible to all packages that uses kernel_build. |
| # Implementation detail of kernel_build; do not use directly. |
| sh_library( |
| name = "build_utils", |
| srcs = ["build_utils.sh"], |
| visibility = ["//visibility:public"], |
| ) |
| |
| # Tools visible to all packages that uses kernel_build. |
| # Implementation detail of kernel_build; do not use directly. |
| py_binary( |
| name = "abi_verify_ksymtab", |
| srcs = ["abi/verify_ksymtab.py"], |
| main = "abi/verify_ksymtab.py", |
| visibility = ["//visibility:public"], |
| deps = [":symbol_extraction"], |
| ) |
| |
| # Tools visible to all packages that uses kernel_build. |
| # Implementation detail of kernel_build; do not use directly. |
| py_binary( |
| name = "abi_flatten_symbol_list", |
| srcs = ["abi/flatten_symbol_list.py"], |
| main = "abi/flatten_symbol_list.py", |
| visibility = ["//visibility:public"], |
| ) |
| |
| # Tools visible to all packages that uses kernel_build. |
| # Implementation detail of kernel_build; do not use directly. |
| py_binary( |
| name = "abi_process_symbols", |
| srcs = ["abi/process_symbols.py"], |
| data = [ |
| "abi/symbols.deny", |
| ], |
| main = "abi/process_symbols.py", |
| visibility = ["//visibility:public"], |
| ) |
| |
| py_library( |
| name = "symbol_extraction", |
| srcs = ["abi/symbol_extraction.py"], |
| imports = ["abi"], |
| visibility = ["//visibility:private"], |
| ) |
| |
| # Tools visible to all packages that uses kernel_abi |
| # Implementation detail of kernel_abi; do not use directly. |
| py_binary( |
| name = "check_buildtime_symbol_protection", |
| srcs = ["abi/check_buildtime_symbol_protection.py"], |
| main = "abi/check_buildtime_symbol_protection.py", |
| visibility = ["//visibility:public"], |
| deps = [":symbol_extraction"], |
| ) |
| |
| # Tools visible to all packages that uses kernel_abi. |
| # Implementation detail of kernel_abi; do not use directly. |
| py_binary( |
| name = "extract_symbols", |
| srcs = ["abi/extract_symbols.py"], |
| main = "abi/extract_symbols.py", |
| visibility = ["//visibility:public"], |
| deps = [":symbol_extraction"], |
| ) |
| |
| # Tools visible to all packages. |
| py_binary( |
| name = "dependency_graph_extractor", |
| srcs = ["abi/dependency_graph_extractor.py"], |
| main = "abi/dependency_graph_extractor.py", |
| visibility = ["//visibility:public"], |
| deps = [":symbol_extraction"], |
| ) |
| |
| py_binary( |
| name = "dependency_graph_drawer", |
| srcs = ["abi/dependency_graph_drawer.py"], |
| main = "abi/dependency_graph_drawer.py", |
| visibility = ["//visibility:public"], |
| ) |
| |
| # Tools visible to all packages. |
| py_library( |
| name = "xml_handler", |
| srcs = ["gki/xml_handler.py"], |
| imports = ["gki"], |
| visibility = ["//visibility:private"], |
| ) |
| |
| # Tools visible to all packages. |
| py_binary( |
| name = "modinfo_summary", |
| srcs = ["gki/modinfo_summary.py"], |
| main = "gki/modinfo_summary.py", |
| visibility = ["//visibility:public"], |
| deps = [":xml_handler"], |
| ) |
| |
| # Boostrap tool for DDK development. |
| py_binary( |
| name = "init_ddk", |
| srcs = [ |
| "init/__init__.py", |
| "init/init_ddk.py", |
| "init/init_errors.py", |
| "init/repo_manifest_parser.py", |
| "init/repo_wrapper.py", |
| ], |
| data = ["init/init_download.py"], |
| imports = ["."], |
| main = "init/init_ddk.py", |
| visibility = ["//build/kernel:__subpackages__"], |
| ) |
| |
| py_test( |
| name = "init_ddk_test", |
| srcs = ["init/init_ddk_test.py"], |
| data = [ |
| "init/test_data/sample_manifest.xml", |
| ], |
| imports = ["init"], |
| visibility = ["//visibility:private"], |
| deps = [ |
| ":init_ddk", |
| "@io_abseil_py//absl/testing:absltest", |
| "@io_abseil_py//absl/testing:parameterized", |
| ], |
| ) |
| |
| # Target for distribution. |
| filegroup( |
| name = "init_ddk_zip", |
| srcs = [":init_ddk"], |
| output_group = "python_zip_file", |
| visibility = ["//visibility:public"], |
| ) |
| |
| pkg_tar( |
| name = "gki_certification_tools_tar", |
| srcs = ["//prebuilts/kernel-build-tools:gki_certification_tools_pkg_files"], |
| out = "gki_certification_tools.tar.gz", |
| compressor = ":gzip", |
| visibility = ["//visibility:private"], |
| ) |
| |
| filegroup( |
| name = "gki_certification_tools", |
| srcs = [":gki_certification_tools_tar"], |
| visibility = ["//visibility:public"], |
| ) |