How to filter the xcodebuild command line output?

XcodeBuild ProcessConsoleBuild AutomationXcodebuild

Xcode Problem Overview


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?

Xcode Solutions


Solution 1 - Xcode

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.

Solution 2 - Xcode

There’s a Ruby gem called xcpretty.

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

UPDATE: As Mike Hardy correctly states in the comments to this answer, xcpretty is no longer maintained.

Solution 3 - Xcode

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:

Solution 4 - Xcode

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

Solution 5 - Xcode

enter image description here

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

Solution 6 - Xcode

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

Solution 7 - Xcode

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.

Solution 8 - Xcode

I am building an expo project and there are a lot of warnings that come from libraries which I don't want to see. I was able to filter out the warnings with this command.

set -o pipefail \
&& xcodebuild build -workspace app.xcworkspace -scheme app \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
| xcpretty \
| grep --line-buffered -v -F "[-W" \
| grep --line-buffered -v -F "*" \
| grep --line-buffered -v -F "^" \
| grep --line-buffered -v -F ";" \
| grep --line-buffered -v -e "^$" \
| grep --line-buffered -v -F "@" \
| grep --line-buffered -v -F ")" \
| grep --line-buffered -v -F "/" \
| grep --line-buffered -v -F "}" \
| grep --line-buffered -v -F "{" \
| grep --line-buffered -v -F "\\" \
| grep --line-buffered -v -F "#" \
| grep --line-buffered -v -F ","

I'll admit it's a little sloppy but I couldn't get any of the other solutions to work. The -quiet option still printed hundreds of warnings I had no ability to resolve.

What is strange is that when I compile on the command line on the build machine I wasn't getting the warnings but when I compiled in my CI build I would get the warnings. Very annoying. I wish apple would provide a way to silence warnings for xcodebuild

Solution 9 - Xcode

I have been bitten by xcpretty swallowing way too much information in a CI environment, making it pretty hard to debug the error. -quiet hides output in a way that's a bit too aggressive, so I put together this one-liner and called it xcquiet.sh. It only hides specific lines, while preserving enough of the original output and not swallowing any other unexpected log entries.

Solution 10 - Xcode

if you want to remove warnings use

xcodebuild <command> | sed -e '/warning:/,/\^/d'

if you want to suppress warnings while using xcpretty try this

xcodebuild <command> \
    | sed -e '/warning:/,/\^/d' \
    | xcpretty -s

Solution 11 - Xcode

We run detox build command and it threw too many logs in CI. -quite parameter failed with hiding logs.

The best solution is to hide and save logs in file:

npx detox build -c ios &> detox_build.log

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionsorinView Question on Stackoverflow
Solution 1 - XcodeAmin ArianaView Answer on Stackoverflow
Solution 2 - XcodeKoraktorView Answer on Stackoverflow
Solution 3 - XcoderosejnView Answer on Stackoverflow
Solution 4 - XcodeGuillaumeView Answer on Stackoverflow
Solution 5 - Xcodeweijia.wangView Answer on Stackoverflow
Solution 6 - XcodeThiView Answer on Stackoverflow
Solution 7 - XcoderavronView Answer on Stackoverflow
Solution 8 - XcodeJosh WoodcockView Answer on Stackoverflow
Solution 9 - XcodeandersonvomView Answer on Stackoverflow
Solution 10 - XcodeWillianView Answer on Stackoverflow
Solution 11 - XcodeAlexander GorbunovView Answer on Stackoverflow