【问题标题】:How to make xcodebuild print compile errors and warnings to stderr?如何使 xcodebuild 向 stderr 打印编译错误和警告?
【发布时间】:2020-09-01 13:39:23
【问题描述】:

似乎 xcodebuild 将所有内容打印到标准输出。

$ /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。除了1>&2,有没有办法让xcodebuild向stderr打印错误和警告?

【问题讨论】:

    标签: xcode compilation qt-creator xcodebuild


    【解决方案1】:

    您可以尝试使用 -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
    

    还有其他工具可以检查,例如 xcprettyxcbeautify

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

    【讨论】:

    • 谢谢! -quiet 1>&2 做这件事。您是否碰巧知道 xcpretty 或 xcbeautify 是否可以将警告和错误重定向到 stderr 而无需更改它们?
    • 欢迎您。我很高兴解决您的问题。那么在 Apple 引入 -quiet 标志之前,我使用 xcpretty 来减少构建日志并将输出从大量输出转换为格式整齐的输出。所以它只会格式化并使其易于阅读。更重要的是,它仍然是当今使用的方便工具,例如 xcodebuild | xcpretty -c
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多