Android/Soongでcompile_commands.jsonを出す

/ Android

Android platformビルド時のcompile_commands.jsonの出し方

下記に直接的な解決策が書かれている。

通常通り、

source build/envsetup.sh
lunch sdk_car_x86_64-userdebug
export SOONG_GEN_COMPDB=1
export SOONG_GEN_COMPDB_DEBUG=1
mkdir .vscode
export SOONG_LINK_COMPDB_TO=.vscode
mm nothing

とすると、.vscode/compile_commands.jsonにシンボリックリンクが作成される。

============================================
[100% 1/1] analyzing Android.bp files and generating ninja file at out/soong/build.ninja
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/linux_glibc_x86_64/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/linux_glibc_x86_64_apex10000/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/linux_glibc_x86/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/linux_glibc_x86_apex10000/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/windows_x86/obj/external/boringssl/src/crypto/fipsmodule/bcm.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/windows_x86_64/obj/external/boringssl/src/crypto/fipsmodule/bcm.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_x86_64/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_x86_64_apex10000/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_x86_64_apex29/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_x86_64_apex30/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_x86_64_apex31/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_x86_64_apex33/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_x86_64_sdk/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_x86_x86_64/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_x86_x86_64_apex29/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_x86_x86_64_apex30/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_x86_x86_64_apex31/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_x86_x86_64_sdk/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_ramdisk_x86_64/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_vendor_ramdisk_x86_64/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_recovery_x86_64/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_vendor.33_x86_64/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_vendor.33_x86_x86_64/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_product.33_x86_64/bcm_object.o
2025/01/04 16:53:03 Unknown file extension .o on file out/soong/.intermediates/external/boringssl/bcm_object/android_product.33_x86_x86_64/bcm_object.o
[100% 2/2] Successfully read the makefiles.

#### build completed successfully (18:26 (mm:ss)) ####

.vscode/c_cpp_properties.jsonで生成されたcompile_commands.jsonを指定しておくとエディタが認識する。

{
    "configurations": [
        {
            "name": "Linux",
            "defines": [],
            "compilerPath": "/usr/bin/clang",
            "cStandard": "c17",
            "cppStandard": "c++17",
            "compileCommands": "${workspaceFolder}/.vscode/compile_commands.json",
            "intelliSenseMode": "linux-clang-x64",
            "browse": {
                "path": [
                    "${workspaceFolder}/art",
                    "${workspaceFolder}/bionic",
                    "${workspaceFolder}/bootable",
                    "${workspaceFolder}/build",
                    "${workspaceFolder}/cts",
                    "${workspaceFolder}/dalvik",
                    "${workspaceFolder}/developers",
                    "${workspaceFolder}/development",
                    "${workspaceFolder}/device",
                    "${workspaceFolder}/external",
                    "${workspaceFolder}/frameworks",
                    "${workspaceFolder}/hardware",
                    "${workspaceFolder}/kernel",
                    "${workspaceFolder}/libcore",
                    "${workspaceFolder}/libnativehelper",
                    "${workspaceFolder}/packages",
                    "${workspaceFolder}/pdk",
                    "${workspaceFolder}/platform_testing",
                    "${workspaceFolder}/prebuilts",
                    "${workspaceFolder}/product",
                    "${workspaceFolder}/sdk",
                    "${workspaceFolder}/system",
                    "${workspaceFolder}/test",
                    "${workspaceFolder}/toolchain",
                    "${workspaceFolder}/tools"
                    ],
                "databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db"
            }
        }
    ],
    "version": 4
}

なお、重すぎて動かないし解析進捗もわからない。