Xcode 构建和分析 - 是否可以故意跳过对特定文件的分析?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4587473/
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 20:03:39  来源:igfitidea点击:

Xcode Build and Analyze - Is it possible to purposely skip analysis on a particular file?

xcodestatic-analysis

提问by Cruinh

I have one particular file in my project which is being worked on by someone else. I don't want to mess with it and would rather not wait for "Build and Analyze" to process it. Is there a way to tell Xcode to skip analysis on this file?

我的项目中有一个特定文件正在由其他人处理。我不想弄乱它,也不想等待“构建和分析”来处理它。有没有办法告诉 Xcode 跳过对这个文件的分析?

采纳答案by otto

If it's OK to edit the file, there's a brute force option.

如果可以编辑文件,则有一个蛮力选项。

Add this to the beginning of the file:

将此添加到文件的开头:

// Omit from static analysis.
#ifndef __clang_analyzer__

Add this to the end:

将此添加到最后:

#endif // not __clang_analyzer__

and the clang analyzer won't see the contents of the file.

并且 clang 分析器不会看到文件的内容。

reference: Controlling Static Analyzer Diagnostics

参考:控制静态分析器诊断

回答by NSDestr0yer

Same idea as this answer only for analysis -> Ignore all warnings in a specific file using LLVM/Clang

与此答案相同的想法仅用于分析 ->使用 LLVM/Clang 忽略特定文件中的所有警告

You can include a "compile sources" argument in the "Build Phases" tab of the project settings to ignore a specific file from the analyzer. Here are some instructions:

您可以在项目设置的“构建阶段”选项卡中包含“编译源”参数以忽略分析器中的特定文件。以下是一些说明:

  1. Select the target for the project you want to change.
  2. Select the build phase tab.
  3. Expand the "Compile Sources" menu.
  4. Find the file to edit.
  5. Double click its "Compiler Flags" cell to change the arguments.
  6. Add -Xanalyzer -analyzer-disable-checker, or -Xanalyzer -analyzer-disable-all-checksfor Xcode 10 and after
  7. Optionally add -Wno-unused-command-line-argumentas well, if Xcode complains that -Xanalyzeris unused during regular compiles and you want to keep your build clean
  1. 为要更改的项目选择目标。
  2. 选择构建阶段选项卡。
  3. 展开“编译源”菜单。
  4. 找到要编辑的文件。
  5. 双击其“编译器标志”单元格以更改参数。
  6. 添加-Xanalyzer -analyzer-disable-checker, 或-Xanalyzer -analyzer-disable-all-checksXcode 10 及之后
  7. 也可以选择添加-Wno-unused-command-line-argument,如果 Xcode 抱怨-Xanalyzer在常规编译期间未使用并且您希望保持构建干净

Note: adding -w will also disable warnings on a particular file as well.

注意:添加 -w 也会禁用特定文件的警告。