이 문서는 SonarQube에서 C/C++언어 분석에 대한 정보를 공유하기 위해 작성되었다.
목차 |
---|
Reference = https://docs.sonarqube.org/latest/analysis/languages/cfamily/
사전준비
빌드 서버 환경
- Windows, Linux 64 bit용 SonarQube Scanner 설치 및 실행 경로 등록
- 다음 링크를 통해 OS 맞는 SonarQube Scanner 다운로드 및 환경 변수 등록sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner
- Windows, Linux 64 bit 용 build wrapper 설치 및 실행 경로 등록
- 리눅스
- http://<sonarqube server url>:<port>/static/cpp/build-wrapper-linux-x86
- .zip
- Mac
- http://<sonarqube server url>:<port>/static/cpp/build-wrapper-macosx-x86.zip
- 윈도우
- http://<sonarqube server url>:<port>/static/cpp/build-wrapper-win-x86.zip
- 리눅스
빌드 및 분석
Build Wrapper를 통해 빌드
상단 다운로드 받은 Build Wrapper를 환경 변수로 등록하거나 소스 코드 위치로 복사합니다.
Linux
make clean build는 자신의 프로젝트에 맞게 빌드 명령 변경코드 블럭 build-wrapper-linux-x86-64 --out-dir bw_output make clean build
Windows
make clean build는 자신의 프로젝트에 맞게 빌드 명령 변경코드 블럭 build-wrapper-win-x86-64.exe --out-dir bw_output make clean build
해당 경로에 bw_output 폴더가 생성되었는지 확인합니다.SonarQube Scanner 환경 구성
소스 코드 루트 위치에서 sonar-project.properties 파일을 생성합니다. 아래와 같이 SonarQube 서버에서 사용할 Project 정보를 입력합니다.코드 블럭 title sonar-project.properties sonar.projectKey=myFirstSonarQubeProject sonar.projectName=My First SonarQube Project sonar.projectVersion=1.0 sonar.sources=. sonar.cfamily.build-wrapper-output=bw_output sonar.sourceEncoding=UTF-8 sonar.host.url=SonarQube 주소 #sonar.host.url=http://10.0.0.15:9000 sonar.login=admin sonar.password=password
SonarQube Scanner 실행
소스 코드 루트 위치에서 다음과 같이 Sonar Scanner 명령을 수행합니다.코드 블럭 sonar-scanner
sonar-properties 파일 없이 파라미터로 수행하는 경우, 아래와 같은 명령을 통해서 진행합니다.코드 블럭 /opt/sonar-scanner-4.5.0.2216-linux/bin/sonar-scanner -Dsonar.host.url=http://10.0.0.15:9000 -Dsonar.login=admin -Dsonar.password=admmin -Dsonar.projectKey=curvc.jira.bitbucketfield -Dsonar.sources=. -Dsonar.sourceEncoding=UTF-8
- 끝
부가 정보
실행 경로 추가하기
- Add Permanent Entry to PATH Variable – Current User Only
~/.bash_profile 에 추가
코드 블럭 PATH=$PATH:/opt/sonar-scanner/bin