how to generate Coverage.profdata on Xcode - code-coverage

first of all thank you in advance for helping me figure this out.
I recently try using slather to produce a code coverage report for my xcode project, but when i execute slather it fail with error below
Are you sure your project is generating coverage? Make sure you enable code coverage in the Test section of your Xcode scheme.
Did you specify your Xcode scheme? (--scheme or 'scheme' in .slather.yml)
If you're using a workspace, did you specify it? (--workspace or 'workspace' in .slather.yml)
If you use a different Xcode configuration, did you specify it? (--configuration or 'configuration' in .slather.yml)
even though i already specify all configuration mention above in .slather.yml file. But i'm still getting the same error. Below are my .slather.yml code
output_directory: slather-report
scheme: *Project scheme* // This scheme has enabled code coverage in test section
workspace: *Project*.xcworkspace
xcodeproj: *Project*.xcodeproj
configuration: Staging
arch: x86_64
html: true
ignore:
- Pods/*
so i go through the slather project.rb file and find out that slather try to find a file called Coverage.profdata. But upon executing Xcode unitTest, Xocde never generate any file with name Coverage.profdata, Even though i already enable code coverage on that particular scheme.
So, am i missing something on generating Coverage.profdata, if yes please let me know? Thank you again in advance

The Coverage.profdata file is usually present in the Build/Intermediate/{scheme}/ProfileData directory. Make sure that the file is present there.
Also, make sure you are using the Product->Test option to generate the Coverage.profdata file as simply running the target in Release/Debug mode will not generate the code coverage data.

Related

Xcode/iOS xctest - Build input file cannot be found

I created the first unit test target in our iOS application by simply clicking through the plus icon inside the test tab on the left navigator.
(The target to be tested is set to the main application)
The unit test target created itself successfully but when I try to run the pre-generated tests, it outputs an error message. The error message displays that the build input file cannot be found. More specifically, the file /Plugins/XXXTests.xctest/XXXTests cannot be found. I double checked and in fact that file is not in that directory.
While I could not find anything similar to this problem, I tried everything that was close to it but nothing seemed to fix problem.
Any help would be greatly appreciated!
For me, it was because the test source files are not included in the test target.
Including those test files in the test target solved it.
It's been a while but we finally found a solution! The problem was in the Podfile where our pods weren't being applied to the different targets of our app. To fix the solution we had to define a shared pod module that included all of our pods and then we applied this new module to each different targets in our app.
Our Podfile looks like this now
I hope this helps out some people!
Do you have it set properly in schemes?
Go to Product -> Scheme -> Edit Scheme -> Test and check, if your test target is properly added to the correct scheme. It should look something like this:

iOS app fails to create archive in Xcode but builds fine

This completely baffles me. I have a project that used to archive just fine, but after I updated Xcode it is now failing to create an archive for it. The failure is from an included project source file not finding a header. Again, this is one that built just fine before and now failing. Also, it builds and runs just fine, just failing on archive. This is the version of Xcode I am using: Version 7.1 (7B91b).
Has anyone encountered similar issues?
The error is basically:
'Header.h' file not found
Again, that file exists. Its there. The project runs and builds just fine. It only fails to find it during 'Archive'.
You said that the failure is from an included source file. I have seen some people with a similar problem when they imported the Cordova library. Some of them solved it with the solution given here.
Add this line to your Build Settings -> Header Search Paths:
"$(OBJROOT)/UninstalledProducts/$(PLATFORM_NAME)/include"
Don't replace the existing line that looks similar, that is still needed to be backwards compatible with Xcode 7 and Xcode 6.4.
Good luck!
Adding this to my "Header Search Paths" fixed the problem.
"$(BUILD_ROOT)/../IntermediateBuildFilesPath/Headers"
Apparently certain folders where the headers reside are not built during the "Archive" process.
Maybe cleaning and building your project fixes the problem?
You need to select a real device as the target, otherwise archiving doesn't work. But can you build release builds at all? (For example, does "build for profiling" work? )
You need to select a real device as the target, otherwise archiving doesn't work. But can you build release builds at all? (For example, does "build for profiling" work? ) For example, you might have a line
#ifdef DEBUG
#include "MyHeader.h"
#endif
and the header won't be included in a release build. Easily done.

Dozens of "profiling:invalid arc tag" when running code coverage in Xcode 5

When running my Test target with code coverage enabled in Xcode 5, I get dozens of the following message in the build output:
profiling:invalid arc tag (0x...)
It doesn't seem to affect the tests, as they complete successfully, and also the GCDA coverage files are generated as expected.
Any idea what the message means, or how to suppress the messages/fix the issue, because they clutter up the build output and make it hard to find the test case results.
Most likely this is a result of the build tools failing to merge current results into the existing .gcda coverage files. As Dave Meehan points out here, there is a brute force way of dealing with this by cleaning the product build folder, but a less hard core approach is to delete the .gcda files from targets generating them (for me, just the test target) as part of the build process. Dave includes a sample script to be included as a build phase -- or, at the project root by hand:
find . -name "*.gcda" -print0 | xargs -0 rm
For the Xcode 7 users out there, you might have been wondering why your Unit Tests crash after receiving messages like this. The solution I found was that you need to make sure that all possible targets involved in your build flow (including all libraries) should have these two build settings set to NO:
GCC_GENERATE_TEST_COVERAGE_FILES = NO;
GCC_INSTRUMENT_PROGRAM_FLOW_ARCS = NO;
If you search for the "Code Generation" section in the build settings you will find these as "Generate Test Coverage Files" and "Instrument Program Flow".
For further reference see https://developer.apple.com/library/ios/qa/qa1514/_index.html
Old question, but now Xcode 7 GM is out, and this behavior hasn't changed, I took a deeper look. The issue, I believe is that code coverage of the test app target is conflicting with code coverage of the main target.
Assuming you don't actually care about code coverage of your test target these settings stop the errors for me, with no need for extra scripts or deleting files:
In your main target (be it a framework, or an app) set:
Enable Code Coverage Support to YES
Generage Legacy Test Coverage Files to YES
Instrument Program Flow to YES
For my purposes I only did this for Debug builds, but your needs may vary.
Then in your Tests target set:
Enable Code Coverage Support to NO
Generage Legacy Test Coverage Files to NO
Instrument Program Flow to NO
This has resolved the error messages, and still allowed the code coverage files to be created appropriately.
Again, the question is old, but as the error still is issued in XCode 7, I found this solution works better than deleting files with special scripts.
I'm having the same issue. In my appDelegate under applicationWillTerminate: I have the __gcov_flush();. Commenting this out removes the invalid arc tag messages in my build output.
I'm doing further research to figure out why this happens. I know that if I completely clean my project and delete the DerivedData directory these messages will stop for a few runs of my tests.
EDIT: I seemed to have fixed this for me. In my appDelegate I had the following:
#ifdef DEBUG
+ (void)initialize {
[[NSUserDefaults standardUserDefaults] setValue:#"XCTestLog,GcovTestObserver"
forKey:#"XCTestObserverClass"];
[super initialize];
}
#endif
I spelled GcovTestObserver wrong, and after fixing this the messages stopped. Make sure you also have a subclass of XCTestObserver in your Test target overriding stopObserving with the following:
- (void) stopObserving
{
[super stopObserving];
UIApplication* application = [UIApplication sharedApplication];
[application.delegate applicationWillTerminate:application];
}
You might want to clear out all derived data folders. Especially if you upgrade Xcode or use more than one Xcode versions.
At one time I've experienced this just after I upgraded Xcode from 6.2 to 6.3 in our integration server and we've seen these messages in the logs as well as missing classes in the coverage report generated by frankencover.it. Removing the DerivedData folders inside the integration server fixes it.
find /Library/Developer/XcodeServer -name DerivedData -print0 | xargs -0 rm -rf
I have spent some time trying to figure out how to get rid of those ugly and annoying messages:
profiling: /Users/appfactory/Desktop/WORK/App/trunk/ObjectiveC.gcda:
cannot merge previous GCDA file: corrupt arc tag (0x00000000)
It seemed like an Xcode 7 issue that was not fixed in the current Xcode 7.1 beta 2.
The problem is caused by failing to merge the existing .gcda coverage files with the current results.
What I tried:
Remove those .gcda files with RunScript - does not work in my case
echo "Delete .gcda files" echo
"${OBJECT_FILE_DIR_normal}/${CURRENT_ARCH}"
Attention: the ObjectiveC.gcda file may be at a different location!
Set the following build settings to YES - also not helping
Enable Code Coverage Support to YES
Generate Legacy Test Coverage Files to YES
Instrument Program Flow to YES
The solution in my case:
Set the following build settings for the main target
Enable Code Coverage Support to YES
Generate Legacy Test Coverage Files to YES
Instrument Program Flow to NO
Set the following build settings for the test target (and any other targets)
Enable Code Coverage Support to NO
Generate Legacy Test Coverage Files to NO
Instrument Program Flow to NO
Hope it helps!
To resolve the issue of getting "cannot merge previous GCDA file: corrupt arc tag" messages in console, avoid generating ObjectiveC.gcda file, by making “Enable Modules (C and Objective-C)" setting to "NO", in the target settings.

Xcode 4.1 fatal error: stdlib modified since the precompiled header was built

Building an iPhone app, using:
Xcode 4.1
Base SDK iOS 4.3
Apple LLVM Compiler 2.1
I have started getting the following error:
fatal error: file
'/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/../lib/clang/2.1/include/stdint.h'
has been modified since the precompiled header was built
I have tried reinstalling Xcode and OS X - no luck. What's causing this?
First try a clean build via the Product -> Clean menu (as of XCode 4.6.2).
If that still doesn't work then open the Organizer (from the menu select Window->Organizer). Once the Organizer is open, select Projects from the toolbar at the top of the window. On the left is a list of projects, select the one you are having a problem with.
The details panel (to the right of the list) will display the project name, location, status. The row beneath that shows where the Derived Data is located. Click the Delete... button the far right. A dialog will appear, click Delete.
You can also manually delete the Derived Data:
~/Library/Developer/Xcode/DerivedData/{project name + gobly-gook}
This directory contains built products and indexes for the project. It is OK to delete it because it only contains items generated by Xcode. Xcode will regenerate everything next time the project is opened.
I was able to fix it in a much easier way, by simply choosing Product > Clean, then Product > Build from the Xcode menubar.
Deleting the DerivedData folder did not work for me when Archiving.
I had to look at Build Settings - Build Locations - Precompiled Header Cache Path and delete that folder.
For me that was:
/var/folders/_w/t0mj70hd1439tqgxff7_mtt00000gn/C/com.apple.Xcode.501/SharedPrecompiledHeaders
I thought I would add a separate answer rather than a comment to Cryptognome's answer, because it is in fact a different solution when the issue comes from running xcodebuild. Like Cryptognome, I had the error come up with the command-line tool xcodebuild. As an alternative to manually going into the /var subfolders, I found that I could set my own cache for the shared PCH, which you can do by setting the environment variable SHARED_PRECOMPS_DIR, e.g as follows
xcodebuild -target Foo -configuration Release SHARED_PRECOMPS_DIR=/tmp/foo/SharedPCH
This way, I never get the error in automatic builds.
Note in the above command, I would also typically set the OBJROOT and SYMROOT env var to build also in /tmp. At the end, I clean things up.
The xcodebuild command line tool sometimes fails with this error. This happened to me when I synched an svn workspace to an earlier build. The xcodebuild tool keeps its precompiled headers in the folder Ants mentioned:
/var/folders/... scrambled eggs .../-Caches-/com.apple.Xcode.503/SharedPrecompiledHeaders/
You have to look in the build command itself to see the actual folder name (-include /var/...), but it may be using several if you're building for different architectures (arm6, arm7, simulator, e.g.) So if you're having this problem with a command line build, just delete everything in /var/.../SharedPrecompiledHeaders.
Remove the contents for the Simulator by iOS Simulator > Reset Content and Settings... and hit Rest. This will remove any existing pre-compiled instances of the headers and resources. This worked for me
Solution:
1)Product->Clean
2)Product->Build
Error Type:
a kind of Build error
One of the causes:
one might have changed the framework file.
This sometimes happens when a change is made to a framework that another framework depends upon. The precompiled header cache gets out of sync, and Xcode is unable to compile the given project.
One of the Scenarios:
one might have chosen Jump To Definition and did some change after selecting a framework control.
I was able to get rid of this error simply by cleaning (command+shift+K) and rebuilding.
I tried above all but no use. Finally I deleted Xcode and re installed again. Now it is working fine..
Xcode->delete->install again
It might help some one...
I had this error on cordova when I ran : cordova run ios
fatal error: file '/Users/.../cordova/platforms/ios/CordovaLib/CordovaLib_Prefix.pch' has been modified since the precompiled header
'/var/folders/gb/3cf6hy4x7z3d7hprls6xmd0m0000gr/C/com.apple.DeveloperTools/6.0-6A313/Xcode/SharedPrecompiledHeaders/CordovaLib_Prefix-bfgesbulnxtdepfwgniffeysypgv/CordovaLib_Prefix.pch.pch' was built
note: please rebuild precompiled header
'/var/folders/gb/3cf6hy4x7z3d7hprls6xmd0m0000gr/C/com.apple.DeveloperTools/6.0-6A313/Xcode/SharedPrecompiledHeaders/CordovaLib_Prefix-bfgesbulnxtdepfwgniffeysypgv/CordovaLib_Prefix.pch.pch'
1 error generated.
** BUILD FAILED **
The following build commands failed:
CompileC build/CordovaLib.build/Debug-iphoneos/CordovaLib.build/Objects-normal/armv7/NSDictionary+Extensions.o Classes/NSDictionary+Extensions.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
CompileC build/CordovaLib.build/Debug-iphoneos/CordovaLib.build/Objects-normal/armv7/CDVInvokedUrlCommand.o Classes/CDVInvokedUrlCommand.m normal armv7 objective-c com.apple.compilers.llvm.clang.1_0.compiler
I tried with clean and build but doesn't work, finaly I removed the folder '/var/folders/gb/3cf6hy4x7z3d7hprls6xmd0m0000gr/C/com.apple.DeveloperTools/6.0-6A313/Xcode' and works!
This tip, may be help others
Clean ways are not working for me, eventually I solved this issue by reinstall XCode.

IOS app - can debug, but not release

I've been trying to submit an app to the app store for a client (my first try) and have been running into various and sundry problems. I finally decided to create a new app name, recreate the developer provision profile and recreate the developers certificate.
I can now run it in simulator and debug on the device, but can no longer run it in release mode - it doesn't even compile. The error message is:
arm-apple-darwin10-gcc-4.2.1: /Users/me/Documents/iphone/QuizApp/CityGuide_Prefix.pch: No such file or directory
The reference to the "CityGuide_Prefix.pch" file would be a holdover from the app I based it on, and apparently did not rename correctly. I don't know why the problem showed up now.
At the beginning of the compile log there is a reference to this file:
ProcessPCH /var/folders/YN/YNuTu4omEDm9bUMfK4s5yU+++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/CityGuide_Prefix-etfgludtmplcfzcirudhxormhsna/CityGuide_Prefix.pch.gch CityGuide_Prefix.pch normal armv7 objective-c com.apple.compilers.gcc.4_2
And it also shows up under the gcc compile command under this parameter:
-c /Users/me/Documents/iphone/QuizApp/CityGuide_Prefix.pch -o /var/folders/YN/YNuTu4omEDm9bUMfK4s5yU+++TI/-Caches-/com.apple.Xcode.501/SharedPrecompiledHeaders/CityGuide_Prefix-etfgludtmplcfzcirudhxormhsna/CityGuide_Prefix.pch.gch
My question is, how do get rid of this old reference? And why did it work before?
Check the build settings for your target in release mode. You will find a GCC_PREFIX_HEADER directive stating the wrong precompiled header file name (CityGuide_Prefix.pch). Change it to the right value (which you can find inspecting the debug configuration).
If you don't find that directive for your target, check the general project build settings.
Alternatively, you can open your /project.pbxproj file and search for ".pch" (without quotes), in order to fix that value for the release configuration.
You should have a look into the Build Phases of your target and figure out the file is named there under Compile Sources. If so, remove it there.

Resources