|
| 1 | +--- |
| 2 | +name: debug-generated-project |
| 3 | +description: Debugs issues users encounter with Tuist-generated projects by reproducing the scenario locally, building Tuist from source when needed, and triaging whether it is a bug, misconfiguration, or something that needs team input. Use when users report generation failures, build errors after generation, or unexpected project behavior. |
| 4 | +--- |
| 5 | + |
| 6 | +# Debug Tuist Project Issue |
| 7 | + |
| 8 | +## Quick Start |
| 9 | + |
| 10 | +1. Ask the user to describe the issue and the project setup (targets, dependencies, configurations, platform). |
| 11 | +2. Confirm the issue exists with the latest release by running `mise exec tuist@latest -- tuist generate` against a reproduction project. |
| 12 | +3. If confirmed, clone the Tuist repository and build from source to test against main. |
| 13 | +4. Triage: fix the bug and open a PR, advise on misconfiguration, or recommend the user files an issue with a reproduction. |
| 14 | + |
| 15 | +## Step 1: Gather Context |
| 16 | + |
| 17 | +Ask the user for: |
| 18 | + |
| 19 | +- What command they ran (e.g. `tuist generate`) |
| 20 | +- The error message or unexpected behavior |
| 21 | +- **When the issue happens**: generation time, compile time, or runtime (app launch or later) |
| 22 | +- Their project structure: targets, platforms, dependencies (SwiftPM, XCFrameworks, local packages) |
| 23 | +- Their `Project.swift` and `Tuist.swift` content (or relevant excerpts) |
| 24 | +- Their Tuist version (`tuist version`) |
| 25 | + |
| 26 | +The answer to "when" determines the verification strategy: |
| 27 | + |
| 28 | +- **Generation time**: the issue might be a Tuist bug or a project misconfiguration. Reproduce with `tuist generate`. |
| 29 | +- **Compile time**: the generated project has incorrect build settings, missing sources, or wrong dependency wiring. Reproduce with `xcodebuild build` after generation. |
| 30 | +- **Runtime**: the app builds but crashes or misbehaves on launch or during use. Reproduce by installing and launching on a simulator. |
| 31 | + |
| 32 | +## Step 2: Reproduce with the latest release |
| 33 | + |
| 34 | +Before investigating the source code, confirm the issue is not already fixed in the latest release. |
| 35 | + |
| 36 | +### Set up a temporary reproduction project |
| 37 | + |
| 38 | +```bash |
| 39 | +REPRO_DIR=$(mktemp -d) |
| 40 | +cd "$REPRO_DIR" |
| 41 | +``` |
| 42 | + |
| 43 | +Create minimal `Tuist.swift`, `Project.swift`, and source files that reproduce the user's scenario. Keep it as small as possible while still triggering the issue. |
| 44 | + |
| 45 | +### Run generation with the latest Tuist release |
| 46 | + |
| 47 | +```bash |
| 48 | +mise exec tuist@latest -- tuist generate --no-open --path "$REPRO_DIR" |
| 49 | +``` |
| 50 | + |
| 51 | +If the issue involves dependencies, install them first: |
| 52 | + |
| 53 | +```bash |
| 54 | +mise exec tuist@latest -- tuist install --path "$REPRO_DIR" |
| 55 | +``` |
| 56 | + |
| 57 | +### Check the result |
| 58 | + |
| 59 | +- If generation succeeds and the issue is gone, tell the user to update to the latest version. |
| 60 | +- If the issue persists, continue to Step 3. |
| 61 | + |
| 62 | +## Step 3: Build Tuist from Source |
| 63 | + |
| 64 | +Clone the repository and build the `tuist` executable and `ProjectDescription` library from source to test against the latest code on `main`. |
| 65 | + |
| 66 | +```bash |
| 67 | +TUIST_SRC=$(mktemp -d) |
| 68 | +git clone --depth 1 https://github.com/tuist/tuist.git "$TUIST_SRC" |
| 69 | +cd "$TUIST_SRC" |
| 70 | +swift build --product tuist --product ProjectDescription --replace-scm-with-registry |
| 71 | +``` |
| 72 | + |
| 73 | +The built binary will be at `.build/debug/tuist`. Use it to test the reproduction project: |
| 74 | + |
| 75 | +```bash |
| 76 | +"$TUIST_SRC/.build/debug/tuist" generate --no-open --path "$REPRO_DIR" |
| 77 | +``` |
| 78 | + |
| 79 | +### If the issue is fixed on main |
| 80 | + |
| 81 | +Tell the user the fix is already on `main`, and it hasn't been released, tell them it'll be in the nest release and point them to the relevant commit if you can identify it. |
| 82 | + |
| 83 | +### If the issue persists on main |
| 84 | + |
| 85 | +Continue to Step 4. |
| 86 | + |
| 87 | +## Step 4: Triage the Issue |
| 88 | + |
| 89 | +Investigate the Tuist source code to understand why the issue occurs. |
| 90 | + |
| 91 | +### Outcome A: It is a bug |
| 92 | + |
| 93 | +1. Identify the root cause in the source code. |
| 94 | +2. Apply the fix. |
| 95 | +3. Verify by rebuilding and running against the reproduction project: |
| 96 | + ```bash |
| 97 | + cd "$TUIST_SRC" |
| 98 | + swift build --product tuist --product ProjectDescription --replace-scm-with-registry |
| 99 | + "$TUIST_SRC/.build/debug/tuist" generate --no-open --path "$REPRO_DIR" |
| 100 | + ``` |
| 101 | +4. Zip the reproduction project and include it in the PR: |
| 102 | + ```bash |
| 103 | + cd "$REPRO_DIR" && cd .. |
| 104 | + zip -r reproduction.zip "$(basename "$REPRO_DIR")" -x '*.xcodeproj/*' -x '*.xcworkspace/*' -x 'Derived/*' -x '.build/*' |
| 105 | + ``` |
| 106 | +5. Open a PR on the Tuist repository with: |
| 107 | + - The fix |
| 108 | + - The zipped reproduction project attached or committed as a fixture |
| 109 | + - A clear description of the root cause and how to verify the fix |
| 110 | + |
| 111 | +### Outcome B: It is a misconfiguration |
| 112 | + |
| 113 | +Tell the user what is wrong and how to fix it. Common misconfigurations: |
| 114 | + |
| 115 | +- Missing `tuist install` before `tuist generate` when using external dependencies |
| 116 | +- Incorrect source or resource globs that exclude or double-include files |
| 117 | +- Mismatched build configurations between the project and external dependencies |
| 118 | +- Wrong product types for dependencies (static vs dynamic) |
| 119 | +- Missing `-ObjC` linker flag for Objective-C dependencies |
| 120 | +- Using `sources` and `resources` globs together with `buildableFolders` |
| 121 | + |
| 122 | +Provide the corrected manifest snippet so the user can apply the fix directly. |
| 123 | + |
| 124 | +### Outcome C: Unclear or needs team input |
| 125 | + |
| 126 | +If you cannot determine whether it is a bug or misconfiguration, recommend the user: |
| 127 | + |
| 128 | +1. Open a GitHub issue at https://github.com/tuist/tuist/issues with: |
| 129 | + - The reproduction project (zipped) |
| 130 | + - The error output |
| 131 | + - Their Tuist version and environment details |
| 132 | + |
| 133 | +Provide a summary of what you investigated and what you ruled out, so the user does not have to repeat the triage. |
| 134 | + |
| 135 | +## Build Verification |
| 136 | + |
| 137 | +When testing a fix, always verify the full cycle: |
| 138 | + |
| 139 | +```bash |
| 140 | +# Build the patched tuist |
| 141 | +cd "$TUIST_SRC" |
| 142 | +swift build --product tuist --product ProjectDescription --replace-scm-with-registry |
| 143 | + |
| 144 | +# Install dependencies if needed |
| 145 | +"$TUIST_SRC/.build/debug/tuist" install --path "$REPRO_DIR" |
| 146 | + |
| 147 | +# Generate the project |
| 148 | +"$TUIST_SRC/.build/debug/tuist" generate --no-open --path "$REPRO_DIR" |
| 149 | + |
| 150 | +# Build the generated project |
| 151 | +xcodebuild build \ |
| 152 | + -workspace "$REPRO_DIR"/*.xcworkspace \ |
| 153 | + -scheme <scheme> \ |
| 154 | + -destination "platform=iOS Simulator,name=iPhone 16 Pro" |
| 155 | +``` |
| 156 | + |
| 157 | +## Runtime Verification |
| 158 | + |
| 159 | +When the user reports a runtime issue (crash on launch, missing resources at runtime, wrong bundle structure, or unexpected behavior), you must go beyond building and actually launch the app on a simulator. |
| 160 | + |
| 161 | +### Launch and monitor for crashes |
| 162 | + |
| 163 | +```bash |
| 164 | +# Boot a simulator |
| 165 | +xcrun simctl boot "iPhone 16 Pro" 2>/dev/null || true |
| 166 | + |
| 167 | +# Build for the simulator |
| 168 | +xcodebuild build \ |
| 169 | + -workspace "$REPRO_DIR"/*.xcworkspace \ |
| 170 | + -scheme <scheme> \ |
| 171 | + -destination "platform=iOS Simulator,name=iPhone 16 Pro" \ |
| 172 | + -derivedDataPath "$REPRO_DIR/DerivedData" |
| 173 | + |
| 174 | +# Install the app |
| 175 | +xcrun simctl install booted "$REPRO_DIR/DerivedData/Build/Products/Debug-iphonesimulator/<AppName>.app" |
| 176 | + |
| 177 | +# Launch and monitor — this will print crash info if the app terminates abnormally |
| 178 | +xcrun simctl launch --console-pty booted <bundle-identifier> |
| 179 | +``` |
| 180 | + |
| 181 | +The `--console-pty` flag streams the app's stdout/stderr so you can observe logs and crash output directly. Watch for: |
| 182 | + |
| 183 | +- **Immediate crash on launch**: usually a missing framework, wrong bundle ID, missing entitlements, or stripped ObjC categories (`-ObjC` linker flag missing) |
| 184 | +- **Crash after a few seconds**: often missing resources (images, storyboards, XIBs, asset catalogs) or a bundle structure mismatch |
| 185 | +- **Runtime misbehavior without crash**: wrong resource paths, missing localization files, or incorrect Info.plist values |
| 186 | + |
| 187 | +### Check crash logs |
| 188 | + |
| 189 | +If the app crashes without useful console output, pull the crash log: |
| 190 | + |
| 191 | +```bash |
| 192 | +# List recent crash logs for the app |
| 193 | +find ~/Library/Logs/DiagnosticReports -name "<AppName>*" -newer "$REPRO_DIR" -print |
| 194 | +``` |
| 195 | + |
| 196 | +Read the crash log to identify the crashing thread and the faulting symbol. |
| 197 | + |
| 198 | +## Done Checklist |
| 199 | + |
| 200 | +- Gathered enough context from the user to reproduce the issue |
| 201 | +- Determined whether the issue is at generation time, compile time, or runtime |
| 202 | +- Confirmed whether the issue exists in the latest release |
| 203 | +- Tested against Tuist built from source (main branch) |
| 204 | +- If runtime issue: launched the app on a simulator and verified the crash or misbehavior |
| 205 | +- Triaged the issue as a bug, misconfiguration, or unclear |
| 206 | +- If bug: applied fix, verified it, and opened a PR with reproduction project |
| 207 | +- If misconfiguration: provided corrected manifest to the user |
| 208 | +- If unclear: gave the user a summary and recommended next steps |
0 commit comments