🙌

xcbeautify で「読める」Xcodeビルドログを作る

に公開

Xcodeプロジェクトのビルド時、ごちゃごちゃのログに怒りを覚えたこと。
ありますよね。

そんな時、便利なツールが xcbeautifyです。

xcbeautify とは

  • Swift製のビルドログフォーマッタ
  • xcodebuildの出力を読みやすく、カラー付きで表示
  • Xcodeの新ビルドシステム(parallel testing含む)に完全対応
  • macOS や Linux で動作
  • CI (特に GitHub Actions) との連携性も高い

GitHub - xcbeautify

使い方

ビルド出力を漏らすことなく表示しつつ、要らない詳細は捨てられます。

シンプルに使うと:

xcodebuild -scheme MyScheme | xcbeautify

主なオプション

  • -q, --quiet
    • 警告やエラーがあるタスクのみを表示
  • --quieter, -qq
    • エラーがあるタスクのみを表示
  • --is-ci
    • CI環境用。テスト結果も表示
  • --renderer github-actions
    • GitHub Actions用フォーマット(エラーをアノテーション表示)
  • --renderer teamcity
  • --renderer azure-devops-pipelines

GitHub Actions での使い方

よく使われるパターンはこれ:

set -o pipefail && xcodebuild -scheme MyScheme | xcbeautify --renderer github-actions
  • パイプラインのエラーを GitHub PR 上でアノテート表示
  • CIログを流し読みできる

tuist.io - xcbeautify x GitHub Actions の使い方

実際のGitHub Actionsスクリプト例

name: Build and Test

on:
  push:
    branches: [main]
  pull_request:
    branches: [main]

jobs:
  build:
    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v2

      - name: Install xcbeautify
        run: brew install xcbeautify

      - name: Build and Test
        run: |
          set -o pipefail && xcodebuild -scheme MyScheme -destination 'platform=iOS Simulator,name=iPhone 13' test | xcbeautify --renderer github-actions
  • brew install xcbeautifyでインストール
  • set -o pipefailでエラーをキャッチ
  • --renderer github-actionsでアノテーション表示

これだけでPRレビュー效率が大幅に高まります。

注意事項

  • 特定のフェーズの出力がパースされないことがまれにある
  • 実際のログを tee で保存しておくのが安全
xcodebuild -scheme MyScheme 2>&1 | tee build.log | xcbeautify
  • 0.21.0周辺で「ハングする」バグが報告されたため、利用バージョンには注意

感想

結論:使わない手はない。

  • 生の xcodebuildログに戻れない
  • GitHub Actionsでアノテーションを表示できるのは嬉しい
  • 最近のバージョンは安定している

「まずは Homebrew で入れて、使ってみる」。

それだけで、日常のデバッグ作業がぐっと楽になります。

Discussion