如何过滤xcodebuild命令行输出?

发布于 2024-08-21 01:25:57 字数 191 浏览 6 评论 0原文

从控制台运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

飘然心甜 2024-08-28 01:25:57

使用 xcodebuild -quiet。

根据 xcodebuild 手册页:

-quiet:除了警告和错误之外,不打印任何输出。

奖励:不需要其他工具! (尽管我也喜欢 xcodebuild | xcpretty

我使用 Travis CI 进行构建,它在 4 MB 的日志后发出抱怨。这个论证解决了问题。

Use xcodebuild -quiet.

According to the xcodebuild man page:

-quiet : Do not print any output except for warnings and errors.

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.

天邊彩虹 2024-08-28 01:25:57

有一个名为 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.

别靠近我心 2024-08-28 01:25:57

这对我来说还不够。通过管道传输到 /dev/null 只会显示构建失败,但您看不到原因。理想情况下,我们只能看到错误和/或警告,而无需看到所有成功的编译器命令。

这基本上完成了工作:

xcodebuild | grep -A 5 error:

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:

xcodebuild | grep -A 5 error:
夏了南城 2024-08-28 01:25:57

要仅查看错误输出消息,请将标准输出重定向到 /dev/null (一个充当黑洞的特殊文件),如下所示:

xcodebuild > /dev/null

如果要将错误输出捕获到文件中,可以执行以下操作:

xcodebuild 2> ./build_errors.log

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:

xcodebuild > /dev/null

If you want to capture the error output into a file, you can do:

xcodebuild 2> ./build_errors.log
蔚蓝源自深海 2024-08-28 01:25:57

输入图像描述这里

-quiet 是目前最好的方法。

enter image description here

-quiet is the best way to do it at now.

真心难拥有 2024-08-28 01:25:57

有一个 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.

两相知 2024-08-28 01:25:57

我喜欢 xcpretty 作为人类来看待,但我需要在自动设置中查找构建错误以便在其他地方传播,并且我想确保我只捕获了相关信息。以下 sed 命令可用于此目的:

xcodebuild | sed -nE '/error:/,/^[[:digit:]] errors? generated/ p'

输出:

main.c:16:5: error: use of undeclared identifier 'x'
    x = 5;
    ^
main.c:17:5: error: use of undeclared identifier 'y'
    y = 3;
    ^
2 errors generated.

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:

xcodebuild | sed -nE '/error:/,/^[[:digit:]] errors? generated/ p'

Output:

main.c:16:5: error: use of undeclared identifier 'x'
    x = 5;
    ^
main.c:17:5: error: use of undeclared identifier 'y'
    y = 3;
    ^
2 errors generated.
自找没趣 2024-08-28 01:25:57

我正在构建一个博览会项目,有很多来自图书馆的警告,我不想看到这些警告。我能够使用此命令过滤掉警告。

set -o pipefail \
&& xcodebuild build -workspace app.xcworkspace -scheme app \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
| xcpretty \
| grep --line-buffered -v -F "[-W" \
| grep --line-buffered -v -F "*" \
| grep --line-buffered -v -F "^" \
| grep --line-buffered -v -F ";" \
| grep --line-buffered -v -e "^$" \
| grep --line-buffered -v -F "@" \
| grep --line-buffered -v -F ")" \
| grep --line-buffered -v -F "/" \
| grep --line-buffered -v -F "}" \
| grep --line-buffered -v -F "{" \
| grep --line-buffered -v -F "\\" \
| grep --line-buffered -v -F "#" \
| grep --line-buffered -v -F ","

我承认这有点草率,但我无法让任何其他解决方案发挥作用。 -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.

set -o pipefail \
&& xcodebuild build -workspace app.xcworkspace -scheme app \
CODE_SIGN_IDENTITY="" \
CODE_SIGNING_REQUIRED=NO \
CODE_SIGNING_ALLOWED=NO \
| xcpretty \
| grep --line-buffered -v -F "[-W" \
| grep --line-buffered -v -F "*" \
| grep --line-buffered -v -F "^" \
| grep --line-buffered -v -F ";" \
| grep --line-buffered -v -e "^
quot; \
| grep --line-buffered -v -F "@" \
| grep --line-buffered -v -F ")" \
| grep --line-buffered -v -F "/" \
| grep --line-buffered -v -F "}" \
| grep --line-buffered -v -F "{" \
| grep --line-buffered -v -F "\\" \
| grep --line-buffered -v -F "#" \
| grep --line-buffered -v -F ","

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

ヅ她的身影、若隐若现 2024-08-28 01:25:57

我一直被 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 it xcquiet.sh. It only hides specific lines, while preserving enough of the original output and not swallowing any other unexpected log entries.

沉默的熊 2024-08-28 01:25:57

如果您想删除警告,请使用

xcodebuild <command> | sed -e '/warning:/,/\^/d'

如果您想在使用 xcpretty 时抑制警告,请尝试此操作

xcodebuild <command> \
    | sed -e '/warning:/,/\^/d' \
    | xcpretty -s

if you want to remove warnings use

xcodebuild <command> | sed -e '/warning:/,/\^/d'

if you want to suppress warnings while using xcpretty try this

xcodebuild <command> \
    | sed -e '/warning:/,/\^/d' \
    | xcpretty -s
染年凉城似染瑾 2024-08-28 01:25:57

您应该将 xcbeautifyquiet (警告和错误)或 更安静(仅错误)选项。

来自他们网站的示例,适用于警告和错误:

set -o pipefail && xcodebuild [flags] | xcbeautify --quiet

You should use xcbeautify with the quiet (warnings and errors) or quieter (only errors) options.

Example from their site, adapted to warnings and errors:

set -o pipefail && xcodebuild [flags] | xcbeautify --quiet
荒人说梦 2024-08-28 01:25:57

我们运行 detox build 命令,它在 CI 中抛出了太多日志。
-quite 参数因隐藏日志而失败。

最好的解决方案是隐藏日志并将其保存在文件中:

npx detox build -c ios &> detox_build.log

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:

npx detox build -c ios &> detox_build.log
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文