Skip to content

ndk-build CLANG_TIDY and SHORT_COMMANDS don't work together #680

Open

Description

@rprichard

When the ndk-build's SHORT_COMMANDS mode is enabled, ndk-build invokes clang (and clang-tidy) with a file containing all the arguments. So instead of invoking:

clang-tidy cppfile.cpp -- <arg1> <arg2>

ndk-build invokes:

clang-tidy cppfile.cpp -- @<argfile>

where argfile contains <arg1> <arg2>.

clang-tidy seems to ignore the arguments from the argfile. I see that clang-tidy sometimes handles argument-file arguments, so I'm not sure what's going on.

standalone clang-tidy test case:

$ echo 'TYPE var = 0;' > main.c
$ echo '-DTYPE=int' > argfile
$ clang-tidy main.c -- -DTYPE=int   # works
$ clang-tidy main.c -- @argfile     # fails
1 error generated.
Error while processing /usr/local/google/home/rprichard/tidytest/main.c.
/usr/local/google/home/rprichard/tidytest/main.c:1:1: error: unknown type name 'TYPE' [clang-diagnostic-error]
TYPE var = 0;
^

ndk-build test case:

mkdir jni

echo >jni/Application.mk '
    APP_ABI := arm64-v8a
'

echo >jni/Android.mk '
    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_MODULE := main
    LOCAL_SRC_FILES := main.cpp
    LOCAL_CLANG_TIDY := true
    LOCAL_SHORT_COMMANDS := true
    include $(BUILD_SHARED_LIBRARY)
'

echo >jni/main.cpp '
    #include <android/log.h>
'

ndk-build V=1

Output:

...
/usr/local/google/home/rprichard/android/ndk/out/android-ndk-r18-canary/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-tidy jni/main.cpp   -- @./obj/local/arm64-v8a/objs/main/main.cpp.tidy.cflags
1 error generated.
Error while processing /usr/local/google/home/rprichard/tidytest/jni/main.cpp.
/usr/local/google/home/rprichard/tidytest/jni/main.cpp:2:14: error: 'android/log.h' file not found [clang-diagnostic-error]
    #include <android/log.h>
             ^
...

Content of main.cpp.tidy.cflags:

-target aarch64-none-linux-android21 -ffunction-sections -fdata-sections -funwind-tables -no-canonical-prefixes -g -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -fno-exceptions -fno-rtti -gcc-toolchain /usr/local/google/home/rprichard/android/ndk/out/android-ndk-r18-canary/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 -fpic -O2 -DNDEBUG -I/usr/local/google/home/rprichard/android/ndk/out/android-ndk-r18-canary/sources/cxx-stl/system/include -Ijni -DANDROID -Wformat -Werror=format-security --sysroot /usr/local/google/home/rprichard/android/ndk/out/android-ndk-r18-canary/sysroot -isystem /usr/local/google/home/rprichard/android/ndk/out/android-ndk-r18-canary/sysroot/usr/include/aarch64-linux-android -c

If I run clang-tidy with those commands it works:

$ /usr/local/google/home/rprichard/android/ndk/out/android-ndk-r18-canary/toolchains/llvm/prebuilt/linux-x86_64/bin/clang-tidy jni/main.cpp   -- -target aarch64-none-linux-android21 -ffunction-sections -fdata-sections -funwind-tables -no-canonical-prefixes -g -Wno-invalid-command-line-argument -Wno-unused-command-line-argument -fno-exceptions -fno-rtti -gcc-toolchain /usr/local/google/home/rprichard/android/ndk/out/android-ndk-r18-canary/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64 -fpic -O2 -DNDEBUG -I/usr/local/google/home/rprichard/android/ndk/out/android-ndk-r18-canary/sources/cxx-stl/system/include -Ijni -DANDROID -Wformat -Werror=format-security --sysroot /usr/local/google/home/rprichard/android/ndk/out/android-ndk-r18-canary/sysroot -isystem /usr/local/google/home/rprichard/android/ndk/out/android-ndk-r18-canary/sysroot/usr/include/aarch64-linux-android -c
<no output>

The new CLANG_TIDY mode has been added recently to master; it's not in r17.

@stephenhines @pirama-arumuga-nainar I'm guessing this is a clang-tidy bug?

Activity

  1. stephenhines commented on Apr 26, 2018

    @stephenhines

    Chih-hung, it appears to me that clang-tidy's driver doesn't support response files at all. This should probably be something that gets added.

  2. chih-hung commented on Apr 30, 2018

    @chih-hung
  3. stephenhines commented on Apr 30, 2018

    @stephenhines

    Yeah, I think that CL talks about using/creating response files for the parameters in the compilation database, but being able to expand a response file (to possibly even put it in the compilation database) seems separate.

  4. added this to the external dependency milestone on Oct 19, 2018
  5. moved this to Awaiting triage in LLVMon Oct 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Type

No type

Projects

  • Status
    Awaiting triage

Relationships

None yet

Development

No branches or pull requests

Issue actions