diff options
author | Yifan Hong <elsk@google.com> | 2023-06-27 22:05:54 -0700 |
---|---|---|
committer | Yifan Hong <elsk@google.com> | 2023-06-28 20:20:34 +0000 |
commit | 8f388a0f072678f1ea94d968c23cfdd46d72e6a4 (patch) | |
tree | 95565e65bedd536e7853855b8e097e5f32777050 | |
parent | 0b3c2e60e8c097dc3d474edd845d77951bc96139 (diff) | |
download | build-8f388a0f072678f1ea94d968c23cfdd46d72e6a4.tar.gz |
kleaf: Set-ffile-prefix-map to real workspace root
For android13-5.10, the kernel image uses the realpath to stdarg.h
under prebuilts. For sandbox builds, this means the real workspace root appears in the
final artifact, affecting hermeticity and emitting absolute paths to ABI dump XML file.
Determine the real workspace root by using ${{ROOT_DIR}}/${{KERNEL_DIR}}/Makefile as an
anchor. If Makefile does not exist, we are not executing Kbuild, so it is fine that
KCPPFLAGS are not set properly.
Bug: 287304304
Test: tools/bazel run //common:kernel_aarch64_abi_update --lto=thin
and examine output
Change-Id: Icf55624d221238bc90dee94876fae609fd2b7894
-rw-r--r-- | kleaf/impl/kernel_env.bzl | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/kleaf/impl/kernel_env.bzl b/kleaf/impl/kernel_env.bzl index 6af722a..400510b 100644 --- a/kleaf/impl/kernel_env.bzl +++ b/kleaf/impl/kernel_env.bzl @@ -200,6 +200,21 @@ def _kernel_env_impl(ctx): if [[ "$(realpath ${{ROOT_DIR}}/${{KERNEL_DIR}})" != "${{ROOT_DIR}}/${{KERNEL_DIR}}" ]]; then export KCPPFLAGS="$KCPPFLAGS -ffile-prefix-map=$(realpath ${{ROOT_DIR}}/${{KERNEL_DIR}})/=" fi + + # HACK: For android13-5.10, the kernel image uses the realpath to stdarg.h + # under prebuilts. For sandbox builds, this means the real workspace root appears in the + # final artifact, affecting reproducibility and emitting absolute paths to ABI dump XML file. + # Determine the real workspace root by using ${{ROOT_DIR}}/${{KERNEL_DIR}}/Makefile as an + # anchor. If Makefile does not exist, we are not executing Kbuild, so it is fine that + # KCPPFLAGS are not set properly. + # See b/287304304 for details. + if [[ -L ${{ROOT_DIR}}/${{KERNEL_DIR}}/Makefile ]]; then + real_makefile=$(realpath ${{ROOT_DIR}}/${{KERNEL_DIR}}/Makefile) + real_kernel_dir=${{real_makefile%/Makefile}} + real_root_dir=${{real_kernel_dir%/${{KERNEL_DIR}}}} + export KCPPFLAGS="$KCPPFLAGS -ffile-prefix-map=${{real_kernel_dir}}/= -ffile-prefix-map=${{real_root_dir}}/=" + unset real_makefile real_kernel_dir real_root_dir + fi """.format( hermetic_tools_additional_setup = ctx.attr._hermetic_tools[HermeticToolsInfo].additional_setup, env = out_file.path, |