From 0cfc4ec09def573db8d5927a330bee3e4b1b067b Mon Sep 17 00:00:00 2001 From: Edward Chen <18449977+edgchen1@users.noreply.github.com> Date: Thu, 26 Aug 2021 09:13:52 -0700 Subject: [PATCH] [Objective-C] Enable static analysis (#8842) Add Objective-C API static analysis pipeline. --- .../static_analysis/requirements.txt | 2 + .../mac-objc-static-analysis-ci-pipeline.yml | 66 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 tools/ci_build/github/apple/objectivec/static_analysis/requirements.txt create mode 100644 tools/ci_build/github/azure-pipelines/mac-objc-static-analysis-ci-pipeline.yml diff --git a/tools/ci_build/github/apple/objectivec/static_analysis/requirements.txt b/tools/ci_build/github/apple/objectivec/static_analysis/requirements.txt new file mode 100644 index 0000000000..b3868a3a7c --- /dev/null +++ b/tools/ci_build/github/apple/objectivec/static_analysis/requirements.txt @@ -0,0 +1,2 @@ +codechecker==6.16.0 +ninja==1.10.2 diff --git a/tools/ci_build/github/azure-pipelines/mac-objc-static-analysis-ci-pipeline.yml b/tools/ci_build/github/azure-pipelines/mac-objc-static-analysis-ci-pipeline.yml new file mode 100644 index 0000000000..29e855de2f --- /dev/null +++ b/tools/ci_build/github/azure-pipelines/mac-objc-static-analysis-ci-pipeline.yml @@ -0,0 +1,66 @@ +jobs: +- job: ObjCStaticAnalysis + + pool: + vmImage: 'macOS-10.15' + + timeoutInMinutes: 10 + + steps: + - task: UsePythonVersion@0 + inputs: + versionSpec: "3.9" + addToPath: true + architecture: "x64" + + - script: | + pip install -r tools/ci_build/github/apple/objectivec/static_analysis/requirements.txt + displayName: Install tools + + - script: | + python tools/ci_build/build.py \ + --build_dir "$(Build.BinariesDirectory)" \ + --cmake_generator "Ninja" \ + --config Debug \ + --build_shared_lib --use_coreml --build_objc \ + --cmake_extra_defines CMAKE_EXPORT_COMPILE_COMMANDS=ON \ + --update + displayName: Generate compile_commands.json + + - script: | + set -e + + LLVM_DIR="$(brew --prefix llvm)" + CODECHECKER_CONFIG_FILE="$(dirname $(which codechecker))/../share/codechecker/config/package_layout.json" + + sed -i "" \ + -e 's#"clangsa": "[^"]*"#"clangsa": "'"${LLVM_DIR}"'/bin/clang"#' \ + -e 's#"clang-tidy": "[^"]*"#"clang-tidy": "'"${LLVM_DIR}"'/bin/clang-tidy"#' \ + "${CODECHECKER_CONFIG_FILE}" + + cat "${CODECHECKER_CONFIG_FILE}" + displayName: Update CodeChecker configuration + + - script: | + codechecker analyze \ + --file "$(Build.SourcesDirectory)/objectivec/*" \ + "$(Build.SourcesDirectory)/onnxruntime/core/platform/apple/logging/apple_log_sink.mm" \ + "$(Build.SourcesDirectory)/onnxruntime/core/providers/coreml/model/*.mm" \ + --output "$(Build.BinariesDirectory)/codechecker.analyze.out" \ + "$(Build.BinariesDirectory)/Debug/compile_commands.json" + + CODECHECKER_ANALYZE_EXIT_CODE=$? + echo "codechecker analyze exited with code: ${CODECHECKER_ANALYZE_EXIT_CODE}" + displayName: Run CodeChecker analysis + + - script: | + # skip results from external dependencies + echo "-$(Build.SourcesDirectory)/cmake/external/*" > "$(Build.BinariesDirectory)/codechecker.parse.skipfile" + + codechecker parse \ + --ignore "$(Build.BinariesDirectory)/codechecker.parse.skipfile" \ + "$(Build.BinariesDirectory)/codechecker.analyze.out" + + CODECHECKER_PARSE_EXIT_CODE=$? + echo "codechecker parse exited with code: ${CODECHECKER_PARSE_EXIT_CODE}" + displayName: Show CodeChecker analysis results