问题
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