Working with AOSP sources

Answered

Hi everyone. I wish to use CLion for working with the C/C++ files in AOSP source code. I only want to use CLion for reading the sources, NOT for building them. For building I will use the usual command line process that is documented on AOSP website. When I try to import the source files into CLIon using compile_commands.json, it attempts to build them. Is there a way to disable this ? Basically I want CLion to just index the sources without building them.

1
7 comments

Hello!

 

It shouldn't build anything while opening project with compilation database file. Could you please explain where did you see the build?

 

Regards,

Maxim

0
Avatar
Permanently deleted user

0
Avatar
Permanently deleted user

After the "Building Symbols" and "Indexing" phase is over when I try opening a few files to check whether the indexing worked, this is what I see on top of every single file.

 

I know my compile_commands.json file is correct because using the same file I was able to use rtags (https://github.com/Andersbakken/rtags) to index the source code. Jumping to function declaration, finding references, etc. works in rtags. It would have been great if it worked in CLion too.

0

To be able to provide such features as auto import, navigation, etc, CLion should index and build symbols for all header files, including system headers. It's not a build of your project.

Probably you are running `rtags` where the path to compiler is correct. But it's not working  in CLion. In the image you attached there is a lot of error: "couldn't find compiler executable". Could you please use absolute path in compile_commands.json or update your PATH? 

 

Regards,

Maxim.

0

I have exactly the same problem: I am not able to force CLion to properly parse compile_commands.json generated for AOSP build.


> Could you please use absolute path in compile_commands.json or update your PATH?
I've done just that in my compile_commands.json:

- "prebuilts/clang/host/linux-x86/clang-2690385/bin/clang++",
+ "/home/michal/workspace/aosp/prebuilts/clang/host/linux-x86/clang-2690385/bin/clang++",

Unfortunately, this does not help much - indexing no longer shows "couldn't find compiler executable" error, but files are not indexed anyway (see sensors.cpp -- it does not have a blue rectangle that denotes files with compiler information):

 

- project root is set properly
- I've tried reimporting the project

I use bear to generate compile_commands.json. This approach always works well for me (e.g. for kernel indexing) but fails for portions of AOSP I am interested in.

E.g., here is the relevant portion of compile_commands.json of sensors.cpp file above, that is not added to index properly:

{
"arguments": [
"/home/michal/workspace/nexwell/prebuilts/clang/host/linux-x86/clang-2690385/bin/clang++",
"-c",
"-I",
"hardware/nexwell/libsensors",
"-I",
"out/target/product/nexo/obj/SHARED_LIBRARIES/sensors.nexo_intermediates",
"-I",
"out/target/product/nexo/gen/SHARED_LIBRARIES/sensors.nexo_intermediates",
"-I",
"libnativehelper/include/nativehelper",
"-I",
"external/libcxx/include",
"-I",
"external/libcxxabi/include",
"-isystem",
"system/core/include",
"-isystem",
"system/media/audio/include",
"-isystem",
"hardware/libhardware/include",
"-isystem",
"hardware/libhardware_legacy/include",
"-isystem",
"hardware/ril/include",
"-isystem",
"libnativehelper/include",
"-isystem",
"frameworks/native/include",
"-isystem",
"frameworks/native/opengl/include",
"-isystem",
"frameworks/av/include",
"-isystem",
"frameworks/base/include",
"-isystem",
"out/target/product/nexo/obj/include",
"-isystem",
"device/fsl/common/kernel-headers",
"-isystem",
"bionic/libc/arch-arm/include",
"-isystem",
"bionic/libc/include",
"-isystem",
"bionic/libc/kernel/uapi",
"-isystem",
"bionic/libc/kernel/common",
"-isystem",
"bionic/libc/kernel/uapi/asm-arm",
"-isystem",
"bionic/libm/include",
"-isystem",
"bionic/libm/include/arm",
"-fno-exceptions",
"-Wno-multichar",
"-msoft-float",
"-ffunction-sections",
"-fdata-sections",
"-funwind-tables",
"-fstack-protector-strong",
"-Wa,--noexecstack",
"-Werror=format-security",
"-D_FORTIFY_SOURCE=2",
"-fno-short-enums",
"-no-canonical-prefixes",
"-march=armv7-a",
"-mfloat-abi=softfp",
"-mfpu=neon",
"-DANDROID",
"-fmessage-length=0",
"-W",
"-Wall",
"-Wno-unused",
"-Winit-self",
"-Wpointer-arith",
"-Werror=return-type",
"-Werror=non-virtual-dtor",
"-Werror=address",
"-Werror=sequence-point",
"-Werror=date-time",
"-DNDEBUG",
"-g",
"-Wstrict-aliasing=2",
"-DNDEBUG",
"-UDEBUG",
"-D__compiler_offsetof=__builtin_offsetof",
"-Werror=int-conversion",
"-Wno-reserved-id-macro",
"-Wno-format-pedantic",
"-Wno-unused-command-line-argument",
"-fcolor-diagnostics",
"-nostdlibinc",
"-target",
"arm-linux-androideabi",
"-target",
"arm-linux-androideabi",
"-Bprebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/arm-linux-androideabi/bin",
"-fvisibility-inlines-hidden",
"-Wsign-promo",
"-Wno-inconsistent-missing-override",
"-nostdlibinc",
"-target",
"arm-linux-androideabi",
"-mthumb",
"-Os",
"-fomit-frame-pointer",
"-fno-strict-aliasing",
"-fno-rtti",
"-std=c++11",
"-fPIC",
"-D_USING_LIBCXX",
"-std=gnu++14",
"-Werror=int-to-pointer-cast",
"-Werror=pointer-to-int-cast",
"-Werror=address-of-temporary",
"-Werror=null-dereference",
"-Werror=return-type",
"-o",
"out/target/product/nexo/obj/SHARED_LIBRARIES/sensors.nexo_intermediates/sensors.o",
"hardware/nexwell/libsensors/sensors.cpp"
],
"directory": "/home/michal/workspace/nexwell",
"file": "hardware/nexwell/libsensors/sensors.cpp"
},

 

Is it possible that the custom compiler binary AOSP uses is somehow not able to provide you what you ask it for to build the index?

0
Avatar
Permanently deleted user

I had tried telling CLion about the Clang compiler used in AOSP build using the Toolchain settings. Even that didn't help. Also, my compile_commands.json already had absolute path for all compiler invocations. Still CLIon kept complaining about not being able to find the compiler. I finally gave up and went back to rtags and later ccls.

It is really strange to see CLion struggling with AOSP code. Soong documentation specifically mentions CLion (https://android.googlesource.com/platform/build/soong/+/pie-gsi/docs/clion.md) . One would expect it to work. To make it worse, the Cmake files generated by the method mentioned in the linked document have a ton of errors in the include paths. So even that cannot be used instead of compile_commands.json

0

Is there any developments? I would really love to use clion to navigate and have autocompletion while developing aosp hals.

Thanks.

0

Please sign in to leave a comment.