diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9eda04ce9..9c8d353ac 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -95,6 +95,13 @@ cmake .. cmake --build . ``` +#### Static Analysis +When the project is built using MSVC on Windows, the compiler can run [static analysis](https://docs.microsoft.com/cpp/code-quality/walkthrough-analyzing-c-cpp-code-for-defects) on the code. The CMake project can add the required compiler flags to perform this check. To enable this feature, set an environment variable `AZURE_ENABLE_STATIC_ANALYSIS`. + +Keep in mind that enabling static analysis will significantly impact build time. It is recommended to run it right before submitting the PR, but not in your inner developer loop. + +The static code analysis is `ON` for the CI pipelines. You can turn this feature `ON` locally to debug errors reported during CI or for the last time you build and test before creating a new PR. + #### CMake build options The following CMake options are available for adding/removing project features. diff --git a/cmake-modules/global_compile_options.cmake b/cmake-modules/global_compile_options.cmake index d86769775..63fa2a776 100644 --- a/cmake-modules/global_compile_options.cmake +++ b/cmake-modules/global_compile_options.cmake @@ -12,7 +12,13 @@ if(MSVC) string(REGEX REPLACE "/W3" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") #https://stackoverflow.com/questions/37527946/warning-unreferenced-inline-function-has-been-removed - add_compile_options(/W4 ${WARNINGS_AS_ERRORS_FLAG} /wd5031 /wd4668 /wd4820 /wd4255 /wd4710 /analyze) + add_compile_options(/W4 ${WARNINGS_AS_ERRORS_FLAG} /wd5031 /wd4668 /wd4820 /wd4255 /wd4710) + + # NOTE: Static analysis will slow building time considerably and it is run during CI gates. + # It is better to turn in on to debug errors reported by CI than have it ON all the time. + if (DEFINED ENV{AZURE_ENABLE_STATIC_ANALYSIS}) + add_compile_options(/analyze) + endif() elseif(CMAKE_C_COMPILER_ID MATCHES "Clang") if(WARNINGS_AS_ERRORS) set(WARNINGS_AS_ERRORS_FLAG "-Werror") diff --git a/eng/pipelines/templates/jobs/archetype-sdk-client.yml b/eng/pipelines/templates/jobs/archetype-sdk-client.yml index d436d0c43..1179c932d 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-client.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-client.yml @@ -37,12 +37,14 @@ jobs: CMAKE_GENERATOR: 'Visual Studio 16 2019' CMAKE_GENERATOR_PLATFORM: Win32 CmakeArgs: ' -DBUILD_TRANSPORT_CURL=ON' #Leaving curl on here to explicitly test what the default behavior is on windows. + BuildArgs: '-v --parallel 8' Win_x64: OSVmImage: 'windows-2019' VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json' VCPKG_DEFAULT_TRIPLET: 'x64-windows-static' CMAKE_GENERATOR: 'Visual Studio 16 2019' CMAKE_GENERATOR_PLATFORM: x64 + BuildArgs: '-v --parallel 8' MacOS_x64: OSVmImage: 'macOS-10.14' VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json' @@ -66,6 +68,7 @@ jobs: CMAKE_GENERATOR: 'Visual Studio 16 2019' CMAKE_GENERATOR_PLATFORM: Win32 CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON -DBUILD_TRANSPORT_WINHTTP=ON' + BuildArgs: '-v --parallel 8' Win_x64_with_unit_test: OSVmImage: 'windows-2019' VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json' @@ -73,6 +76,7 @@ jobs: CMAKE_GENERATOR: 'Visual Studio 16 2019' CMAKE_GENERATOR_PLATFORM: x64 CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON -DBUILD_TRANSPORT_CURL=ON -DBUILD_TRANSPORT_WINHTTP=ON' + BuildArgs: '-v --parallel 8' MacOS_x64_with_unit_test: OSVmImage: 'macOS-10.14' VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json' @@ -84,6 +88,7 @@ jobs: CMOCKA_XML_FILE: "%g-test-results.xml" CMOCKA_MESSAGE_OUTPUT: "xml" BuildArgs: "" + AZURE_ENABLE_STATIC_ANALYSIS: 1 steps: - checkout: self diff --git a/eng/pipelines/templates/jobs/archetype-sdk-tests.yml b/eng/pipelines/templates/jobs/archetype-sdk-tests.yml index 91b1b2804..7b25db8d0 100644 --- a/eng/pipelines/templates/jobs/archetype-sdk-tests.yml +++ b/eng/pipelines/templates/jobs/archetype-sdk-tests.yml @@ -39,6 +39,7 @@ jobs: CMAKE_GENERATOR: 'Visual Studio 16 2019' CMAKE_GENERATOR_PLATFORM: Win32 CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON' + BuildArgs: '-v --parallel 8' Win_x64_with_unit_test: OSVmImage: 'windows-2019' VcpkgInstall: 'curl[winssl] libxml2 nlohmann-json' @@ -46,6 +47,7 @@ jobs: CMAKE_GENERATOR: 'Visual Studio 16 2019' CMAKE_GENERATOR_PLATFORM: x64 CmakeArgs: ' -DBUILD_TESTING=ON -DRUN_LONG_UNIT_TESTS=ON' + BuildArgs: '-v --parallel 8' MacOS_x64_with_unit_test: OSVmImage: 'macOS-10.14' VcpkgInstall: 'curl[ssl] libxml2 openssl nlohmann-json' @@ -56,6 +58,7 @@ jobs: variables: CMOCKA_XML_FILE: "%g-test-results.xml" CMOCKA_MESSAGE_OUTPUT: "xml" + AZURE_ENABLE_STATIC_ANALYSIS: 1 steps: - checkout: self @@ -111,4 +114,4 @@ jobs: - template: /eng/common/TestResources/remove-test-resources.yml parameters: ServiceDirectory: ${{ parameters.ServiceDirectory }} - SubscriptionConfiguration: ${{ parameters.SubscriptionConfiguration }} \ No newline at end of file + SubscriptionConfiguration: ${{ parameters.SubscriptionConfiguration }}