在 Xcode 中使用 Clang 静态分析器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/961844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:36:25  来源:igfitidea点击:

Using Clang Static Analyzer from within Xcode

xcodeclang

提问by mmc

Since there is no Xcode script variable for "current project directory," how can you create a script menu item to run the Clang Static Analyzer on your current project from Xcode?

由于“当前项目目录”没有 Xcode 脚本变量,您如何创建脚本菜单项以从 Xcode 对当前项目运行 Clang 静态分析器?

采纳答案by mmc

From the XCode script menu item, "Edit User Scripts" enter the following script:

从 XCode 脚本菜单项中,“编辑用户脚本”输入以下脚本:

#!/bin/bash
result=$( osascript << END
tell application "Xcode"
 tell active project document
  set projectPath to path as string
 end tell 
end tell 
return projectPath
END
)

cd "$result"

/Developer/clangchecker/scan-build -k -V xcodebuild -configuration Debug -sdk iphonesimulator3.0

Obviously, you will need to adjust the path to your install of Clang, and adjust to the version of the SDK you are using.

显然,您需要调整安装 Clang 的路径,并调整到您使用的 SDK 版本。

Remember to do a "Clean All" immediately before using scan-build, or the results may be incomplete.

请记住在使用 scan-build 之前立即执行“全部清除”,否则结果可能不完整。

回答by Dan J

FYI, Xcode 3.2 (Snow Leopard only I believe) includes the Clang Static Analyzer in the "Build and Analyze" menu option.

仅供参考,Xcode 3.2(我相信只有雪豹)在“构建和分析”菜单选项中包含 Clang 静态分析器。

http://iosdevelopertips.com/xcode/static-code-analysis-clang-and-xcode-3-2.html

http://iosdevelopertips.com/xcode/static-code-analysis-clang-and-xcode-3-2.html

One downside of Xcode 3.2 (aside from it only working on Snow Leopard) is that the v2.x Simulators don't seem to work - in fact, I've seen posts indicating that v2.x builds are not supported at all.

Xcode 3.2 的一个缺点(除了它仅适用于 Snow Leopard)是 v2.x 模拟器似乎不起作用 - 事实上,我看到一些帖子表明 v2.x 版本根本不受支持。

回答by user7610

Either use the version bundled in XCode 3.2+, or download a newer version at https://clang-analyzer.llvm.org/then see some additional instructions at https://clang-analyzer.llvm.org/xcode.htmlto switch XCode to that downloaded version.

无论是使用XCode中捆绑3.2+版本,或下载新版本https://clang-analyzer.llvm.org/然后看到一些额外的指令在https://clang-analyzer.llvm.org/xcode.html到将 XCode 切换到该下载版本。

回答by Barry Wark

I believe the ${PROJECT_DIR} environment variable is what you want for the directory of the project running a build-phase script.

我相信 ${PROJECT_DIR} 环境变量是运行构建阶段脚本的项目目录所需要的。