510 lines
No EOL
16 KiB
Batchfile
510 lines
No EOL
16 KiB
Batchfile
@echo off
|
|
|
|
:: Set to the drive (DRIVE ONLY) where this C#-specific script will store data.
|
|
set _CovDrv=D:
|
|
|
|
:: Set to the IM server hostname, HTTP port and admin password.
|
|
set _IMHost=tgcoverity
|
|
set _IMPort=8080
|
|
set _IMPass=Cov96eriTy
|
|
|
|
:: Set to your Visual Studio folder.
|
|
set _MVSFld=C:\Program Files (x86)\Microsoft Visual Studio 10.0
|
|
|
|
:: Set to the Triage Store to which your stream will be added. Note that this will only be applicable to a new stream.
|
|
:: Move existing streams to different Triage Stores from within CIM.
|
|
set _Triage=Default Triage Store
|
|
|
|
:: DO NOT TOUCH REST OF SCRIPT UNLESS YOU KNOW WHAT YOU'RE DOING!
|
|
|
|
:: Skipping to var_error label if empty variables
|
|
if "%_CovDrv%" == "" goto var_error
|
|
if "%_IMHost%" == "" goto var_error
|
|
if "%_IMPort%" == "" goto var_error
|
|
if "%_IMPass%" == "" goto var_error
|
|
|
|
:: Setting folder structure
|
|
set _CovFld=%CD%\coverity
|
|
set _CovInt=%_CovFld%\Intermediate
|
|
set _CovScr=%_CovFld%\Scripts
|
|
|
|
:: Setting variables for command line parameters
|
|
set _Projct=%1
|
|
set _Lnguag=cs
|
|
set _Stream=%1_CS
|
|
set _Scope=%2
|
|
|
|
:check_scope
|
|
:: Checking the 2nd parameter, scope.
|
|
if "%_Scope%" == "commit" goto check_im
|
|
if "%_Scope%" == "full" goto check_project
|
|
if "%_Scope%" == "incremental" goto check_project
|
|
echo Please enter a valid scope.
|
|
goto usage_info
|
|
|
|
:check_project
|
|
:: Checking if project parameter specified by user
|
|
if "%1" neq "" goto setup_pc
|
|
echo Please specify a project.
|
|
|
|
:usage_info
|
|
:: Showing usage information
|
|
echo.
|
|
echo ------------------------------ USAGE ------------------------------
|
|
echo.
|
|
echo %~n0%~x0 {project} {scope}
|
|
echo For example: staticanalysis_csharp.bat Hive full
|
|
echo.
|
|
echo PARAMETERS
|
|
echo.
|
|
echo {project}
|
|
echo YOU MUST SPECIFY A PROJECT.
|
|
echo The name specified here will be used to create the project on
|
|
echo the server or to write to that project if it already exists.
|
|
echo.
|
|
echo {scope}
|
|
echo Supported scopes are:
|
|
echo incremental - Keeps the last Intermediate folder and build.
|
|
echo Limits Coverity to changed code and improves speed.
|
|
echo full - Cleans the build and deletes the Intermediate folder.
|
|
echo commit - Bypasses analysis and commits previous results.
|
|
echo.
|
|
echo We recommend intermittently running a full scope. Incremental
|
|
echo builds present a small risk of having inaccurate results.
|
|
echo.
|
|
exit /b 1
|
|
|
|
:setup_pc
|
|
|
|
echo.
|
|
echo ************* SETTING UP YOUR VISUAL STUDIO VARIABLES *************
|
|
echo.
|
|
|
|
:: Calling Visual Studio variables initialization script
|
|
call "%_MVSFld%\Common7\Tools\vsvars32.bat"
|
|
|
|
:: Checking if Visual Studio variables initialization script was successful
|
|
if %errorlevel% neq 0 goto mvs_error
|
|
|
|
goto check_scripts_folder
|
|
|
|
:check_scripts_folder
|
|
|
|
:: Checking existence of scripts folder
|
|
if exist "%_CovScr%" goto check_build_script
|
|
|
|
:: Creating scripts folder
|
|
mkdir "%_CovScr%"
|
|
|
|
:: Checking if scripts folder was successfully created
|
|
if exist "%_CovScr%" goto check_build_script
|
|
|
|
echo Failed to create %_CovScr% folder.
|
|
exit /b 1
|
|
|
|
:check_build_script
|
|
|
|
:: Checking existence of build script
|
|
echo Checking existence of build script.
|
|
if exist "%_CovScr%\Build_%_Stream%.bat" goto check_clean_script
|
|
|
|
:: Creating build script
|
|
echo. 2> "%_CovScr%\Build_%_Stream%.bat"
|
|
|
|
:: Checking if build script was successfully created
|
|
if exist "%_CovScr%\Build_%_Stream%.bat" goto populate_build_script
|
|
|
|
echo Failed to create %_CovScr%\Build_%_Stream%.bat.
|
|
exit /b 1
|
|
|
|
:populate_build_script
|
|
|
|
:: Asking user to populate the build script
|
|
echo ********************* POPULATING BUILD SCRIPT *********************
|
|
echo.
|
|
echo List all commands required to build %_Stream% in:
|
|
echo %_CovScr%\Build_%_Stream%.bat.
|
|
echo.
|
|
echo Press Enter to prompt Notepad where you can enter the build command.
|
|
set /p _Cntnue=" Then save and close the file."
|
|
echo.
|
|
NOTEPAD %_CovScr%\Build_%_Stream%.bat
|
|
|
|
:check_clean_script
|
|
|
|
:: Skip if build type is incremental.
|
|
if "%_Scope%" == "incremental" goto check_code_sync
|
|
|
|
:: Checking existence of clean script
|
|
echo Checking existence of clean script.
|
|
if exist "%_CovScr%\Clean_%_Stream%.bat" goto check_code_sync
|
|
|
|
:: Creating the clean script
|
|
echo. 2> "%_CovScr%\Clean_%_Stream%.bat"
|
|
|
|
:: Checking if clean script was successfully created
|
|
if exist "%_CovScr%\Clean_%_Stream%.bat" goto populate_clean_script
|
|
|
|
echo Failed to create %_CovScr%\Clean_%_Stream%.bat
|
|
exit /b 1
|
|
|
|
:populate_clean_script
|
|
|
|
:: Asking user to populate the clean script
|
|
echo ********************* POPULATING CLEAN SCRIPT *********************
|
|
echo.
|
|
echo List all commands required to clean %_Stream% in:
|
|
echo %_CovScr%\Clean_%_Stream%.bat
|
|
echo.
|
|
echo Press Enter to prompt Notepad where you can enter the clean command.
|
|
set /p _Cntnue="Then save and close the file."
|
|
echo.
|
|
NOTEPAD %_CovScr%\Clean_%_Stream%.bat
|
|
|
|
:check_code_sync
|
|
|
|
:: Checking existence of code sync script
|
|
if exist "%_CovScr%\Sync_%_Stream%.bat" goto check_assembly_file
|
|
|
|
:: Creating code sync script
|
|
echo exit /b 0 > "%_CovScr%\Sync_%_Stream%.bat"
|
|
|
|
:: Checking if code sync script was successfully created
|
|
if exist "%_CovScr%\Sync_%_Stream%.bat" goto populate_code_sync
|
|
|
|
echo Failed to create %_CovScr%\Sync_%_Stream%.bat
|
|
exit /b 1
|
|
|
|
:populate_code_sync
|
|
|
|
:: Asking user to populate the code sync script
|
|
echo ********************* POPULATING SYNC SCRIPT **********************
|
|
echo.
|
|
echo List all commands required to sync %_Stream% in:
|
|
echo %_CovScr%\sync_%_Stream%.bat.
|
|
echo.
|
|
echo Example:
|
|
echo p4 -p server -u username -P password -c clientspec sync path/to/depot/...
|
|
echo.
|
|
echo NOTE: If you plan to sync code elsewhere,
|
|
echo leave the file as-is with its "exit /b 0" command.
|
|
echo.
|
|
echo Press Enter to prompt Notepad where you can enter the sync command.
|
|
set /p _Cntnue="Then save and close the file."
|
|
echo.
|
|
NOTEPAD %_CovScr%\sync_%_Stream%.bat
|
|
|
|
:check_assembly_file
|
|
|
|
:: Checking existence of assembly file
|
|
if exist "%_CovScr%\Files%_Stream%.txt" goto check_intermediate_folder
|
|
|
|
:: Creating assembly file
|
|
echo. 2> "%_CovScr%\Files%_Stream%.txt"
|
|
|
|
:: Checking if assembly file was successfully created
|
|
if exist "%_CovScr%\Files%_Stream%.txt" goto populate_assembly_file
|
|
|
|
echo Failed to create %_CovScr%\Files%_Stream%.txt.
|
|
exit /b 1
|
|
|
|
:populate_assembly_file
|
|
|
|
:: Asking user to populate the assembly file
|
|
echo ****************** POPULATING ASSEMBLY FILE LIST ******************
|
|
echo.
|
|
echo List all assembly files (.exe and .dll) that need to be analyzed
|
|
echo including their full path (one per line) in:
|
|
echo %_CovScr%\Files%_Stream%.txt
|
|
echo.
|
|
echo Press Enter to prompt Notepad where you can enter the
|
|
echo full path names of all the project's assembly files.
|
|
set /p _Cntnue="Then save and close the file."
|
|
echo.
|
|
NOTEPAD %_CovScr%\Files%_Stream%.txt
|
|
|
|
:check_intermediate_folder
|
|
|
|
:: Checking existence of intermediate folder
|
|
if not exist "%_CovInt%\%_Stream%" goto sync_code
|
|
|
|
:: Checking if we want an incremental build
|
|
if "%2" == "incremental" echo ******************* KEEPING INTERMEDIATE FOLDER *******************
|
|
echo.
|
|
if "%2" == "incremental" goto sync_code
|
|
|
|
:: Removing intermediate folder
|
|
rmdir /s /q "%_CovInt%\%_Stream%"
|
|
|
|
:: Checking if intermediate folder was successfully removed
|
|
if not exist "%_CovInt%\%_Stream%" goto sync_code
|
|
|
|
echo Failed to remove %_CovInt%\%_Stream%.
|
|
exit /b 1
|
|
|
|
:sync_code
|
|
|
|
echo ************************ SYNCING THE CODE *************************
|
|
echo.
|
|
:: Calling the code sync script
|
|
call "%_CovScr%\Sync_%_Stream%.bat"
|
|
|
|
:: Checking if the code sync script was sucessful
|
|
if %errorlevel% == 0 goto clean_previous_build
|
|
|
|
echo Failed to run %_CovScr%\Sync_%_Stream%.bat.
|
|
echo Please correct it, then rerun the static analysis script.
|
|
exit /b 1
|
|
|
|
:clean_previous_build
|
|
|
|
if "%2" == "incremental" echo ****************** NO CLEANING OF PREVIOUS BUILD ******************
|
|
echo.
|
|
if "%2" == "incremental" goto run_cs_cov_build
|
|
|
|
echo ******************* CLEANING THE PREVIOUS BUILD *******************
|
|
echo.
|
|
|
|
:: Calling the clean script
|
|
call "%_CovScr%\Clean_%_Stream%.bat"
|
|
|
|
:: Checking if the clean script was sucessful
|
|
if %errorlevel% == 0 goto run_cs_cov_build
|
|
|
|
echo Failed to run %_CovScr%\Clean_%_Stream%.bat.
|
|
exit /b 1
|
|
|
|
:run_cs_cov_build
|
|
|
|
echo. ************ BUILDING/REBUILDING %_Projct% ************
|
|
echo.
|
|
|
|
:: Building project
|
|
call "%_CovScr%\Build_%_Stream%.bat"
|
|
|
|
:: Checking if build was successful
|
|
if %errorlevel% == 0 goto run_cov_analyze_cs
|
|
|
|
echo Build failed. Please be certain that your build works outside of Coverity.
|
|
echo If it is a problem specific to Coverity, please consult our wiki at:
|
|
echo http://coverity.
|
|
exit /b 1
|
|
|
|
:run_cov_analyze_cs
|
|
|
|
echo.
|
|
echo.
|
|
echo ***************** ANALYZING %_Projct% ******************
|
|
|
|
:: Analyzing build
|
|
cov-analyze-cs @"%_CovScr%\Files%_Stream%.txt" --dir "%_CovInt%\%_Stream%" --all
|
|
|
|
:: Checking if analysis was successful
|
|
if %errorlevel% == 0 goto check_im
|
|
|
|
echo.
|
|
echo The cov-analyze-cs FAILED.
|
|
echo.
|
|
echo Check for errors here:
|
|
echo %_CovInt%\%_Stream%\cs\output\analysis-log.txt.
|
|
echo.
|
|
echo You may wish to visit http://coverity, where you can read over the FAQ
|
|
echo and the official documentation sections, to help you resolve your issue.
|
|
exit /b 1
|
|
|
|
:check_im
|
|
|
|
echo.
|
|
echo ***************** CHECKING FOR A MATCHING PROJECT *****************
|
|
echo.
|
|
|
|
:: Checking for configuration and analysis data
|
|
if not exist "%_CovInt%\%_Stream%" goto analysis_error
|
|
|
|
:: Looking for a project that matches this project
|
|
cov-manage-im --host "%_IMHost%" --port %_IMPort% --user admin --password %_IMPass% --mode projects --show --name "%_Projct%"
|
|
|
|
:: Checking if project exists
|
|
if %errorlevel% == 0 goto check_triage
|
|
|
|
:: Creating project
|
|
cov-manage-im --host "%_IMHost%" --port %_IMPort% --user admin --password %_IMPass% --mode projects --add --set name:"%_Projct%"
|
|
|
|
:: Checking if project was successfully created
|
|
if %errorlevel% == 0 goto check_triage
|
|
|
|
echo Failed to create the %_Projct% project in CIM.
|
|
goto cim_error
|
|
|
|
:check_triage
|
|
|
|
echo.
|
|
echo ************** CHECKING FOR A MATCHING TRIAGE STORE ***************
|
|
echo.
|
|
|
|
:: Looking for a Triage Store, new to 6.0, that matches the stream name. This suggests an upgrade from 5.x to 6.0.
|
|
:: If so, we will delete this triage store.
|
|
cov-manage-im --host "%_IMHost%" --port %_IMPort% --user admin --password %_IMPass% --mode triage --show --name "%_Stream%"
|
|
if %errorlevel% == 1 goto check_triage2
|
|
|
|
:del_triage
|
|
echo Triage store has same name as stream, this is probably a result of converting from 5.x.
|
|
:: Looking for a stream that matches name and language.
|
|
cov-manage-im --host "%_IMHost%" --port %_IMPort% --user admin --password %_IMPass% --mode streams --show --name "%_Stream%" --language %_Lnguag%
|
|
|
|
:: If the stream does not exist, continue with rest of triage creation process.
|
|
if %errorlevel% == 1 goto check_triage2
|
|
|
|
:: Moving stream.
|
|
cov-manage-im --host "%_IMHost%" --port %_IMPort% --user admin --password %_IMPass% --mode streams --update --name "%_Stream%" --set triage:"%_Triage%"
|
|
if %errorlevel% == 1 goto str_error
|
|
|
|
:: Deleting old triage store.
|
|
cov-manage-im --host "%_IMHost%" --port %_IMPort% --user admin --password %_IMPass% --mode triage --delete --triage "%_Stream%"
|
|
|
|
if %errorlevel% == 0 goto check_triage2
|
|
|
|
echo Failed to delete the %_Stream% triage store in CIM.
|
|
echo.
|
|
goto str_error
|
|
|
|
:check_triage2
|
|
:: Looking for a Triage Store that matches name.
|
|
cov-manage-im --host "%_IMHost%" --port %_IMPort% --user admin --password %_IMPass% --mode triage --show --name "%_Triage%"
|
|
|
|
:: Checking if Triage Store exists
|
|
if %errorlevel% == 0 goto check_stream
|
|
|
|
:: Creating triage store. As of 6.0, you need to specify a triage store for each stream, although there can be multiple streams under a single triage store.
|
|
:: Limiting triage stores is generally recommended, so this script adds all streams to the default triage.
|
|
:: You can, if desired, specify your own triage store. Just change the %_Triage% variable at the top of this script.
|
|
cov-manage-im --host "%_IMHost%" --port %_IMPort% --user admin --password %_IMPass% --mode triage --add --set name:"%_Triage%"
|
|
|
|
:: Checking if stream was successfully created
|
|
if %errorlevel% == 0 goto check_stream
|
|
|
|
echo Failed to create the %_Triage% triage store in CIM.
|
|
echo.
|
|
goto cim_error
|
|
|
|
:check_stream
|
|
|
|
echo.
|
|
echo ***************** CHECKING FOR A MATCHING STREAM ******************
|
|
echo.
|
|
|
|
:: Looking for a stream that matches name and language. As of 5.5, no need to specify type.
|
|
cov-manage-im --host "%_IMHost%" --port %_IMPort% --user admin --password %_IMPass% --mode streams --show --name "%_Stream%" --language %_Lnguag%
|
|
|
|
:: Checking if stream exists
|
|
if %errorlevel% == 0 goto check_stream_association
|
|
|
|
:: Creating stream. As of 5.5, no need to specify type.
|
|
cov-manage-im --host "%_IMHost%" --port %_IMPort% --user admin --password %_IMPass% --mode streams --add --set name:"%_Stream%" --set language:%_Lnguag% --set triage:"%_Triage%"
|
|
|
|
:: Checking if stream was successfully created
|
|
if %errorlevel% == 0 goto check_stream_association
|
|
|
|
echo Failed to create the %_Stream% stream in CIM.
|
|
echo.
|
|
goto cim_error
|
|
|
|
:check_stream_association
|
|
|
|
echo.
|
|
echo ****** CHECKING FOR ASSOCIATION BETWEEN PROJECT AND STREAMS *******
|
|
echo.
|
|
|
|
:: Looking for an association between project and stream
|
|
cov-manage-im --host "%_IMHost%" --port %_IMPort% --user admin --password %_IMPass% --mode projects --show --name "%_Projct%" --stream "%_Stream%"
|
|
|
|
:: Checking if association exists
|
|
if %errorlevel% == 0 goto run_cov_commit
|
|
|
|
:: Associating stream and project
|
|
cov-manage-im --host "%_IMHost%" --port %_IMPort% --user admin --password %_IMPass% --mode projects --update --name "%_Projct%" --insert stream:"%_Stream%"
|
|
|
|
:: Checking if association was successful
|
|
if %errorlevel% == 0 goto run_cov_commit
|
|
|
|
echo Failed to associate the %_Stream% stream to the
|
|
echo %_Projct% project in CIM.
|
|
goto cim_error
|
|
|
|
:run_cov_commit
|
|
|
|
echo.
|
|
echo *********** COMMITTING DEFECTS TO THE INTEGRITY MANAGER ***********
|
|
echo.
|
|
|
|
:: Committing defects to the IM database
|
|
cov-commit-defects --dir "%_CovInt%\%_Stream%" --host "%_IMHost%" --port %_IMPort% --stream "%_Stream%" --user admin --password %_IMPass%
|
|
|
|
:: Checking if defects were successfully committed
|
|
if %errorlevel% == 0 goto display_new_defect
|
|
|
|
|
|
|
|
|
|
:display_new_defect
|
|
echo.
|
|
echo *********** DISPLAY NEW DEFECTS FOUND IF ANY ***********
|
|
echo START_ANALYSIS
|
|
:: display new defects found
|
|
cov-manage-im --host "%_IMHost%" --port %_IMPort% --user admin --password %_IMPass% --mode defects --show --project "%_Projct%" --status New --separator " " --no-headers --fields action,cid,checker,classification,component,ext-ref,file,function,owner,severity,status
|
|
|
|
echo END_ANALYSIS
|
|
|
|
if %errorlevel% == 0 goto script_end
|
|
if %errorlevel% == 1 goto script_end
|
|
|
|
echo The cov-commit-defects command failed.
|
|
echo You can avoid re-running the analysis by using:
|
|
echo.
|
|
echo %~n0%~x0 {project} commit
|
|
exit /b 1
|
|
|
|
echo END_ANALYSIS
|
|
echo.
|
|
|
|
|
|
:script_end
|
|
|
|
echo %_Projct% C# static analysis complete.
|
|
exit /b 0
|
|
|
|
:cim_error
|
|
echo Double-check the CIM server information:
|
|
echo Host = %_IMHost%
|
|
echo HTTP Port = %_IMPort%
|
|
echo Admin Password = %_IMPass%
|
|
echo.
|
|
echo Correct any server information mistakes in the script, then rerun it.
|
|
echo Avoid re-running the analysis by running the following command:
|
|
echo.
|
|
echo %~n0%~x0 %_Projct% commit
|
|
exit /b 1
|
|
|
|
:str_error
|
|
echo Try to manually move the stream(s) directly within the CIM. Then rerun your script.
|
|
exit /b 1
|
|
|
|
:var_error
|
|
echo Set the batch file's script variables before proceeding:
|
|
echo the Coverity drive;
|
|
echo the server host, port, and password;
|
|
echo and the Visual Studio folder.
|
|
exit /b 1
|
|
|
|
:mvs_error
|
|
echo Failed to find or run:
|
|
echo %_MVSFld%\Common7\Tools\vsvars32.bat.
|
|
echo.
|
|
echo Verify that in the appropriate place near the top of this script
|
|
echo you have entered the correct path to your Visual Studio solution.
|
|
exit /b 1
|
|
|
|
:analysis_error
|
|
echo Failed to find analysis results in:
|
|
echo %_CovInt%\%_Stream%.
|
|
exit /b 1 |