Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to generate compile_commands.json on Android Kernel build. #233

Open
acama opened this issue Dec 7, 2024 · 0 comments

Comments

@acama
Copy link

acama commented Dec 7, 2024

Hi I get an error when trying to use this tool to get compile_commands.json on an Android kernel build (Oneplus 12). I am ware that Android provides a way to get compile_commands.json but it is very incomplete when it is something other than the common kernel (so like a real kernel on device) so I am not using that. This is what my WORKSPACE file looks like:

# 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.
#
# Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")


# Hedron's Compile Commands Extractor for Bazel
# https://github.com/hedronvision/bazel-compile-commands-extractor
http_archive(
    name = "hedron_compile_commands",

    # Replace the commit hash (0e990032f3c5a866e72615cf67e5ce22186dcb97) in both places (below) with the latest (https://github.com/hedronvision/bazel-compile-commands-extractor/commits/main), rather than using the stale one here.
    # Even better, set up Renovate and let it do the work for you (see "Suggestion: Updates" in the README).
    url = "https://github.com/hedronvision/bazel-compile-commands-extractor/archive/4f28899228fb3ad0126897876f147ca15026151e.tar.gz",
    strip_prefix = "bazel-compile-commands-extractor-4f28899228fb3ad0126897876f147ca15026151e",
    # When you first run this tool, it'll recommend a sha256 hash to put here with a message like: "DEBUG: Rule 'hedron_compile_commands' indicated that a canonical reproducible form can be obtained by modifying arguments sha256 = ..."
)
load("@hedron_compile_commands//:workspace_setup.bzl", "hedron_compile_commands_setup")
hedron_compile_commands_setup()
load("@hedron_compile_commands//:workspace_setup_transitive.bzl", "hedron_compile_commands_setup_transitive")
hedron_compile_commands_setup_transitive()
load("@hedron_compile_commands//:workspace_setup_transitive_transitive.bzl", "hedron_compile_commands_setup_transitive_transitive")
hedron_compile_commands_setup_transitive_transitive()
load("@hedron_compile_commands//:workspace_setup_transitive_transitive_transitive.bzl", "hedron_compile_commands_setup_transitive_transitive_transitive")
hedron_compile_commands_setup_transitive_transitive_transitive()

### build/kernel/kleaf/bazel.WORKSPACE contents ###
load("//build/kernel/kleaf:workspace.bzl", "define_kleaf_workspace")

define_kleaf_workspace()

# Optional epilog for analysis testing.
load("//build/kernel/kleaf:workspace_epilog.bzl", "define_kleaf_workspace_epilog")
define_kleaf_workspace_epilog()

### Qualcomm customizations ###
new_local_repository(
    name = "dtc",
    path = "external/dtc",
    build_file = "msm-kernel/BUILD.dtc",
)

After building the kernel successfully I then try to run tools/bazel run @hedron_compile_commands//:refresh_all and I get:

root@Ubuntu-2204-jammy-amd64-base ~/sources/oneplus12/kernel_platform # tools/bazel run @hedron_compile_commands//:refresh_all --sandbox_debug
INFO: Analyzed target @hedron_compile_commands//:refresh_all (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
[0 / 3] [Prepa] BazelWorkspaceStatusAction stable-status.txt
ndbox.cc:156: calling pipe(2)...
1733606729.163652683: src/main/tools/linux-sandbox.cc:165: Netns is 0
1733606729.163657984: src/main/tools/linux-sandbox.cc:176: calling clone(2)...
1733606729.164030850: src/main/tools/linux-sandbox.cc:185: linux-sandbox-pid1 has PID 3227263
1733606729.164197769: src/main/tools/linux-sandbox-pid1.cc:700: Pid1Main started
1733606729.164384473: src/main/tools/linux-sandbox.cc:202: done manipulating pipes
1733606729.164655455: src/main/tools/linux-sandbox-pid1.cc:311: writable: /root/sources/oneplus12/kernel_platform/out/bazel/output_user_root/7805a789231cf4f63952908734fee831/sandbox/linux-sandbox/812/execroot/__main__
1733606729.164719699: src/main/tools/linux-sandbox-pid1.cc:311: writable: /tmp
1733606729.164758038: src/main/tools/linux-sandbox-pid1.cc:311: writable: /dev/shm
1733606729.164777807: src/main/tools/linux-sandbox-pid1.cc:327: working dir: /root/sources/oneplus12/kernel_platform/out/bazel/output_user_root/7805a789231cf4f63952908734fee831/sandbox/linux-sandbox/812/execroot/__main__
1733606729.164950157: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /
1733606729.164970215: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /dev
1733606729.164984865: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /dev/pts
1733606729.164998951: src/main/tools/linux-sandbox-pid1.cc:405: remount rw: /dev/shm
1733606729.165008831: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /dev/hugepages
1733606729.165022471: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /dev/mqueue
1733606729.165036686: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /run
1733606729.165050465: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /run/lock
1733606729.165063540: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /run/credentials/systemd-sysusers.service
1733606729.165075494: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /run/user/0
1733606729.165089895: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /sys
1733606729.165102875: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /sys/kernel/security
1733606729.165120590: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /sys/fs/cgroup
1733606729.165135300: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /sys/fs/pstore
1733606729.165193474: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /sys/firmware/efi/efivars
1733606729.165209933: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /sys/fs/bpf
1733606729.165223033: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /sys/kernel/tracing
1733606729.165235795: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /sys/kernel/debug
1733606729.165248663: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /sys/fs/fuse/connections
1733606729.165263988: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /sys/kernel/config
1733606729.165277262: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /proc
1733606729.165291318: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /proc/sys/fs/binfmt_misc
1733606729.165305772: src/main/tools/linux-sandbox-pid1.cc:427: remount(nullptr, /proc/sys/fs/binfmt_misc, nullptr, 2101281, nullptr) failure (Operation not permitted) ignored
1733606729.165322397: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /proc/sys/fs/binfmt_misc
1733606729.165335247: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /boot
1733606729.165348916: src/main/tools/linux-sandbox-pid1.cc:405: remount ro: /boot/efi
1733606729.165374402: src/main/tools/linux-sandbox-pid1.cc:405: remount rw: /root/sources/oneplus12/kernel_platform/out/bazel/output_user_root/7805a789231cf4f63952908734fee831/sandbox/linux-sandbox/812/execroot/__main__
1733606729.165385547: src/main/tools/linux-sandbox-pid1.cc:405: remount rw: /tmp
1733606729.165395002: src/main/tools/linux-sandbox-pid1.cc:405: remount rw: /dev/shm
1733606729.165403606: src/main/tools/linux-sandbox-pid1.cc:405: remount rw: /root/sources/oneplus12/kernel_platform/out/bazel/output_user_root/7805a789231cf4f63952908734fee831/sandbox/linux-sandbox/812/execroot/__main__
1733606729.165544030: src/main/tools/linux-sandbox-pid1.cc:496: calling fork...
1733606729.165784357: src/main/tools/linux-sandbox-pid1.cc:533: child started with PID 2
1733606729.184080880: src/main/tools/linux-sandbox-pid1.cc:550: wait returned pid=2, status=0x100
1733606729.184114300: src/main/tools/linux-sandbox-pid1.cc:568: child exited normally with code 1
1733606729.186815499: src/main/tools/linux-sandbox.cc:243: child exited normally with code 1
ERROR: /root/sources/oneplus12/kernel_platform/out/bazel/output_user_root/7805a789231cf4f63952908734fee831/external/hedron_compile_commands/BUILD:30:10: Compiling print_args.cpp failed: (Exit 1): linux-sandbox failed: error executing CppCompile command
  (cd /root/sources/oneplus12/kernel_platform/out/bazel/output_user_root/7805a789231cf4f63952908734fee831/sandbox/linux-sandbox/812/execroot/__main__ && \
  exec env - \
    BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 \
    PATH=/bin:/usr/bin:/usr/local/bin \
    PWD=/proc/self/cwd \
    TMPDIR=/tmp \
  /root/sources/oneplus12/kernel_platform/out/bazel/output_user_root/install/7924869d3f6695d7ef5e02d62f3d0252/linux-sandbox -t 15 -w /root/sources/oneplus12/kernel_platform/out/bazel/output_user_root/7805a789231cf4f63952908734fee831/sandbox/linux-sandbox/812/execroot/__main__ -w /tmp -w /dev/shm -S /root/sources/oneplus12/kernel_platform/out/bazel/output_user_root/7805a789231cf4f63952908734fee831/sandbox/linux-sandbox/812/stats.out -D /root/sources/oneplus12/kernel_platform/out/bazel/output_user_root/7805a789231cf4f63952908734fee831/sandbox/linux-sandbox/812/debug.out -- prebuilts/clang/host/linux-x86/clang-r487747c/bin/clang++ -MD -MF bazel-out/k8-fastbuild/bin/external/hedron_compile_commands/_objs/print_args/print_args.d '-frandom-seed=bazel-out/k8-fastbuild/bin/external/hedron_compile_commands/_objs/print_args/print_args.o' '-DBAZEL_CURRENT_REPOSITORY="hedron_compile_commands"' -iquote external/hedron_compile_commands -iquote bazel-out/k8-fastbuild/bin/external/hedron_compile_commands -iquote external/bazel_tools -iquote bazel-out/k8-fastbuild/bin/external/bazel_tools -no-canonical-prefixes '--sysroot=build/kernel/build-tools/sysroot' -c external/hedron_compile_commands/print_args.cpp -o bazel-out/k8-fastbuild/bin/external/hedron_compile_commands/_objs/print_args/print_args.o)
external/hedron_compile_commands/print_args.cpp:3:10: fatal error: 'iostream' file not found
#include <iostream>
         ^~~~~~~~~~
1 error generated.
Target @hedron_compile_commands//:refresh_all failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 1.071s, Critical Path: 0.12s
INFO: 2 processes: 2 internal.
ERROR: Build did NOT complete successfully
ERROR: Build failed. Not running target

Android kernel build systems use some prebuilts in order to compile the kernel. It seems like somehow bazel is only copying the bin and lib folders without the include folders in the exec root for some reason for the bazel-compile-commands-extractor.
Is there something I can do to solve this problem ?
Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant