简体   繁体   English

Xcode 4.2代码覆盖率

[英]Xcode 4.2 Code Coverage

I started to use Xcode 4.2 and i have problems with generating code coverage. 我开始使用Xcode 4.2,我在生成代码覆盖方面遇到了问题。

Xcode 4.2 does not include the GCC 4.2 compiler, but it was replaced with the LLVM GCC 4.2 compiler. Xcode 4.2不包含GCC 4.2编译器,但它已被LLVM GCC 4.2编译器取代。 The first one was needed to generate code coverage in the previous version of Xcode. 第一个需要在以前版本的Xcode中生成代码覆盖。

I followed the 'tutorial' on CoverStory website , but this results in the following: 我按照CoverStory 网站上的“教程”进行了操作,但结果如下:

a) when i do all steps, no coverage files. a)当我执行所有步骤时,没有覆盖文件。
b) when i link the libprofile_rt.dylib to my project, the test which should fail, do not fail anymore. b)当我将libprofile_rt.dylib链接到我的项目时,应该失败的测试,不再失败。

Did anyone encounter this issue? 有人遇到过这个问题吗? And how did you solve it? 你是怎么解决的?

Thanks 谢谢

This Blog has a nice tutorial on how to achive gcc-compatible coverage results with LLVM. 这个博客提供了一个很好的教程,介绍如何使用LLVM实现与gcc兼容的覆盖结果。

The coverage features are available in the current LLVM frontend but as it seems not exposed 覆盖功能在当前的LLVM前端中可用,但似乎没有暴露
in the current version that ships with XCode. 在XCode附带的当前版本中。

I agree tho the author that it can be a solution to compile your own version for coverage purposes and stick to the shipped version for final binary generation. 我同意作者的说法,它可以是一个解决方案来编译自己的版本用于覆盖目的,并坚持最终二进制生成的发货版本。

I's also worth to note that his tutorial claims: 我还值得注意他的教程声称:

Since Clang outputs these files in the same format as GCC,
they are compatible with tools such as CoverStory.

Maybe this is of some use to you. 也许这对你有用。

Here is a way to enable compiling with gcc 4.2 in xcode 4.2 . 这是一种在xcode 4.2中使用gcc 4.2进行编译的方法。 This is mostly done via command line so when you see lines starting with: [ 15:30 jon@MacBookPro / ]$ , you need to open up Terminal.app and run the command that starts after the $ . 这主要通过命令行完成,因此当您看到以[ 15:30 jon@MacBookPro / ]$开头的行时,您需要打开Terminal.app并运行在$后面开始的命令。

No files or directories are removed or deleted in this process, so it is easy to undo if you need to compile with LLVM in the future. 在此过程中不会删除删除任何文件或目录,因此如果您将来需要使用LLVM进行编译,则很容易撤消。

  1. Download - but do not install yet - xcode_4.1_for_lion.dmg or xcode_4.1_for_snow_leopard.dmg 下载-但是不要安装尚未 - xcode_4.1_for_lion.dmgxcode_4.1_for_snow_leopard.dmg

  2. Now, follow these steps to install Xcode 4.1 into /Developer-4.1 : 现在,按照以下步骤将Xcode 4.1安装到/Developer-4.1

    1. Backup the working /Developer directory (where Xcode 4.2 is installed) 备份working /Developer目录(安装Xcode 4.2的地方)

    2.  [ 15:30 jon@MacBookPro / ]$ sudo mv -v /Developer /Developer-4.2 
    3. Run the Xcode 4.1 installer using the default install location ( /Developer ) 使用默认安装位置( /Developer )运行Xcode 4.1安装程序

    4. Move the new Xcode 4.1 installation to /Developer-4.1 : 将新的Xcode 4.1安装移至/Developer-4.1

       [ 15:30 jon@MacBookPro / ]$ sudo mv -v /Developer /Developer-4.1 
    5. Move the Xcode 4.2 developer directory back to /Developer : 将Xcode 4.2开发人员目录移回/Developer

       [ 15:30 jon@MacBookPro / ]$ sudo mv -v /Developer-4.2 /Developer 
  3. Edit the Xcode 4.2 GCC 4.2.xcspec file to get gcc 4.2 to show in the list of compiler options [1] : 编辑Xcode 4.2 GCC 4.2.xcspec文件,使gcc 4.2显示在编译器选项列表中[1]

     [ 15:30 jon@MacBookPro / ]$ sudo vi "/Developer/Library/Xcode/PrivatePlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/GCC 4.2 (Plausible Blocks).xcplugin/Contents/Resources/GCC 4.2.xcspec" 
    • Change lines 41 and 42 from this: 从这里改变第4142行:

       ShowInCompilerSelectionPopup = NO; IsNoLongerSupported = YES; 
    • To This: 对此:

       ShowInCompilerSelectionPopup = YES; IsNoLongerSupported = NO; 
  4. Backup the Xcode 4.2 iOS/Simulator Framework usr directories: 备份Xcode 4.2 iOS / Simulator Framework usr目录:

     [ 15:30 jon@MacBookPro / ]$ sudo mv -v /Developer/Platforms/iPhoneOS.platform/Developer/usr /Developer/Platforms/iPhoneOS.platform/Developer/usr.backup [ 15:30 jon@MacBookPro / ]$ sudo mv -v /Developer/Platforms/iPhoneSimulator.platform/Developer/usr /Developer/Platforms/iPhoneSimulator.platform/Developer/usr.backup 
  5. Copy Xcode 4.1 iOS/Simulator Framework usr directories to Xcode 4.2: 将Xcode 4.1 iOS / Simulator Framework usr目录复制到Xcode 4.2:

     [ 15:30 jon@MacBookPro / ]$ sudo cp -rv /Developer-4.1/Platforms/iPhoneOS.platform/Developer/usr /Developer/Platforms/iPhoneOS.platform/Developer/usr [ 15:30 jon@MacBookPro / ]$ sudo cp -rv /Developer-4.1/usr /Developer/Platforms/iPhoneSimulator.platform/Developer/usr 
  6. Copy the gcc and info iOS SDK library directories from Xcode 4.1 to Xcode 4.2 [2] : gccinfo iOS SDK库目录从Xcode 4.1复制到Xcode 4.2 [2]

     [ 15:30 jon@MacBookPro / ]$ sudo cp -rv /Developer-4.1/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/gcc /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/gcc [ 15:30 jon@MacBookPro / ]$ sudo cp -rv /Developer-4.1/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/info /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/info 
  7. Compile using gcc-4.2! 使用gcc-4.2编译!

    xcode 4.2中CGG 4.2的屏幕截图

This is a blog post I've written with a little more info about this process. 这是一篇博文,我写了一些关于这个过程的更多信息。 Feel free to leave a comment on the blog if you run into any issues or have any questions. 如果您遇到任何问题或有任何问题,请随时在博客上发表评论。


[1] If opening from a command line (using something like vi , emacs , nano , etc) make sure to either enclose the path in quotes "/long path/with spaces/in it/file.xcspec" or escape the spaces /some/long\\ path/with\\ spaces/in\\ it/file.xcspec [1]如果从命令行打开(使用类似viemacsnano等的东西),请确保将路径括在引号“/ long path / with spaces / in / file.xcspec”中,或者转义空格/ some / long \\ path / with \\ spaces / in \\ it / file.xcspec

[2] This is necessary because the iPhoneOS.platform SDK has its own seperate /usr/lib directories but the iPhoneSimulator.platform SDK does not [2]这是必要的,因为iPhoneOS.platform SDK有自己的单独的/usr/lib目录,但iPhoneSimulator.platform SDK没有

The default compiler of Xcode 4.2 is LLVM 3.0. Xcode 4.2的默认编译器是LLVM 3.0。 Apple is moving away from LLVM to GCC 4.2, which is still available as an option. Apple正在从LLVM转移到GCC 4.2,它仍然可以选择。 GCC 4.2 however is gone for good. 然而,GCC 4.2已经不复存在了。

I suppose you have no option other than finding a different code coverage solution that works with LLVM 3.0 (preferably) or LLVM GCC 4.2, or wait until someone provides such a tool. 我想除了找到一个与LLVM 3.0(最好)或LLVM GCC 4.2一起使用的不同代码覆盖解决方案之外别无选择,或者等到有人提供这样的工具。 After all, Xcode 4.2 is relatively new and code coverage relatively important, so I'm sure eventually a working solution will surface. 毕竟,Xcode 4.2相对较新,代码覆盖相对重要,所以我相信最终会有一个有效的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM