Skip to content

leavez/LazyWarningChecker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

LazyWarningChecker

A configurable warning checking script for Xcode project.

What

LazyWarningChecker is:

  • a script that print matched warnings from Xcode's build log.
  • a solution that moves the "Treat Warnings as Errors" feature to commit time, with configurable rules, without blocking debugging.
  • also a tool to generate a blame report of warnings.

Why "Treat Warnings as Errors"?

Warnings may grow to a huge level if we aren't disciplined enough. Too many warnings can swallow the newly generated ones when coding, which may have potential problems.

For example, an unimplemented method may cause a crash, but it can be easily avoided at by fix the compile warnings.

Why another checking script?

"Treat Warnings as Errors" is good, but very annoying when coding/debugging. The building could be interpreted by warnings very often, such as unused variables and unimplemented methods, which are common halfway code when developing.

So we move the checking to commit time, and get both strict warning checking and relaxed coding experience.

Furthermore, the script provides a way to set checking rules, compared to prohibit all warning. You could only check several rules, or exclude some files.

Also, the script provides a functionality of generating a blame report for warning lines.

Usage

setup steps for moving "Treat Warnings as Errors" to commit time

  1. Copy the 2 script files to your project directory

  2. Add below to the build Post-Action of your scheme (remember to replace the path). And set Provide build setting from to your target.

# wait log file generated (3 seconds)
function action() { sleep 3; python $SRCROOT/path/to/check_warning.py $BUILD_ROOT -o $SRCROOT/.warning_checker/last_result; python $SRCROOT/path/to/add_pre_commit_hook.py add $SRCROOT;  }

# run in background to avoid blocking app launching
action&
  1. Add .warning_checker/last_result to .gitignore

Done! Now you could get a commit time warning checking.

NOTE: if a pre-commit hook already existed, you should add the hook manually. The hook content could be got from python add_pre_commit_hook.py raw

NOTE: Depend on how it works, the script cannot 100% guarantee excludes the warning line from committing. The checking result is only refreshed when build finished. So any change after building cannot be checked by this script. But it’s enough for most using cases.

generate blame report

python check_warning.py --blame path/to/issues_log # the path is the content of $BUILD_ROOT, you can the log_path in .warning_checker/last_result

files

check_warning.py the main script for checking warnings

add_pre_commit_hook.py add pre-commit git hook to read the checking result. more options in "—help"

configuration

Configuration file could be pass to check_warnings.py with -c option.

The configuration file is a JSON formatted text.

{
    "show_non_pass_warning": "all",
    "rules": [
        { "type" : "flag", "content": "-Wunused-variable" }
    ],
    "exclusive_rules": [
        { "type" : "regex", "content": "ABC.m" }
    ]
}
  • show_non_pass_warning : all means record all matched warnings. first means just return on the first match.
  • rules: the checking rules. No rule key in config means check all warnings.
    • the rule object represented as { "type" : "flag", "content": "-Wunused-variable" }
    • type: flag means the match the compiler's flag
    • type: regex means match the warning log with regular expression. You could use it to match a specific file, or what you want. A common warning log looks like /path/to/the/sourefile/ABCView.h:112:39: warning: auto property synthesis will not synthesize property 'description' because it is 'readwrite' but it will be synthesized 'readonly' via another property [-Wobjc-property-synthesis]
  • exclusive_rules the rule to exclude warning logs.

How

LazyWarningChecker scans the build logs generated by Xcode. All issues are logged as xcactivitylog file ( just a gzip file) in some path of the derivedData.

The script runs in the post-build action (so we could run background task without block debugging.) and saves the checking result to file, which will be read by pre-commit git hook.

License

LazyWarningChecker is available under the MIT license.