Question

Running xcodebuild from the console will bring you very verbose output and I wasn't able to locate any options for limit its output in order to display only warnings and errors.

I'm looking for a way to capture the xcodebuild output and filter it. It would prefer a Python solution that will work with pipes but I'm open to other approaches as long they are command line based solutions.

Are any tools that are already able to do this?

Was it helpful?

Solution

To only see the error output messages, redirect the standard output to /dev/null (a special file that works as a black hole) like this:

xcodebuild > /dev/null

If you want to capture the error output into a file, you can do:

xcodebuild 2> ./build_errors.log

OTHER TIPS

Use xcodebuild -quiet.

According to the xcodebuild man page:

-quiet : Do not print any output except for warnings and errors.

Bonus: No other tools necessary! (Although I also like xcodebuild | xcpretty)

I build with Travis CI, which complains after 4 MB of logs. This argument solved the problem.

There’s a Ruby gem called xcpretty.

It filters the output of xcodebuild and also provides different formatters and coloring.

This isn't sufficient for me. Piping to /dev/null will just show you that a build failed, but you don't see the reason(s) why. Ideally we could see just the errors and/or warnings without all of the successful compiler commands.

This basically does the job:

xcodebuild | grep -A 5 error:

enter image description here

-quiet is the best way to do it at now.

There’s a Swift command line tool https://github.com/thii/xcbeautify that can also format xcodebuild output.

I love xcpretty for looking at as a human, but I had a need to find build errors in an automated setting for propagation elsewhere, and I wanted to be sure I captured just the relevant information. The following sed command serves that purpose:

xcodebuild | sed -nE '/error:/,/^[[:digit:]] errors? generated/ p'

Output:

main.c:16:5: error: use of undeclared identifier 'x'
    x = 5;
    ^
main.c:17:5: error: use of undeclared identifier 'y'
    y = 3;
    ^
2 errors generated.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top