Build-wrapper failing xctool build

ERROR - Command ‘xctool -workspace NetVelocityConsumer.xcworkspace -sdk iphonesimulator ARCHS=i386 VALID_ARCHS=i386 CURRENT_ARCH=i386 ONLY_ACTIVE_ARCH=NO -scheme NetVelocityConsumer’ failed with error code: 134

Unable to integrated SonarQube in XCode Objetive C version in Mac OS
I have sam error and I was trying to do last 2 days could you please provide any standard document how to integrate sonar in ios objective c project.

Hi @Ankitios,

I moved your posts to a new topic, could you please provide more details and the entire output?

I am intrigrating sounar in my objective c project.
Below is console log

Xcode workspace file is: Myproject.xcworkspace
Xcode project file is: Myproject.xcodeproj
Xcode application scheme is: Myproject
Xcode test scheme is:
Excluded paths from coverage are:
Extracting Xcode project information

  • xctool -workspace Myproject.xcworkspace -sdk iphonesimulator ARCHS=i386 VALID_ARCHS=i386 CURRENT_ARCH=i386 ONLY_ACTIVE_ARCH=NO -scheme Myproject
    [Info] Loading settings for scheme ‘Myproject’ … (5297 ms)

=== BUILD ===

xcodebuild build Myproject
2020-02-25 19:38:04.314 xctool[24014:1013711] *** Assertion failure in BOOL LaunchXcodebuildTaskAndFeedEventsToReporters(NSTask *__strong, NSArray *__strong, NSString *__autoreleasing *, long long *)_block_invoke(), /tmp/xctool-20191211-3782-tno2a8/xctool-0.3.7/Common/XCToolUtil.m:417
2020-02-25 19:38:04.316 xctool[24014:1013711] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Got error while trying to deserialize event ‘Build settings from command line:’: The data is not in the correct format.’
*** First throw call stack:
(
0 CoreFoundation 0x00007fff3ff8f2fd __exceptionPreprocess + 256
1 libobjc.A.dylib 0x00007fff6a682a17 objc_exception_throw + 48
2 CoreFoundation 0x00007fff3ffaa016 +[NSException raise:format:arguments:] + 98
3 Foundation 0x00007fff42298135 -[NSAssertionHandler handleFailureInFunction:file:lineNumber:description:] + 166
4 xctool 0x0000000102f597aa __LaunchXcodebuildTaskAndFeedEventsToReporters_block_invoke + 793
5 xctool 0x0000000102f96db4 __ReadOutputsAndFeedOuputLinesToBlockOnQueue_block_invoke + 165
6 xctool 0x0000000102f97085 __ReadOutputsAndFeedOuputLinesToBlockOnQueue_block_invoke.22 + 629
7 xctool 0x0000000102f971d3 __ReadOutputsAndFeedOuputLinesToBlockOnQueue_block_invoke_2.55 + 181
8 libdispatch.dylib 0x00007fff6be2b45d ___dispatch_operation_deliver_data_block_invoke + 109
9 libdispatch.dylib 0x00007fff6be025f8 _dispatch_call_block_and_release + 12
10 libdispatch.dylib 0x00007fff6be0363d _dispatch_client_callout + 8
11 libdispatch.dylib 0x00007fff6be098e0 _dispatch_lane_serial_drain + 602
12 libdispatch.dylib 0x00007fff6be0a3c6 _dispatch_lane_invoke + 433
13 libdispatch.dylib 0x00007fff6be09792 _dispatch_lane_serial_drain + 268
14 libdispatch.dylib 0x00007fff6be0a396 _dispatch_lane_invoke + 385
15 libdispatch.dylib 0x00007fff6be126ed _dispatch_workloop_worker_thread + 598
16 libsystem_pthread.dylib 0x00007fff6c043611 _pthread_wqthread + 421
17 libsystem_pthread.dylib 0x00007fff6c0433fd start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
./run-sonar.sh: line 43: 24014 Abort trap: 6 command "@"

  • returnValue=134
  • set +x
    ERROR - Command ‘xctool -workspace Myproject.xcworkspace -sdk iphonesimulator ARCHS=i386 VALID_ARCHS=i386 CURRENT_ARCH=i386 ONLY_ACTIVE_ARCH=NO -scheme Myproject’ failed with error code: 134

Please confirm me
Is it possible or not to scan the objective c code with sonar? I am already spending my 2 days on it.

Hi @Ankitios,

it could be that xctool is messing up with build-wrapper, if I recall correctly xctool uses dynamic libraries. Could you try on a small hello world project built with xctool? What version of xctool are you using?

I am using 0.3.7 version of xctool

Please suggest how I resolve this issue. I also spent whole day today but result is 0.

Hi @Ankitios,

it is not that nice the way you are asking for help.

In any case, xctool is calling xcodebuild underneath, which means that you can call xcodebuild directly, you can run build-wrapper-macosx-x86 --out-dir output-dir xcodebuild .... in the mean time.

Below is my sonar-project.properties

# Sonar Server details

sonar.host.url=http://localhost:9000

sonar.login=admin

sonar.password=admin

# Project Details

sonar.projectKey=com.company.app.demo

sonar.projectName=SonarDemoApplication

sonar.projectDescription=This is the Sonar demo application for the code quality check

# Comment if you have a project with mixed ObjC / Swift

sonar.language=objc

# Path to source directories

# sonar.sources=SonarDemo,SonarDemoTests,SonarDemoUITests

sonar.sources=.

# sonar.destination= 

# Exclude directories

# sonar.test.inclusions=**/*Test*/**

# sonar.test.inclusions=Ankit.swift

sonar.exclusions=**/*.xml,Pods/**/*,Reports/**/*

# sonar.inclusions=*.swift

sonar.exclusions=

# Path to test directories (comment if no test)

# sonar.tests=TestSonarFunctionality,SonarDemoUITests

# Destination Simulator to run surefire

# As string expected in destination argument of xcodebuild command

sonar.objectivec.simulator=platform=iPhone,name=iPhone 11,OS=13.2.2

# Xcode project configuration (.xcodeproj)

# and use the later to specify which project(s) to include in the analysis (comma separated list)

# Specify either xcodeproj or xcodeproj + xcworkspace

sonar.objectivec.project=Myproject.xcodeproj

sonar.objectivec.workspace=Myproject.xcworkspace

# Specify your appname.

# This will be something like "myApp"

# Use when basename is different from targeted scheme. 

# Or when slather fails with 'No product binary found'

sonar.objectivec.appName=Myproject

# Scheme to build your application

sonar.objectivec.appScheme=Myproject

# Configuration to use for your scheme. if you do not specify that the default will be Debug

sonar.objectivec.appConfiguration=Debug

##########################

# Optional configuration #

##########################

# Encoding of the source code

sonar.sourceEncoding=UTF-8

sonar.objectivec.excludedPathsFromCoverage=.*Tests.*

This is Scripting file

#!/bin/bash
## INSTALLATION: script to copy in your Xcode project in the same directory as the .xcodeproj file
## USAGE: ./run-sonar.sh
## DEBUG: ./run-sonar.sh -v
## WARNING: edit your project parameters in sonar-project.properties rather than modifying this script
#

trap "echo 'Script interrupted by Ctrl+C'; stopProgress; exit 1" SIGHUP SIGINT SIGTERM

function startProgress() {
	while true
	do
    	echo -n "."
	    sleep 5
	done
}

function stopProgress() {
	if [ "$vflag" = "" -a "$nflag" = "" ]; then
		kill $PROGRESS_PID &>/dev/null
	fi
}

function testIsInstalled() {

	hash $1 2>/dev/null
	if [ $? -eq 1 ]; then
		echo >&2 "ERROR - $1 is not installed or not in your PATH"; exit 1;
	fi
}

function readParameter() {
	
	variable=$1
	shift
	parameter=$1
	shift

	eval $variable="\"$(sed '/^\#/d' sonar-project.properties | grep $parameter | tail -n 1 | cut -d '=' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//')\""
}

# Run a set of commands with logging and error handling
function runCommand() {

	# 1st arg: redirect stdout 
	# 2nd arg: command to run
	# 3rd..nth arg: args
	redirect=$1
	shift

	command=$1
	shift
	
	if [ "$nflag" = "on" ]; then
		# don't execute command, just echo it
		echo
		if [ "$redirect" = "/dev/stdout" ]; then	
			if [ "$vflag" = "on" ]; then
				echo "+" $command "$@"
			else
				echo "+" $command "$@" "> /dev/null"
			fi
		elif [ "$redirect" != "no" ]; then
			echo "+" $command "$@" "> $redirect"
		else
			echo "+" $command "$@"
		fi
		
	elif [ "$vflag" = "on" ]; then
		echo

		if [ "$redirect" = "/dev/stdout" ]; then	
			set -x #echo on
			$command "$@"
			returnValue=$?	
			set +x #echo off			
		elif [ "$redirect" != "no" ]; then
			set -x #echo on
			$command "$@" > $redirect
			returnValue=$?	
			set +x #echo off			
		else
			set -x #echo on
			$command "$@"
			returnValue=$?	
			set +x #echo off			
		fi
		
		if [[ $returnValue != 0 && $returnValue != 5 ]] ; then
			stopProgress
			echo "ERROR - Command '$command $@' failed with error code: $returnValue"
			exit $returnValue
		fi
	else
	
		if [ "$redirect" = "/dev/stdout" ]; then	
			$command "$@" > /dev/null
		elif [ "$redirect" != "no" ]; then
			$command "$@" > $redirect
		else
			$command "$@"
		fi

        returnValue=$?
		if [[ $returnValue != 0 && $returnValue != 5 ]] ; then
			stopProgress
			echo "ERROR - Command '$command $@' failed with error code: $returnValue"
			exit $?
		fi

	
		echo	
	fi	
}

## COMMAND LINE OPTIONS
vflag=""
nflag=""
oclint="on"
while [ $# -gt 0 ]
do
    case "$1" in
    -v)	vflag=on;;
    -n) nflag=on;;
	-nooclint) oclint="";;	    
	--)	shift; break;;
	-*)
        echo >&2 "Usage: $0 [-v]"
		exit 1;;
	*)	break;;		# terminate while loop
    esac
    shift
done

# Usage OK
echo "Running run-sonar.sh..."

## CHECK PREREQUISITES

# xctool, gcovr and oclint installed
testIsInstalled xctool
testIsInstalled gcovr
testIsInstalled oclint

# sonar-project.properties in current directory
if [ ! -f sonar-project.properties ]; then
	echo >&2 "ERROR - No sonar-project.properties in current directory"; exit 1;
fi

## READ PARAMETERS from sonar-project.properties

# Your .xcworkspace/.xcodeproj filename
workspaceFile=''; readParameter workspaceFile 'sonar.objectivec.workspace'
projectFile=''; readParameter projectFile 'sonar.objectivec.project'
if [[ "$workspaceFile" != "" ]] ; then
	xctoolCmdPrefix="xctool -workspace $workspaceFile -sdk iphonesimulator ARCHS=i386 VALID_ARCHS=i386 CURRENT_ARCH=i386 ONLY_ACTIVE_ARCH=NO"
else
	xctoolCmdPrefix="xctool -project $projectFile -sdk iphonesimulator ARCHS=i386 VALID_ARCHS=i386 CURRENT_ARCH=i386 ONLY_ACTIVE_ARCH=NO"
fi	

# Source directories for .h/.m files
srcDirs=''; readParameter srcDirs 'sonar.sources'
# The name of your application scheme in Xcode
appScheme=''; readParameter appScheme 'sonar.objectivec.appScheme'

# The name of your test scheme in Xcode
testScheme=''; readParameter testScheme 'sonar.objectivec.testScheme'
# The file patterns to exclude from coverage report
excludedPathsFromCoverage=''; readParameter excludedPathsFromCoverage 'sonar.objectivec.excludedPathsFromCoverage'

# Check for mandatory parameters
if [ -z "$projectFile" -o "$projectFile" = " " ]; then

	if [ ! -z "$workspaceFile" -a "$workspaceFile" != " " ]; then
		echo >&2 "ERROR - sonar.objectivec.project parameter is missing in sonar-project.properties. You must specify which projects (comma-separated list) are application code within the workspace $workspaceFile."
	else
		echo >&2 "ERROR - sonar.objectivec.project parameter is missing in sonar-project.properties (name of your .xcodeproj)"
	fi
	exit 1
fi
if [ -z "$srcDirs" -o "$srcDirs" = " " ]; then
	echo >&2 "ERROR - sonar.sources parameter is missing in sonar-project.properties. You must specify which directories contain your .h/.m source files (comma-separated list)."
	exit 1
fi
if [ -z "$appScheme" -o "$appScheme" = " " ]; then
	echo >&2 "ERROR - sonar.objectivec.appScheme parameter is missing in sonar-project.properties. You must specify which scheme is used to build your application."
	exit 1
fi

if [ "$vflag" = "on" ]; then
 	echo "Xcode workspace file is: $workspaceFile"
 	echo "Xcode project file is: $projectFile"
 	echo "Xcode application scheme is: $appScheme"
 	echo "Xcode test scheme is: $testScheme"
 	echo "Excluded paths from coverage are: $excludedPathsFromCoverage" 	
fi

## SCRIPT

# Start progress indicator in the background
if [ "$vflag" = "" -a "$nflag" = "" ]; then
	startProgress &
	# Save PID
	PROGRESS_PID=$!
fi

# Create sonar-reports/ for reports output
if [[ ! (-d "sonar-reports") && ("$nflag" != "on") ]]; then
	if [ "$vflag" = "on" ]; then
		echo 'Creating directory sonar-reports/'
	fi
	mkdir sonar-reports
	if [[ $? != 0 ]] ; then
		stopProgress
    	exit $?
	fi
fi

# Extracting project information needed later
echo -n 'Extracting Xcode project information'
runCommand /dev/stdout $xctoolCmdPrefix -scheme "$appScheme"
runCommand /dev/stdout $xctoolCmdPrefix -scheme "$appScheme" -reporter json-compilation-database:compile_commands.json build

# Unit tests and coverage
if [ "$testScheme" = "" ]; then
	echo 'Skipping tests as no test scheme has been provided!'
	
	# Put default xml files with no tests and no coverage...
	echo "<?xml version='1.0' encoding='UTF-8' standalone='yes'?><testsuites name='AllTestUnits'></testsuites>" > sonar-reports/TEST-report.xml
	echo "<?xml version='1.0' ?><!DOCTYPE coverage SYSTEM 'http://cobertura.sourceforge.net/xml/coverage-03.dtd'><coverage><sources></sources><packages></packages></coverage>" > sonar-reports/coverage.xml
else

	echo -n 'Running tests using xctool'	
	runCommand sonar-reports/TEST-report.xml $xctoolCmdPrefix -scheme "$testScheme" -reporter junit GCC_GENERATE_TEST_COVERAGE_FILES=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=YES test

	echo -n 'Computing coverage report'

	# We do it for every xcodeproject (in case of workspaces)

	# Extract the path to the .gcno/.gcda coverage files
	echo $projectFile | sed -n 1'p' | tr ',' '\n' > tmpFileRunSonarSh
	while read projectName; do
	
		coverageFilesPath=$(grep 'command' compile_commands.json | sed 's#^.*-o \\/#\/#;s#",##' | grep "${projectName%%.*}.build" | awk 'NR<2' | sed 's/\\\//\//g' | sed 's/\\\\//g' | xargs -0 dirname)
		if [ "$vflag" = "on" ]; then
			echo
			echo "Path for .gcno/.gcda coverage files is: $coverageFilesPath"
		fi

		# Build the --exclude flags
		excludedCommandLineFlags=""
		if [ ! -z "$excludedPathsFromCoverage" -a "$excludedPathsFromCoverage" != " " ]; then
			echo $excludedPathsFromCoverage | sed -n 1'p' | tr ',' '\n' > tmpFileRunSonarSh2
			while read word; do
				excludedCommandLineFlags+=" --exclude $word"
			done < tmpFileRunSonarSh2
			rm -rf tmpFileRunSonarSh2
		fi
		if [ "$vflag" = "on" ]; then
			echo "Command line exclusion flags for gcovr is:$excludedCommandLineFlags"
		fi
	
		# Run gcovr with the right options
		runCommand "sonar-reports/coverage-${projectName%%.*}.xml" gcovr -r . "$coverageFilesPath" $excludedCommandLineFlags --xml 

	done < tmpFileRunSonarSh
	rm -rf tmpFileRunSonarSh
	
fi	

if [ "$oclint" = "on" ]; then

	# OCLint
	echo -n 'Running OCLint...'
	
	# Build the --include flags
	currentDirectory=${PWD##*/}
	includedCommandLineFlags=""
	echo "$srcDirs" | sed -n 1'p' | tr ',' '\n' > tmpFileRunSonarSh
	while read word; do
		includedCommandLineFlags+=" --include .*/${currentDirectory}/${word}"
	done < tmpFileRunSonarSh
	rm -rf tmpFileRunSonarSh
	if [ "$vflag" = "on" ]; then
		echo
		echo -n "Path included in oclint analysis is:$includedCommandLineFlags"
	fi
	
	# Run OCLint with the right set of compiler options
    maxPriority=10000
	runCommand no oclint-json-compilation-database $includedCommandLineFlags -- -max-priority-1 $maxPriority -max-priority-2 $maxPriority -max-priority-3 $maxPriority -report-type pmd -o sonar-reports/oclint.xml
else
	echo 'Skipping OCLint (test purposes only!)'
fi

# SonarQube
echo -n 'Running SonarQube using SonarQube Runner'
runCommand /dev/stdout sonar-runner
	
# Kill progress indicator
stopProgress

exit 0

In below I have added .sh file and property file please look into this what I. am doing wrong.

Hi @Ankitios,

just copy pasting your scripts asking people to have a look and telling you what is wrong is not the recommended way to ask for help.

It seems like you are using some unofficial plugins too which may interfere.

Any update?
I have below error
CompileC /Users/apple1/Library/Developer/Xcode/DerivedData/Myproject-dbmgipmhyrrsgzfyjxdzgkwqtetg/Build/Intermediates.noindex/Myproject.build/Debug-iphonesimulator/Myproject.build/Objects-normal/x86_64/AppSharedData.o /Users/Data/NetVelocity/SonarSmartFenAppStore/Myproject/Myproject/Classes/AppSharedData/AppSharedData.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler

please confirm is sonar work in objctive c or not.

Hi @Ankitios,

Do you even read my replies before posting random statements?

1 Like

I am new in sonar integration in ios. I am not writing script. I am follow sonar instruction.
I have no idea. Is it really a very challenging job to integrate sonar in iOS.

Could you please provide me step by step tutorial How to integrate sonar in iOS objective c code.

This doc is not clear can you please provide step by step solution.[quote=“mpaladin, post:13, topic:20643”]

It seems like you are using some unofficial plugins too which may interfere.
[/quote]

Do I need to purchase SonarCFamily for Objective-C

I have below error when I integrate sonar in my iOS objective c project.

Could you provide any suggestion?

CompileC /Users/apple1/Library/Developer/Xcode/DerivedData/Myproject-dbmgipmhyrrsgzfyjxdzgkwqtetg/Build/Intermediates.noindex/Myproject.build/Debug-iphonesimulator/Myproject.build/Objects-normal/x86_64/AppSharedData.o /Users/Data/NetVelocity/SonarSmartFenAppStore/Myproject/Myproject/Classes/AppSharedData/AppSharedData.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compile

ERROR - Command ‘xctool -workspace Myproject.xcworkspace -sdk iphonesimulator ARCHS=i386 VALID_ARCHS=i386 CURRENT_ARCH=i386 ONLY_ACTIVE_ARCH=NO -scheme Myproject’ failed with error code: 134b