# airbuild-xcode

> AirBuild のビルドスクリプト内で xcodebuild の install、archive、test を実行します。構成、出力先、署名、キャッシュには AirBuild のデフォルトが適用されます。

Source: https://air.build/ja/docs/cli/airbuild-xcode/

`airbuild-xcode` は 1 つのアクションで `xcodebuild` を 1 回呼び出し、指定しなかった項目に AirBuild のデフォルトを追加します。これが存在するのは、クラウドの macOS ビルダーまたは Mac チームの Mac 上で `runbuild`、`runtest`、`runmacos` が実行するスクリプト（そこから呼び出されるスクリプトを含む）の中だけです。ほかの場所にはインストールされておらず、Linux ビルダーにもありません。

`install`、`archive`、`test`、`-showBuildSettings` では `xcodebuild` の代わりにこれを使ってください。そのほかの Xcode の操作には、`xcodebuild` を直接呼び出してください。

## 書式

```bash
airbuild-xcode install|archive|test|-showBuildSettings [xcodebuild options and build settings]
airbuild-xcode --help
```

アクションは先頭に置く必要があります。ほかの引数はすべてそのまま `xcodebuild` に渡され、`airbuild-xcode` は `xcodebuild` の終了コードで終了します。

## アクション

| アクション | 用途 | キャッシュ |
| --- | --- | --- |
| `install` | 日常のビルド: `xcodebuild install` がスキームの Archive ターゲットを `DSTROOT` にインクリメンタルにビルドします。`build.script` に書きます。 | クラウドビルドでは、run 内で最初の `install` がプロジェクトの DerivedData を復元します。 |
| `archive` | 署名付きの `.ipa` や未署名のデバイス用パッケージの元になるアーカイブ。`release.script` に書きます。 | なし: アーカイブは毎回最初からやり直します。 |
| `test` | テストを実行します。 | クラウドビルドでは、run 内で最初の `test` がプロジェクトの DerivedData（`install` のものとは別のコピー）を復元します。 |
| `-showBuildSettings` | ビルド時と同じデフォルトを適用したビルド設定を表示します。 | — |

署名付きビルドとデバイス用ビルドは `install` を拒否します。これらはアーカイブを書き出すため、`release:` レシピを実行します。

## デフォルト

`install`、`archive`、`-showBuildSettings` は、`runbuild` が設定する `AIRBUILD_SIGN`（デフォルト `0`）に従います。

| ビルド | 構成 | 出力先 | 署名 |
| --- | --- | --- | --- |
| 通常（`AIRBUILD_SIGN=0`） | `Debug` | `generic/platform=iOS Simulator` | `CODE_SIGN_IDENTITY=-`。プロジェクトのほかの署名設定は維持されます |
| デバイス用パッケージ（`AIRBUILD_SIGN=0`、`AIRBUILD_DEVICE=1`）: `runbuild --unsigned`、またはマネージド署名なしの **デバイスにインストール** | `Release` | `generic/platform=iOS` | プロジェクトのエンタイトルメントでアドホック署名され、チームやプロファイルはありません。シミュレータ用の `-destination` と `-sdk` の値は取り除かれます。 |
| 署名付き（`AIRBUILD_SIGN=1`）: `runbuild --sign` | `Release` | `generic/platform=iOS` | AirBuild が準備するマネージド署名 |

`test` のデフォルトは、通常の（折りたたみではない）iPhone がある最新の iOS ランタイム上の iPhone シミュレータで、すでに起動しているものが優先されます。加えて `CODE_SIGN_IDENTITY=-` と `-collect-test-diagnostics never` が付きます。シミュレータを作成することはありません。

## 上書きできるもの

- 明示的な `-configuration`、`-destination`（テストでは複数可）、そして通常のビルドとテストでは `CODE_SIGN_IDENTITY=…` が、デフォルトの代わりに使われます。
- `-collect-test-diagnostics on-failure` を付けると、`test` でシミュレータの診断情報の収集が再びオンになります。
- コマンドラインで指定した `ARCHS`、`COMPILATION_CACHE_*`、`SWIFT_ENABLE_PREFIX_MAPPING`、`CLANG_ENABLE_PREFIX_MAPPING` は、ビルダーのプラットフォーム設定より優先されます。ビルダーでは、`ARCHS` を指定しない限り、シミュレータ用と macOS 用のビルドは arm64 のみです。
- マネージド署名は、プロジェクト、`-xcconfig`、コマンドラインの署名設定を上書きします: `CODE_SIGNING_ALLOWED`、`CODE_SIGNING_REQUIRED`、`CODE_SIGN_IDENTITY`、`CODE_SIGN_STYLE`、`DEVELOPMENT_TEAM`、`PROVISIONING_PROFILE`、`PROVISIONING_PROFILE_SPECIFIER`、`OTHER_CODE_SIGN_FLAGS`。`CODE_SIGN_ENTITLEMENTS` は維持されます。

## バージョン番号

ユーザーが AirBuild アプリから開始したデバイス用またはマネージド署名のアーカイブは、プロジェクトのバージョン下限まで引き上げられます。`MARKETING_VERSION` と `CURRENT_PROJECT_VERSION` は、ソース上の値がそれより小さい場合にのみ上書きされます。エージェントが開始したビルドでは引き上げは行われないため、ビルド番号はご自身でプロジェクトに設定してください。

## 出力

`xcodebuild` を実行する前に、`airbuild-xcode` は選択した内容を標準エラー出力に表示します。

```text
[airbuild-xcode] sign=0; configuration=Debug (default); destination=generic/platform=iOS\ Simulator (default).
[airbuild-xcode] CODE_SIGN_IDENTITY=default (-); project signing settings are preserved.
```

```text
[airbuild-xcode] default test device: iPhone 17 (iOS 26.1).
airbuild-xcode: skipping simulator diagnostics collection (simctl diagnose waits 600 s on Xcode 27); pass -collect-test-diagnostics on-failure to collect them.
[airbuild-xcode] action=test; destination=id=<UDID> (default); CODE_SIGN_IDENTITY=default (-).
```

ほかに表示されることのある行:

| 行 | 意味 |
| --- | --- |
| `[airbuild-xcode] archive starts over every run and keeps no cache; …` | 通常のビルドでアーカイブしています。インクリメンタルビルドにするには、`build:` では `install` を使い、`archive` は `release:` に置いてください。`runbuild` も結果とともにこれを警告として表示します。 |
| `[airbuild-xcode] device build: dropped -destination …` | デバイス用ビルドからシミュレータの出力先または SDK が取り除かれました。 |
| `[airbuild-xcode] device build: ad-hoc signed, no team or profile; CODE_SIGN_ENTITLEMENTS is preserved.` | デバイス用パッケージのビルドです。 |
| `[airbuild-xcode] Managed signing overrides via XCODE_XCCONFIG_FILE: …` | 署名付きビルドです。 |
| `[airbuild-xcode] command-line ARCHS=… kept over the platform build settings.` | ご自身の設定がビルダーの設定より優先されました。 |
| `[airbuild-xcode] version floor: raised …` / `nothing raised.` | アプリから開始したビルドでのバージョン下限の処理です。 |

## 終了コードとエラー

`airbuild-xcode` は `xcodebuild` の終了コードで終了します。次の場合は `xcodebuild` を実行する前に `64` で停止します。

| メッセージ | 対処 |
| --- | --- |
| `airbuild-xcode: start with install, archive, test or -showBuildSettings; use xcodebuild directly for other operations.` | アクションを先頭に置くか、`xcodebuild` を呼び出してください。 |
| `airbuild-xcode: use one leading action; run other Xcode operations separately.` | `-list`、`-version`、`-show…`、`-exportArchive`、`-resolvePackageDependencies` などを取り除き、`xcodebuild` で実行してください（`-showBuildTimingSummary` は使えます）。 |
| `airbuild-xcode: -configuration requires a value.`（または `-destination`） | 値を指定してください。 |
| `airbuild-xcode: a signed or device build exports an archive; put airbuild-xcode archive in the release: recipe of airbuild.yaml …` | `airbuild-xcode archive` を実行する `release:` レシピを追加してください。 |
| `airbuild-xcode: no available iOS simulator could be selected. Install an iOS simulator runtime and device in Xcode, or pass -destination explicitly.` | `-destination` を指定するか、シミュレータのランタイムをインストールしてください。 |
| `airbuild-xcode: AIRBUILD_SIGN must be 0 or 1. Start managed signing through AirBuild.` | `AIRBUILD_SIGN` をご自身で設定せず、`runbuild --sign` を使ってください。 |
| `airbuild-xcode: signing preparation is incomplete. Start signing through AirBuild again.` | `runbuild --sign` をもう一度実行してください。 |

## 例

```bash
# build.script: the everyday, incremental build
airbuild-xcode install -workspace App.xcworkspace -scheme App \
  DSTROOT="$PWD/.airbuild/artifacts/install"
```

```bash
# release.script: the archive for --sign and --unsigned
rm -rf .airbuild/artifacts/App.xcarchive
airbuild-xcode archive -workspace App.xcworkspace -scheme App \
  -archivePath .airbuild/artifacts/App.xcarchive
```

```bash
# A test entry, with runtest's --additional-options
airbuild-xcode test -workspace App.xcworkspace -scheme App \
  -resultBundlePath .airbuild/artifacts/Tests.xcresult $additional_options
```
