diff --git a/build/ndk-build b/build/ndk-build index 84d423e7..312912d7 100755 --- a/build/ndk-build +++ b/build/ndk-build @@ -61,6 +61,7 @@ fi PROJECT_PATH= PROJECT_PATH_NEXT= +NDK_ANALYZER_OUT= for opt; do if [ -z "$PROJECT_PATH" -a "$PROJECT_PATH_NEXT" = "yes" ] ; then PROJECT_PATH=$opt @@ -79,6 +80,9 @@ for opt; do NDK_ANALYZE=*) NDK_ANALYZE=0 ;; + NDK_ANALYZER_OUT=*) + NDK_ANALYZER_OUT=${opt#NDK_ANALYZER_OUT=} + ;; NDK_TOOLCHAIN_VERSION=*) NDK_TOOLCHAIN_VERSION=${opt#NDK_TOOLCHAIN_VERSION=} ;; @@ -264,6 +268,7 @@ if [ "$NDK_ANALYZE" = 1 ]; then for ABI in $APP_ABIS; do TOOLCHAIN_PREFIX=`get_build_var_for_abi TOOLCHAIN_PREFIX $ABI` LLVM_PATH=$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$HOST_TAG + ANALYZER_OUT=`get_build_var NDK_APP_ANALYZER_OUT` if [ "$TOOLCHAIN" = "clang" ]; then ANALYZER_CC=$LLVM_PATH/bin/clang @@ -273,11 +278,17 @@ if [ "$NDK_ANALYZE" = 1 ]; then ANALYZER_CXX=${TOOLCHAIN_PREFIX}g++ fi + ANALYZER_OUT_FLAG= + if [ -n "$NDK_ANALYZER_OUT" ]; then + ANALYZER_OUT_FLAG="-o $NDK_ANALYZER_OUT/$ABI" + fi + perl $LLVM_PATH/tools/scan-build/bin/scan-build \ --use-analyzer $LLVM_PATH/bin/${ABI}/analyzer \ --use-cc $ANALYZER_CC \ --use-c++ $ANALYZER_CXX \ --status-bugs \ + $ANALYZER_OUT_FLAG \ $GNUMAKE -f $PROGDIR/core/build-local.mk "$@" APP_ABI=$ABI done else diff --git a/tests/build/NDK_ANALYZE/project/jni/foo.cpp b/tests/build/NDK_ANALYZE/project/jni/foo.cpp index 85e6cd8c..6aaa547a 100644 --- a/tests/build/NDK_ANALYZE/project/jni/foo.cpp +++ b/tests/build/NDK_ANALYZE/project/jni/foo.cpp @@ -1 +1,5 @@ -void foo() {} +#include + +void foo() { + malloc(0); +} diff --git a/tests/build/NDK_ANALYZE/test.py b/tests/build/NDK_ANALYZE/test.py index 519facbc..5344a303 100644 --- a/tests/build/NDK_ANALYZE/test.py +++ b/tests/build/NDK_ANALYZE/test.py @@ -22,12 +22,25 @@ def run_test(abi, platform, _toolchain, build_flags): ndk_dir = os.environ['NDK'] ndk_build = os.path.join(ndk_dir, 'ndk-build') project_path = 'project' + analyzer_out = os.path.join(project_path, 'report') ndk_args = build_flags + [ 'APP_ABI=' + abi, 'APP_PLATFORM=android-{}'.format(platform), 'NDK_ANALYZE=1', + 'NDK_ANALYZER_OUT=' + analyzer_out, ] proc = subprocess.Popen([ndk_build, '-C', project_path] + ndk_args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) out, _ = proc.communicate() - return proc.returncode == 0, out + # We expect the analyzer to find an issue and exit with a failure. + if proc.returncode == 0: + return False, out + + analyzer_abi_out = os.path.join(analyzer_out, abi) + # The out directory gets created even if the analyzer fails, so we + # intentionally include bad code and make sure we get a failure report. + reports = os.listdir(analyzer_abi_out) + if len(reports) == 0: + return False, 'No analyzer output found in ' + analyzer_abi_out + + return True, out diff --git a/tests/build/NDK_ANALYZE/test_config.py b/tests/build/NDK_ANALYZE/test_config.py index 8ea0127b..80f96940 100644 --- a/tests/build/NDK_ANALYZE/test_config.py +++ b/tests/build/NDK_ANALYZE/test_config.py @@ -5,6 +5,4 @@ def build_unsupported(_abi, _api, toolchain): if sys.platform == 'win32': return sys.platform - if toolchain != 'clang': - return toolchain return None