-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
05313a9
commit 316e64b
Showing
1 changed file
with
128 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
#!/bin/bash -xe | ||
|
||
#------------------------------------------------------------------------------ | ||
# Sample build script for SonarQube analysis | ||
# | ||
# This script should be run from the root of your project (usually along side | ||
# your *.xcodeproj). It contains commands to produce all the different types | ||
# of reports that can be imported into SonarQube. | ||
#------------------------------------------------------------------------------ | ||
|
||
TEST_SCHEME_NAME='MyTestScheme' | ||
APP_TARGET_NAME='MyApplication' | ||
SOURCES_DIR='MyApplication' | ||
TEST_SOURCES_DIR='MyApplicationTests' | ||
|
||
# Set the version of Xcode to use with xcodebuild | ||
export DEVELOPER_DIR=/Applications/Xcode7.0.1.app/Contents/Developer | ||
|
||
# Corresponding SDK version to build with that is available with the Xcode version you're using | ||
SDK_VERSION=9.0 | ||
|
||
# Allows snapshot's reset_simulators command to work without prompting the user for confirmation | ||
export SNAPSHOT_FORCE_DELETE=true | ||
|
||
# Clean | ||
rm -rf compile_commands.json build/ DerivedData/ | ||
|
||
# Recreate output dirs | ||
mkdir -p build/logs | ||
mkdir -p build/reports/cobertura | ||
mkdir -p build/reports/junit | ||
mkdir -p build/reports/lizard | ||
mkdir -p build/reports/oclint | ||
|
||
# For informational purposes | ||
xcodebuild -version | ||
xcodebuild -showsdks | ||
xcodebuild -list | ||
|
||
# Fresh simulator state for tests | ||
killall "iOS Simulator" "iPhone Simulator" "Simulator" || true | ||
snapshot reset_simulators | ||
|
||
# Will check xcodebuild for failures when piped into xcpretty | ||
set -o pipefail | ||
|
||
# Run tests | ||
xcodebuild \ | ||
-scheme "${TEST_SCHEME_NAME}" \ | ||
-sdk "iphonesimulator${SDK_VERSION}" \ | ||
-destination "OS=${SDK_VERSION},name=iPhone 6" \ | ||
-destination-timeout 600 \ | ||
-configuration Release \ | ||
clean test \ | ||
ONLY_ACTIVE_ARCH=NO \ | ||
-enableCodeCoverage YES \ | ||
-derivedDataPath DerivedData \ | ||
| tee build/logs/xcodebuild-test.log \ | ||
| xcpretty -r junit -o "build/reports/junit/TESTS-${TEST_SCHEME_NAME}.xml" | ||
|
||
# Build and run Clang analysis | ||
# You may need to add extra arguments such as "CODE_SIGN_IDENTITY=iPhone Distribution: My Cert (ABC123)" | ||
xcodebuild \ | ||
-target "${APP_TARGET_NAME}" \ | ||
-sdk "iphoneos${SDK_VERSION}" \ | ||
-configuration Release \ | ||
clean analyze \ | ||
CONFIGURATION_BUILD_DIR=build \ | ||
| tee build/logs/xcodebuild-analyze.log \ | ||
| xcpretty -r json-compilation-database -o compile_commands.json | ||
|
||
# Done with xcpretty, so we can disable pipefail | ||
set +o pipefail | ||
|
||
if which lizard | ||
then | ||
# Run Lizard report for complexity | ||
lizard \ | ||
--xml \ | ||
"${SOURCES_DIR}" \ | ||
> 'build/reports/lizard/lizard.xml' | ||
fi | ||
|
||
if which slather | ||
then | ||
# Run Slather for coverage with Xcode 7 or later | ||
slather \ | ||
coverage \ | ||
--cobertura-xml \ | ||
--output-directory build/reports/cobertura \ | ||
--input-format profdata \ | ||
--build-directory DerivedData \ | ||
--source-directory . \ | ||
--ignore '../**' \ | ||
--ignore "${TEST_SOURCES_DIR}/**" \ | ||
MyApplication.xcodeproj | ||
fi | ||
|
||
MAX_PRIORITY=10000 | ||
oclint-json-compilation-database \ | ||
--include "${SOURCES_DIR}/.*" \ | ||
-- \ | ||
-max-priority-1 "${MAX_PRIORITY}" \ | ||
-max-priority-2 "${MAX_PRIORITY}" \ | ||
-max-priority-3 "${MAX_PRIORITY}" \ | ||
-report-type pmd \ | ||
-o 'build/reports/oclint/oclint.xml' | ||
|
||
cat << _EOF > sonar-project.properties | ||
sonar.projectName=MyApplication | ||
sonar.projectKey=com.example:my-application | ||
sonar.projectVersion=1.0 | ||
sonar.language=objectivec | ||
sonar.sourceEncoding=UTF-8 | ||
sonar.sources=${SOURCES_DIR} | ||
sonar.tests=${TEST_SOURCES_DIR} | ||
sonar.objectivec.junit.reportsPath=build/reports/junit | ||
sonar.objectivec.cobertura.reportPath=build/reports/cobertura/cobertura.xml | ||
sonar.objectivec.lizard.reportPath=build/reports/lizard/lizard.xml | ||
sonar.objectivec.clang.reportsPath=$(find build -type d -name StaticAnalyzer)/MyApplication/${APP_TARGET_NAME}/normal/armv7 | ||
sonar.objectivec.oclint.reportPath=build/reports/oclint/oclint.xml | ||
_EOF | ||
|
||
sonar-runner |