Xcode Generate Code Coverage Report fails with Error : Error Domain=IDEFoundationErrorDomain Code=14 "Failed to merge raw profiles in directory - xcode

I am unable to generate the code coverage data when the the workspace is built with custom XCODE_CONFIGURATION_BUILD_DIR.
We run the xcodebuild commands to build the workspace with a XCODE_CONFIGURATION_BUILD_DIR, so that multiple jenkins CI jobs won't overwrite the build output of other jobs which are also running concurrently.
When we run the tests for a build generated this way and try to get the code coverage report, the command fails with the below error.
jenkins$ xcrun xccov view *.xccovreport
Errors:
Error Domain=IDEFoundationErrorDomain Code=14 "Failed to merge raw profiles in directory /Users/jenkins/Library/Developer/Xcode/DerivedData/XXXXXX-buggtqumttnpjvejnbfhulhqcvno/Build/ProfileData/bff950eda0f75b2dbadb3ce08510474b4667ac82 to destination /Users/jenkins/Library/Developer/Xcode/DerivedData/XXXXXX-buggtqumttnpjvejnbfhulhqcvno/Build/ProfileData/bff950eda0f75b2dbadb3ce08510474b4667ac82/Coverage.profdata: No profile data files were written to '/Users/jenkins/Library/Developer/Xcode/DerivedData/XXXXXX-buggtqumttnpjvejnbfhulhqcvno/Build/ProfileData/bff950eda0f75b2dbadb3ce08510474b4667ac82'" UserInfo={NSLocalizedDescription=Failed to merge raw profiles in directory /Users/jenkins/Library/Developer/Xcode/DerivedData/XXXXXX-buggtqumttnpjvejnbfhulhqcvno/Build/ProfileData/bff950eda0f75b2dbadb3ce08510474b4667ac82 to destination /Users/jenkins/Library/Developer/Xcode/DerivedData/XXXXXX-buggtqumttnpjvejnbfhulhqcvno/Build/ProfileData/bff950eda0f75b2dbadb3ce08510474b4667ac82/Coverage.profdata: No profile data files were written to '/Users/jenkins/Library/Developer/Xcode/DerivedData/XXXXXX-buggtqumttnpjvejnbfhulhqcvno/Build/ProfileData/bff950eda0f75b2dbadb3ce08510474b4667ac82'}
Version/Build:
Version 10.1 (10B61)

Found this thread on Github
The issue was: generating coverage for a Static Library fails, but not for a Dynamic Library.
So check if it works, changing on pbxproj:
- MACH_O_TYPE = staticlib;
+ MACH_O_TYPE = mh_dylib;
And it really generated coverage successfully on my sample framework.

The solution which worked for me was, I have changed the Mach-O-Type from Executable to Static Library.
With the option Dynamic Library also, the coverage report was generating but the build was failing.
Another option was to set the test target as Static Library and Main Target as Executable. Build Succeeded and able to see the coverage for multiple targets.
Xcode Version : 13.4

Related

Coverity Scan for JS

I have initiated the Coverity scan for the JS using Coverity Wizards.
The capture build step has been completed & failed in to Run analysis step.
The failed message is "failed with error code 8. See console for details.
Some of your source code may not have been captured, which can result in fewer issues being found.
Please check that all project files in compiled languages are being built by the provided build command, and that all interpreted language files are parsable by the appropriate interpreter.
Please refer to the console for the build errors you are getting and see if your build is successful. Once your build will be successful ,then only you can run the cov-analysis .
For JavaScript you need to perform buildless capture. Please Run the cov-capture command for the repository/directory that contains your project(s).Kindly refer to cov_analysis_administration_guide.html document .You can find it under /doc/en/ folder.
Furthermore, which version of Coverity you are using ? Use of Coverity Wizard has been deprecated since 2021.09. You can try running the central build or point&scan .

Azure DevOps Pipelines build using Xcode CLI command, xcodebuild, failing. Cannot open content.xcworkspacedata file

I am attempting to trigger an Xcode build using Azure Pipelines. Pipelines essentially uses Xcode BuildTools commands to create the build. I am receiving the following error where I've inserted Project and ProjectPath to replace:
xcodebuild: error: Unable to read project ProjectName.xcodeproj' from folder 'ProjectPath'. Reason: Could not open workspace file at ProjectPath.xcodeproj/project.xcworkspace/contents.xcworkspacedata
Strange thing is that if I run my build command directly on the build server, from the build server's CLI, there is no issue and the build succeeds. However, when I try via Pipelines it says that this particular file, contents.xcworkspacedata, can't be opened.

Xcode 10, sourcery & swiftlint build phases order

After updating to Xcode 10 there are some issues with initial project configurations. The steps look like this:
Generating some files using Sourcery
Linting with SwiftLint
Build
And configuration works like this:
And this was working fine in Xcode 9, but apparently, it's not working under Xcode 10 build system. The issue is if I download repository (.generated files are not a part of the repository). And hit build it will show me results like:
...
Using configuration file at '.sourcery.yml'
Scanning sources...
Found 239 types.
Loading templates...
Loaded 9 templates.
Generating code...
Finished.
Processing time 0.491948962211609 seconds
...
So sourcery works ok, then linting:
Linting 'FromResponse.generated.swift' (1/186)
Works fine as well as a process, but in the end, build will fail with:
error: Build input files cannot be found:
'/path/Generated/FromResponse.generated.swift',
...
So it's strange since a files are physically there and according to build settings file should be compiled later than generating them. How should I approach sourcery in build process then?
We are able to "fix" this in a similar way as this Github issue:
https://github.com/mac-cain13/R.swift/issues/438#issuecomment-416982928
We have to add each of the generated files by Sourcery to the output folder and it will get picked up by the Xcode correctly.
This relates to changes in the New Xcode Build System that has been enabled by default in Xcode 10. If a build phase creates files which are needed as an input to a later build phase then it needs to specify them explicitly in the Output Files or Output File List.
In your example the Sourcery build phase is generating Swift source file(s) which are needed as input to the Compile Sources phase.
However, the issue at this point is that after you specify the output files for Sourcery, the build phase doesn't re-run every time as it sees the output file is already there. So far I haven't worked out a useable solution to this part, beyond running tools like Sourcery and SwiftGen manually or keeping the generated files in Git so that they are always present.
I was having a similar problem with a buildphase calling mogenerator to build my data model classes. The approach given by #Yuchen should work.
#Andrew: To force always (re-)running this build phase, I add the line
touch .alwaysRun
as the last line in the shell command to run and mark the build phase "Input Files" to have $(SRCROOT)/.alwaysRun. That seems to do the trick.

LCov - Found unrecognized record format errors

I've looking to get an HTML code coverage report working with an XCode 6.1 based project. My solution 'partially works', but I'm getting a lot of skipped files when running lcov:
geninfo: file found unrecognized record format - skipping
Some more detail on my setup:
Created an XCode 'Coverage' configuration via these instructions (Steps 1+2):
https://developer.apple.com/library/ios/qa/qa1514/_index.html
Build and run my standalone testrunner using this configuration via xcodebuild.
This successfully appears to generate GCNO files and GCDA files for each of my source files. So far so good.
Run lcov (v1.11) to generate an HTML report. The command I'm using looks like the following:
lcov --capture --derive-func-data --directory ./build/Coverage/MyCppRunner.build --output-file lcov-testrun.info --ignore-errors graph
This also succeeds, due to the ignore-errors argument. However, I'm getting a lot of skipped gcno files with the following error:
geninfo: WARNING: /Users/myname/build/Coverage/MyCppRunner.build/Objects-normal/x86_64/MyFile.gcno: found unrecognized record format - skipping
When I generate my HTML report via genhtml, these files don't show any coverage.
Is there any way around this issue? A different set of clang flags perhaps, or an alternative to lcov? I briefly tried gcovr, but I couldn't get it working.

What does the error "version '404*', prefer '402*'" mean running gcov

Trying to build coverage data for Coveralls I get the following error messages during the Travis-CI build:
DTHTMLWriter.gcno:version '404*', prefer '402*'
File '/Users/travis/build/Cocoanetics/DTCoreText/Core/Source/DTHTMLWriter.m'
Lines executed:67.00% of 497
/Users/travis/build/Cocoanetics/DTCoreText/Core/Source/DTHTMLWriter.m:creating 'DTHTMLWriter.m.gcov'
File 'Core/Source/DTHTMLWriter.m'
Lines executed:0.00% of 10
Core/Source/DTHTMLWriter.m:creating 'DTHTMLWriter.m.gcov'
Core/Source/DTHTMLWriter.m:cannot open source file
File 'Core/Source/DTHTMLWriter.h'
Lines executed:66.67% of 3
Core/Source/DTHTMLWriter.h:creating 'DTHTMLWriter.h.gcov'
Core/Source/DTHTMLWriter.h:cannot open source file
There is coverage, namely 67%, but the result of this is that Coveralls shows this file as having 0 coverage.
How do I fix that?
Tests have shown that this error occurs with the gcov tool bundled with Xcode 4 and 5, version 4.2.1 in both cases. I dound that if I run the same unit test on Mac instead, then I don't get the warning and the files are found.
Which lewds me to believe that the gcov tool has a bug handling certain gcda files produced by iOS simulator. Some, not all.
The resultning coverage report is missing those files when run for iOS, but is complete for Mac.
So my second question is if there is a way to change those files to allow gcov to correctly process them?

Resources