简体   繁体   English

如何使用 Xcode static 分析器命令行生成 HTML 警告报告?

[英]How to use Xcode static analyzer command line to generate an HTML report of warnings?

I installed llvm and use scan-build to statically analyze a very simple demo project.我安装了 llvm 并使用scan-build静态分析了一个非常简单的演示项目。 In this project, I intentionally created a retain cycle and Xcode can immediately display a retain cycle warning in the editor.在这个项目中,我故意创建了一个保留周期,Xcode 可以立即在编辑器中显示保留周期警告。 However, if I switch to use the following scan-build command line tool, it states that no bugs found and no report is generated in the end.但是,如果我切换到使用下面的scan-build命令行工具,它会说没有发现任何错误并且最终没有生成报告。

scan-build xcodebuild -workspace RetainCycleDemo.xcworkspace -scheme RetainCycleDemo -configuration Debug -sdk iphonesimulator15.2

Here's the retain cycle code snippet.这是保留周期代码片段。

@interface ViewController ()

@property (nonatomic, copy) void(^aBlock)(void);

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.aBlock = ^{
        NSLog(@"current vc = %p", self);
    };
    self.aBlock();
}

What I want to do is use any static analyzer command line tool to find bugs such as some retain cycles.我想做的是使用任何 static 分析器命令行工具来查找诸如某些保留周期之类的错误。 Since Xcode is able to report warnings in the editor, how can we ask it to generate a report that contains these warnings?既然 Xcode 能够在编辑器中报告警告,我们如何要求它生成包含这些警告的报告? Or is there any other command line tools we can use?或者还有其他我们可以使用的命令行工具吗?

If you call scan-build without any checkers, it will use default checkers for analysing.如果您在没有任何检查器的情况下调用 scan-build,它将使用默认检查器进行分析。 You can check default enabled checker with您可以检查默认启用的检查器

scan-build --help

Checkers with "+" are enabled by default.默认情况下启用带有“+”的检查器。 Within the list, there are some checkers, that work with OSX (for example: osx.OSObjectRetainCount Check for leaks and improper reference count management for OSObject).在列表中,有一些检查器可以与 OSX 一起使用(例如:osx.OSObjectRetainCount 检查 OSObject 的泄漏和不正确的引用计数管理)。 To enable checker, use -enable-checker:要启用检查器,请使用 -enable-checker:

scan-build -enable-checker osx.OSObjectRetainCount <your compile command>

Wish it would help.希望它会有所帮助。

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

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