How to make xcodebuild print compile errors and warnings to stderr?

与世无争的帅哥 提交于 2021-01-27 22:36:18

问题


Seems like xcodebuild prints everything to stdout.

$ /Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project test.xcodeproj build -target test -configuration Debug -jobs 3 2>err
 # xcodebuild stdout with bunch of warnings and errors

$ cat err
** BUILD FAILED **


The following build commands failed:
    CompileC _build/test.build/Objects-normal/x86_64/test.o /Users/me/test/test.cpp normal x86_64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)

That doesn't let my IDE(QtCreator) correctly parse the output.

And clang, actually, prints errors and warnings to stderr. But xcodebuild redirects everything to strdout for some reason. Is there a way to make xcodebuild print errors and warnings to stderr except 1>&2?


回答1:


Can you try running the command with -quiet option as follows.

# Do not print any output except for warnings and errors
/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project -quiet

So you can just pipe warnings and errors by using -quiet option and to filter only error you can use 2> ./errors.log

/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild -project -quiet test.xcodeproj build -target test -configuration Debug -jobs 3 2> ./errors.log

There are other tools to check such as xcpretty and xcbeautify.

https://github.com/xcpretty/xcpretty (I prefer this)



来源:https://stackoverflow.com/questions/63688882/how-to-make-xcodebuild-print-compile-errors-and-warnings-to-stderr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!