22

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?

bneely
  • 9,083
  • 4
  • 38
  • 46
Cruinh
  • 3,611
  • 4
  • 38
  • 45
  • 1
    What kind of source control are you using that you have to wait for edits on another file before you can do a build? – Tim Jan 03 '11 at 19:12
  • I'm not waiting... that's my point. Build and Analyze takes forever on this one file I don't care about right now, so I'd just like to skip it while I work on my own files. – Cruinh Jan 03 '11 at 19:45
  • 1
    This question is particularly pertinent when considering massive third party source files that can often be included in your source tree, but you know that you will never change (I am looking at you sqlite3.c). – John Bowers Feb 20 '14 at 20:27

2 Answers2

16

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.

reference: Controlling Static Analyzer Diagnostics

otto
  • 2,230
  • 2
  • 26
  • 26
15

Same idea as this answer only for analysis -> Ignore all warnings in a specific file using 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-checks for Xcode 10 and after
  7. Optionally add -Wno-unused-command-line-argument as well, if Xcode complains that -Xanalyzer is unused during regular compiles and you want to keep your build clean

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

mm2001
  • 6,427
  • 5
  • 39
  • 37
NSDestr0yer
  • 1,419
  • 16
  • 20