warnings2xcconfig is a tool to extract compiler and static analyzer warning flags from Xcode and format them into a xcconfig file you can use in your projects.
It provides sensible defaults for each flag so you can get as much help from the compiler as possible.
You can find pre-generated xcconfig files for your version of Xcode in the Xcode-*
folders. Each folder contains a few xcconfig files with differents default settings (one per --defaults
option, see below for what each option means).
To produce a xcconfig file with strict, hand-picked defaults, run:
python3 warnings2xcconfig.py --defaults strict > Warnings.xcconfig
This will produce a xcconfig file with strict, but pragmatic, handpicked default values for each build setting.
You may need to install python 3 to run the script. Python 3 is available using brew:
brew install python3
The possible values you can pass to the --defaults
flag are:
Use strict, hand-picked default values. Those are similar to "agressive", but with some warnings turned off to keep day-to-day development sane:
python warnings2xcconfig.py --defaults strict
Use Clang's default values:
python warnings2xcconfig.py --defaults clang
Use Xcode's default values (the ones you get when creating a new project):
python warnings2xcconfig.py --defaults xcode
Enable all warnings, using the most aggressive option available for each flag:
python warnings2xcconfig.py --defaults aggressive
If you pass none
, or do not include the --defaults
flag at all, the xcconfig file will be generated without default values, but with comments listing the valid values for each flag.
For example:
$ python warnings2xcconfig.py --defaults none
// Generated using XcodeWarningsAsXcconfig
// https://github.com/guillaumealgis/XcodeWarningsAsXcconfig
// Apple LLVM 7.1 - Warnings - Objective C and ARC
CLANG_WARN_OBJC_REPEATED_USE_OF_WEAK = // YES | NO
CLANG_WARN_OBJC_EXPLICIT_OWNERSHIP_TYPE = // YES | NO
... snip ...
// Static Analyzer - Analysis Policy
RUN_CLANG_STATIC_ANALYZER = // YES | NO
CLANG_STATIC_ANALYZER_MODE = // shallow | deep
CLANG_STATIC_ANALYZER_MODE_ON_ANALYZE_ACTION = // shallow | deep
You can then pick the settings you want to enable or not for your specific needs.
If you decide to include Clang Static Analyzer flags in your xcconfig (which is the default), remember to enable the Static Analyzer in your project.
It can be done with the following flags (either in your xcconfig or Xcode project):
RUN_CLANG_STATIC_ANALYZER // YES | NO
CLANG_STATIC_ANALYZER_MODE // deep | shallow
CLANG_STATIC_ANALYZER_MODE_ON_ANALYZE_ACTION // deep | shallow
By default, the script will use xcode-select -p
to find your Xcode installation path. If you want to extract warnings from another Xcode install (say, a Beta), use the --xcode-path
flag:
python warnings2xcconfig.py --xcode-path /Applications/Xcode-Beta.app/
To find out what changed between two version of Xcode, you can use the following command (in bash):
diff <(grep -E "^[^/ ]" Xcode-10.3/Warnings-XcodeDefaults.xcconfig | sort) <(grep -E "^[^/ ]" Xcode-11.0/Warnings-XcodeDefaults.xcconfig | sort)
(replace the xcconfig files to compare in the command)
All PRs are welcome, just try to respect PEP-8, and make sure the code is formatted using Black.
The hand-picked values for the --defaults strict
flag are really open to change (see the first few line of the script), I'd be super happy to get feedback on real-world results of using these.
This project is largely inpired from other great xcconfig projects and blog posts:
- https://github.com/jonreid/XcodeWarnings
- https://github.com/tewha/MoreWarnings-xcconfig
- http://www.jontolof.com/cocoa/using-xcconfig-files-for-you-xcode-project/
Credit to @steipete for finding the Clang Analyzer alpha checkers.
Guillaume Algis (@guillaumealgis)