如何过滤xcodebuild命令行输出?
从控制台运行 xcodebuild 将为您带来非常详细的输出,并且我无法找到任何限制其输出的选项以便仅显示警告和错误。
我正在寻找一种方法来捕获 xcodebuild 输出并对其进行过滤。它更喜欢与管道一起使用的 Python 解决方案,但我对其他方法持开放态度,只要它们是基于命令行的解决方案即可。
是否有任何工具已经能够做到这一点?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(12)
使用 xcodebuild -quiet。
根据 xcodebuild 手册页:
奖励:不需要其他工具! (尽管我也喜欢
xcodebuild | xcpretty
)我使用 Travis CI 进行构建,它在 4 MB 的日志后发出抱怨。这个论证解决了问题。
Use
xcodebuild -quiet
.According to the xcodebuild man page:
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.
有一个名为
xcpretty
的 Ruby gem。它过滤 xcodebuild 的输出,并提供不同的格式化程序和着色。
更新:正如 Mike Hardy 在此答案的评论中正确指出的那样,
xcpretty
不再维护。There’s a Ruby gem called
xcpretty
.It filters the output of
xcodebuild
and also provides different formatters and coloring.UPDATE: As Mike Hardy correctly states in the comments to this answer,
xcpretty
is no longer maintained.这对我来说还不够。通过管道传输到 /dev/null 只会显示构建失败,但您看不到原因。理想情况下,我们只能看到错误和/或警告,而无需看到所有成功的编译器命令。
这基本上完成了工作:
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:
要仅查看错误输出消息,请将标准输出重定向到 /dev/null (一个充当黑洞的特殊文件),如下所示:
如果要将错误输出捕获到文件中,可以执行以下操作:
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:
If you want to capture the error output into a file, you can do:
-quiet
是目前最好的方法。-quiet
is the best way to do it at now.有一个 Swift 命令行工具 https://github.com/thii/xcbeautify 也可以格式化 xcodebuild 输出。
There’s a Swift command line tool https://github.com/thii/xcbeautify that can also format xcodebuild output.
我喜欢 xcpretty 作为人类来看待,但我需要在自动设置中查找构建错误以便在其他地方传播,并且我想确保我只捕获了相关信息。以下 sed 命令可用于此目的:
输出:
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:Output:
我正在构建一个博览会项目,有很多来自图书馆的警告,我不想看到这些警告。我能够使用此命令过滤掉警告。
我承认这有点草率,但我无法让任何其他解决方案发挥作用。
-quiet
选项仍然打印了数百个我无法解决的警告。奇怪的是,当我在构建机器上的命令行上编译时,我没有收到警告,但当我在 CI 构建中编译时,我会收到警告。很烦人。我希望苹果能够提供一种方法来消除 xcodebuild 的警告
I am building an expo project and there are a lot of warnings that come from libraries which I don't want to see. I was able to filter out the warnings with this command.
I'll admit it's a little sloppy but I couldn't get any of the other solutions to work. The
-quiet
option still printed hundreds of warnings I had no ability to resolve.What is strange is that when I compile on the command line on the build machine I wasn't getting the warnings but when I compiled in my CI build I would get the warnings. Very annoying. I wish apple would provide a way to silence warnings for xcodebuild
我一直被
xcpretty
困扰,在 CI 环境中吞下了太多的信息,使得调试错误变得非常困难。-quiet
以一种有点过于激进的方式隐藏输出,所以我将这个单行代码组合在一起并将其命名为xcquiet.sh
。它只隐藏特定的行,同时保留足够的原始输出并且不会吞没任何其他意外的日志条目。I have been bitten by
xcpretty
swallowing way too much information in a CI environment, making it pretty hard to debug the error.-quiet
hides output in a way that's a bit too aggressive, so I put together this one-liner and called itxcquiet.sh
. It only hides specific lines, while preserving enough of the original output and not swallowing any other unexpected log entries.如果您想删除警告,请使用
如果您想在使用 xcpretty 时抑制警告,请尝试此操作
if you want to remove warnings use
if you want to suppress warnings while using
xcpretty
try this您应该将 xcbeautify 与
quiet
(警告和错误)或更安静
(仅错误)选项。来自他们网站的示例,适用于警告和错误:
You should use xcbeautify with the
quiet
(warnings and errors) orquieter
(only errors) options.Example from their site, adapted to warnings and errors:
我们运行 detox build 命令,它在 CI 中抛出了太多日志。
-quite
参数因隐藏日志而失败。最好的解决方案是隐藏日志并将其保存在文件中:
We run detox build command and it threw too many logs in CI.
-quite
parameter failed with hiding logs.The best solution is to hide and save logs in file: