code coverage with gcovr and Xcode 5 is not working - code-coverage

I'm using gcovr to generate code coverage for cobertura.
Everything was working fine with xcode 4.6. Now I updated to xcode5 and everything I get is 0% coverage...
my setup:
gcovr 3.0
Xcode 5 (Apple LLVM 5)
'Generate Test Coverage Files' is set to YES
'Instrument Program Flow' is set to YES
and to command I use:
gcovr -r . --object-directory Build/Intermediates/myApp.build/Debug-iphonesimulator/myApp.build/Objects-normal/i386 --exclude '.*Tests.*' --exclude '.*KiwiUnitTest' --exclude '.*main.*' --xml > reports/coverage.xml
is someone having the same issue or better, have a solution? :)

And now it works again... :)
as #kenji said, Xcode 5.1 solved the problem. thx btw
here is my working environment and configuration for the one who are interested
Xcode 5.1.1 (from the AppStore)
gcovr 3.1-prerelease (installed with easy_install)
and in my project under 'Build Settings' I set the following:
'Generate Test Coverage Files' is set to YES
'Instrument Program Flow' is set to YES
after I run the tests, I execute the following command: (happens with jenkins)
gcovr -r . --object-directory Build/Intermediates/MyProj.build/Debug-iphonesimulator/KiwiUnitTest.build/Objects-normal/i386 --exclude '.*Tests.*' --exclude '.*KiwiUnitTest' --exclude '.*main.*' --xml > reports/coverage.xml
done.
sorry guys for making you wait for an answer and thank you everyone for your help.

At first make sure that your .gcda and .gcno files are created!
(Check: ~/Library/Developer/Xcode/DerivedData/{YOUR-PROJECT-NAME}/Build/Intermediates/{YOUR-PROJECT-NAME}.build/Debug-iphonesimulator/{YOUR-PROJECT-NAME}.build/Objects-normal/i386 )
If they have been successfully created you need to do the following:
(If not check the comments under your question)
copy the all the files from the folder i386 (full path as described above) into you
workspace where your .h and .m files are.
run terminal and change you parent working directory to your workspace
cd [YOUR WORKSPACE PATH]
run gcovr
gcovr -r . --xml > reports/coverage.xml
If you are using jenkins (which i assume) this will be your further steps:
Generating gcda files to view the code-coverage from XCTests in IOS with Jenkins
Let me know if you still have questions!

Related

Code Sign Error in macOS Monterey, Xcode - resource fork, Finder information, or similar detritus not allowed

Already tried : Code Sign Error on macOS Sierra, Xcode 8
Please see image showing error
CodeSign /Users/gururajtallur/Library/Developer/Xcode/DerivedData/Flow-bkqjkvtmvjovpyepfjeyqmjpintj/Build/Products/Debug-iphoneos/Super\ Flow\ Flip.app
cd "/Volumes/Development/Project/Top Best Games/19. Lets Flow/35/let's FLOW - source/proj.ios_mac"
export CODESIGN_ALLOCATE=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/codesign_allocate
export PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
Signing Identity: "iPhone Distribution: New Free Games (2CHN583K4J)"
Provisioning Profile: "Super Flow Flipp AppStore"
(c6c30d2a-1025-4a23-8d12-1863ff684a05)
/usr/bin/codesign --force --sign E48B98966150110E55EAA9B149F731901A41B37F --entitlements /Users/gururajtallur/Library/Developer/Xcode/DerivedData/Flow-bkqjkvtmvjovpyepfjeyqmjpintj/Build/Intermediates/Flow.build/Debug-iphoneos/Super\ Flow\ Flip.build/Super\ Flow\ Flip.app.xcent --timestamp=none /Users/gururajtallur/Library/Developer/Xcode/DerivedData/Flow-bkqjkvtmvjovpyepfjeyqmjpintj/Build/Products/Debug-iphoneos/Super\ Flow\ Flip.app
/Users/gururajtallur/Library/Developer/Xcode/DerivedData/Flow-bkqjkvtmvjovpyepfjeyqmjpintj/Build/Products/Debug-iphoneos/Super Flow Flip.app: resource fork, Finder information, or similar detritus not allowed
Command /usr/bin/codesign failed with exit code 1
In Code Sign section its allowing me to select profile and certificate...but still giving error.
How to fix this problem ?
Solution 1:
Apple Developer Website Answers above problem Here.
Execute below command in terminal : First goto projects root folder
xattr -cr <path_to_project_dir>
Clean Xcode and Re-build.
Solution 2:
Just go to project root directory and run this command xattr -cr .
xattr -cr .
Clean Xcode and Re-build.
Solution 3:
You can fix this problem by finding files which holds finder information.
In terminal, goto project root directory and execute
ls -alR# . > kundapura.txt
This creates kundapura.txt in current directory. Now search for com.apple.FinderInfo and clear this attributes for all files. You can do it like this
xattr -c <filename>
Example: xattr -c guru.png
Once you clear all then code sign works. Clean Xcode and Re Build. Cheers
Solution 4: Inspired by Mark McCorkle's Answer
In terminal, goto project's root directory and execute one by one command
find . -type f -name '*.jpeg' -exec xattr -c {} \;
find . -type f -name '*.jpg' -exec xattr -c {} \;
find . -type f -name '*.png' -exec xattr -c {} \;
find . -type f -name '*.json' -exec xattr -c {} \;
Clean Xcode and Re-build.
The error is from attributes inside your image files. This happened from our graphics designer saving images from photoshop with attributes.
Here is a simple command to find all of your png files and remove their attributes. Run this in your projects root directory from terminal. Clean and rebuild; problem solved.
find . -type f -name '*.png' -exec xattr -c {} \;
If you have this error when codesigning an app:
resource fork, Finder information, or similar detritus not allowed
Command /usr/bin/codesign failed with exit code 1
Go to your project root folder and execute
find . | xargs -0 xattr -c
This will clear attributes for all files.
In Sierra, the rules on what can be in a signed bundle have been tightened, and resource forks are no longer allowed. AppleScript has been saving information in resource forks forever, although that information has been unused for a long time. With Sierra, when you save a script, this resource fork information will no longer be saved.
It means you cannot codesign a script that was last saved in a version before Sierra; you have to save in Sierra to be able to sign in Sierra.
The people likely to be affected by are who bundle other scripts within their scripts (cordova?). They will not be able to sign the container script until all the embedded scripts have been resaved under Sierra.
UPDATE:
Seems like this also works:
xattr -rc .
If you have any insufficient permissions error try to prepend sudo: sudo xattr -rc .
The easiest way to handle attributes on your source files is to have Xcode clear up the archive before it runs codesign. To do this:
Select your target in XCode
Select the Build Phases tab
Press the + symbol
Select New Run Script Phase
Enter the following for the script:
xattr -cr ~/Library/Developer/Xcode/DerivedData || echo Clear
Now when you build your target it will clear out any attributes that would have broken codesign. By clearing out at this stage you don't have to alter your source code / project directory.
The "|| echo Clear" part of the script ensures that the project build continues even if xattr errors.
This method is good if you use programs such as DropBox on your code repository that add the attributes, as it doesn't change your source project, only the built archive.
You may need to change the path to match your DerivedData directory - this path will be shown next to the codesign error.
I have used following command. Use terminal window. Navigate to your Project and execute following:
xattr -rc .
There is official Apple answer for this issue in Technical Q&A QA1940.
This is a security hardening change that was introduced with iOS 10,
macOS Sierra, watchOS 3, and tvOS 10.
Code signing no longer allows any file in an app bundle to have an
extended attribute containing a resource fork or Finder info.
To see which files are causing this error, run this command in
Terminal: xattr -lr <path_to_app_bundle>
You can also remove all extended attributes from your app bundle with
the xattr command: xattr -cr <path_to_app_bundle>
<path_to_app_bundle> can be replaced with directory of your Xcode project. For example ~/Development/MyProject
All about clearing files is fine, but tedious for multiple projects.
graphics apps, (like photoshop in old versions) write additional info (we now call it metadata..) in an old fashion in external files, or they came frm older OSX, files like:
"com.apple.ResourceFork" and "com.apple.FinderInfo", when unzipping folder, for example.
Xcode 8 refuses to add it to a build (as You added them to a project with a "git --add ." maybe..)
You can find in terminal recursively and delete them, but can be tedious.
I wrote a small free utility to delete it.. hope it can help..
https://itunes.apple.com/us/app/cleandetritus/id1161108431?ls=1&mt=12
For those (like me) who are just trying to develop an app without having to strip extended attributes on every new photoshop created PNG added to the macOS target, you can temporarily disable code signing by adding a user defined build setting:
CODE_SIGNING_ALLOWED = No
Obviously, one distributing an app needs to eventually deal with the issue but this enables development in cases like mine where it wasn't necessarily straightforward to omit code signing in Sierra (on past OS X / Xcode it was easier to do so).
Per RGriffith's comment, here are a few screenshots for those who aren't sure how the custom build setting is added.
Simple solution:-
How I did [Working for me]
Step 1:-
Go to this folder - from your finder press option Go - > Go to Folder
then type your project path like this
example:-
Library/Developer/Xcode/DerivedData/yourprojectname/Build/Products/Debug-iphoneos
Now you can see a window pop with list of available File, There you see yourApp.app file [ Don't do anything just wait for step 2].
Step 2:-
Open new Terminal and type just cd then just drag step 1 yourApp.app to terminal, now you will get the path for the app, now press enter button.
Step 3:-
Now type this command **
xattr -rc .
Don't miss "."(Dot) press enter button.
That's it, Go to your Xcode project and clean and run again.
-----In case you can't apply the solutions above, because of lack of bash knowledge or something else.
I had this problem as soon as I enabled iCloud Drive on my Sierra. And my project was in a folder which was synced with iCloud Drive. I suppose this is what adds those additional attributes.
Temporary solution:
Disable iCloud Drive for the folder where your project is.
You will need to delete the app bundle folder and rebuild the app as explained below.
My app is called: augment
In terminal window, goto your app folder
e.g.: cd /Users/username/Library/Developer/Xcode/DerivedData/
In terminal window run command for your app folder
e.g.: xattr -cr augment-flmbiciuyuwaomgdvhulunibwrms
Clean>Build>Run.
There is also a free app on Mac Appstore called "CleanDetritus" which will do removal of these.
This problem came to me yesterday.
(What's wrong) I updated image resources by manually replacing file in finder and I failed with this compilation error.
(What's right) Don't update image in this way. After that I dragged images to 'xcassets' in Xcode. No more error appear again.
My problem is every change I make in the code and execute again the error reappears. Then I find a solution to execute the command automatically every compilation/execution of code.
Thanks to #rich-able I discovered "Run Script". Then I put the command "xattr -cr ." in the field.
One of the best solution is
Go to terminal type this
xattr -cr "Full path of your project"
To find full path of your right click on Xcode project->get info -> copy path and replace with .
Then type below command
xattr -cr "Full path of your project"
Clean and build done.
The simplest fix may be if you are using git. Try:
$ git stash
$ git stash pop
Git does not store file metadata, the above will strip it all away.
Open terminal and just run this command.
xattr -cr "path to .app file"
I found that if I add color tag on the folder under DerivedData, it will give the above error when debug on device.
Remove the color Tag fix this error for me.
My problem was that I used cordova to build the app around 1 year ago, but it wasn't compatible with the new version of xcode, so I simply used cordova build ios and it worked again.
If the xattr commands doesn't the trick this may be due to an XCode 9 bug:
let's try to remove and re-add the resource folder (it was a .xcassets in my case) containing the affected files from Xcode. (you should understand which are the affected files previous through the xattr -lr command)
The problem is in the derived data, You should clean the derived data and then clean the project and build. Please check this link.
I'm also facing the same issue, got fixed by just restarting my Macbook.
You can remove the derived data
Xcode -> Preferences
And click on the arrow below Derived Data, and empty the folder Derived Data
I don't know what happened to me, but when I was running flutter app on simulator, I was encountered by the error. I used flutter clean command and removed the derived data and then everything goes fine.
My .app was on a network mounted drive.
codesign -f -vv --preserve-metadata=entitlements -s {*my Apple distribution cert SHA*} my.app
my.app: resource fork, Finder information, or similar detritus not allowed
I don't know if too long path or the fact it was on a NAS device was a problem. I copied the .app to my local Downloads directory, and then was able to codesign.
my.app: signed app bundle with Mach-O thin (arm64) [*com.something.my*]
This happened to me as well when I duplicated a .plist file and edited it, instead of creating a new one. the xattr -lr <path> command helped me identify the problematic file.
My issue was related to unintended changes on framework integrated using Carthage. I had modified one line in framework by mistake and it didn't show up in git because dependency build folder was ignored from git.
Solution : Deleted framework folder in Carthage and rebuilt it.

Xcode 7 GCDA corrupt arc tag

When I run unit test in Xcode 7, I'm getting below error.
cannot merge previous GCDA file: corrupt arc tag
In my run script I'm running below code in current and derived directory to remove all GCDA files
find . -name "*.gcda" -print0 | xargs -0 rm
In my post script code, I'm using gcovr to generate coverage report.
Some other forum mention on enabling below setting for main target, and disabling them for test target.
Enable Code Coverage Support to YES
Generate Legacy Test Coverage Files to YES
Instrument Program Flow to YES
But this didn't work for me.

CMake: How can I copy a directory into the ios application bundle

I have an ios project that builds with CMake 3.1.1, but I am stuck on the last problem - getting CMake to copy the asset directory into the right location for the app.
I have this, which works when running the app in the simulator. However, it does not work, and in fact causes a build failure when archiving because the destination directory it constructs does not exist.
get_target_property(APPLICATION_BIN ${APPLICATION_NAME} LOCATION)
get_dotapp_dir(${APPLICATION_BIN} APPLICATION_APP_LOCATION)
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND cp -r "${CMAKE_SOURCE_DIR}/assets" "${APPLICATION_APP_LOCATION}")
The directory I am copying has many subdirectories and I need them all preserved. Essentially I want to accomplish with cmake the same thing that happens when I drag the "assets" folder into the ios project underneath "Resources".
Use ${CMAKE_COMMAND} -E copy_directory instead of calling cp.
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${LOCATION_FOR_THE_APP} DEPENDS "${PROJECT_SOURCE_DIR}/assets" COMMAND -E copy_directory ${PROJECT_SOURCE_DIR}/assets ${CMAKE_CURRENT_BINARY_DIR}/${LOCATION_FOR_THE_APP})
add_custom_target(${CMAKE_CURRENT_BINARY_DIR}/${LOCATION_FOR_THE_APP} DEPENDS
My solution to this is similar to this answer. The goal of my project was to get googletests running on a cross-platform library, in which I had to wrap googletests into an XCTest Bundle. The build tool we are converting to is CMake for obvious reasons.
I ended up doing this as a pre-build step:
add_custom_command(TARGET ExampleTestTarget PRE_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_CURRENT_LIST_DIR}/resources $<TARGET_FILE_DIR:ExampleTestTarget>
)
Essentially, at prebuild, CMake will copy everything in the resources folder into the root of the target's bundle. For some reason (probably a CMake thing), XCode picked these resource files up with no issue, so I didn't have to set the files to be RESOURCE files explicitly.
If you're using MacOS Bundles/Packages/etc., you'll have to copy-paste these files into $<TARGET_FILE_DIR:ExampleTestTarget>/Resources instead since this is the default resource location for MacOS xcodeproj's generated by CMake. (There are so many loopholes to get XCTests working in CMake that I advise everyone doing cross-platform gtests to create an executable instead for MacOS so you won't get into any trouble like this anyway).
Note, you won't see the files in XCode unless you add the files in target_sources(), but who cares... it works anyway! Who develops C++ exclusively in iOS? ....

How to check appledoc valid or not in the xcode build phases run script?

i'm working in generating docset for a ios project, but stumped.
as you known, we can write a sh script for the xcode build phases run script; and i want it run only when the project in release version & the software appledoc already installed, so i write it as follows:
# appledoc Xcode script
APPLEDOC_PATH=`which appledoc`
if [ $APPLEDOC_PATH ]; then
if [ "${CONFIGURATION}" = "Release" ]; then
#============================#
# some code here, omit! #
#============================#
fi
fi
it seems not work at all! and i know the problem is the command 'which appledoc' went wrong! so the question is:
how to check appledoc valid or not in the xcode build phases run script?
any ideas? please give a hand! thanks!
I've met the problem just days ago.
If the execute file is not under /bin/sh . The command may not be found.
!!Use full path!!
I installed appledoc with macports, the bin path is /opt/local/bin .
So, it becomes 'ls' command rather than 'which' command.
It looks no option to make port command return its bin path. If other package manager can do, don't make hard code like that.
I checked $PATH and printed it with Xcode script. The path /opt/local/bin is exist.So I still have no idea why it can't find appledoc in the script.

Generating gcda files to view the code-coverage from XCTests in IOS with Jenkins

I want to view the code coverage by running gcovr on generated gcda files. Jenkins seems to put the generated gcda files in Users/../Library/developer/Xcode/DerivedData/../../../i386. I expect them to be in Users/Shared/Jenkins/workspace/../build/example.build/Debug-iphonesimulator/example.build/Objects-normal/i386
When i run my IOS project with XCode locally it does generate gcda files and i can view my coverage.
Im running xcode 5 and all tests are created with XCTest.
I've set 'Generate Test Coverage Files=YES' and 'Instrument Program Flow=YES' for debug and release, basicly i have done everything according to this post
In Jenkins i use the xcode plugin to build. It has two build commands. The first one builds with the target "example" and configuration debug.
The second Xcode build command builds with the target "ExampleTests", configuration debug, arguments" test -destination OS=7.0,name=”iPhone Retina (4-inch)” and a scheme . In the output i can see the test being run and the simulator starts on the building machnine.
It seems i have missed something maybe in the project setting or havent set something right in the jenkins job. Maybe something like TEST_AFTER_BUILD=YES only then for XCode5.
As you recognised the .gcda files are put in the "wrong" directory.
Do the following:
Select your application target in your Xcode-Project and go to "Editor -> Add Build Phase -> Add Run Script Build Phase"
Paste this script into the script field:
echo "Creating derivedDataDirectory file"
echo "${OBJECT_FILE_DIR_normal}/${CURRENT_ARCH}" > ${PROJECT_DIR}/derivedDataDirectory
XCode setup
(This creates a file with the path to the derivedDataDirectory)
Go to your jenkins project, click on "Add build step" and select "Execute shell".
Paste this script into the "Command" field:
#CopyCodeCoverageFile
echo "Start copying code coverage Files"
projectname="[YOUR PROJECTNAME]"
source=$(cat ${WORKSPACE}/$projectname/derivedDataDirectory)
cp -a $source/. ${WORKSPACE}/$projectname/
#CodeCoverage
echo "Start CodeCoverage"
cd ${WORKSPACE}/$projectname
[YOUR PATH TO GCOVR]/gcovr -r /private/tmp/workspace/${JOB_NAME}/$projectname --xml > ${WORKSPACE}/$projectname/test-reports/coverage.xml
Insert [YOUR PROJECTNAME] and [YOUR PATH TO GCOVR]. If your PROJECTNAME or target has
spaces in it, this will cause trouble! Make sure all the paths are correct!
This works for me and if all your paths are correct it should work for you to.
Im running XCTests on Jenkins using XCode 5. This should be the same as your setup.
If you dont use gcovr to generate code coverage for cobertura you can delete the last step
in the script. If you are experiencing problems with gvovr try using gcovr 3.0 instead of
3.1!
Tell me if something is not working for you or you found a better solution!

Resources