可以告诉 clang 不要分析某些文件吗?
我正在尝试使用 clang 来分析我正在开发的项目。 该项目包含一个相当大的静态库,它作为依赖项包含在 Xcode 中。
我真的希望 clang 不分析依赖项的文件,因为它似乎会使 clang 失败。 这可能吗? 我一直在阅读 clang 文档,但没有找到它。
I'm trying to use clang to profile a project I'm working on. The project includes a rather large static library that is included in Xcode as a dependency.
I would really like clang to not analyze the dependencies' files, as it seems to make clang fail. Is this possible? I've been reading the clang documentation, and I haven't found it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
作为最后的手段,还有一个暴力选择。
将其添加到文件的开头:
将其添加到末尾:
并且 clang --analyze 将看不到文件的内容。
参考:控制静态分析器诊断
As a last resort, there is a brute force option.
Add this to the beginning of a file:
Add this to the end:
and clang --analyze won't see the contents of the file.
reference: Controlling Static Analyzer Diagnostics
所以,这并不是一个真正的答案,但它效果很好。
我最终做的是提前构建静态库,然后使用 scan-build 构建项目。 由于已经有静态库的最新版本,因此没有重建它,因此也没有扫描。
不过,我仍然希望得到一个真正的答案。
So, this isn't really an answer, but it worked well enough.
What I ended up doing was building the static library ahead of time, and then building the project using scan-build. Since there was already an up-to-date build of the static library, it wasn't rebuilt and thus wasn't scanned.
I'd still love to have a real answer for this, though.
最终,该选项于 2018 年得到实施。
使用
--exclude
[1] [2] 选项Finally, in 2018 the option was implemented.
Use
--exclude <path>
[1] [2] option我不使用 XCode,但在 linux 中使用 scan-build 以下内容对我有用。 就我而言,我想对所有第一方非生成的代码运行静态分析。 但是,我想避免在第三方代码和生成的代码上运行它。
在命令行上,当 scan-build 将 CC 和 CXX 环境变量设置为 ccc-analyzer 和 c++-analyzer 位置时,clang-analyzer 就会挂接到构建中。 我编写了两个名为 ccc-analyzer.py 和 c++-analyzer.py 的简单脚本,并将它们连接到编译中以代替默认脚本。 在这些包装器脚本中,我只是查看正在编译的文件的路径,然后直接运行原始编译器(如果我希望避免静态分析)或 c*-analyzer(如果我希望进行静态分析)。 我的脚本是用 python 编写的,并与我的特定构建系统相关联,但作为一个需要修改的示例:
I don't use XCode, but using scan-build in linux the following works for me. I my case, I want to run the static analysis on all first party, non-generated code. However, I want to avoid running it on third_party code and generated code.
On the command line, clang-analyzer is hooked into the build when scan-build sets CC and CXX environment variables to ccc-analyzer and c++-analyzer locations. I wrote two simple scripts called ccc-analyzer.py and c++-analyzer.py and hooked them in to the compile in place of the default. In these wrapper scripts, I simply looked at the path of the file being compiled and then run either the raw compiler directly (if I wish to avoid static analysis) or the c*-analyzer (if I wish for static analysis to occur). My script is in python and tied to my specific build system, but as an example that needs modification:
对于 Xcode 用户,您可以通过在 Target -> 中添加以下标志来从静态分析器中排除单个文件。 构建阶段 -> 编译源部分:
-Xanalyzer -analyzer-disable-all-checks
For Xcode users, you can exclude individual files from static analyzer by adding the following flags in the Target -> Build Phases -> Compile Sources section:
-Xanalyzer -analyzer-disable-all-checks