Skip to content

Commit

Permalink
[SCRIPT] Add support for compiler static analysis in build scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
Takishima committed Nov 18, 2022
1 parent 4209878 commit 0a25ca4
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ rem ============================================================================
goto :END
)

if /I "%1" == "/analyzer" (
set enable_analyzer=1
shift & goto :initial
)

if /I "%1" == "/N" (
set dry_run=1
shift & goto :initial
Expand Down Expand Up @@ -344,6 +349,7 @@ if !build_isolation! == 0 set args=!args! --no-isolation
set RETVAL=
call %SCRIPTDIR%\dos\build_cmake_option.bat BUILD_TESTING !enable_tests!
call %SCRIPTDIR%\dos\build_cmake_option.bat CLEAN_3RDPARTY_INSTALL_DIR !do_clean_3rdparty!
call %SCRIPTDIR%\dos\build_cmake_option.bat ENABLE_ANALYZER !enable_analyzer!
call %SCRIPTDIR%\dos\build_cmake_option.bat ENABLE_CMAKE_DEBUG !cmake_debug_mode!
call %SCRIPTDIR%\dos\build_cmake_option.bat ENABLE_CUDA !enable_gpu!
call %SCRIPTDIR%\dos\build_cmake_option.bat ENABLE_CXX_EXPERIMENTAL !enable_cxx!
Expand Down Expand Up @@ -467,6 +473,7 @@ rem ============================================================================
echo /H,/help Show this help message and exit
echo /N Dry run; only print commands but do not execute them
echo
echo /Analyzer Use the compiler static analysis tool during compilation (GCC & MSVC)
echo /B,/Build [dir] Specify build directory
echo Defaults to: %build_dir%
echo /Clean3rdParty Clean 3rd party installation directory
Expand Down
5 changes: 5 additions & 0 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

Param(
[switch]$Analyzer,
[Alias("B")][ValidateNotNullOrEmpty()][string]$Build,
[switch]$BuildIsolation,
[switch]$CCache,
Expand Down Expand Up @@ -239,6 +240,7 @@ $build_args = @()
$cmake_option_names = @{
cmake_debug_mode = 'ENABLE_CMAKE_DEBUG'
do_clean_3rdparty = 'CLEAN_3RDPARTY_INSTALL_DIR'
enable_analyzer = 'ENABLE_ANALYZER'
enable_cxx = 'ENABLE_CXX_EXPERIMENTAL'
enable_gitee = 'ENABLE_GITEE'
enable_gpu = 'ENABLE_CUDA'
Expand Down Expand Up @@ -444,6 +446,9 @@ knows how to find them.
A pth-file will be created in the virtualenv site-packages directory so that the MindQuantum root folder will be added
to the Python PATH without the need to modify PYTHONPATH.
.PARAMETER Analyzer
Use the compiler static analysis tool during compilation (GCC & MSVC)
.PARAMETER Build
Specify build directory. Defaults to: Path\To\Script\build
Expand Down
1 change: 1 addition & 0 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ args=()
declare_AA cmake_option_names
set_AA cmake_option_names cmake_debug_mode ENABLE_CMAKE_DEBUG
set_AA cmake_option_names do_clean_3rdparty CLEAN_3RDPARTY_INSTALL_DIR
set_AA cmake_option_names enable_analyzer ENABLE_ANALYZER
set_AA cmake_option_names enable_cxx ENABLE_CXX_EXPERIMENTAL
set_AA cmake_option_names enable_gitee ENABLE_GITEE
set_AA cmake_option_names enable_gpu ENABLE_CUDA
Expand Down
7 changes: 7 additions & 0 deletions build_locally.bat
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ rem ============================================================================
shift & goto :initial
)

if /I "%1" == "/analyzer" (
set enable_analyzer=1
shift & goto :initial
)

if /I "%1" == "/B" set result=true
if /I "%1" == "/Build" set result=true
if "%result%" == "true" (
Expand Down Expand Up @@ -336,6 +341,7 @@ set cmake_args="-DIN_PLACE_BUILD:BOOL=ON -DIS_PYTHON_BUILD:BOOL=OFF -DCMAKE_EXPO
set RETVAL=
call %SCRIPTDIR%\dos\build_locally_cmake_option.bat BUILD_TESTING !enable_tests!
call %SCRIPTDIR%\dos\build_locally_cmake_option.bat CLEAN_3RDPARTY_INSTALL_DIR !do_clean_3rdparty!
call %SCRIPTDIR%\dos\build_locally_cmake_option.bat ENABLE_ANALYZER !enable_analyzer!
call %SCRIPTDIR%\dos\build_locally_cmake_option.bat ENABLE_CMAKE_DEBUG !cmake_debug_mode!
call %SCRIPTDIR%\dos\build_locally_cmake_option.bat ENABLE_CUDA !enable_gpu!
call %SCRIPTDIR%\dos\build_locally_cmake_option.bat ENABLE_CXX_EXPERIMENTAL !enable_cxx!
Expand Down Expand Up @@ -523,6 +529,7 @@ exit /B 0
echo Options:
echo /H,/Help Show this help message and exit
echo /N Dry run; only print commands but do not execute them
echo /Analyzer Use the compiler static analysis tool during compilation (GCC & MSVC)
echo /B,/Build [dir] Specify build directory
echo Defaults to: %build_dir%
echo /C,/Clean Run make clean before building
Expand Down
5 changes: 5 additions & 0 deletions build_locally.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

Param(
[ValidateNotNullOrEmpty()][string]$A,
[switch]$Analyzer,
[Alias("B")][ValidateNotNullOrEmpty()][string]$Build,
[switch]$CCache,
[switch]$CMakeNoRegistry,
Expand Down Expand Up @@ -239,6 +240,7 @@ $cmake_args = @('-DIN_PLACE_BUILD:BOOL=ON'
'-DIS_PYTHON_BUILD:BOOL=OFF'
'-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON'
"-DCMAKE_BUILD_TYPE:STRING={0}" -f $build_type
"-DENABLE_ANALYZER:BOOL={0}" -f $CMAKE_BOOL[$enable_analyzer]
"-DENABLE_PROJECTQ:BOOL={0}" -f $CMAKE_BOOL[$enable_projectq]
"-DENABLE_CMAKE_DEBUG:BOOL={0}" -f $CMAKE_BOOL[$cmake_debug_mode]
"-DENABLE_CUDA:BOOL={0}" -f $CMAKE_BOOL[$enable_gpu]
Expand Down Expand Up @@ -392,6 +394,9 @@ knows how to find them.
A pth-file will be created in the virtualenv site-packages directory so that the MindQuantum root folder will be added
to the Python PATH without the need to modify PYTHONPATH.
.PARAMETER Analyzer
Use the compiler static analysis tool during compilation (GCC & MSVC)
.PARAMETER Build
Specify build directory. Defaults to: Path\To\Script\build
Expand Down
1 change: 1 addition & 0 deletions build_locally.sh
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ cmake_args=(-DIN_PLACE_BUILD:BOOL=ON
-DIS_PYTHON_BUILD:BOOL=OFF
-DCMAKE_EXPORT_COMPILE_COMMANDS:BOOL=ON
-DCMAKE_BUILD_TYPE:STRING="$build_type"
-DENABLE_ANALYZER:BOOL="${CMAKE_BOOL[$enable_analyzer]}"
-DENABLE_PROJECTQ:BOOL="${CMAKE_BOOL[$enable_projectq]}"
-DENABLE_CMAKE_DEBUG:BOOL="${CMAKE_BOOL[$cmake_debug_mode]}"
-DENABLE_CUDA:BOOL="${CMAKE_BOOL[$enable_gpu]}"
Expand Down
1 change: 1 addition & 0 deletions scripts/build/default_values.bat
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ if NOT DEFINED do_clean_cache set do_clean_cache=0
if NOT DEFINED do_clean_venv set do_clean_venv=0
if NOT DEFINED do_update_venv set do_update_venv=0
if NOT DEFINED dry_run set dry_run=0
if NOT DEFINED enable_analyzer set enable_analyzer=0
if NOT DEFINED enable_ccache set enable_ccache=0
if NOT DEFINED enable_cxx set enable_cxx=0
if NOT DEFINED enable_gitee set enable_gitee=0
Expand Down
1 change: 1 addition & 0 deletions scripts/build/default_values.conf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ do_clean_venv = false
do_update_venv = false

[common.features]
enable_analyzer = false
enable_gitee = false
enable_ccache = false
enable_cxx = false
Expand Down
5 changes: 5 additions & 0 deletions scripts/build/parse_common_args.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ function Help-Message() {
Write-Output ''
Write-Output ' -B,-Build [dir] Specify build directory'
Write-Output (" Defaults to: {0}" -f $build_dir)
Write-Output ' -Analyzer Use the compiler static analysis tool during compilation (GCC & MSVC)'
Write-Output ' -CCache If ccache or sccache are found within the PATH, use them with CMake'
Write-Output ' -Clean3rdParty Clean 3rd party installation directory'
Write-Output ' -CleanAll Clean everything before building.'
Expand Down Expand Up @@ -154,6 +155,10 @@ foreach($arg in $args) {

# =============================================================================)=

if (([bool]$Analyzer)) {
Set-Value 'enable_analyzer'
}

if (([bool]$CMakeNoRegistry)) {
Set-Value 'cmake_no_registry'
}
Expand Down
4 changes: 4 additions & 0 deletions scripts/build/parse_common_args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ help_message() {
echo ''
echo ' -B,--build=[dir] Specify build directory'
echo " Defaults to: $build_dir"
echo ' --analyzer Use the compiler static analysis tool during compilation (GCC & MSVC)'
echo ' --ccache If ccache or sccache are found within the PATH, use them with CMake'
echo ' --clean-3rdparty Clean 3rd party installation directory'
echo ' --clean-all Clean everything before building.'
Expand Down Expand Up @@ -195,6 +196,9 @@ while getopts "${getopts_args}" OPT; do
# shellcheck disable=SC2034
set_var build_dir "$OPTARG"
;;
analyzer ) no_arg;
set_var enable_analyzer $flag_value
;;
ccache ) no_arg;
set_var enable_ccache $flag_value
;;
Expand Down

0 comments on commit 0a25ca4

Please sign in to comment.