如何让xcodebuild打印stderr的编译错误和警告



xcodebuild似乎会将所有内容打印到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)

这不允许我的IDE(QtCreator(正确解析输出。

事实上,clang会将错误和警告打印到stderr。但由于某种原因,xcodebuild将所有内容重定向到strdout。有没有办法让xcodebuild将错误和警告打印到除1>&2之外的stderr?

您可以尝试运行带有-quiet选项的命令吗。

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

因此,您可以通过使用-quiet选项来传送警告和错误,并且要只过滤错误,您可以使用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

还有其他工具需要检查,如xcprettexcprett

https://github.com/xcpretty/xcpretty(我更喜欢这个(

最新更新