How to filter the xcodebuild command line output?

2019-01-13 17:39发布

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?

6条回答
淡お忘
2楼-- · 2019-01-13 18:02

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:
查看更多
萌系小妹纸
3楼-- · 2019-01-13 18:12

enter image description here

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

查看更多
乱世女痞
4楼-- · 2019-01-13 18:13

There’s a Ruby gem called xcpretty.

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

查看更多
家丑人穷心不美
5楼-- · 2019-01-13 18:15

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.

查看更多
放荡不羁爱自由
6楼-- · 2019-01-13 18:19

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
查看更多
太酷不给撩
7楼-- · 2019-01-13 18:25

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.
查看更多
登录 后发表回答