diff --git a/CHANGELOG.md b/CHANGELOG.md index cb495b3..df991eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,56 @@ versions follow [Semantic Versioning](https://semver.org/) with `alpha` prerelea ## [Unreleased] +### Changed +- `build` stops seconds after it starts, before the `patches` step (on Expo, once `expo prebuild` has written `ios/`), + when a file of the app target has a quote include of one of the app's own headers that resolves nowhere, instead of + minutes later in `xtool-build`: one `✖` line per include, naming the file and line, the places the app target's copy + searched ("which is not among the files the app target lists next to , in the app target's headers or in ") and, when `ios/` holds one, a file of that name that differs only in case ("file names are case-sensitive on + Linux"), that the target does not list, or, on Expo, that is not copied ("exists, but rn-xtool copies only the + bridging header of an Expo app"), then " include(s) of the app's own sources resolve nowhere (listed above): the + build would stop compiling them; if xtool-build builds them, build with rn-xtool build --skip-precheck and report it + with rn-xtool doctor --report". With `--skip-precheck` each line is a `⚠` line instead, followed by "⚠ + include(s) of the app's own sources resolve nowhere (listed above); checked by xtool-build (--skip-precheck)", and the + build goes on. In a project with CocoaPods binaries it never stops: every miss is left to the `precheck` step. A + quote include with a folder (`"SomeLib/Utils.h"`) counts as the app's own only when a header of the app target, or a + file under `ios/`, has that path, and an include under a condition on a macro the App compile does not define + (`RCT_NEW_ARCH_ENABLED`) is left to the compile. On Expo it reads the bridging header. See + [troubleshooting.md](docs/troubleshooting.md#precheck). +- A bare React Native app target that takes its files from an Xcode 16 synchronized folder is refused by `build` + and `doctor --project`: "The app target takes its files from the synchronized folder (an Xcode 16 + folder group); rn-xtool reads only the files a target lists. Convert the folder to a group (Xcode: Convert to + Group) so the target lists its files". + +### Added +- The `precheck` build step, between `generate` and `xtool-build`: SwiftPM plans the generated package, the app's + includes are resolved again with the App target's full include list, `swiftc -typecheck` checks the Swift files and + `clang -fsyntax-only` each C-family file with the generated manifest's flags. When a Swift file imports a module + SwiftPM builds from Swift (a Swift library, or one with Swift files next to its Objective-C), the Swift files are left + to `xtool-build`, and a C-family file that `@import`s such a module, or one no module map of the package graph + declares (an SDK module such as CommonCrypto is left to xtool-build too), is left to it too ("ℹ precheck — + imports the module , which SwiftPM builds; checked by xtool-build", or "…, which no module map of the package + graph declares; …"); on Expo the app's Swift files import such a module (`Expo`, or `ExpoModulesCore` in the + generated `ExpoModulesProvider.swift`), so they are always checked there. Errors stop the build before `xtool-build`, with one line per include that resolves nowhere and + the compilers' first ten errors with their include stacks (an error several files report counts once), and the stop + names `rn-xtool build --skip-precheck` for a false one; so does every other stop of the step (SwiftPM's refusals, an + unreadable xcframework, a full disk) except a missing toolchain, which names `rn-xtool setup`. A precheck that passes + does not promise that `xtool-build` does: code generation and link errors still show there. Every command and its + output go to `ios-xtool/.precheck/precheck.log`; after a write to it fails (a full disk), the log may miss the lines + that follow, while the terminal and the stop lose none. The first precheck is slower while clang builds React Native's + modules into the module cache, which `--clean` empties. See + [how-it-works.md](docs/how-it-works.md#the-build-step-by-step). +- `--skip-precheck` on `build` and `run` leaves the `precheck` step out, with "⚠ precheck skipped (--skip-precheck): + errors in the app's own sources show in xtool-build"; the check of the app's own includes at the start of `build` + still runs, and prints its misses as `⚠` lines without stopping. +- `rn-xtool doctor --project` checks the app's own includes as `build` does, without a toolchain: `app-includes` lines + (`✖` per include that resolves nowhere, `ℹ` for those left to the `precheck` step, `✔` when they resolve). +- A `⚠` line, at `build` and as `app-target` in `doctor --project`, for an `.xcconfig` other than CocoaPods' that the + Debug configuration of the app target or of the project is based on and that sets a setting rn-xtool reads from the + pbxproj: "⚠ sets for the app target; rn-xtool does not read xcconfig files". +- `rn-xtool doctor --report` has a `precheck:` line: `precheck: run (last build)`, `precheck: skipped with + --skip-precheck (last build)` or `precheck: not recorded`. + ## [0.1.0-alpha.8] - 2026-11-09 ### Upgrading from 0.1.0-alpha.7 diff --git a/README.md b/README.md index 65edc7b..5460f38 100644 --- a/README.md +++ b/README.md @@ -46,8 +46,8 @@ Swift file) and 20 native libraries builds, installs over USB and launches on a 2026-11-06; its features are not checked yet, [details](docs/bare-react-native.md#react-native-085)). `rn-xtool doctor --project` shows which line your project is on and what rn-xtool finds in it (the SwiftPM scripts -and prebuilt artifacts it would use, Expo's plugin and modules, podspec features), without the toolchain, login and -device checks ([details](docs/troubleshooting.md#doctor---project)). +and prebuilt artifacts it would use, Expo's plugin and modules, podspec features, the app's own includes), without +the toolchain, login and device checks ([details](docs/troubleshooting.md#doctor---project)). CocoaPods is not needed: the `Podfile` is ignored. Any library with a podspec is tried automatically (CocoaPods-only ones get a generated `Package.swift`, and the pods they depend on come from SwiftPM packages or, for pods of prebuilt @@ -155,10 +155,10 @@ Details, every message and what to do: [docs/troubleshooting.md](docs/troublesho | `setup [--xcode-xip ] [--wifi [--yes] [--udid ]]` | Installs Swift via swiftly, the xtool AppImage and the Darwin SDK. Idempotent. `--wifi` is the one-time USB step for Wi‑Fi installs: it caches the pair record and, with `--yes`, enables Wi‑Fi connections on the iPhone. | | `auth [args...]` | Runs `xtool auth ` (`auth login`, `auth logout`); with no arguments, `xtool auth status`. | | `doctor [--project] [--report]` | Checks toolchain, SDK, login, connected device, Wi‑Fi install readiness and project. Exits non-zero on problems. `--project` checks only the project in the current folder: its version gates, what rn-xtool finds in it and the setups it cannot build yet. `--report` prints the same checks as one block to paste into a GitHub issue, with your home folder, Apple ID, Team ID, bundle identifiers, UDIDs, device names, IP and MAC addresses replaced by placeholders, and makes no network request ([details](docs/troubleshooting.md#reporting-a-problem)). | -| `build [--clean]` | Prebuild if `ios/` is missing (Expo only), patches, RN/Expo SwiftPM pipeline, ExpoModulesJSI (Expo modules only), generates `ios-xtool/`, `xtool dev build`. `--clean` re-runs `expo prebuild --clean` for Expo; for bare it removes `ios/build` and `ios-xtool` and leaves the rest of `ios/` alone. | +| `build [--clean] [--skip-precheck]` | Prebuild if `ios/` is missing (Expo only), patches, RN/Expo SwiftPM pipeline, ExpoModulesJSI (Expo modules only), generates `ios-xtool/`, checks the app's own sources (`precheck`), `xtool dev build`. `--clean` re-runs `expo prebuild --clean` for Expo; for bare it removes `ios/build` and `ios-xtool` and leaves the rest of `ios/` alone. `--skip-precheck` leaves the `precheck` step out, and the check of the app's own includes at build start warns instead of stopping ([details](docs/troubleshooting.md#precheck)). | | `install [--network [ip] [--udid ] [--pair-record ]]` | Signs and installs the app on the USB-connected iPhone (over Wi‑Fi without the cable with `--network`, see [docs/wifi-install.md](docs/wifi-install.md)), then prints, for apps with expo-dev-client, the Metro URL with a link and QR code that open the app on it, and the first-run checklist. | | `start [--clear]` | Starts Metro (`npx expo start`; `npx react-native start` for bare) on the port and LAN IP the app was built for. Tells you to rebuild if either changed; clears the Metro cache when dependencies changed (or with `--clear`). With expo-dev-client it announces Metro to the dev launcher under the installed app's bundle id. | -| `run [--clean] [--force] [--network [ip]]` | `build` and `install` when dependencies changed (or with `--force`), then `start`. `--network` installs over Wi‑Fi. | +| `run [--clean] [--force] [--network [ip]] [--skip-precheck]` | `build` and `install` when dependencies changed (or with `--force`), then `start`. `--network` installs over Wi‑Fi; `--skip-precheck` goes to `build`. | ## Configuration diff --git a/docs/bare-react-native.md b/docs/bare-react-native.md index 59d584c..36a5172 100644 --- a/docs/bare-react-native.md +++ b/docs/bare-react-native.md @@ -193,16 +193,35 @@ missing bundle identifier. `patches`, `rn-artifacts` (with the vendored SwiftPM scripts, so 0.85, 0.86 and 0.87, unless `rnArtifactsDir` is set), `rn-spm`, `jsi` (only with Expo modules), `app-config` (only when `expo-constants` is installed), `frameworks`, -`generate` and `xtool-build`. `expo prebuild` never runs, and the `rn-spm` step runs React Native's +`generate`, `precheck` and `xtool-build`. `expo prebuild` never runs, and the `rn-spm` step runs React Native's SwiftPM generation steps without injecting anything into your Xcode project (it writes `ios/build/` only). Your `Podfile` and any `pod install` result are ignored. `build --clean` removes `ios/build` and `ios-xtool` and leaves the rest of `ios/` alone. +Before the first step, `build` resolves the `#import` and `#include` lines of the app target's C-family sources, headers +and bridging header as the generated App target compiles them, with file reads only (pass 1): a quote include of one of +the app's own headers that resolves nowhere stops the build seconds after it starts, naming the file, the places +searched and, when `ios/` holds one, a file of that name that differs only in case or that the target does not list. In +a project with CocoaPods binaries it never stops: every miss is left to the `precheck` step. With `--skip-precheck` it +prints its misses as `⚠` lines and the build goes on, and `doctor --project` runs the same check as its `app-includes` +line. Includes into React Native's or the libraries' headers are left to the `precheck` step: SwiftPM plans the +generated package, the includes are resolved again with the App target's full include list, `swiftc -typecheck` checks +the Swift files and `clang -fsyntax-only` each C-family file with the generated manifest's flags, so an error in the +app's own sources stops the build before `xtool-build`. When a Swift file imports a module SwiftPM builds from Swift (a +Swift library, or one with Swift files next to its Objective-C), the Swift files are left to `xtool-build`, and so is a +C-family file that `@import`s such a module or one no module map of the package graph declares (an SDK module such as +CommonCrypto is left to xtool-build too). `build --skip-precheck` leaves that step out. +Each line and what to do: +[troubleshooting.md](troubleshooting.md#precheck). + ## What is read from `project.pbxproj` -The single application target (several application targets or several `.xcodeproj` are an error naming them). From its -Debug configuration, then the project's: +The single application target (several application targets or several `.xcodeproj` are an error naming them). A target +that takes its files from an Xcode 16 synchronized folder is refused, by `build` and `doctor --project`, with `The app +target takes its files from the synchronized folder (an Xcode 16 folder group); rn-xtool reads only +the files a target lists. Convert the folder to a group (Xcode: Convert to Group) so the target lists its files`. From +its Debug configuration, then the project's: - `PRODUCT_BUNDLE_IDENTIFIER` (required; bare projects are never written to, so add it in Xcode or the pbxproj if it is missing), `PRODUCT_NAME`, `MARKETING_VERSION`, `CURRENT_PROJECT_VERSION` and `INFOPLIST_FILE` (the `Info.plist` @@ -213,7 +232,12 @@ Debug configuration, then the project's: and `$(CONFIGURATION)` (`Debug`), the `:rfc1034identifier` and `:c99extidentifier` modifiers and settings defined in the pbxproj itself (for example `$(PRODUCT_NAME)`) are resolved. Any other `$(VAR)` stops the build with `Cannot resolve build setting` naming it. Relative paths in `HEADER_SEARCH_PATHS` and the bridging header are relative to - `ios/`. `.xcconfig` files are ignored. + `ios/`. `.xcconfig` files are not read: when the Debug configuration of the app target or of the project is based + on one, other than CocoaPods' `Pods-*.xcconfig`, that sets (itself or through its `#include` lines) + `HEADER_SEARCH_PATHS`, `GCC_PREPROCESSOR_DEFINITIONS`, `CLANG_CXX_LANGUAGE_STANDARD`, `SWIFT_OBJC_BRIDGING_HEADER`, + `PRODUCT_MODULE_NAME`, `CODE_SIGN_ENTITLEMENTS` or `INFOPLIST_FILE`, `build` prints `⚠ sets for the + app target; rn-xtool does not read xcconfig files` and `doctor --project` the same line as `⚠ app-target — …`. Set + those values in the target's build settings ([details](troubleshooting.md#precheck)). Not carried over: `IPHONEOS_DEPLOYMENT_TARGET` (the generated package always targets iOS 16.4, in Swift 5 language mode), capabilities and script phases. When `OTHER_CFLAGS`, `OTHER_LDFLAGS` or `OTHER_SWIFT_FLAGS` hold flags beyond diff --git a/docs/design/plans/2026-11-06-alpha-8-fail-early.md b/docs/design/plans/2026-11-06-alpha-8-fail-early.md index 29d1559..153aa63 100644 --- a/docs/design/plans/2026-11-06-alpha-8-fail-early.md +++ b/docs/design/plans/2026-11-06-alpha-8-fail-early.md @@ -5,7 +5,8 @@ its rulings R1–R13. This file lists the task groups and the failure-walk rows exactly one owner. The tasks, their tests and the execution order are written next. Plans: [plan 1, the podspec reader](2026-11-06-alpha-8-plan-1-podspec-reader.md) covers group A (rows 1–28), F1 (rows -104–108), F3 (rows 112–115) and records row 29 as deferred. +104–108), F3 (rows 112–115) and records row 29 as deferred; [plan 2, the precheck](2026-11-09-alpha-8-plan-2-precheck.md) +covers group B (rows 30–55), with the response-file capture (R12) as its Task 13. Two gates come before the groups that depend on them: diff --git a/docs/design/plans/2026-11-09-alpha-8-plan-2-precheck.md b/docs/design/plans/2026-11-09-alpha-8-plan-2-precheck.md new file mode 100644 index 0000000..fddba1a --- /dev/null +++ b/docs/design/plans/2026-11-09-alpha-8-plan-2-precheck.md @@ -0,0 +1,1050 @@ +# Release 0.1.0-alpha.8, plan 2: the app target fails in seconds — Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or +> superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Report every failure of the app target's own sources (F1–F5) before `xtool-build` starts: a static +resolution of the app's `#import`/`#include` in `doctor --project` and at the start of `build` (B1 pass 1), and a +`precheck` build step after `generate` that plans the package, resolves the includes again with the App target's full +include list (B1 pass 2) and compiles the app's own sources with the manifest's flags (B2), with +`rn-xtool build --skip-precheck` as the exit. + +**Architecture:** B1 is TypeScript over files only: `src/project/includeScan.ts` reads a file's directives under a +small preprocessor, and `src/project/appIncludes.ts` resolves them against the app target as `generate` will copy it +(one layout function shared with `copyBareTarget`) and decides between error, `⚠` and `ℹ`. B2 lives in +`src/pipeline/`: `precheckGraph.ts` asks SwiftPM for the generated package's plan and its dependency graph's header +folders, `precheckCommands.ts` turns the flag lists `renderPackageSwift` renders (one flag source in `packageSwift.ts`) +into `clang`/`swiftc` command lines, and `precheck.ts` runs the hops and reports through `precheckReport.ts`. `build` +gains the step and the flag; the build state records whether the precheck ran, and `doctor --report` prints it. A +golden test compares the command lines with the response files Swift Build wrote for the reference apps (R12). + +**Tech Stack:** TypeScript ESM (Node 22), vitest, the Swift toolchain's `clang` and `swiftc` (swiftly, on the PATH +`toolEnv()` builds), SwiftPM (`swift package describe`, `show-dependencies`, `dump-package`), the Darwin SDK bundle +`rn-xtool setup` installs. + +**Spec:** [`docs/design/specs/2026-11-06-alpha-8-fail-early-design.md`](../specs/2026-11-06-alpha-8-fail-early-design.md) +(decision B, rulings R2, R6, R12, "Design → B. The app target's checks", failure-walk rows 30–55, the anti-goals, +Verification's response-file capture and build-only proofs 1 and 3). Index of all groups: +[`2026-11-06-alpha-8-fail-early.md`](2026-11-06-alpha-8-fail-early.md). Format model, and the interfaces this plan +consumes: [plan 1](2026-11-06-alpha-8-plan-1-podspec-reader.md). + +**Branch:** execution continues on `feature/alpha-8-precheck` (cut with `--no-track` from `origin/main` ebd1b83) unless +the owner names another; never track `develop`/`main`; push only with `git push -u origin feature/alpha-8-precheck`, +then check that `@{u}` is `origin/feature/alpha-8-precheck`. + +## Global Constraints + +- Linux only, no Mac, no Xcode tools. `doctor --project` keeps working without Swift, xtool or a network: B1 is pure + file-system work (row 38); the compile (B2) runs only in `build`'s `precheck` step. +- The precheck's `clang`, `swiftc` and `swift` are the ones on `toolEnv()`'s PATH (swiftly's `bin` first), the PATH + `xtool dev build` runs with (`devEnv`, `src/tools/xtool.ts:155`): the toolchain xtool uses. The iPhoneOS SDK is the + one the Darwin SDK bundle names (`sdkBundle()/swift-sdk.json`, triple `arm64-apple-ios`, `sdkRootPath`). +- This plan does NOT touch `vendor/rn-spm/spm/` or `patches/react-native+0.88.{0,1}.patch`. If a task seems to need + it, stop and add it to "Open questions for the owner"; plan around it. +- Exact texts (spec): `✖ : imports "AppDelegate.h", which is not in ` (row 30; after the + final review, `which is not among the files the app target lists next to , in the app target's headers or in + `); + `ℹ precheck — imports , which SwiftPM builds: checked by xtool-build` (row 43; `which no module map + of the package graph declares` for a module neither the graph's maps nor the SDK's frameworks and Swift modules have); + `⚠ sets for the app target; rn-xtool does not read xcconfig files` (row 46); + `✖ precheck — :: ` with clang's include stack, the first ten errors and the log file's + path (hop 4); `⚠ precheck skipped (--skip-precheck): errors in the app's own sources show in xtool-build` (hop 6). + The flag is exactly `--skip-precheck`, on `build` (R2); it has no config twin and no `knownLimits.allow` key (the + spec gives neither). +- Certainty (anti-goal, R6): an error only where the check is certain; a condition B1 cannot evaluate never makes an + error (row 33); B1 never errors on `@import` (row 35) nor on a generated `-Swift.h` (row 36); pass 2 errors on an + angle include only when its first path component names no target of the package graph (row 37); a Swift or clang + module the precheck cannot place skips the file with `ℹ`, never an error (rows 43, 44). +- No fallback without a line naming it: a skipped file, a dropped module map, a stale-cache retry and a skipped + precheck each print one line. +- Mechanisms over versions: every rule follows a content fact (a spelling, a folder, a module map, a `describe` + field), never a library name or a React Native version. +- Downloads and builds on the owner's machine need the owner's approval first (the response-file capture is approved + in principle, R12; still ask before each series); builds go through a delegated session, one at a time, on copies + of the reference apps in a scratch folder, never the apps themselves; device runs are the owner's. The reference + apps set `metroPort: 8082` in `rn-xtool.config.json`; the runs here are build-only, so the port plays no part. +- Before every commit: `git add` the task's files, then `npm run scan:private` (must print `scan-private: clean`; read + its whole output). No absolute home path, Team ID, UDID, e-mail, IP or production-app name in any committed file; + tests normalise temp roots to ``/``, fixtures use `/home/me`. No bare `` `@word` `` outside code spans in + any markdown (`tests/mentions.test.ts`): `@import`, `@main` and `@objc` go in code spans. +- Commits: Conventional Commits, English, subject ≤ 50 characters, imperative, no body; one logical change each. +- Every task ends with `npm test` and `npm run lint` green. Tests that need the Darwin SDK and the toolchain's `clang` + skip with a reason naming `rn-xtool setup` when either is missing, as `tests/devSupport.test.ts:249-253` does. + +## Review Focus + +1. **A header whose name differs from the import only in case** (`#import "appdelegate.h"`, a project written on a + Mac, whose file system ignores case): Linux is case-sensitive, so `xtool-build` fails too; the stop must say the + file exists with other case, not only "not in". Pinned in Task 3 (`it("names a header that differs only in + case")`). +2. **Files saved on Windows or by odd editors**: CRLF line ends, a UTF-8 BOM, `# import` with spaces after `#`, a + directive continued with a trailing backslash. Directives and line numbers must come out as clang sees them. + Pinned in Task 1 (`it("reads CRLF, a BOM, spaced and continued directives")`). +3. **A project folder or a `HEADER_SEARCH_PATHS` entry with spaces** (`~/My Apps/x`, `"$(SRCROOT)/Vendor Kit"`): every + path stays one argument (argv, never a shell string) and displays whole. Pinned in Task 8 (`it("keeps a folder + with spaces one argument")`) and Task 3 (`it("lists a search path with spaces whole")`). +4. **A relative include that leaves the target folder** (`#import "../Shared/Theme.h"` from `ios/App/X.m`): the copy + lays files out differently from `ios/`, so the include is resolved against the copy, as `xtool-build` sees it. + Pinned in Task 2 (`it("resolves a relative include against the copy's layout")`). +5. **An app target with no Swift file, or with no C-family file** (the pre-0.77 Objective-C template has no Swift; the + Swift template has no `.m`): an empty hop must not run its compiler (`swiftc` with no input fails: a false stop). + Pinned in Task 10 (`it("runs no swiftc for a target without Swift files")`, `it("runs no clang for a Swift-only + target")`). + +## Interfaces later plans consume + +- **`tests/fixtures/objc-app/`** (Task 3): an Objective-C app target written from React Native's pre-0.77 template + (MIT). Plan F2's drift target overlays it on the CLI's project (rows 109–111). +- **`ios-xtool/.precheck/`** (Task 10): `precheck.log`, `inputs.json`, `swift-headers/`, `modulemaps/`, + `ModuleCache//`. Plan D's per-command log replaces `precheck.log` as hop 4's "log file" when it lands; + `build --clean` removes `.precheck/` with `ios-xtool/` on bare, and the step empties its module cache on Expo. +- **`PrecheckError`** (Tasks 7, 9): its message is the stop's summary; plan D appends its log line. +- **`BuildState.precheck`** (`"run" | "skipped"`) and `doctor --report`'s `precheck:` line, printed after plan 1's + `podspec reader:` lines (Task 11). + +--- + +### Task 1: The include scanner + +**Files:** +- Create: `src/project/includeScan.ts` +- Test: `tests/includeScan.test.ts` + +**Interfaces:** +- Consumes: nothing. +- Produces: + - `interface ScannedInclude { line: number; spelling: string; angle: boolean; certain: boolean }` — `line` 1-based + in the original text; `certain` when every enclosing condition is definitely taken. + - `interface ScanEnv { defines: ReadonlyMap; hasInclude(spelling: string, angle: boolean): boolean | + undefined }` — `undefined`: the pass cannot know. + - `scanIncludes(text: string, env: ScanEnv): ScannedInclude[]` — `#include`, `#import` (and `#include_next`, always + uncertain) in taken or unknown branches; `@import`, `#include MACRO` and anything in a false branch are not + returned (rows 34, 35). + - `B1_DEFINES: ReadonlyMap` — the macros every App compile of Swift Build gets, `SWIFT_PACKAGE=1` + and `DEBUG=1`, and the iOS values `TARGET_OS_MAC=1`, `TARGET_OS_IPHONE=1`, `TARGET_OS_IOS=1`, `TARGET_OS_OSX=0`, + `TARGET_OS_MACCATALYST=0`, `TARGET_OS_TV=0`, `TARGET_OS_WATCH=0`, `TARGET_OS_VISION=0`, `TARGET_OS_SIMULATOR=0`; + no `RCT_NEW_ARCH_ENABLED`, which the generated App target does not define (row 33b). A test keeps it equal to the + macros `SWIFT_BUILD_DEFINES.clang` and `.importer` share. + - `definesOf(targetDefines: readonly string[]): Map` — `B1_DEFINES` overlaid with the target's + `KEY`/`KEY=VALUE` (`KEY` alone is `1`). + +- [ ] **Step 1: Write the failing tests** (`env` = `{ defines: definesOf([]), hasInclude: () => undefined }` unless + stated): + + ```ts + it("returns each include with its line and form", () => { + expect(scanIncludes(`#import "A.h"\n#include \n@import Foundation;\n`, env)).toEqual([ + { line: 1, spelling: "A.h", angle: false, certain: true }, + { line: 2, spelling: "B/C.h", angle: true, certain: true }, + ]); + }); + it("drops includes in comments and under #if 0", () => { /* `// #import "X.h"`, a block comment over two lines with + an #import inside, `#if 0` … `#endif` → []; the line numbers after the block stay right */ }); + it("follows #ifdef/#elif/#else with the known defines", () => { /* #if DEBUG → taken; #ifdef RCT_NEW_ARCH_ENABLED → + uncertain (the generated App target does not define it); #if TARGET_OS_OSX + → not returned; #ifdef DEBUG … #else #import "Rel.h" → only the DEBUG branch; target define FOO=2 and + `#if FOO == 2` → taken */ }); + it("marks includes under a condition it cannot evaluate as uncertain", () => { /* #ifdef FB_SONARKIT_ENABLED, + #if __has_include() with hasInclude → undefined, #if SOME_MACRO(1) → certain: false; an #elif after an + unknown branch → certain: false; `0 && UNKNOWN` → not returned; `1 || UNKNOWN` → certain: true */ }); + it("evaluates __has_include with the resolver", () => { /* codegen's RCTAppDependencyProvider.h shape: + #if __has_include() / #import / #elif + __has_include("RCTModuleProviders.h") / #import "RCTModuleProviders.h" / #endif; hasInclude true for the first → + only the first, certain; false for both → [] */ }); + it("treats an include guard as taken", () => { /* #ifndef APP_H / #define APP_H / #import "B.h" / #endif → certain; + a #pragma once file → certain */ }); + it("does not report an include built from a macro", () => { /* #include MY_HEADER → [] */ }); + it("reads CRLF, a BOM, spaced and continued directives", () => { /* "#import \"A.h\"\r\n# import \r\n#if + defined(DEBUG) && \\\r\n defined(SWIFT_PACKAGE)\r\n#import \"C.h\"\r\n#endif" → A.h line 1, B.h line 2, + C.h line 5, all certain */ }); + ``` + +- [ ] **Step 2: Run them to verify they fail.** Run: `npx vitest run tests/includeScan.test.ts`. Expected: FAIL + (module not found). + +- [ ] **Step 3: Implement `src/project/includeScan.ts`.** Decisions the tests leave open: strip the BOM, join + backslash-continued lines (keeping the first line's number), blank comments and string literals before reading + directives; a three-valued evaluator (`true | false | undefined`) over integers, known identifiers, `defined X`, + `defined(X)`, `__has_include(...)`, `! && || == != < > <= >=` and parentheses, where an unknown identifier or a + function-like macro is `undefined`; a branch stack where an `#elif`/`#else` after an `undefined` branch is at best + `undefined`. An include guard is the file's first directive `#ifndef X` directly followed by `#define X`. + +- [ ] **Step 4: Run them to verify they pass.** Same command. Expected: PASS; `npm run lint` clean. + +- [ ] **Step 5: Commit.** + + ```bash + git add src/project/includeScan.ts tests/includeScan.test.ts + npm run scan:private + git commit -m "feat: scan the includes of app sources" + ``` + +### Task 2: The copy's layout and the include resolver + +**Files:** +- Modify: `src/generate/bareSources.ts` (`copyBareTarget` :46–163: the placement, the `include/` and same-destination + refusals and the forwards move into `bareCopyLayout`; `copyBareTarget` copies and logs from it) +- Create: `src/project/appIncludes.ts` (the resolver; Task 3 adds pass 1) +- Test: `tests/appIncludes.test.ts`, `tests/generate.test.ts` (the existing copy tests pass unchanged) + +**Interfaces:** +- Consumes: `scanIncludes`, `definesOf` (Task 1); `BareTargetContent`, `TargetFile`, `compiledName`. +- Produces: + - `interface BareCopyLayout { files: { file: TargetFile; dest: string }[]; forwards: Map; + missingHeaders: TargetFile[]; swiftHeaderForward?: string }` — `dest` relative to `Sources/App`; `forwards` maps a + header's base name to its `dest` (the first one wins, as today); `swiftHeaderForward` is + `-Swift.h` when `copyBareTarget` writes that forward. + - `bareCopyLayout(bare: BareTargetContent, iosDir: string, iosTargetDir: string, exists?: (p: string) => boolean): + BareCopyLayout` — throws the three errors `copyBareTarget` throws today (outside `ios/`, a file landing in + `include/`, two files to one destination), with the same texts. + - `CopiedBareTarget.origins: Record` (new field): each copied code file's absolute copy path → its + absolute source path. + - `interface IncludeScope { files: { path: string; source: string; display: string }[]; exists: (p: string) => + boolean; includeDirs: string[]; defines: ReadonlyMap }` — `path`: where the file sits in the copy; + `source`: where its text is read; `display`: how messages name it. + - `interface ResolvedInclude { file: string; line: number; spelling: string; angle: boolean; certain: boolean; + found?: string; searched: string[]; generated: boolean }` — `file` is the `display` of the including file. + - `resolveIncludes(scope: IncludeScope): ResolvedInclude[]` — quote: the including file's copy folder, then + `includeDirs` in order; angle: `includeDirs` in order; a spelling whose last component ends in `-Swift.h` is + `generated` and not looked up (row 36). `__has_include` asks the same lookup. + +- [ ] **Step 1: Write the failing tests:** + + ```ts + it("finds an app header in another folder by name, through the forwards", () => { /* headers at the root of the + group tree (ios/AppDelegate.h), ios/App/main.m importing "AppDelegate.h" → found at /include/AppDelegate.h + (row 31) */ }); + it("finds a quote include next to the including file first", () => { /* ios/App/A.h and an include dir with another + A.h → the neighbour */ }); + it("resolves a relative include against the copy's layout", () => { /* target folder ios/App; ios/App/X.m imports + "../Shared/Theme.h"; ios/Shared/Theme.h is in the target, so the copy holds Sources/App/X.m and + Sources/App/Shared/Theme.h: "../Shared/Theme.h" is not found, "Shared/Theme.h" is */ }); + it("never looks up a generated Swift header", () => { /* "App-Swift.h", "BareDemo-Swift.h", → + generated: true, no found, searched [] */ }); + it("answers __has_include with the same lookup", () => { /* #if __has_include("Found.h") → its branch taken */ }); + // tests/generate.test.ts + it("records where each copied file came from", () => { /* copyBareTarget(...).origins maps /AppMain.m → + /App/main.m */ }); + ``` + +- [ ] **Step 2: Run them to verify they fail.** Run: `npx vitest run tests/appIncludes.test.ts tests/generate.test.ts`. + Expected: FAIL (`bareCopyLayout`, `resolveIncludes` and `origins` not defined). + +- [ ] **Step 3: Implement** `bareCopyLayout` by moving the placement code out of `copyBareTarget` unchanged (`exists` + defaults to `existsSync`; a missing referenced header goes to `missingHeaders`, and `copyBareTarget` logs its + `ℹ Skipped …` line as today), then `resolveIncludes`, reading each `source` once. + +- [ ] **Step 4: Run the tests to verify they pass.** Same command, then `npm test`. Expected: PASS; every existing + `copyBareTarget` test unchanged. + +- [ ] **Step 5: Commit.** + + ```bash + git add src/generate/bareSources.ts src/project/appIncludes.ts tests/appIncludes.test.ts tests/generate.test.ts + npm run scan:private + git commit -m "refactor: share the app copy layout with B1" + ``` + +### Task 3: B1 pass 1 and the Objective-C fixture + +**Files:** +- Modify: `src/project/appIncludes.ts` +- Create: `tests/fixtures/objc-app/` (`package.json`, `app.json`, `ios/ObjcApp.xcodeproj/project.pbxproj`, + `ios/ObjcApp/{main.m,AppDelegate.h,AppDelegate.mm,Info.plist}`), `tests/fixtures/pbxproj/objc-root-group.pbxproj`, + `tests/support/objcApp.ts` +- Test: `tests/appIncludes.test.ts` + +**Interfaces:** +- Consumes: Task 2; `dependencyDirs`, `packageDir` (`src/project/podspecs.ts:30,68`). +- Produces: + - `dependencyHeaderIndex(root: string): Map` — base name → header paths (`.h`, `.hpp`) under the + installed `react-native` and each `dependencyDirs(root)` entry, nested `node_modules` and dot folders skipped; + built lazily, only when a certain quote include is missing. + - `bareScope(bare: BareTargetContent, iosDir: string, iosTargetDir: string, sources: string, root: string): + IncludeScope["files"]` — every C-family source, kept header and the bridging header, `path` at its copy place under + `sources` (from `bareCopyLayout`), `display` relative to the project root (`ios/ObjcApp/main.m`). + - `interface Pass1Input { root: string; files: IncludeScope["files"]; forwards: Map; sources: string; + headerSearchPaths: string[]; defines: string[]; binaryPods: boolean }` + - `interface Pass1Result { missing: string[]; pending: number; checked: number }` — `missing` holds row-30 lines + without `✖ `; `checked` counts the certain includes that resolved. + - `appIncludesPass1(i: Pass1Input): Pass1Result` — include dirs `[/include (virtual: the forwards), + ...headerSearchPaths]`; the copy is virtual (`exists` answers for the layout's places, the disk elsewhere). A + certain miss: angle → pending; quote → pending when `dependencyHeaderIndex` holds a header whose path ends with + the spelling or the project has binary pods, else missing. Uncertain misses count nowhere. + - The row-30 line, the spec's frame with the plan's list: `: imports "", which is not in + `, where `` = the including file's source folder (relative to the project + root), `the app target's headers`, then each `HEADER_SEARCH_PATHS` entry relative to the project root, joined as + `a, b or c`; when a file matching the spelling but for case exists where it looked: + `; differs only in case (file names are case-sensitive on Linux)`. + - `objcApp(layout: "template" | "root-group"): string` (`tests/support/objcApp.ts`) — copies the fixture into a temp + project root with an empty `node_modules/react-native/package.json` (`0.88.1`); `root-group` swaps in + `objc-root-group.pbxproj` and moves the three files next to the `.xcodeproj` (the trial's layout). + +- [ ] **Step 1: Write the fixture.** From React Native's pre-0.77 Objective-C template (0.76, MIT; each file keeps the + template's `This source code is licensed under the MIT license found in the LICENSE file in the root directory of + this source tree.`): `AppDelegate.h` (`#import `, `#import `, `@interface + AppDelegate : RCTAppDelegate`), `AppDelegate.mm` (`#import "AppDelegate.h"`, `#import + `, `moduleName` `ObjcApp`, `bundleURL` under `#if DEBUG`), `main.m` (`#import + `, `#import "AppDelegate.h"`, `UIApplicationMain(…, NSStringFromClass([AppDelegate class]))`). The + pbxproj: one application target `ObjcApp`, Sources phase `main.m` and `AppDelegate.mm`, `AppDelegate.h` in the + group, Debug `PRODUCT_BUNDLE_IDENTIFIER = com.example.objcapp`, `INFOPLIST_FILE = ObjcApp/Info.plist`, + `CLANG_CXX_LANGUAGE_STANDARD = "c++20"`, and a `baseConfigurationReference` to `Pods-ObjcApp.debug.xcconfig` + (CocoaPods' name, not on disk). `package.json` depends on `react-native` `0.88.1`. + +- [ ] **Step 2: Write the failing tests:** + + ```ts + it("passes the Objective-C template in both layouts", () => { /* objcApp("template"), objcApp("root-group") → + missing []; pending counts the certain angle includes (, , + , per including file) */ }); + it("stops on an app-own quote include that resolves nowhere (F2)", () => { /* root-group layout, AppDelegate.h + deleted from disk → missing has 'ios/main.m: imports "AppDelegate.h", which is not in ios or the app + target\'s headers' and the same for ios/AppDelegate.mm */ }); + it("leaves a quote include a dependency provides to the build", () => { /* "RNCAsyncStorage.h" missing in the app; + node_modules/x/ios/RNCAsyncStorage.h present and x in package.json dependencies → missing [], pending + 1 */ }); + it("leaves quote misses to the build when the project has binary pods", () => { /* binaryPods true → pending */ }); + it("never errors on an uncertain include", () => { /* #ifdef FB_SONARKIT_ENABLED / #import "FlipperKit.h" → nothing */ }); + it("names a header that differs only in case", () => { /* "appdelegate.h" with AppDelegate.h on disk → the line ends + '; ios/ObjcApp/AppDelegate.h differs only in case (file names are case-sensitive on Linux)' */ }); + it("lists a search path with spaces whole", () => { /* HEADER_SEARCH_PATHS "$(SRCROOT)/Vendor Kit" and a missing + quote include → the folders list contains 'ios/Vendor Kit' */ }); + ``` + +- [ ] **Step 3: Run them to verify they fail.** Run: `npx vitest run tests/appIncludes.test.ts`. Expected: FAIL. + +- [ ] **Step 4: Implement** `dependencyHeaderIndex`, `bareScope`, `appIncludesPass1` and `objcApp`. The first test's + pending number is what the rule above gives on the fixture: fix the number to the rule, never the rule to a number. + +- [ ] **Step 5: Run them to verify they pass.** Same command. Expected: PASS; `npm run lint` clean. + +- [ ] **Step 6: Commit.** + + ```bash + git add src/project/appIncludes.ts tests/appIncludes.test.ts tests/support/objcApp.ts tests/fixtures/objc-app \ + tests/fixtures/pbxproj/objc-root-group.pbxproj + npm run scan:private + git commit -m "feat: resolve the app's own includes (B1)" + ``` + +### Task 4: The app target's shape: xcconfig and synchronized folders + +**Files:** +- Modify: `src/project/pbxproj.ts` (`readTargetContent` :332; a new `appXcconfigWarnings`) +- Test: `tests/project/pbxproj.test.ts` + +**Interfaces:** +- Consumes: `openPbxproj`, the group walk (`walkGroups` :270). +- Produces: + - `XCCONFIG_READ_SETTINGS = ["HEADER_SEARCH_PATHS", "GCC_PREPROCESSOR_DEFINITIONS", "CLANG_CXX_LANGUAGE_STANDARD", + "SWIFT_OBJC_BRIDGING_HEADER", "PRODUCT_MODULE_NAME", "CODE_SIGN_ENTITLEMENTS", "INFOPLIST_FILE"] as const` (the + spec's list, in its order). + - `appXcconfigWarnings(p: Pbxproj, root: string): string[]` — for the `baseConfigurationReference` of the app + target's and the project's Debug configuration whose file name is not `Pods-*.xcconfig`: the settings of + `XCCONFIG_READ_SETTINGS` it sets (`KEY =` or `KEY[cond] =`, following `#include`/`#include?` relative to the file, + each file once) → `⚠ sets for the app target; rn-xtool does not read xcconfig + files`; a file that cannot be read → `⚠ (the app target's base configuration) could not be read; + rn-xtool does not read xcconfig files` (plan's wording). No line for a file that sets none of them (R6). + - `readTargetContent` throws `DetectError` when the app target has `fileSystemSynchronizedGroups` (row 47, plan's + wording): `The app target takes its files from the synchronized folder (an Xcode 16 folder group); + rn-xtool reads only the files a target lists. Convert the folder to a group (Xcode: Convert to Group) so the + target lists its files`. + +- [ ] **Step 1: Write the failing tests** (pbxproj text from `with-objc.pbxproj` and the Task 3 fixture, edited as + strings in the test): + + ```ts + it("warns about an xcconfig that sets a setting rn-xtool reads", () => { /* baseConfigurationReference → + Config/App.xcconfig: "HEADER_SEARCH_PATHS = $(inherited) Vendor\nOTHER_LDFLAGS = -lz\n#include \"Base.xcconfig\"", + Base.xcconfig: "GCC_PREPROCESSOR_DEFINITIONS[config=Debug] = X=1" → ["⚠ ios/Config/App.xcconfig sets + HEADER_SEARCH_PATHS, GCC_PREPROCESSOR_DEFINITIONS for the app target; rn-xtool does not read xcconfig files"] */ }); + it("says nothing about CocoaPods' xcconfigs or one that sets nothing rn-xtool reads", () => { /* with-objc.pbxproj + (Pods-HelloWorld.debug.xcconfig, not on disk) → []; an xcconfig with only OTHER_LDFLAGS → [] */ }); + it("names an xcconfig it cannot read", () => { /* App.xcconfig referenced, missing → the could-not-be-read line */ }); + it("refuses a synchronized folder in the app target", () => { /* a PBXFileSystemSynchronizedRootGroup (path = + ObjcApp) listed in the target's fileSystemSynchronizedGroups → DetectError naming "ObjcApp" */ }); + ``` + +- [ ] **Step 2: Run them to verify they fail.** Run: `npx vitest run tests/project/pbxproj.test.ts`. Expected: FAIL. + +- [ ] **Step 3: Implement.** The xcconfig's file reference is placed by the same group walk `readTargetContent` uses. + +- [ ] **Step 4: Run them to verify they pass.** Same command, then `npm test`. Expected: PASS. + +- [ ] **Step 5: Commit.** + + ```bash + git add src/project/pbxproj.ts tests/project/pbxproj.test.ts + npm run scan:private + git commit -m "feat: name xcconfigs and synchronized folders" + ``` + +### Task 5: Pass 1 in `doctor --project` and at the start of `build` + +**Files:** +- Modify: `src/project/appIncludes.ts` (`appTargetCheck`, `appTargetLines`); `src/generate/iosXtool.ts` + (`expoBridgingHeader` :169: its path resolution moves into an exported `expoBridgingHeaderPath`) +- Modify: `src/project/capabilities.ts` (`Capabilities` :239, `detectCapabilities` :347), `src/commands/doctor.ts` + (`capabilityChecks` :417) +- Modify: `src/commands/build.ts` (`BuildDeps` :150, `realDeps` :234, `build` :366: after `readProject` :407 on bare, + after the entitlements read :464 on Expo, so after `prebuild`) +- Test: `tests/capabilities.test.ts`, `tests/doctor.test.ts`, `tests/build.test.ts` + +**Interfaces:** +- Consumes: Tasks 3 and 4; `binaryPodCandidates` (`src/project/earlyChecks.ts:728`). +- Produces: + - `expoBridgingHeaderPath(iosDir: string): string | undefined` — the file `expoBridgingHeader` would copy (undefined + in each case it returns undefined, the same throws); `expoBridgingHeader` calls it. + - `interface AppTargetCheck { errors: string[]; warnings: string[]; pending: number; checked: number }` + - `appTargetCheck(input: { root: string; project: Pick; binaryPods: + boolean }): AppTargetCheck` — bare: pass 1 over `bareScope` plus `appXcconfigWarnings`; Expo: pass 1 over the + bridging header alone (its copy at `Sources/App/`, no forwards, no search paths) plus + `appXcconfigWarnings`; Expo without `ios/` → all empty. + - `appTargetLines(root: string, kind: ProjectKind | undefined, opts: { binaryPods: boolean }): string[]` — for + doctor: `✖ app-includes — ` per error; `⚠ app-target — ` per warning; + `ℹ app-includes — includes into React Native's or the libraries' headers: checked at build` when pending > 0 + (row 32, the spec's "checked at build" in the plan's sentence); `✔ app-includes — includes of the app's + own sources resolve` without errors. A read that throws gives no line (the `project` line reports it). + - `Capabilities.appTarget?: string[]` (`detectCapabilities` always sets it); `capabilityChecks` maps each line to a + check named `app-includes` or `app-target` with the status of its mark, after `patches` and before `known-limits`. + - `BuildDeps.appTargetCheck: typeof appTargetCheck`. `build` logs each warning, then each error as `✖ `, and + with errors throws `new Error(" include(s) of the app's own sources resolve nowhere (listed above): the build + would stop compiling them")` (plan's wording). `--skip-precheck` does not skip it (hop 6). Superseded after the + final review: with `--skip-precheck` the lines are `⚠` and the build goes on, and the stop ends with `; if + xtool-build builds them, build with rn-xtool build --skip-precheck and report it with rn-xtool doctor --report`. + +- [ ] **Step 1: Write the failing tests:** + + ```ts + // tests/doctor.test.ts + it("--project reports the app's includes", async () => { /* capabilities.appTarget lines → checks + { name: "app-includes", status: "fail", detail: 'ios/main.m:9 imports "AppDelegate.h", …' } and + { name: "app-includes", status: "info", detail: "4 includes into React Native's or the libraries' headers: checked at build" } */ }); + // tests/capabilities.test.ts + it("reads the app target's includes without a toolchain", async () => { /* objcApp("root-group") with PATH "" → + appTarget holds the ✔ and ℹ lines; with a non-Pods xcconfig setting HEADER_SEARCH_PATHS → an "⚠ app-target — …" line */ }); + it("gives no app-target line when the project cannot be read", async () => { /* synchronized folder → appTarget [] */ }); + // tests/build.test.ts + it("stops a bare build on an app-own include before any step", async () => { /* appTargetCheck → { errors: ["…"] } → + rejects with "1 include(s) of the app's own sources resolve nowhere"; no step in calls; logs has "✖ …" */ }); + it("checks an Expo app's bridging header after prebuild", async () => { /* the check runs after "prebuild" */ }); + ``` + +- [ ] **Step 2: Run them to verify they fail.** Run: `npx vitest run tests/doctor.test.ts tests/capabilities.test.ts + tests/build.test.ts`. Expected: FAIL. + +- [ ] **Step 3: Implement** the Interfaces block; the `setup()` fake in `tests/build.test.ts` gets + `appTargetCheck: () => ({ errors: [], warnings: [], pending: 0, checked: 0 })`. + +- [ ] **Step 4: Run them to verify they pass.** Same command, then `npm test`. Expected: PASS. + +- [ ] **Step 5: Commit.** + + ```bash + git add src/project/appIncludes.ts src/generate/iosXtool.ts src/project/capabilities.ts src/commands/doctor.ts \ + src/commands/build.ts tests/capabilities.test.ts tests/doctor.test.ts tests/build.test.ts + npm run scan:private + git commit -m "feat: check the app's includes in doctor and build" + ``` + +### Task 6: One flag source for the App target + +**Files:** +- Modify: `src/generate/packageSwift.ts` (`expoSwiftSettings` :113, `appSwiftSettings` :130, `importerSwiftSettings` + :137, `appClangSettings` :150) +- Modify: `src/generate/iosXtool.ts` (`writeIosXtool` :241 returns what it generated; `writeAppSources` :102 passes + the origins on) +- Test: `tests/generate.test.ts`, `tests/build.test.ts` (its `writeIosXtool` fake) + +**Interfaces:** +- Consumes: `CopiedBareTarget.origins` (Task 2). +- Produces: + - `appIncludeDirs(app: AppTargetInputs, expo?: ExpoPackageInputs): string[]` — + `[...app.headerSearchPaths, app.swiftHeadersDir, ...(expo?.clangImporter?.includeDirs ?? [])]`, the list + `appClangSettings` renders. B1 pass 2 and B2 build on it (R6: one include-list function). + - `appClangArgs(app: AppTargetInputs, expo: ExpoPackageInputs | undefined, cxx: boolean): string[]` — what the + manifest's `cSettings` (`cxx` false) or `cxxSettings` (`cxx` true) give the compiler: `-D` per define, `-I` per + `appIncludeDirs` entry, `-fmodule-map-file=` per importer module map, `-F ` with Expo, and the + `-std=` of `cxxStandardFlag` for C++; `[]` when `!app.mixed`. + - `appSwiftArgs(app: AppTargetInputs, expo: ExpoPackageInputs | undefined): string[]` — what `swiftSettings` give a + Debug build: `-DDEBUG`, Expo's `-DEXPO_CONFIGURATION_DEBUG` and flags, the bridging header's + `-import-objc-header`/`-Xcc` flags, the importer paths. + - `renderPackageSwift` renders from these lists; its output is byte-identical to today's. + - `interface GeneratedApp { pkg: PackageSwiftInput; origins: Record }`; + `writeIosXtool(ctx: GenerateContext): Promise` — `pkg` is the object handed to + `renderPackageSwift`; `origins` is the bare copy's map, or on Expo the copies of `AppDelegate.swift`, + `SceneDelegate.swift`, the bridging header and the `ExpoModulesProvider.swift` link → their sources. + +- [ ] **Step 1: Write the failing tests:** + + ```ts + it("gives the manifest's C and C++ flags as compiler arguments", () => { /* mixed app, defines ["FOO=1","BAR"], + headerSearchPaths ["/p/include","/p/hsp"], cxxStandard "gnu++20" → appClangArgs(app, undefined, true) equals + ["-DFOO=1","-DBAR","-I","/p/include","-I","/p/hsp","-I",app.swiftHeadersDir,"-std=gnu++20"]; cxx false → no -std */ }); + it("gives the Swift flags of a Debug build", () => { /* bridging header → contains "-import-objc-header", its path, + "-Xcc", "-I/p/include"; with expo → "-DEXPO_CONFIGURATION_DEBUG", no RELEASE */ }); + it("returns the package input and the origins it generated", async () => { /* writeIosXtool on the bare fixture → + result.pkg.app.headerSearchPaths[0] ends with Sources/App/include; origins maps the AppDelegate copy to its source */ }); + ``` + +- [ ] **Step 2: Run them to verify they fail.** Run: `npx vitest run tests/generate.test.ts`. Expected: FAIL. + +- [ ] **Step 3: Implement** the Interfaces block. `BuildDeps.writeIosXtool` stays `typeof writeIosXtool`; the + `tests/build.test.ts` fake returns `{ pkg: {}, origins: {} } as never`. + +- [ ] **Step 4: Run the tests to verify they pass.** `npm test`. Expected: PASS; the manifest expectations of + `tests/generate.test.ts` and `tests/fixtures/expo-Package.swift` unchanged. + +- [ ] **Step 5: Commit.** + + ```bash + git add src/generate/packageSwift.ts src/generate/iosXtool.ts tests/generate.test.ts tests/build.test.ts + npm run scan:private + git commit -m "refactor: one flag source for the App target" + ``` + +### Task 7: The package's plan and its graph's headers + +**Files:** +- Create: `src/pipeline/precheckGraph.ts`, `src/pipeline/precheckReport.ts` (only `PrecheckError` here; Task 9 fills it) +- Create: `tests/fixtures/precheck/graph/` (`describe-app.json`, `describe-executable.json`, `show-dependencies.json`, + `dump-.json` for: a root like the generated manifest, an xcframeworks package with a binary target, a + generated-code package with a clang target without a module map, an autolinked package, one library with a custom + `publicHeadersPath` and a Swift target, one package App does not reach), trimmed by hand to SwiftPM's output shape +- Test: `tests/precheckGraph.test.ts` + +**Interfaces:** +- Consumes: `readXcframeworkSlices` (`src/pipeline/rnArtifacts.ts`), `devEnv` (`src/tools/xtool.ts:155`). +- Produces: + - `class PrecheckError extends Error {}` (`src/pipeline/precheckReport.ts`). + - `type SwiftRunner = (args: string[], opts: { cwd: string; env: NodeJS.ProcessEnv }) => Promise<{ code: number; + stdout: string; stderr: string }>` — `swift` from `toolEnv()`'s PATH; a non-zero exit resolves. + - `planManifest(iosXtool: string, run: SwiftRunner): Promise` — `swift package describe --type json` in + `iosXtool` with `devEnv(iosXtool)` (row 54). Non-zero → `PrecheckError` `precheck — SwiftPM refused the generated + package (ios-xtool/Package.swift):` and SwiftPM's `error:` lines; an `App` target of `type` `executable` → + `PrecheckError` `precheck — SwiftPM plans the App target as an executable target (a file named main); xtool links + the app's entry point from the App library` (plan's wording). + - `interface DumpedPackage { name: string; path: string; products: { name: string; targets: string[] }[]; targets: + { name: string; type: string; path?: string | null; publicHeadersPath?: string | null; dependencies: unknown[] + }[] }` + - `readPackageGraph(iosXtool: string, scratch: string, run: SwiftRunner): Promise<{ root: DumpedPackage; packages: + DumpedPackage[] }>` — `swift package show-dependencies --format json`, then `swift package dump-package + --package-path

--scratch-path /` for the root and each local package, at most + `os.availableParallelism()` at a time, so nothing is written into a library's folder. A failure is a + `PrecheckError` naming the package and SwiftPM's lines. + - `interface PrecheckGraph { headerDirs: string[]; moduleMaps: string[]; synthesized: { module: string; text: string + }[]; targets: string[]; modules: string[] }` + - `graphHeaders(graph: { root: DumpedPackage; packages: DumpedPackage[] }): PrecheckGraph` — the targets reachable + from the root's `App` target through product, target and by-name dependencies (a product's package is the one + whose `name`, or whose lower-cased last path component, equals the reference), in dependency order. A clang target + gives `//` when that folder exists, with its + `module.modulemap` there, else a synthesized one by SwiftPM's rule (row 44; the plan's call is synthesis, so the + Swift template's `AppDelegate.swift` stays checked): `include//.h`, else + `include/.h`, as `umbrella header`, else the folder as `umbrella`; text + `module {\n umbrella header ""\n export *\n}\n`. A binary target gives its device slice's + `Headers` (the slice without a platform variant, as `reactNativeBareIncludeDirs` picks it). `targets` lists every + target name of every package (row 37); `modules` every module the graph's module maps declare (`module X`, + `framework module X`) and the synthesized ones. + +- [ ] **Step 1: Write the failing tests:** + + ```ts + it("plans the package and refuses an executable App target", async () => { /* fake run: describe-executable.json → + rejects PrecheckError "SwiftPM plans the App target as an executable target"; exit 1 with stderr "error: …" → + "SwiftPM refused the generated package" and the error line; describe-app.json → resolves */ }); + it("collects the header folders reachable from App", () => { /* fixtures → headerDirs in dependency order with the + binary slice's Headers; the unreachable package's folders absent */ }); + it("synthesizes a module map as SwiftPM does", () => { /* clang target without module.modulemap, with + include//.h → umbrella header text; a target with only include/*.h → `umbrella ""` */ }); + it("lists the graph's targets and modules", () => { /* targets has "ReactCodegen" and "Autolinked"; modules has the + binary slice's `module React` and the synthesized ones */ }); + it("runs dump-package with a scratch path outside the library", async () => { /* every recorded dump-package call has + --scratch-path under */ }); + ``` + +- [ ] **Step 2: Run them to verify they fail.** Run: `npx vitest run tests/precheckGraph.test.ts`. Expected: FAIL. + +- [ ] **Step 3: Implement** `src/pipeline/precheckGraph.ts` and the `PrecheckError` class. + +- [ ] **Step 4: Run them to verify they pass.** Same command. Expected: PASS; `npm run lint` clean. + +- [ ] **Step 5: Commit.** + + ```bash + git add src/pipeline/precheckGraph.ts src/pipeline/precheckReport.ts tests/precheckGraph.test.ts \ + tests/fixtures/precheck/graph + npm run scan:private + git commit -m "feat: read the package graph for the precheck" + ``` + +### Task 8: The toolchain and the command lines + +**Files:** +- Create: `src/pipeline/precheckCommands.ts` +- Test: `tests/precheckCommands.test.ts` + +**Interfaces:** +- Consumes: `appIncludeDirs`, `appClangArgs`, `appSwiftArgs`, `GeneratedApp` (Task 6); `PrecheckGraph`, + `PrecheckError` (Task 7); `sdkBundle()` (`src/commands/setup.ts:158`); `onPath`, `toolEnv` (`src/tools/exec.ts`); + `IOS_MIN` (`src/versions.ts:14`). +- Produces: + - `interface PrecheckToolchain { clang: string; swiftc: string; sdk: string; swiftExtra: string[]; versions: string }` + - `precheckToolchain(env?: NodeJS.ProcessEnv): Promise` — `clang` and `swiftc` found on + `toolEnv()`'s PATH, else `PrecheckError` `precheck — was not found on the Swift toolchain's PATH; run + rn-xtool setup`; the SDK from `swift-sdk.json` (`targetTriples["arm64-apple-ios"].sdkRootPath`, under the bundle), + missing → `PrecheckError` `precheck — the iPhoneOS SDK was not found in the Darwin SDK (); run rn-xtool + setup --xcode-xip ` (row 41, plan's wording); `swiftExtra` = `swiftCompiler.extraCLIOptions` of the toolsets + `swift-sdk.json` names for that triple, `-use-ld=…` left out; `versions` = `clang --version`, `swiftc --version` + and `darwin-sdk-version.txt`, joined. + - `moduleCacheKey(rnVersion: string, versions: string): string` — `rn-` (row 42). + - `interface PrecheckInputs { app: GeneratedApp; graph: PrecheckGraph; toolchain: PrecheckToolchain; dir: string; + moduleCache: string }` — `dir` is `ios-xtool/.precheck`; `moduleCache` is `

/ModuleCache/`. + - `precheckIncludeDirs(i: PrecheckInputs): string[]` — `appIncludeDirs` with `app.swiftHeadersDir` replaced by + `/swift-headers`, then `graph.headerDirs`: B1 pass 2's list and the compile's. + - `clangArgs(i: PrecheckInputs, file: string): string[]` — `-fsyntax-only`, `-x` by extension (`.m` objective-c, + `.mm` objective-c++, `.c` c, `.cc`/`.cpp`/`.cxx` c++, a header objective-c), `-target arm64-apple-ios`, + `-isysroot `, `-fobjc-arc` (Objective-C, Objective-C++), `-fmodules`, `-fno-cxx-modules` (C++, + Objective-C++), `-fmodules-cache-path=`, `-DDEBUG=1`, `appClangArgs` (its C++ form for C++ and + Objective-C++) with the swift-headers swap, `-I` per graph folder, `-fmodule-map-file=` per graph and synthesized + map (written to `/modulemaps//module.modulemap`), then `file`. The bridging header of a target without + C-family sources takes the `-Xcc` values of `appSwiftArgs` in place of `appClangArgs`. + - `swiftcArgs(i: PrecheckInputs, files: string[]): string[]` — `-typecheck`, `-module-name App`, `-target + arm64-apple-ios`, `-sdk `, `-swift-version 5`, `-module-cache-path `, + `-emit-objc-header-path /swift-headers/App-Swift.h`, `swiftExtra`, `appSwiftArgs`, `-I` and `-Xcc -I` per graph + folder, `-Xcc -fmodule-map-file=` per graph and synthesized map, then `files`. + - Every path is one argv element; nothing is joined into a shell string. + +- [ ] **Step 1: Write the failing tests:** + + ```ts + it("compiles Objective-C++ as Swift Build does", () => { /* clangArgs(.mm) contains "-x","objective-c++", + "-fobjc-arc","-fmodules","-fno-cxx-modules","-std=c++20","-target","arm64-apple-ios16.4"; clangArgs(.m) has no + -std and no -fno-cxx-modules (F4, F5) */ }); + it("uses the precheck's Swift header folder", () => { /* "-I", "/swift-headers" present; app.swiftHeadersDir absent */ }); + it("typechecks Swift with the bridging header and writes App-Swift.h", () => { /* swiftcArgs has + "-import-objc-header", "-emit-objc-header-path", "/swift-headers/App-Swift.h", "-module-name", "App" */ }); + it("keeps a folder with spaces one argument", () => { /* header search path "/p/My Apps/inc" is one element */ }); + it("names a missing compiler and a missing SDK", async () => { /* PATH "" → rejects + "precheck — clang was not found on the Swift toolchain's PATH; run rn-xtool setup"; a temp bundle whose + swift-sdk.json names a missing sdkRootPath → "the iPhoneOS SDK was not found" */ }); + it("keys the module cache by React Native and the toolchain", () => { /* same inputs → same key; other versions text + → other key; starts with "rn0.88.1-" */ }); + ``` + +- [ ] **Step 2: Run them to verify they fail.** Run: `npx vitest run tests/precheckCommands.test.ts`. Expected: FAIL. + +- [ ] **Step 3: Implement** `src/pipeline/precheckCommands.ts`. + +- [ ] **Step 4: Run them to verify they pass.** Same command. Expected: PASS; `npm run lint` clean. + +- [ ] **Step 5: Commit.** + + ```bash + git add src/pipeline/precheckCommands.ts tests/precheckCommands.test.ts + npm run scan:private + git commit -m "feat: build the precheck's command lines" + ``` + +### Task 9: Reading the compilers' errors + +**Files:** +- Modify: `src/pipeline/precheckReport.ts` +- Test: `tests/precheckReport.test.ts` + +**Interfaces:** +- Consumes: `PrecheckError` (Task 7). +- Produces: + - `interface Diagnostic { file: string; line: number; message: string; stack: string[] }` — `stack`: the + `In file included from ::` lines before it, in order. + - `parseDiagnostics(output: string): Diagnostic[]` — clang's and swiftc's `::: error: ` and + `fatal error:`; warnings, notes and source excerpts dropped (row 51). + - `precheckErrorLines(diags: Diagnostic[], display: (file: string) => string): string[]` — the first ten as + `✖ precheck — :: `, each followed by its stack, indented two spaces, `display` + applied (row 50); then `… and more` when there are more. + - `precheckStop(count: number, log: string): PrecheckError` — message `precheck: error(s) in the app's own + sources before xtool-build (the first ten are above; all of them in ). If xtool-build compiles these files, + this is a false stop: build with rn-xtool build --skip-precheck and report it with rn-xtool doctor --report` + (plan's wording; row 39's stop names `--skip-precheck`). + - `STALE_MODULE_CACHE = /module file .* is out of date|has been modified since the module file|malformed or corrupted + AST file/` (row 42). + +- [ ] **Step 1: Write the failing tests:** + + ```ts + it("keeps the include stack of an error in a library header (F4)", () => { /* "In file included from + /p/ios-xtool/Sources/App/AppDelegate.mm:3:\nIn file included from /rn/RCTAppDelegate.h:9:\n + /rn/react/utils/hash_combine.h:21:3: error: unknown type name 'requires'\n 21 | …\n" → one Diagnostic, stack of two */ }); + it("drops warnings and notes", () => { /* a warning, a note and an error → one */ }); + it("prints the first ten and counts the rest", () => { /* 12 errors → 10 "✖ precheck — " lines and "… and 2 more" */ }); + it("names the copy's source file", () => { /* display maps /AppMain.m → ios/ObjcApp/main.m */ }); + it("names --skip-precheck in the stop", () => { + expect(precheckStop(3, "ios-xtool/.precheck/precheck.log").message).toContain("rn-xtool build --skip-precheck"); + }); + ``` + +- [ ] **Step 2: Run them to verify they fail.** Run: `npx vitest run tests/precheckReport.test.ts`. Expected: FAIL. + +- [ ] **Step 3: Implement** `src/pipeline/precheckReport.ts`. + +- [ ] **Step 4: Run them to verify they pass.** Same command. Expected: PASS. + +- [ ] **Step 5: Commit.** + + ```bash + git add src/pipeline/precheckReport.ts tests/precheckReport.test.ts + npm run scan:private + git commit -m "feat: report the precheck's compile errors" + ``` + +### Task 10: The precheck run: pass 2, Swift, then the C family + +**Files:** +- Create: `src/pipeline/precheck.ts` +- Test: `tests/precheck.test.ts`; `tests/precheckToolchain.test.ts` (real `clang`/`swiftc` with the Darwin SDK, + skipped without them) + +**Interfaces:** +- Consumes: Tasks 1, 2, 6–9; `runArgv` (`src/tools/exec.ts:36`, `nice -n 15`). +- Produces: + - `interface PrecheckOptions { root: string; rnVersion: string; clean: boolean; log: (s: string) => void }` + - `interface PrecheckDeps { swift: SwiftRunner; compile: (cmd: string, args: string[], opts: { cwd: string; env: + NodeJS.ProcessEnv }) => Promise<{ code: number; output: string }>; toolchain: () => Promise }` + - `runPrecheck(paths: ProjectPaths, app: GeneratedApp, opts: PrecheckOptions, deps?: Partial): + Promise` — in order: + 1. `clean` removes `/ModuleCache`; any `ModuleCache/` is removed; `toolchain()`. + 2. `planManifest` (hop 5, first), `readPackageGraph`, `graphHeaders`; the synthesized maps are written; the + `PrecheckInputs` go to `/inputs.json`. + 3. B1 pass 2 over the copied code files (`origins`) with `precheckIncludeDirs` and `definesOf(app.pkg.app.defines)`: + a certain miss of a quote include, or of an angle include whose first path component is not in + `graph.targets`, is `✖ precheck — : imports , which is in none of the App target's + include folders (listed in )`, and these stop the step (`precheckStop`) before any compile; any other + certain angle miss is `⚠ precheck — : imports , which rn-xtool did not find; is a + target of the package, so the compile decides` (row 37, plan's wording). + 4. Swift (hop 2): the `import` lines of the copied `.swift` files (`@attr import`, `import struct X.Y` included); + a module that is neither the SDK's (`/System/Library/Frameworks/.framework`, + `/usr/lib/swift/.swiftmodule`) nor in `graph.modules` prints `ℹ precheck — imports , + which SwiftPM builds: checked by xtool-build`, and the Swift hop is skipped (one module, row 43); otherwise one + `swiftc` over all Swift files. No Swift file → no `swiftc`. The bridging header of a skipped or Swift-only target + is compiled by `clang` alone (row 53). + 5. C family (hop 3): `clang` per `.m`/`.mm`/`.c`/`.cc`/`.cpp`/`.cxx`, `os.availableParallelism()` at a time, each + under `nice`. A file that imports (itself or through the app headers it includes) a `-Swift.h` the precheck did + not write is not compiled: one `ℹ precheck — import
, which the Swift check did not write: + checked by xtool-build` (row 45). A `-fmodule-map-file` naming a file that does not exist yet (Expo's importer + maps in Swift Build's folder) is dropped, with one `ℹ precheck — module maps Swift Build writes are not + there yet: files that need them are checked by xtool-build` (plan's wording). + 6. Output matching `STALE_MODULE_CACHE` removes the cache and runs that hop once more, with `ℹ precheck — the + module cache was stale (); checked again without it` (row 42). + 7. Errors → `precheckErrorLines` through `opts.log`, then `throw precheckStop(...)`. Every command line and all + output go to `/precheck.log` (written anew each run); the terminal gets errors only (row 51). + - `display`: a copied file is named by its source, relative to the project root; any other path relative to it. + +- [ ] **Step 1: Write the failing tests** (`tests/precheck.test.ts`: fakes for `swift`, `compile` and `toolchain`; the + Task 3 fixture generated into a temp root): + + ```ts + it("plans, reads the graph, then compiles Swift before the C family", async () => { /* recorded order: describe, + show-dependencies, dump-package…, swiftc, clang… */ }); + it("stops on F3 in pass 2 before compiling", async () => { /* in no folder → logs + "✖ precheck — ios/ObjcApp/AppDelegate.h: imports RCTAppDelegate.h, which is in none of …", rejects + PrecheckError, no compile call */ }); + it("leaves a miss under a graph target to the compile", async () => { /* missing, ReactCodegen a + target → the ⚠ line, the compiles run */ }); + it("skips Swift that imports a module SwiftPM builds", async () => { /* AppDelegate.swift `import Expo` → exactly + "ℹ precheck — ios/App/AppDelegate.swift imports Expo, which SwiftPM builds: checked by xtool-build", no swiftc; + an .m importing "App-Swift.h" → the row-45 ℹ line, no clang for it */ }); + it("runs no swiftc for a target without Swift files", async () => { /* Objective-C fixture → no swiftc call */ }); + it("runs no clang for a Swift-only target", async () => { /* Swift template, no bridging header → no clang call */ }); + it("retries once without a stale module cache", async () => { /* first clang output "module file '…' is out of + date" → cache removed, second run passes, the ℹ line once */ }); + it("prints errors only and names the log", async () => { /* clang output with a warning and two errors → two + "✖ precheck — " lines and no warning text on the terminal; precheck.log holds the warning */ }); + it("empties the module cache on --clean", async () => { /* clean true → /ModuleCache gone before toolchain() */ }); + ``` + + `tests/precheckToolchain.test.ts`, `describe.skipIf(!HAS_IOS_TOOLS)` with the reason `(needs the Darwin SDK and the + Swift toolchain's clang: rn-xtool setup)`, real compilers on a tiny target built from SDK headers only: + + ```ts + it("F4: an Objective-C++ file that needs C++20 fails without the manifest's -std and passes with it", () => { /* a + header with a `requires` clause, included from a .mm */ }); + it("F5: an @import in a header a .mm includes fails as in Swift Build", () => { /* header with `@import Foundation;` + → clang's "use of '@import' when C++ modules are disabled" */ }); + it("writes App-Swift.h from swiftc -typecheck", () => { /* one Swift file with an @objc class → the header exists */ }); + ``` + +- [ ] **Step 2: Run them to verify they fail.** Run: `npx vitest run tests/precheck.test.ts + tests/precheckToolchain.test.ts`. Expected: FAIL (module not found). + +- [ ] **Step 3: Implement** `src/pipeline/precheck.ts`. Real deps: execa with `toolEnv()`, `extendEnv: false`, + `reject: false`, `all: true`; `compile` runs through `runArgv(cmd, args, true)`. + +- [ ] **Step 4: Run them to verify they pass.** Same command, then `npm test`. Expected: PASS (the toolchain file runs + here once `rn-xtool setup` ran, and is listed as skipped in CI). + +- [ ] **Step 5: Commit.** + + ```bash + git add src/pipeline/precheck.ts tests/precheck.test.ts tests/precheckToolchain.test.ts + npm run scan:private + git commit -m "feat: precheck the app sources before xtool" + ``` + +### Task 11: The `precheck` step, `--skip-precheck` and the report line + +**Files:** +- Modify: `src/commands/build.ts` (`BUILD_STEP_NAMES` :62, `BuildPlanInput` :73, `plainSteps` :109, `BuildDeps`, + `realDeps`, `build` :366 and :578–593) +- Modify: `src/cli.ts` (the `build` command :67–75), `src/state.ts` (`BuildState` :6), `src/commands/report.ts` + (`renderIssueReport` :262, `doctorReport` :315) +- Test: `tests/build.test.ts` (the step lists at :26–99 gain `precheck`), `tests/cli.test.ts`, `tests/report.test.ts` + +**Interfaces:** +- Consumes: `runPrecheck`, `PrecheckOptions` (Task 10), `GeneratedApp` (Task 6). +- Produces: + - `BUILD_STEP_NAMES` gains `"precheck"` between `"generate"` and `"xtool-build"`; `BuildPlanInput.precheck?: + boolean` (`false` leaves the step out; absent means planned). + - `build(root, opts: { clean?: boolean; skipPrecheck?: boolean }, overrides)`; `BuildDeps.precheck: (paths: + ProjectPaths, app: GeneratedApp, opts: PrecheckOptions) => Promise` (real: `runPrecheck`). With + `skipPrecheck`, `build` logs `⚠ precheck skipped (--skip-precheck): errors in the app's own sources show in + xtool-build` where the step would run; pass 1 (Task 5) still runs. + - `rn-xtool build --skip-precheck` (`.option("--skip-precheck", "skip the check of the app's own sources before + xtool-build")`); `run` calls `build` without it (the spec gives the flag to `build`). + - `BuildState.precheck?: "run" | "skipped"`, in the state written at `generate`. + - `precheckReportLine(state: BuildState | undefined): string` (`report.ts`) — `precheck: run (last build)`, + `precheck: skipped with --skip-precheck (last build)` or `precheck: not recorded`; `renderIssueReport` prints it + after the podspec lines, from `readState(projectPaths(root).iosXtool)` in a project (unreadable → `not + recorded`), inside the redacted block (R2). + +- [ ] **Step 1: Write the failing tests:** + + ```ts + // tests/build.test.ts + it("plans precheck between generate and xtool-build", () => { /* each list ends "generate","precheck","xtool-build"; + precheck: false → no "precheck" */ }); + it("runs the precheck with the generated app and stops before xtool-build", async () => { /* the precheck fake throws + → calls end with "generate","precheck"; the state has no depsFingerprint and precheck "run" */ }); + it("skips the precheck with --skip-precheck and says so", async () => { /* skipPrecheck → no "precheck" call; logs + contain exactly "⚠ precheck skipped (--skip-precheck): errors in the app's own sources show in xtool-build"; + state.precheck "skipped"; appTargetCheck still called */ }); + // tests/cli.test.ts + it("offers --skip-precheck on build only", () => { /* buildProgram().commands: "build" has the option + "--skip-precheck", "run" does not (the shape of the existing option tests at :39–55) */ }); + // tests/report.test.ts + it("records whether the last build skipped the precheck", async () => { /* state precheck "skipped" → the report has + "precheck: skipped with --skip-precheck (last build)" after the podspec reader line; no state → "precheck: not recorded" */ }); + ``` + +- [ ] **Step 2: Run them to verify they fail.** Run: `npx vitest run tests/build.test.ts tests/cli.test.ts + tests/report.test.ts`. Expected: FAIL. + +- [ ] **Step 3: Implement** the Interfaces block; `setup()` in `tests/build.test.ts` gets `precheck: rec("precheck")`. + +- [ ] **Step 4: Run them to verify they pass.** `npm test`. Expected: PASS; `npm run lint` clean. + +- [ ] **Step 5: Commit.** + + ```bash + git add src/commands/build.ts src/cli.ts src/state.ts src/commands/report.ts tests/build.test.ts tests/cli.test.ts \ + tests/report.test.ts + npm run scan:private + git commit -m "feat: add the precheck step and --skip-precheck" + ``` + +### Task 12: The user docs and the CHANGELOG + +**Files:** +- Modify: `docs/bare-react-native.md` ("Build steps" :192; "What is read from `project.pbxproj`" :202, whose + "`.xcconfig` files are ignored" gains the `⚠` and the synchronized-folder refusal) +- Modify: `docs/how-it-works.md` ("The build, step by step" :33; "Reference timings" :609 once Task 15 measured) +- Modify: `docs/troubleshooting.md` (a new `### Precheck` under "Build and patches", before `### Podspec reader` :976; + `app-includes` and `app-target` in "doctor --project" :1424) +- Modify: `CHANGELOG.md` (`## [Unreleased]`, :6) +- Test: `tests/docsLinks.test.ts`, `tests/mentions.test.ts` + +**Interfaces:** +- Consumes: the texts of Tasks 3–11. +- Produces: present-tense user text; no code. + +- [ ] **Step 1: Write the docs.** bare-react-native and how-it-works: the step list with `precheck`, what pass 1 and + the precheck check, and that pass 1 runs in `doctor --project` without a toolchain. troubleshooting `### Precheck`: + each stop and line of Tasks 3–11 with what to do: an app-own include (the file, the folders searched, case on + Linux); a stop in a library header (the include stack starts at the app's file; the cause is usually the app's + flags); a false stop (`rn-xtool build --skip-precheck`, after which `rn-xtool run` uses that build, and + `rn-xtool doctor --report` to report it); the xcconfig line; the synchronized folder; the `ℹ` skips; + `ios-xtool/.precheck/precheck.log`; `--clean` empties the module cache; the first precheck is slower while clang + builds React Native's modules (row 49). + +- [ ] **Step 2: Write the CHANGELOG entries** under `[Unreleased]`: `### Added` (pass 1 in `doctor --project` and at + `build` start, the `precheck` step, `--skip-precheck`, the `doctor --report` line, the xcconfig `⚠`), `### Changed` + (an app target with a synchronized folder is refused; `build` stops seconds after it starts on an app-own include + that resolves nowhere). + +- [ ] **Step 3: Verify.** Run: `npx vitest run tests/docsLinks.test.ts tests/mentions.test.ts`. Expected: PASS; every + `@import` of the new text in a code span. + +- [ ] **Step 4: Commit.** + + ```bash + git add docs/bare-react-native.md docs/how-it-works.md docs/troubleshooting.md CHANGELOG.md + npm run scan:private + git commit -m "docs: describe the app target precheck" + ``` + +### Task 13: The response-file capture (R12, the owner's approval first) + +**Files:** +- Create: `tests/fixtures/precheck/golden//inputs.json` and `tests/fixtures/precheck/golden//responses/`, + `` in `bare-085`, `bare-086`, `bare-087`, `bare-088`, `objc-088`, `expo-58-bridging` + +**Interfaces:** +- Consumes: everything above, built (`npm run build`), run from the branch's `dist/`. +- Produces: what Task 14 reads: Swift Build's response files of the App target's compiles (each C-family file and the + Swift compile) and the precheck's `inputs.json` of the same build, normalised. + +- [ ] **Step 1: Ask the owner** for six builds (minutes and gigabytes each), one at a time, through a delegated + session, on copies in a scratch folder of `../app-bare-085`, `../app-bare-086`, `../app-bare-087`, `../app-bare` + (0.88.1), `../app-bare` with `tests/fixtures/objc-app/ios/` laid over its `ios/` (build-only: the JavaScript + component name is not adjusted), and `../app` (Expo SDK 58) after `expo prebuild`, with `#import + ` added to the prebuild's bridging header so it is passed. The reference apps stay + untouched. + +- [ ] **Step 2: Build each copy.** `rn-xtool build --clean`. A precheck stop on these references is a false stop (row + 55): record its text, then `rn-xtool build --skip-precheck` so Swift Build writes its response files. Copy + `ios-xtool/.precheck/inputs.json` and the App target's response files (`find ios-xtool/.build -path '*App.build*' + -name '*.resp'`) into the fixture folder. + +- [ ] **Step 3: Normalise.** Home folder → `/home/me`; the copy's root → `/home/me/`; nothing else. Run + `npm run scan:private` with the fixtures staged and read its whole output. + +- [ ] **Step 4: Commit.** + + ```bash + git add tests/fixtures/precheck/golden + npm run scan:private + git commit -m "test: capture Swift Build's App command lines" + ``` + +### Task 14: The golden test of the command lines (row 39) + +**Files:** +- Create: `tests/precheckGolden.test.ts` +- Modify: `src/pipeline/precheckCommands.ts`, `src/pipeline/precheckGraph.ts` (only where the golden shows a flag Swift + Build gives and the precheck does not, or the reverse) + +**Interfaces:** +- Consumes: Task 13's fixtures; `clangArgs`, `swiftcArgs`. +- Produces: `compareFlags(ours: string[], theirs: string[]): { missing: string[]; extra: string[] }` (in the test + file), comparing after normalisation only these flag classes: `-D…`, `-U…`, `-I…`, `-iquote`, `-isystem`, `-F…`, + `-fmodule-map-file=…`, `-std=…`, `-fobjc-arc`/`-fno-objc-arc`, `-fmodules`, `-fno-cxx-modules`/`-fcxx-modules`, + `-fmodule-name=…`, `-include`, `-target`, `-isysroot`/`-sdk`, `-x`, `-import-objc-header`, `-Xcc …`, + `-swift-version`, `-module-name`, `-enable-…` and `-Xfrontend` pairs; every other flag is ignored and listed in the + test. Normalisation: Swift Build's `GeneratedModuleMaps-iphoneos` and the precheck's `swift-headers` → + ``; a module map under `.build` and the precheck's synthesized one → `>`; module + cache paths dropped. + +- [ ] **Step 1: Write the test**: per `` and response file, `it(": gets Swift Build's flags")` with + `expect(compareFlags(ours, theirs)).toEqual({ missing: [], extra: [] })`. + +- [ ] **Step 2: Run it.** Run: `npx vitest run tests/precheckGolden.test.ts`. Expected: FAIL wherever the builder + differs; read each `missing` and `extra`. + +- [ ] **Step 3: Fix the builder, not the golden.** Each difference is fixed in `precheckCommands.ts` or + `precheckGraph.ts`; one that only normalisation explains joins the normalisation with a one-line comment naming the + response file it came from. A flag that would need `vendor/rn-spm/spm/` changed goes to "Open questions". + +- [ ] **Step 4: Run the tests to verify they pass.** `npm test`. Expected: PASS; the false stops Task 13 recorded do + not happen with the fixed builder on the same `inputs.json`. + +- [ ] **Step 5: Commit.** + + ```bash + git add tests/precheckGolden.test.ts src/pipeline/precheckCommands.ts src/pipeline/precheckGraph.ts + npm run scan:private + git commit -m "test: compare the precheck with Swift Build" + ``` + +### Task 15: Build-only proofs and the hand-off (the owner's approval first) + +**Files:** +- None committed but `CHANGELOG.md` and `docs/how-it-works.md` ("Reference timings") when a result changes their + text; results go to the task's report. + +**Interfaces:** +- Consumes: everything above, built. +- Produces: the evidence the spec's Verification asks of group B (build-only proof 1, B's half of proof 3, row 55). + +- [ ] **Step 1: Ask the owner** for the series below, run one build at a time through a delegated session, on scratch + copies only. + +- [ ] **Step 2: Seeded faults** on the Objective-C overlay of Task 13, one per build from a clean copy: F2, + `AppDelegate.h` deleted → stopped at `build` start by pass 1 with the row-30 line, and the same line in + `doctor --project`; F3, the bare include dirs dropped in the scratch install's built + `dist/generate/iosXtool.js` only (`reactNativeBareIncludeDirs` returning `[]`) → stopped by pass 2 naming + `RCTAppDelegate.h`; F4, `CLANG_CXX_LANGUAGE_STANDARD = "c++17"` → stopped by the precheck in a React Native C++ + header, the include stack starting at `AppDelegate.mm`; F5, `@import Foundation;` in `AppDelegate.h` → stopped by + the precheck with clang's `@import` error. Record per fault the time from the `generate` line to the report (about + 30 s, Goal 1) and whether the module cache was cold (row 49). + +- [ ] **Step 3: The references with no new stop** (row 55): bare 0.85, 0.86, 0.87 and 0.88 (Swift templates), the + Objective-C overlay, Expo SDK 57 and 58: `rn-xtool build --clean`, then `rn-xtool doctor --project`. Expected: no + `✖` from pass 1 or the precheck, no `⚠` but those this plan lists, the `precheck` step's time; Expo's + `AppDelegate.swift` gives the row-43 `ℹ`. + +- [ ] **Step 4: Hand the production app to the owner**: built with the branch's `npm pack`; expected: pass 1 and the + precheck pass on its Objective-C app target with no hand fix, then `xtool-build` as before. He runs it himself and + reports. + +- [ ] **Step 5: Report** each result and time to the owner. No commit unless a text changed. + +--- + +## Deferred + +- **Rows 34 (macro includes), 36, 40, 48, 51, 52**: accepted by the spec; nothing to build beyond the lines of Tasks + 1, 2 and 9. +- **Row 49** (a slower first precheck): accepted; measured in Task 15. +- **Reading xcconfig settings and synchronized folders** into the generated project (rows 46, 47): a later block (the + spec's non-goals); this plan only names them. +- **B1 pass 2's React Native half right after `rn-artifacts`** ("Left to the builder"): not built; pass 2 runs in the + `precheck` step (the plan's call, minimal). +- **A precompile in `doctor`**: not built; the spec puts B2 in `build`, and `doctor` already fails on `swift` and + `darwin-sdk` (row 41). +- **Drift watch on Swift Build's flags** (row 40b, after the final review): deferred to a named task in alpha.9, plan + F2 / drift watch: after a successful `xtool-build`, read the App compile argv from the task store as Task 13 did and + run `compareFlags` against the precheck's; `⚠` on drift. Rows 49b (memory on a cold cache) and 49c (a full disk) are + accepted: both stop with a line naming `--skip-precheck`. + +## Open questions for the owner + +1. **Approvals**: the six capture builds of Task 13 and the proof series of Task 15 (each asked before it runs), and + the production-app run (yours). +2. **Who creates the Objective-C fixture**: this plan creates `tests/fixtures/objc-app/` (group B's tests and golden + need it first); plan F2 overlays it for the drift watch. Confirm. +3. **Pass 1's certainty for quote includes**: a missing quote include is an error only when no header of the installed + `react-native` or of a dependency ends with that spelling and the project has no binary pods (Task 3); otherwise + it waits for pass 2. The spec says "app-own" without a rule; this is the plan's. Superseded: the app-own rule + (ledger line 57) and, after the final review, path-matching evidence for spellings with a folder. Ruled after the + re-review: the `ios/` match ignores case (the app target's headers match case-sensitively), so a case-only twin is + evidence and keeps its hint; this narrows the old base-name rule (spec, B1 pass 1). +4. **`run` has no `--skip-precheck`**: the spec gives it to `build`; after a false stop, `build --skip-precheck` then + `run` uses that build. Add it to `run` too? Answered: `run` has it (Task 11). +5. **The release**: 0.1.0-alpha.8 shipped with group A; this plan's entries go to `[Unreleased]`. Which version + carries group B? + +## Self-review + +- **Spec coverage** (rows 30–55): 30 T3, T5; 31 T2; 32 T3, T5; 33 T1; 34 T1 (comments, `#if 0`; macros Deferred); 35 + T1; 36 T2, Deferred; 37 T6 (one list), T7 (targets), T10; 38 T1–T5 (no toolchain; T5's capability test runs with an + empty PATH); 39 T8, T9, T11, T13, T14; 40 Deferred; 41 T8; 42 T8, T9, T10; 43 T10; 44 T7, T10; 45 T10; 46 T4, T5; + 47 T4, T5; 48 Deferred; 49 Deferred, T15; 50 T9; 51 T9, T10; 52 Deferred; 53 T5 (pass 1), T10 (the bridging header + through `clang`), T13 (the Expo 58 golden); 54 T7, T10; 55 T13, T15. R2 T11; R6 T4–T7, T10; R12 T13. The anti-goal: + Global Constraints' certainty line, T14, T15 Step 3. +- **Spec contradictions planned around**: (a) hop 6 skips "hops 2–5" while hop 5 runs first and pass 2 lives in the + step: `--skip-precheck` skips the whole `precheck` step; pass 1 still runs (T11). (b) Verification proof 1 seeds F4 + by removing `CLANG_CXX_LANGUAGE_STANDARD`, which today means C++20 and builds: T15 seeds `c++17`, by the trial's + ruling that an older standard fails as in Xcode. (c) Hop 4 names "the log file's path" before group D's logs exist: + the precheck keeps `ios-xtool/.precheck/precheck.log` until plan D replaces it. (d) B1's `@import` lookup has no + effect once row 35 rules that B1 never errors on `@import`: B1 skips `@import`; B2 compiles it. +- **Type consistency**: `GeneratedApp` (T6), `PrecheckError` and `PrecheckGraph` (T7), `PrecheckInputs` (T8), + `IncludeScope` (T2), `AppTargetCheck` (T5) and `PrecheckOptions` (T10) are each defined once and used under the same + names in later tasks. diff --git a/docs/design/specs/2026-11-06-alpha-8-fail-early-design.md b/docs/design/specs/2026-11-06-alpha-8-fail-early-design.md index 04607ae..1c03052 100644 --- a/docs/design/specs/2026-11-06-alpha-8-fail-early-design.md +++ b/docs/design/specs/2026-11-06-alpha-8-fail-early-design.md @@ -96,9 +96,10 @@ written with them. and video take their old-architecture branch. The shim models the helpers and gives one result on every machine with Ruby. The JavaScript evaluator stays as the fallback without Ruby. - **R2. An exit for each new stop that can block a working app** (rows 5 and 39). `RN_XTOOL_PODSPEC_READER=reduced` - forces the reduced reader for one run, and `rn-xtool build --skip-precheck` skips the precheck; each prints a `⚠` - line naming itself, and `doctor --report` records that it was used. A blocked user with no way out abandons the tool - before reporting; the report turns each use into a signal for the maintainers. + forces the reduced reader for one run, and `rn-xtool build --skip-precheck` skips the precheck and turns B1 pass 1's + errors into `⚠` lines; each prints a `⚠` line naming itself, and `doctor --report` records that it was used. A + blocked user with no way out abandons the tool before reporting; the report turns each use into a signal for the + maintainers. - **R3. A shim failure is never swallowed** (row 10): it stops `rn-spm` with the shim's text, also when an autolinking read hits it. The reader sweep covers every podspec of the Expo SDK 57 and 58 templates and of the reference apps, so Expo modules are proven before release. @@ -495,8 +496,11 @@ are not proposed again without new facts. **B1, the include resolution.** It reads the app target as `generate` will copy it (fact 13): every C-family source, every header the copy keeps, and the bridging header. For each file it strips comments, follows `#if`/`#ifdef`/ -`#elif`/`#else` with the target's defines, `RCT_NEW_ARCH_ENABLED=1`, `DEBUG=1` and the iOS values of `TARGET_OS_*`, -and evaluates `__has_include` with the resolver itself. Each `#import`/`#include`: +`#elif`/`#else` with the defines the compile gets: the target's own, the ones Swift Build gives every App compile +(`SWIFT_PACKAGE` and `DEBUG=1`, which a C-family file and the bridging header both get) and the iOS values of +`TARGET_OS_*` that clang predefines; it evaluates `__has_include` with the resolver itself. The App target as rn-xtool +generates it does not define `RCT_NEW_ARCH_ENABLED`, so a condition on it is one B1 cannot evaluate, as is a condition +on any other macro outside that list. Each `#import`/`#include`: - `"X.h"`: the including file's folder, then the app's headers by name (the forwards of fact 14), then the include paths in order; @@ -508,20 +512,31 @@ and evaluates `__has_include` with the resolver itself. Each `#import`/`#include An include is **missing** when it is unconditional (outside every `#if` group except include guards) and resolves nowhere; one under a condition B1 cannot evaluate is never an error. B1 runs twice: -1. **Pass 1, before anything changes**: in `doctor --project` and at the start of `build`, next to the early checks. - It knows the app's own files and `HEADER_SEARCH_PATHS`. An app-own quote include that is missing (F2) is an error - with the file, the line, the header and where rn-xtool looked. An angle include into React Native's or a library's - headers is "not checked yet" while `ios/build/xcframeworks` and the scaffolds are not staged: one `ℹ` line with the - count, in doctor only. The same pass checks the app target's shape (R6, rows 46 and 47): an xcconfig the target or - the project names (`baseConfigurationReference`) that is not CocoaPods' generated `Pods-*.xcconfig` and sets a - setting rn-xtool reads (`HEADER_SEARCH_PATHS`, `GCC_PREPROCESSOR_DEFINITIONS`, `CLANG_CXX_LANGUAGE_STANDARD`, - `SWIFT_OBJC_BRIDGING_HEADER`, `PRODUCT_MODULE_NAME`, `CODE_SIGN_ENTITLEMENTS`, `INFOPLIST_FILE`) gives - `⚠ sets for the app target; rn-xtool does not read xcconfig files`; a synchronized folder group - in the app target is refused, naming the group. +1. **Pass 1, before anything changes**: in `doctor --project` and at the start of `build`, next to the early checks. It + knows the app's own files and `HEADER_SEARCH_PATHS`. An app-own quote include that is missing (F2) is an error with + the file, the line, the header and where rn-xtool looked. A quote include is app-own when a header the app target + lists (its headers and its bridging header, by path under `ios/`; on Expo, the bridging header's name), or a file + under `ios/`, has a path that ends with the spelling (for a spelling without a folder, its name; case ignored, so + that a case-only twin is named): a header of that name in another folder is no evidence for a spelling with a folder + (`"SomeLib/Utils.h"`), which a library's headers may answer, and pass 1 leaves it to the build. The match on the + headers the app target lists is case-sensitive; the match on the files under `ios/` ignores case, so a file whose + path differs from the spelling only in case counts as evidence and the miss names it with the case hint. This + narrows the earlier base-name rule (a `Utils.h` anywhere under `ios/` no longer makes `"SomeLib/Utils.h"` app-own); + a false `✖` from the case-insensitive match needs both a case-only twin under `ios/` and a library holding the exact + spelling, and otherwise clang on Linux fails on the same include. With `--skip-precheck` (hop 6) these errors are `⚠` lines and the build goes on. An angle include into React + Native's or a library's headers is "not checked yet" while `ios/build/xcframeworks` and the scaffolds are not staged: + one `ℹ` line with the count, in doctor only. The same pass checks the app target's shape (R6, rows 46 and 47): an + xcconfig the target or the project names (`baseConfigurationReference`) that is not CocoaPods' generated + `Pods-*.xcconfig` and sets a setting rn-xtool reads (`HEADER_SEARCH_PATHS`, `GCC_PREPROCESSOR_DEFINITIONS`, + `CLANG_CXX_LANGUAGE_STANDARD`, `SWIFT_OBJC_BRIDGING_HEADER`, `PRODUCT_MODULE_NAME`, `CODE_SIGN_ENTITLEMENTS`, + `INFOPLIST_FILE`) gives `⚠ sets for the app target; rn-xtool does not read xcconfig files`; a + synchronized folder group in the app target is refused, naming the group. 2. **Pass 2, in the precheck step** (below): the include list the manifest has just been given, plus the dependency - products' header folders, from the one include-list function B2 uses. A missing include is an error (F3) when it is - a quote include or its first path component names no target of the package graph; otherwise it is a `⚠` and B2 - decides (R6, row 37). + products' header folders, from the one include-list function B2 uses, in the order of the compile that reads each + file: B2's line for a C-family file of the target names the graph's folders first, the bridging header's (Swift's + clang importer) the target's own first, so a header two folders hold is the copy that compile opens. A missing + include is an error (F3) when it is a quote include or its first path component names no target of the package + graph; otherwise it is a `⚠` and B2 decides (R6, row 37). **B2, the precheck.** A new `build` step, `precheck`, after `generate` and before `xtool-build`: @@ -536,17 +551,23 @@ nowhere; one under a condition B1 cannot evaluate is never an error. B1 runs twi 2. **Swift first.** `swiftc -typecheck` on the App's Swift files with `-import-objc-header` and the same `-Xcc` paths, writing `App-Swift.h` into `ios-xtool/.precheck/` (`-emit-objc-header-path`) for the next hop. When a Swift file imports a module SwiftPM builds from Swift (Expo, `ExpoModulesCore`, any Swift library target), the Swift part is - not checked: one `ℹ` line names the file and the module (row 43). + not checked: one `ℹ` line names the file and the module (row 43). A module counts as one SwiftPM builds from Swift + when its target has a Swift source, even when the graph also has a clang module map for it (a mixed target). 3. **C-family next.** `clang -fsyntax-only` on each `.m`, `.mm`, `.c`, `.cc`, `.cpp` of the App, in parallel, with - `nice`. A file that imports `App-Swift.h` is checked only when hop 2 wrote it. + `nice`. A file that imports `App-Swift.h` is checked only when hop 2 wrote it. A file whose reach `@import`s a + module SwiftPM builds from Swift, or one no map declares, is not compiled: one `ℹ` line per module (row 43b). 4. **Report.** An error stops the build before `xtool-build`: `✖ precheck — :: ` with clang's include stack (F4's error is in a React Native header; the cause is the app's flags), the first ten errors, and the log file's path. Warnings are not printed: `xtool-build` prints them once. 5. **Manifest planning** (R6, row 54): `swift package describe --type json` in `ios-xtool/`, which plans the package without compiling, runs first and reports F1-like refusals (an executable App target, an invalid header layout). -6. **The exit** (R2, row 39): `rn-xtool build --skip-precheck` skips hops 2–5 with - `⚠ precheck skipped (--skip-precheck): errors in the app's own sources show in xtool-build`, and `doctor --report` - says the last build skipped it. B1 pass 1 still runs. +6. **The exit** (R2, row 39): `rn-xtool build --skip-precheck` skips hops 2–5 with `⚠ precheck skipped + (--skip-precheck): errors in the app's own sources show in xtool-build`, and `doctor --report` says the last build + skipped it. B1 pass 1's stop names this exit (`; if xtool-build builds them, build with rn-xtool build + --skip-precheck and report it with rn-xtool doctor --report`). With the flag B1 pass 1 still runs, but does not + stop: each of its `✖` lines is printed as a `⚠` line with the same text, then `⚠ include(s) of the app's own + sources resolve nowhere (listed above); checked by xtool-build (--skip-precheck)`, and the build goes on to + `xtool-build` (`run --skip-precheck` passes the flag to `build`). `doctor --project` keeps them `✖`. Both B1 and B2 run on bare projects and on an Expo project's bridging header ([library compatibility](2026-11-04-library-compat-design.md), goal 3.6); an Expo project's `AppDelegate.swift` imports `Expo` @@ -752,10 +773,11 @@ USB, the disk, GitHub's mention parser, npm and the drift watch's runners. | 27 | A, reduced reader in use | the JavaScript evaluator's known limits remain on a machine without Ruby | user: the fixed `⚠` line on every build | accept: the line is the decision; C and the class checks run whatever the reader | | 28 | A, model fields | the regex path's internal fields (`__unresolved__`, `__header_dir_scopes__`) are absent from the shim's JSON | nobody: the consumer derives them from the layers | handle: the sweep compares the two models field by field | | 29 | A, rn-xtool's other readers | the early checks and the resource reader keep their TypeScript line readers, which may disagree with the shim (a dependency under a Ruby condition) | user: an early refusal for a pod the scaffold does not use, or none for one it does | defer to alpha.9, "one podspec model for every reader" (R5); the sweep lists the disagreements meanwhile | -| 30 | B1 pass 1 | an app-own quote include resolves nowhere (F2) | user in `doctor --project` and seconds after `build` starts: `✖ : imports "AppDelegate.h", which is not in ` | handle: fixture of the root-group layout | +| 30 | B1 pass 1 | an app-own quote include resolves nowhere (F2) | user in `doctor --project` and seconds after `build` starts: `✖ : imports "AppDelegate.h", which is not ` (the files the target lists next to the including file, the app target's headers, the search paths: never a folder on disk that may hold the file), then ` include(s) of the app's own sources resolve nowhere (listed above): the build would stop compiling them; if xtool-build builds them, build with rn-xtool build --skip-precheck and report it with rn-xtool doctor --report` | handle: fixture of the root-group layout | | 31 | B1, header map | a quote include of an app header that lives in another folder | nobody: resolved by name, as Xcode's header map and the forwards do | handle: test with headers at the root of the group tree and in the app folder | | 32 | B1 pass 1, before staging | an angle include into React Native's or a library's headers cannot be checked yet | user in doctor: one `ℹ` with the count, "checked at build" | handle | | 33 | B1, conditions | `__has_include` chains (codegen's `RCTAppDependencyProvider.h` shape), `#ifdef RCT_NEW_ARCH_ENABLED`, `#if TARGET_OS_OSX` | nobody for a branch not taken; a condition B1 cannot evaluate never makes an error | handle: tests per form | +| 33b | B1, defines | a condition on a macro the generated App target does not define (`RCT_NEW_ARCH_ENABLED`) | nobody; the include is uncertain and the compile decides | handle: B1 assumes only the compile's defines (this wave) | | 34 | B1, text forms | an include in a comment or under `#if 0`; an include built from a macro | nobody | handle (comments, `#if 0`); accept (macro includes are not checked; B2 compiles them) | | 35 | B1, `@import` | a module B1 cannot place | nobody in B1; B2 compiles it | handle: B1 never errors on `@import` | | 36 | B1, generated headers | `App-Swift.h`, `-Swift.h` | nobody | accept: the build generates them; B2's hop 2 writes the App's | @@ -763,15 +785,19 @@ USB, the disk, GitHub's mention parser, npm and the drift watch's runners. | 38 | B1, where it runs | `doctor --project` and the drift watch have no toolchain | nobody | handle: B1 is TypeScript over files only (fact 18) | | 39 | B2, command lines | rn-xtool's flags differ from Swift Build's and the precheck stops a file that `xtool-build` compiles | user: a false stop, whose text names `--skip-precheck` | handle: a golden test against the App target's response files of the bare 0.85–0.88 references, the Objective-C fixture and an Expo 58 app with a bridging header, captured on the owner's machine one build at a time and normalised (home folders become `/home/me`) before they enter `tests/fixtures/` (R12); `rn-xtool build --skip-precheck` skips it, printed with `⚠` and recorded in `doctor --report` (R2) | | 40 | B2, false pass | the flags differ the other way | user at `xtool-build`, as today | accept | +| 40b | B2, toolchain drift | a newer Swift Build passes other defines, language mode or search paths than the capture of 2026-11-09 (swiftly 6.4.1) | user: false stops naming `--skip-precheck` until rn-xtool updates | defer: drift watch task (alpha.9): after a successful `xtool-build`, read the App compile argv from the task store, as the response-file capture did, and compare it with the precheck's (`compareFlags`); `⚠` on drift | | 41 | B2, toolchain | `clang`, `swiftc` or the iPhoneOS SDK cannot be found | user: a stop naming the tool and `rn-xtool setup` | handle; doctor already fails on `swift` and `darwin-sdk` | | 42 | B2, module cache | a stale cache after a React Native or toolchain change ("module file out of date") | user: a stop, or nothing after the retry | handle: the cache is keyed by React Native version and toolchain; one retry without it; `--clean` removes it | -| 43 | B2, Swift modules | a Swift file imports a module SwiftPM builds from Swift (Expo, `ExpoModulesCore`) | user: `ℹ precheck — imports , which SwiftPM builds: checked by xtool-build` | accept: an Expo app's `AppDelegate.swift` is never prechecked; handle the line | +| 43 | B2, Swift modules | a Swift file imports a module whose target SwiftPM builds from Swift (Expo, `ExpoModulesCore`, a mixed target), or one no map of the graph declares and the SDK has as no framework or Swift module (`CommonCrypto`) | user: `ℹ precheck — imports , which SwiftPM builds: checked by xtool-build` (`which no module map of the package graph declares` for a module of the second kind; through the bridging header: the line names it) | accept: an Expo app's `AppDelegate.swift` is never prechecked; handle the line: a module is known to Swift only when the graph's maps declare it and its target has no Swift sources, or the SDK has it | +| 43b | B2, C-family `@import` | a C-family file, or the bridging header through its includes, `@import`s a module whose target SwiftPM builds from Swift, or one no map declares | user: `ℹ precheck — imports the module , which SwiftPM builds; checked by xtool-build` (`which no module map of the package graph declares` for such a module, an SDK one like `CommonCrypto` included), one line per module; the log lists every such file | handle (this wave): the file is not compiled, nor are the Swift files when it is the bridging header; B1 never errors on `@import` (row 35) | | 44 | B2, clang modules | Swift imports a clang target without a module map on disk (`ReactAppDependencyProvider`, `ReactCodegen`; SwiftPM synthesises theirs at build) | nobody: synthesised by SwiftPM's rule into `.precheck/`, or the file skipped with `ℹ` | handle: never an error; the builder picks synthesis or skip | | 45 | B2, `App-Swift.h` | an Objective-C file imports the App's Swift header and hop 2 did not write it | user: one `ℹ` naming the files not checked | handle | | 46 | B, target shape: xcconfig | `HEADER_SEARCH_PATHS`, defines, the C++ standard or another setting rn-xtool reads come from an xcconfig (`baseConfigurationReference`); the manifest lacks them, and B mirrors the manifest, so the errors look like rn-xtool's | user: `⚠ sets HEADER_SEARCH_PATHS, … for the app target; rn-xtool does not read xcconfig files` at doctor and build start | handle (R6): the `⚠` only, and only for an xcconfig that is not CocoaPods' generated `Pods-*.xcconfig` and sets a setting rn-xtool reads; reading xcconfigs is a later block | | 47 | B, target shape: synchronized folders | an Xcode 16 synchronized folder group holds the app's sources; nothing is in the Sources phase | user: a refusal at doctor and build start naming the group | handle (R6): the refusal; reading such groups is a later block | | 48 | B, per-file flags | the app target's per-file `COMPILER_FLAGS` (`-fno-objc-arc`) are not read | user at precheck or `xtool-build`, the same way | accept: the trial's ruling; B2 uses the manifest's flags | | 49 | B2, time | the first precheck builds React Native's clang modules into its cache | user: a slower first build | accept: measured in the proof; parallel and `nice` | +| 49b | B2, memory | `availableParallelism()` niced clangs on a cold cache exhaust memory; a killed clang reads `compiler exited 137 without a diagnostic` | user: a stop naming `--skip-precheck` | accept: troubleshooting says, present tense, that exit code 137 means the system stopped the compiler, usually for memory | +| 49c | B2, disk | the disk fills during the precheck (`ENOSPC`) | user: a stop naming `--skip-precheck` (every stop of the step but a missing toolchain names it); the terminal and the stop never lose a line, and `ios-xtool/.precheck/precheck.log` may miss the lines after a failed write | accept | | 50 | B2, location | the error is in a library header (F4: `hash_combine.h`) while the cause is the app's flags | user: clang's include stack, starting at the app's file | handle | | 51 | B2, warnings | the app's warnings | user at `xtool-build`, once | accept: the precheck prints errors only | | 52 | B2, beyond syntax | a file passes `-fsyntax-only` and fails at code generation or link | user at `xtool-build`, as today | accept | diff --git a/docs/how-it-works.md b/docs/how-it-works.md index abe60d1..0208bde 100644 --- a/docs/how-it-works.md +++ b/docs/how-it-works.md @@ -97,9 +97,38 @@ scaffolded libraries, CocoaPods binaries); [recipe.md](recipe.md) has every step - the resource bundles of the CocoaPods binaries and of scaffolded libraries, under `Resources/`, and, with CocoaPods binaries, their link flags on the App target ([CocoaPods binaries](#cocoapods-binaries)). 6. Gives CocoaPods-only libraries a `Package.swift` (see [below](#cocoapods-only-libraries)). -7. `xtool` builds, signs and installs the app; Metro serves JS to the phone over Wi‑Fi. With CocoaPods binaries, +7. The `precheck` step checks the app's own sources before `xtool-build` compiles them. SwiftPM plans the generated + package (`swift package describe`), and rn-xtool reads the header folders and module maps of its dependency graph; + the app's includes are resolved again with the App target's full include list; `swiftc -typecheck` checks the Swift + files, and `clang -fsyntax-only` each C-family file with the generated manifest's flags, as many at a time as the + machine has cores. When a Swift file imports a module SwiftPM builds from Swift (a Swift module such as `Expo`, or + a library target that holds Swift files next to its Objective-C), the Swift files are left to `xtool-build`, and so + is a C-family file that `@import`s such a module or one no module map of the package graph declares (an SDK module + such as CommonCrypto is left to xtool-build too): on Expo the app's Swift files import such a module (`Expo`, or + `ExpoModulesCore` in the generated `ExpoModulesProvider.swift`), so they are always checked there. On errors it prints each include that + resolves nowhere and the compilers' first ten errors, with their include stacks, and stops the build; every command + line and all compiler output go to `ios-xtool/.precheck/precheck.log` (after a write to it fails, on a full disk, + the log may miss the lines that follow; the terminal does not). clang's module cache stays under + `ios-xtool/.precheck/` between builds; the first precheck, and the first after `--clean` empties the cache, is slower + while clang builds React Native's modules. A precheck that passes does not promise that `xtool-build` does: it + checks syntax and includes with Swift Build's flags, and code generation and link errors still show in + `xtool-build`. `--skip-precheck` on `build` and `run` leaves the step out + ([troubleshooting.md](troubleshooting.md#precheck)). +8. `xtool` builds, signs and installs the app; Metro serves JS to the phone over Wi‑Fi. With CocoaPods binaries, rn-xtool checks the packed `App.app` before anything installs it. +The app's own includes are also checked earlier, with file reads only (pass 1): before the `patches` step (on Expo, once +`expo prebuild` has written `ios/`), rn-xtool resolves the `#import` and `#include` lines of the app target's own files +as the generated App target compiles them, and a quote include of one of the app's own headers that resolves nowhere +stops the build seconds after it starts (with `--skip-precheck`, a `⚠` line that does not stop it). It reads `#if` and +`#ifdef` with the macros the App compile defines: `SWIFT_PACKAGE`, `DEBUG=1`, the target's own +`GCC_PREPROCESSOR_DEFINITIONS` and the iOS values of `TARGET_OS_*`. The generated App target does not define +`RCT_NEW_ARCH_ENABLED`, so an include under a condition on it, or on any other macro, is left to the compile. In a +project with CocoaPods binaries, whose headers pass 1 cannot see, it never stops: every miss is left to the `precheck` +step. On Expo the one app file it reads is the bridging header. `doctor --project` runs the same check as its +`app-includes` line, on a machine without a toolchain too. Includes into React Native's or the libraries' headers are +left to the `precheck` step. + Bare React Native projects follow the same steps with a few differences (no `expo prebuild`, no injection into your Xcode project, ExpoModulesJSI only with Expo modules): see [bare-react-native.md](bare-react-native.md). @@ -614,6 +643,11 @@ is about 99 MB with 8 embedded frameworks. A bare React Native 0.85.0 app with 20 native libraries, its scaffolds made again (2026-11-06): `rn-spm` 578 s, `frameworks` 35 s, `xtool-build` 273 s. +The `precheck` step (2026-11-10, two series on a loaded machine), with the module cache cold (`build --clean`) and then +warm (the next `build`): a bare React Native 0.88.1 app 8.6–11.1 s and 1.8–2.9 s, the Expo SDK 58 app 7.7–7.8 s and +3.3–6.7 s (its Swift files are left to `xtool-build`; most of the warm time is SwiftPM planning the package), the Expo +SDK 57 app 3.0 s and 0.6 s, an Objective-C 0.88.1 app 6.9 s cold. + ## Further reading - [recipe.md](recipe.md): the full technical recipe, with file locations. diff --git a/docs/troubleshooting.md b/docs/troubleshooting.md index 80bbbf6..56dc370 100644 --- a/docs/troubleshooting.md +++ b/docs/troubleshooting.md @@ -973,6 +973,166 @@ an `ios/build/pod-binaries` from an earlier build stays on disk, unused ([Leavin read-only, often after `sudo npm install`. Make it writable (reinstall without `sudo`), or apply the portable manifest yourself. +### Precheck + +`build` checks the app target's own sources twice before `xtool-build` compiles them. Pass 1 runs before the `patches` +step (on Expo, once `expo prebuild` has written `ios/`), and in `doctor --project`, with file reads only: it resolves +the `#import` and `#include` lines of the app target's C-family sources, headers and bridging header (on Expo, the +bridging header alone) as the generated App target compiles them; with `--skip-precheck` it prints its misses as `⚠` +lines and does not stop. The `precheck` step, between `generate` and `xtool-build`, has SwiftPM plan the generated +package, reads the header folders and module maps of its dependency graph, resolves the includes again with the App +target's full include list (pass 2), and runs `swiftc -typecheck` over the Swift files and `clang -fsyntax-only` over +each C-family file with the generated manifest's flags. Every command line and all compiler output go to +`ios-xtool/.precheck/precheck.log`, which each precheck writes anew. clang's module cache is +`ios-xtool/.precheck/ModuleCache`, kept for one React Native version and toolchain at a time; `build --clean` (and `run +--clean`) empties it. The first precheck of a project, and the first after the cache is emptied, is slower than the next +ones while clang builds React Native's modules into the cache; the compilers run at low priority (`nice`), as many at a +time as the machine has cores. A precheck that passes does not promise that `xtool-build` does: it checks syntax and +includes with Swift Build's flags, and code generation and link errors still show in `xtool-build`. + +- **"✖ ios//AppDelegate.mm:3 imports "AppDelegate.h", which is not among the files the app target lists next + to ios//AppDelegate.mm, in the app target's headers or in
"**, followed by "✖ + include(s) of the app's own sources resolve nowhere (listed above): the build would stop compiling them; if + xtool-build builds them, build with rn-xtool build --skip-precheck and report it with rn-xtool doctor --report": pass 1 + found a quote include of one of the app's own headers (a header the app target references, or a file anywhere under + `ios/`, case ignored, whose path ends with the spelling: for `"Shared/Utils.h"`, a `Shared/Utils.h`, not a `Utils.h` + in another folder) in none of the places clang searches in the app target's copy, in the order the line names them: + the files the target lists next to the including file, the app target's headers (the forwards in + `Sources/App/include`) and `HEADER_SEARCH_PATHS`. On Expo the first place reads "among the files rn-xtool copies + next to ". `doctor --project` prints the same line as `✖ app-includes — …` + and exits non-zero. The line ends with what `ios/` holds of that name: + - `; differs only in case (file names are case-sensitive on Linux)`: a Mac finds the file, Linux does not. + Rename the file, or change the include, so both spell the name the same way. + - `; exists but the app target does not list it (add it to the target)`: rn-xtool copies only the files the + Xcode project references. Add the header to the Xcode project; any group outside `Pods/` works + ([Sources](bare-react-native.md#sources)). + - `; exists, but rn-xtool copies only the bridging header of an Expo app`: on Expo, the bridging header is + the one file of `ios/` the App target compiles, so a header beside it is not there. Move what the bridging header + needs from that header into the bridging header itself. + - nothing: no file of that name is under `ios/` (outside `Pods/`, `build/`, `DerivedData/` and `ios-xtool/`). Restore + the header, or fix the include. + + An absolute spelling that does not exist reads `: imports "", which does not exist`. Pass 1 + stops on these only. An angle include (`#import `), a quote include of a header that is not the + app's (the SDK's, a library's) and every miss in a project with CocoaPods binaries are left to the `precheck` step; + `doctor --project` counts them in `ℹ app-includes — includes into React Native's or the libraries' headers: + checked at build`. When a miss is not real (Xcode, or `xtool-build`, finds the header), `rn-xtool build + --skip-precheck` (or `run --skip-precheck`) prints each of these lines with `⚠` instead, then "⚠ include(s) of + the app's own sources resolve nowhere (listed above); checked by xtool-build (--skip-precheck)", and the build goes + on; report it with `rn-xtool doctor --report`. `doctor --project` still prints them as `✖`. +- **"⚠ sets for the app target; rn-xtool does not read xcconfig files"** (`⚠ app-target — …` in + `doctor --project`): the Debug configuration of the app target or of the project is based on an `.xcconfig`, other + than CocoaPods' `Pods-*.xcconfig`, that sets, itself or through its `#include` lines, one of the settings rn-xtool + reads from the pbxproj: `HEADER_SEARCH_PATHS`, `GCC_PREPROCESSOR_DEFINITIONS`, `CLANG_CXX_LANGUAGE_STANDARD`, + `SWIFT_OBJC_BRIDGING_HEADER`, `PRODUCT_MODULE_NAME`, `CODE_SIGN_ENTITLEMENTS` and `INFOPLIST_FILE`. The build goes on + with the pbxproj's values only, so a header found only through the xcconfig's search paths is missing for pass 1, + the precheck and `xtool-build` alike. Set the values the app needs in the target's build settings (in Xcode, or in + the pbxproj). + `⚠ (the app target's base configuration) could not be read; rn-xtool does not read xcconfig files` is the + same line for a base configuration, or a file it includes, that is missing or unreadable. +- **"The app target takes its files from the synchronized folder (an Xcode 16 folder group); rn-xtool + reads only the files a target lists. Convert the folder to a group (Xcode: Convert to Group) so the target lists its + files"** (bare React Native): `build` stops before its first step, and `doctor --project` fails its `project` line. + A synchronized folder gives the target every file in it without listing them in the pbxproj. Do what the line says: + in Xcode, choose Convert to Group on the folder, which lists each file in the target, then build again. +- **"✖ precheck — : imports , which is in none of the App target's include folders (listed in + ios-xtool/.precheck/precheck.log)"**: pass 2 looked for the header in the App target's include folders, the SDK, + clang's own headers and the frameworks, and found it in none. The include is not behind a condition the precheck + cannot evaluate, and its file is one the compile surely reads; an angle include stops only when its first path + component names no target of the package. The log lists the folders in order, per compile: a C-family file of the + app searches the libraries' header folders before the app target's own, as Swift Build orders them, and the bridging + header the app target's own first, as Swift's clang importer does, so a header both hold is the copy that compile + opens. Fix the include or the header search path, or install the library that ships the header. The other misses + are `⚠` lines, and the build goes on; `xtool-build` decides them: + - `⚠ precheck — : imports , which nothing compiles; checked by xtool-build if it is ever + included`: the include is in a header of the app that no compiled file includes. + - `⚠ precheck — : imports , which only a condition the precheck cannot evaluate includes; the + compile decides`: the file is reached only through an `#if __has_include(…)`, `#ifdef` or similar branch. + - `⚠ precheck — : imports , which rn-xtool did not find; is a target of the package, so + the compile decides`: an angle include whose first component is a target or product of the package graph + (``). + - `⚠ precheck — : imports , which rn-xtool did not find; the compile decides`: clang's own + header folder was not found, so an angle include cannot be judged. +- **"✖ precheck — :: "**, each followed by its include stack (`In file included from + ::` and clang's `While building module '' imported from ::` lines), the first ten, + then `… and more`: a compiler error. A file of the app is named by its source in `ios/`, other files relative to + the project root. An error in your own file is yours to fix. An error in a React Native or library header has a + stack that starts at the app's file that included it, and its cause is usually the app's flags rather than the + header: the C++ standard (`CLANG_CXX_LANGUAGE_STANDARD`; React Native's headers need C++20), a define in + `GCC_PREPROCESSOR_DEFINITIONS`, or a header search path that makes another file of the same name win. Check those + settings in the pbxproj (an `.xcconfig` that sets them prints the `⚠` line above). +- **"✖ precheck — : compiler exited without a diagnostic rn-xtool could read"**, followed by the + compiler's last 20 lines: the compiler failed without an error line rn-xtool reads. Those lines, and the whole + output in the log, say why. Exit code 137 means the system stopped the compiler, usually because memory ran out: the + precheck runs as many compilers as the machine has cores, and the first one, with a cold module cache, needs the + most. Close other programs and build again; the stop names `--skip-precheck` for a build without the step. +- An error in a header that several files include is printed and counted once, with the include stack of the first + file that reported it. +- **"✖ precheck: error(s) in the app's own sources before xtool-build (the first ten are above; all of them in + ios-xtool/.precheck/precheck.log). If xtool-build compiles these files, this is a false stop: build with rn-xtool + build --skip-precheck and report it with rn-xtool doctor --report"**: the stop after the lines above. Fix the errors + and build again. When the errors are not real (Xcode compiles these files, or `xtool-build` does once the step is + left out), the stop is false: `rn-xtool build --skip-precheck` builds without the step, then `rn-xtool install` and + `rn-xtool start` run the app; `rn-xtool run --skip-precheck` does all three. Every build without the flag runs the + precheck again; once the app is installed, `rn-xtool run` skips the build while nothing changed. Report the false + stop with the block of `rn-xtool doctor --report` and the stop's lines ([Reporting a problem](#reporting-a-problem)). +- **"⚠ precheck skipped (--skip-precheck): errors in the app's own sources show in xtool-build"**: printed right after + `generate` by a build with `--skip-precheck`, which still runs pass 1 (its misses as `⚠` lines). `rn-xtool doctor + --report` then reads `precheck: skipped with --skip-precheck (last build)`; after a build that ran the step, stopped + or not, it reads `precheck: run (last build)`, and before any build of this release reached `generate`, `precheck: + not recorded`. +- **"ℹ precheck — imports , which SwiftPM builds: checked by xtool-build"**: a Swift file imports a + module that exists only once SwiftPM builds it (a Swift library, or a library target with Swift files next to its + Objective-C, whose clang half alone the precheck could give `swiftc`), or the bridging header `@import`s one (the + line then names the bridging header). For a module no map of the graph declares and the SDK has as no framework or + Swift module, such as the SDK's `CommonCrypto`, the line reads `which no module map of the package graph declares` + instead. Either way `swiftc -typecheck` does not run and the Swift files are left to `xtool-build`. On Expo it is the usual line once Swift Build has written its module maps: the app's + `AppDelegate.swift` imports `Expo`, or the generated `ExpoModulesProvider.swift` imports `ExpoModulesCore`. The + C-family files are still checked. Nothing to do. +- **"ℹ precheck — imports the module , which SwiftPM builds; checked by xtool-build"** (or `…, which no + module map of the package graph declares; …`): a C-family file, or a header it includes, has `@import M;` for a + module SwiftPM builds from Swift, or for one no module map of the package graph declares (an SDK module such as + `CommonCrypto` is left to `xtool-build` too), so the precheck cannot give clang the module as `xtool-build` does. That file is not compiled (nor the Swift files, + when it is the bridging header); the line names the first such file, and `ios-xtool/.precheck/precheck.log` lists + them all. The other C-family files are still checked. Nothing to do. +- **"ℹ precheck — import
, which the Swift check did not write: checked by xtool-build"**: these files + import a `-Swift.h` header (Xcode's generated Swift header) that the Swift check did not write, because it did not + run or the header is another module's, so they are left to `xtool-build`. Nothing to do. +- **"ℹ precheck — module maps Swift Build writes are not there yet: files that need them are checked by + xtool-build"** (or `…: are checked by xtool-build`): on Expo, Swift Build writes the module maps of Expo's + Swift importers during `xtool-build`, so the files that `@import` or import those modules are left to it. Nothing + to do. +- **"ℹ precheck — dependencies of App could not be placed (): checked by xtool-build"**: the precheck could + not match these dependencies of the App target to a package SwiftPM listed, so their headers are not in its include + list and `xtool-build` checks what needs them. +- **"ℹ precheck — the module cache was stale (); checked again without it"**: clang found a module in the + cache out of date, for example after a library changed; the precheck removed the cache and ran once more, at the + speed of a first precheck. Nothing to do. +- **"✖ precheck — clang was not found on the Swift toolchain's PATH; run rn-xtool setup"** (or `swiftc`), + **"✖ precheck — the iPhoneOS SDK was not found in the Darwin SDK (); run rn-xtool setup --xcode-xip "** + and **"✖ precheck — the Swift resources were not found in the Darwin SDK (); run rn-xtool setup --xcode-xip + "**: the toolchain or the Darwin SDK is incomplete. Do what the line says, then check with `rn-xtool doctor`. +- **"✖ precheck — SwiftPM refused the generated package (ios-xtool/Package.swift):"**, followed by SwiftPM's error + lines, and its siblings `SwiftPM gave no plan for the generated package (ios-xtool/Package.swift)`, `SwiftPM's plan + of the generated package (ios-xtool/Package.swift) has no App target`, `SwiftPM could not list the dependencies of + the generated package (ios-xtool/Package.swift)` and `SwiftPM could not read the package ()`: SwiftPM + cannot plan the package `xtool-build` builds. SwiftPM's lines after the first say why; `` is the folder of the + package it could not read. +- **"✖ precheck — SwiftPM plans the App target as an executable target (a file named main); xtool links the app's + entry point from the App library"**: a file of the App target is named `main`. See + [Sources](bare-react-native.md#sources) for how rn-xtool copies a C-family `main` file and what to do with a + `main.swift`. +- **"✖ precheck — rn-xtool could not read the xcframework (): "**: a binary target of the package + is an xcframework whose `Info.plist` is missing or cannot be parsed, so the precheck cannot find its headers. + Rebuild or reinstall the library that ships it. +- **"…; if xtool-build builds this app, build with rn-xtool build --skip-precheck and report it with rn-xtool doctor + --report"**: the end of every precheck stop other than the compilers' errors and a missing toolchain: the SwiftPM + and xcframework lines above, and anything else that stops the step (a full disk, `ENOSPC`, or an error in rn-xtool + itself). The first part says what failed; `ios-xtool/.precheck/precheck.log` ends with it on a `# stopped:` line. + After a write to the log fails (a full disk), the log may miss the lines that follow, that `# stopped:` line among + them; the terminal and the stop lose none. + When `xtool-build` builds the app without the step, the stop is false: build with `--skip-precheck` and report it. + ### Podspec reader The `rn-spm` step reads each library's podspec with the system `ruby`, through a shim of CocoaPods' DSL and React @@ -1502,6 +1662,17 @@ checks, so it also runs on a machine without Swift or xtool. Run it from the pro installed; skipped. Delete it if you removed the library.` ([details](#build-and-patches)), and one per pod a persisted scaffold pins at another version than the pod table (`patches/ pins AppAuth 3.0.0, the config says 3.1.0; delete it so rn-xtool regenerates it …`) or does not pin although the library's podspec maps it. +- **app-includes**: pass 1 of the [precheck](#precheck) over the app target's own sources, as `build` runs it before + the `patches` step: `✖ app-includes — : imports "", which is not …` for each include of one + of the app's own headers that resolves nowhere (the line `build` stops on), + `ℹ app-includes — includes into React Native's or the libraries' headers: checked at build` for the includes + left to the `precheck` step, and `✔ app-includes — includes of the app's own sources resolve` when there is no + ✖ line and an include was checked. On Expo it reads the bridging header alone, and prints nothing before + `expo prebuild` wrote `ios/`. A ✖ line also carries an error of the check itself, such as an Expo bridging header + that is missing. +- **app-target**: one ⚠ line per `.xcconfig` that sets a setting rn-xtool reads from the pbxproj, the `build` line + without its `⚠`, for example `⚠ app-target — ios/Config/App.xcconfig sets HEADER_SEARCH_PATHS for the app target; + rn-xtool does not read xcconfig files` ([details](#precheck)). - **known-limits**: the setups rn-xtool refuses before a build ([Unsupported setups](#unsupported-setups)). With none, it reads `none of the setups rn-xtool refuses early (CocoaPods-only libraries with prebuilt binaries, vendored C sources or CocoaPods pods without a SwiftPM package, pnpm, Yarn PnP, hoisted packages)`. Otherwise there is one ✖ line diff --git a/src/cli.ts b/src/cli.ts index 58b582a..b51b883 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -68,9 +68,10 @@ export function buildProgram(): Command { .command("build") .description("Prebuild if needed (Expo), run the SwiftPM pipeline and build with xtool") .option("--clean", "re-run expo prebuild --clean (Expo) or remove ios/build and ios-xtool (bare)") + .option("--skip-precheck", "skip the check of the app's own sources before xtool-build") .action( - action(async (o: { clean?: boolean }) => { - await build(process.cwd(), { clean: o.clean }); + action(async (o: { clean?: boolean; skipPrecheck?: boolean }) => { + await build(process.cwd(), { clean: o.clean, skipPrecheck: o.skipPrecheck }); }), ); program @@ -90,9 +91,17 @@ export function buildProgram(): Command { .option("--network [ip]", "install over Wi‑Fi (see install --network)") .option("--udid ", "which paired iPhone to use over Wi‑Fi") .option("--pair-record ", "pair record to use over Wi‑Fi") + .option("--skip-precheck", "skip the check of the app's own sources before xtool-build") .action( action( - async (o: { clean?: boolean; force?: boolean; network?: boolean | string; udid?: string; pairRecord?: string }) => { + async (o: { + clean?: boolean; + force?: boolean; + network?: boolean | string; + udid?: string; + pairRecord?: string; + skipPrecheck?: boolean; + }) => { if (!o.network && (o.udid || o.pairRecord)) throw new Error("--udid and --pair-record need --network"); await run(process.cwd(), o); }, diff --git a/src/commands/build.ts b/src/commands/build.ts index e5b29e2..b241a13 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -4,10 +4,11 @@ import { join, relative } from "node:path"; import { depsFingerprint } from "../deps.js"; import { configFileOf, loadConfig, type ExpoXtoolConfig, type PodEntry } from "../config.js"; import { readFlavoredFrameworks, stageFrameworks, type RuntimeFramework } from "../frameworks.js"; -import { hasDevSupport, writeIosXtool } from "../generate/iosXtool.js"; +import { hasDevSupport, writeIosXtool, type GeneratedApp } from "../generate/iosXtool.js"; import { detectLanIp, detectLanRoute, findFreePort, isMetroRunning, isPortFree, suspiciousLanRoute, tunnelWarning, type LanRoute } from "../net.js"; import { projectPaths, type ProjectPaths } from "../paths.js"; import { generateAppConfig } from "../pipeline/appConfig.js"; +import { runPrecheck, type PrecheckOptions } from "../pipeline/precheck.js"; import { buildExpoModulesJsi, jsiRnHeaderDirs, type JsiRnHeaders } from "../pipeline/jsi.js"; import { fixLibraryManifests } from "../pipeline/manifests.js"; import { applyPatches } from "../pipeline/patches.js"; @@ -37,6 +38,7 @@ import { type EarlyFailure, type LibraryCheckOptions, } from "../project/earlyChecks.js"; +import { appTargetCheck } from "../project/appIncludes.js"; import { entitlementLines, readEntitlements, type AppEntitlements } from "../project/entitlements.js"; import { mergedPodTable, type PodBinary, type PodTable } from "../project/podTable.js"; import { @@ -67,6 +69,7 @@ export const BUILD_STEP_NAMES = [ "app-config", "frameworks", "generate", + "precheck", "xtool-build", ] as const; @@ -84,6 +87,8 @@ export interface BuildPlanInput { expoPlugin: ExpoPlugin; /** Binary CocoaPods pods to resolve: `pods` first, `pod-binaries` right before rn-spm. */ pods?: boolean; + /** The check of the app's own sources before xtool-build; `false` (`--skip-precheck`) leaves it out. */ + precheck?: boolean; } /** Whether `installed` is xtool's signed form of `bundleIdentifier`: XTL-., exactly. */ @@ -107,6 +112,10 @@ export function buildSteps(state: BuildPlanInput): string[] { } function plainSteps(state: BuildPlanInput): string[] { + return kindSteps(state).filter((s) => s !== "precheck" || state.precheck !== false); +} + +function kindSteps(state: BuildPlanInput): string[] { if (state.kind === "expo") { const vendored = state.expoPlugin === "vendored"; const steps: string[] = BUILD_STEP_NAMES.filter( @@ -228,6 +237,10 @@ export interface BuildDeps { codegenClasses: (root: string, appBundle: string) => Promise; /** The app's CODE_SIGN_ENTITLEMENTS file (Debug); throws an EntitlementsError when xtool could not sign with it. */ readEntitlements: (project: ProjectInfo, iosDir: string) => AppEntitlements | undefined; + /** B1 pass 1: the app's own includes that resolve nowhere, and the xcconfig warnings (bare before any step, Expo after prebuild). */ + appTargetCheck: typeof appTargetCheck; + /** B1 pass 2: compiles the generated App target's own sources; a `PrecheckError` stops the build before xtool-build. */ + precheck: (paths: ProjectPaths, app: GeneratedApp, opts: PrecheckOptions) => Promise; log: (s: string) => void; } @@ -275,6 +288,8 @@ const realDeps: BuildDeps = { return emptyTargetsOf(table, [...scaffoldedPods(root, table, opts).values()].flat()); }, readEntitlements, + appTargetCheck, + precheck: (paths, app, opts) => runPrecheck(paths, app, opts), log: (s) => console.log(s), }; @@ -365,11 +380,12 @@ export async function restagePods( export async function build( root: string, - opts: { clean?: boolean }, + opts: { clean?: boolean; skipPrecheck?: boolean }, overrides: Partial = {}, ): Promise { const d: BuildDeps = { ...realDeps, ...overrides }; const clean = opts.clean === true; + const skipPrecheck = opts.skipPrecheck === true; const paths = projectPaths(root); let previousState: BuildState | undefined; try { @@ -428,8 +444,30 @@ export async function build( rnArtifacts: (project.rnScripts === "vendored" || vendoredExpo) && !config.rnArtifactsDir, expoPlugin: project.expoPlugin, pods: podRoots.length > 0, + precheck: !skipPrecheck, }); const planned = (name: string): boolean => steps.includes(name); + // B1 pass 1: an app-own include that resolves nowhere stops the build in seconds, not in xtool-build; with + // --skip-precheck its lines are warnings and xtool-build decides (the state records the skipped precheck). Bare: + // before any step; Expo: once prebuild wrote ios/. + const checkAppTarget = (): void => { + const check = d.appTargetCheck({ root: paths.root, project, binaryPods: podRoots.length > 0 }); + for (const line of check.warnings) d.log(line); + const n = check.errors.length; + if (skipPrecheck) { + for (const error of check.errors) d.log(`⚠ ${error}`); + if (n > 0) d.log(`⚠ ${n} include(s) of the app's own sources resolve nowhere (listed above); checked by xtool-build (--skip-precheck)`); + return; + } + for (const error of check.errors) d.log(`✖ ${error}`); + if (n > 0) { + throw new Error( + `${n} include(s) of the app's own sources resolve nowhere (listed above): the build would stop compiling them; ` + + "if xtool-build builds them, build with rn-xtool build --skip-precheck and report it with rn-xtool doctor --report", + ); + } + }; + if (project.kind === "bare") checkAppTarget(); // Before anything changes in the project: an unreachable host, a changed file or a short disk stops here. const table = mergedPodTable(config.pods); @@ -463,6 +501,7 @@ export async function build( // cannot sign at all. const entitlements = d.readEntitlements(project, paths.ios); if (entitlements !== undefined) for (const line of entitlementLines(entitlements, project.bundleIdentifier)) d.log(line); + if (project.kind === "expo") checkAppTarget(); // The app config icon this prebuild turned into the icon set; without a prebuild, the last one's record stays. // With no record (the user ran expo prebuild, or the state predates it), the current icon is recorded silently, // so a later change warns. @@ -574,9 +613,10 @@ export async function build( }), ...(emptyTargets.length > 0 && { emptyTargets }), ...(postPack !== undefined && { postPack }), + precheck: planned("precheck") ? "run" : "skipped", }; - await step("generate", async () => { - await d.writeIosXtool({ + const app = await step("generate", async () => { + const generated = await d.writeIosXtool({ project, paths, frameworks, @@ -589,7 +629,14 @@ export async function build( ...(resourceBundles.length > 0 ? { resourceBundles } : {}), }); await writeState(paths.iosXtool, state); + return generated; }); + // B1 pass 2: an error in the app's own sources stops here in seconds, not minutes into xtool-build. + if (planned("precheck")) { + await step("precheck", () => d.precheck(paths, app, { root: paths.root, rnVersion: project.rnVersion, clean, log: d.log })); + } else { + d.log("⚠ precheck skipped (--skip-precheck): errors in the app's own sources show in xtool-build"); + } await step("xtool-build", () => d.devBuild(d.xtoolBin(config), paths.iosXtool)); // A failure leaves the state without the fingerprint, so the next run builds again. if (postPack !== undefined) await d.postPack(paths.appBundle, postPack); diff --git a/src/commands/doctor.ts b/src/commands/doctor.ts index 8d8496b..4c5e7ea 100644 --- a/src/commands/doctor.ts +++ b/src/commands/doctor.ts @@ -404,14 +404,15 @@ function knownLimitsChecks(limits: NonNullable): DoctorC /** * `doctor --project`'s capability lines, in order: versions, rn-scripts, rn-artifacts, expo-plugin, expo-modules, - * podspecs, exclude, pods (the binary pods' lines, then the pin lines), patches, known-limits and entitlements. The four in between are left out when the project has no such field + * podspecs, exclude, pods (the binary pods' lines, then the pin lines), patches, app-includes/app-target (the app + * target's lines, `appTargetLines`), known-limits and entitlements. The four in between are left out when the project has no such field * (no react-native, no expo), exclude without the config's `exclude` (one line per entry: info for the modules left * out, warn for a name it ignores), pods unless a pod pin misses a podspec's requirement, patches unless a patch's package is not * installed or a scaffold patch's pod pins are stale (one warning each, the build's line without its `⚠ `), and * known-limits when `limits` is undefined. `projectError` is why the project could not be read; a * `VersionGateError` fails the versions line. */ -/** The status a binary-pod line's mark stands for. */ +/** The status the mark of a binary-pod or app-target line stands for. */ const POD_LINE_STATUS: Record = { "✔": "ok", ℹ: "info", "⚠": "warn", "✖": "fail" }; export function capabilityChecks(c: Capabilities, projectError?: unknown): DoctorCheck[] { @@ -448,6 +449,11 @@ export function capabilityChecks(c: Capabilities, projectError?: unknown): Docto status: "warn" as const, detail: line.replace(/^⚠ /, ""), })), + ...(c.appTarget ?? []).map((line) => { + // `✖ app-includes — …`: the mark gives the status, the name the check. + const [, mark, name, detail] = /^(\S+) (app-includes|app-target) — (.*)$/s.exec(line) ?? []; + return { name: name ?? "app-includes", status: POD_LINE_STATUS[mark ?? ""] ?? ("info" as const), detail: detail ?? line }; + }), ...(c.limits === undefined ? [] : knownLimitsChecks(c.limits)), ...entitlementsChecks(c.entitlements), ]; diff --git a/src/commands/report.ts b/src/commands/report.ts index 3d1aba2..f8a0ac0 100644 --- a/src/commands/report.ts +++ b/src/commands/report.ts @@ -12,6 +12,7 @@ import { DEFAULT_CONFIG, loadConfig, type ExpoXtoolConfig } from "../config.js"; import { projectPaths } from "../paths.js"; import { podspecReportLines, readPodspecReads } from "../pipeline/podspecReads.js"; import { MissingBundleIdentifierError } from "../project/index.js"; +import { readState, type BuildState } from "../state.js"; import { packageRoot } from "../tools/exec.js"; import { doctorWithProbes, realProbes, renderReport, type DoctorProbes, type DoctorReport } from "./doctor.js"; @@ -255,14 +256,22 @@ function projectLine(r: DoctorReport, inProject: boolean): string { return parts.length > 0 ? parts.join(", ") : "unknown (see the project line)"; } +/** Whether the last build ran the check of the app's own sources or skipped it with `--skip-precheck` (R2). */ +export function precheckReportLine(state: BuildState | undefined): string { + if (state?.precheck === "run") return "precheck: run (last build)"; + if (state?.precheck === "skipped") return "precheck: skipped with --skip-precheck (last build)"; + return "precheck: not recorded"; +} + /** * The block, fenced as text, before redaction. `podspecLines` are the last `rn-spm`'s reader and `ENV` names - * (`podspecReportLines`): the report is the only place outside the reads file that names them (R2, R4). + * (`podspecReportLines`): the report is the only place outside the reads file that names them (R2, R4). `precheckLine` is + * `precheckReportLine`'s. */ export function renderIssueReport( r: DoctorReport, env: ReportEnv, - opts: { projectOnly: boolean; nodeVersion: string; inProject: boolean; podspecLines: string[] }, + opts: { projectOnly: boolean; nodeVersion: string; inProject: boolean; podspecLines: string[]; precheckLine: string }, ): string { const detail = (name: string): string => r.checks.find((c) => c.name === name)?.detail ?? "not checked"; const tool = (name: string): string => (opts.projectOnly ? "not checked (--project)" : detail(name)); @@ -276,6 +285,7 @@ export function renderIssueReport( // doctor --project checks Ruby too. `ruby: ${detail("ruby")}`, ...opts.podspecLines, + opts.precheckLine, `os: ${env.os}, ${env.arch}`, `project: ${projectLine(r, opts.inProject)}`, renderReport(r.checks), @@ -341,11 +351,13 @@ export async function doctorReport( // Without a project there is no reads file. const project = inProject ? projectPaths(root ?? process.cwd()) : undefined; const reads = project !== undefined ? readPodspecReads(project.podspecReads) : []; + const state = project !== undefined ? await readState(project.iosXtool).catch(() => undefined) : undefined; const text = renderIssueReport(r, env, { projectOnly, nodeVersion: probes.nodeVersion(), inProject, podspecLines: podspecReportLines(reads, project?.root ?? ""), + precheckLine: precheckReportLine(state), }); return `${redact(text, { home, seen })}\n${REVIEW_LINE}`; }); diff --git a/src/commands/run.ts b/src/commands/run.ts index ba3cae9..2384337 100644 --- a/src/commands/run.ts +++ b/src/commands/run.ts @@ -11,7 +11,7 @@ import { install, type InstallOptions } from "./install.js"; import { start, startDecision } from "./start.js"; export interface RunDeps { - build: (root: string, opts: { clean?: boolean }) => Promise; + build: (root: string, opts: { clean?: boolean; skipPrecheck?: boolean }) => Promise; install: (root: string, opts: InstallOptions) => Promise; start: (root: string, opts: { clear?: boolean }) => Promise; readState: (iosXtoolDir: string) => Promise; @@ -43,7 +43,7 @@ const realDeps: RunDeps = { export async function run( root: string, - opts: { clean?: boolean; force?: boolean } & InstallOptions, + opts: { clean?: boolean; force?: boolean; skipPrecheck?: boolean } & InstallOptions, overrides: Partial = {}, ): Promise { const d: RunDeps = { ...realDeps, ...overrides }; @@ -52,7 +52,7 @@ export async function run( rebuilt = false; d.log("Native app is up to date (nothing changed since the last build); skipping build and install."); } else { - await d.build(root, { clean: opts.clean }); + await d.build(root, { clean: opts.clean, skipPrecheck: opts.skipPrecheck }); // `--network [ip]` (and its --udid / --pair-record) go straight to install. await d.install(root, { network: opts.network, udid: opts.udid, pairRecord: opts.pairRecord }); } diff --git a/src/generate/bareSources.ts b/src/generate/bareSources.ts index 3de48ac..1848183 100644 --- a/src/generate/bareSources.ts +++ b/src/generate/bareSources.ts @@ -10,6 +10,20 @@ export interface CopiedBareTarget { headerSearchPaths: string[]; /** Top-level entries of the staged resources directory (files, `.lproj` and `.bundle` dirs), sorted. */ resources: string[]; + /** Each copied code file's copy path → its source path. */ + origins: Record; +} + +/** Where the copy of a bare app target puts its code; every path relative to Sources/App. */ +export interface BareCopyLayout { + /** One entry per copied code file, in the order Swift sources, C-family sources, headers, bridging header. */ + files: { file: TargetFile; dest: string }[]; + /** A header's base name → the `dest` its `include/` forward imports (the first header of a name wins). */ + forwards: Map; + /** Headers the project references that do not exist: not copied. */ + missingHeaders: TargetFile[]; + /** `-Swift.h` when `include/` holds a forward of that name to `App-Swift.h`. */ + swiftHeaderForward?: string; } const INCLUDE_DIR = "include"; @@ -35,22 +49,19 @@ async function copyListed(file: TargetFile, dest: string): Promise { } /** - * Copies the app target's code into `sourcesDir` (Sources/App), keeping its layout under the - * target folder (`ios//Native/X.m` → `Native/X.m`; files elsewhere in ios/ keep their - * path from ios/), with one forwarding header per header in `include/` so `#import "X.h"` resolves - * from any folder as Xcode's header maps allow, plus `-Swift.h` forwarding to `App-Swift.h` - * in a mixed target. A header the project references that does not exist is skipped with a note. A C-family `main.m` - * (any `main.`) is copied as `AppMain.` in its folder, so SwiftPM keeps App a library target. Resources are - * staged flat in `resourcesDir`, laid out as Xcode copies them to the bundle root (xtool.yml lists each top-level entry). + * Where `copyBareTarget` puts the app target's code under Sources/App: the layout under the target folder + * (`ios//Native/X.m` → `Native/X.m`; files elsewhere in ios/ keep their path from ios/), a C-family `main.m` + * (any `main.`) as `AppMain.` in its folder, one `include/` forward per header name, as Xcode's header maps + * allow `#import "X.h"` from any folder, plus `-Swift.h` forwarding to `App-Swift.h` in a mixed target. + * A referenced header that does not exist is left out. Throws for a file outside ios/, a file landing in `include/` + * and two files landing on one path. */ -export async function copyBareTarget( +export function bareCopyLayout( bare: BareTargetContent, iosDir: string, iosTargetDir: string, - sourcesDir: string, - resourcesDir: string, - log: (s: string) => void, -): Promise { + exists: (p: string) => boolean = existsSync, +): BareCopyLayout { const targetRel = path.relative(iosDir, iosTargetDir).split(path.sep).join("/"); const place = (file: TargetFile): string => { if (path.posix.isAbsolute(file.relPath) || file.relPath.split("/").includes("..")) { @@ -76,58 +87,86 @@ export async function copyBareTarget( const code = [...bare.swiftSources, ...bare.cSources, ...bare.headers, ...(bare.bridgingHeader ? [bare.bridgingHeader] : [])]; const cSources = new Set(bare.cSources); const headers = new Set(bare.headers); - const codeDest = new Map(); + const files: BareCopyLayout["files"] = []; + const missingHeaders: TargetFile[] = []; for (const file of code) { // Xcode builds with a referenced header missing until a source imports it; so does the generated target. - if (headers.has(file) && !existsSync(file.absPath)) { - log(`ℹ Skipped ${file.relPath}: the Xcode project references this header, but the file does not exist`); + if (headers.has(file) && !exists(file.absPath)) { + missingHeaders.push(file); continue; } let dest = place(file); + if (cSources.has(file)) dest = path.posix.join(path.posix.dirname(dest), compiledName(dest)); + if (dest.split("/")[0] === INCLUDE_DIR) { + throw new Error(`${file.relPath} would land in Sources/App/${INCLUDE_DIR}/, which holds the generated header forwards; rename its folder`); + } + if (claim(dest, file)) files.push({ file, dest }); + } + + const forwards = new Map(); + for (const { file, dest } of files) { const base = path.posix.basename(dest); - const name = cSources.has(file) ? compiledName(dest) : base; - if (name !== base) { - dest = path.posix.join(path.posix.dirname(dest), name); + if (headers.has(file) && !forwards.has(base)) forwards.set(base, dest); + } + + // Xcode names the generated Swift header after the module (BareDemo-Swift.h); the SwiftPM target is App. + const swiftHeader = `${bare.productModuleName}-Swift.h`; + const swiftHeaderForward = bare.mixed && bare.productModuleName !== "App" && !forwards.has(swiftHeader) ? swiftHeader : undefined; + return { files, forwards, missingHeaders, swiftHeaderForward }; +} + +/** + * Copies the app target's code into `sourcesDir` (Sources/App) as `bareCopyLayout` places it, writing the `include/` + * forwards, and says so for each renamed `main.`, skipped header and header name clash: `main.m` is copied as + * `AppMain.m` so SwiftPM keeps App a library target. Resources are staged flat in `resourcesDir`, laid out as Xcode + * copies them to the bundle root (xtool.yml lists each top-level entry). + */ +export async function copyBareTarget( + bare: BareTargetContent, + iosDir: string, + iosTargetDir: string, + sourcesDir: string, + resourcesDir: string, + log: (s: string) => void, +): Promise { + const layout = bareCopyLayout(bare, iosDir, iosTargetDir); + const origins: Record = {}; + for (const { file, dest } of layout.files) { + const name = path.posix.basename(dest); + if (name !== path.posix.basename(file.relPath)) { log( `ℹ ${file.relPath} is compiled as ${name}: SwiftPM takes a target with a file named main for an executable, ` + "and xtool links the app's entry point from the App library", ); } - if (dest.split("/")[0] === INCLUDE_DIR) { - throw new Error(`${file.relPath} would land in Sources/App/${INCLUDE_DIR}/, which holds the generated header forwards; rename its folder`); - } - codeDest.set(file, dest); - if (claim(dest, file)) await copyListed(file, path.join(sourcesDir, dest)); + origins[path.join(sourcesDir, dest)] = file.absPath; + await copyListed(file, path.join(sourcesDir, dest)); + } + for (const file of layout.missingHeaders) { + log(`ℹ Skipped ${file.relPath}: the Xcode project references this header, but the file does not exist`); } - const forwarded = new Map(); + const ownerOf = new Map(layout.files.map(({ file, dest }) => [dest, file.relPath])); + const missing = new Set(layout.missingHeaders); for (const header of bare.headers) { - const dest = codeDest.get(header); - if (dest === undefined) continue; - const base = path.posix.basename(dest); - const first = forwarded.get(base); - if (first !== undefined) { + if (missing.has(header)) continue; + const base = path.posix.basename(header.relPath); + const first = ownerOf.get(layout.forwards.get(base)!)!; + if (first !== header.relPath) { log(`ℹ Two app headers are named ${base} (${first}, ${header.relPath}): #import "${base}" finds ${first}`); continue; } - forwarded.set(base, header.relPath); const shim = path.join(sourcesDir, INCLUDE_DIR, base); await mkdir(path.dirname(shim), { recursive: true }); - await writeFile(shim, `#import "../${dest}"\n`); + await writeFile(shim, `#import "../${layout.forwards.get(base)}"\n`); } - // Xcode names the generated Swift header after the module (BareDemo-Swift.h); the SwiftPM target is App. - let swiftHeaderForward = false; - if (bare.mixed && bare.productModuleName !== "App") { + if (layout.swiftHeaderForward !== undefined) { + await mkdir(path.join(sourcesDir, INCLUDE_DIR), { recursive: true }); + await writeFile(path.join(sourcesDir, INCLUDE_DIR, layout.swiftHeaderForward), `#import "App-Swift.h"\n`); + } else if (bare.mixed && bare.productModuleName !== "App") { const name = `${bare.productModuleName}-Swift.h`; - const owner = forwarded.get(name); - if (owner !== undefined) { - log(`ℹ The app header ${owner} is named like Xcode's generated Swift header: #import "${name}" finds it, not App-Swift.h`); - } else { - await mkdir(path.join(sourcesDir, INCLUDE_DIR), { recursive: true }); - await writeFile(path.join(sourcesDir, INCLUDE_DIR, name), `#import "App-Swift.h"\n`); - swiftHeaderForward = true; - } + log(`ℹ The app header ${ownerOf.get(layout.forwards.get(name)!)} is named like Xcode's generated Swift header: #import "${name}" finds it, not App-Swift.h`); } const staged = new Map(); @@ -152,12 +191,14 @@ export async function copyBareTarget( log(`ℹ Build settings of the app target not carried over: ${bare.ignoredSettings.join(", ")}`); } + const bridging = bare.bridgingHeader && layout.files.find(({ file }) => file.relPath === bare.bridgingHeader!.relPath); return { - bridgingHeader: bare.bridgingHeader ? path.join(sourcesDir, codeDest.get(bare.bridgingHeader)!) : undefined, + bridgingHeader: bridging ? path.join(sourcesDir, bridging.dest) : undefined, headerSearchPaths: [ - ...(forwarded.size > 0 || swiftHeaderForward ? [path.join(sourcesDir, INCLUDE_DIR)] : []), + ...(layout.forwards.size > 0 || layout.swiftHeaderForward !== undefined ? [path.join(sourcesDir, INCLUDE_DIR)] : []), ...bare.headerSearchPaths, ], resources: [...new Set([...staged.keys()].map((d) => d.split("/")[0]!))].sort(), + origins, }; } diff --git a/src/generate/iosXtool.ts b/src/generate/iosXtool.ts index b2f2192..f60da93 100644 --- a/src/generate/iosXtool.ts +++ b/src/generate/iosXtool.ts @@ -1,4 +1,4 @@ -import { readdirSync } from "node:fs"; +import { readdirSync, readFileSync } from "node:fs"; import { copyFile, cp, mkdir, readFile, rm, symlink, writeFile } from "node:fs/promises"; import { basename, dirname, join, relative, resolve } from "node:path"; import * as plist from "plist"; @@ -14,7 +14,7 @@ import { APP_ICON_FILE, findAppIcon, type IconRecord } from "./appIcon.js"; import { podHeaderForwardDirs, reactNativeBareIncludeDirs } from "./bareIncludes.js"; import { copyBareTarget } from "./bareSources.js"; import { expoClangImporterInputs } from "./expoImporter.js"; -import { DEV_SUPPORT_TARGET, renderPackageSwift, type AppTargetInputs } from "./packageSwift.js"; +import { DEV_SUPPORT_TARGET, renderPackageSwift, type AppTargetInputs, type PackageSwiftInput } from "./packageSwift.js"; import { writeEmptyTargetObjects } from "../pods/emptyTargets.js"; import type { PodsLinks } from "../pods/stage.js"; import { PodsError } from "../pods/format.js"; @@ -96,6 +96,16 @@ interface AppSources { app: AppTargetInputs; /** Top-level entries staged in ios-xtool/Resources. */ resources: string[]; + /** Each copied code file's copy path → its source path. */ + origins: Record; +} + +/** What `writeIosXtool` generated the App from. */ +export interface GeneratedApp { + /** The input handed to `renderPackageSwift`. */ + pkg: PackageSwiftInput; + /** Each file in Sources/App (a copy, or Expo's ExpoModulesProvider.swift link) → its source path. */ + origins: Record; } /** Copies the app's sources into Sources/App (resources into ios-xtool/Resources) and says what the App target compiles. */ @@ -123,15 +133,19 @@ async function writeAppSources(ctx: GenerateContext, headersDir: string, resourc cxxStandard: project.bare.cxxStandard, swiftHeadersDir: headersDir, }; - return { app, resources: copied.resources }; + return { app, resources: copied.resources, origins: copied.origins }; } - const appDelegate = await readRequired(join(project.iosTargetDir, "AppDelegate.swift"), "AppDelegate.swift"); + const origins: Record = {}; + const appDelegatePath = join(project.iosTargetDir, "AppDelegate.swift"); + const appDelegate = await readRequired(appDelegatePath, "AppDelegate.swift"); await writeFile(join(paths.sources, "AppDelegate.swift"), appDelegate); + origins[join(paths.sources, "AppDelegate.swift")] = appDelegatePath; // SDK 58's template adds a SceneDelegate; SDK 57's is AppDelegate-only. It is required only when Info.plist names one. const sceneDelegatePath = join(project.iosTargetDir, "SceneDelegate.swift"); const sceneDelegate = await readOptional(sceneDelegatePath); if (sceneDelegate !== undefined) { await writeFile(join(paths.sources, "SceneDelegate.swift"), sceneDelegate); + origins[join(paths.sources, "SceneDelegate.swift")] = sceneDelegatePath; } else { const names = sceneDelegateClassNames(await readRequired(project.infoPlistPath, "Info.plist")); if (names.length > 0) { @@ -140,7 +154,9 @@ async function writeAppSources(ctx: GenerateContext, headersDir: string, resourc ); } } - const bridgingHeader = await expoBridgingHeader(paths.ios, paths.sources, ctx.log ?? console.log); + const bridging = await expoBridgingHeader(paths.ios, paths.sources, ctx.log ?? console.log); + if (bridging) origins[bridging.copy] = bridging.source; + const bridgingHeader = bridging?.copy; return { app: { mixed: false, @@ -150,6 +166,7 @@ async function writeAppSources(ctx: GenerateContext, headersDir: string, resourc swiftHeadersDir: headersDir, }, resources: [], + origins, }; } @@ -159,14 +176,13 @@ function hasDeclarations(text: string): boolean { } /** - * The Expo prebuild's bridging header (`SWIFT_OBJC_BRIDGING_HEADER` of the app target, Debug, relative to ios/), - * copied into Sources/App for Swift when it holds more than comments: a config plugin adds imports to it - * (react-native-app-auth's `RNAppAuthAuthorizationFlowManager.h`). The prebuild's default holds only a comment and is - * not passed, so such an app's manifest stays as it was. Undefined without an Xcode project or the setting, and with a - * ⚠ line when ios/ holds several Xcode projects or application targets; a setting naming a missing file, or one that - * cannot be resolved, throws naming the setting. + * The Expo prebuild's bridging header (`SWIFT_OBJC_BRIDGING_HEADER` of the app target, Debug, relative to ios/), when it + * holds more than comments: a config plugin adds imports to it (react-native-app-auth's + * `RNAppAuthAuthorizationFlowManager.h`). The prebuild's default holds only a comment. Undefined without an Xcode + * project, the setting or declarations, and when ios/ holds several Xcode projects or application targets (with a ⚠ + * line through `log`); a setting naming a missing file, or one that cannot be resolved, throws naming the setting. */ -async function expoBridgingHeader(iosDir: string, sourcesDir: string, log: (s: string) => void): Promise { +export function expoBridgingHeaderPath(iosDir: string, log?: (s: string) => void): string | undefined { let projects: string[]; try { projects = readdirSync(iosDir).filter((n) => n.endsWith(".xcodeproj")).sort(); @@ -181,7 +197,7 @@ async function expoBridgingHeader(iosDir: string, sourcesDir: string, log: (s: s p = openPbxproj(iosDir); } catch (e) { if (e instanceof AmbiguousProjectError) { - log(`⚠ ${e.what}; rn-xtool reads no bridging header or entitlements from it`); + log?.(`⚠ ${e.what}; rn-xtool reads no bridging header or entitlements from it`); return undefined; } throw unreadable(`ios/${projects[0]}`, e); @@ -193,17 +209,31 @@ async function expoBridgingHeader(iosDir: string, sourcesDir: string, log: (s: s throw unreadable(`ios/${p.projectName}.xcodeproj`, e); } if (!rel) return undefined; - const text = await readOptional(resolve(iosDir, rel)); - if (text === undefined) { + const file = resolve(iosDir, rel); + let text: string; + try { + text = readFileSync(file, "utf8"); + } catch (e) { + if ((e as NodeJS.ErrnoException).code !== "ENOENT") throw e; throw new Error( `SWIFT_OBJC_BRIDGING_HEADER in ios/${p.projectName}.xcodeproj names ${rel}, which does not exist. ` + "Run rn-xtool build --clean to run expo prebuild again.", ); } - if (!hasDeclarations(text)) return undefined; - const copy = join(sourcesDir, basename(rel)); - await writeFile(copy, text); - return copy; + return hasDeclarations(text) ? file : undefined; +} + +/** `expoBridgingHeaderPath`'s header, copied into Sources/App for Swift; the prebuild's default is not passed. */ +async function expoBridgingHeader( + iosDir: string, + sourcesDir: string, + log: (s: string) => void, +): Promise<{ copy: string; source: string } | undefined> { + const header = expoBridgingHeaderPath(iosDir, log); + if (header === undefined) return undefined; + const copy = join(sourcesDir, basename(header)); + await writeFile(copy, await readFile(header, "utf8")); + return { copy, source: header }; } /** @@ -238,7 +268,7 @@ async function writeBundles(bundles: readonly BundleSource[], resourcesDir: stri return names.sort(); } -export async function writeIosXtool(ctx: GenerateContext): Promise { +export async function writeIosXtool(ctx: GenerateContext): Promise { const { project, paths } = ctx; const headersDir = swiftHeadersDir(paths.iosXtool); const resourcesDir = join(paths.iosXtool, "Resources"); @@ -246,7 +276,7 @@ export async function writeIosXtool(ctx: GenerateContext): Promise { await rm(paths.sources, { recursive: true, force: true }); await rm(resourcesDir, { recursive: true, force: true }); await mkdir(paths.sources, { recursive: true }); - const { app, resources } = await writeAppSources(ctx, headersDir, resourcesDir); + const { app, resources, origins } = await writeAppSources(ctx, headersDir, resourcesDir); const appResources = [...(project.hasExpoConstants ? DEFAULT_RESOURCES : BASE_RESOURCES), ...resources.map((r) => `Resources/${r}`)]; const bundleSources = ctx.resourceBundles ?? []; checkBundleNames(bundleSources, appResources); @@ -265,12 +295,10 @@ export async function writeIosXtool(ctx: GenerateContext): Promise { if (project.hasExpoModules) { const linkPath = join(paths.sources, "ExpoModulesProvider.swift"); - const target = relative( - dirname(linkPath), - join(paths.expoDir, "ExpoModulesProvider.swift"), - ); + const provider = join(paths.expoDir, "ExpoModulesProvider.swift"); await rm(linkPath, { force: true }); - await symlink(target, linkPath); + await symlink(relative(dirname(linkPath), provider), linkPath); + origins[linkPath] = provider; } const template = await readRequired(project.infoPlistPath, "Info.plist"); @@ -306,7 +334,7 @@ export async function writeIosXtool(ctx: GenerateContext): Promise { entitlementsPath: entitlements !== undefined ? ENTITLEMENTS_FILE : undefined, }), ); - const { manifest, manifest65 } = renderPackageSwift({ + const pkg: PackageSwiftInput = { iosDir: paths.ios, frameworks: ctx.frameworks, iosMin: IOS_MIN, @@ -320,11 +348,13 @@ export async function writeIosXtool(ctx: GenerateContext): Promise { app: { ...app, importerPaths: await scaffoldedImporterPaths(paths.autolinking) }, devSupport, ...(ctx.pods !== undefined ? { pods: ctx.pods } : {}), - }); + }; + const { manifest, manifest65 } = renderPackageSwift(pkg); await writeFile(join(paths.iosXtool, "Package.swift"), manifest); if (manifest65 !== undefined) await writeFile(join(paths.iosXtool, MANIFEST_6_5), manifest65); else await rm(join(paths.iosXtool, MANIFEST_6_5), { force: true }); await writeFile(join(paths.iosXtool, ".gitignore"), "*\n"); // Before xtool-build: Swift Build links an object it never writes for a target without sources. if (ctx.emptyTargets !== undefined && ctx.emptyTargets.length > 0) await writeEmptyTargetObjects(paths.iosXtool, ctx.emptyTargets, IOS_MIN); + return { pkg, origins }; } diff --git a/src/generate/packageSwift.ts b/src/generate/packageSwift.ts index cecac0b..6dbda22 100644 --- a/src/generate/packageSwift.ts +++ b/src/generate/packageSwift.ts @@ -110,54 +110,83 @@ function cDefine(entry: string): string { return eq < 0 ? `.define(${lit(entry)})` : `.define(${lit(entry.slice(0, eq))}, to: ${lit(entry.slice(eq + 1))})`; } -function expoSwiftSettings(expo: ExpoPackageInputs): string { - const importer = expo.clangImporter; - const importerFlags = importer - ? [ - `-I${importer.swiftHeadersDir}`, - ...importer.includeDirs.map((d) => `-I${d}`), - ...importer.moduleMaps.map((m) => `-fmodule-map-file=${m}`), - ].flatMap((f) => ["-Xcc", f]) - : []; - return ` // CocoaPods sets these for the app; ExpoModulesProvider.swift registers debug-only - // modules (expo-dev-launcher, expo-dev-menu) under EXPO_CONFIGURATION_DEBUG. - .define("EXPO_CONFIGURATION_DEBUG", .when(configuration: .debug)), - .define("EXPO_CONFIGURATION_RELEASE", .when(configuration: .release)), -${settingLines([flags(["-F", expo.compileInterfacesDir]), ...(importerFlags.length ? [flags(importerFlags)] : [])])}`; -} - -/** Swift reads the bridging header with the target's include paths and defines, as Xcode passes them. */ -function appSwiftSettings(app: AppTargetInputs): string { - if (!app.bridgingHeader) return ""; - const clang = [...app.headerSearchPaths.map((p) => `-I${p}`), ...app.defines.map((d) => `-D${d}`)]; - return settingLines([flags(["-import-objc-header", app.bridgingHeader, ...clang.flatMap((f) => ["-Xcc", f])])]); -} - -/** Swift builds a scaffolded library's module from its headers in each importer, the App too: give it what it needs. */ -function importerSwiftSettings(app: AppTargetInputs): string { - const paths = app.importerPaths ?? []; - return paths.length ? settingLines([flags(paths.flatMap((p) => ["-Xcc", `-I${p}`]))]) : ""; +/** The App target's include dirs, in search order: the app's own and bare ones, Swift's header dir, Expo's importer dirs. */ +export function appIncludeDirs(app: AppTargetInputs, expo?: ExpoPackageInputs): string[] { + return [...app.headerSearchPaths, app.swiftHeadersDir, ...(expo?.clangImporter?.includeDirs ?? [])]; } /** - * Objective-C/C++ settings; `-I swiftHeadersDir` lets them `#import "App-Swift.h"`. In a hybrid project that header - * does `@import Expo;`, so they also get what Swift's clang importer gets (as clang flags, without `-Xcc`): the + * What the manifest's `cSettings` (`cxx` false) or `cxxSettings` (`cxx` true) give the compiler; `[]` for a Swift-only + * target. `-I swiftHeadersDir` lets Objective-C `#import "App-Swift.h"`. In a hybrid project that header does + * `@import Expo;`, so they also get what Swift's clang importer gets (as clang flags, without `-Xcc`): the * compile-interfaces frameworks (``) and the importer's include dirs and module maps. * Swift Build does not apply the package's `cxxLanguageStandard` to a mixed target, so its ObjC++/C++ files get the * standard as `-std=` (C++ only: on a C/Objective-C file the flag is rejected) or compile with clang's default and * fail on React Native's C++20 headers. */ -function appClangSettings(app: AppTargetInputs, expo: ExpoPackageInputs | undefined): string { - if (!app.mixed) return ""; - const importer = expo?.clangImporter; - const includes = [ - ...[...app.headerSearchPaths, app.swiftHeadersDir, ...(importer?.includeDirs ?? [])].flatMap((p) => ["-I", p]), - ...(importer?.moduleMaps ?? []).map((m) => `-fmodule-map-file=${m}`), +export function appClangArgs(app: AppTargetInputs, expo: ExpoPackageInputs | undefined, cxx: boolean): string[] { + if (!app.mixed) return []; + return [ + ...app.defines.map((d) => `-D${d}`), + ...appIncludeDirs(app, expo).flatMap((p) => ["-I", p]), + ...(expo?.clangImporter?.moduleMaps ?? []).map((m) => `-fmodule-map-file=${m}`), ...(expo ? ["-F", expo.compileInterfacesDir] : []), + ...(cxx ? [cxxStandardFlag(app.cxxStandard)] : []), ]; - const shared = [...app.defines.map(cDefine), flags(includes)]; +} + +/** The App's Swift unsafe flags, one group per manifest line. */ +function appSwiftFlagGroups(app: AppTargetInputs, expo: ExpoPackageInputs | undefined): string[][] { + const xcc = (list: string[]) => list.flatMap((f) => ["-Xcc", f]); + const importer = expo?.clangImporter; + return [ + expo ? ["-F", expo.compileInterfacesDir] : [], + importer + ? xcc([ + `-I${importer.swiftHeadersDir}`, + ...importer.includeDirs.map((d) => `-I${d}`), + ...importer.moduleMaps.map((m) => `-fmodule-map-file=${m}`), + ]) + : [], + // Swift reads the bridging header with the target's include paths and defines, as Xcode passes them. + app.bridgingHeader + ? ["-import-objc-header", app.bridgingHeader, ...xcc([...app.headerSearchPaths.map((p) => `-I${p}`), ...app.defines.map((d) => `-D${d}`)])] + : [], + // Swift builds a scaffolded library's module from its headers in each importer, the App too: give it what it needs. + xcc((app.importerPaths ?? []).map((p) => `-I${p}`)), + ].filter((group) => group.length > 0); +} + +/** What the manifest's `swiftSettings` give the compiler in a Debug build. */ +export function appSwiftArgs(app: AppTargetInputs, expo: ExpoPackageInputs | undefined): string[] { + return ["-DDEBUG", ...(expo ? ["-DEXPO_CONFIGURATION_DEBUG"] : []), ...appSwiftFlagGroups(app, expo).flat()]; +} + +/** The App's `swiftSettings` entries: {@link appSwiftArgs} with the defines per configuration. */ +function appSwiftSettings(app: AppTargetInputs, expo: ExpoPackageInputs | undefined): string { + const expoDefines = expo + ? ` // CocoaPods sets these for the app; ExpoModulesProvider.swift registers debug-only + // modules (expo-dev-launcher, expo-dev-menu) under EXPO_CONFIGURATION_DEBUG. + .define("EXPO_CONFIGURATION_DEBUG", .when(configuration: .debug)), + .define("EXPO_CONFIGURATION_RELEASE", .when(configuration: .release)), +` + : ""; + return ` .define("DEBUG", .when(configuration: .debug)), +${expoDefines}${settingLines(appSwiftFlagGroups(app, expo).map(flags))}`; +} + +/** + * The App's `cSettings` and `cxxSettings`, from {@link appClangArgs}: SwiftPM spells its leading `-D` arguments as + * `.define`, the rest as one line of flags; C++'s own arguments follow on a line of their own. + */ +function appClangSettings(app: AppTargetInputs, expo: ExpoPackageInputs | undefined): string { + if (!app.mixed) return ""; + const c = appClangArgs(app, expo, false); + const defines = app.defines.length; + const shared = [...c.slice(0, defines).map((d) => cDefine(d.slice("-D".length))), flags(c.slice(defines))]; + const cxxOnly = appClangArgs(app, expo, true).slice(c.length); const section = (name: string, lines: string[]) => ` ${name}: [\n${settingLines(lines)} ],\n`; - return section("cSettings", shared) + section("cxxSettings", [...shared, flags([cxxStandardFlag(app.cxxStandard)])]); + return section("cSettings", shared) + section("cxxSettings", [...shared, flags(cxxOnly)]); } export function renderPackageSwift(i: PackageSwiftInput): RenderedPackageSwift { @@ -223,8 +252,7 @@ ${jsiPackage} ], ${jsiProduct}${devSupportDependency} ], path: "Sources/App", ${appClangSettings(app, expo)} swiftSettings: [ - .define("DEBUG", .when(configuration: .debug)), -${expo ? expoSwiftSettings(expo) : ""}${appSwiftSettings(app)}${importerSwiftSettings(app)} ], +${appSwiftSettings(app, expo)} ], linkerSettings: [ .linkedLibrary("c++"), .unsafeFlags([${linkerFlags.map(lit).join(", ")}]), diff --git a/src/pipeline/precheck.ts b/src/pipeline/precheck.ts new file mode 100644 index 0000000..0ddf5ce --- /dev/null +++ b/src/pipeline/precheck.ts @@ -0,0 +1,721 @@ +// The precheck step (spec "B2, the precheck", rows 37–55): the generated package planned and its graph read, B1's pass 2 +// over the app's copied files, then `swiftc -typecheck` (hop 2) and `clang -fsyntax-only` per C-family file (hop 3), +// each translation unit's output parsed on its own. The flags come from `precheckCommands.ts`, the parsing from +// `precheckReport.ts`: this file only runs the hops, in order, and says what it skipped. + +import { appendFileSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs"; +import { availableParallelism } from "node:os"; +import path from "node:path"; +import { execa } from "execa"; +import type { GeneratedApp } from "../generate/iosXtool.js"; +import type { ProjectPaths } from "../paths.js"; +import { resolveIncludes, type IncludeScope, type ResolvedInclude } from "../project/appIncludes.js"; +import { definesOf } from "../project/includeScan.js"; +import { runArgv } from "../tools/exec.js"; +import { devEnv } from "../tools/xtool.js"; +import { + clangArgs, + compileIncludeDirs, + moduleCacheKey, + precheckIncludeDirs, + precheckToolchain, + swiftcArgs, + synthesizedModuleMap, + type PrecheckInputs, + type PrecheckToolchain, +} from "./precheckCommands.js"; +import { graphHeaders, planManifest, readPackageGraph, type SwiftRunner } from "./precheckGraph.js"; +import { parseDiagnostics, precheckErrorLines, precheckStop, STALE_MODULE_CACHE, withExit, type Diagnostic } from "./precheckReport.js"; + +export interface PrecheckOptions { + root: string; + rnVersion: string; + /** `build --clean`: the module cache is emptied first. */ + clean: boolean; + /** The terminal: errors, and the `ℹ`/`⚠` lines that name what the precheck left to xtool-build. */ + log: (s: string) => void; +} + +export interface PrecheckDeps { + swift: SwiftRunner; + /** One compiler run; a non-zero exit resolves. `output` is stdout and stderr interleaved. */ + compile: (cmd: string, args: string[], opts: { cwd: string; env: NodeJS.ProcessEnv }) => Promise<{ code: number; output: string }>; + toolchain: () => Promise; + /** Opens `precheck.log` (emptied) and returns its append. */ + logWriter: (file: string) => (text: string) => void; +} + +/** The extensions clang compiles in the App target; any other copied file is a header, read only through an include. */ +const C_FAMILY = new Set([".m", ".mm", ".c", ".cc", ".cpp", ".cxx"]); +/** The output lines shown for a compiler that failed without a diagnostic. */ +const FAILURE_TAIL = 20; +const MODULE_MAP_FLAG = "-fmodule-map-file="; + +/** A command that could not start has no exit code: execa's message stands for its output. */ +const notStarted = (r: { exitCode?: number; message?: string }): string => (r.exitCode === undefined ? (r.message ?? "") : ""); + +const realSwift: SwiftRunner = async (args, opts) => { + const r = await execa("swift", args, { cwd: opts.cwd, env: opts.env, extendEnv: false, reject: false }); + return { code: r.exitCode ?? 1, stdout: `${r.stdout ?? ""}`, stderr: `${r.stderr ?? ""}${notStarted(r)}` }; +}; + +const realCompile: PrecheckDeps["compile"] = async (cmd, args, opts) => { + const [bin, argv] = runArgv(cmd, args, true); + const r = await execa(bin, argv, { cwd: opts.cwd, env: opts.env, extendEnv: false, reject: false, all: true }); + return { code: r.exitCode ?? 1, output: `${r.all ?? ""}${notStarted(r)}` }; +}; + +/** A path as the precheck's lines name it: a copied file by its source, any path relative to the project root. */ +export function display(file: string, root: string, origins: Record): string { + const source = origins[file] ?? file; + const rel = path.relative(root, source); + const outside = rel === "" || rel === ".." || rel.startsWith(`..${path.sep}`) || path.isAbsolute(rel); + return outside ? source : rel.split(path.sep).join("/"); +} + +/** One compiler run: the files it was given, its exit code and its output. */ +interface Unit { + files: string[]; + code: number; + output: string; +} + +/** What every hop shares. */ +interface Run { + paths: ProjectPaths; + app: GeneratedApp; + opts: PrecheckOptions; + deps: PrecheckDeps; + dir: string; + logFile: string; + /** The compilers' TMPDIR, removed at the end. */ + tmp: string; + env: NodeJS.ProcessEnv; + /** To precheck.log only. */ + write: (text: string) => void; + /** To the terminal and precheck.log. */ + show: (line: string) => void; + name: (file: string) => string; +} + +/** `file` emptied, then each text appended as it comes. */ +function logWriter(file: string): (text: string) => void { + writeFileSync(file, ""); + return (text) => appendFileSync(file, text.endsWith("\n") ? text : `${text}\n`); +} + +const quote = (arg: string): string => (/^[\w@%+=:,./-]+$/.test(arg) ? arg : `'${arg.replace(/'/g, `'\\''`)}'`); +const commandLine = (cmd: string, args: string[]): string => [cmd, ...args].map(quote).join(" "); +const within = (dir: string, p: string): boolean => p === dir || p.startsWith(`${dir}${path.sep}`); +const isDir = (p: string): boolean => { + try { + return statSync(p).isDirectory(); + } catch { + return false; + } +}; +const entries = (dir: string): string[] => { + try { + return readdirSync(dir); + } catch { + return []; + } +}; + +/** `fn` over `items`, at most `limit` at a time; results in `items`' order. */ +async function mapLimit(items: T[], limit: number, fn: (item: T) => Promise): Promise { + const results: R[] = new Array(items.length); + let next = 0; + const worker = async () => { + while (next < items.length) { + const i = next++; + results[i] = await fn(items[i]!); + } + }; + await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker)); + return results; +} + +/** + * Checks the app's own sources before xtool-build, in order: the module cache (emptied on `clean`, other keys + * removed) and the toolchain; SwiftPM's plan and graph; pass 2; Swift; the C family; the report. Every command line + * and all output go to `/precheck.log`; errors stop with `precheckStop`, and any other stop but a missing + * toolchain names the way past the precheck too (`withExit`). + */ +export async function runPrecheck( + paths: ProjectPaths, + app: GeneratedApp, + opts: PrecheckOptions, + deps: Partial = {}, +): Promise { + const dir = path.join(paths.iosXtool, ".precheck"); + const logFile = path.join(dir, "precheck.log"); + const d: PrecheckDeps = { swift: realSwift, compile: realCompile, toolchain: () => precheckToolchain(), logWriter, ...deps }; + const tmp = path.join(dir, "tmp"); + let append: ((text: string) => void) | undefined; + const write = (text: string): void => append?.(text); + const r: Run = { + paths, + app, + opts, + deps: d, + dir, + logFile, + tmp, + env: { ...devEnv(paths.iosXtool), TMPDIR: tmp }, + write, + // The terminal first: a log that cannot be written (a full disk) does not hide the line. + show: (line) => { + opts.log(line); + try { + write(line); + } catch { + // Only the log misses the line; a plain write that fails stops the run, naming the exit. + } + }, + name: (file) => display(file, opts.root, app.origins), + }; + try { + mkdirSync(dir, { recursive: true }); + append = d.logWriter(logFile); + rmSync(tmp, { recursive: true, force: true }); + mkdirSync(tmp, { recursive: true }); + const { toolchain, moduleCache } = await prepare(r); + const inputs = await readGraph(r, toolchain, moduleCache); + const maps = placeImporterMaps(r); + const includes = pass2(r, inputs, maps.missing); + const waiting = waitingForMaps(r, includes, maps); + const swiftBuilt = importsSwiftBuilt(r, inputs, includes, maps, waiting); + const swift = await swiftHop(r, inputs, waiting, swiftBuilt, maps); + const cFamily = await cFamilyHop(r, inputs, swift !== undefined, includes, new Set([...waiting, ...swiftBuilt.keys()]), maps); + report(r, [...(swift ?? []), ...cFamily]); + } catch (e) { + // The log may be what failed (ENOSPC): the stop names the exit all the same. + try { + write(`# stopped: ${e instanceof Error ? e.message : String(e)}`); + } catch { + // Nothing more to keep. + } + throw withExit(e); + } finally { + try { + rmSync(tmp, { recursive: true, force: true }); + } catch { + // A leftover TMPDIR is removed by the next precheck; it must not replace the stop. + } + } +} + +/** `clean` empties the module cache before the toolchain is read; a cache under another key is removed after. */ +async function prepare(r: Run): Promise<{ toolchain: PrecheckToolchain; moduleCache: string }> { + const caches = path.join(r.dir, "ModuleCache"); + if (r.opts.clean) rmSync(caches, { recursive: true, force: true }); + const toolchain = await r.deps.toolchain(); + const key = moduleCacheKey(r.opts.rnVersion, toolchain.versions); + for (const other of entries(caches).filter((e) => e !== key)) rmSync(path.join(caches, other), { recursive: true, force: true }); + r.write(`# precheck of ${r.opts.root}\n# toolchain:\n${toolchain.versions}\n# module cache: ${key}`); + return { toolchain, moduleCache: path.join(caches, key) }; +} + +/** SwiftPM's plan (hop 5, first), the package graph's headers, the synthesized module maps and `inputs.json`. */ +async function readGraph(r: Run, toolchain: PrecheckToolchain, moduleCache: string): Promise { + const swift: SwiftRunner = async (args, o) => { + const res = await r.deps.swift(args, o); + r.write(`$ ${commandLine("swift", args)}\n${res.stdout}\n${res.stderr}\n# exit ${res.code}`); + return res; + }; + await planManifest(r.paths.iosXtool, swift); + const graph = graphHeaders(await readPackageGraph(r.paths.iosXtool, path.join(r.tmp, "scratch"), swift)); + rmSync(path.join(r.dir, "modulemaps"), { recursive: true, force: true }); + for (const s of graph.synthesized) { + const file = synthesizedModuleMap(r.dir, s.module); + mkdirSync(path.dirname(file), { recursive: true }); + writeFileSync(file, s.text); + } + const inputs: PrecheckInputs = { app: r.app, graph, toolchain, dir: r.dir, moduleCache }; + writeFileSync(path.join(r.dir, "inputs.json"), `${JSON.stringify(inputs, null, 2)}\n`); + if (graph.unresolved.length > 0) { + r.show( + `ℹ precheck — ${graph.unresolved.length} dependencies of App could not be placed (${graph.unresolved.join(", ")}): checked by xtool-build`, + ); + } + return inputs; +} + +/** Expo's importer module maps, as the precheck places them. */ +interface ImporterMaps { + /** The modules whose map Swift Build has not written yet (each map is named for its module). */ + missing: Set; + /** `args` without the flags that name such a map; on the first drop, the `ℹ` line unless `skip` gave it. */ + drop: (args: string[]) => string[]; + /** The one `ℹ` line, naming the files left to xtool-build for those maps. */ + skip: (files: string[]) => void; +} + +/** A path a module map names: after `header` (any kind, `umbrella header` too), `umbrella`, or `extern module X`. */ +const MAP_PATH = /(\b(?:header|umbrella)\s+|\bextern\s+module\s+[A-Za-z_][A-Za-z0-9_]*\s+)"((?:[^"\\]|\\.)*)"/g; + +/** + * Swift Build's module map `text`, read from `map`, with each relative path it names made absolute against the map's + * own folder, so that the copy still names Swift Build's files (`header "ExpoUI-Swift.h"`); absolute paths stay. A path + * to the App's own Swift header (`app.from`) names the precheck's (`app.to`) instead. Nothing else changes. + */ +function withSwiftBuildPaths(text: string, map: string, app: { from: string; to: string }): string { + return text.replace(MAP_PATH, (whole, head: string, named: string) => { + if (named.includes("\\")) return whole; + const resolved = path.resolve(path.dirname(map), named); + if (resolved === app.from) return `${head}"${app.to}"`; + return path.isAbsolute(named) ? whole : `${head}"${resolved}"`; + }); +} + +/** + * The precheck's Swift header folder, emptied (`App-Swift.h` is written anew), with Expo's importer module maps Swift + * Build wrote copied in where the swapped flags name them, their paths still naming Swift Build's files + * (`withSwiftBuildPaths`). A map Swift Build has not written yet is dropped from the + * command lines, with one `ℹ` line. + */ +function placeImporterMaps(r: Run): ImporterMaps { + const to = path.join(r.dir, "swift-headers"); + rmSync(to, { recursive: true, force: true }); + mkdirSync(to, { recursive: true }); + const from = r.app.pkg.app.swiftHeadersDir; + const placedMissing = new Set(); + const missing = new Set(); + for (const map of r.app.pkg.expo?.clangImporter?.moduleMaps ?? []) { + if (!within(from, map) || map === from) continue; + const placed = path.join(to, path.relative(from, map)); + if (existsSync(map)) { + mkdirSync(path.dirname(placed), { recursive: true }); + writeFileSync(placed, withSwiftBuildPaths(readFileSync(map, "utf8"), map, { from: path.join(from, "App-Swift.h"), to: path.join(to, "App-Swift.h") })); + } else { + placedMissing.add(placed); + missing.add(path.basename(map, ".modulemap")); + } + } + let told = false; + const head = `ℹ precheck — ${placedMissing.size} module maps Swift Build writes are not there yet`; + return { + missing, + drop: (args) => { + const kept: string[] = []; + for (const arg of args) { + if (arg.startsWith(MODULE_MAP_FLAG) && placedMissing.has(arg.slice(MODULE_MAP_FLAG.length))) { + if (kept.at(-1) === "-Xcc") kept.pop(); + if (!told) r.show(`${head}: files that need them are checked by xtool-build`); + told = true; + continue; + } + kept.push(arg); + } + return kept; + }, + skip: (files) => { + if (files.length === 0) return; + r.show(`${head}: ${files.map(r.name).join(", ")} are checked by xtool-build`); + told = true; + }, + }; +} + +/** Where clang looks after the target's include folders, and whether its own resource headers were found. */ +interface SystemHeaders { + has: (spelling: string) => boolean; + /** clang's resource folder is known: without it, an angle include of `` cannot be judged. */ + resource: boolean; +} + +/** The include folders clang searches after the target's: its own headers', the SDK's, and the frameworks'. */ +function systemHeaders(inputs: PrecheckInputs): SystemHeaders { + const { sdk, versions } = inputs.toolchain; + // clang's resource headers (stdarg.h, arm_neon.h, …): /../lib/clang//include. + const installed = /^InstalledDir: (.+)$/m.exec(versions)?.[1]?.trim(); + const clangLib = installed !== undefined ? path.join(installed, "..", "lib", "clang") : undefined; + const resource = clangLib !== undefined ? entries(clangLib).map((v) => path.join(clangLib, v, "include")).filter(isDir) : []; + const dirs = [...resource, path.join(sdk, "usr", "local", "include"), path.join(sdk, "usr", "include"), path.join(sdk, "usr", "include", "c++", "v1")]; + const compileInterfaces = inputs.app.pkg.expo?.compileInterfacesDir; + const frameworks = [ + ...(compileInterfaces !== undefined ? [compileInterfaces] : []), + path.join(sdk, "System", "Library", "Frameworks"), + path.join(sdk, "System", "Library", "SubFrameworks"), + ]; + const has = (spelling: string): boolean => { + if (path.isAbsolute(spelling)) return false; + if (dirs.some((d) => existsSync(path.join(d, spelling)))) return true; + const slash = spelling.indexOf("/"); + if (slash <= 0) return false; + const framework = `${spelling.slice(0, slash)}.framework`; + const rest = spelling.slice(slash + 1); + return frameworks.some((d) => ["Headers", "PrivateHeaders"].some((h) => existsSync(path.join(d, framework, h, rest)))); + }; + return { has, resource: resource.length > 0 }; +} + +/** The copy's includes, resolved as one compile's include folders find them. */ +interface Resolver { + /** The include folders, in the compile's order (after the including file's folder for a quote include). */ + includeDirs: string[]; + of: (file: string) => ResolvedInclude[]; + /** A spelling looked up as clang does: from `from`'s folder (quote), then the include folders. */ + lookup: (from: string, spelling: string, angle: boolean) => string | undefined; + /** `file` and the copy's files its includes find, transitively (a `-Swift.h` forward in the copy followed). */ + reached: (file: string) => string[]; + /** With `certain`, only the includes clang surely opens are followed. */ + reach: (file: string, certain: boolean) => string[]; +} + +/** The copy's includes, resolved as pass 2 resolves them: each compile root in the order of the compile that reads it. */ +interface Includes { + /** The resolver of `root`'s compile. */ + forRoot: (root: string) => Resolver; + /** `root` and the copy's files its includes find, transitively, as its compile finds them. */ + reached: (root: string) => string[]; +} + +/** The files clang reads first: the C-family sources and the bridging header. */ +function compileRoots(r: Run): string[] { + const bridging = r.app.pkg.app.bridgingHeader; + return [...Object.keys(r.app.origins).filter((f) => C_FAMILY.has(path.extname(f))), ...(bridging !== undefined ? [bridging] : [])]; +} + +/** The includes of the copy's files as `includeDirs`, in that order, find them; each file resolved once, when first asked. */ +function resolver(r: Run, includeDirs: string[], files: string[]): Resolver { + const scope: Omit = { exists: existsSync, includeDirs, defines: definesOf(r.app.pkg.app.defines) }; + const byFile = new Map(); + const of = (file: string): ResolvedInclude[] => { + let found = byFile.get(file); + if (found === undefined) { + found = existsSync(file) ? resolveIncludes({ ...scope, files: [{ path: file, source: file, display: file }] }) : []; + byFile.set(file, found); + } + return found; + }; + for (const inc of resolveIncludes({ ...scope, files: files.map((f) => ({ path: f, source: f, display: f })) })) { + byFile.set(inc.file, [...(byFile.get(inc.file) ?? []), inc]); + } + for (const f of files) if (!byFile.has(f)) byFile.set(f, []); + const lookup = (from: string, spelling: string, angle: boolean): string | undefined => { + if (path.isAbsolute(spelling)) return existsSync(spelling) ? spelling : undefined; + return (angle ? includeDirs : [path.dirname(from), ...includeDirs]).map((d) => path.join(d, spelling)).find((p) => existsSync(p)); + }; + const reach = (file: string, certain: boolean): string[] => { + const seen = new Set(); + const visit = (f: string): void => { + if (seen.has(f)) return; + seen.add(f); + for (const inc of of(f)) { + if (certain && !inc.certain) continue; + const found = inc.generated ? lookup(f, inc.spelling, inc.angle) : inc.found; + if (found !== undefined && within(r.paths.sources, found)) visit(found); + } + }; + visit(file); + return [...seen]; + }; + return { includeDirs, of, lookup, reached: (file) => reach(file, false), reach }; +} + +/** + * B1 pass 2 over the copied files (Swift's aside) with the App target's include folders and defines. Each compile root + * and the files it reaches are resolved in the order of the compile that reads it (`compileIncludeDirs`): a file of the + * target searches the graph's folders first, the bridging header the target's own, so a header both hold is the copy + * that compile opens. A certain miss the system folders do not answer either, in a file a compile reaches through + * certain includes, is an error when it is a quote include, or an angle include whose first path component is no + * target of the graph (and clang's own headers were found); the errors stop the step before any compile. Any other + * certain miss is a `⚠`. + */ +function pass2(r: Run, inputs: PrecheckInputs, unwritten: ReadonlySet): Includes { + const files = Object.keys(r.app.origins).filter((f) => path.extname(f) !== ".swift"); + const roots = compileRoots(r); + // One resolver per include order: the target's files share one, the bridging header has its own. + const byOrder = new Map(); + const rootResolver = new Map(); + for (const root of roots) { + const dirs = compileIncludeDirs(inputs, root, unwritten); + const key = dirs.join("\0"); + let group = byOrder.get(key); + if (group === undefined) { + group = { resolver: resolver(r, dirs, files), roots: [] }; + byOrder.set(key, group); + } + group.roots.push(root); + rootResolver.set(root, group.resolver); + } + const groups = [...byOrder.values()]; + const fallback = groups[0]?.resolver ?? resolver(r, precheckIncludeDirs(inputs), files); + for (const g of groups) { + const dirs = g.resolver.includeDirs; + r.write(`# pass 2: ${g.roots.map(r.name).join(", ")} searches ${dirs.length} include folders, in order\n${dirs.map((d) => ` ${d}`).join("\n")}`); + } + if (groups.length === 0) r.write("# pass 2: no compile reads the copy's files"); + const forRoot = (root: string): Resolver => rootResolver.get(root) ?? fallback; + + // Errors only where clang surely reads the file: a header reached only through an uncertain include may never be. + const reach = groups.map((g) => ({ + resolver: g.resolver, + compiled: new Set(g.roots.flatMap((f) => g.resolver.reach(f, false))), + surely: new Set(g.roots.flatMap((f) => g.resolver.reach(f, true))), + })); + const system = systemHeaders(inputs); + const targets = new Set(inputs.graph.targets); + let errors = 0; + for (const file of files) { + const by = reach.filter((g) => g.compiled.has(file)); + // Per include, the line of the compile that judges it most severely (a miss two compiles share is told once). + const verdicts = new Map(); + for (const g of by.length > 0 ? by : [{ resolver: fallback, compiled: new Set(), surely: new Set() }]) { + for (const inc of g.resolver.of(file)) { + if (!inc.certain || inc.generated || inc.found !== undefined || system.has(inc.spelling)) continue; + const at = `${r.name(inc.file)}:${inc.line} imports ${inc.spelling}`; + const first = inc.spelling.split("/")[0]!; + let verdict: { rank: number; line: string; error: boolean }; + if (!g.compiled.has(file)) { + verdict = { rank: 0, line: `⚠ precheck — ${at}, which nothing compiles; checked by xtool-build if it is ever included`, error: false }; + } else if (!g.surely.has(file)) { + verdict = { rank: 1, line: `⚠ precheck — ${at}, which only a condition the precheck cannot evaluate includes; the compile decides`, error: false }; + } else if (inc.angle && targets.has(first)) { + verdict = { rank: 2, line: `⚠ precheck — ${at}, which rn-xtool did not find; ${first} is a target of the package, so the compile decides`, error: false }; + } else if (inc.angle && !system.resource) { + verdict = { rank: 2, line: `⚠ precheck — ${at}, which rn-xtool did not find; the compile decides`, error: false }; + } else { + const count = g.resolver.includeDirs.length; + verdict = { rank: 3, line: `✖ precheck — ${at}, which is in none of the App target's ${count} include folders (listed in ${r.name(r.logFile)})`, error: true }; + } + const key = `${inc.line}\0${inc.spelling}`; + const seen = verdicts.get(key); + if (seen === undefined || verdict.rank > seen.rank) verdicts.set(key, verdict); + } + } + for (const v of verdicts.values()) { + if (v.error) errors++; + r.show(v.line); + } + } + if (errors > 0) throw precheckStop(errors, r.name(r.logFile)); + return { forRoot, reached: (root) => forRoot(root).reached(root) }; +} + +const withoutComments = (text: string): string => text.replace(/\/\*[\s\S]*?\*\//g, " ").replace(/\/\/.*$/gm, ""); +const readText = (file: string): string => { + try { + return readFileSync(file, "utf8"); + } catch { + return ""; + } +}; + +/** `import M`, `@attr import M`, `public import M`, `import struct M.X`: the modules a Swift file imports. */ +const SWIFT_IMPORT = + /^\s*(?:(?:@\w+(?:\([^)]*\))?|public|internal|package|private|fileprivate)\s+)*import\s+(?:(?:typealias|struct|class|enum|protocol|let|var|func)\s+)?([A-Za-z_]\w*)/; +/** `@import M;` and `@import M.Sub;` in a C-family file. */ +const AT_IMPORT = /^\s*@import\s+([A-Za-z_]\w*)/; + +/** + * The modules `text` imports, one per statement `pattern` matches (comments aside): lines split at `;` too, so that + * `import UIKit; import Expo` is two (a `;` inside a string on an import line is not looked for). + */ +function moduleImports(text: string, pattern: RegExp): string[] { + return withoutComments(text) + .split(/\r?\n|;/) + .flatMap((line) => { + const m = pattern.exec(line); + return m ? [m[1]!] : []; + }); +} + +/** + * The files that import a module whose map Swift Build has not written yet: a C-family file or the bridging header + * whose reach `@import`s one, a Swift file that `import`s one. When swiftc would read one (a Swift file, or the + * bridging header), every Swift file waits. Named in the module-map `ℹ` line; none of them is compiled. + */ +function waitingForMaps(r: Run, includes: Includes, maps: ImporterMaps): Set { + if (maps.missing.size === 0) return new Set(); + const needs = (modules: string[]) => modules.some((m) => maps.missing.has(m)); + const atImports = (file: string) => includes.reached(file).flatMap((f) => moduleImports(readText(f), AT_IMPORT)); + const swift = Object.keys(r.app.origins).filter((f) => path.extname(f) === ".swift"); + const waiting = compileRoots(r).filter((f) => needs(atImports(f))); + const bridging = r.app.pkg.app.bridgingHeader; + const swiftWaits = swift.some((f) => needs(moduleImports(readText(f), SWIFT_IMPORT))) || (bridging !== undefined && waiting.includes(bridging)); + const all = new Set([...waiting, ...(swiftWaits ? swift : [])]); + maps.skip([...all]); + return all; +} + +/** Why the precheck cannot place module `m` that a file imports: SwiftPM builds it from Swift, or no map declares it. */ +const whyUnplaced = (inputs: PrecheckInputs, m: string): string => + inputs.graph.swiftModules.includes(m) ? "which SwiftPM builds" : "which no module map of the package graph declares"; + +/** The SDK has module `m`: a framework, or a Swift module of its own. */ +const sdkHas = (sdk: string, m: string): boolean => + isDir(path.join(sdk, "System", "Library", "Frameworks", `${m}.framework`)) || existsSync(path.join(sdk, "usr", "lib", "swift", `${m}.swiftmodule`)); + +/** + * The compile roots, not already waiting for a module map, whose reach `@import`s a module SwiftPM builds from Swift + * (`graph.swiftModules`) or one no map declares (not a module of the graph's maps, of the SDK, or of an importer map + * Swift Build wrote): file → that module. clang would not find the module as Swift Build gives it, so none of them is + * compiled; one `ℹ` line per module names the first file, and the log lists them all. B1 never errors on `@import`. + */ +function importsSwiftBuilt(r: Run, inputs: PrecheckInputs, includes: Includes, maps: ImporterMaps, waiting: Set): Map { + const swiftBuilt = new Set(inputs.graph.swiftModules); + const modules = new Set(inputs.graph.modules); + const importer = new Set((r.app.pkg.expo?.clangImporter?.moduleMaps ?? []).map((m) => path.basename(m, ".modulemap"))); + const placed = (m: string): boolean => + !swiftBuilt.has(m) && (modules.has(m) || importer.has(m) || maps.missing.has(m) || sdkHas(inputs.toolchain.sdk, m)); + const out = new Map(); + const byModule = new Map(); + for (const root of compileRoots(r)) { + if (waiting.has(root)) continue; + const module = includes + .reached(root) + .flatMap((f) => moduleImports(readText(f), AT_IMPORT)) + .find((m) => !placed(m)); + if (module === undefined) continue; + out.set(root, module); + byModule.set(module, [...(byModule.get(module) ?? []), root]); + } + for (const [module, files] of byModule) { + r.show(`ℹ precheck — ${r.name(files[0]!)} imports the module ${module}, ${whyUnplaced(inputs, module)}; checked by xtool-build`); + r.write(`# not compiled, imports the module ${module}: ${files.join(" ")}`); + } + return out; +} + +/** + * Hop 2: one `swiftc -typecheck` over the App's Swift files, writing `App-Swift.h`. Not run without Swift files, while + * they wait for a module map, when a file imports a module the SDK does not have and the graph has only as clang's + * (SwiftPM builds it from Swift, or it is in no map), nor when the bridging header imports one (`swiftBuilt`): one + * `ℹ` line, the first such import. Undefined when swiftc did not run. + */ +async function swiftHop( + r: Run, + inputs: PrecheckInputs, + waiting: Set, + swiftBuilt: Map, + maps: ImporterMaps, +): Promise { + const files = Object.keys(r.app.origins).filter((f) => path.extname(f) === ".swift"); + if (files.length === 0 || files.some((f) => waiting.has(f))) return undefined; + const modules = new Set(inputs.graph.modules); + const fromSwift = new Set(inputs.graph.swiftModules); + const known = (m: string): boolean => (modules.has(m) && !fromSwift.has(m)) || sdkHas(inputs.toolchain.sdk, m); + for (const file of files) { + const unknown = moduleImports(readFileSync(file, "utf8"), SWIFT_IMPORT).find((m) => !known(m)); + if (unknown !== undefined) { + r.show(`ℹ precheck — ${r.name(file)} imports ${unknown}, ${whyUnplaced(inputs, unknown)}: checked by xtool-build`); + return undefined; + } + } + const bridging = r.app.pkg.app.bridgingHeader; + const throughBridging = bridging !== undefined ? swiftBuilt.get(bridging) : undefined; + if (bridging !== undefined && throughBridging !== undefined) { + // swiftc reads the bridging header: the module is as far from it as from clang. + r.show(`ℹ precheck — ${r.name(bridging)} imports ${throughBridging}, ${whyUnplaced(inputs, throughBridging)}: checked by xtool-build`); + return undefined; + } + const args = maps.drop(["-no-color-diagnostics", ...swiftcArgs(inputs, files, maps.missing)]); + return withRetry(r, inputs, async () => [await compileOne(r, inputs.toolchain.swiftc, args, files)]); +} + +/** + * Hop 3: `clang -fsyntax-only` per C-family file, `os.availableParallelism()` at a time; the bridging header too when + * swiftc did not read it. A file in `waiting` (for a module map, or importing a module SwiftPM builds from Swift) is + * not compiled, nor one that imports, itself or through the + * copy's headers, a `-Swift.h` the precheck did not write: one `ℹ` line per such header. + */ +async function cFamilyHop( + r: Run, + inputs: PrecheckInputs, + swiftRan: boolean, + includes: Includes, + waiting: Set, + maps: ImporterMaps, +): Promise { + const files = Object.keys(r.app.origins).filter((f) => C_FAMILY.has(path.extname(f))); + const bridging = r.app.pkg.app.bridgingHeader; + if (!swiftRan && bridging !== undefined && path.extname(bridging) === ".h") files.push(bridging); + + const unwritten = swiftHeadersNotWritten(r, includes); + const skipped = new Map(); + const compiled = files.filter((file) => { + if (waiting.has(file)) return false; + const headers = unwritten(file); + for (const h of headers) skipped.set(h, [...(skipped.get(h) ?? []), file]); + return headers.length === 0; + }); + for (const [header, by] of skipped) { + r.show(`ℹ precheck — ${by.map(r.name).join(", ")} import ${header}, which the Swift check did not write: checked by xtool-build`); + } + if (compiled.length === 0) return []; + const commands = compiled.map((file) => ({ file, args: maps.drop(["-fno-color-diagnostics", ...clangArgs(inputs, file, maps.missing)]) })); + return withRetry(r, inputs, () => + mapLimit(commands, availableParallelism(), (c) => compileOne(r, inputs.toolchain.clang, c.args, [c.file])), + ); +} + +/** + * The `-Swift.h` spellings a file imports, itself or through the copy's files it reaches, that do not lead to the + * precheck's Swift header folder (a forward in the copy leads on). + */ +function swiftHeadersNotWritten(r: Run, includes: Includes): (file: string) => string[] { + const written = path.join(r.dir, "swift-headers"); + return (file) => { + const missing = new Set(); + const resolver = includes.forRoot(file); + for (const f of resolver.reached(file)) { + for (const inc of resolver.of(f)) { + if (!inc.generated) continue; + const found = resolver.lookup(f, inc.spelling, inc.angle); + if (found === undefined || !(within(written, found) || within(r.paths.sources, found))) missing.add(inc.spelling); + } + } + return [...missing]; + }; +} + +/** One compiler run, its command line and output appended to the log. */ +async function compileOne(r: Run, cmd: string, args: string[], files: string[]): Promise { + const res = await r.deps.compile(cmd, args, { cwd: r.paths.iosXtool, env: r.env }); + r.write(`$ ${commandLine(cmd, args)}\n${res.output}\n# exit ${res.code}`); + return { files, ...res }; +} + +/** The hop, run once more after removing the module cache when clang said it was stale (row 42). */ +async function withRetry(r: Run, inputs: PrecheckInputs, hop: () => Promise): Promise { + const first = await hop(); + const stale = first.flatMap((u) => u.output.split(/\r?\n/)).find((l) => STALE_MODULE_CACHE.test(l)); + if (stale === undefined) return first; + rmSync(inputs.moduleCache, { recursive: true, force: true }); + r.show(`ℹ precheck — the module cache was stale (${stale.trim()}); checked again without it`); + return hop(); +} + +/** + * Each run's errors, its output parsed on its own; one error several runs report (a header's, through each file that + * includes it) counts once, with the first run's include stack. A run that failed without a diagnostic counts as one + * error, shown with its last lines. Any error: the lines, then the stop. + */ +function report(r: Run, units: Unit[]): void { + const diags: Diagnostic[] = []; + const seen = new Set(); + const silent: string[] = []; + let failures = 0; + for (const unit of units) { + const found = parseDiagnostics(unit.output); + for (const d of found) { + const key = `${d.file}\0${d.line}\0${d.message}`; + if (seen.has(key)) continue; + seen.add(key); + diags.push(d); + } + if (unit.code === 0 || found.length > 0) continue; + failures++; + silent.push( + `✖ precheck — ${unit.files.map(r.name).join(", ")}: compiler exited ${unit.code} without a diagnostic rn-xtool could read`, + ...unit.output.trimEnd().split(/\r?\n/).slice(-FAILURE_TAIL).map((l) => ` ${l}`), + ); + } + const count = diags.length + failures; + if (count === 0) return; + for (const line of [...silent, ...precheckErrorLines(diags, r.name)]) r.show(line); + throw precheckStop(count, r.name(r.logFile)); +} diff --git a/src/pipeline/precheckCommands.ts b/src/pipeline/precheckCommands.ts new file mode 100644 index 0000000..6629da9 --- /dev/null +++ b/src/pipeline/precheckCommands.ts @@ -0,0 +1,381 @@ +import { createHash } from "node:crypto"; +import { accessSync, constants, existsSync, readFileSync } from "node:fs"; +import path from "node:path"; +import { execa } from "execa"; +import { sdkBundle } from "../commands/setup.js"; +import type { GeneratedApp } from "../generate/iosXtool.js"; +import { appClangArgs, appIncludeDirs, appSwiftArgs } from "../generate/packageSwift.js"; +import { toolEnv } from "../tools/exec.js"; +import { IOS_MIN } from "../versions.js"; +import { c99name, type PrecheckGraph } from "./precheckGraph.js"; +import { PrecheckToolchainError } from "./precheckReport.js"; + +/** The compilers and the iPhoneOS SDK `xtool dev build` uses, as the precheck runs them. */ +export interface PrecheckToolchain { + clang: string; + swiftc: string; + /** The iPhoneOS SDK root of the Darwin SDK bundle. */ + sdk: string; + /** The triple's `swiftResourcesPath`: Swift's `-resource-dir` (SwiftShims and the runtime's modules), as SwiftPM passes it. */ + swiftResources: string; + /** The triple's `includeSearchPaths` (XCTest's folder), each Swift's `-Isystem` as Swift Build passes them. */ + swiftIncludes: string[]; + /** The Swift options of the bundle's toolsets for arm64-apple-ios, without `-use-ld=…` (nothing is linked). */ + swiftExtra: string[]; + /** `clang --version`, `swiftc --version` and `darwin-sdk-version.txt`: what the module cache depends on. */ + versions: string; +} + +const IOS_TRIPLE = "arm64-apple-ios"; +const TARGET = `${IOS_TRIPLE}${IOS_MIN}`; + +/** The absolute path of the executable `name` in `env.PATH`, or undefined. */ +function findOnPath(name: string, env: NodeJS.ProcessEnv): string | undefined { + for (const dir of (env.PATH ?? "").split(path.delimiter)) { + if (!dir) continue; + const file = path.join(dir, name); + try { + accessSync(file, constants.X_OK); + return file; + } catch { + // not in this folder + } + } + return undefined; +} + +function readJson(file: string): unknown { + try { + return JSON.parse(readFileSync(file, "utf8")); + } catch { + return undefined; + } +} + +const strings = (v: unknown): string[] => (Array.isArray(v) ? v.filter((s): s is string => typeof s === "string") : []); + +async function versionText(bin: string, env: NodeJS.ProcessEnv): Promise { + const r = await execa(bin, ["--version"], { env, extendEnv: false, reject: false }); + return `${r.stdout}`.trim() || `${r.stderr}`.trim(); +} + +/** + * `clang` and `swiftc` on the Swift toolchain's PATH (`toolEnv()`), and from the Darwin SDK bundle's `swift-sdk.json` + * the iPhoneOS SDK (`targetTriples["arm64-apple-ios"].sdkRootPath`) and the Swift options of that triple's toolsets. + * Paths in `swift-sdk.json` are relative to its folder. + */ +export async function precheckToolchain(env: NodeJS.ProcessEnv = toolEnv()): Promise { + const found = (tool: string): string => { + const file = findOnPath(tool, env); + if (file === undefined) throw new PrecheckToolchainError(`precheck — ${tool} was not found on the Swift toolchain's PATH; run rn-xtool setup`); + return file; + }; + const clang = found("clang"); + const swiftc = found("swiftc"); + + const bundle = sdkBundle(); + const sdkJson = path.join(bundle, "swift-sdk.json"); + const notFound = (where: string) => + new PrecheckToolchainError(`precheck — the iPhoneOS SDK was not found in the Darwin SDK (${where}); run rn-xtool setup --xcode-xip `); + type Triple = { sdkRootPath?: unknown; toolsetPaths?: unknown; swiftResourcesPath?: unknown; includeSearchPaths?: unknown }; + const triple = (readJson(sdkJson) as { targetTriples?: Record } | undefined)?.targetTriples?.[IOS_TRIPLE]; + if (typeof triple?.sdkRootPath !== "string") throw notFound(sdkJson); + const sdk = path.resolve(bundle, triple.sdkRootPath); + if (!existsSync(sdk)) throw notFound(sdk); + // Unnamed: the path given is swift-sdk.json's, as for the SDK. + const swiftResources = typeof triple.swiftResourcesPath === "string" ? path.resolve(bundle, triple.swiftResourcesPath) : undefined; + if (swiftResources === undefined || !existsSync(swiftResources)) { + throw new PrecheckToolchainError( + `precheck — the Swift resources were not found in the Darwin SDK (${swiftResources ?? sdkJson}); run rn-xtool setup --xcode-xip `, + ); + } + const swiftIncludes = strings(triple.includeSearchPaths).map((p) => path.resolve(bundle, p)); + + const swiftExtra = strings(triple.toolsetPaths) + .flatMap((toolset) => { + const json = readJson(path.resolve(bundle, toolset)) as { swiftCompiler?: { extraCLIOptions?: unknown } } | undefined; + return strings(json?.swiftCompiler?.extraCLIOptions); + }) + .filter((o) => !o.startsWith("-use-ld=")); + + let sdkVersion = ""; + try { + sdkVersion = readFileSync(path.join(bundle, "darwin-sdk-version.txt"), "utf8").trim(); + } catch { + // an older bundle without it: the compilers' versions still key the cache + } + const versions = [await versionText(clang, env), await versionText(swiftc, env), sdkVersion].join("\n"); + return { clang, swiftc, sdk, swiftResources, swiftIncludes, swiftExtra, versions }; +} + +/** `rn-`: the module cache's folder under `/ModuleCache`. */ +export function moduleCacheKey(rnVersion: string, versions: string): string { + return `rn${rnVersion}-${createHash("sha256").update(versions).digest("hex").slice(0, 12)}`; +} + +export interface PrecheckInputs { + app: GeneratedApp; + graph: PrecheckGraph; + toolchain: PrecheckToolchain; + /** `ios-xtool/.precheck`. */ + dir: string; + /** `/ModuleCache/`. */ + moduleCache: string; +} + +/** + * Swift's `-package-name`, as SwiftPM derives it: the generated package's identity (its folder's name, lower-cased; the + * precheck's folder is in it) as a C99 name, `ios_xtool`. `package` declarations need it. + */ +const packageName = (i: PrecheckInputs): string => c99name(path.basename(path.dirname(i.dir)).toLowerCase()); + +/** The platform's and the SDK's developer frameworks (XCTest's), which Swift Build searches after the SDK's. */ +const developerFrameworks = (sdk: string): string[] => [ + path.join(sdk, "..", "..", "Library", "Frameworks"), + path.join(sdk, "Developer", "Library", "Frameworks"), +]; + +/** Where the precheck's `swiftc` writes `App-Swift.h`, in place of Swift Build's folder. */ +const swiftHeaders = (i: PrecheckInputs): string => path.join(i.dir, "swift-headers"); + +/** Where the precheck writes the module map SwiftPM synthesizes for `module`. */ +export function synthesizedModuleMap(dir: string, module: string): string { + return path.join(dir, "modulemaps", module, "module.modulemap"); +} + +/** The module Swift Build's importer map `map` is for: each is named for its module. */ +const importerModule = (map: string): string => path.basename(map, ".modulemap"); + +/** The header folder a synthesized map's umbrella names: the longest of the graph's folders it names or is inside. */ +function synthesizedFolder(headerDirs: string[], text: string): string | undefined { + return headerDirs.filter((d) => text.includes(`"${d}"`) || text.includes(`"${d}/`)).sort((a, b) => b.length - a.length)[0]; +} + +/** The module maps of a command, one per module, and what the target's own flags and the graph's folders give up. */ +interface ModuleMaps { + /** The graph's maps on disk, then the synthesized maps that stand in (after the target's own importer maps). */ + maps: string[]; + /** Swift Build's importer maps of a module a map on disk declares: left out of the target's flags. */ + shadowed: Set; + /** The header folders of the synthesized maps that gave way to Swift Build's own: left out too. */ + folders: Set; +} + +/** + * The module maps, one per module (two maps of one module are a redefinition). On the command line Swift Build's + * importer maps (`expo.clangImporter.moduleMaps`, in the target's own flags) come first, for the modules the graph's + * maps on disk do not declare; then the graph's on disk (`graphHeaders` synthesizes none for a module they declare); + * then a synthesized map for each module neither names. Swift Build gives the App no header folder for a module whose + * map it writes (a mixed Swift and Objective-C target), so a synthesized map that gives way takes its folder with it. A module in `unwritten`, whose importer map Swift Build has not written yet (the + * precheck drops that map from the command), keeps its synthesized map and folder. + */ +function moduleMaps(i: PrecheckInputs, unwritten: ReadonlySet): ModuleMaps { + const synthesized = new Set(i.graph.synthesized.map((s) => s.module)); + const onDisk = new Set(i.graph.modules.filter((m) => !synthesized.has(m))); + const importer = i.app.pkg.expo?.clangImporter?.moduleMaps ?? []; + const shadowed = new Set(importer.filter((m) => onDisk.has(importerModule(m)))); + const swiftBuilds = new Set(importer.filter((m) => !shadowed.has(m)).map(importerModule).filter((m) => !unwritten.has(m))); + const gaveWay = i.graph.synthesized.filter((s) => swiftBuilds.has(s.module)); + return { + maps: [ + ...i.graph.moduleMaps, + ...i.graph.synthesized.filter((s) => !swiftBuilds.has(s.module)).map((s) => synthesizedModuleMap(i.dir, s.module)), + ], + shadowed, + folders: new Set(gaveWay.flatMap((s) => synthesizedFolder(i.graph.headerDirs, s.text) ?? [])), + }; +} + +/** `args` without the `-fmodule-map-file=` of each of `maps`, and the `-Xcc` before it. */ +function withoutMaps(args: string[], maps: Set): string[] { + const kept: string[] = []; + for (const arg of args) { + if (arg.startsWith("-fmodule-map-file=") && maps.has(arg.slice("-fmodule-map-file=".length))) { + if (kept.at(-1) === "-Xcc") kept.pop(); + continue; + } + kept.push(arg); + } + return kept; +} + +/** + * `args` with Swift Build's header folder moved to the precheck's wherever a path starts with it: an element of its + * own, or after a flag joined to it (`-I`, `-fmodule-map-file=/X.modulemap`). + */ +function withPrecheckHeaders(i: PrecheckInputs, args: string[]): string[] { + const from = i.app.pkg.app.swiftHeadersDir; + const to = swiftHeaders(i); + return args.map((arg) => { + const at = arg.indexOf(from); + if (at < 0) return arg; + const flag = arg.slice(0, at); + const rest = arg.slice(at + from.length); + const isPath = /^(-[A-Za-z][\w-]*=?)?$/.test(flag) && (rest === "" || rest.startsWith("/")); + return isPath ? `${flag}${to}${rest}` : arg; + }); +} + +/** The App target's include folders, Swift Build's header folder replaced by the precheck's, then the graph's. */ +export function precheckIncludeDirs(i: PrecheckInputs): string[] { + return [...withPrecheckHeaders(i, appIncludeDirs(i.app.pkg.app, i.app.pkg.expo)), ...i.graph.headerDirs]; +} + +type Language = "objective-c" | "objective-c++" | "c" | "c++"; + +const LANGUAGES: Record = { + ".m": "objective-c", + ".mm": "objective-c++", + ".c": "c", + ".cc": "c++", + ".cpp": "c++", + ".cxx": "c++", + ".h": "objective-c", +}; + +function languageOf(file: string): Language { + const language = LANGUAGES[path.extname(file).toLowerCase()]; + if (language === undefined) throw new Error(`precheck: no clang language for ${file}`); + return language; +} + +/** + * What Swift Build defines for a package target in a Debug build, besides the manifest's own settings: Swift's + * conditions, its clang importer's macros, and a C-family file's macros (C++ adds libc++'s hardening mode). + */ +export const SWIFT_BUILD_DEFINES = { + swift: ["SWIFT_PACKAGE", "DEBUG", "SWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE", "Xcode"], + importer: ["SWIFT_PACKAGE", "DEBUG=1", "_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG"], + clang: ["SWIFT_PACKAGE", "DEBUG=1", "OBJC_OLD_DISPATCH_PROTOTYPES=1", "Xcode"], + cxx: ["_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG"], +}; + +/** What `appSwiftArgs` gives Swift's clang importer: its `-F ` pairs and the values after each `-Xcc`. */ +function importerArgs(args: string[]): string[] { + return args.flatMap((a, n) => { + if (n === 0) return []; + if (args[n - 1] === "-F") return ["-F", a]; + return args[n - 1] === "-Xcc" ? [a] : []; + }); +} + +/** + * `clang -fsyntax-only` of one C-family file, as Swift Build compiles it in the App target. The bridging header is + * not a file of the target: Swift's clang importer reads it, in a mixed target too, so it gets what the importer gets + * (expo-58-bridging's swiftDriver): Swift Build's importer macros (`-Xcc -DSWIFT_PACKAGE`, `-DDEBUG=1` and libc++'s + * hardening mode), the `-F` frameworks and the `-Xcc` values of `appSwiftArgs` (the target's own defines among them), + * and no `-fmodule-name=App`. + */ +export function clangArgs(i: PrecheckInputs, file: string, unwritten: ReadonlySet = new Set()): string[] { + const language = languageOf(file); + const objc = language === "objective-c" || language === "objective-c++"; + const cxx = language === "c++" || language === "objective-c++"; + return [ + "-fsyntax-only", + "-x", + language, + "-target", + TARGET, + "-isysroot", + i.toolchain.sdk, + ...developerFrameworks(i.toolchain.sdk).flatMap((d) => ["-iframework", d]), + ...(objc ? ["-fobjc-arc"] : []), + "-fmodules", + // A file of the App target, as Swift Build compiles one; the importer's bridging header gets none. + ...(readByImporter(i, file) ? [] : ["-fmodule-name=App"]), + // With C++ modules off the cache is unused, and clang warns about the flag. + ...(cxx ? ["-fno-cxx-modules"] : [`-fmodules-cache-path=${i.moduleCache}`]), + ...searchArgs(i, file, cxx, unwritten), + file, + ]; +} + +/** Swift's clang importer reads `file`: the bridging header, the one C-family file of a target without C-family sources. */ +const readByImporter = (i: PrecheckInputs, file: string): boolean => !i.app.pkg.app.mixed || file === i.app.pkg.app.bridgingHeader; + +/** + * Where `clangArgs` tells clang to look for `file`'s headers and what it defines, in the line's order. A file of the + * target: the graph's header folders, then the defines and the target's own flags (Swift Build's order, objc-088's + * `.resp`). The bridging header: the importer's macros, the target's flags, then the graph's folders (swiftc's + * `-Xcc` order, expo-58-bridging's swiftDriver). + */ +function searchArgs(i: PrecheckInputs, file: string, cxx: boolean, unwritten: ReadonlySet): string[] { + const { app, expo } = i.app.pkg; + const maps = moduleMaps(i, unwritten); + const graph = i.graph.headerDirs.filter((d) => !maps.folders.has(d)).flatMap((d) => ["-I", d]); + const own = (target: string[]): string[] => withPrecheckHeaders(i, withoutMaps(target, maps.shadowed)); + const mapFlags = maps.maps.map((m) => `-fmodule-map-file=${m}`); + if (readByImporter(i, file)) { + return [...SWIFT_BUILD_DEFINES.importer.map((d) => `-D${d}`), ...own(importerArgs(appSwiftArgs(app, expo))), ...graph, ...mapFlags]; + } + const defines = [...SWIFT_BUILD_DEFINES.clang, ...(cxx ? SWIFT_BUILD_DEFINES.cxx : [])]; + return [...graph, ...defines.map((d) => `-D${d}`), ...own(appClangArgs(app, expo, cxx)), ...mapFlags]; +} + +/** + * The folders B1 pass 2 searches for the headers of `root` (a compile root) and of every file it reaches, in the order + * of the compile that reads it: the `-I` folders of `clangArgs`' line (`searchArgs`), then those of + * `precheckIncludeDirs` the line does not name (a folder whose module map Swift Build writes instead), which only + * answer what the line's own folders do not. + */ +export function compileIncludeDirs(i: PrecheckInputs, root: string, unwritten: ReadonlySet = new Set()): string[] { + const args = searchArgs(i, root, false, unwritten); + const dirs: string[] = []; + for (let n = 0; n < args.length; n++) { + const a = args[n]!; + if (a === "-I") dirs.push(args[++n]!); + else if (a.startsWith("-I")) dirs.push(a.slice("-I".length)); + } + return [...new Set([...dirs, ...precheckIncludeDirs(i)])]; +} + +/** + * `swiftc -typecheck` of the App's Swift files, writing `App-Swift.h` to the precheck's header folder. App is a library + * target (the precheck refuses an executable one), which Swift Build compiles with `-parse-as-library`: without it a + * one-file module's file is its main file, where an `@main` type is an error. The clang importer gets Swift Build's + * macros (`DEBUG=1`: React Native's headers hide their debug API without it) and, in a mixed target, the App's own, + * which the manifest's `cSettings` give Swift Build; a Swift-only target has them only with its bridging header. + */ +export function swiftcArgs(i: PrecheckInputs, files: string[], unwritten: ReadonlySet = new Set()): string[] { + const { app, expo } = i.app.pkg; + const maps = moduleMaps(i, unwritten); + return [ + "-typecheck", + "-parse-as-library", + "-module-name", + "App", + "-target", + TARGET, + "-sdk", + i.toolchain.sdk, + "-resource-dir", + i.toolchain.swiftResources, + // The importer's clang headers, as Swift Build names them: the Swift resources' own. + "-Xcc", + "-resource-dir", + "-Xcc", + path.join(i.toolchain.swiftResources, "clang"), + "-package-name", + packageName(i), + // Swift Build's Debug feature: `@DebugDescription` expands. + "-enable-experimental-feature", + "DebugDescriptionMacro", + "-swift-version", + "5", + "-module-cache-path", + i.moduleCache, + "-emit-objc-header-path", + path.join(swiftHeaders(i), "App-Swift.h"), + ...i.toolchain.swiftExtra, + ...SWIFT_BUILD_DEFINES.swift.map((d) => `-D${d}`), + ...[...new Set([...SWIFT_BUILD_DEFINES.importer, ...(app.mixed ? app.defines : [])])].flatMap((d) => ["-Xcc", `-D${d}`]), + ...withPrecheckHeaders(i, withoutMaps(appSwiftArgs(app, expo), maps.shadowed)), + // After the target's own `-F`, as Swift Build orders them (expo-58-bridging's swiftDriver). + ...i.toolchain.swiftIncludes.flatMap((d) => ["-Isystem", d]), + ...developerFrameworks(i.toolchain.sdk).flatMap((d) => ["-F", d]), + // The importer's only: Swift Build gives Swift no search path for a clang target's headers. + ...i.graph.headerDirs.filter((d) => !maps.folders.has(d)).flatMap((d) => ["-Xcc", `-I${d}`]), + ...maps.maps.flatMap((m) => ["-Xcc", `-fmodule-map-file=${m}`]), + ...files, + ]; +} diff --git a/src/pipeline/precheckGraph.ts b/src/pipeline/precheckGraph.ts new file mode 100644 index 0000000..175b975 --- /dev/null +++ b/src/pipeline/precheckGraph.ts @@ -0,0 +1,437 @@ +import { existsSync, readdirSync, readFileSync, realpathSync, statSync, type Dirent } from "node:fs"; +import { availableParallelism } from "node:os"; +import path from "node:path"; +import { devEnv } from "../tools/xtool.js"; +import { PrecheckError } from "./precheckReport.js"; +import { readXcframeworkSlices } from "./rnArtifacts.js"; + +/** `swift` (from `toolEnv()`'s PATH) with `args`; a non-zero exit resolves. */ +export type SwiftRunner = ( + args: string[], + opts: { cwd: string; env: NodeJS.ProcessEnv }, +) => Promise<{ code: number; stdout: string; stderr: string }>; + +/** What the precheck reads of `swift package dump-package`, with the package's folder. */ +export interface DumpedPackage { + name: string; + path: string; + /** + * The packages the manifest depends on: SwiftPM's identity, the name the manifest gives it + * (`nameForTargetDependencyResolutionOnly`, what a `package:` reference names) and its folder when it has one. + */ + dependencies: { identity: string; name?: string; path?: string }[]; + products: { name: string; targets: string[] }[]; + targets: { + name: string; + type: string; + path?: string | null; + publicHeadersPath?: string | null; + /** The manifest's `sources` (relative to the target's folder); absent: the whole folder. */ + sources?: string[]; + /** The manifest's `exclude`, relative to the target's folder. */ + exclude?: string[]; + /** The paths of the manifest's `resources`, relative to the target's folder. */ + resources?: string[]; + dependencies: unknown[]; + }[]; +} + +type Graph = { root: DumpedPackage; packages: DumpedPackage[] }; +type Target = DumpedPackage["targets"][number]; + +export interface PrecheckGraph { + /** The public header folders of the targets App reaches, in dependency order. */ + headerDirs: string[]; + /** The module maps on disk in those folders. */ + moduleMaps: string[]; + /** The module maps SwiftPM synthesizes for those folders (written by the precheck). */ + synthesized: { module: string; text: string }[]; + /** + * Every target name and every product name of every package in the graph (per package: its targets, then its + * products), each once: the names that could provide an angle include's first path component (row 37). + */ + targets: string[]; + /** Every module the module maps declare, then the synthesized ones. */ + modules: string[]; + /** + * The modules of the targets SwiftPM builds from Swift: each reached target whose sources hold a `.swift` file, by + * its C99 name and the modules its own module map declares. Their clang half alone (in `modules`) is not the module + * Swift Build gives an importer. + */ + swiftModules: string[]; + /** The references the walk could not place (` of `, or a by-name reference), each once. */ + unresolved: string[]; +} + +const MANIFEST = "ios-xtool/Package.swift"; + +/** `head`, then SwiftPM's `error:` lines of `stderr` (all of its lines when it has none). */ +function withSwiftLines(head: string, stderr: string): string { + const lines = stderr.split(/\r?\n/).filter((l) => l.trim() !== ""); + const errors = lines.filter((l) => /\berror:/.test(l)); + const shown = errors.length > 0 ? errors : lines; + return shown.length > 0 ? `${head}:\n${shown.join("\n")}` : head; +} + +/** The JSON object SwiftPM printed, or undefined when there is none. */ +function parseJson(stdout: string): unknown { + const start = stdout.search(/^\{/m); + if (start < 0) return undefined; + try { + return JSON.parse(stdout.slice(start)); + } catch { + return undefined; + } +} + +/** + * `swift package describe --type json` in `iosXtool`: SwiftPM plans the generated package. A `main` file makes App an + * executable target (SwiftPM prints the plan and exits non-zero): named first; any other refusal with SwiftPM's lines. + */ +export async function planManifest(iosXtool: string, run: SwiftRunner): Promise { + const r = await run(["package", "describe", "--type", "json"], { cwd: iosXtool, env: devEnv(iosXtool) }); + const plan = parseJson(r.stdout) as { targets?: { name?: unknown; type?: unknown }[] } | undefined; + const app = Array.isArray(plan?.targets) ? plan.targets.find((t) => t?.name === "App") : undefined; + if (app?.type === "executable") { + throw new PrecheckError( + "precheck — SwiftPM plans the App target as an executable target (a file named main); xtool links the app's entry point from the App library", + ); + } + if (r.code !== 0) throw new PrecheckError(withSwiftLines(`precheck — SwiftPM refused the generated package (${MANIFEST})`, r.stderr)); + if (plan === undefined) throw new PrecheckError(withSwiftLines(`precheck — SwiftPM gave no plan for the generated package (${MANIFEST})`, r.stderr)); + if (app === undefined) throw new PrecheckError(`precheck — SwiftPM's plan of the generated package (${MANIFEST}) has no App target`); +} + +interface ListedPackage { + name: string; + path: string; +} + +/** The packages `show-dependencies --format json` lists under the root, each once, in its order. */ +function listedPackages(tree: unknown): ListedPackage[] { + const seen = new Map(); + const walk = (node: unknown) => { + const deps = (node as { dependencies?: unknown })?.dependencies; + if (!Array.isArray(deps)) return; + for (const d of deps as { name?: unknown; path?: unknown }[]) { + if (typeof d?.path !== "string" || seen.has(d.path)) continue; + seen.set(d.path, { name: typeof d.name === "string" ? d.name : path.basename(d.path), path: d.path }); + walk(d); + } + }; + walk(tree); + return [...seen.values()]; +} + +/** + * One package dependency of a dump-package output (`{ fileSystem: [..] }`, `{ sourceControl: [..] }`, `{ registry: [..] }`): + * its identity, the manifest's name for it, and its folder (a file-system path, or a local source-control location). + */ +function packageDependency(raw: unknown): DumpedPackage["dependencies"][number] | undefined { + const kinds = raw !== null && typeof raw === "object" ? Object.values(raw as Record) : []; + const entry = (Array.isArray(kinds[0]) ? kinds[0][0] : undefined) as + | { identity?: unknown; nameForTargetDependencyResolutionOnly?: unknown; path?: unknown; location?: { local?: unknown } } + | undefined; + if (typeof entry?.identity !== "string") return undefined; + const name = entry.nameForTargetDependencyResolutionOnly; + const local = Array.isArray(entry.location?.local) ? entry.location.local[0] : undefined; + const dir = typeof entry.path === "string" ? entry.path : typeof local === "string" ? local : undefined; + return { identity: entry.identity, ...(typeof name === "string" ? { name } : {}), ...(dir !== undefined ? { path: dir } : {}) }; +} + +/** The fields the precheck reads of one dump-package output; undefined when it is not one. */ +function dumpedPackage(json: unknown, dir: string): DumpedPackage | undefined { + const raw = json as { name?: unknown; dependencies?: unknown; products?: unknown; targets?: unknown } | undefined; + if (typeof raw?.name !== "string" || !Array.isArray(raw.targets)) return undefined; + const products = Array.isArray(raw.products) ? (raw.products as { name?: unknown; targets?: unknown }[]) : []; + return { + name: raw.name, + path: dir, + dependencies: (Array.isArray(raw.dependencies) ? raw.dependencies : []).flatMap((d) => packageDependency(d) ?? []), + products: products + .filter((p) => typeof p?.name === "string") + .map((p) => ({ name: p.name as string, targets: Array.isArray(p.targets) ? p.targets.filter((n): n is string => typeof n === "string") : [] })), + targets: (raw.targets as Record[]) + .filter((t) => typeof t?.name === "string" && typeof t.type === "string") + .map((t) => ({ + name: t.name as string, + type: t.type as string, + ...(typeof t.path === "string" ? { path: t.path } : {}), + ...(typeof t.publicHeadersPath === "string" ? { publicHeadersPath: t.publicHeadersPath } : {}), + ...(Array.isArray(t.sources) ? { sources: t.sources.filter((x): x is string => typeof x === "string") } : {}), + ...(Array.isArray(t.exclude) ? { exclude: t.exclude.filter((x): x is string => typeof x === "string") } : {}), + ...(Array.isArray(t.resources) ? { resources: resourcePaths(t.resources) } : {}), + dependencies: Array.isArray(t.dependencies) ? t.dependencies : [], + })), + }; +} + +/** The paths of dump-package's `resources` (`{ path, rule }` each). */ +const resourcePaths = (list: unknown[]): string[] => + list.flatMap((r) => { + const at = (r as { path?: unknown } | null)?.path; + return typeof at === "string" ? [at] : []; + }); + +/** `fn` over `items`, at most `limit` at a time; results in `items`' order. */ +async function mapLimit(items: T[], limit: number, fn: (item: T, index: number) => Promise): Promise { + const results: R[] = new Array(items.length); + let next = 0; + const worker = async () => { + while (next < items.length) { + const i = next++; + results[i] = await fn(items[i]!, i); + } + }; + await Promise.all(Array.from({ length: Math.min(limit, items.length) }, worker)); + return results; +} + +/** + * The generated package and every package it depends on, as `dump-package` gives them. `show-dependencies` lists the + * packages; each is dumped with its own `--scratch-path /` (the root is 0), so nothing is written into a + * library's folder, `os.availableParallelism()` at a time. + */ +export async function readPackageGraph(iosXtool: string, scratch: string, run: SwiftRunner): Promise { + const env = devEnv(iosXtool); + const shown = await run(["package", "show-dependencies", "--format", "json"], { cwd: iosXtool, env }); + const tree = shown.code === 0 ? parseJson(shown.stdout) : undefined; + if (tree === undefined) { + throw new PrecheckError(withSwiftLines(`precheck — SwiftPM could not list the dependencies of the generated package (${MANIFEST})`, shown.stderr)); + } + const listed = [{ name: path.basename(iosXtool), path: iosXtool }, ...listedPackages(tree)]; + const dumped = await mapLimit(listed, availableParallelism(), async (p, n) => { + const r = await run(["package", "dump-package", "--package-path", p.path, "--scratch-path", path.join(scratch, String(n))], { cwd: iosXtool, env }); + const pkg = r.code === 0 ? dumpedPackage(parseJson(r.stdout), p.path) : undefined; + if (pkg === undefined) throw new PrecheckError(withSwiftLines(`precheck — SwiftPM could not read the package ${p.name} (${p.path})`, r.stderr)); + return pkg; + }); + return { root: dumped[0]!, packages: dumped.slice(1) }; +} + +const isDir = (p: string): boolean => { + try { + return statSync(p).isDirectory(); + } catch { + return false; + } +}; + +/** SwiftPM's C99 name of a target (its module name) or of a package identity (Swift's `-package-name`). */ +export function c99name(name: string): string { + const s = name.replace(/[^A-Za-z0-9_]/g, "_"); + return /^[0-9]/.test(s) ? `_${s}` : s; +} + +/** + * The module map SwiftPM synthesizes for a clang target's public headers folder `include` without one: + * `.h`, else `/.h`, as the umbrella header (SwiftPM looks for the flat one first); else + * the folder as the umbrella. + */ +function synthesizedModuleMap(module: string, include: string): string { + const flat = path.join(include, `${module}.h`); + const nested = path.join(include, module, `${module}.h`); + const umbrella = existsSync(flat) ? `umbrella header "${flat}"` : existsSync(nested) ? `umbrella header "${nested}"` : `umbrella "${include}"`; + return `module ${module} {\n ${umbrella}\n export *\n}\n`; +} + +/** The top-level modules a module map declares (`module X`, `framework module X`, `extern module X`). */ +function declaredModules(text: string): string[] { + const modules: string[] = []; + let depth = 0; + const tokens = /\/\/[^\n]*|\/\*[\s\S]*?\*\/|"(?:[^"\\]|\\.)*"|\{|\}|\bmodule\s+([A-Za-z_][A-Za-z0-9_]*)/g; + for (const m of text.matchAll(tokens)) { + if (m[0] === "{") depth++; + else if (m[0] === "}") depth = Math.max(0, depth - 1); + else if (m[1] !== undefined && depth === 0) modules.push(m[1]); + } + return modules; +} + +/** One dependency of a dump-package target: a target, a product or a name (a target first, else a product). */ +type Dependency = { kind: "target"; name: string } | { kind: "product"; name: string; package: string } | { kind: "byName"; name: string }; + +function dependency(raw: unknown): Dependency | undefined { + const d = raw as Record | null; + const name = (list: unknown[] | undefined) => (Array.isArray(list) && typeof list[0] === "string" ? list[0] : undefined); + const target = name(d?.target ?? undefined); + if (target !== undefined) return { kind: "target", name: target }; + const product = name(d?.product ?? undefined); + if (product !== undefined) { + const pkg = d!.product![1]; + return { kind: "product", name: product, package: typeof pkg === "string" ? pkg : product }; + } + const byName = name(d?.byName ?? undefined); + return byName !== undefined ? { kind: "byName", name: byName } : undefined; +} + +const realPath = (p: string): string => { + try { + return realpathSync(p); + } catch { + return path.resolve(p); + } +}; + +/** + * The header folders, module maps and module names of the targets the root's `App` target reaches through product, + * target and by-name dependencies, in dependency order (each target before the ones it depends on, a target's + * dependencies in the manifest's order). A reference to package `X` resolves as SwiftPM resolves it: against the + * depending manifest's own dependencies, the one whose name or identity is `X` (case ignored), found among the dumped + * packages by its folder (real paths), else by identity; the package named `X`, or whose folder's lower-cased name is + * `x`, is the last fallback. A by-name reference that is not a target of its package goes the same way. A reference + * still unplaced is listed in `unresolved` (SwiftPM planned the package, so it never stops the precheck). + */ +export function graphHeaders(graph: Graph): PrecheckGraph { + const all = [graph.root, ...graph.packages]; + const real = new Map(all.map((p) => [p, realPath(p.path)])); + const identity = (p: DumpedPackage) => path.basename(p.path).toLowerCase(); + const packageOf = (from: DumpedPackage, ref: string): DumpedPackage | undefined => { + const r = ref.toLowerCase(); + const dep = from.dependencies.find((d) => d.name?.toLowerCase() === r) ?? from.dependencies.find((d) => d.identity.toLowerCase() === r); + if (dep !== undefined) { + const dir = dep.path !== undefined ? realPath(dep.path) : undefined; + const found = all.find((p) => real.get(p) === dir) ?? all.find((p) => identity(p) === dep.identity.toLowerCase()); + if (found !== undefined) return found; + } + return all.find((p) => p.name === ref) ?? all.find((p) => identity(p) === r); + }; + const out: PrecheckGraph = { headerDirs: [], moduleMaps: [], synthesized: [], targets: [], modules: [], swiftModules: [], unresolved: [] }; + const seen = new Set(); + + const visitProduct = (pkg: DumpedPackage | undefined, productName: string, unplaced: string) => { + const product = pkg?.products.find((p) => p.name === productName); + if (pkg === undefined || product === undefined) { + out.unresolved.push(unplaced); + return; + } + for (const name of product.targets) { + const target = pkg.targets.find((t) => t.name === name); + if (target !== undefined) visit(pkg, target); + } + }; + const visit = (pkg: DumpedPackage, target: Target) => { + if (seen.has(target)) return; + seen.add(target); + if (target !== appTarget) { + const declared = addHeaders(pkg, target); + if (target.type === "regular" && hasSwiftSources(pkg, target)) out.swiftModules.push(c99name(target.name), ...declared); + } + for (const raw of target.dependencies) { + const d = dependency(raw); + if (d === undefined) continue; + const local = d.kind === "product" ? undefined : pkg.targets.find((t) => t.name === d.name); + if (local !== undefined) { + visit(pkg, local); + } else if (d.kind === "product") { + visitProduct(packageOf(pkg, d.package), d.name, `${d.name} of ${d.package}`); + } else { + const named = packageOf(pkg, d.name); + const owner = named?.products.some((q) => q.name === d.name) ? named : all.find((p) => p !== pkg && p.products.some((q) => q.name === d.name)); + visitProduct(owner, d.name, d.name); + } + } + }; + /** The target's header folder and module map; the modules its map on disk declares (none: synthesized or no map). */ + const addHeaders = (pkg: DumpedPackage, target: Target): string[] => { + if (target.type === "binary") { + const headers = binaryHeaders(pkg, target); + if (headers === undefined) return []; + out.headerDirs.push(headers); + return addModuleMap(path.join(headers, "module.modulemap")) ?? []; + } + if (target.type !== "regular") return []; + const include = path.join(sourceDir(pkg, target), target.publicHeadersPath ?? "include"); + if (!isDir(include)) return []; + out.headerDirs.push(include); + const declared = addModuleMap(path.join(include, "module.modulemap")); + if (declared !== undefined) return declared; + const module = c99name(target.name); + out.synthesized.push({ module, text: synthesizedModuleMap(module, include) }); + return []; + }; + /** The modules the map declares; undefined when there is no map. */ + const addModuleMap = (file: string): string[] | undefined => { + let text: string; + try { + text = readFileSync(file, "utf8"); + } catch { + return undefined; + } + const declared = declaredModules(text); + out.moduleMaps.push(file); + out.modules.push(...declared); + return declared; + }; + + const appTarget = graph.root.targets.find((t) => t.name === "App"); + if (appTarget !== undefined) visit(graph.root, appTarget); + out.targets = [...new Set(all.flatMap((p) => [...p.targets.map((t) => t.name), ...p.products.map((q) => q.name)]))]; + // One map per module: a module a map on disk declares gets no synthesized one (two would be a redefinition). + const declared = new Set(out.modules); + out.synthesized = out.synthesized.filter((s) => !declared.has(s.module)); + out.modules = [...new Set([...out.modules, ...out.synthesized.map((s) => s.module)])]; + out.swiftModules = [...new Set(out.swiftModules)]; + out.unresolved = [...new Set(out.unresolved)]; + return out; +} + +/** A regular target's folder: its `path`, else `Sources/`. */ +const sourceDir = (pkg: DumpedPackage, target: Target): string => path.join(pkg.path, target.path ?? path.join("Sources", target.name)); + +/** + * The target compiles a Swift file: one of its `sources` is a `.swift` file or a folder holding one, or, without + * `sources`, its folder holds one. Not looked in: dot folders, its `exclude` and `resources` entries and the folders + * of the package's other targets inside its own. A symbolic link to a folder is followed, as SwiftPM follows it, each + * folder once (a link back up the tree ends there). Its public headers folder counts (an Expo mixed target's is its + * whole folder). + */ +function hasSwiftSources(pkg: DumpedPackage, target: Target): boolean { + const dir = sourceDir(pkg, target); + const skipped = new Set([ + ...[...(target.exclude ?? []), ...(target.resources ?? [])].map((e) => path.join(dir, e)), + ...pkg.targets.filter((t) => t !== target && t.type !== "binary").map((t) => sourceDir(pkg, t)).filter((d) => d !== dir), + ]); + const skippedReal = new Set([...skipped].map(realPath)); + const walked = new Set(); + const found = (p: string): boolean => { + if (skipped.has(p)) return false; + if (!isDir(p)) return p.endsWith(".swift") && existsSync(p); + const real = realPath(p); + if (walked.has(real) || (p !== dir && skippedReal.has(real))) return false; + walked.add(real); + let entries: Dirent[]; + try { + entries = readdirSync(p, { withFileTypes: true }); + } catch { + return false; + } + return entries.some((e) => { + const child = path.join(p, e.name); + const folder = e.isDirectory() || (e.isSymbolicLink() && isDir(child)); + return folder ? !e.name.startsWith(".") && found(child) : e.name.endsWith(".swift") && !skipped.has(child); + }); + }; + return (target.sources ?? ["."]).some((s) => found(path.join(dir, s))); +} + +/** + * A binary target's device slice `Headers` (the slice without a platform variant), when it is an xcframework with one. + * An xcframework whose `Info.plist` is missing or unreadable is a `PrecheckError` naming it; a binary target that is no + * xcframework folder (a zip archive) gives none. + */ +function binaryHeaders(pkg: DumpedPackage, target: Target): string | undefined { + if (typeof target.path !== "string" || !target.path.endsWith(".xcframework")) return undefined; + const xcframework = path.join(pkg.path, target.path); + let slices: ReturnType; + try { + slices = readXcframeworkSlices(xcframework); + } catch (e) { + const why = e instanceof Error ? e.message : String(e); + throw new PrecheckError(`precheck — rn-xtool could not read the xcframework ${target.name} (${xcframework}): ${why}`); + } + const device = slices.find((s) => s.SupportedPlatform === "ios" && s.SupportedPlatformVariant === undefined); + if (device === undefined) return undefined; + const headers = path.join(xcframework, device.LibraryIdentifier, device.HeadersPath ?? "Headers"); + return isDir(headers) ? headers : undefined; +} diff --git a/src/pipeline/precheckReport.ts b/src/pipeline/precheckReport.ts new file mode 100644 index 0000000..71b355c --- /dev/null +++ b/src/pipeline/precheckReport.ts @@ -0,0 +1,114 @@ +/** A precheck stop: the message is what the user reads. */ +export class PrecheckError extends Error { + override name = "PrecheckError"; +} + +/** + * The toolchain or the Darwin SDK is incomplete (`precheckToolchain`): xtool-build fails the same way, so the stop names + * `rn-xtool setup` and not the way past the precheck. + */ +export class PrecheckToolchainError extends PrecheckError {} + +/** What every stop the precheck did not plan for ends with: the way past it, and how to report it. */ +export const PRECHECK_EXIT = + "; if xtool-build builds this app, build with rn-xtool build --skip-precheck and report it with rn-xtool doctor --report"; + +/** + * The error a precheck stop throws: a `PrecheckToolchainError`, and a message that already names `--skip-precheck`, + * as they are; any other error, planned or not (rn-xtool's reading of SwiftPM's answers, `ENOSPC`, a bug), a + * `PrecheckError` whose message ends with `PRECHECK_EXIT`. + */ +export function withExit(e: unknown): unknown { + if (e instanceof PrecheckToolchainError) return e; + const message = e instanceof Error ? e.message : String(e); + if (message.includes("--skip-precheck")) return e; + return new PrecheckError(`${message}${PRECHECK_EXIT}`, { cause: e }); +} + +/** One compiler error: where it is, what it says, and the include stack clang printed before it. */ +export interface Diagnostic { + /** "" when the compiler named no file (a driver error, swiftc's `:0`). */ + file: string; + /** 0 when the compiler named no line. */ + line: number; + message: string; + /** The `In file included from ::` lines before it (clang's module-build lines and swiftc's include notes too), in order. */ + stack: string[]; +} + +/** clang's stale or broken module cache: the precheck clears the cache and runs once more (row 42). */ +export const STALE_MODULE_CACHE = + /module file .* is out of date|has been modified since the module file|malformed or corrupted AST file/; + +const SHOWN = 10; +/** `:[:]: : `; the lazy file takes the first such split, so a message may hold `error:`. */ +const LOCATED = /^(.+?):(\d+)(?::\d+)?: (fatal error|error|warning|note|remark): (.*)$/; +/** `error: …` or `: error: …` with no location. */ +const UNLOCATED = /^(?:[^\s:]+: )?(fatal error|error|warning|note|remark): (.*)$/; +/** clang's context lines before a diagnostic: an include, or the module build that reached it. */ +const STACK = /^(In file included from|(?:While building|In) module '[^']*' imported from) (.+):(\d+):$/; +/** A source excerpt or caret line: clang's ` 21 | …`, swiftc's `1 | …` and ` | \`- error: …`. */ +const EXCERPT = /^\s*\d*\s*\|/; +/** swiftc's include trail, a note per include: `::: note: in file included from ::`. */ +const SWIFT_TRAIL = /^in file included from (.+:\d+:)$/; + +/** The errors (and fatal errors) in clang's or swiftc's output; warnings, notes and excerpts dropped (row 51). */ +export function parseDiagnostics(output: string): Diagnostic[] { + const diags: Diagnostic[] = []; + let stack: string[] = []; + // The stack resets at each diagnostic only: swiftc puts excerpts, blank lines and clang's + // `N errors generated.` between its include-trail notes and the error they lead to. + for (const raw of output.split(/\r?\n/)) { + const text = raw.trimEnd(); + if (STACK.test(text)) { + stack.push(text); + continue; + } + if (EXCERPT.test(text)) continue; + const found = diagnostic(text); + if (!found) continue; + if (found.severity === "note") { + const trail = SWIFT_TRAIL.exec(found.message); + if (trail) { + stack.push(`In file included from ${trail[1]}`); + continue; + } + } + if (isError(found.severity)) diags.push({ file: found.file, line: found.line, message: found.message, stack }); + stack = []; + } + return diags; +} + +function diagnostic(text: string): { file: string; line: number; severity: string; message: string } | undefined { + const located = LOCATED.exec(text); + if (located) { + const [, file, line, severity, message] = located; + return file === "" ? { file: "", line: 0, severity, message } : { file, line: Number(line), severity, message }; + } + const unlocated = UNLOCATED.exec(text); + return unlocated ? { file: "", line: 0, severity: unlocated[1], message: unlocated[2] } : undefined; +} + +function isError(severity: string): boolean { + return severity === "error" || severity === "fatal error"; +} + +/** `✖ precheck — :: ` for the first ten, each with its stack (row 50), then `… and more`. */ +export function precheckErrorLines(diags: Diagnostic[], display: (file: string) => string): string[] { + const lines = diags.slice(0, SHOWN).flatMap((d) => [ + d.file === "" ? `✖ precheck — ${d.message}` : `✖ precheck — ${display(d.file)}:${d.line}: ${d.message}`, + ...d.stack.map((s) => ` ${s.replace(STACK, (_, from: string, file: string, line: string) => `${from} ${display(file)}:${line}:`)}`), + ]); + if (diags.length > SHOWN) lines.push(`… and ${diags.length - SHOWN} more`); + return lines; +} + +/** The stop after the error lines: names the log and the way past a false stop (row 39). */ +export function precheckStop(count: number, log: string): PrecheckError { + return new PrecheckError( + `precheck: ${count} error(s) in the app's own sources before xtool-build (the first ten are above; all of them in ${log}). ` + + "If xtool-build compiles these files, this is a false stop: build with rn-xtool build --skip-precheck " + + "and report it with rn-xtool doctor --report", + ); +} diff --git a/src/project/appIncludes.ts b/src/project/appIncludes.ts new file mode 100644 index 0000000..d4a136e --- /dev/null +++ b/src/project/appIncludes.ts @@ -0,0 +1,396 @@ +// B1's include resolution (spec "B. The app target's checks", rows 30–37): each `#import`/`#include` the scanner +// returns for an app file, looked up as clang looks it up in the generated App target. Pure: each file's text is read +// once, every other question goes to `IncludeScope.exists`. Pass 1 (`appIncludesPass1`) runs it over the app's copy +// before the copy exists, with no toolchain: file-system reads only. + +import { existsSync, readdirSync, readFileSync, type Dirent } from "node:fs"; +import path from "node:path"; +import { bareCopyLayout } from "../generate/bareSources.js"; +import { expoBridgingHeaderPath } from "../generate/iosXtool.js"; +import { projectPaths } from "../paths.js"; +import { definesOf, scanIncludes } from "./includeScan.js"; +import { + AmbiguousProjectError, + appXcconfigWarnings, + openPbxproj, + readTargetContent, + resolveSetting, + type BareTargetContent, + type Pbxproj, +} from "./pbxproj.js"; +import type { ProjectInfo, ProjectKind } from "./types.js"; + +export interface IncludeScope { + /** `path`: where the file sits in the copy; `source`: where its text is read; `display`: how messages name it. */ + files: { path: string; source: string; display: string }[]; + exists: (p: string) => boolean; + /** The include folders, in clang's order (after the including file's folder for a quote include). */ + includeDirs: string[]; + defines: ReadonlyMap; +} + +export interface ResolvedInclude { + /** The `display` of the including file. */ + file: string; + line: number; + spelling: string; + angle: boolean; + certain: boolean; + /** The path that answered; absent when no folder did, and for a generated header. */ + found?: string; + /** The folders looked in, in order, up to the one that answered; empty for a generated header or an absolute spelling. */ + searched: string[]; + /** Xcode's generated Swift header (`*-Swift.h`): the build writes it, so it is never looked up (row 36). */ + generated: boolean; +} + +const isGenerated = (spelling: string): boolean => path.posix.basename(spelling).endsWith("-Swift.h"); + +/** + * Resolves the includes of every file in `scope`: a quote include in the including file's copy folder, then in + * `includeDirs` in order; an angle include in `includeDirs` in order; an absolute spelling as it is. `__has_include` + * asks the same lookup: true when it finds the header, unknown otherwise (the header may come from a folder the scope + * lacks, so its branch stays uncertain). + */ +export function resolveIncludes(scope: IncludeScope): ResolvedInclude[] { + const lookup = (from: string, spelling: string, angle: boolean): { found?: string; searched: string[] } => { + // Clang opens an absolute spelling as it is, in no folder. + if (path.isAbsolute(spelling)) return scope.exists(spelling) ? { found: spelling, searched: [] } : { searched: [] }; + const searched: string[] = []; + for (const dir of angle ? scope.includeDirs : [path.dirname(from), ...scope.includeDirs]) { + searched.push(dir); + const candidate = path.join(dir, spelling); + if (scope.exists(candidate)) return { found: candidate, searched }; + } + return { searched }; + }; + + const out: ResolvedInclude[] = []; + for (const file of scope.files) { + const text = readFileSync(file.source, "utf8"); + const hasInclude = (spelling: string, angle: boolean): boolean | undefined => + !isGenerated(spelling) && lookup(file.path, spelling, angle).found !== undefined ? true : undefined; + for (const inc of scanIncludes(text, { defines: scope.defines, hasInclude })) { + const generated = isGenerated(inc.spelling); + const { found, searched } = generated ? { found: undefined, searched: [] } : lookup(file.path, inc.spelling, inc.angle); + out.push({ file: file.display, ...inc, ...(found !== undefined ? { found } : {}), searched, generated }); + } + } + return out; +} + +// --------------------------------------------------------------------------------------------------------------- +// Pass 1 (rows 30–32): the app's own includes, before staging. + +/** The copy's folder of header forwards (`Sources/App/include`), as `copyBareTarget` writes it. */ +const INCLUDE_DIR = "include"; +/** Folders of ios/ that hold no app files: CocoaPods', build output, and rn-xtool's own. */ +const NOT_APP_DIRS = new Set(["Pods", "build", "DerivedData", "ios-xtool"]); + +/** + * Lowercased file name → the files of that name under `iosDir`, sorted by path. Not walked: the top-level folders of + * `NOT_APP_DIRS`, dot folders and `node_modules`; symbolic links to folders are not followed. + */ +function iosFileIndex(iosDir: string): Map { + const index = new Map(); + const walk = (dir: string, top: boolean): void => { + let entries: Dirent[]; + try { + entries = readdirSync(dir, { withFileTypes: true }).sort((x, y) => (x.name < y.name ? -1 : x.name > y.name ? 1 : 0)); + } catch { + return; + } + for (const e of entries) { + const p = path.join(dir, e.name); + if (e.isDirectory()) { + if (!e.name.startsWith(".") && e.name !== "node_modules" && !(top && NOT_APP_DIRS.has(e.name))) walk(p, false); + } else { + const key = e.name.toLowerCase(); + index.set(key, [...(index.get(key) ?? []), p]); + } + } + }; + walk(iosDir, true); + return index; +} + +/** `p` relative to the project root, with forward slashes; as it is when outside the root. */ +function fromRoot(root: string, p: string): string { + const rel = path.relative(root, p); + return rel === "" || rel.startsWith("..") || path.isAbsolute(rel) ? p : rel.split(path.sep).join("/"); +} + +/** + * The files pass 1 reads: the app target's C-family sources, its kept headers and its bridging header, each at its + * place in the copy under `sources` (`bareCopyLayout`), named relative to the project root (`ios/ObjcApp/main.m`). A + * listed file missing on disk is left out: the copy stops on it with its own message. + */ +export function bareScope( + bare: BareTargetContent, + iosDir: string, + iosTargetDir: string, + sources: string, + root: string, +): IncludeScope["files"] { + const swift = new Set(bare.swiftSources); + return bareCopyLayout(bare, iosDir, iosTargetDir) + .files.filter(({ file }) => !swift.has(file) && existsSync(file.absPath)) + .map(({ file, dest }) => ({ path: path.join(sources, dest), source: file.absPath, display: fromRoot(root, file.absPath) })); +} + +export interface Pass1Input { + root: string; + files: IncludeScope["files"]; + /** A header's base name → its place in the copy, relative to `sources` (`BareCopyLayout.forwards`). */ + forwards: Map; + /** Where the copy goes (`ios-xtool/Sources/App`); it is not read: the build writes it afresh. */ + sources: string; + /** Absolute, in the project's order. */ + headerSearchPaths: string[]; + /** The target's `GCC_PREPROCESSOR_DEFINITIONS` entries. */ + defines: string[]; + /** The headers the app target references, on disk or not (and its bridging header), by their paths from ios/. */ + appHeaders: string[]; + /** The project uses binary pods, whose headers pass 1 cannot see. */ + binaryPods: boolean; + /** `files` is an Expo app's bridging header, the one file of ios/ generate copies. */ + expo?: boolean; +} + +export interface Pass1Result { + /** One line per app-own include that resolves nowhere (row 30), without the `✖ ` mark. */ + missing: string[]; + /** Includes left to the build: React Native's or the libraries' headers (row 32). */ + pending: number; + /** The certain includes that resolved. */ + checked: number; +} + +/** A quote spelling without its leading `./` and `../` segments: the part a file's path must end with. */ +const pathTail = (spelling: string): string => spelling.replace(/^(?:\.\.?\/)+/, ""); + +/** `file` (forward slashes) is `tail`, or ends with `/`. */ +const endsWithPath = (file: string, tail: string): boolean => file === tail || file.endsWith(`/${tail}`); + +/** "a, b or c" */ +function orList(items: readonly string[]): string { + return items.length < 2 ? items.join("") : `${items.slice(0, -1).join(", ")} or ${items[items.length - 1]}`; +} + +/** + * Pass 1 of B1: the includes of `files` resolved in the app's copy as the generated App target compiles it, before + * the copy exists. The include folders are `/include` (the forwards) then the header search paths; under + * `sources` only the copy's planned files and forwards exist, elsewhere the disk answers. Only a certain include + * counts (R6): resolved → `checked`; unresolved, an angle include → `pending`, and a quote include → `missing` only + * with app-own evidence and without binary pods, else `pending`. The evidence: one of `appHeaders`, or a file under + * ios/ (case ignored, so that a case-only twin gets its hint), whose path ends with the spelling, its leading `./` + * and `../` aside; for a spelling without a folder, its name alone. A header of that name in another folder is no + * evidence for a spelling with one (`SomeLib/Utils.h`): a library's forwards may hold it: clang falls back to the angle and system folders, so the compile decides + * (an SDK, libc or library header). Uncertain includes and Xcode's generated Swift headers count nowhere. + */ +export function appIncludesPass1(i: Pass1Input): Pass1Result { + const include = path.join(i.sources, INCLUDE_DIR); + /** Each place in the copy → the source file it holds, named from the project root. */ + const copy = new Map(i.files.map((f) => [f.path, f.display])); + for (const [base, dest] of i.forwards) { + const held = copy.get(path.join(i.sources, dest)); + if (held !== undefined) copy.set(path.join(include, base), held); + } + const inCopy = (p: string): boolean => p === i.sources || p.startsWith(`${i.sources}${path.sep}`); + const exists = (p: string): boolean => copy.has(p) || (!inCopy(p) && existsSync(p)); + const results = resolveIncludes({ + files: i.files, + exists, + includeDirs: [include, ...i.headerSearchPaths], + defines: definesOf(i.defines), + }); + + let iosFiles: Map | undefined; + /** The files under ios/ named `base`, ignoring case (the walk runs once, at the first quote miss). */ + const onDisk = (base: string): string[] => (iosFiles ??= iosFileIndex(path.join(i.root, "ios"))).get(base.toLowerCase()) ?? []; + /** The files under ios/ whose path ends with the spelling, case ignored (by name alone for one without a folder). */ + const matching = (spelling: string): string[] => { + const tail = pathTail(spelling).toLowerCase(); + return onDisk(path.posix.basename(spelling)).filter((f) => endsWithPath(f.split(path.sep).join("/").toLowerCase(), tail)); + }; + const appOwn = (spelling: string): boolean => { + const tail = pathTail(spelling); + return i.appHeaders.some((h) => endsWithPath(h.split(path.sep).join("/"), tail)) || matching(spelling).length > 0; + }; + + const listed = new Set(i.files.map((f) => f.source)); + /** + * What ios/ holds of that name: a file the target does not list (on Expo, one generate does not copy), else one + * whose name differs only in case. + */ + const hint = (spelling: string): string => { + const base = path.posix.basename(spelling); + const files = matching(spelling); + const unlisted = files.find((f) => path.basename(f) === base && !listed.has(f)); + if (unlisted !== undefined) { + return i.expo === true + ? `; ${fromRoot(i.root, unlisted)} exists, but rn-xtool copies only the bridging header of an Expo app` + : `; ${fromRoot(i.root, unlisted)} exists but the app target does not list it (add it to the target)`; + } + const twin = files.find((f) => path.basename(f) !== base); + return twin === undefined ? "" : `; ${fromRoot(i.root, twin)} differs only in case (file names are case-sensitive on Linux)`; + }; + const missingLine = (r: ResolvedInclude): string => { + const head = `${r.file}:${r.line} imports "${r.spelling}"`; + if (path.isAbsolute(r.spelling)) return `${head}, which does not exist`; + // Where the app target's copy looked: never a folder on disk, which may hold the file the target does not list. + const places = [ + `among the files ${i.expo === true ? "rn-xtool copies" : "the app target lists"} next to ${r.file}`, + "in the app target's headers", + ...i.headerSearchPaths.map((d) => `in ${fromRoot(i.root, d)}`), + ]; + return `${head}, which is not ${orList(places)}${hint(r.spelling)}`; + }; + + const out: Pass1Result = { missing: [], pending: 0, checked: 0 }; + for (const r of results) { + if (r.generated || !r.certain) continue; + if (r.found !== undefined) out.checked++; + else if (r.angle || i.binaryPods || !appOwn(r.spelling)) out.pending++; + else out.missing.push(missingLine(r)); + } + return out; +} + +// --------------------------------------------------------------------------------------------------------------- +// Pass 1 in `doctor --project` and at the start of `build`. + +export interface AppTargetCheck { + /** Pass 1's `missing` lines, without the `✖ ` mark. */ + errors: string[]; + /** `appXcconfigWarnings`' lines, with their `⚠ ` mark. */ + warnings: string[]; + pending: number; + checked: number; +} + +type AppTargetProject = Pick; + +/** Pass 1 over the app target of `project`, then the xcconfig warnings of the project `pbx` opens (none: undefined). */ +function checkAppTarget( + root: string, + project: AppTargetProject, + binaryPods: boolean, + pbx: () => Pbxproj | undefined, +): AppTargetCheck { + const iosDir = path.join(root, "ios"); + const sources = projectPaths(root).sources; + let input: Pass1Input | undefined; + if (project.kind === "bare" && project.bare !== undefined) { + const bare = project.bare; + input = { + root, + files: bareScope(bare, iosDir, project.iosTargetDir, sources, root), + forwards: bareCopyLayout(bare, iosDir, project.iosTargetDir).forwards, + sources, + headerSearchPaths: bare.headerSearchPaths, + defines: bare.defines, + appHeaders: [...bare.headers, ...(bare.bridgingHeader ? [bare.bridgingHeader] : [])].map((h) => h.relPath), + binaryPods, + }; + } else if (project.kind === "expo") { + // generate copies the bridging header alone, to Sources/App/; nothing else of ios/ is compiled. + const header = expoBridgingHeaderPath(iosDir); + if (header !== undefined) { + const base = path.basename(header); + input = { + root, + files: [{ path: path.join(sources, base), source: header, display: fromRoot(root, header) }], + forwards: new Map(), + sources, + headerSearchPaths: [], + defines: [], + appHeaders: [base], + binaryPods, + expo: true, + }; + } + } + const pass = input === undefined ? { missing: [], pending: 0, checked: 0 } : appIncludesPass1(input); + const opened = pbx(); + return { + errors: pass.missing, + warnings: opened === undefined ? [] : appXcconfigWarnings(opened, root), + pending: pass.pending, + checked: pass.checked, + }; +} + +/** + * The Expo app's Xcode project, once expo prebuild wrote it; undefined without one, and when ios/ holds several + * (generate warns about that). + */ +function expoPbxproj(iosDir: string): Pbxproj | undefined { + try { + if (!readdirSync(iosDir).some((n) => n.endsWith(".xcodeproj"))) return undefined; + } catch { + return undefined; + } + try { + return openPbxproj(iosDir); + } catch (e) { + if (e instanceof AmbiguousProjectError) return undefined; + throw e; + } +} + +/** + * Pass 1 of B1 over the app target as `generate` will copy it, with `appXcconfigWarnings`: on bare, the target's + * C-family sources, headers and bridging header; on Expo, the prebuild's bridging header alone (no forwards, no search + * paths), all empty before expo prebuild. File-system reads only. `binaryPods`: `binaryPodCandidates` finds any. + */ +export function appTargetCheck(input: { root: string; project: AppTargetProject; binaryPods: boolean }): AppTargetCheck { + const iosDir = path.join(input.root, "ios"); + const pbx = () => (input.project.kind === "bare" ? openPbxproj(iosDir) : expoPbxproj(iosDir)); + return checkAppTarget(input.root, input.project, input.binaryPods, pbx); +} + +/** + * `doctor --project`'s app-target lines, in order: `✖ app-includes — ` per error, `⚠ app-target — ` + * per warning, `ℹ app-includes — …: checked at build` with pending includes, and `✔ app-includes — …` without errors + * when an include was checked. A bare project whose pbxproj, app target or INFOPLIST_FILE cannot be read, as + * `readProject` reads them, gives no line: the project line reports it. A throw of the check itself (a file the copy + * refuses, an Expo bridging header that is missing) is an error line: the build stops on it too. + */ +export function appTargetLines(root: string, kind: ProjectKind | undefined, opts: { binaryPods: boolean }): string[] { + const iosDir = path.join(root, "ios"); + let run: () => AppTargetCheck; + if (kind === "bare") { + let pbx: Pbxproj; + let project: AppTargetProject; + try { + pbx = openPbxproj(iosDir); + const infoPlist = resolveSetting(pbx, "INFOPLIST_FILE"); + if (!infoPlist) return []; + project = { kind, bare: readTargetContent(pbx, iosDir), iosTargetDir: path.dirname(path.resolve(iosDir, infoPlist)) }; + } catch { + return []; + } + run = () => checkAppTarget(root, project, opts.binaryPods, () => pbx); + } else if (kind === "expo") { + // The Expo check reads only the bridging header: the target folder plays no part. + run = () => appTargetCheck({ root, project: { kind, iosTargetDir: iosDir }, binaryPods: opts.binaryPods }); + } else { + return []; + } + let check: AppTargetCheck; + try { + check = run(); + } catch (e) { + return [`✖ app-includes — ${e instanceof Error ? e.message : String(e)}`]; + } + const n = check.pending; + return [ + ...check.errors.map((e) => `✖ app-includes — ${e}`), + ...check.warnings.map((w) => `⚠ app-target — ${w.replace(/^⚠ /, "")}`), + ...(n > 0 ? [`ℹ app-includes — ${n} includes into React Native's or the libraries' headers: checked at build`] : []), + ...(check.errors.length === 0 && check.checked > 0 + ? [`✔ app-includes — ${check.checked} includes of the app's own sources resolve`] + : []), + ]; +} diff --git a/src/project/capabilities.ts b/src/project/capabilities.ts index ccbf352..c12982b 100644 --- a/src/project/capabilities.ts +++ b/src/project/capabilities.ts @@ -14,13 +14,14 @@ import { PodsNetworkError, type CdnOptions } from "../pods/cdn.js"; import { cachedArchive, headSize } from "../pods/fetch.js"; import { formatSize } from "../pods/format.js"; import { PODS_LOCK, lockedVersions, readPodsLock, unusedLockEntries, type PodsLock } from "../pods/lock.js"; -import { SourcePodError, resolveBinaryPods } from "../pods/resolve.js"; +import { SourcePodError, resolveBinaryPods, type PodRoot } from "../pods/resolve.js"; import { parseRequirements, satisfiesAll } from "../pods/versions.js"; import { buildsEveryResourceBundle } from "../pipeline/scaffoldResources.js"; import { rawSlotComplete, rnArtifactsCacheRoot, type Flavor } from "../pipeline/rnArtifactsStep.js"; import { orphanPatchLine, orphanPatches, scaffoldPinWarnings } from "../pipeline/patches.js"; import { resolveRnDir, vendoredScriptsRoot } from "../pipeline/rnSpm.js"; import { bareLines, compareVersions, expoPluginFor, releaseLine, rnLineStatus } from "../versions.js"; +import { appTargetLines } from "./appIncludes.js"; import { DetectError, detectProjectKind } from "./detect.js"; import { allowKnownLimits, @@ -275,6 +276,11 @@ export interface Capabilities { * found, the lock entries no library needs, and unzip; [] without binary pods. detectCapabilities always sets it. */ binaryPods?: string[]; + /** + * The app target's lines (`appTargetLines`: `✖`/`ℹ`/`✔ app-includes — …`, `⚠ app-target — …`); [] when the project + * cannot be read. detectCapabilities always sets it. + */ + appTarget?: string[]; } /** The SwiftPM settings reader the build's plugin discovery uses (vendor/rn-spm/spm/swiftpm-config.js). */ @@ -361,8 +367,9 @@ export async function detectCapabilities(projectRoot: string, opts: ProbeOptions const podTable = mergedPodTable(config.pods); const allowed = config.knownLimits?.allow ?? []; const limits = allowKnownLimits(earlyFailures(root, libraryChecks), allowed); + const podRoots = binaryPodCandidates(root, libraryChecks); // Started now, so its probe runs alongside the rn-artifacts probe, within the same budget. - const binaryPods = binaryPodsLines(root, libraryChecks, podTable, opts, { allowed, limits }); + const binaryPods = binaryPodsLines(root, podRoots, podTable, opts, { allowed, limits }); const caps: Capabilities = { podspecs: podspecFeatures(root), excluded: excludeLines(root, config.exclude ?? [], { kind, file: configFileOf(config, "exclude") }), @@ -370,6 +377,7 @@ export async function detectCapabilities(projectRoot: string, opts: ProbeOptions podPins: podPinWarnings(root, podTable, libraryChecks), orphanPatches: orphanPatches(root).map(orphanPatchLine), scaffoldPins: scaffoldPinWarnings(root, podTable, config.exclude, kind), + appTarget: appTargetLines(root, kind, { binaryPods: podRoots.length > 0 }), }; if (kind !== undefined) caps.kind = kind; const entitlements = entitlementsCapability(root, kind); @@ -452,12 +460,11 @@ function neededLine(pods: readonly NeededPod[], libs: readonly string[]): string */ async function binaryPodsLines( root: string, - checks: LibraryCheckOptions, + roots: readonly PodRoot[], table: PodTable, opts: ProbeOptions, known: { allowed: readonly string[]; limits: readonly EarlyFailure[] }, ): Promise { - const roots = binaryPodCandidates(root, checks); let lock: PodsLock; try { lock = readPodsLock(root); diff --git a/src/project/includeScan.ts b/src/project/includeScan.ts new file mode 100644 index 0000000..b644dc6 --- /dev/null +++ b/src/project/includeScan.ts @@ -0,0 +1,475 @@ +// The include scanner of B1 (spec "B. The app target's checks", rows 33–35, R6): the `#import`/`#include` lines +// clang would see as taken or possibly taken in one source file, with their line numbers. Pure string work: the +// only outside contact is `ScanEnv.hasInclude`, which answers `__has_include`. +// +// Certainty rule (R6): an include is `certain` only when every enclosing condition is definitely taken. A condition +// the scanner cannot evaluate (an unknown name, a function-like macro, an operator outside the small grammar below) +// is `undefined`, never a guess, and makes its includes uncertain. Not returned: anything in a definitely false +// branch, includes in comments, `#include MACRO` (row 34), and `@import` (row 35). + +export interface ScannedInclude { + /** 1-based, in the original text (a continued directive keeps its first line's number). */ + line: number; + spelling: string; + angle: boolean; + /** Every enclosing condition is definitely taken (and it is not `#include_next`). */ + certain: boolean; +} + +export interface ScanEnv { + defines: ReadonlyMap; + /** `undefined`: the pass cannot know. */ + hasInclude(spelling: string, angle: boolean): boolean | undefined; +} + +/** + * The defines B1 assumes: the ones every App compile of Swift Build gets (a C-family file and, through Swift's clang + * importer, the bridging header: `SWIFT_PACKAGE`, `DEBUG=1`), and the iOS device values clang predefines for the + * target. Nothing else: the App target as rn-xtool generates it defines no `RCT_NEW_ARCH_ENABLED`, so a condition on + * it, or on a macro only one of the two compiles gets (`Xcode`, `OBJC_OLD_DISPATCH_PROTOTYPES`), is one B1 cannot + * evaluate (R6). The App target's own defines come on top (`definesOf`). + */ +export const B1_DEFINES: ReadonlyMap = new Map([ + ["SWIFT_PACKAGE", "1"], + ["DEBUG", "1"], + ["TARGET_OS_MAC", "1"], + ["TARGET_OS_IPHONE", "1"], + ["TARGET_OS_IOS", "1"], + ["TARGET_OS_OSX", "0"], + ["TARGET_OS_MACCATALYST", "0"], + ["TARGET_OS_TV", "0"], + ["TARGET_OS_WATCH", "0"], + ["TARGET_OS_VISION", "0"], + ["TARGET_OS_SIMULATOR", "0"], +]); + +const IDENTIFIER = /^[A-Za-z_][A-Za-z0-9_]*$/; + +/** + * `B1_DEFINES` overlaid with the target's `KEY` / `KEY=VALUE` entries (`KEY` alone is `1`). An entry whose key is + * not an identifier (a build-setting reference such as `$(inherited)`) defines nothing. + */ +export function definesOf(targetDefines: readonly string[]): Map { + const out = new Map(B1_DEFINES); + for (const entry of targetDefines) { + const eq = entry.indexOf("="); + const key = (eq < 0 ? entry : entry.slice(0, eq)).trim(); + if (!IDENTIFIER.test(key)) continue; + out.set(key, eq < 0 ? "1" : entry.slice(eq + 1).trim()); + } + return out; +} + +// --------------------------------------------------------------------------------------------------------------- +// Lexer: BOM, line splicing, comments. Yields the directives with their original line numbers. + +interface Directive { + line: number; + /** `if`, `ifdef`, `include`, … ("" for the null directive). */ + name: string; + /** The text after the name, comments blanked. */ + rest: string; +} + +/** Physical lines joined at a trailing backslash; each logical line keeps its first physical line's number. */ +function logicalLines(text: string): { line: number; text: string }[] { + const physical = text.replace(/^\uFEFF/, "").split(/\r\n|\n|\r/); + const out: { line: number; text: string }[] = []; + let start = -1; + let acc = ""; + for (let i = 0; i < physical.length; i++) { + const cur = physical[i]!; + const spliced = /\\[ \t]*$/.exec(cur); + if (start < 0) start = i; + acc += spliced ? cur.slice(0, spliced.index) : cur; + if (spliced && i < physical.length - 1) continue; + out.push({ line: start + 1, text: acc }); + start = -1; + acc = ""; + } + return out; +} + +/** + * Each logical line with its comments replaced by one space. String and character literals are copied as they are + * (a directive's `"X.h"` must survive) but skipped, so a `//` or `/*` inside one opens no comment; a literal ends at + * the end of its line at the latest. A block comment carries over to the following lines. + */ +function withoutComments(lines: { line: number; text: string }[]): { line: number; text: string }[] { + let inBlock = false; + return lines.map(({ line, text }) => { + let out = ""; + let i = 0; + while (i < text.length) { + if (inBlock) { + const end = text.indexOf("*/", i); + if (end < 0) { + i = text.length; + break; + } + inBlock = false; + out += " "; + i = end + 2; + continue; + } + const c = text[i]!; + if (c === "/" && text[i + 1] === "/") break; + if (c === "/" && text[i + 1] === "*") { + inBlock = true; + i += 2; + continue; + } + if (c === "'" && inNumber(out)) { + out += c; // a digit separator (`1'000`), not a character literal + i++; + continue; + } + if (c === '"' || c === "'") { + let j = i + 1; + while (j < text.length && text[j] !== c) j += text[j] === "\\" ? 2 : 1; + out += text.slice(i, j + 1); + i = j + 1; + continue; + } + out += c; + i++; + } + return { line, text: out }; + }); +} + +/** The text ends inside a preprocessing number (`1'0`, `0x1F`): a `'` that follows is a digit separator. */ +function inNumber(before: string): boolean { + const run = /[0-9A-Za-z_.']*$/.exec(before)![0]; + return /^[0-9]/.test(run) || /^\.[0-9]/.test(run); +} + +function directives(text: string): Directive[] { + const out: Directive[] = []; + for (const { line, text: clean } of withoutComments(logicalLines(text))) { + const m = /^\s*#\s*([A-Za-z_][A-Za-z0-9_]*)?(.*)$/s.exec(clean); + if (m) out.push({ line, name: m[1] ?? "", rest: m[2]!.trim() }); + } + return out; +} + +// --------------------------------------------------------------------------------------------------------------- +// Evaluator: a three-valued `#if` expression. A value is an integer, or `undefined` when the scanner cannot know it. + +type Value = number | undefined; +type Tri = boolean | undefined; + +type Token = + | { kind: "num"; value: Value } + | { kind: "id"; name: string } + | { kind: "has"; spelling: string; angle: boolean } + | { kind: "op"; op: string }; + +/** Thrown for an expression outside the grammar; the whole condition is then `undefined`. */ +class Unsupported extends Error {} + +const OPERATORS = ["&&", "||", "==", "!=", "<=", ">=", "!", "<", ">", "(", ")"]; + +function integer(spelling: string): Value { + const m = /^(0[xX][0-9a-fA-F]+|0[0-7]*|[1-9][0-9]*)(?:[uU](?:ll|LL|l|L)?|(?:ll|LL|l|L)[uU]?)?$/.exec(spelling); + if (!m) return undefined; + const digits = m[1]!; + if (/^0[xX]/.test(digits)) return parseInt(digits.slice(2), 16); + if (digits.length > 1 && digits.startsWith("0")) return parseInt(digits.slice(1), 8); + return parseInt(digits, 10); +} + +function tokenize(expr: string): Token[] { + const out: Token[] = []; + let i = 0; + while (i < expr.length) { + const rest = expr.slice(i); + const space = /^\s+/.exec(rest); + if (space) { + i += space[0].length; + continue; + } + const num = /^[0-9][0-9A-Za-z_.']*/.exec(rest); + if (num) { + out.push({ kind: "num", value: integer(num[0]) }); + i += num[0].length; + continue; + } + const has = /^__has_include\s*\(\s*(?:<([^>]*)>|"([^"]*)")\s*\)/.exec(rest); + if (has) { + out.push({ kind: "has", spelling: has[1] ?? has[2]!, angle: has[1] !== undefined }); + i += has[0].length; + continue; + } + const id = /^[A-Za-z_][A-Za-z0-9_]*/.exec(rest); + if (id) { + out.push({ kind: "id", name: id[0] }); + i += id[0].length; + continue; + } + const op = OPERATORS.find((o) => rest.startsWith(o)); + if (!op) throw new Unsupported(rest); + out.push({ kind: "op", op }); + i += op.length; + } + return out; +} + +function truth(v: Value): Tri { + return v === undefined ? undefined : v !== 0; +} + +function fromTri(t: Tri): Value { + return t === undefined ? undefined : t ? 1 : 0; +} + +/** Recursive descent over `|| && == != < > <= >= !`, parentheses, integers, names, `defined` and `__has_include`. */ +class Evaluator { + private pos = 0; + + constructor( + private readonly tokens: Token[], + private readonly lookup: (name: string) => { defined: Tri; value: Value }, + private readonly hasInclude: ScanEnv["hasInclude"], + ) {} + + run(): Value { + if (this.tokens.length === 0) throw new Unsupported("empty"); + const v = this.or(); + if (this.pos !== this.tokens.length) throw new Unsupported("trailing tokens"); + return v; + } + + private peekOp(...ops: string[]): string | undefined { + const t = this.tokens[this.pos]; + return t?.kind === "op" && ops.includes(t.op) ? t.op : undefined; + } + + private expectOp(op: string): void { + if (!this.peekOp(op)) throw new Unsupported(`expected ${op}`); + this.pos++; + } + + // Kleene logic: a definite operand decides when it can (`0 && ?` is 0, `1 || ?` is 1); otherwise `undefined`. + private or(): Value { + let left = this.and(); + while (this.peekOp("||")) { + this.pos++; + const right = this.and(); + const l = truth(left); + const r = truth(right); + left = l === true || r === true ? 1 : l === false && r === false ? 0 : undefined; + } + return left; + } + + private and(): Value { + let left = this.equality(); + while (this.peekOp("&&")) { + this.pos++; + const right = this.equality(); + const l = truth(left); + const r = truth(right); + left = l === false || r === false ? 0 : l === true && r === true ? 1 : undefined; + } + return left; + } + + private equality(): Value { + let left = this.relational(); + for (let op = this.peekOp("==", "!="); op; op = this.peekOp("==", "!=")) { + this.pos++; + const right = this.relational(); + if (left === undefined || right === undefined) left = undefined; + else left = fromTri(op === "==" ? left === right : left !== right); + } + return left; + } + + private relational(): Value { + let left = this.unary(); + for (let op = this.peekOp("<", ">", "<=", ">="); op; op = this.peekOp("<", ">", "<=", ">=")) { + this.pos++; + const right = this.unary(); + if (left === undefined || right === undefined) { + left = undefined; + continue; + } + if (op === "<") left = fromTri(left < right); + else if (op === ">") left = fromTri(left > right); + else if (op === "<=") left = fromTri(left <= right); + else left = fromTri(left >= right); + } + return left; + } + + private unary(): Value { + if (this.peekOp("!")) { + this.pos++; + const t = truth(this.unary()); + return t === undefined ? undefined : fromTri(!t); + } + return this.primary(); + } + + private primary(): Value { + const t = this.tokens[this.pos++]; + if (!t) throw new Unsupported("missing operand"); + if (t.kind === "num") return t.value; + if (t.kind === "has") return fromTri(this.hasInclude(t.spelling, t.angle)); + if (t.kind === "op") { + if (t.op !== "(") throw new Unsupported(t.op); + const v = this.or(); + this.expectOp(")"); + return v; + } + if (t.name === "defined") return fromTri(this.lookup(this.definedOperand()).defined); + if (this.peekOp("(")) { + // A function-like macro (`__has_feature(x)`, `SOME_MACRO(1)`): skip its arguments; its value is unknown. + this.skipParens(); + return undefined; + } + return this.lookup(t.name).value; + } + + private definedOperand(): string { + const paren = this.peekOp("(") !== undefined; + if (paren) this.pos++; + const t = this.tokens[this.pos++]; + if (t?.kind !== "id") throw new Unsupported("defined without a name"); + if (paren) this.expectOp(")"); + return t.name; + } + + private skipParens(): void { + let depth = 0; + do { + const t = this.tokens[this.pos++]; + if (!t) throw new Unsupported("unbalanced parentheses"); + if (t.kind === "op" && t.op === "(") depth++; + if (t.kind === "op" && t.op === ")") depth--; + } while (depth > 0); + } +} + +// --------------------------------------------------------------------------------------------------------------- +// Branch stack and the scan. + +interface Group { + /** The state of the code around the group. */ + outer: Tri; + /** The current branch's own state. */ + branch: Tri; + /** An earlier branch's condition was definitely true: every later branch is false. */ + done: boolean; + /** An earlier branch's condition was unknown: a later branch is at best unknown. */ + maybeDone: boolean; +} + +function both(a: Tri, b: Tri): Tri { + if (a === false || b === false) return false; + return a === true && b === true ? true : undefined; +} + +/** Opens or advances a group with a branch whose own condition is `cond`. */ +function enter(group: Group, cond: Tri): void { + group.branch = group.done || cond === false ? false : group.maybeDone ? undefined : cond; + if (cond === true) group.done = true; + if (cond === undefined) group.maybeDone = true; +} + +const INCLUDES = new Set(["include", "import", "include_next"]); + +/** The name a directive such as `#ifdef X` or `#define X 1` starts with. */ +function firstName(rest: string): string | undefined { + return /^[A-Za-z_][A-Za-z0-9_]*/.exec(rest)?.[0]; +} + +export function scanIncludes(text: string, env: ScanEnv): ScannedInclude[] { + const list = directives(text); + const stack: Group[] = []; + /** Names the file defines or undefines where it may run: their values are no longer the env's. */ + const changed = new Set(); + const state = (): Tri => (stack.length === 0 ? true : both(stack.at(-1)!.outer, stack.at(-1)!.branch)); + + const lookup = (name: string): { defined: Tri; value: Value } => { + const v = changed.has(name) ? undefined : env.defines.get(name); + if (v === undefined) return { defined: undefined, value: undefined }; + return { defined: true, value: integer(v) }; + }; + const evaluate = (expr: string): Tri => { + try { + return truth(new Evaluator(tokenize(expr), lookup, (s, a) => env.hasInclude(s, a)).run()); + } catch (e) { + if (e instanceof Unsupported) return undefined; + throw e; + } + }; + const isDefined = (rest: string): Tri => { + const name = firstName(rest); + return name === undefined ? undefined : lookup(name).defined; + }; + const not = (t: Tri): Tri => (t === undefined ? undefined : !t); + + const out: ScannedInclude[] = []; + list.forEach((d, index) => { + const here = state(); + switch (d.name) { + case "if": + case "ifdef": + case "ifndef": { + const group: Group = { outer: here, branch: false, done: false, maybeDone: false }; + let cond: Tri = false; + if (here !== false) { + cond = d.name === "if" ? evaluate(d.rest) : d.name === "ifdef" ? isDefined(d.rest) : not(isDefined(d.rest)); + if (cond === undefined && d.name === "ifndef" && index === 0 && isGuard(list, d.rest)) cond = true; + } + enter(group, cond); + stack.push(group); + return; + } + case "elif": + case "elifdef": + case "elifndef": + case "else": { + const group = stack.at(-1); + if (!group) return; + let cond: Tri = true; + if (group.outer === false || group.done) cond = false; + else if (d.name === "elif") cond = evaluate(d.rest); + else if (d.name === "elifdef") cond = isDefined(d.rest); + else if (d.name === "elifndef") cond = not(isDefined(d.rest)); + enter(group, cond); + return; + } + case "endif": + stack.pop(); + return; + case "define": + case "undef": { + const name = firstName(d.rest); + if (here !== false && name !== undefined) changed.add(name); + return; + } + } + if (!INCLUDES.has(d.name) || here === false) return; + const m = /^(?:<([^>]*)>|"([^"]*)")/.exec(d.rest); + if (!m) return; // `#include MACRO`: not checked (row 34) + const spelling = m[1] ?? m[2]!; + if (spelling === "") return; + out.push({ + line: d.line, + spelling, + angle: m[1] !== undefined, + certain: here === true && d.name !== "include_next", + }); + }); + return out; +} + +/** The file's first directive `#ifndef X` is a guard when the next directive is `#define X`. */ +function isGuard(list: Directive[], rest: string): boolean { + const name = firstName(rest); + const next = list[1]; + return name !== undefined && next?.name === "define" && firstName(next.rest) === name; +} diff --git a/src/project/pbxproj.ts b/src/project/pbxproj.ts index fcc0521..e37e100 100644 --- a/src/project/pbxproj.ts +++ b/src/project/pbxproj.ts @@ -1,4 +1,4 @@ -import { readdirSync } from "node:fs"; +import { readdirSync, readFileSync } from "node:fs"; import path from "node:path"; import xcode from "xcode"; import { DetectError } from "./detect.js"; @@ -90,18 +90,23 @@ export function openPbxproj(iosDir: string): Pbxproj { return { path: file, projectName: projects[0]!.slice(0, -".xcodeproj".length), appTarget: apps[0]!, targets, project }; } -/** The `buildSettings` of `configuration` in the configuration list `listUuid`. */ -function configurationSettings(p: Pbxproj, listUuid: string, configuration: string): Record | undefined { +/** The XCBuildConfiguration named `configuration` in the configuration list `listUuid`. */ +function buildConfiguration(p: Pbxproj, listUuid: string, configuration: string): any { const list = p.project.pbxXCConfigurationList()[listUuid]; if (!list) return undefined; const configs = p.project.pbxXCBuildConfigurationSection(); for (const ref of list.buildConfigurations as { value: string }[]) { const config = configs[ref.value]; - if (config && unquote(String(config.name)) === configuration) return config.buildSettings; + if (config && unquote(String(config.name)) === configuration) return config; } return undefined; } +/** The `buildSettings` of `configuration` in the configuration list `listUuid`. */ +function configurationSettings(p: Pbxproj, listUuid: string, configuration: string): Record | undefined { + return buildConfiguration(p, listUuid, configuration)?.buildSettings; +} + function targetLevel(p: Pbxproj, key: string, configuration: string): string | undefined { const target = p.project.pbxNativeTargetSection()[p.appTarget.uuid]; return toText(configurationSettings(p, target.buildConfigurationList, configuration)?.[key]); @@ -271,7 +276,10 @@ function walkGroups(objs: Record, mainGroup: string) { const groups = objs.PBXGroup ?? {}; const fileRefs = objs.PBXFileReference ?? {}; const variantGroups = objs.PBXVariantGroup ?? {}; + const syncedGroups = objs.PBXFileSystemSynchronizedRootGroup ?? {}; const files = new Map(); + /** Xcode 16 synchronized folder uuid -> its path. */ + const folders = new Map(); /** Variant group uuid -> its child file references. */ const variants = new Map(); const groupPaths = new Map(); @@ -306,13 +314,16 @@ function walkGroups(objs: Record, mainGroup: string) { } else if (fileRefs[child.value]) { placeRef(child.value, "", here); collected.push(child.value); + } else if (syncedGroups[child.value]) { + const s = syncedGroups[child.value]; + folders.set(child.value, here === undefined ? undefined : place(unquote(String(s.sourceTree ?? "")), s.path === undefined ? undefined : unquote(String(s.path)), here)); } } groupPaths.set(uuid, { path: here ?? "", name: g.name === undefined ? undefined : unquote(String(g.name)), files: collected }); return collected; }; visit(mainGroup, "", new Set()); - return { files, groupPaths, variants }; + return { files, groupPaths, variants, folders }; } function phaseFiles(objs: Record, target: any, section: string, variants: Map): string[] { @@ -333,7 +344,17 @@ export function readTargetContent(p: Pbxproj, iosDir: string): BareTargetContent const objs = p.project.hash.project.objects as Record; const target = objs.PBXNativeTarget[p.appTarget.uuid]; const mainGroup = p.project.getFirstProject().firstProject.mainGroup as string; - const { files, groupPaths, variants } = walkGroups(objs, mainGroup); + const { files, groupPaths, variants, folders } = walkGroups(objs, mainGroup); + + const synced = ((target.fileSystemSynchronizedGroups ?? []) as ({ value: string } | string)[]).map(ref); + if (synced.length > 0) { + const g = objs.PBXFileSystemSynchronizedRootGroup?.[synced[0]!]; + const folder = folders.get(synced[0]!) ?? unquote(String(g?.path ?? g?.name ?? synced[0])); + throw new DetectError( + `The app target ${p.appTarget.name} takes its files from the synchronized folder ${folder} (an Xcode 16 folder group); ` + + "rn-xtool reads only the files a target lists. Convert the folder to a group (Xcode: Convert to Group) so the target lists its files", + ); + } const toFile = (rel: string): TargetFile => { const abs = path.isAbsolute(rel) ? rel : path.join(iosDir, rel); @@ -456,3 +477,91 @@ export function readTargetContent(p: Pbxproj, iosDir: string): BareTargetContent c99Identifier(resolveSetting(p, "PRODUCT_NAME")?.trim() || p.appTarget.name), }; } + +/** The settings rn-xtool reads from the pbxproj that an xcconfig could set instead. */ +export const XCCONFIG_READ_SETTINGS = [ + "HEADER_SEARCH_PATHS", + "GCC_PREPROCESSOR_DEFINITIONS", + "CLANG_CXX_LANGUAGE_STANDARD", + "SWIFT_OBJC_BRIDGING_HEADER", + "PRODUCT_MODULE_NAME", + "CODE_SIGN_ENTITLEMENTS", + "INFOPLIST_FILE", +] as const; + +/** `KEY = …` or `KEY[cond]… = …`. */ +const XCCONFIG_SETTING = /^\s*([A-Za-z_][A-Za-z0-9_]*)\s*(?:\[[^\]]*\]\s*)*=/; +const XCCONFIG_INCLUDE = /^\s*#include(\?)?\s*"([^"]*)"/; +/** CocoaPods' generated xcconfigs: their settings are the pods', which rn-xtool builds itself. */ +const PODS_XCCONFIG = /^Pods-.*\.xcconfig$/; + +/** + * Adds to `found` the setting names `file` and its includes (`#include`, `#include?`, relative to the including file) + * set. Each file is read once (`seen`); CocoaPods' are skipped; a file that cannot be read, unless an `#include?`, goes + * to `unreadable`. + */ +function scanXcconfig(file: string, seen: Set, found: Set, unreadable: string[], optional = false): void { + if (seen.has(file) || PODS_XCCONFIG.test(path.basename(file))) return; + seen.add(file); + let text: string; + try { + text = readFileSync(file, "utf8"); + } catch { + if (!optional) unreadable.push(file); + return; + } + for (const line of text.split(/\r?\n/)) { + const include = XCCONFIG_INCLUDE.exec(line); + if (include) { + scanXcconfig(path.resolve(path.dirname(file), include[2]!), seen, found, unreadable, include[1] === "?"); + continue; + } + // Anchored at the line start, neither pattern matches a `//` comment line. + const key = XCCONFIG_SETTING.exec(line)?.[1]; + if (key) found.add(key); + } +} + +/** + * One `⚠` line per xcconfig, other than CocoaPods', that the Debug configuration of the app target or of the project + * is based on and that sets one of `XCCONFIG_READ_SETTINGS` (in that order), and one per such file that cannot be read. + * rn-xtool reads those settings from the pbxproj only. Paths are relative to the project root `root`. + */ +export function appXcconfigWarnings(p: Pbxproj, root: string): string[] { + const objs = p.project.hash.project.objects as Record; + const firstProject = p.project.getFirstProject().firstProject; + const { files } = walkGroups(objs, firstProject.mainGroup as string); + const iosDir = path.dirname(path.dirname(p.path)); + const display = (abs: string): string => path.relative(root, abs).split(path.sep).join("/"); + const cannotRead = (name: string): string => + `⚠ ${name} (the app target's base configuration) could not be read; rn-xtool does not read xcconfig files`; + + const lists = [objs.PBXNativeTarget[p.appTarget.uuid].buildConfigurationList, firstProject.buildConfigurationList]; + const bases = new Set(); + for (const list of lists) { + const base = buildConfiguration(p, String(list), "Debug")?.baseConfigurationReference; + if (base !== undefined) bases.add(String(base)); + } + + const seen = new Set(); + const out: string[] = []; + for (const uuid of bases) { + const placed = files.get(uuid); + if (placed === undefined) { + const fileRef = objs.PBXFileReference?.[uuid]; + const name = unquote(String(fileRef?.path ?? fileRef?.name ?? uuid)); + if (!PODS_XCCONFIG.test(path.posix.basename(name))) out.push(cannotRead(name)); + continue; + } + const abs = path.isAbsolute(placed) ? placed : path.join(iosDir, placed); + const found = new Set(); + const unreadable: string[] = []; + scanXcconfig(abs, seen, found, unreadable); + const sets = XCCONFIG_READ_SETTINGS.filter((s) => found.has(s)); + if (sets.length > 0) { + out.push(`⚠ ${display(abs)} sets ${sets.join(", ")} for the app target; rn-xtool does not read xcconfig files`); + } + out.push(...unreadable.map((f) => cannotRead(display(f)))); + } + return out; +} diff --git a/src/state.ts b/src/state.ts index 4cc7e21..afa5c01 100644 --- a/src/state.ts +++ b/src/state.ts @@ -39,6 +39,8 @@ export interface BuildState { emptyTargets?: string[]; /** With binary pods: what the post-pack checks read; `install` runs them on the app xtool builds (row 88). */ postPack?: PostPackPods; + /** Whether the last build ran the check of the app's own sources or skipped it (`--skip-precheck`), for the report. */ + precheck?: "run" | "skipped"; } const STATE_FILE = ".rn-xtool-state.json"; diff --git a/tests/appIncludes.test.ts b/tests/appIncludes.test.ts new file mode 100644 index 0000000..b8cc887 --- /dev/null +++ b/tests/appIncludes.test.ts @@ -0,0 +1,374 @@ +import { existsSync, mkdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "node:fs"; +import { mkdir, mkdtemp, rm, writeFile } from "node:fs/promises"; +import { tmpdir } from "node:os"; +import { join } from "node:path"; +import { afterEach, describe, expect, it } from "vitest"; +import { bareCopyLayout } from "../src/generate/bareSources.js"; +import { + appIncludesPass1, + bareScope, + resolveIncludes, + type IncludeScope, + type Pass1Result, +} from "../src/project/appIncludes.js"; +import { definesOf } from "../src/project/includeScan.js"; +import { readProject, type BareTargetContent, type TargetFile } from "../src/project/index.js"; +import { objcApp } from "./support/objcApp.js"; + +const tmps: string[] = []; +afterEach(async () => { + await Promise.all(tmps.splice(0).map((d) => rm(d, { recursive: true, force: true }))); +}); + +/** A temp project: `ios/` holding `files` (paths relative to ios/), and where the copy would go. */ +async function project(files: Record) { + const root = await mkdtemp(join(tmpdir(), "xt-incl-")); + tmps.push(root); + const ios = join(root, "ios"); + for (const [rel, text] of Object.entries(files)) { + await mkdir(join(ios, rel, ".."), { recursive: true }); + await writeFile(join(ios, rel), text); + } + const at = (relPath: string): TargetFile => ({ absPath: join(ios, relPath), relPath }); + return { root, ios, sources: join(root, "ios-xtool", "Sources", "App"), at }; +} + +function bareOf(o: Partial): BareTargetContent { + return { + swiftSources: [], cSources: [], headers: [], resources: [], skippedResources: [], defines: [], + headerSearchPaths: [], ignoredSettings: [], mixed: true, productModuleName: "App", ...o, + }; +} + +/** + * The scope of the copy `bareCopyLayout` plans under `sources`, before it exists: the planned places and the forwards + * exist there, the disk answers elsewhere. `display` is the file's path from ios/. + */ +function copyScope(bare: BareTargetContent, ios: string, target: string, sources: string, includeDirs: string[]): IncludeScope { + const layout = bareCopyLayout(bare, ios, target); + const places = new Set([ + ...layout.files.map((f) => join(sources, f.dest)), + ...[...layout.forwards.keys()].map((base) => join(sources, "include", base)), + ]); + return { + files: layout.files.map(({ file, dest }) => ({ path: join(sources, dest), source: file.absPath, display: file.relPath })), + exists: (p) => places.has(p) || existsSync(p), + includeDirs, + defines: definesOf([]), + }; +} + +/** spelling → [found, searched] of the includes `display` makes. */ +const lookups = (scope: IncludeScope, display: string) => + resolveIncludes(scope) + .filter((r) => r.file === display) + .map((r) => [r.spelling, r.found, r.searched]); + +describe("resolveIncludes", () => { + it("finds an app header in another folder by name, through the forwards", async () => { + // Row 31: headers at the root of the group tree (ios/AppDelegate.h) and in the app folder (ios/App/Native). + const { ios, sources, at } = await project({ + "AppDelegate.h": "@interface AppDelegate : NSObject\n@end\n", + "App/main.m": '#import "AppDelegate.h"\n#import "Bridge.h"\n', + "App/Native/Bridge.h": "// bridge\n", + "App/Native/Module.m": '#import "AppDelegate.h"\n', + }); + const bare = bareOf({ cSources: [at("App/main.m"), at("App/Native/Module.m")], headers: [at("App/Native/Bridge.h"), at("AppDelegate.h")] }); + const include = join(sources, "include"); + const scope = copyScope(bare, ios, join(ios, "App"), sources, [include]); + // The copy puts ios/AppDelegate.h next to main.m's copy (AppMain.m), so the neighbour answers there. + expect(lookups(scope, "App/main.m")).toEqual([ + ["AppDelegate.h", join(sources, "AppDelegate.h"), [sources]], + ["Bridge.h", join(include, "Bridge.h"), [sources, include]], + ]); + expect(lookups(scope, "App/Native/Module.m")).toEqual([ + ["AppDelegate.h", join(include, "AppDelegate.h"), [join(sources, "Native"), include]], + ]); + }); + + it("finds a quote include next to the including file first", async () => { + const { ios, sources, at } = await project({ + "App/X.m": '#import "A.h"\n', + "App/A.h": "// the neighbour\n", + "Vendor/A.h": "// another A.h\n", + }); + const bare = bareOf({ cSources: [at("App/X.m")], headers: [at("App/A.h")] }); + const scope = copyScope(bare, ios, join(ios, "App"), sources, [join(ios, "Vendor")]); + expect(lookups(scope, "App/X.m")).toEqual([["A.h", join(sources, "A.h"), [sources]]]); + }); + + it("resolves a relative include against the copy's layout", async () => { + // ios/Shared is outside the target folder ios/App: its copy keeps the path from ios/ (Sources/App/Shared/Theme.h). + const { ios, sources, at } = await project({ + "App/X.m": '#import "../Shared/Theme.h"\n#import "Shared/Theme.h"\n', + "Shared/Theme.h": "// theme\n", + }); + const bare = bareOf({ cSources: [at("App/X.m")], headers: [at("Shared/Theme.h")] }); + const scope = copyScope(bare, ios, join(ios, "App"), sources, []); + expect(lookups(scope, "App/X.m")).toEqual([ + ["../Shared/Theme.h", undefined, [sources]], + ["Shared/Theme.h", join(sources, "Shared", "Theme.h"), [sources]], + ]); + }); + + it("never looks up a generated Swift header", async () => { + const { ios, sources, at } = await project({ + "App/X.m": '#import "App-Swift.h"\n#import "BareDemo-Swift.h"\n#import \n', + // A file of that name on disk changes nothing: the build generates the header. + "Vendor/App-Swift.h": "// stale\n", + }); + const bare = bareOf({ cSources: [at("App/X.m")] }); + const scope = copyScope(bare, ios, join(ios, "App"), sources, [join(ios, "Vendor")]); + expect(resolveIncludes(scope)).toEqual([ + { file: "App/X.m", line: 1, spelling: "App-Swift.h", angle: false, certain: true, searched: [], generated: true }, + { file: "App/X.m", line: 2, spelling: "BareDemo-Swift.h", angle: false, certain: true, searched: [], generated: true }, + { file: "App/X.m", line: 3, spelling: "Foo/Foo-Swift.h", angle: true, certain: true, searched: [], generated: true }, + ]); + }); + + it("answers __has_include with the same lookup", async () => { + const text = [ + `#if __has_include("Found.h")`, + `#import "Found.h"`, + `#else`, + `#import "Fallback.h"`, + `#endif`, + `#if __has_include("Gone.h")`, + `#import "Gone.h"`, + `#endif`, + ].join("\n"); + const { ios, sources, at } = await project({ "App/X.m": text, "App/Found.h": "// found\n" }); + const bare = bareOf({ cSources: [at("App/X.m")], headers: [at("App/Found.h")] }); + const scope = copyScope(bare, ios, join(ios, "App"), sources, []); + // A header the lookup does not find may still come from a folder the scope lacks: its branch stays uncertain. + expect(resolveIncludes(scope).map((r) => [r.spelling, r.line, r.certain, r.found])).toEqual([ + ["Found.h", 2, true, join(sources, "Found.h")], + ["Gone.h", 7, false, undefined], + ]); + }); + + it("opens an absolute include spelling as is", async () => { + const { root, ios, sources, at } = await project({ "Vendor/Z.h": "// z\n" }); + const z = join(ios, "Vendor", "Z.h"); + const gone = join(root, "Gone.h"); + const text = [`#import "${z}"`, `#import "${gone}"`, `#if __has_include("${z}")`, `#import "Taken.h"`, `#endif`].join("\n"); + await mkdir(join(ios, "App"), { recursive: true }); + await writeFile(join(ios, "App", "X.m"), text); + const scope = copyScope(bareOf({ cSources: [at("App/X.m")] }), ios, join(ios, "App"), sources, [join(sources, "include")]); + expect(resolveIncludes(scope).map((r) => [r.spelling, r.certain, r.found, r.searched])).toEqual([ + [z, true, z, []], + [gone, true, undefined, []], + ["Taken.h", true, undefined, [sources, join(sources, "include")]], + ]); + }); +}); + +/** Pass 1 over the project at `root` as `doctor --project` and `build` read it; the copy goes to ios-xtool/Sources/App. */ +async function pass1(root: string, o: { binaryPods?: boolean } = {}): Promise { + const project = await readProject(root); + const ios = join(root, "ios"); + const sources = join(root, "ios-xtool", "Sources", "App"); + const bare = project.bare!; + return appIncludesPass1({ + root, + files: bareScope(bare, ios, project.iosTargetDir, sources, root), + forwards: bareCopyLayout(bare, ios, project.iosTargetDir).forwards, + sources, + headerSearchPaths: bare.headerSearchPaths, + defines: bare.defines, + appHeaders: [...bare.headers, ...(bare.bridgingHeader ? [bare.bridgingHeader] : [])].map((h) => h.relPath), + binaryPods: o.binaryPods ?? false, + }); +} + +/** Rewrites a file of the project at `root` (`rel` from the root). */ +function edit(root: string, rel: string, change: (text: string) => string): void { + const file = join(root, rel); + const before = readFileSync(file, "utf8"); + const after = change(before); + expect(after).not.toBe(before); + writeFileSync(file, after); +} + +/** Adds `lines` to the template's AppDelegate.mm after its React import (line 9), so they start at line 10. */ +const addToAppDelegate = (root: string, lines: string) => + edit(root, "ios/ObjcApp/AppDelegate.mm", (t) => t.replace("#import \n", `$&${lines}`)); + +describe("appIncludesPass1", () => { + it("passes the Objective-C template in both layouts", async () => { + // Pending: the certain angle includes, per including file — AppDelegate.mm , main.m + // , AppDelegate.h and . Checked: "AppDelegate.h" from main.m and + // from AppDelegate.mm. + for (const layout of ["template", "root-group"] as const) { + expect(await pass1(objcApp(layout))).toEqual({ missing: [], pending: 4, checked: 2 }); + } + }); + + it("stops on an app-own quote include that resolves nowhere (F2)", async () => { + const root = objcApp("root-group"); + rmSync(join(root, "ios", "AppDelegate.h")); + // A copy left by an earlier build changes nothing: the build writes Sources/App afresh. + mkdirSync(join(root, "ios-xtool", "Sources", "App"), { recursive: true }); + writeFileSync(join(root, "ios-xtool", "Sources", "App", "AppDelegate.h"), "// stale\n"); + expect(await pass1(root)).toEqual({ + missing: [ + `ios/AppDelegate.mm:7 imports "AppDelegate.h", which is not among the files the app target lists next to ios/AppDelegate.mm or in the app target's headers`, + `ios/main.m:9 imports "AppDelegate.h", which is not among the files the app target lists next to ios/main.m or in the app target's headers`, + ], + pending: 2, + checked: 0, + }); + }); + + it("leaves a quote include a dependency provides to the build", async () => { + const root = objcApp("template"); + addToAppDelegate(root, '#import "RNCAsyncStorage.h"\n'); + edit(root, "package.json", (t) => t.replace('"react": "19.3.0",', '"react": "19.3.0",\n "x": "1.0.0",')); + const x = join(root, "node_modules", "x"); + mkdirSync(join(x, "ios"), { recursive: true }); + writeFileSync(join(x, "package.json"), JSON.stringify({ name: "x", version: "1.0.0" })); + writeFileSync(join(x, "ios", "RNCAsyncStorage.h"), "// the library's header\n"); + // CocoaPods' copies, build output, dot folders and node_modules under ios/ are not the app's own headers. + for (const dir of ["Pods/Headers/Public/x", "build/x", ".cache", "node_modules/x"]) { + mkdirSync(join(root, "ios", dir), { recursive: true }); + writeFileSync(join(root, "ios", dir, "RNCAsyncStorage.h"), "// a copy\n"); + } + expect(await pass1(root)).toEqual({ missing: [], pending: 5, checked: 2 }); + }); + + it("leaves a quote include a dependency provides under another folder to the build", async () => { + // The build finds it through React Native's staged headers (React/ flattened); the source tree has React/Base/. + const root = objcApp("template"); + addToAppDelegate(root, '#import "React/RCTBridgeModule.h"\n'); + mkdirSync(join(root, "node_modules", "react-native", "React", "Base"), { recursive: true }); + writeFileSync(join(root, "node_modules", "react-native", "React", "Base", "RCTBridgeModule.h"), "// bridge module\n"); + expect(await pass1(root)).toEqual({ missing: [], pending: 5, checked: 2 }); + }); + + it("leaves a quote include of an SDK or libc header to the build", async () => { + // Clang falls back from the quote folders to the angle and system ones: Xcode and the generated build compile it. + const root = objcApp("template"); + edit(root, "ios/ObjcApp/main.m", (t) => t.replace("#import \n", '$&#include "stdlib.h"\n#import "Foundation/Foundation.h"\n')); + expect(await pass1(root)).toEqual({ missing: [], pending: 6, checked: 2 }); + }); + + it("leaves quote misses to the build when the project has binary pods", async () => { + const root = objcApp("template"); + addToAppDelegate(root, '#import "RNCAsyncStorage.h"\n'); + expect(await pass1(root, { binaryPods: true })).toEqual({ missing: [], pending: 5, checked: 2 }); + }); + + it("never errors on an uncertain include", async () => { + const root = objcApp("template"); + addToAppDelegate(root, '#ifdef FB_SONARKIT_ENABLED\n#import "FlipperKit.h"\n#endif\n'); + expect(await pass1(root)).toEqual({ missing: [], pending: 4, checked: 2 }); + }); + + it("never errors on a branch on a macro the App target does not define", async () => { + // Swift Build compiles the App without RCT_NEW_ARCH_ENABLED: the include is uncertain, and the compile decides. + const root = objcApp("template"); + writeFileSync(join(root, "ios", "ObjcApp", "Unlisted.h"), "// not in the Xcode project\n"); + addToAppDelegate(root, '#ifdef RCT_NEW_ARCH_ENABLED\n#import "Unlisted.h"\n#endif\n#if RCT_NEW_ARCH_ENABLED\n#import "Gone.h"\n#endif\n'); + expect(await pass1(root)).toEqual({ missing: [], pending: 4, checked: 2 }); + }); + + it("needs evidence on the path for a spelling with a folder", async () => { + // An app file named Utils.h, or the app's AppDelegate.h, says nothing of SomeLib/: a library's forwards may hold it. + const root = objcApp("template"); + writeFileSync(join(root, "ios", "ObjcApp", "Utils.h"), "// the app's own Utils.h\n"); + addToAppDelegate(root, '#import "SomeLib/Utils.h"\n#import "SomeLib/AppDelegate.h"\n'); + expect(await pass1(root)).toEqual({ missing: [], pending: 6, checked: 2 }); + }); + + it("matches a folder spelling against the app's headers and ios/ by its path", async () => { + const root = await mkdtemp(join(tmpdir(), "xt-incl-")); + tmps.push(root); + const ios = join(root, "ios"); + const sources = join(root, "ios-xtool", "Sources", "App"); + await mkdir(join(ios, "App", "Shared"), { recursive: true }); + await writeFile(join(ios, "App", "X.m"), '#import "Shared/Utils.h"\n#import "Shared/utils.h"\n#import "../App/Shared/Utils.h"\n'); + await writeFile(join(ios, "App", "Shared", "Utils.h"), "// utils\n"); + const x = { path: join(sources, "X.m"), source: join(ios, "App", "X.m"), display: "ios/App/X.m" }; + const utils = { path: join(sources, "Shared", "Utils.h"), source: join(ios, "App", "Shared", "Utils.h"), display: "ios/App/Shared/Utils.h" }; + const input = (listed: boolean) => ({ + root, + files: listed ? [x, utils] : [x], + forwards: listed ? new Map([["Utils.h", "Shared/Utils.h"]]) : new Map(), + sources, + headerSearchPaths: [], + defines: [], + appHeaders: listed ? ["App/Shared/Utils.h"] : [], + binaryPods: false, + }); + // Listed: the copy holds it next to X.m (the relative spelling lands there too); the case-only twin misses. + const head = (line: number, spelling: string) => + `ios/App/X.m:${line} imports "${spelling}", which is not among the files the app target lists next to ios/App/X.m or in the app target's headers`; + expect(appIncludesPass1(input(true))).toEqual({ + missing: [`${head(2, "Shared/utils.h")}; ios/App/Shared/Utils.h differs only in case (file names are case-sensitive on Linux)`], + pending: 0, + checked: 2, + }); + // On disk, not listed: evidence on the path, and the hint names that file. + expect(appIncludesPass1(input(false))).toEqual({ + missing: [ + `${head(1, "Shared/Utils.h")}; ios/App/Shared/Utils.h exists but the app target does not list it (add it to the target)`, + `${head(2, "Shared/utils.h")}; ios/App/Shared/Utils.h differs only in case (file names are case-sensitive on Linux)`, + `${head(3, "../App/Shared/Utils.h")}; ios/App/Shared/Utils.h exists but the app target does not list it (add it to the target)`, + ], + pending: 0, + checked: 0, + }); + }); + + it("names a header that differs only in case", async () => { + const root = objcApp("template"); + edit(root, "ios/ObjcApp/AppDelegate.mm", (t) => t.replace('#import "AppDelegate.h"', '#import "appdelegate.h"')); + expect((await pass1(root)).missing).toEqual([ + `ios/ObjcApp/AppDelegate.mm:7 imports "appdelegate.h", which is not among the files the app target lists next to ` + + "ios/ObjcApp/AppDelegate.mm or in the app target's headers; " + + "ios/ObjcApp/AppDelegate.h differs only in case (file names are case-sensitive on Linux)", + ]); + }); + + it("names a header whose file name on disk differs only in case", async () => { + const root = objcApp("root-group"); + renameSync(join(root, "ios", "AppDelegate.h"), join(root, "ios", "appdelegate.h")); + const tail = "or in the app target's headers; ios/appdelegate.h differs only in case (file names are case-sensitive on Linux)"; + const line = (file: string, n: number) => `${file}:${n} imports "AppDelegate.h", ${"which is not among the files the app target lists next to"} ${file} ${tail}`; + expect(await pass1(root)).toEqual({ + missing: [line("ios/AppDelegate.mm", 7), line("ios/main.m", 9)], + pending: 2, + checked: 0, + }); + }); + + it("names a header on disk the app target does not list", async () => { + const root = objcApp("template"); + writeFileSync(join(root, "ios", "ObjcApp", "Unlisted.h"), "// not in the Xcode project\n"); + addToAppDelegate(root, '#import "Unlisted.h"\n'); + expect((await pass1(root)).missing).toEqual([ + // The head names where the app target's copy looked; the tail, the file on disk it does not list. + `ios/ObjcApp/AppDelegate.mm:10 imports "Unlisted.h", which is not among the files the app target lists next to ` + + "ios/ObjcApp/AppDelegate.mm or in the app target's headers; " + + "ios/ObjcApp/Unlisted.h exists but the app target does not list it (add it to the target)", + ]); + }); + + it("lists a search path with spaces whole", async () => { + const root = objcApp("template"); + edit(root, "ios/ObjcApp.xcodeproj/project.pbxproj", (t) => + t.replace( + "\t\t\t\tINFOPLIST_FILE = ObjcApp/Info.plist;\n", + '\t\t\t\tHEADER_SEARCH_PATHS = (\n\t\t\t\t\t"$(inherited)",\n\t\t\t\t\t"$(SRCROOT)/Vendor Kit",\n\t\t\t\t);\n$&', + ), + ); + // The header sits one folder below the search path: the app's own, so a miss is an error. + mkdirSync(join(root, "ios", "Vendor Kit", "include"), { recursive: true }); + writeFileSync(join(root, "ios", "Vendor Kit", "include", "VendorKit.h"), "// vendor\n"); + addToAppDelegate(root, '#import "VendorKit.h"\n'); + expect((await pass1(root)).missing).toEqual([ + `ios/ObjcApp/AppDelegate.mm:10 imports "VendorKit.h", which is not among the files the app target lists next to ` + + "ios/ObjcApp/AppDelegate.mm, in the app target's headers or in ios/Vendor Kit; ios/Vendor Kit/include/VendorKit.h exists but the app target does not list it (add it to the target)", + ]); + }); +}); diff --git a/tests/build.test.ts b/tests/build.test.ts index 815ef5a..54a896d 100644 --- a/tests/build.test.ts +++ b/tests/build.test.ts @@ -7,6 +7,7 @@ import { describe, expect, it, vi } from "vitest"; import { build, buildSteps, chooseMetroPort, restagePods, type BuildDeps } from "../src/commands/build.js"; import { projectPaths } from "../src/paths.js"; import { postPackPods } from "../src/pods/postPack.js"; +import { PrecheckError } from "../src/pipeline/precheckReport.js"; import { loadConfig as realLoadConfig } from "../src/config.js"; import { jsiRnHeaderDirs } from "../src/pipeline/jsi.js"; import { fixLibraryManifests } from "../src/pipeline/manifests.js"; @@ -25,14 +26,14 @@ const bareFlags = { kind: "bare" as const, hasExpoModules: false, hasExpoConstan describe("buildSteps", () => { it("runs pods first and pod-binaries right before rn-spm, only with binary pods", () => { expect(buildSteps({ ...bareFlags, rnArtifacts: true, hasIos: true, clean: true, pods: true })).toEqual([ - "pods", "clean", "patches", "rn-artifacts", "pod-binaries", "rn-spm", "frameworks", "generate", "xtool-build", + "pods", "clean", "patches", "rn-artifacts", "pod-binaries", "rn-spm", "frameworks", "generate", "precheck", "xtool-build", ]); expect(buildSteps({ ...expoFlags, hasIos: false, clean: false, pods: true })).toEqual([ - "pods", "prebuild", "patches", "pod-binaries", "rn-spm", "jsi", "app-config", "frameworks", "generate", "xtool-build", + "pods", "prebuild", "patches", "pod-binaries", "rn-spm", "jsi", "app-config", "frameworks", "generate", "precheck", "xtool-build", ]); const sdk57 = { ...expoFlags, expoPlugin: "vendored" as const, rnArtifacts: true, hasIos: true, clean: false }; expect(buildSteps({ ...sdk57, pods: true })).toEqual([ - "pods", "patches", "rn-artifacts", "jsi", "pod-binaries", "rn-spm", "app-config", "frameworks", "generate", "xtool-build", + "pods", "patches", "rn-artifacts", "jsi", "pod-binaries", "rn-spm", "app-config", "frameworks", "generate", "precheck", "xtool-build", ]); }); it("plans today's steps for a project without binary pods", () => { @@ -50,7 +51,7 @@ describe("buildSteps", () => { }); it("omits prebuild when ios/ exists", () => { expect(buildSteps({ ...expoFlags, hasIos: true, clean: false })).toEqual([ - "patches", "rn-spm", "jsi", "app-config", "frameworks", "generate", "xtool-build", + "patches", "rn-spm", "jsi", "app-config", "frameworks", "generate", "precheck", "xtool-build", ]); }); it("uses prebuild --clean when clean", () => { @@ -65,23 +66,23 @@ describe("buildSteps", () => { }); it("bare pure: no prebuild, jsi or app-config", () => { expect(buildSteps({ ...bareFlags, hasIos: false, clean: false })).toEqual([ - "patches", "rn-spm", "frameworks", "generate", "xtool-build", + "patches", "rn-spm", "frameworks", "generate", "precheck", "xtool-build", ]); }); it("bare --clean cleans instead of prebuilding", () => { const steps = buildSteps({ ...bareFlags, hasIos: true, clean: true }); - expect(steps).toEqual(["clean", "patches", "rn-spm", "frameworks", "generate", "xtool-build"]); + expect(steps).toEqual(["clean", "patches", "rn-spm", "frameworks", "generate", "precheck", "xtool-build"]); }); it("bare hybrid: jsi with expo modules, app-config only with expo-constants", () => { const hybrid = { ...bareFlags, hasExpoModules: true, hasIos: true, clean: false }; - expect(buildSteps(hybrid)).toEqual(["patches", "rn-spm", "jsi", "frameworks", "generate", "xtool-build"]); + expect(buildSteps(hybrid)).toEqual(["patches", "rn-spm", "jsi", "frameworks", "generate", "precheck", "xtool-build"]); expect(buildSteps({ ...hybrid, hasExpoConstants: true })).toEqual([ - "patches", "rn-spm", "jsi", "app-config", "frameworks", "generate", "xtool-build", + "patches", "rn-spm", "jsi", "app-config", "frameworks", "generate", "precheck", "xtool-build", ]); }); it("bare vendored: rn-artifacts between patches and rn-spm", () => { expect(buildSteps({ ...bareFlags, rnArtifacts: true, hasIos: true, clean: false })).toEqual([ - "patches", "rn-artifacts", "rn-spm", "frameworks", "generate", "xtool-build", + "patches", "rn-artifacts", "rn-spm", "frameworks", "generate", "precheck", "xtool-build", ]); }); it("expo 58 (installed plugin) never gets rn-artifacts", () => { @@ -90,15 +91,28 @@ describe("buildSteps", () => { it("expo 57: jsi before rn-spm, with rn-artifacts", () => { const sdk57 = { ...expoFlags, expoPlugin: "vendored" as const, rnArtifacts: true, hasIos: true, clean: false }; expect(buildSteps(sdk57)).toEqual([ - "patches", "rn-artifacts", "jsi", "rn-spm", "app-config", "frameworks", "generate", "xtool-build", + "patches", "rn-artifacts", "jsi", "rn-spm", "app-config", "frameworks", "generate", "precheck", "xtool-build", ]); expect(buildSteps({ ...sdk57, rnArtifacts: false })).toEqual([ - "patches", "jsi", "rn-spm", "app-config", "frameworks", "generate", "xtool-build", + "patches", "jsi", "rn-spm", "app-config", "frameworks", "generate", "precheck", "xtool-build", ]); }); + it("plans precheck between generate and xtool-build", () => { + const sdk57 = { ...expoFlags, expoPlugin: "vendored" as const, rnArtifacts: true }; + for (const flags of [expoFlags, bareFlags, sdk57]) { + for (const [hasIos, clean, pods] of [[true, false, false], [false, false, true], [true, true, false]] as const) { + const input = { ...flags, hasIos, clean, pods }; + expect(buildSteps(input).slice(-3)).toEqual(["generate", "precheck", "xtool-build"]); + expect(buildSteps({ ...input, precheck: true })).toEqual(buildSteps(input)); + const without = buildSteps({ ...input, precheck: false }); + expect(without).not.toContain("precheck"); + expect(without).toEqual(buildSteps(input).filter((s) => s !== "precheck")); + } + } + }); it("expo 57 --clean re-creates artifacts and JSI headers before rn-spm", () => { expect(buildSteps({ ...expoFlags, expoPlugin: "vendored", rnArtifacts: true, hasIos: true, clean: true })).toEqual([ - "prebuild --clean", "patches", "rn-artifacts", "jsi", "rn-spm", "app-config", "frameworks", "generate", "xtool-build", + "prebuild --clean", "patches", "rn-artifacts", "jsi", "rn-spm", "app-config", "frameworks", "generate", "precheck", "xtool-build", ]); }); }); @@ -114,6 +128,7 @@ function setup(over: { isPortFree?: (p: number) => Promise; isMetroRunn }; const writeIosXtool = vi.fn(async () => { calls.push("generate"); + return { pkg: {}, origins: {} } as never; }); const deps: BuildDeps = { loadConfig: async () => ({ metroPort: 8081, ...over.cfg }), @@ -179,6 +194,8 @@ function setup(over: { isPortFree?: (p: number) => Promise; isMetroRunn }, codegenClasses: async () => [], emptyTargets: over.emptyTargets ?? (() => []), + appTargetCheck: () => ({ errors: [], warnings: [], pending: 0, checked: 0 }), + precheck: rec("precheck"), log: (s) => logs.push(s), }; return { root, calls, logs, deps, writeIosXtool }; @@ -683,7 +700,7 @@ describe("build", () => { it("runs rn-artifacts for a bare project on vendored scripts", async () => { const t = setup({ project: { kind: "bare", rnScripts: "vendored", rnVersion: "0.86.3", hasExpoModules: false, hasExpoConstants: false } }); await build(t.root, {}, t.deps); - expect(t.calls).toEqual(["patches", "rn-artifacts", "rn-spm", "frameworks", "generate", "xtool-build"]); + expect(t.calls).toEqual(["patches", "rn-artifacts", "rn-spm", "frameworks", "generate", "precheck", "xtool-build"]); expect(t.logs).toContain("▸ rn-artifacts"); }); it("passes the prepared artifacts root to runRnSpm", async () => { @@ -850,7 +867,7 @@ describe("build", () => { it("builds the JSI framework for a bare project with expo modules, app-config only with expo-constants", async () => { const t = setup({ project: { kind: "bare", hasExpoModules: true, hasExpoConstants: false } }); await build(t.root, {}, t.deps); - expect(t.calls).toEqual(["patches", "rn-spm", "jsi", "frameworks", "generate", "xtool-build"]); + expect(t.calls).toEqual(["patches", "rn-spm", "jsi", "frameworks", "generate", "precheck", "xtool-build"]); const ctx = (t.writeIosXtool.mock.calls[0] as unknown[])[0] as { frameworks: { name: string }[] }; expect(ctx.frameworks.map((f) => f.name)).toEqual(["A", "ExpoModulesJSI"]); const u = setup({ project: { kind: "bare", hasExpoModules: true, hasExpoConstants: true } }); @@ -1178,6 +1195,116 @@ describe("build", () => { ); expect(t.calls).toEqual([]); }); + it("stops a bare build on an app-own include before any step", async () => { + const error = 'ios/main.m:9 imports "AppDelegate.h", which is not in ios or the app target\'s headers'; + const xcconfig = "⚠ ios/Config/App.xcconfig sets HEADER_SEARCH_PATHS for the app target; rn-xtool does not read xcconfig files"; + for (const binaryPods of [false, true]) { + const t = setup({ hasIos: true, project: { kind: "bare" } }); + const seen: unknown[] = []; + const pod = { library: "lib", libraryVersion: "1.0.0", dependency: "Pod", requirements: [] }; + await expect( + build(t.root, { clean: true }, { + ...t.deps, + binaryPodCandidates: () => (binaryPods ? [pod] : []), + appTargetCheck: (input) => { + seen.push(input); + return { errors: [error], warnings: [xcconfig], pending: 4, checked: 0 }; + }, + }), + ).rejects.toThrow( + new Error( + "1 include(s) of the app's own sources resolve nowhere (listed above): the build would stop compiling them; " + + "if xtool-build builds them, build with rn-xtool build --skip-precheck and report it with rn-xtool doctor --report", + ), + ); + expect(seen).toEqual([{ root: t.root, project: expect.objectContaining({ kind: "bare" }), binaryPods }]); + expect(t.calls).toEqual([]); + expect(t.logs.some((l) => l.startsWith("▸ "))).toBe(false); + expect(t.logs.slice(-2)).toEqual([xcconfig, `✖ ${error}`]); + } + }); + + it("checks an Expo app's bridging header after prebuild", async () => { + const t = setup(); + const seen: string[][] = []; + await build(t.root, {}, { + ...t.deps, + appTargetCheck: () => { + seen.push([...t.calls]); + return { errors: [], warnings: ["⚠ w"], pending: 1, checked: 0 }; + }, + }); + expect(seen).toEqual([["prebuild"]]); + expect(t.logs.indexOf("⚠ w")).toBeGreaterThan(t.logs.indexOf("✔ prebuild (0.0s)")); + expect(t.logs.indexOf("⚠ w")).toBeLessThan(t.logs.indexOf("▸ patches")); + const u = setup(); + await expect( + build(u.root, {}, { ...u.deps, appTargetCheck: () => ({ errors: ["e1", "e2"], warnings: [], pending: 0, checked: 0 }) }), + ).rejects.toThrow(/resolve nowhere \(listed above\): the build would stop compiling them; if xtool-build builds them, build with rn-xtool build --skip-precheck and report it with rn-xtool doctor --report$/); + expect(u.calls).toEqual(["prebuild"]); + expect(u.logs.slice(-2)).toEqual(["✖ e1", "✖ e2"]); + }); + + it("runs the precheck with the generated app and stops before xtool-build", async () => { + const app = { pkg: { name: "App" }, origins: { "main.m": "ios/main.m" } } as never; + const t = setup({ project: { rnVersion: "0.88.2" } }); + const seen: unknown[] = []; + const precheck: BuildDeps["precheck"] = async (paths, generated, opts) => { + t.calls.push("precheck"); + seen.push([paths.root, generated, opts.root, opts.rnVersion, opts.clean]); + opts.log("✖ ios/main.m:3: error: boom"); + throw new PrecheckError("1 error in the app's own sources"); + }; + await expect( + build(t.root, { clean: true }, { ...t.deps, writeIosXtool: async () => (t.calls.push("generate"), app), precheck }), + ).rejects.toThrow(PrecheckError); + expect(t.calls.slice(-2)).toEqual(["generate", "precheck"]); + expect(seen).toEqual([[t.root, app, t.root, "0.88.2", true]]); + expect(t.logs).toContain("✖ ios/main.m:3: error: boom"); + const state = await readState(join(t.root, "ios-xtool")); + expect(state?.depsFingerprint).toBeUndefined(); + expect(state?.precheck).toBe("run"); + + const ok = setup(); + await build(ok.root, {}, ok.deps); + expect(ok.calls.slice(-3)).toEqual(["generate", "precheck", "xtool-build"]); + expect(await readState(join(ok.root, "ios-xtool"))).toMatchObject({ precheck: "run", depsFingerprint: "fp-test" }); + }); + + it("skips the precheck with --skip-precheck and says so", async () => { + const skipped = "⚠ precheck skipped (--skip-precheck): errors in the app's own sources show in xtool-build"; + for (const kind of ["expo", "bare"] as const) { + const t = setup({ hasIos: true, project: { kind } }); + const appTargetCheck = vi.fn(() => ({ errors: [], warnings: [], pending: 0, checked: 0 })); + await build(t.root, { skipPrecheck: true }, { ...t.deps, appTargetCheck }); + expect(t.calls).not.toContain("precheck"); + expect(t.calls.slice(-2)).toEqual(["generate", "xtool-build"]); + expect(t.logs.filter((l) => l === skipped)).toHaveLength(1); + expect(t.logs.indexOf(skipped)).toBeGreaterThan(t.logs.findIndex((l) => l.startsWith("✔ generate ("))); + expect(t.logs.indexOf(skipped)).toBeLessThan(t.logs.indexOf("▸ xtool-build")); + expect(appTargetCheck).toHaveBeenCalledTimes(1); + expect(await readState(join(t.root, "ios-xtool"))).toMatchObject({ precheck: "skipped", depsFingerprint: "fp-test" }); + } + }); + + it("softens pass-1 misses to warnings with --skip-precheck", async () => { + const error = 'ios/main.m:9 imports "AppDelegate.h", which is not in ios or the app target\'s headers'; + for (const kind of ["expo", "bare"] as const) { + const t = setup({ hasIos: true, project: { kind } }); + const appTargetCheck = () => ({ errors: [error, "e2"], warnings: [], pending: 0, checked: 0 }); + await build(t.root, { skipPrecheck: true }, { ...t.deps, appTargetCheck }); + expect(t.logs.filter((l) => l.startsWith("✖"))).toEqual([]); + const at = t.logs.indexOf(`⚠ ${error}`); + expect(t.logs.slice(at, at + 3)).toEqual([ + `⚠ ${error}`, + "⚠ e2", + "⚠ 2 include(s) of the app's own sources resolve nowhere (listed above); checked by xtool-build (--skip-precheck)", + ]); + expect(t.calls.slice(-2)).toEqual(["generate", "xtool-build"]); + expect(await readState(join(t.root, "ios-xtool"))).toMatchObject({ precheck: "skipped" }); + } + }); + it("cleans ios/build and ios-xtool instead of prebuilding a bare project", async () => { const t = setup({ hasIos: true, project: { kind: "bare" } }); await build(t.root, { clean: true }, t.deps); diff --git a/tests/capabilities.test.ts b/tests/capabilities.test.ts index 09d4b48..c6a676c 100644 --- a/tests/capabilities.test.ts +++ b/tests/capabilities.test.ts @@ -14,6 +14,7 @@ import { fakeExpo57Modules } from "./support/expo57.js"; import { fakeExpo58Modules } from "./support/expo58.js"; import { makeFakeSlot088 } from "./support/fakeSlots.js"; import { fakeRnScripts } from "./support/rnScripts.js"; +import { objcApp } from "./support/objcApp.js"; import { plistOf, withEntitlements } from "./support/entitlements.js"; import { useGitSpecCache } from "./support/podsCache.js"; import { troubleshootingUrl } from "../src/docs.js"; @@ -676,6 +677,88 @@ describe("detectCapabilities", () => { }); }); + it("reads the app target's includes without a toolchain", async () => { + // No swift, clang or xtool: pass 1 reads files only. + vi.stubEnv("PATH", ""); + const root = objcApp("root-group"); + const pending = "ℹ app-includes — 4 includes into React Native's or the libraries' headers: checked at build"; + const resolved = "✔ app-includes — 2 includes of the app's own sources resolve"; + expect((await detect(root)).appTarget).toEqual([pending, resolved]); + // ios/Config/App.xcconfig, in the main group, as the target's Debug base. + const pbxproj = path.join(root, "ios", "ObjcApp.xcodeproj", "project.pbxproj"); + const ref = "C50000000000000000000A01"; + let src = await readFile(pbxproj, "utf8"); + for (const [from, to] of [ + ["/* End PBXFileReference section */", `\t\t${ref} = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config/App.xcconfig; sourceTree = ""; };\n$&`], + ["83CBB9F61A601CBA00E9B192 = {\n\t\t\tisa = PBXGroup;\n\t\t\tchildren = (\n", `$&\t\t\t\t${ref},\n`], + ["baseConfigurationReference = 3B4392A12AC88292D35C810B /* Pods-ObjcApp.debug.xcconfig */;", `baseConfigurationReference = ${ref};`], + ] as const) { + expect(src).toContain(from); + src = src.replace(from, to); + } + await writeFile(pbxproj, src); + await mkdir(path.join(root, "ios", "Config")); + await writeFile(path.join(root, "ios", "Config", "App.xcconfig"), "HEADER_SEARCH_PATHS = $(inherited) Vendor\n"); + expect((await detect(root)).appTarget).toEqual([ + "⚠ app-target — ios/Config/App.xcconfig sets HEADER_SEARCH_PATHS for the app target; rn-xtool does not read xcconfig files", + pending, + resolved, + ]); + }); + + it("gives no app-target line when the project cannot be read", async () => { + // The app target takes its files from a synchronized folder: the project line names it. + const root = objcApp("template"); + const pbxproj = path.join(root, "ios", "ObjcApp.xcodeproj", "project.pbxproj"); + const synced = "C60000000000000000000A01"; + const src = (await readFile(pbxproj, "utf8")) + .replace( + "/* Begin PBXGroup section */", + "/* Begin PBXFileSystemSynchronizedRootGroup section */\n" + + `\t\t${synced} /* ObjcApp */ = {isa = PBXFileSystemSynchronizedRootGroup; path = ObjcApp; sourceTree = ""; };\n` + + "/* End PBXFileSystemSynchronizedRootGroup section */\n\n/* Begin PBXGroup section */", + ) + .replace("\t\t\t\t13B07FAE1A68108700A75B9A /* ObjcApp */,\n\t\t\t\t83CBBA001A601CBA00E9B192", `\t\t\t\t${synced} /* ObjcApp */,\n\t\t\t\t83CBBA001A601CBA00E9B192`) + .replace("\t\t\tdependencies = (\n\t\t\t);\n", `$&\t\t\tfileSystemSynchronizedGroups = (\n\t\t\t\t${synced} /* ObjcApp */,\n\t\t\t);\n`); + expect(src.match(new RegExp(synced, "g"))).toHaveLength(3); + await writeFile(pbxproj, src); + expect((await detect(root)).appTarget).toEqual([]); + }); + + it("reads an Expo app's bridging header once expo prebuild wrote it", async () => { + const dir = await expo58(); + expect((await detect(dir)).appTarget).toEqual([]); + await mkdir(path.join(dir, "ios", "LibApp.xcodeproj"), { recursive: true }); + await cp(path.join(fixtures, "pbxproj", "expo-libapp.pbxproj"), path.join(dir, "ios", "LibApp.xcodeproj", "project.pbxproj")); + await mkdir(path.join(dir, "ios", "LibApp")); + // A config plugin's imports: the library's header and React Native's, both left to the build. + await writeFile( + path.join(dir, "ios", "LibApp", "LibApp-Bridging-Header.h"), + '#import \n#import "RNAppAuthAuthorizationFlowManager.h"\n', + ); + expect((await detect(dir)).appTarget).toEqual([ + "ℹ app-includes — 2 includes into React Native's or the libraries' headers: checked at build", + ]); + // A header next to it in ios/ is not copied: the build stops, and the line says why. + await writeFile(path.join(dir, "ios", "LibApp", "LibApp-Shared.h"), "// shared\n"); + await writeFile( + path.join(dir, "ios", "LibApp", "LibApp-Bridging-Header.h"), + '#import \n#import "LibApp-Shared.h"\n', + ); + expect((await detect(dir)).appTarget).toEqual([ + '✖ app-includes — ios/LibApp/LibApp-Bridging-Header.h:2 imports "LibApp-Shared.h", which is not among the files ' + + "rn-xtool copies next to ios/LibApp/LibApp-Bridging-Header.h or in the app target's headers; " + + "ios/LibApp/LibApp-Shared.h exists, but rn-xtool copies only the bridging header of an Expo app", + "ℹ app-includes — 1 includes into React Native's or the libraries' headers: checked at build", + ]); + // A setting naming a missing file stops the build's check too: an error line, not silence. + await rm(path.join(dir, "ios", "LibApp", "LibApp-Bridging-Header.h")); + expect((await detect(dir)).appTarget).toEqual([ + "✖ app-includes — SWIFT_OBJC_BRIDGING_HEADER in ios/LibApp.xcodeproj names LibApp/LibApp-Bridging-Header.h, which " + + "does not exist. Run rn-xtool build --clean to run expo prebuild again.", + ]); + }); + it("leaves the React Native fields out without react-native", async () => { const c = await detect(await bare(null), noNetwork); expect(c.rnVersion).toBeUndefined(); diff --git a/tests/cli.test.ts b/tests/cli.test.ts index 00e7a80..1b13626 100644 --- a/tests/cli.test.ts +++ b/tests/cli.test.ts @@ -51,6 +51,16 @@ describe("buildProgram", () => { expect(runCmd.options.map((o) => o.flags)).toContain("--network [ip]"); }); + it("offers --skip-precheck on build and run", () => { + for (const name of ["build", "run"]) { + const cmd = buildProgram().commands.find((c) => c.name() === name)!; + expect(cmd.options.map((o) => [o.flags, o.description])).toContainEqual([ + "--skip-precheck", + "skip the check of the app's own sources before xtool-build", + ]); + } + }); + it("doctor has --project and --report", () => { const doctorCmd = buildProgram().commands.find((c) => c.name() === "doctor")!; expect(doctorCmd.options.map((o) => [o.flags, o.description])).toEqual([ diff --git a/tests/doctor.test.ts b/tests/doctor.test.ts index a23bee3..d70c123 100644 --- a/tests/doctor.test.ts +++ b/tests/doctor.test.ts @@ -773,6 +773,33 @@ describe("doctor --project", () => { expect(r.ok).toBe(true); }); + it("--project reports the app's includes", async () => { + const error = 'ios/main.m:9 imports "AppDelegate.h", which is not in ios or the app target\'s headers'; + const xcconfig = "ios/Config/App.xcconfig sets HEADER_SEARCH_PATHS for the app target; rn-xtool does not read xcconfig files"; + const pending = "4 includes into React Native's or the libraries' headers: checked at build"; + const run = (appTarget: string[]) => + doctorWithProbes( + { ...good, capabilities: async () => ({ ...expo58Caps, orphanPatches: ["⚠ patches/x+1.0.0.patch is for x."], limits: [], appTarget }) }, + "/proj", + { projectOnly: true }, + ); + const r = await run([`✖ app-includes — ${error}`, `⚠ app-target — ${xcconfig}`, `ℹ app-includes — ${pending}`]); + expect(r.checks.filter((c) => c.name.startsWith("app-"))).toEqual([ + { name: "app-includes", status: "fail", detail: error }, + { name: "app-target", status: "warn", detail: xcconfig }, + { name: "app-includes", status: "info", detail: pending }, + ]); + // After patches, before known-limits. + expect(r.checks.map((c) => c.name).slice(-5)).toEqual(["patches", "app-includes", "app-target", "app-includes", "known-limits"]); + expect(renderReport(r.checks)).toContain(`✖ app-includes — ${error}`); + expect(r.ok).toBe(false); + const resolved = "2 includes of the app's own sources resolve"; + expect((await run([`✔ app-includes — ${resolved}`])).checks.filter((c) => c.name.startsWith("app-"))).toEqual([ + { name: "app-includes", status: "ok", detail: resolved }, + ]); + expect((await run([])).checks.some((c) => c.name.startsWith("app-"))).toBe(false); + }); + it("--project prints an exclude line per entry", async () => { const info = "exclude — left out of this iOS build: react-native-vision-camera (rn-xtool.config.json). JavaScript that uses it must check that it is there; see https://example.invalid"; const warn = "exclude names lodash, which is not a native iOS dependency of this project; ignored"; diff --git a/tests/fixtures/objc-app/app.json b/tests/fixtures/objc-app/app.json new file mode 100644 index 0000000..ab9f7a3 --- /dev/null +++ b/tests/fixtures/objc-app/app.json @@ -0,0 +1,4 @@ +{ + "name": "ObjcApp", + "displayName": "ObjcApp" +} diff --git a/tests/fixtures/objc-app/ios/ObjcApp.xcodeproj/project.pbxproj b/tests/fixtures/objc-app/ios/ObjcApp.xcodeproj/project.pbxproj new file mode 100644 index 0000000..58539e2 --- /dev/null +++ b/tests/fixtures/objc-app/ios/ObjcApp.xcodeproj/project.pbxproj @@ -0,0 +1,296 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 54; + objects = { + +/* Begin PBXBuildFile section */ + 0C80B921A6F3F58F76C31292 /* libPods-ObjcApp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DCACB8F33CDC322A6C60F78 /* libPods-ObjcApp.a */; }; + 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; }; + 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 13B07F961A680F5B00A75B9A /* ObjcApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ObjcApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = ObjcApp/AppDelegate.h; sourceTree = ""; }; + 13B07FB01A68108700A75B9A /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = ObjcApp/AppDelegate.mm; sourceTree = ""; }; + 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ObjcApp/Info.plist; sourceTree = ""; }; + 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = ObjcApp/main.m; sourceTree = ""; }; + 3B4392A12AC88292D35C810B /* Pods-ObjcApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ObjcApp.debug.xcconfig"; path = "Target Support Files/Pods-ObjcApp/Pods-ObjcApp.debug.xcconfig"; sourceTree = ""; }; + 5709B34CF0A7D63546082F79 /* Pods-ObjcApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ObjcApp.release.xcconfig"; path = "Target Support Files/Pods-ObjcApp/Pods-ObjcApp.release.xcconfig"; sourceTree = ""; }; + 5DCACB8F33CDC322A6C60F78 /* libPods-ObjcApp.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ObjcApp.a"; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 13B07F8C1A680F5B00A75B9A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 0C80B921A6F3F58F76C31292 /* libPods-ObjcApp.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 13B07FAE1A68108700A75B9A /* ObjcApp */ = { + isa = PBXGroup; + children = ( + 13B07FAF1A68108700A75B9A /* AppDelegate.h */, + 13B07FB01A68108700A75B9A /* AppDelegate.mm */, + 13B07FB61A68108700A75B9A /* Info.plist */, + 13B07FB71A68108700A75B9A /* main.m */, + ); + name = ObjcApp; + sourceTree = ""; + }; + 2D16E6871FA4F8E400B85C8A /* Frameworks */ = { + isa = PBXGroup; + children = ( + 5DCACB8F33CDC322A6C60F78 /* libPods-ObjcApp.a */, + ); + name = Frameworks; + sourceTree = ""; + }; + 83CBB9F61A601CBA00E9B192 = { + isa = PBXGroup; + children = ( + 13B07FAE1A68108700A75B9A /* ObjcApp */, + 83CBBA001A601CBA00E9B192 /* Products */, + 2D16E6871FA4F8E400B85C8A /* Frameworks */, + BBD78D7AC51CEA395F1C20DB /* Pods */, + ); + indentWidth = 2; + sourceTree = ""; + tabWidth = 2; + usesTabs = 0; + }; + 83CBBA001A601CBA00E9B192 /* Products */ = { + isa = PBXGroup; + children = ( + 13B07F961A680F5B00A75B9A /* ObjcApp.app */, + ); + name = Products; + sourceTree = ""; + }; + BBD78D7AC51CEA395F1C20DB /* Pods */ = { + isa = PBXGroup; + children = ( + 3B4392A12AC88292D35C810B /* Pods-ObjcApp.debug.xcconfig */, + 5709B34CF0A7D63546082F79 /* Pods-ObjcApp.release.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 13B07F861A680F5B00A75B9A /* ObjcApp */ = { + isa = PBXNativeTarget; + buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "ObjcApp" */; + buildPhases = ( + 13B07F871A680F5B00A75B9A /* Sources */, + 13B07F8C1A680F5B00A75B9A /* Frameworks */, + 13B07F8E1A680F5B00A75B9A /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ObjcApp; + productName = ObjcApp; + productReference = 13B07F961A680F5B00A75B9A /* ObjcApp.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 83CBB9F71A601CBA00E9B192 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1210; + }; + buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "ObjcApp" */; + compatibilityVersion = "Xcode 12.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 83CBB9F61A601CBA00E9B192; + productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 13B07F861A680F5B00A75B9A /* ObjcApp */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 13B07F8E1A680F5B00A75B9A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 13B07F871A680F5B00A75B9A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */, + 13B07FC11A68108700A75B9A /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 13B07F941A680F5B00A75B9A /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 3B4392A12AC88292D35C810B /* Pods-ObjcApp.debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = 1; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = ObjcApp/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 15.1; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + OTHER_LDFLAGS = ( + "$(inherited)", + "-ObjC", + "-lc++", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.objcapp; + PRODUCT_NAME = ObjcApp; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Debug; + }; + 13B07F951A680F5B00A75B9A /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 5709B34CF0A7D63546082F79 /* Pods-ObjcApp.release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = 1; + INFOPLIST_FILE = ObjcApp/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 15.1; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + OTHER_LDFLAGS = ( + "$(inherited)", + "-ObjC", + "-lc++", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.objcapp; + PRODUCT_NAME = ObjcApp; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Release; + }; + 83CBBA201A601CBA00E9B192 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "c++20"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + IPHONEOS_DEPLOYMENT_TARGET = 15.1; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + OTHER_CPLUSPLUSFLAGS = ( + "$(OTHER_CFLAGS)", + "-DFOLLY_NO_CONFIG", + "-DFOLLY_MOBILE=1", + "-DFOLLY_USE_LIBCPP=1", + "-DFOLLY_CFG_NO_COROUTINES=1", + "-DFOLLY_HAVE_CLOCK_GETTIME=1", + ); + SDKROOT = iphoneos; + }; + name = Debug; + }; + 83CBBA211A601CBA00E9B192 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "c++20"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 15.1; + MTL_ENABLE_DEBUG_INFO = NO; + OTHER_CPLUSPLUSFLAGS = ( + "$(OTHER_CFLAGS)", + "-DFOLLY_NO_CONFIG", + "-DFOLLY_MOBILE=1", + "-DFOLLY_USE_LIBCPP=1", + "-DFOLLY_CFG_NO_COROUTINES=1", + "-DFOLLY_HAVE_CLOCK_GETTIME=1", + ); + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "ObjcApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 13B07F941A680F5B00A75B9A /* Debug */, + 13B07F951A680F5B00A75B9A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "ObjcApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 83CBBA201A601CBA00E9B192 /* Debug */, + 83CBBA211A601CBA00E9B192 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */; +} diff --git a/tests/fixtures/objc-app/ios/ObjcApp/AppDelegate.h b/tests/fixtures/objc-app/ios/ObjcApp/AppDelegate.h new file mode 100644 index 0000000..5d34816 --- /dev/null +++ b/tests/fixtures/objc-app/ios/ObjcApp/AppDelegate.h @@ -0,0 +1,12 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. + */ + +#import +#import + +@interface AppDelegate : RCTAppDelegate + +@end diff --git a/tests/fixtures/objc-app/ios/ObjcApp/AppDelegate.mm b/tests/fixtures/objc-app/ios/ObjcApp/AppDelegate.mm new file mode 100644 index 0000000..3f1a3c7 --- /dev/null +++ b/tests/fixtures/objc-app/ios/ObjcApp/AppDelegate.mm @@ -0,0 +1,37 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. + */ + +#import "AppDelegate.h" + +#import + +@implementation AppDelegate + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + self.moduleName = @"ObjcApp"; + // You can add your custom initial props in the dictionary below. + // They will be passed down to the ViewController used by React Native. + self.initialProps = @{}; + + return [super application:application didFinishLaunchingWithOptions:launchOptions]; +} + +- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge +{ + return [self bundleURL]; +} + +- (NSURL *)bundleURL +{ +#if DEBUG + return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; +#else + return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; +#endif +} + +@end diff --git a/tests/fixtures/objc-app/ios/ObjcApp/Info.plist b/tests/fixtures/objc-app/ios/ObjcApp/Info.plist new file mode 100644 index 0000000..f59733e --- /dev/null +++ b/tests/fixtures/objc-app/ios/ObjcApp/Info.plist @@ -0,0 +1,49 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleDisplayName + ObjcApp + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + $(MARKETING_VERSION) + CFBundleSignature + ???? + CFBundleVersion + $(CURRENT_PROJECT_VERSION) + LSRequiresIPhoneOS + + NSAppTransportSecurity + + NSAllowsArbitraryLoads + + NSAllowsLocalNetworking + + + NSLocationWhenInUseUsageDescription + + UIRequiredDeviceCapabilities + + arm64 + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + UIInterfaceOrientationLandscapeLeft + UIInterfaceOrientationLandscapeRight + + UIViewControllerBasedStatusBarAppearance + + + diff --git a/tests/fixtures/objc-app/ios/ObjcApp/main.m b/tests/fixtures/objc-app/ios/ObjcApp/main.m new file mode 100644 index 0000000..e5e5823 --- /dev/null +++ b/tests/fixtures/objc-app/ios/ObjcApp/main.m @@ -0,0 +1,16 @@ +/** + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE file in the root directory of this source tree. + */ + +#import + +#import "AppDelegate.h" + +int main(int argc, char *argv[]) +{ + @autoreleasepool { + return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); + } +} diff --git a/tests/fixtures/objc-app/package.json b/tests/fixtures/objc-app/package.json new file mode 100644 index 0000000..78bc839 --- /dev/null +++ b/tests/fixtures/objc-app/package.json @@ -0,0 +1,13 @@ +{ + "name": "ObjcApp", + "version": "0.0.1", + "private": true, + "scripts": { + "ios": "react-native run-ios", + "start": "react-native start" + }, + "dependencies": { + "react": "19.3.0", + "react-native": "0.88.1" + } +} diff --git a/tests/fixtures/pbxproj/objc-root-group.pbxproj b/tests/fixtures/pbxproj/objc-root-group.pbxproj new file mode 100644 index 0000000..bc8cb3c --- /dev/null +++ b/tests/fixtures/pbxproj/objc-root-group.pbxproj @@ -0,0 +1,296 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 54; + objects = { + +/* Begin PBXBuildFile section */ + 0C80B921A6F3F58F76C31292 /* libPods-ObjcApp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5DCACB8F33CDC322A6C60F78 /* libPods-ObjcApp.a */; }; + 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; }; + 13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 13B07F961A680F5B00A75B9A /* ObjcApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ObjcApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 13B07FAF1A68108700A75B9A /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AppDelegate.h; path = AppDelegate.h; sourceTree = ""; }; + 13B07FB01A68108700A75B9A /* AppDelegate.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; name = AppDelegate.mm; path = AppDelegate.mm; sourceTree = ""; }; + 13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = ObjcApp/Info.plist; sourceTree = ""; }; + 13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = main.m; sourceTree = ""; }; + 3B4392A12AC88292D35C810B /* Pods-ObjcApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ObjcApp.debug.xcconfig"; path = "Target Support Files/Pods-ObjcApp/Pods-ObjcApp.debug.xcconfig"; sourceTree = ""; }; + 5709B34CF0A7D63546082F79 /* Pods-ObjcApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ObjcApp.release.xcconfig"; path = "Target Support Files/Pods-ObjcApp/Pods-ObjcApp.release.xcconfig"; sourceTree = ""; }; + 5DCACB8F33CDC322A6C60F78 /* libPods-ObjcApp.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-ObjcApp.a"; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 13B07F8C1A680F5B00A75B9A /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 0C80B921A6F3F58F76C31292 /* libPods-ObjcApp.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 13B07FAE1A68108700A75B9A /* ObjcApp */ = { + isa = PBXGroup; + children = ( + 13B07FB61A68108700A75B9A /* Info.plist */, + ); + name = ObjcApp; + sourceTree = ""; + }; + 2D16E6871FA4F8E400B85C8A /* Frameworks */ = { + isa = PBXGroup; + children = ( + 5DCACB8F33CDC322A6C60F78 /* libPods-ObjcApp.a */, + ); + name = Frameworks; + sourceTree = ""; + }; + 83CBB9F61A601CBA00E9B192 = { + isa = PBXGroup; + children = ( + 13B07FAF1A68108700A75B9A /* AppDelegate.h */, + 13B07FB01A68108700A75B9A /* AppDelegate.mm */, + 13B07FB71A68108700A75B9A /* main.m */, + 13B07FAE1A68108700A75B9A /* ObjcApp */, + 83CBBA001A601CBA00E9B192 /* Products */, + 2D16E6871FA4F8E400B85C8A /* Frameworks */, + BBD78D7AC51CEA395F1C20DB /* Pods */, + ); + indentWidth = 2; + sourceTree = ""; + tabWidth = 2; + usesTabs = 0; + }; + 83CBBA001A601CBA00E9B192 /* Products */ = { + isa = PBXGroup; + children = ( + 13B07F961A680F5B00A75B9A /* ObjcApp.app */, + ); + name = Products; + sourceTree = ""; + }; + BBD78D7AC51CEA395F1C20DB /* Pods */ = { + isa = PBXGroup; + children = ( + 3B4392A12AC88292D35C810B /* Pods-ObjcApp.debug.xcconfig */, + 5709B34CF0A7D63546082F79 /* Pods-ObjcApp.release.xcconfig */, + ); + path = Pods; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 13B07F861A680F5B00A75B9A /* ObjcApp */ = { + isa = PBXNativeTarget; + buildConfigurationList = 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "ObjcApp" */; + buildPhases = ( + 13B07F871A680F5B00A75B9A /* Sources */, + 13B07F8C1A680F5B00A75B9A /* Frameworks */, + 13B07F8E1A680F5B00A75B9A /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = ObjcApp; + productName = ObjcApp; + productReference = 13B07F961A680F5B00A75B9A /* ObjcApp.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 83CBB9F71A601CBA00E9B192 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1210; + }; + buildConfigurationList = 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "ObjcApp" */; + compatibilityVersion = "Xcode 12.0"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 83CBB9F61A601CBA00E9B192; + productRefGroup = 83CBBA001A601CBA00E9B192 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 13B07F861A680F5B00A75B9A /* ObjcApp */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 13B07F8E1A680F5B00A75B9A /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 13B07F871A680F5B00A75B9A /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */, + 13B07FC11A68108700A75B9A /* main.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin XCBuildConfiguration section */ + 13B07F941A680F5B00A75B9A /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 3B4392A12AC88292D35C810B /* Pods-ObjcApp.debug.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = 1; + ENABLE_BITCODE = NO; + INFOPLIST_FILE = ObjcApp/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 15.1; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + OTHER_LDFLAGS = ( + "$(inherited)", + "-ObjC", + "-lc++", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.objcapp; + PRODUCT_NAME = ObjcApp; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Debug; + }; + 13B07F951A680F5B00A75B9A /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 5709B34CF0A7D63546082F79 /* Pods-ObjcApp.release.xcconfig */; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CLANG_ENABLE_MODULES = YES; + CURRENT_PROJECT_VERSION = 1; + INFOPLIST_FILE = ObjcApp/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 15.1; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + OTHER_LDFLAGS = ( + "$(inherited)", + "-ObjC", + "-lc++", + ); + PRODUCT_BUNDLE_IDENTIFIER = com.example.objcapp; + PRODUCT_NAME = ObjcApp; + TARGETED_DEVICE_FAMILY = "1,2"; + VERSIONING_SYSTEM = "apple-generic"; + }; + name = Release; + }; + 83CBBA201A601CBA00E9B192 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "c++20"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + IPHONEOS_DEPLOYMENT_TARGET = 15.1; + MTL_ENABLE_DEBUG_INFO = YES; + ONLY_ACTIVE_ARCH = YES; + OTHER_CPLUSPLUSFLAGS = ( + "$(OTHER_CFLAGS)", + "-DFOLLY_NO_CONFIG", + "-DFOLLY_MOBILE=1", + "-DFOLLY_USE_LIBCPP=1", + "-DFOLLY_CFG_NO_COROUTINES=1", + "-DFOLLY_HAVE_CLOCK_GETTIME=1", + ); + SDKROOT = iphoneos; + }; + name = Debug; + }; + 83CBBA211A601CBA00E9B192 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_CXX_LANGUAGE_STANDARD = "c++20"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + COPY_PHASE_STRIP = YES; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + IPHONEOS_DEPLOYMENT_TARGET = 15.1; + MTL_ENABLE_DEBUG_INFO = NO; + OTHER_CPLUSPLUSFLAGS = ( + "$(OTHER_CFLAGS)", + "-DFOLLY_NO_CONFIG", + "-DFOLLY_MOBILE=1", + "-DFOLLY_USE_LIBCPP=1", + "-DFOLLY_CFG_NO_COROUTINES=1", + "-DFOLLY_HAVE_CLOCK_GETTIME=1", + ); + SDKROOT = iphoneos; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 13B07F931A680F5B00A75B9A /* Build configuration list for PBXNativeTarget "ObjcApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 13B07F941A680F5B00A75B9A /* Debug */, + 13B07F951A680F5B00A75B9A /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 83CBB9FA1A601CBA00E9B192 /* Build configuration list for PBXProject "ObjcApp" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 83CBBA201A601CBA00E9B192 /* Debug */, + 83CBBA211A601CBA00E9B192 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 83CBB9F71A601CBA00E9B192 /* Project object */; +} diff --git a/tests/fixtures/precheck/golden/bare-085/commands.json b/tests/fixtures/precheck/golden/bare-085/commands.json new file mode 100644 index 0000000..4c6a095 --- /dev/null +++ b/tests/fixtures/precheck/golden/bare-085/commands.json @@ -0,0 +1,239 @@ +{ + "swiftDriver": [ + [ + "builtin-SwiftDriver", + "--", + "/home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin/swiftc", + "-parse-as-library", + "-resource-dir", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift", + "-Xcc", + "-resource-dir", + "-Xcc", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang", + "-module-name", + "App", + "-Onone", + "@/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App.SwiftFileList", + "-DSWIFT_PACKAGE", + "-DDEBUG", + "-DSWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE", + "-DDEBUG", + "-Xcc", + "-fmodule-map-file=/home/me/bare-085/ios/build/xcframeworks/ReactHeadersTarget/include/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactCodegen.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactAppDependencyProvider.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNGestureHandler.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactNativeSafeAreaContext.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-085/ios/build/generated/autolinking/libs/RNScreens/ios/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNSVG.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-085/ios/build/generated/ios/ReactAppHeaders/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactNativeWebview.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNXtoolDevSupport.modulemap", + "-DXcode", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-gesture-handler/apple/Handlers", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-gesture-handler/apple", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-gesture-handler/shared/runtime", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-gesture-handler/.", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-svg/common/cpp", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-svg/apple/Brushes", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-svg/apple/Elements", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-svg/apple/Filters/MetalCI", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-svg/apple/Filters", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-svg/apple", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-svg/apple/Shapes", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-svg/apple/Text", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-svg/apple/Utils", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-svg/apple/ViewManagers", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-svg/common/cpp/react/renderer/components/rnsvg", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-svg/.", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-svg/include", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/common/cpp", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/utils", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/cpp", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/bridging", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/conversion", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/events", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/helpers/container", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/helpers/image", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/helpers/scroll-view", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/integrations", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/safe-area", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/stubs", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/tabs", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/tabs/bottom-accessory", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/tabs/extensions", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/tabs/host", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/tabs/screen", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/utils", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/ios/utils/extensions", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/.", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-screens/include", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-webview/apple", + "-Xcc", + "-I/home/me/bare-085/node_modules/react-native-webview/.", + "-Xfrontend", + "-enable-cross-import-overlays", + "-external-plugin-path", + "/home/me/.local/share/swiftly/toolchains/6.4.1/usr/lib/swift/host/plugins/testing#/home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin/swift-plugin-server", + "-enable-experimental-feature", + "DebugDescriptionMacro", + "-sdk", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk", + "-target", + "arm64-apple-ios16.4", + "-g", + "-module-cache-path", + "/home/me/bare-085/ios-xtool/.build/out/ModuleCache.noindex", + "-Xfrontend", + "-serialize-debugging-options", + "-enable-testing", + "-index-store-path", + "/home/me/bare-085/ios-xtool/.build/out", + "-Xcc", + "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG", + "-swift-version", + "5", + "-I", + "/home/me/bare-085/ios-xtool/.build/out/Products/Debug-iphoneos", + "-Isystem", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib", + "-F", + "/home/me/bare-085/ios-xtool/.build/out/Products/Debug-iphoneos/PackageFrameworks", + "-F", + "/home/me/bare-085/ios-xtool/.build/out/Products/Debug-iphoneos", + "-F", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks", + "-F", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk/Developer/Library/Frameworks", + "-c", + "-j12", + "-enable-batch-mode", + "-incremental", + "-output-file-map", + "/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-OutputFileMap.json", + "-save-temps", + "-color-diagnostics", + "-explicit-module-build", + "-module-cache-path", + "/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/SwiftExplicitPrecompiledModules", + "-clang-scanner-module-cache-path", + "/home/me/bare-085/ios-xtool/.build/out/ModuleCache.noindex", + "-sdk-module-cache-path", + "/home/me/bare-085/ios-xtool/.build/out/SDKExplicitPrecompiledModules", + "-emit-dependencies", + "-emit-module", + "-emit-module-path", + "/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App.swiftmodule", + "-serialize-diagnostics", + "-dependency-scan-serialize-diagnostics-path", + "/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-dependency-scan.dia", + "-validate-clang-modules-once", + "-clang-build-session-file", + "/home/me/bare-085/ios-xtool/.build/out/ModuleCache.noindex/Session.modulevalidation", + "-Xcc", + "-fmodules-prune-interval=86400", + "-Xcc", + "-fmodules-prune-after=345600", + "-package-name", + "ios_xtool", + "-emit-const-values", + "-const-gather-protocols-list", + "/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App_const_extract_protocols.json", + "-Xcc", + "-I/home/me/bare-085/ios/build/xcframeworks/ReactHeadersTarget/include", + "-Xcc", + "-I/home/me/bare-085/ios/build/generated/ios/ReactCodegen", + "-Xcc", + "-I/home/me/bare-085/ios/build/generated/ios/ReactAppDependencyProvider", + "-Xcc", + "-I/home/me/bare-085/ios/build/generated/autolinking/libs/RNGestureHandler/include", + "-Xcc", + "-I/home/me/bare-085/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios", + "-Xcc", + "-I/home/me/bare-085/ios/build/generated/autolinking/libs/RNScreens/ios", + "-Xcc", + "-I/home/me/bare-085/ios/build/generated/autolinking/libs/RNSVG/apple", + "-Xcc", + "-I/home/me/bare-085/ios/build/generated/ios/ReactAppHeaders", + "-Xcc", + "-I/home/me/bare-085/ios/build/generated/autolinking/libs/ReactNativeWebview/apple", + "-Xcc", + "-I/home/me/bare-085/ios-xtool/Sources/RNXtoolDevSupport/include", + "-Xcc", + "-I/home/me/bare-085/ios-xtool/.build/out/Products/Debug-iphoneos/include", + "-Xcc", + "-I/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources-normal/arm64", + "-Xcc", + "-I/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources/arm64", + "-Xcc", + "-I/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources", + "-Xcc", + "-DSWIFT_PACKAGE", + "-Xcc", + "-DDEBUG=1", + "-emit-objc-header", + "-emit-objc-header-path", + "/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-Swift.h", + "-working-directory", + "/home/me/bare-085/ios-xtool/xtool", + "-experimental-emit-module-separately", + "-disable-cmo" + ] + ], + "compileC": [] +} \ No newline at end of file diff --git a/tests/fixtures/precheck/golden/bare-085/inputs.json b/tests/fixtures/precheck/golden/bare-085/inputs.json new file mode 100644 index 0000000..f87a359 --- /dev/null +++ b/tests/fixtures/precheck/golden/bare-085/inputs.json @@ -0,0 +1,216 @@ +{ + "app": { + "pkg": { + "iosDir": "/home/me/bare-085/ios", + "frameworks": [ + { + "id": "react", + "name": "React", + "executable": "React", + "searchPath": "/home/me/bare-085/ios/build/xcframeworks/debug/React.xcframework/ios-arm64", + "frameworkDir": "/home/me/bare-085/ios/build/xcframeworks/debug/React.xcframework/ios-arm64/React.framework" + }, + { + "id": "react-native-dependencies", + "name": "ReactNativeDependencies", + "executable": "ReactNativeDependencies", + "searchPath": "/home/me/bare-085/ios/build/xcframeworks/debug/ReactNativeDependencies.xcframework/ios-arm64", + "frameworkDir": "/home/me/bare-085/ios/build/xcframeworks/debug/ReactNativeDependencies.xcframework/ios-arm64/ReactNativeDependencies.framework" + }, + { + "id": "hermes", + "name": "hermesvm", + "executable": "hermesvm", + "searchPath": "/home/me/bare-085/ios/build/xcframeworks/debug/hermes-engine.xcframework/ios-arm64", + "frameworkDir": "/home/me/bare-085/ios/build/xcframeworks/debug/hermes-engine.xcframework/ios-arm64/hermesvm.framework" + } + ], + "iosMin": "16.4", + "app": { + "mixed": false, + "defines": [ + "DEBUG=1" + ], + "headerSearchPaths": [ + "/home/me/bare-085/ios/build/xcframeworks/ReactHeadersTarget/include/React", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/CoreModules", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTAnimation", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTBlob", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTDeprecation", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTImage", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSettings", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSwiftUIWrapper", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTText", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTVibration", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/ReactCommon", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/React_RCTAppDelegate", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/reactperflogger", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/yoga" + ], + "cxxStandard": "c++20", + "swiftHeadersDir": "/home/me/bare-085/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos", + "importerPaths": [ + "/home/me/bare-085/node_modules/react-native-gesture-handler/apple/Handlers", + "/home/me/bare-085/node_modules/react-native-gesture-handler/apple", + "/home/me/bare-085/node_modules/react-native-gesture-handler/shared/runtime", + "/home/me/bare-085/node_modules/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen", + "/home/me/bare-085/node_modules/react-native-gesture-handler/.", + "/home/me/bare-085/node_modules/react-native-svg/common/cpp", + "/home/me/bare-085/node_modules/react-native-svg/apple/Brushes", + "/home/me/bare-085/node_modules/react-native-svg/apple/Elements", + "/home/me/bare-085/node_modules/react-native-svg/apple/Filters/MetalCI", + "/home/me/bare-085/node_modules/react-native-svg/apple/Filters", + "/home/me/bare-085/node_modules/react-native-svg/apple", + "/home/me/bare-085/node_modules/react-native-svg/apple/Shapes", + "/home/me/bare-085/node_modules/react-native-svg/apple/Text", + "/home/me/bare-085/node_modules/react-native-svg/apple/Utils", + "/home/me/bare-085/node_modules/react-native-svg/apple/ViewManagers", + "/home/me/bare-085/node_modules/react-native-svg/common/cpp/react/renderer/components/rnsvg", + "/home/me/bare-085/node_modules/react-native-svg/.", + "/home/me/bare-085/node_modules/react-native-svg/include", + "/home/me/bare-085/node_modules/react-native-screens/common/cpp", + "/home/me/bare-085/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens", + "/home/me/bare-085/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/utils", + "/home/me/bare-085/node_modules/react-native-screens/cpp", + "/home/me/bare-085/node_modules/react-native-screens/ios", + "/home/me/bare-085/node_modules/react-native-screens/ios/bridging", + "/home/me/bare-085/node_modules/react-native-screens/ios/conversion", + "/home/me/bare-085/node_modules/react-native-screens/ios/events", + "/home/me/bare-085/node_modules/react-native-screens/ios/helpers/container", + "/home/me/bare-085/node_modules/react-native-screens/ios/helpers/image", + "/home/me/bare-085/node_modules/react-native-screens/ios/helpers/scroll-view", + "/home/me/bare-085/node_modules/react-native-screens/ios/integrations", + "/home/me/bare-085/node_modules/react-native-screens/ios/safe-area", + "/home/me/bare-085/node_modules/react-native-screens/ios/stubs", + "/home/me/bare-085/node_modules/react-native-screens/ios/tabs", + "/home/me/bare-085/node_modules/react-native-screens/ios/tabs/bottom-accessory", + "/home/me/bare-085/node_modules/react-native-screens/ios/tabs/extensions", + "/home/me/bare-085/node_modules/react-native-screens/ios/tabs/host", + "/home/me/bare-085/node_modules/react-native-screens/ios/tabs/screen", + "/home/me/bare-085/node_modules/react-native-screens/ios/utils", + "/home/me/bare-085/node_modules/react-native-screens/ios/utils/extensions", + "/home/me/bare-085/node_modules/react-native-screens/.", + "/home/me/bare-085/node_modules/react-native-screens/include", + "/home/me/bare-085/node_modules/react-native-webview/apple", + "/home/me/bare-085/node_modules/react-native-webview/." + ] + }, + "devSupport": true + }, + "origins": { + "/home/me/bare-085/ios-xtool/Sources/App/AppDelegate.swift": "/home/me/bare-085/ios/BareDemo/AppDelegate.swift" + } + }, + "graph": { + "headerDirs": [ + "/home/me/bare-085/ios/build/xcframeworks/ReactHeadersTarget/include", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeDependenciesHeaders.xcframework/ios-arm64/Headers", + "/home/me/bare-085/ios/build/generated/ios/ReactCodegen", + "/home/me/bare-085/ios/build/generated/ios/ReactAppHeaders", + "/home/me/bare-085/ios/build/generated/ios/ReactAppDependencyProvider", + "/home/me/bare-085/ios/build/generated/autolinking/libs/RNGestureHandler/include", + "/home/me/bare-085/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios", + "/home/me/bare-085/ios/build/generated/autolinking/libs/RNScreens/ios", + "/home/me/bare-085/ios/build/generated/autolinking/libs/RNSVG/apple", + "/home/me/bare-085/ios/build/generated/autolinking/libs/ReactNativeWebview/apple", + "/home/me/bare-085/ios-xtool/Sources/RNXtoolDevSupport/include" + ], + "moduleMaps": [ + "/home/me/bare-085/ios/build/xcframeworks/ReactHeadersTarget/include/module.modulemap", + "/home/me/bare-085/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/module.modulemap", + "/home/me/bare-085/ios/build/generated/ios/ReactAppHeaders/module.modulemap", + "/home/me/bare-085/ios/build/generated/autolinking/libs/RNScreens/ios/module.modulemap" + ], + "synthesized": [ + { + "module": "ReactCodegen", + "text": "module ReactCodegen {\n umbrella \"/home/me/bare-085/ios/build/generated/ios/ReactCodegen\"\n export *\n}\n" + }, + { + "module": "ReactAppDependencyProvider", + "text": "module ReactAppDependencyProvider {\n umbrella \"/home/me/bare-085/ios/build/generated/ios/ReactAppDependencyProvider\"\n export *\n}\n" + }, + { + "module": "RNGestureHandler", + "text": "module RNGestureHandler {\n umbrella header \"/home/me/bare-085/ios/build/generated/autolinking/libs/RNGestureHandler/include/RNGestureHandler/RNGestureHandler.h\"\n export *\n}\n" + }, + { + "module": "ReactNativeSafeAreaContext", + "text": "module ReactNativeSafeAreaContext {\n umbrella \"/home/me/bare-085/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios\"\n export *\n}\n" + }, + { + "module": "RNSVG", + "text": "module RNSVG {\n umbrella \"/home/me/bare-085/ios/build/generated/autolinking/libs/RNSVG/apple\"\n export *\n}\n" + }, + { + "module": "ReactNativeWebview", + "text": "module ReactNativeWebview {\n umbrella \"/home/me/bare-085/ios/build/generated/autolinking/libs/ReactNativeWebview/apple\"\n export *\n}\n" + }, + { + "module": "RNXtoolDevSupport", + "text": "module RNXtoolDevSupport {\n umbrella header \"/home/me/bare-085/ios-xtool/Sources/RNXtoolDevSupport/include/RNXtoolDevSupport.h\"\n export *\n}\n" + } + ], + "targets": [ + "App", + "RNXtoolDevSupport", + "ReactHeaders", + "ReactNativeHeaders", + "ReactNativeDependenciesHeaders", + "ReactCodegen", + "ReactAppDependencyProvider", + "ReactAppHeaders", + "AutolinkedAggregate", + "Autolinked", + "RNGestureHandler", + "ReactNativeSafeAreaContext", + "RNScreens", + "RNSVG", + "ReactNativeWebview" + ], + "modules": [ + "React", + "CoreModules", + "RCTAnimation", + "RCTBlob", + "RCTDeprecation", + "RCTImage", + "RCTSettings", + "RCTSwiftUIWrapper", + "RCTText", + "RCTVibration", + "ReactCommon", + "React_RCTAppDelegate", + "ReactNativeHeaders_react", + "reactperflogger", + "yoga", + "ReactAppHeaders", + "RNScreens", + "ReactCodegen", + "ReactAppDependencyProvider", + "RNGestureHandler", + "ReactNativeSafeAreaContext", + "RNSVG", + "ReactNativeWebview", + "RNXtoolDevSupport" + ], + "unresolved": [] + }, + "toolchain": { + "clang": "/home/me/.local/share/swiftly/bin/clang", + "swiftc": "/home/me/.local/share/swiftly/bin/swiftc", + "sdk": "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk", + "swiftResources": "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift", + "swiftIncludes": [ + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib" + ], + "swiftExtra": [ + "-Xfrontend", + "-enable-cross-import-overlays" + ], + "versions": "clang version 21.0.0 (https://github.com/swiftlang/llvm-project.git 51091bd668a61591b761afe08e2776476e20ff1c)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin\nSwift version 6.4.1 (swift-6.4.1-RELEASE)\nTarget: x86_64-unknown-linux-gnu\nepoch=4,darwinTools=1.1.0,oam=1.4.1" + }, + "dir": "/home/me/bare-085/ios-xtool/.precheck", + "moduleCache": "/home/me/bare-085/ios-xtool/.precheck/ModuleCache/rn0.85.0-b534cbed0fc4" +} diff --git a/tests/fixtures/precheck/golden/bare-086/commands.json b/tests/fixtures/precheck/golden/bare-086/commands.json new file mode 100644 index 0000000..57f1106 --- /dev/null +++ b/tests/fixtures/precheck/golden/bare-086/commands.json @@ -0,0 +1,247 @@ +{ + "swiftDriver": [ + [ + "builtin-SwiftDriver", + "--", + "/home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin/swiftc", + "-parse-as-library", + "-resource-dir", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift", + "-Xcc", + "-resource-dir", + "-Xcc", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang", + "-module-name", + "App", + "-Onone", + "@/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App.SwiftFileList", + "-DSWIFT_PACKAGE", + "-DDEBUG", + "-DSWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE", + "-DDEBUG", + "-Xcc", + "-fmodule-map-file=/home/me/bare-086/ios/build/xcframeworks/ReactHeadersTarget/include/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactCodegen.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactAppDependencyProvider.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNGestureHandler.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNReanimated.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactNativeSafeAreaContext.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-086/ios/build/generated/autolinking/libs/RNScreens/ios/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNSVG.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactNativeWebview.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-086/ios/build/generated/ios/ReactAppHeaders/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNWorklets.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNXtoolDevSupport.modulemap", + "-DXcode", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-gesture-handler/apple/Handlers", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-gesture-handler/apple", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-gesture-handler/shared/runtime", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-gesture-handler/.", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-svg/common/cpp", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-svg/apple/Brushes", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-svg/apple/Elements", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-svg/apple/Filters/MetalCI", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-svg/apple/Filters", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-svg/apple", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-svg/apple/Shapes", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-svg/apple/Text", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-svg/apple/Utils", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-svg/apple/ViewManagers", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-svg/common/cpp/react/renderer/components/rnsvg", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-svg/.", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-svg/include", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/common/cpp", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/utils", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/cpp", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/bridging", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/conversion", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/events", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/helpers/container", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/helpers/image", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/helpers/scroll-view", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/integrations", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/safe-area", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/stubs", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/tabs", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/tabs/bottom-accessory", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/tabs/extensions", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/tabs/host", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/tabs/screen", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/utils", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/ios/utils/extensions", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/.", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-screens/include", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-webview/apple", + "-Xcc", + "-I/home/me/bare-086/node_modules/react-native-webview/.", + "-Xfrontend", + "-enable-cross-import-overlays", + "-external-plugin-path", + "/home/me/.local/share/swiftly/toolchains/6.4.1/usr/lib/swift/host/plugins/testing#/home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin/swift-plugin-server", + "-enable-experimental-feature", + "DebugDescriptionMacro", + "-sdk", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk", + "-target", + "arm64-apple-ios16.4", + "-g", + "-module-cache-path", + "/home/me/bare-086/ios-xtool/.build/out/ModuleCache.noindex", + "-Xfrontend", + "-serialize-debugging-options", + "-enable-testing", + "-index-store-path", + "/home/me/bare-086/ios-xtool/.build/out", + "-Xcc", + "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG", + "-swift-version", + "5", + "-I", + "/home/me/bare-086/ios-xtool/.build/out/Products/Debug-iphoneos", + "-Isystem", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib", + "-F", + "/home/me/bare-086/ios-xtool/.build/out/Products/Debug-iphoneos/PackageFrameworks", + "-F", + "/home/me/bare-086/ios-xtool/.build/out/Products/Debug-iphoneos", + "-F", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks", + "-F", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk/Developer/Library/Frameworks", + "-c", + "-j12", + "-enable-batch-mode", + "-incremental", + "-output-file-map", + "/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-OutputFileMap.json", + "-save-temps", + "-color-diagnostics", + "-explicit-module-build", + "-module-cache-path", + "/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/SwiftExplicitPrecompiledModules", + "-clang-scanner-module-cache-path", + "/home/me/bare-086/ios-xtool/.build/out/ModuleCache.noindex", + "-sdk-module-cache-path", + "/home/me/bare-086/ios-xtool/.build/out/SDKExplicitPrecompiledModules", + "-emit-dependencies", + "-emit-module", + "-emit-module-path", + "/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App.swiftmodule", + "-serialize-diagnostics", + "-dependency-scan-serialize-diagnostics-path", + "/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-dependency-scan.dia", + "-validate-clang-modules-once", + "-clang-build-session-file", + "/home/me/bare-086/ios-xtool/.build/out/ModuleCache.noindex/Session.modulevalidation", + "-Xcc", + "-fmodules-prune-interval=86400", + "-Xcc", + "-fmodules-prune-after=345600", + "-package-name", + "ios_xtool", + "-emit-const-values", + "-const-gather-protocols-list", + "/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App_const_extract_protocols.json", + "-Xcc", + "-I/home/me/bare-086/ios/build/xcframeworks/ReactHeadersTarget/include", + "-Xcc", + "-I/home/me/bare-086/ios/build/generated/ios/ReactCodegen", + "-Xcc", + "-I/home/me/bare-086/ios/build/generated/ios/ReactAppDependencyProvider", + "-Xcc", + "-I/home/me/bare-086/ios/build/generated/autolinking/libs/RNGestureHandler/include", + "-Xcc", + "-I/home/me/bare-086/ios/build/generated/autolinking/libs/RNReanimated/include", + "-Xcc", + "-I/home/me/bare-086/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios", + "-Xcc", + "-I/home/me/bare-086/ios/build/generated/autolinking/libs/RNScreens/ios", + "-Xcc", + "-I/home/me/bare-086/ios/build/generated/autolinking/libs/RNSVG/apple", + "-Xcc", + "-I/home/me/bare-086/ios/build/generated/autolinking/libs/ReactNativeWebview/apple", + "-Xcc", + "-I/home/me/bare-086/ios/build/generated/ios/ReactAppHeaders", + "-Xcc", + "-I/home/me/bare-086/ios/build/generated/autolinking/libs/RNWorklets/Common/cpp", + "-Xcc", + "-I/home/me/bare-086/ios-xtool/Sources/RNXtoolDevSupport/include", + "-Xcc", + "-I/home/me/bare-086/ios-xtool/.build/out/Products/Debug-iphoneos/include", + "-Xcc", + "-I/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources-normal/arm64", + "-Xcc", + "-I/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources/arm64", + "-Xcc", + "-I/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources", + "-Xcc", + "-DSWIFT_PACKAGE", + "-Xcc", + "-DDEBUG=1", + "-emit-objc-header", + "-emit-objc-header-path", + "/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-Swift.h", + "-working-directory", + "/home/me/bare-086/ios-xtool/xtool", + "-experimental-emit-module-separately", + "-disable-cmo" + ] + ], + "compileC": [] +} \ No newline at end of file diff --git a/tests/fixtures/precheck/golden/bare-086/inputs.json b/tests/fixtures/precheck/golden/bare-086/inputs.json new file mode 100644 index 0000000..ac36d15 --- /dev/null +++ b/tests/fixtures/precheck/golden/bare-086/inputs.json @@ -0,0 +1,230 @@ +{ + "app": { + "pkg": { + "iosDir": "/home/me/bare-086/ios", + "frameworks": [ + { + "id": "react", + "name": "React", + "executable": "React", + "searchPath": "/home/me/bare-086/ios/build/xcframeworks/debug/React.xcframework/ios-arm64", + "frameworkDir": "/home/me/bare-086/ios/build/xcframeworks/debug/React.xcframework/ios-arm64/React.framework" + }, + { + "id": "react-native-dependencies", + "name": "ReactNativeDependencies", + "executable": "ReactNativeDependencies", + "searchPath": "/home/me/bare-086/ios/build/xcframeworks/debug/ReactNativeDependencies.xcframework/ios-arm64", + "frameworkDir": "/home/me/bare-086/ios/build/xcframeworks/debug/ReactNativeDependencies.xcframework/ios-arm64/ReactNativeDependencies.framework" + }, + { + "id": "hermes", + "name": "hermesvm", + "executable": "hermesvm", + "searchPath": "/home/me/bare-086/ios/build/xcframeworks/debug/hermes-engine.xcframework/ios-arm64", + "frameworkDir": "/home/me/bare-086/ios/build/xcframeworks/debug/hermes-engine.xcframework/ios-arm64/hermesvm.framework" + } + ], + "iosMin": "16.4", + "app": { + "mixed": false, + "defines": [ + "DEBUG=1" + ], + "headerSearchPaths": [ + "/home/me/bare-086/ios/build/xcframeworks/ReactHeadersTarget/include/React", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/CoreModules", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTAnimation", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTBlob", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTDeprecation", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTImage", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSettings", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSwiftUIWrapper", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTText", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTVibration", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/ReactCommon", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/React_RCTAppDelegate", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/reactperflogger", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/yoga" + ], + "cxxStandard": "c++20", + "swiftHeadersDir": "/home/me/bare-086/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos", + "importerPaths": [ + "/home/me/bare-086/node_modules/react-native-gesture-handler/apple/Handlers", + "/home/me/bare-086/node_modules/react-native-gesture-handler/apple", + "/home/me/bare-086/node_modules/react-native-gesture-handler/shared/runtime", + "/home/me/bare-086/node_modules/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen", + "/home/me/bare-086/node_modules/react-native-gesture-handler/.", + "/home/me/bare-086/node_modules/react-native-svg/common/cpp", + "/home/me/bare-086/node_modules/react-native-svg/apple/Brushes", + "/home/me/bare-086/node_modules/react-native-svg/apple/Elements", + "/home/me/bare-086/node_modules/react-native-svg/apple/Filters/MetalCI", + "/home/me/bare-086/node_modules/react-native-svg/apple/Filters", + "/home/me/bare-086/node_modules/react-native-svg/apple", + "/home/me/bare-086/node_modules/react-native-svg/apple/Shapes", + "/home/me/bare-086/node_modules/react-native-svg/apple/Text", + "/home/me/bare-086/node_modules/react-native-svg/apple/Utils", + "/home/me/bare-086/node_modules/react-native-svg/apple/ViewManagers", + "/home/me/bare-086/node_modules/react-native-svg/common/cpp/react/renderer/components/rnsvg", + "/home/me/bare-086/node_modules/react-native-svg/.", + "/home/me/bare-086/node_modules/react-native-svg/include", + "/home/me/bare-086/node_modules/react-native-screens/common/cpp", + "/home/me/bare-086/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens", + "/home/me/bare-086/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/utils", + "/home/me/bare-086/node_modules/react-native-screens/cpp", + "/home/me/bare-086/node_modules/react-native-screens/ios", + "/home/me/bare-086/node_modules/react-native-screens/ios/bridging", + "/home/me/bare-086/node_modules/react-native-screens/ios/conversion", + "/home/me/bare-086/node_modules/react-native-screens/ios/events", + "/home/me/bare-086/node_modules/react-native-screens/ios/helpers/container", + "/home/me/bare-086/node_modules/react-native-screens/ios/helpers/image", + "/home/me/bare-086/node_modules/react-native-screens/ios/helpers/scroll-view", + "/home/me/bare-086/node_modules/react-native-screens/ios/integrations", + "/home/me/bare-086/node_modules/react-native-screens/ios/safe-area", + "/home/me/bare-086/node_modules/react-native-screens/ios/stubs", + "/home/me/bare-086/node_modules/react-native-screens/ios/tabs", + "/home/me/bare-086/node_modules/react-native-screens/ios/tabs/bottom-accessory", + "/home/me/bare-086/node_modules/react-native-screens/ios/tabs/extensions", + "/home/me/bare-086/node_modules/react-native-screens/ios/tabs/host", + "/home/me/bare-086/node_modules/react-native-screens/ios/tabs/screen", + "/home/me/bare-086/node_modules/react-native-screens/ios/utils", + "/home/me/bare-086/node_modules/react-native-screens/ios/utils/extensions", + "/home/me/bare-086/node_modules/react-native-screens/.", + "/home/me/bare-086/node_modules/react-native-screens/include", + "/home/me/bare-086/node_modules/react-native-webview/apple", + "/home/me/bare-086/node_modules/react-native-webview/." + ] + }, + "devSupport": true + }, + "origins": { + "/home/me/bare-086/ios-xtool/Sources/App/AppDelegate.swift": "/home/me/bare-086/ios/BareDemo/AppDelegate.swift" + } + }, + "graph": { + "headerDirs": [ + "/home/me/bare-086/ios/build/xcframeworks/ReactHeadersTarget/include", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeDependenciesHeaders.xcframework/ios-arm64/Headers", + "/home/me/bare-086/ios/build/generated/ios/ReactCodegen", + "/home/me/bare-086/ios/build/generated/ios/ReactAppHeaders", + "/home/me/bare-086/ios/build/generated/ios/ReactAppDependencyProvider", + "/home/me/bare-086/ios/build/generated/autolinking/libs/RNGestureHandler/include", + "/home/me/bare-086/ios/build/generated/autolinking/libs/RNWorklets/Common/cpp", + "/home/me/bare-086/ios/build/generated/autolinking/libs/RNReanimated/include", + "/home/me/bare-086/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios", + "/home/me/bare-086/ios/build/generated/autolinking/libs/RNScreens/ios", + "/home/me/bare-086/ios/build/generated/autolinking/libs/RNSVG/apple", + "/home/me/bare-086/ios/build/generated/autolinking/libs/ReactNativeWebview/apple", + "/home/me/bare-086/ios-xtool/Sources/RNXtoolDevSupport/include" + ], + "moduleMaps": [ + "/home/me/bare-086/ios/build/xcframeworks/ReactHeadersTarget/include/module.modulemap", + "/home/me/bare-086/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/module.modulemap", + "/home/me/bare-086/ios/build/generated/ios/ReactAppHeaders/module.modulemap", + "/home/me/bare-086/ios/build/generated/autolinking/libs/RNScreens/ios/module.modulemap" + ], + "synthesized": [ + { + "module": "ReactCodegen", + "text": "module ReactCodegen {\n umbrella \"/home/me/bare-086/ios/build/generated/ios/ReactCodegen\"\n export *\n}\n" + }, + { + "module": "ReactAppDependencyProvider", + "text": "module ReactAppDependencyProvider {\n umbrella \"/home/me/bare-086/ios/build/generated/ios/ReactAppDependencyProvider\"\n export *\n}\n" + }, + { + "module": "RNGestureHandler", + "text": "module RNGestureHandler {\n umbrella header \"/home/me/bare-086/ios/build/generated/autolinking/libs/RNGestureHandler/include/RNGestureHandler/RNGestureHandler.h\"\n export *\n}\n" + }, + { + "module": "RNWorklets", + "text": "module RNWorklets {\n umbrella \"/home/me/bare-086/ios/build/generated/autolinking/libs/RNWorklets/Common/cpp\"\n export *\n}\n" + }, + { + "module": "RNReanimated", + "text": "module RNReanimated {\n umbrella \"/home/me/bare-086/ios/build/generated/autolinking/libs/RNReanimated/include\"\n export *\n}\n" + }, + { + "module": "ReactNativeSafeAreaContext", + "text": "module ReactNativeSafeAreaContext {\n umbrella \"/home/me/bare-086/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios\"\n export *\n}\n" + }, + { + "module": "RNSVG", + "text": "module RNSVG {\n umbrella \"/home/me/bare-086/ios/build/generated/autolinking/libs/RNSVG/apple\"\n export *\n}\n" + }, + { + "module": "ReactNativeWebview", + "text": "module ReactNativeWebview {\n umbrella \"/home/me/bare-086/ios/build/generated/autolinking/libs/ReactNativeWebview/apple\"\n export *\n}\n" + }, + { + "module": "RNXtoolDevSupport", + "text": "module RNXtoolDevSupport {\n umbrella header \"/home/me/bare-086/ios-xtool/Sources/RNXtoolDevSupport/include/RNXtoolDevSupport.h\"\n export *\n}\n" + } + ], + "targets": [ + "App", + "RNXtoolDevSupport", + "ReactHeaders", + "ReactNativeHeaders", + "ReactNativeDependenciesHeaders", + "ReactCodegen", + "ReactAppDependencyProvider", + "ReactAppHeaders", + "AutolinkedAggregate", + "Autolinked", + "RNGestureHandler", + "RNWorklets", + "RNReanimated", + "ReactNativeSafeAreaContext", + "RNScreens", + "RNSVG", + "ReactNativeWebview" + ], + "modules": [ + "React", + "CoreModules", + "RCTAnimation", + "RCTBlob", + "RCTDeprecation", + "RCTImage", + "RCTSettings", + "RCTSwiftUIWrapper", + "RCTText", + "RCTVibration", + "ReactCommon", + "React_RCTAppDelegate", + "ReactNativeHeaders_react", + "reactperflogger", + "yoga", + "ReactAppHeaders", + "RNScreens", + "ReactCodegen", + "ReactAppDependencyProvider", + "RNGestureHandler", + "RNWorklets", + "RNReanimated", + "ReactNativeSafeAreaContext", + "RNSVG", + "ReactNativeWebview", + "RNXtoolDevSupport" + ], + "unresolved": [] + }, + "toolchain": { + "clang": "/home/me/.local/share/swiftly/bin/clang", + "swiftc": "/home/me/.local/share/swiftly/bin/swiftc", + "sdk": "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk", + "swiftResources": "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift", + "swiftIncludes": [ + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib" + ], + "swiftExtra": [ + "-Xfrontend", + "-enable-cross-import-overlays" + ], + "versions": "clang version 21.0.0 (https://github.com/swiftlang/llvm-project.git 51091bd668a61591b761afe08e2776476e20ff1c)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin\nSwift version 6.4.1 (swift-6.4.1-RELEASE)\nTarget: x86_64-unknown-linux-gnu\nepoch=4,darwinTools=1.1.0,oam=1.4.1" + }, + "dir": "/home/me/bare-086/ios-xtool/.precheck", + "moduleCache": "/home/me/bare-086/ios-xtool/.precheck/ModuleCache/rn0.86.3-b534cbed0fc4" +} diff --git a/tests/fixtures/precheck/golden/bare-087/commands.json b/tests/fixtures/precheck/golden/bare-087/commands.json new file mode 100644 index 0000000..1cadeca --- /dev/null +++ b/tests/fixtures/precheck/golden/bare-087/commands.json @@ -0,0 +1,239 @@ +{ + "swiftDriver": [ + [ + "builtin-SwiftDriver", + "--", + "/home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin/swiftc", + "-parse-as-library", + "-resource-dir", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift", + "-Xcc", + "-resource-dir", + "-Xcc", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang", + "-module-name", + "App", + "-Onone", + "@/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App.SwiftFileList", + "-DSWIFT_PACKAGE", + "-DDEBUG", + "-DSWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE", + "-DDEBUG", + "-Xcc", + "-fmodule-map-file=/home/me/bare-087/ios/build/xcframeworks/ReactHeadersTarget/include/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactCodegen.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactAppDependencyProvider.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNGestureHandler.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactNativeSafeAreaContext.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-087/ios/build/generated/autolinking/libs/RNScreens/ios/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNSVG.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-087/ios/build/generated/ios/ReactAppHeaders/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactNativeWebview.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNXtoolDevSupport.modulemap", + "-DXcode", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-gesture-handler/apple/Handlers", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-gesture-handler/apple", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-gesture-handler/shared/runtime", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-gesture-handler/.", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-svg/common/cpp", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-svg/apple/Brushes", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-svg/apple/Elements", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-svg/apple/Filters/MetalCI", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-svg/apple/Filters", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-svg/apple", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-svg/apple/Shapes", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-svg/apple/Text", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-svg/apple/Utils", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-svg/apple/ViewManagers", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-svg/common/cpp/react/renderer/components/rnsvg", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-svg/.", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-svg/include", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/common/cpp", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/utils", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/cpp", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/bridging", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/conversion", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/events", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/helpers/container", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/helpers/image", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/helpers/scroll-view", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/integrations", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/safe-area", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/stubs", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/tabs", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/tabs/bottom-accessory", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/tabs/extensions", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/tabs/host", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/tabs/screen", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/utils", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/ios/utils/extensions", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/.", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-screens/include", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-webview/apple", + "-Xcc", + "-I/home/me/bare-087/node_modules/react-native-webview/.", + "-Xfrontend", + "-enable-cross-import-overlays", + "-external-plugin-path", + "/home/me/.local/share/swiftly/toolchains/6.4.1/usr/lib/swift/host/plugins/testing#/home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin/swift-plugin-server", + "-enable-experimental-feature", + "DebugDescriptionMacro", + "-sdk", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk", + "-target", + "arm64-apple-ios16.4", + "-g", + "-module-cache-path", + "/home/me/bare-087/ios-xtool/.build/out/ModuleCache.noindex", + "-Xfrontend", + "-serialize-debugging-options", + "-enable-testing", + "-index-store-path", + "/home/me/bare-087/ios-xtool/.build/out", + "-Xcc", + "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG", + "-swift-version", + "5", + "-I", + "/home/me/bare-087/ios-xtool/.build/out/Products/Debug-iphoneos", + "-Isystem", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib", + "-F", + "/home/me/bare-087/ios-xtool/.build/out/Products/Debug-iphoneos/PackageFrameworks", + "-F", + "/home/me/bare-087/ios-xtool/.build/out/Products/Debug-iphoneos", + "-F", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks", + "-F", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk/Developer/Library/Frameworks", + "-c", + "-j12", + "-enable-batch-mode", + "-incremental", + "-output-file-map", + "/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-OutputFileMap.json", + "-save-temps", + "-color-diagnostics", + "-explicit-module-build", + "-module-cache-path", + "/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/SwiftExplicitPrecompiledModules", + "-clang-scanner-module-cache-path", + "/home/me/bare-087/ios-xtool/.build/out/ModuleCache.noindex", + "-sdk-module-cache-path", + "/home/me/bare-087/ios-xtool/.build/out/SDKExplicitPrecompiledModules", + "-emit-dependencies", + "-emit-module", + "-emit-module-path", + "/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App.swiftmodule", + "-serialize-diagnostics", + "-dependency-scan-serialize-diagnostics-path", + "/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-dependency-scan.dia", + "-validate-clang-modules-once", + "-clang-build-session-file", + "/home/me/bare-087/ios-xtool/.build/out/ModuleCache.noindex/Session.modulevalidation", + "-Xcc", + "-fmodules-prune-interval=86400", + "-Xcc", + "-fmodules-prune-after=345600", + "-package-name", + "ios_xtool", + "-emit-const-values", + "-const-gather-protocols-list", + "/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App_const_extract_protocols.json", + "-Xcc", + "-I/home/me/bare-087/ios/build/xcframeworks/ReactHeadersTarget/include", + "-Xcc", + "-I/home/me/bare-087/ios/build/generated/ios/ReactCodegen", + "-Xcc", + "-I/home/me/bare-087/ios/build/generated/ios/ReactAppDependencyProvider", + "-Xcc", + "-I/home/me/bare-087/ios/build/generated/autolinking/libs/RNGestureHandler/include", + "-Xcc", + "-I/home/me/bare-087/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios", + "-Xcc", + "-I/home/me/bare-087/ios/build/generated/autolinking/libs/RNScreens/ios", + "-Xcc", + "-I/home/me/bare-087/ios/build/generated/autolinking/libs/RNSVG/apple", + "-Xcc", + "-I/home/me/bare-087/ios/build/generated/ios/ReactAppHeaders", + "-Xcc", + "-I/home/me/bare-087/ios/build/generated/autolinking/libs/ReactNativeWebview/apple", + "-Xcc", + "-I/home/me/bare-087/ios-xtool/Sources/RNXtoolDevSupport/include", + "-Xcc", + "-I/home/me/bare-087/ios-xtool/.build/out/Products/Debug-iphoneos/include", + "-Xcc", + "-I/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources-normal/arm64", + "-Xcc", + "-I/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources/arm64", + "-Xcc", + "-I/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources", + "-Xcc", + "-DSWIFT_PACKAGE", + "-Xcc", + "-DDEBUG=1", + "-emit-objc-header", + "-emit-objc-header-path", + "/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-Swift.h", + "-working-directory", + "/home/me/bare-087/ios-xtool/xtool", + "-experimental-emit-module-separately", + "-disable-cmo" + ] + ], + "compileC": [] +} \ No newline at end of file diff --git a/tests/fixtures/precheck/golden/bare-087/inputs.json b/tests/fixtures/precheck/golden/bare-087/inputs.json new file mode 100644 index 0000000..77cea18 --- /dev/null +++ b/tests/fixtures/precheck/golden/bare-087/inputs.json @@ -0,0 +1,216 @@ +{ + "app": { + "pkg": { + "iosDir": "/home/me/bare-087/ios", + "frameworks": [ + { + "id": "react", + "name": "React", + "executable": "React", + "searchPath": "/home/me/bare-087/ios/build/xcframeworks/debug/React.xcframework/ios-arm64", + "frameworkDir": "/home/me/bare-087/ios/build/xcframeworks/debug/React.xcframework/ios-arm64/React.framework" + }, + { + "id": "react-native-dependencies", + "name": "ReactNativeDependencies", + "executable": "ReactNativeDependencies", + "searchPath": "/home/me/bare-087/ios/build/xcframeworks/debug/ReactNativeDependencies.xcframework/ios-arm64", + "frameworkDir": "/home/me/bare-087/ios/build/xcframeworks/debug/ReactNativeDependencies.xcframework/ios-arm64/ReactNativeDependencies.framework" + }, + { + "id": "hermes", + "name": "hermesvm", + "executable": "hermesvm", + "searchPath": "/home/me/bare-087/ios/build/xcframeworks/debug/hermes-engine.xcframework/ios-arm64", + "frameworkDir": "/home/me/bare-087/ios/build/xcframeworks/debug/hermes-engine.xcframework/ios-arm64/hermesvm.framework" + } + ], + "iosMin": "16.4", + "app": { + "mixed": false, + "defines": [ + "DEBUG=1" + ], + "headerSearchPaths": [ + "/home/me/bare-087/ios/build/xcframeworks/ReactHeadersTarget/include/React", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/CoreModules", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTAnimation", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTBlob", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTDeprecation", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTImage", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSettings", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSwiftUIWrapper", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTText", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTVibration", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/ReactCommon", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/React_RCTAppDelegate", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/reactperflogger", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/yoga" + ], + "cxxStandard": "c++20", + "swiftHeadersDir": "/home/me/bare-087/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos", + "importerPaths": [ + "/home/me/bare-087/node_modules/react-native-gesture-handler/apple/Handlers", + "/home/me/bare-087/node_modules/react-native-gesture-handler/apple", + "/home/me/bare-087/node_modules/react-native-gesture-handler/shared/runtime", + "/home/me/bare-087/node_modules/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen", + "/home/me/bare-087/node_modules/react-native-gesture-handler/.", + "/home/me/bare-087/node_modules/react-native-svg/common/cpp", + "/home/me/bare-087/node_modules/react-native-svg/apple/Brushes", + "/home/me/bare-087/node_modules/react-native-svg/apple/Elements", + "/home/me/bare-087/node_modules/react-native-svg/apple/Filters/MetalCI", + "/home/me/bare-087/node_modules/react-native-svg/apple/Filters", + "/home/me/bare-087/node_modules/react-native-svg/apple", + "/home/me/bare-087/node_modules/react-native-svg/apple/Shapes", + "/home/me/bare-087/node_modules/react-native-svg/apple/Text", + "/home/me/bare-087/node_modules/react-native-svg/apple/Utils", + "/home/me/bare-087/node_modules/react-native-svg/apple/ViewManagers", + "/home/me/bare-087/node_modules/react-native-svg/common/cpp/react/renderer/components/rnsvg", + "/home/me/bare-087/node_modules/react-native-svg/.", + "/home/me/bare-087/node_modules/react-native-svg/include", + "/home/me/bare-087/node_modules/react-native-screens/common/cpp", + "/home/me/bare-087/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens", + "/home/me/bare-087/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/utils", + "/home/me/bare-087/node_modules/react-native-screens/cpp", + "/home/me/bare-087/node_modules/react-native-screens/ios", + "/home/me/bare-087/node_modules/react-native-screens/ios/bridging", + "/home/me/bare-087/node_modules/react-native-screens/ios/conversion", + "/home/me/bare-087/node_modules/react-native-screens/ios/events", + "/home/me/bare-087/node_modules/react-native-screens/ios/helpers/container", + "/home/me/bare-087/node_modules/react-native-screens/ios/helpers/image", + "/home/me/bare-087/node_modules/react-native-screens/ios/helpers/scroll-view", + "/home/me/bare-087/node_modules/react-native-screens/ios/integrations", + "/home/me/bare-087/node_modules/react-native-screens/ios/safe-area", + "/home/me/bare-087/node_modules/react-native-screens/ios/stubs", + "/home/me/bare-087/node_modules/react-native-screens/ios/tabs", + "/home/me/bare-087/node_modules/react-native-screens/ios/tabs/bottom-accessory", + "/home/me/bare-087/node_modules/react-native-screens/ios/tabs/extensions", + "/home/me/bare-087/node_modules/react-native-screens/ios/tabs/host", + "/home/me/bare-087/node_modules/react-native-screens/ios/tabs/screen", + "/home/me/bare-087/node_modules/react-native-screens/ios/utils", + "/home/me/bare-087/node_modules/react-native-screens/ios/utils/extensions", + "/home/me/bare-087/node_modules/react-native-screens/.", + "/home/me/bare-087/node_modules/react-native-screens/include", + "/home/me/bare-087/node_modules/react-native-webview/apple", + "/home/me/bare-087/node_modules/react-native-webview/." + ] + }, + "devSupport": true + }, + "origins": { + "/home/me/bare-087/ios-xtool/Sources/App/AppDelegate.swift": "/home/me/bare-087/ios/BareDemo/AppDelegate.swift" + } + }, + "graph": { + "headerDirs": [ + "/home/me/bare-087/ios/build/xcframeworks/ReactHeadersTarget/include", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeDependenciesHeaders.xcframework/ios-arm64/Headers", + "/home/me/bare-087/ios/build/generated/ios/ReactCodegen", + "/home/me/bare-087/ios/build/generated/ios/ReactAppHeaders", + "/home/me/bare-087/ios/build/generated/ios/ReactAppDependencyProvider", + "/home/me/bare-087/ios/build/generated/autolinking/libs/RNGestureHandler/include", + "/home/me/bare-087/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios", + "/home/me/bare-087/ios/build/generated/autolinking/libs/RNScreens/ios", + "/home/me/bare-087/ios/build/generated/autolinking/libs/RNSVG/apple", + "/home/me/bare-087/ios/build/generated/autolinking/libs/ReactNativeWebview/apple", + "/home/me/bare-087/ios-xtool/Sources/RNXtoolDevSupport/include" + ], + "moduleMaps": [ + "/home/me/bare-087/ios/build/xcframeworks/ReactHeadersTarget/include/module.modulemap", + "/home/me/bare-087/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/module.modulemap", + "/home/me/bare-087/ios/build/generated/ios/ReactAppHeaders/module.modulemap", + "/home/me/bare-087/ios/build/generated/autolinking/libs/RNScreens/ios/module.modulemap" + ], + "synthesized": [ + { + "module": "ReactCodegen", + "text": "module ReactCodegen {\n umbrella \"/home/me/bare-087/ios/build/generated/ios/ReactCodegen\"\n export *\n}\n" + }, + { + "module": "ReactAppDependencyProvider", + "text": "module ReactAppDependencyProvider {\n umbrella \"/home/me/bare-087/ios/build/generated/ios/ReactAppDependencyProvider\"\n export *\n}\n" + }, + { + "module": "RNGestureHandler", + "text": "module RNGestureHandler {\n umbrella header \"/home/me/bare-087/ios/build/generated/autolinking/libs/RNGestureHandler/include/RNGestureHandler/RNGestureHandler.h\"\n export *\n}\n" + }, + { + "module": "ReactNativeSafeAreaContext", + "text": "module ReactNativeSafeAreaContext {\n umbrella \"/home/me/bare-087/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios\"\n export *\n}\n" + }, + { + "module": "RNSVG", + "text": "module RNSVG {\n umbrella \"/home/me/bare-087/ios/build/generated/autolinking/libs/RNSVG/apple\"\n export *\n}\n" + }, + { + "module": "ReactNativeWebview", + "text": "module ReactNativeWebview {\n umbrella \"/home/me/bare-087/ios/build/generated/autolinking/libs/ReactNativeWebview/apple\"\n export *\n}\n" + }, + { + "module": "RNXtoolDevSupport", + "text": "module RNXtoolDevSupport {\n umbrella header \"/home/me/bare-087/ios-xtool/Sources/RNXtoolDevSupport/include/RNXtoolDevSupport.h\"\n export *\n}\n" + } + ], + "targets": [ + "App", + "RNXtoolDevSupport", + "ReactHeaders", + "ReactNativeHeaders", + "ReactNativeDependenciesHeaders", + "ReactCodegen", + "ReactAppDependencyProvider", + "ReactAppHeaders", + "AutolinkedAggregate", + "Autolinked", + "RNGestureHandler", + "ReactNativeSafeAreaContext", + "RNScreens", + "RNSVG", + "ReactNativeWebview" + ], + "modules": [ + "React", + "CoreModules", + "RCTAnimation", + "RCTBlob", + "RCTDeprecation", + "RCTImage", + "RCTSettings", + "RCTSwiftUIWrapper", + "RCTText", + "RCTVibration", + "ReactCommon", + "React_RCTAppDelegate", + "ReactNativeHeaders_react", + "reactperflogger", + "yoga", + "ReactAppHeaders", + "RNScreens", + "ReactCodegen", + "ReactAppDependencyProvider", + "RNGestureHandler", + "ReactNativeSafeAreaContext", + "RNSVG", + "ReactNativeWebview", + "RNXtoolDevSupport" + ], + "unresolved": [] + }, + "toolchain": { + "clang": "/home/me/.local/share/swiftly/bin/clang", + "swiftc": "/home/me/.local/share/swiftly/bin/swiftc", + "sdk": "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk", + "swiftResources": "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift", + "swiftIncludes": [ + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib" + ], + "swiftExtra": [ + "-Xfrontend", + "-enable-cross-import-overlays" + ], + "versions": "clang version 21.0.0 (https://github.com/swiftlang/llvm-project.git 51091bd668a61591b761afe08e2776476e20ff1c)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin\nSwift version 6.4.1 (swift-6.4.1-RELEASE)\nTarget: x86_64-unknown-linux-gnu\nepoch=4,darwinTools=1.1.0,oam=1.4.1" + }, + "dir": "/home/me/bare-087/ios-xtool/.precheck", + "moduleCache": "/home/me/bare-087/ios-xtool/.precheck/ModuleCache/rn0.87.1-b534cbed0fc4" +} diff --git a/tests/fixtures/precheck/golden/bare-088/commands.json b/tests/fixtures/precheck/golden/bare-088/commands.json new file mode 100644 index 0000000..3307362 --- /dev/null +++ b/tests/fixtures/precheck/golden/bare-088/commands.json @@ -0,0 +1,259 @@ +{ + "swiftDriver": [ + [ + "builtin-SwiftDriver", + "--", + "/home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin/swiftc", + "-parse-as-library", + "-resource-dir", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift", + "-Xcc", + "-resource-dir", + "-Xcc", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang", + "-module-name", + "App", + "-Onone", + "@/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App.SwiftFileList", + "-DSWIFT_PACKAGE", + "-DDEBUG", + "-DSWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE", + "-DDEBUG", + "-Xcc", + "-fmodule-map-file=/home/me/bare-088/ios/build/xcframeworks/ReactHeadersTarget/include/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactCodegen.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactAppDependencyProvider.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNDateTimePicker.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNGestureHandler.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNReanimated.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactNativeSafeAreaContext.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-088/ios/build/generated/autolinking/libs/RNScreens/ios/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNSVG.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactNativeWebview.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-088/ios/build/generated/ios/ReactAppHeaders/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNWorklets.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNXtoolDevSupport.modulemap", + "-DXcode", + "-Xcc", + "-I/home/me/bare-088/node_modules/@react-native-community/datetimepicker/ios", + "-Xcc", + "-I/home/me/bare-088/node_modules/@react-native-community/datetimepicker/ios/fabric", + "-Xcc", + "-I/home/me/bare-088/node_modules/@react-native-community/datetimepicker/ios/fabric/cpp/react/renderer/components/RNDateTimePicker", + "-Xcc", + "-I/home/me/bare-088/node_modules/@react-native-community/datetimepicker/.", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-gesture-handler/apple/Handlers", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-gesture-handler/apple", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-gesture-handler/shared/runtime", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-gesture-handler/.", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-svg/common/cpp", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-svg/apple/Brushes", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-svg/apple/Elements", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-svg/apple/Filters/MetalCI", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-svg/apple/Filters", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-svg/apple", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-svg/apple/Shapes", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-svg/apple/Text", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-svg/apple/Utils", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-svg/apple/ViewManagers", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-svg/common/cpp/react/renderer/components/rnsvg", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-svg/.", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-svg/include", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/common/cpp", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/utils", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/cpp", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/bridging", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/conversion", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/events", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/helpers/container", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/helpers/image", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/helpers/scroll-view", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/integrations", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/safe-area", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/stubs", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/tabs", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/tabs/bottom-accessory", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/tabs/extensions", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/tabs/host", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/tabs/screen", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/utils", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/ios/utils/extensions", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/.", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-screens/include", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-webview/apple", + "-Xcc", + "-I/home/me/bare-088/node_modules/react-native-webview/.", + "-Xfrontend", + "-enable-cross-import-overlays", + "-external-plugin-path", + "/home/me/.local/share/swiftly/toolchains/6.4.1/usr/lib/swift/host/plugins/testing#/home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin/swift-plugin-server", + "-enable-experimental-feature", + "DebugDescriptionMacro", + "-sdk", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk", + "-target", + "arm64-apple-ios16.4", + "-g", + "-module-cache-path", + "/home/me/bare-088/ios-xtool/.build/out/ModuleCache.noindex", + "-Xfrontend", + "-serialize-debugging-options", + "-enable-testing", + "-index-store-path", + "/home/me/bare-088/ios-xtool/.build/out", + "-Xcc", + "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG", + "-swift-version", + "5", + "-I", + "/home/me/bare-088/ios-xtool/.build/out/Products/Debug-iphoneos", + "-Isystem", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib", + "-F", + "/home/me/bare-088/ios-xtool/.build/out/Products/Debug-iphoneos/PackageFrameworks", + "-F", + "/home/me/bare-088/ios-xtool/.build/out/Products/Debug-iphoneos", + "-F", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks", + "-F", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk/Developer/Library/Frameworks", + "-c", + "-j12", + "-enable-batch-mode", + "-incremental", + "-output-file-map", + "/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-OutputFileMap.json", + "-save-temps", + "-color-diagnostics", + "-explicit-module-build", + "-module-cache-path", + "/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/SwiftExplicitPrecompiledModules", + "-clang-scanner-module-cache-path", + "/home/me/bare-088/ios-xtool/.build/out/ModuleCache.noindex", + "-sdk-module-cache-path", + "/home/me/bare-088/ios-xtool/.build/out/SDKExplicitPrecompiledModules", + "-emit-dependencies", + "-emit-module", + "-emit-module-path", + "/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App.swiftmodule", + "-serialize-diagnostics", + "-dependency-scan-serialize-diagnostics-path", + "/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-dependency-scan.dia", + "-validate-clang-modules-once", + "-clang-build-session-file", + "/home/me/bare-088/ios-xtool/.build/out/ModuleCache.noindex/Session.modulevalidation", + "-Xcc", + "-fmodules-prune-interval=86400", + "-Xcc", + "-fmodules-prune-after=345600", + "-package-name", + "ios_xtool", + "-emit-const-values", + "-const-gather-protocols-list", + "/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App_const_extract_protocols.json", + "-Xcc", + "-I/home/me/bare-088/ios/build/xcframeworks/ReactHeadersTarget/include", + "-Xcc", + "-I/home/me/bare-088/ios/build/generated/ios/ReactCodegen", + "-Xcc", + "-I/home/me/bare-088/ios/build/generated/ios/ReactAppDependencyProvider", + "-Xcc", + "-I/home/me/bare-088/ios/build/generated/autolinking/libs/RNDateTimePicker/include", + "-Xcc", + "-I/home/me/bare-088/ios/build/generated/autolinking/libs/RNGestureHandler/include", + "-Xcc", + "-I/home/me/bare-088/ios/build/generated/autolinking/libs/RNReanimated/include", + "-Xcc", + "-I/home/me/bare-088/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios", + "-Xcc", + "-I/home/me/bare-088/ios/build/generated/autolinking/libs/RNScreens/ios", + "-Xcc", + "-I/home/me/bare-088/ios/build/generated/autolinking/libs/RNSVG/apple", + "-Xcc", + "-I/home/me/bare-088/ios/build/generated/autolinking/libs/ReactNativeWebview/apple", + "-Xcc", + "-I/home/me/bare-088/ios/build/generated/ios/ReactAppHeaders", + "-Xcc", + "-I/home/me/bare-088/ios/build/generated/autolinking/libs/RNWorklets/Common/cpp", + "-Xcc", + "-I/home/me/bare-088/ios-xtool/Sources/RNXtoolDevSupport/include", + "-Xcc", + "-I/home/me/bare-088/ios-xtool/.build/out/Products/Debug-iphoneos/include", + "-Xcc", + "-I/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources-normal/arm64", + "-Xcc", + "-I/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources/arm64", + "-Xcc", + "-I/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources", + "-Xcc", + "-DSWIFT_PACKAGE", + "-Xcc", + "-DDEBUG=1", + "-emit-objc-header", + "-emit-objc-header-path", + "/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-Swift.h", + "-working-directory", + "/home/me/bare-088/ios-xtool/xtool", + "-experimental-emit-module-separately", + "-disable-cmo" + ] + ], + "compileC": [] +} \ No newline at end of file diff --git a/tests/fixtures/precheck/golden/bare-088/inputs.json b/tests/fixtures/precheck/golden/bare-088/inputs.json new file mode 100644 index 0000000..772fefb --- /dev/null +++ b/tests/fixtures/precheck/golden/bare-088/inputs.json @@ -0,0 +1,242 @@ +{ + "app": { + "pkg": { + "iosDir": "/home/me/bare-088/ios", + "frameworks": [ + { + "id": "react", + "name": "React", + "executable": "React", + "searchPath": "/home/me/bare-088/ios/build/xcframeworks/debug/React.xcframework/ios-arm64", + "frameworkDir": "/home/me/bare-088/ios/build/xcframeworks/debug/React.xcframework/ios-arm64/React.framework" + }, + { + "id": "react-native-dependencies", + "name": "ReactNativeDependencies", + "executable": "ReactNativeDependencies", + "searchPath": "/home/me/bare-088/ios/build/xcframeworks/debug/ReactNativeDependencies.xcframework/ios-arm64", + "frameworkDir": "/home/me/bare-088/ios/build/xcframeworks/debug/ReactNativeDependencies.xcframework/ios-arm64/ReactNativeDependencies.framework" + }, + { + "id": "hermes", + "name": "hermesvm", + "executable": "hermesvm", + "searchPath": "/home/me/bare-088/ios/build/xcframeworks/debug/hermes-engine.xcframework/ios-arm64", + "frameworkDir": "/home/me/bare-088/ios/build/xcframeworks/debug/hermes-engine.xcframework/ios-arm64/hermesvm.framework" + } + ], + "iosMin": "16.4", + "app": { + "mixed": false, + "defines": [ + "DEBUG=1" + ], + "headerSearchPaths": [ + "/home/me/bare-088/ios/build/xcframeworks/ReactHeadersTarget/include/React", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/CoreModules", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTAnimation", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTBlob", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTDeprecation", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTImage", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSettings", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSwiftUIWrapper", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTText", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTVibration", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/ReactCommon", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/React_RCTAppDelegate", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/reactperflogger", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/yoga" + ], + "cxxStandard": "c++20", + "swiftHeadersDir": "/home/me/bare-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos", + "importerPaths": [ + "/home/me/bare-088/node_modules/@react-native-community/datetimepicker/ios", + "/home/me/bare-088/node_modules/@react-native-community/datetimepicker/ios/fabric", + "/home/me/bare-088/node_modules/@react-native-community/datetimepicker/ios/fabric/cpp/react/renderer/components/RNDateTimePicker", + "/home/me/bare-088/node_modules/@react-native-community/datetimepicker/.", + "/home/me/bare-088/node_modules/react-native-gesture-handler/apple/Handlers", + "/home/me/bare-088/node_modules/react-native-gesture-handler/apple", + "/home/me/bare-088/node_modules/react-native-gesture-handler/shared/runtime", + "/home/me/bare-088/node_modules/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen", + "/home/me/bare-088/node_modules/react-native-gesture-handler/.", + "/home/me/bare-088/node_modules/react-native-svg/common/cpp", + "/home/me/bare-088/node_modules/react-native-svg/apple/Brushes", + "/home/me/bare-088/node_modules/react-native-svg/apple/Elements", + "/home/me/bare-088/node_modules/react-native-svg/apple/Filters/MetalCI", + "/home/me/bare-088/node_modules/react-native-svg/apple/Filters", + "/home/me/bare-088/node_modules/react-native-svg/apple", + "/home/me/bare-088/node_modules/react-native-svg/apple/Shapes", + "/home/me/bare-088/node_modules/react-native-svg/apple/Text", + "/home/me/bare-088/node_modules/react-native-svg/apple/Utils", + "/home/me/bare-088/node_modules/react-native-svg/apple/ViewManagers", + "/home/me/bare-088/node_modules/react-native-svg/common/cpp/react/renderer/components/rnsvg", + "/home/me/bare-088/node_modules/react-native-svg/.", + "/home/me/bare-088/node_modules/react-native-svg/include", + "/home/me/bare-088/node_modules/react-native-screens/common/cpp", + "/home/me/bare-088/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens", + "/home/me/bare-088/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/utils", + "/home/me/bare-088/node_modules/react-native-screens/cpp", + "/home/me/bare-088/node_modules/react-native-screens/ios", + "/home/me/bare-088/node_modules/react-native-screens/ios/bridging", + "/home/me/bare-088/node_modules/react-native-screens/ios/conversion", + "/home/me/bare-088/node_modules/react-native-screens/ios/events", + "/home/me/bare-088/node_modules/react-native-screens/ios/helpers/container", + "/home/me/bare-088/node_modules/react-native-screens/ios/helpers/image", + "/home/me/bare-088/node_modules/react-native-screens/ios/helpers/scroll-view", + "/home/me/bare-088/node_modules/react-native-screens/ios/integrations", + "/home/me/bare-088/node_modules/react-native-screens/ios/safe-area", + "/home/me/bare-088/node_modules/react-native-screens/ios/stubs", + "/home/me/bare-088/node_modules/react-native-screens/ios/tabs", + "/home/me/bare-088/node_modules/react-native-screens/ios/tabs/bottom-accessory", + "/home/me/bare-088/node_modules/react-native-screens/ios/tabs/extensions", + "/home/me/bare-088/node_modules/react-native-screens/ios/tabs/host", + "/home/me/bare-088/node_modules/react-native-screens/ios/tabs/screen", + "/home/me/bare-088/node_modules/react-native-screens/ios/utils", + "/home/me/bare-088/node_modules/react-native-screens/ios/utils/extensions", + "/home/me/bare-088/node_modules/react-native-screens/.", + "/home/me/bare-088/node_modules/react-native-screens/include", + "/home/me/bare-088/node_modules/react-native-webview/apple", + "/home/me/bare-088/node_modules/react-native-webview/." + ] + }, + "devSupport": true + }, + "origins": { + "/home/me/bare-088/ios-xtool/Sources/App/AppDelegate.swift": "/home/me/bare-088/ios/BareDemo/AppDelegate.swift", + "/home/me/bare-088/ios-xtool/Sources/App/SceneDelegate.swift": "/home/me/bare-088/ios/BareDemo/SceneDelegate.swift" + } + }, + "graph": { + "headerDirs": [ + "/home/me/bare-088/ios/build/xcframeworks/ReactHeadersTarget/include", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeDependenciesHeaders.xcframework/ios-arm64/Headers", + "/home/me/bare-088/ios/build/generated/ios/ReactCodegen", + "/home/me/bare-088/ios/build/generated/ios/ReactAppHeaders", + "/home/me/bare-088/ios/build/generated/ios/ReactAppDependencyProvider", + "/home/me/bare-088/ios/build/generated/autolinking/libs/RNDateTimePicker/include", + "/home/me/bare-088/ios/build/generated/autolinking/libs/RNGestureHandler/include", + "/home/me/bare-088/ios/build/generated/autolinking/libs/RNWorklets/Common/cpp", + "/home/me/bare-088/ios/build/generated/autolinking/libs/RNReanimated/include", + "/home/me/bare-088/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios", + "/home/me/bare-088/ios/build/generated/autolinking/libs/RNScreens/ios", + "/home/me/bare-088/ios/build/generated/autolinking/libs/RNSVG/apple", + "/home/me/bare-088/ios/build/generated/autolinking/libs/ReactNativeWebview/apple", + "/home/me/bare-088/ios-xtool/Sources/RNXtoolDevSupport/include" + ], + "moduleMaps": [ + "/home/me/bare-088/ios/build/xcframeworks/ReactHeadersTarget/include/module.modulemap", + "/home/me/bare-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/module.modulemap", + "/home/me/bare-088/ios/build/generated/ios/ReactAppHeaders/module.modulemap", + "/home/me/bare-088/ios/build/generated/autolinking/libs/RNScreens/ios/module.modulemap" + ], + "synthesized": [ + { + "module": "ReactCodegen", + "text": "module ReactCodegen {\n umbrella \"/home/me/bare-088/ios/build/generated/ios/ReactCodegen\"\n export *\n}\n" + }, + { + "module": "ReactAppDependencyProvider", + "text": "module ReactAppDependencyProvider {\n umbrella \"/home/me/bare-088/ios/build/generated/ios/ReactAppDependencyProvider\"\n export *\n}\n" + }, + { + "module": "RNDateTimePicker", + "text": "module RNDateTimePicker {\n umbrella header \"/home/me/bare-088/ios/build/generated/autolinking/libs/RNDateTimePicker/include/RNDateTimePicker/RNDateTimePicker.h\"\n export *\n}\n" + }, + { + "module": "RNGestureHandler", + "text": "module RNGestureHandler {\n umbrella header \"/home/me/bare-088/ios/build/generated/autolinking/libs/RNGestureHandler/include/RNGestureHandler/RNGestureHandler.h\"\n export *\n}\n" + }, + { + "module": "RNWorklets", + "text": "module RNWorklets {\n umbrella \"/home/me/bare-088/ios/build/generated/autolinking/libs/RNWorklets/Common/cpp\"\n export *\n}\n" + }, + { + "module": "RNReanimated", + "text": "module RNReanimated {\n umbrella \"/home/me/bare-088/ios/build/generated/autolinking/libs/RNReanimated/include\"\n export *\n}\n" + }, + { + "module": "ReactNativeSafeAreaContext", + "text": "module ReactNativeSafeAreaContext {\n umbrella \"/home/me/bare-088/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios\"\n export *\n}\n" + }, + { + "module": "RNSVG", + "text": "module RNSVG {\n umbrella \"/home/me/bare-088/ios/build/generated/autolinking/libs/RNSVG/apple\"\n export *\n}\n" + }, + { + "module": "ReactNativeWebview", + "text": "module ReactNativeWebview {\n umbrella \"/home/me/bare-088/ios/build/generated/autolinking/libs/ReactNativeWebview/apple\"\n export *\n}\n" + }, + { + "module": "RNXtoolDevSupport", + "text": "module RNXtoolDevSupport {\n umbrella header \"/home/me/bare-088/ios-xtool/Sources/RNXtoolDevSupport/include/RNXtoolDevSupport.h\"\n export *\n}\n" + } + ], + "targets": [ + "App", + "RNXtoolDevSupport", + "ReactHeaders", + "ReactNativeHeaders", + "ReactNativeDependenciesHeaders", + "ReactCodegen", + "ReactAppDependencyProvider", + "ReactAppHeaders", + "AutolinkedAggregate", + "Autolinked", + "RNDateTimePicker", + "RNGestureHandler", + "RNWorklets", + "RNReanimated", + "ReactNativeSafeAreaContext", + "RNScreens", + "RNSVG", + "ReactNativeWebview" + ], + "modules": [ + "React", + "CoreModules", + "RCTAnimation", + "RCTBlob", + "RCTDeprecation", + "RCTImage", + "RCTSettings", + "RCTSwiftUIWrapper", + "RCTText", + "RCTVibration", + "ReactCommon", + "React_RCTAppDelegate", + "ReactNativeHeaders_react", + "reactperflogger", + "yoga", + "ReactAppHeaders", + "RNScreens", + "ReactCodegen", + "ReactAppDependencyProvider", + "RNDateTimePicker", + "RNGestureHandler", + "RNWorklets", + "RNReanimated", + "ReactNativeSafeAreaContext", + "RNSVG", + "ReactNativeWebview", + "RNXtoolDevSupport" + ], + "unresolved": [] + }, + "toolchain": { + "clang": "/home/me/.local/share/swiftly/bin/clang", + "swiftc": "/home/me/.local/share/swiftly/bin/swiftc", + "sdk": "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk", + "swiftResources": "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift", + "swiftIncludes": [ + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib" + ], + "swiftExtra": [ + "-Xfrontend", + "-enable-cross-import-overlays" + ], + "versions": "clang version 21.0.0 (https://github.com/swiftlang/llvm-project.git 51091bd668a61591b761afe08e2776476e20ff1c)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin\nSwift version 6.4.1 (swift-6.4.1-RELEASE)\nTarget: x86_64-unknown-linux-gnu\nepoch=4,darwinTools=1.1.0,oam=1.4.1" + }, + "dir": "/home/me/bare-088/ios-xtool/.precheck", + "moduleCache": "/home/me/bare-088/ios-xtool/.precheck/ModuleCache/rn0.88.1-b534cbed0fc4" +} diff --git a/tests/fixtures/precheck/golden/expo-58-bridging/commands.json b/tests/fixtures/precheck/golden/expo-58-bridging/commands.json new file mode 100644 index 0000000..7bcea36 --- /dev/null +++ b/tests/fixtures/precheck/golden/expo-58-bridging/commands.json @@ -0,0 +1,292 @@ +{ + "swiftDriver": [ + [ + "builtin-SwiftDriver", + "--", + "/home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin/swiftc", + "-parse-as-library", + "-resource-dir", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift", + "-Xcc", + "-resource-dir", + "-Xcc", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang", + "-module-name", + "App", + "-Onone", + "@/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App.SwiftFileList", + "-DSWIFT_PACKAGE", + "-DDEBUG", + "-DSWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE", + "-DDEBUG", + "-DEXPO_CONFIGURATION_DEBUG", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios/build/xcframeworks/ReactHeadersTarget/include/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactCodegen.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactAppDependencyProvider.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNCMaskedView.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNGestureHandler.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNReanimated.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactNativeSafeAreaContext.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNScreens/ios/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNWorklets.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoLogBoxObjC.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoLoader.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoObjC.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/EXConstantsObjC.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios/build/generated/ios/ReactAppHeaders/module.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNXtoolDevSupport.modulemap", + "-DXcode", + "-F", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/compile-interfaces", + "-Xcc", + "-I/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoAsset/pod-headers", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoDevice/pod-headers", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoDomWebView/pod-headers", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoGlassEffect/pod-headers", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoKeepAwake/pod-headers", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoLinking/pod-headers", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoRouter/pod-headers", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoSplashScreen/pod-headers", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoStatusBar/pod-headers", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoSymbols/pod-headers", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoSystemUI/pod-headers", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoUI/pod-headers", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoWebBrowser/pod-headers", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoAsset.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoDevice.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoDomWebView.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoGlassEffect.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoKeepAwake.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoLinking.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoRouter.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoSplashScreen.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoStatusBar.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoSymbols.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoSystemUI.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoUI.modulemap", + "-Xcc", + "-fmodule-map-file=/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoWebBrowser.modulemap", + "-import-objc-header", + "/home/me/expo-58-bridging/ios-xtool/Sources/App/app-Bridging-Header.h", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/@react-native-masked-view/masked-view/ios", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/@react-native-masked-view/masked-view/.", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-gesture-handler/apple/Handlers", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-gesture-handler/apple", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-gesture-handler/shared/runtime", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-gesture-handler/.", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/common/cpp", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/utils", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/cpp", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/bridging", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/conversion", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/events", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/helpers/container", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/helpers/image", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/helpers/scroll-view", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/integrations", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/safe-area", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/stubs", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/tabs", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/tabs/bottom-accessory", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/tabs/extensions", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/tabs/host", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/tabs/screen", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/utils", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/ios/utils/extensions", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/.", + "-Xcc", + "-I/home/me/expo-58-bridging/node_modules/react-native-screens/include", + "-Xfrontend", + "-enable-cross-import-overlays", + "-external-plugin-path", + "/home/me/.local/share/swiftly/toolchains/6.4.1/usr/lib/swift/host/plugins/testing#/home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin/swift-plugin-server", + "-enable-experimental-feature", + "DebugDescriptionMacro", + "-sdk", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk", + "-target", + "arm64-apple-ios16.4", + "-g", + "-module-cache-path", + "/home/me/expo-58-bridging/ios-xtool/.build/out/ModuleCache.noindex", + "-Xfrontend", + "-serialize-debugging-options", + "-enable-testing", + "-index-store-path", + "/home/me/expo-58-bridging/ios-xtool/.build/out", + "-Xcc", + "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG", + "-swift-version", + "5", + "-I", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Products/Debug-iphoneos", + "-Isystem", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib", + "-F", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Products/Debug-iphoneos/PackageFrameworks", + "-F", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Products/Debug-iphoneos", + "-F", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks", + "-F", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk/Developer/Library/Frameworks", + "-c", + "-j12", + "-enable-batch-mode", + "-incremental", + "-output-file-map", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-OutputFileMap.json", + "-save-temps", + "-color-diagnostics", + "-explicit-module-build", + "-module-cache-path", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/SwiftExplicitPrecompiledModules", + "-clang-scanner-module-cache-path", + "/home/me/expo-58-bridging/ios-xtool/.build/out/ModuleCache.noindex", + "-sdk-module-cache-path", + "/home/me/expo-58-bridging/ios-xtool/.build/out/SDKExplicitPrecompiledModules", + "-emit-dependencies", + "-emit-module", + "-emit-module-path", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App.swiftmodule", + "-serialize-diagnostics", + "-dependency-scan-serialize-diagnostics-path", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-dependency-scan.dia", + "-validate-clang-modules-once", + "-clang-build-session-file", + "/home/me/expo-58-bridging/ios-xtool/.build/out/ModuleCache.noindex/Session.modulevalidation", + "-Xcc", + "-fmodules-prune-interval=86400", + "-Xcc", + "-fmodules-prune-after=345600", + "-package-name", + "ios_xtool", + "-emit-const-values", + "-const-gather-protocols-list", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App_const_extract_protocols.json", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/xcframeworks/ReactHeadersTarget/include", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/ios/ReactCodegen", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/ios/ReactAppDependencyProvider", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNCMaskedView/include", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNGestureHandler/include", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNReanimated/include", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNScreens/ios", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNWorklets/Common/cpp", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/expo-log-box/root/ios/ExpoLogBoxObjC/include", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/expo/root/ios/ExpoLoader/include", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/expo/root/ios/ExpoObjC/include", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/expo-constants/root/ios/EXConstantsObjC/include", + "-Xcc", + "-I/home/me/expo-58-bridging/ios/build/generated/ios/ReactAppHeaders", + "-Xcc", + "-I/home/me/expo-58-bridging/ios-xtool/Sources/RNXtoolDevSupport/include", + "-Xcc", + "-I/home/me/expo-58-bridging/ios-xtool/.build/out/Products/Debug-iphoneos/include", + "-Xcc", + "-I/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources-normal/arm64", + "-Xcc", + "-I/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources/arm64", + "-Xcc", + "-I/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources", + "-Xcc", + "-DSWIFT_PACKAGE", + "-Xcc", + "-DDEBUG=1", + "-emit-objc-header", + "-emit-objc-header-path", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/App-Swift.h", + "-working-directory", + "/home/me/expo-58-bridging/ios-xtool/xtool", + "-experimental-emit-module-separately", + "-disable-cmo" + ] + ], + "compileC": [] +} \ No newline at end of file diff --git a/tests/fixtures/precheck/golden/expo-58-bridging/inputs.json b/tests/fixtures/precheck/golden/expo-58-bridging/inputs.json new file mode 100644 index 0000000..e23c441 --- /dev/null +++ b/tests/fixtures/precheck/golden/expo-58-bridging/inputs.json @@ -0,0 +1,363 @@ +{ + "app": { + "pkg": { + "iosDir": "/home/me/expo-58-bridging/ios", + "frameworks": [ + { + "id": "react", + "name": "React", + "executable": "React", + "searchPath": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/React.xcframework/ios-arm64", + "frameworkDir": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/React.xcframework/ios-arm64/React.framework" + }, + { + "id": "react-native-dependencies", + "name": "ReactNativeDependencies", + "executable": "ReactNativeDependencies", + "searchPath": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/ReactNativeDependencies.xcframework/ios-arm64", + "frameworkDir": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/ReactNativeDependencies.xcframework/ios-arm64/ReactNativeDependencies.framework" + }, + { + "id": "hermes", + "name": "hermesvm", + "executable": "hermesvm", + "searchPath": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/hermes-engine.xcframework/ios-arm64", + "frameworkDir": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/hermes-engine.xcframework/ios-arm64/hermesvm.framework" + }, + { + "id": "expo-file-system", + "name": "ExpoFileSystem", + "executable": "ExpoFileSystem", + "searchPath": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-file-system.xcframework/ios-arm64", + "frameworkDir": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-file-system.xcframework/ios-arm64/ExpoFileSystem.framework" + }, + { + "id": "expo-font", + "name": "ExpoFont", + "executable": "ExpoFont", + "searchPath": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-font.xcframework/ios-arm64", + "frameworkDir": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-font.xcframework/ios-arm64/ExpoFont.framework" + }, + { + "id": "expo-image", + "name": "ExpoImage", + "executable": "ExpoImage", + "searchPath": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-image.xcframework/ios-arm64", + "frameworkDir": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-image.xcframework/ios-arm64/ExpoImage.framework" + }, + { + "id": "expo-libavif", + "name": "libavif", + "executable": "libavif", + "searchPath": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-libavif.xcframework/ios-arm64", + "frameworkDir": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-libavif.xcframework/ios-arm64/libavif.framework" + }, + { + "id": "expo-modules-core", + "name": "ExpoModulesCore", + "executable": "ExpoModulesCore", + "searchPath": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-modules-core.xcframework/ios-arm64", + "frameworkDir": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-modules-core.xcframework/ios-arm64/ExpoModulesCore.framework" + }, + { + "id": "expo-modules-worklets", + "name": "ExpoModulesWorklets", + "executable": "ExpoModulesWorklets", + "searchPath": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-modules-worklets.xcframework/ios-arm64", + "frameworkDir": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-modules-worklets.xcframework/ios-arm64/ExpoModulesWorklets.framework" + }, + { + "id": "expo-sdweb-image", + "name": "SDWebImage", + "executable": "SDWebImage", + "searchPath": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-sdweb-image.xcframework/ios-arm64", + "frameworkDir": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-sdweb-image.xcframework/ios-arm64/SDWebImage.framework" + }, + { + "id": "expo-sdweb-image-avifcoder", + "name": "SDWebImageAVIFCoder", + "executable": "SDWebImageAVIFCoder", + "searchPath": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-sdweb-image-avifcoder.xcframework/ios-arm64", + "frameworkDir": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-sdweb-image-avifcoder.xcframework/ios-arm64/SDWebImageAVIFCoder.framework" + }, + { + "id": "expo-sdweb-image-svgcoder", + "name": "SDWebImageSVGCoder", + "executable": "SDWebImageSVGCoder", + "searchPath": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-sdweb-image-svgcoder.xcframework/ios-arm64", + "frameworkDir": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-sdweb-image-svgcoder.xcframework/ios-arm64/SDWebImageSVGCoder.framework" + }, + { + "id": "expo-sdweb-image-web-pcoder", + "name": "SDWebImageWebPCoder", + "executable": "SDWebImageWebPCoder", + "searchPath": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-sdweb-image-web-pcoder.xcframework/ios-arm64", + "frameworkDir": "/home/me/expo-58-bridging/ios/build/xcframeworks/debug/plugins/expo-sdweb-image-web-pcoder.xcframework/ios-arm64/SDWebImageWebPCoder.framework" + }, + { + "id": "expo-modules-jsi", + "name": "ExpoModulesJSI", + "executable": "ExpoModulesJSI", + "searchPath": "/home/me/expo-58-bridging/ios-xtool/jsi-out", + "frameworkDir": "/home/me/expo-58-bridging/ios-xtool/jsi-out/ExpoModulesJSI.framework" + } + ], + "iosMin": "16.4", + "expo": { + "compileInterfacesDir": "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/compile-interfaces", + "clangImporter": { + "swiftHeadersDir": "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos", + "includeDirs": [ + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoAsset/pod-headers", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoDevice/pod-headers", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoDomWebView/pod-headers", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoGlassEffect/pod-headers", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoKeepAwake/pod-headers", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoLinking/pod-headers", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoRouter/pod-headers", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoSplashScreen/pod-headers", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoStatusBar/pod-headers", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoSymbols/pod-headers", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoSystemUI/pod-headers", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoUI/pod-headers", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoWebBrowser/pod-headers" + ], + "moduleMaps": [ + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoAsset.modulemap", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoDevice.modulemap", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoDomWebView.modulemap", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoGlassEffect.modulemap", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoKeepAwake.modulemap", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoLinking.modulemap", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoRouter.modulemap", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoSplashScreen.modulemap", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoStatusBar.modulemap", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoSymbols.modulemap", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoSystemUI.modulemap", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoUI.modulemap", + "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ExpoWebBrowser.modulemap" + ] + }, + "jsiHeaders": true + }, + "app": { + "mixed": false, + "bridgingHeader": "/home/me/expo-58-bridging/ios-xtool/Sources/App/app-Bridging-Header.h", + "defines": [], + "headerSearchPaths": [], + "swiftHeadersDir": "/home/me/expo-58-bridging/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos", + "importerPaths": [ + "/home/me/expo-58-bridging/node_modules/@react-native-masked-view/masked-view/ios", + "/home/me/expo-58-bridging/node_modules/@react-native-masked-view/masked-view/.", + "/home/me/expo-58-bridging/node_modules/react-native-gesture-handler/apple/Handlers", + "/home/me/expo-58-bridging/node_modules/react-native-gesture-handler/apple", + "/home/me/expo-58-bridging/node_modules/react-native-gesture-handler/shared/runtime", + "/home/me/expo-58-bridging/node_modules/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen", + "/home/me/expo-58-bridging/node_modules/react-native-gesture-handler/.", + "/home/me/expo-58-bridging/node_modules/react-native-screens/common/cpp", + "/home/me/expo-58-bridging/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens", + "/home/me/expo-58-bridging/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/utils", + "/home/me/expo-58-bridging/node_modules/react-native-screens/cpp", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/bridging", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/conversion", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/events", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/helpers/container", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/helpers/image", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/helpers/scroll-view", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/integrations", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/safe-area", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/stubs", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/tabs", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/tabs/bottom-accessory", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/tabs/extensions", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/tabs/host", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/tabs/screen", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/utils", + "/home/me/expo-58-bridging/node_modules/react-native-screens/ios/utils/extensions", + "/home/me/expo-58-bridging/node_modules/react-native-screens/.", + "/home/me/expo-58-bridging/node_modules/react-native-screens/include" + ] + }, + "devSupport": true + }, + "origins": { + "/home/me/expo-58-bridging/ios-xtool/Sources/App/AppDelegate.swift": "/home/me/expo-58-bridging/ios/app/AppDelegate.swift", + "/home/me/expo-58-bridging/ios-xtool/Sources/App/SceneDelegate.swift": "/home/me/expo-58-bridging/ios/app/SceneDelegate.swift", + "/home/me/expo-58-bridging/ios-xtool/Sources/App/app-Bridging-Header.h": "/home/me/expo-58-bridging/ios/app/app-Bridging-Header.h", + "/home/me/expo-58-bridging/ios-xtool/Sources/App/ExpoModulesProvider.swift": "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/ExpoModulesProvider.swift" + } + }, + "graph": { + "headerDirs": [ + "/home/me/expo-58-bridging/ios/build/xcframeworks/ReactHeadersTarget/include", + "/home/me/expo-58-bridging/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers", + "/home/me/expo-58-bridging/ios/build/xcframeworks/ReactNativeDependenciesHeaders.xcframework/ios-arm64/Headers", + "/home/me/expo-58-bridging/ios/build/generated/ios/ReactCodegen", + "/home/me/expo-58-bridging/ios/build/generated/ios/ReactAppHeaders", + "/home/me/expo-58-bridging/ios/build/generated/ios/ReactAppDependencyProvider", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNCMaskedView/include", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNGestureHandler/include", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNWorklets/Common/cpp", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNReanimated/include", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNScreens/ios", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/ExpoModulesJSIHeaders/ExpoModulesJSIHeaders.xcframework/ios-arm64/Headers", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/expo-log-box/root/ios/ExpoLogBoxObjC/include", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoUI/root/ios", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/expo/root/ios/ExpoObjC/include", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/expo/root/ios/ExpoLoader/include", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/expo-constants/root/ios/EXConstantsObjC/include", + "/home/me/expo-58-bridging/ios-xtool/Sources/RNXtoolDevSupport/include" + ], + "moduleMaps": [ + "/home/me/expo-58-bridging/ios/build/xcframeworks/ReactHeadersTarget/include/module.modulemap", + "/home/me/expo-58-bridging/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/module.modulemap", + "/home/me/expo-58-bridging/ios/build/generated/ios/ReactAppHeaders/module.modulemap", + "/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNScreens/ios/module.modulemap" + ], + "synthesized": [ + { + "module": "ReactCodegen", + "text": "module ReactCodegen {\n umbrella \"/home/me/expo-58-bridging/ios/build/generated/ios/ReactCodegen\"\n export *\n}\n" + }, + { + "module": "ReactAppDependencyProvider", + "text": "module ReactAppDependencyProvider {\n umbrella \"/home/me/expo-58-bridging/ios/build/generated/ios/ReactAppDependencyProvider\"\n export *\n}\n" + }, + { + "module": "RNCMaskedView", + "text": "module RNCMaskedView {\n umbrella header \"/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNCMaskedView/include/RNCMaskedView/RNCMaskedView.h\"\n export *\n}\n" + }, + { + "module": "RNGestureHandler", + "text": "module RNGestureHandler {\n umbrella header \"/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNGestureHandler/include/RNGestureHandler/RNGestureHandler.h\"\n export *\n}\n" + }, + { + "module": "RNWorklets", + "text": "module RNWorklets {\n umbrella \"/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNWorklets/Common/cpp\"\n export *\n}\n" + }, + { + "module": "RNReanimated", + "text": "module RNReanimated {\n umbrella \"/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/RNReanimated/include\"\n export *\n}\n" + }, + { + "module": "ReactNativeSafeAreaContext", + "text": "module ReactNativeSafeAreaContext {\n umbrella \"/home/me/expo-58-bridging/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios\"\n export *\n}\n" + }, + { + "module": "ExpoLogBoxObjC", + "text": "module ExpoLogBoxObjC {\n umbrella \"/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/expo-log-box/root/ios/ExpoLogBoxObjC/include\"\n export *\n}\n" + }, + { + "module": "ExpoUI", + "text": "module ExpoUI {\n umbrella \"/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/ExpoUI/root/ios\"\n export *\n}\n" + }, + { + "module": "ExpoObjC", + "text": "module ExpoObjC {\n umbrella \"/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/expo/root/ios/ExpoObjC/include\"\n export *\n}\n" + }, + { + "module": "ExpoLoader", + "text": "module ExpoLoader {\n umbrella \"/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/expo/root/ios/ExpoLoader/include\"\n export *\n}\n" + }, + { + "module": "EXConstantsObjC", + "text": "module EXConstantsObjC {\n umbrella \"/home/me/expo-58-bridging/ios/build/generated/autolinking/expo/expo-source/expo-constants/root/ios/EXConstantsObjC/include\"\n export *\n}\n" + }, + { + "module": "RNXtoolDevSupport", + "text": "module RNXtoolDevSupport {\n umbrella header \"/home/me/expo-58-bridging/ios-xtool/Sources/RNXtoolDevSupport/include/RNXtoolDevSupport.h\"\n export *\n}\n" + } + ], + "targets": [ + "App", + "RNXtoolDevSupport", + "ReactHeaders", + "ReactNativeHeaders", + "ReactNativeDependenciesHeaders", + "ReactCodegen", + "ReactAppDependencyProvider", + "ReactAppHeaders", + "AutolinkedAggregate", + "Autolinked", + "RNCMaskedView", + "RNGestureHandler", + "RNWorklets", + "RNReanimated", + "ReactNativeSafeAreaContext", + "RNScreens", + "ExpoDomWebView", + "ExpoModulesJSIHeaders", + "ExpoModulesJSILink", + "ExpoLogBox", + "ExpoLogBoxObjC", + "ExpoUI", + "Expo", + "ExpoObjC", + "ExpoLoader", + "ExpoAsset", + "EXConstants", + "EXConstantsObjC", + "ExpoDevice", + "ExpoGlassEffect", + "ExpoKeepAwake", + "ExpoLinking", + "ExpoRouter", + "ExpoSplashScreen", + "ExpoStatusBar", + "ExpoSymbols", + "ExpoSystemUI", + "ExpoWebBrowser" + ], + "modules": [ + "React", + "CoreModules", + "RCTAnimation", + "RCTBlob", + "RCTDeprecation", + "RCTImage", + "RCTSettings", + "RCTSwiftUIWrapper", + "RCTText", + "RCTVibration", + "ReactCommon", + "React_RCTAppDelegate", + "ReactNativeHeaders_react", + "reactperflogger", + "yoga", + "ReactAppHeaders", + "RNScreens", + "ReactCodegen", + "ReactAppDependencyProvider", + "RNCMaskedView", + "RNGestureHandler", + "RNWorklets", + "RNReanimated", + "ReactNativeSafeAreaContext", + "ExpoLogBoxObjC", + "ExpoUI", + "ExpoObjC", + "ExpoLoader", + "EXConstantsObjC", + "RNXtoolDevSupport" + ], + "unresolved": [] + }, + "toolchain": { + "clang": "/home/me/.local/share/swiftly/bin/clang", + "swiftc": "/home/me/.local/share/swiftly/bin/swiftc", + "sdk": "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk", + "swiftResources": "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift", + "swiftIncludes": [ + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib" + ], + "swiftExtra": [ + "-Xfrontend", + "-enable-cross-import-overlays" + ], + "versions": "clang version 21.0.0 (https://github.com/swiftlang/llvm-project.git 51091bd668a61591b761afe08e2776476e20ff1c)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin\nSwift version 6.4.1 (swift-6.4.1-RELEASE)\nTarget: x86_64-unknown-linux-gnu\nepoch=4,darwinTools=1.1.0,oam=1.4.1" + }, + "dir": "/home/me/expo-58-bridging/ios-xtool/.precheck", + "moduleCache": "/home/me/expo-58-bridging/ios-xtool/.precheck/ModuleCache/rn0.88.1-b534cbed0fc4" +} diff --git a/tests/fixtures/precheck/golden/objc-088/commands.json b/tests/fixtures/precheck/golden/objc-088/commands.json new file mode 100644 index 0000000..168b117 --- /dev/null +++ b/tests/fixtures/precheck/golden/objc-088/commands.json @@ -0,0 +1,173 @@ +{ + "swiftDriver": [], + "compileC": [ + { + "description": "CompileC /home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/AppDelegate.o /home/me/objc-088/ios-xtool/Sources/App/AppDelegate.mm normal arm64 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler", + "tool": "shell", + "argsFrom": "manifest", + "args": [ + "/home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin/clang", + "-x", + "objective-c++", + "-target", + "arm64-apple-ios16.4", + "-fmessage-length=0", + "-fdiagnostics-show-note-include-stack", + "-fmacro-backtrace-limit=0", + "-fcolor-diagnostics", + "-fmodules-prune-interval=86400", + "-fmodules-prune-after=345600", + "-fbuild-session-file=/home/me/objc-088/ios-xtool/.build/out/ModuleCache.noindex/Session.modulevalidation", + "-fmodules-validate-once-per-build-session", + "-Wnon-modular-include-in-framework-module", + "-Werror=non-modular-include-in-framework-module", + "-Wno-trigraphs", + "-Wno-missing-field-initializers", + "-Wno-missing-prototypes", + "-Wno-return-type", + "-Wno-implicit-atomic-properties", + "-Wno-objc-interface-ivars", + "-Wno-arc-repeated-use-of-weak", + "-Wno-non-virtual-dtor", + "-Wno-overloaded-virtual", + "-Wno-exit-time-destructors", + "-Wno-missing-braces", + "-Wparentheses", + "-Wswitch", + "-Wno-unused-function", + "-Wno-unused-label", + "-Wno-unused-parameter", + "-Wno-unused-variable", + "-Wunused-value", + "-Wno-empty-body", + "-Wno-uninitialized", + "-Wno-unknown-pragmas", + "-Wno-shadow", + "-Wno-four-char-constants", + "-Wno-conversion", + "-Wno-constant-conversion", + "-Wno-int-conversion", + "-Wno-bool-conversion", + "-Wno-enum-conversion", + "-Wno-float-conversion", + "-Wno-non-literal-null-conversion", + "-Wno-objc-literal-conversion", + "-Wshorten-64-to-32", + "-Wno-newline-eof", + "-Wno-selector", + "-Wno-strict-selector-match", + "-Wno-undeclared-selector", + "-Wno-deprecated-implementations", + "-Wno-c++11-extensions", + "-Wno-implicit-fallthrough", + "-isysroot", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk", + "-fstrict-aliasing", + "-Wprotocol", + "-Wdeprecated-declarations", + "-Winvalid-offsetof", + "-Wno-sign-conversion", + "-Wno-infinite-recursion", + "-Wno-move", + "-Wno-comma", + "-Wno-block-capture-autoreleasing", + "-Wno-strict-prototypes", + "-Wno-range-loop-analysis", + "-Wno-semicolon-before-method-body", + "@/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/1327f19f0bcfdca2b0edc983f55b1f87bc6668d9b41defbef7b7987f2db570ad-common-args.resp", + "-MMD", + "-MT", + "dependencies", + "-MF", + "/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/AppDelegate.d", + "--serialize-diagnostics", + "/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/AppDelegate.dia", + "-c", + "/home/me/objc-088/ios-xtool/Sources/App/AppDelegate.mm", + "-o", + "/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/AppDelegate.o" + ] + }, + { + "description": "CompileC /home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/AppMain.o /home/me/objc-088/ios-xtool/Sources/App/AppMain.m normal arm64 objective-c com.apple.compilers.llvm.clang.1_0.compiler", + "tool": "ccompile", + "argsFrom": "task-store (1 candidate(s))", + "args": [ + "/home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin/clang", + "-x", + "objective-c", + "-target", + "arm64-apple-ios16.4", + "-fmessage-length=0", + "-fdiagnostics-show-note-include-stack", + "-fmacro-backtrace-limit=0", + "-fcolor-diagnostics", + "-fmodules-prune-interval=86400", + "-fmodules-prune-after=345600", + "-fbuild-session-file=/home/me/objc-088/ios-xtool/.build/out/ModuleCache.noindex/Session.modulevalidation", + "-fmodules-validate-once-per-build-session", + "-Wnon-modular-include-in-framework-module", + "-Werror=non-modular-include-in-framework-module", + "-Wno-trigraphs", + "-Wno-missing-field-initializers", + "-Wno-missing-prototypes", + "-Wno-return-type", + "-Wno-implicit-atomic-properties", + "-Wno-objc-interface-ivars", + "-Wno-arc-repeated-use-of-weak", + "-Wno-missing-braces", + "-Wparentheses", + "-Wswitch", + "-Wno-unused-function", + "-Wno-unused-label", + "-Wno-unused-parameter", + "-Wno-unused-variable", + "-Wunused-value", + "-Wno-empty-body", + "-Wno-uninitialized", + "-Wno-unknown-pragmas", + "-Wno-shadow", + "-Wno-four-char-constants", + "-Wno-conversion", + "-Wno-constant-conversion", + "-Wno-int-conversion", + "-Wno-bool-conversion", + "-Wno-enum-conversion", + "-Wno-float-conversion", + "-Wno-non-literal-null-conversion", + "-Wno-objc-literal-conversion", + "-Wshorten-64-to-32", + "-Wpointer-sign", + "-Wno-newline-eof", + "-Wno-selector", + "-Wno-strict-selector-match", + "-Wno-undeclared-selector", + "-Wno-deprecated-implementations", + "-Wno-implicit-fallthrough", + "-isysroot", + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk", + "-fstrict-aliasing", + "-Wprotocol", + "-Wdeprecated-declarations", + "-Wno-sign-conversion", + "-Wno-infinite-recursion", + "-Wno-comma", + "-Wno-block-capture-autoreleasing", + "-Wno-strict-prototypes", + "-Wno-semicolon-before-method-body", + "@/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/6f95552a3397ee1cec971b90cf334075d5f321c3a3b0689ad55c3d1e24702600-common-args.resp", + "-MMD", + "-MT", + "dependencies", + "-MF", + "/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/AppMain.d", + "--serialize-diagnostics", + "/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/AppMain.dia", + "-c", + "/home/me/objc-088/ios-xtool/Sources/App/AppMain.m", + "-o", + "/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/Objects-normal/arm64/AppMain.o" + ] + } + ] +} \ No newline at end of file diff --git a/tests/fixtures/precheck/golden/objc-088/inputs.json b/tests/fixtures/precheck/golden/objc-088/inputs.json new file mode 100644 index 0000000..c93eaac --- /dev/null +++ b/tests/fixtures/precheck/golden/objc-088/inputs.json @@ -0,0 +1,244 @@ +{ + "app": { + "pkg": { + "iosDir": "/home/me/objc-088/ios", + "frameworks": [ + { + "id": "react", + "name": "React", + "executable": "React", + "searchPath": "/home/me/objc-088/ios/build/xcframeworks/debug/React.xcframework/ios-arm64", + "frameworkDir": "/home/me/objc-088/ios/build/xcframeworks/debug/React.xcframework/ios-arm64/React.framework" + }, + { + "id": "react-native-dependencies", + "name": "ReactNativeDependencies", + "executable": "ReactNativeDependencies", + "searchPath": "/home/me/objc-088/ios/build/xcframeworks/debug/ReactNativeDependencies.xcframework/ios-arm64", + "frameworkDir": "/home/me/objc-088/ios/build/xcframeworks/debug/ReactNativeDependencies.xcframework/ios-arm64/ReactNativeDependencies.framework" + }, + { + "id": "hermes", + "name": "hermesvm", + "executable": "hermesvm", + "searchPath": "/home/me/objc-088/ios/build/xcframeworks/debug/hermes-engine.xcframework/ios-arm64", + "frameworkDir": "/home/me/objc-088/ios/build/xcframeworks/debug/hermes-engine.xcframework/ios-arm64/hermesvm.framework" + } + ], + "iosMin": "16.4", + "app": { + "mixed": true, + "defines": [ + "DEBUG=1" + ], + "headerSearchPaths": [ + "/home/me/objc-088/ios-xtool/Sources/App/include", + "/home/me/objc-088/ios/build/xcframeworks/ReactHeadersTarget/include/React", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/CoreModules", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTAnimation", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTBlob", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTDeprecation", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTImage", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSettings", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSwiftUIWrapper", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTText", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTVibration", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/ReactCommon", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/React_RCTAppDelegate", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/reactperflogger", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/yoga" + ], + "cxxStandard": "c++20", + "swiftHeadersDir": "/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos", + "importerPaths": [ + "/home/me/objc-088/node_modules/@react-native-community/datetimepicker/ios", + "/home/me/objc-088/node_modules/@react-native-community/datetimepicker/ios/fabric", + "/home/me/objc-088/node_modules/@react-native-community/datetimepicker/ios/fabric/cpp/react/renderer/components/RNDateTimePicker", + "/home/me/objc-088/node_modules/@react-native-community/datetimepicker/.", + "/home/me/objc-088/node_modules/react-native-gesture-handler/apple/Handlers", + "/home/me/objc-088/node_modules/react-native-gesture-handler/apple", + "/home/me/objc-088/node_modules/react-native-gesture-handler/shared/runtime", + "/home/me/objc-088/node_modules/react-native-gesture-handler/shared/shadowNodes/react/renderer/components/rngesturehandler_codegen", + "/home/me/objc-088/node_modules/react-native-gesture-handler/.", + "/home/me/objc-088/node_modules/react-native-svg/common/cpp", + "/home/me/objc-088/node_modules/react-native-svg/apple/Brushes", + "/home/me/objc-088/node_modules/react-native-svg/apple/Elements", + "/home/me/objc-088/node_modules/react-native-svg/apple/Filters/MetalCI", + "/home/me/objc-088/node_modules/react-native-svg/apple/Filters", + "/home/me/objc-088/node_modules/react-native-svg/apple", + "/home/me/objc-088/node_modules/react-native-svg/apple/Shapes", + "/home/me/objc-088/node_modules/react-native-svg/apple/Text", + "/home/me/objc-088/node_modules/react-native-svg/apple/Utils", + "/home/me/objc-088/node_modules/react-native-svg/apple/ViewManagers", + "/home/me/objc-088/node_modules/react-native-svg/common/cpp/react/renderer/components/rnsvg", + "/home/me/objc-088/node_modules/react-native-svg/.", + "/home/me/objc-088/node_modules/react-native-svg/include", + "/home/me/objc-088/node_modules/react-native-screens/common/cpp", + "/home/me/objc-088/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens", + "/home/me/objc-088/node_modules/react-native-screens/common/cpp/react/renderer/components/rnscreens/utils", + "/home/me/objc-088/node_modules/react-native-screens/cpp", + "/home/me/objc-088/node_modules/react-native-screens/ios", + "/home/me/objc-088/node_modules/react-native-screens/ios/bridging", + "/home/me/objc-088/node_modules/react-native-screens/ios/conversion", + "/home/me/objc-088/node_modules/react-native-screens/ios/events", + "/home/me/objc-088/node_modules/react-native-screens/ios/helpers/container", + "/home/me/objc-088/node_modules/react-native-screens/ios/helpers/image", + "/home/me/objc-088/node_modules/react-native-screens/ios/helpers/scroll-view", + "/home/me/objc-088/node_modules/react-native-screens/ios/integrations", + "/home/me/objc-088/node_modules/react-native-screens/ios/safe-area", + "/home/me/objc-088/node_modules/react-native-screens/ios/stubs", + "/home/me/objc-088/node_modules/react-native-screens/ios/tabs", + "/home/me/objc-088/node_modules/react-native-screens/ios/tabs/bottom-accessory", + "/home/me/objc-088/node_modules/react-native-screens/ios/tabs/extensions", + "/home/me/objc-088/node_modules/react-native-screens/ios/tabs/host", + "/home/me/objc-088/node_modules/react-native-screens/ios/tabs/screen", + "/home/me/objc-088/node_modules/react-native-screens/ios/utils", + "/home/me/objc-088/node_modules/react-native-screens/ios/utils/extensions", + "/home/me/objc-088/node_modules/react-native-screens/.", + "/home/me/objc-088/node_modules/react-native-screens/include", + "/home/me/objc-088/node_modules/react-native-webview/apple", + "/home/me/objc-088/node_modules/react-native-webview/." + ] + }, + "devSupport": true + }, + "origins": { + "/home/me/objc-088/ios-xtool/Sources/App/AppDelegate.mm": "/home/me/objc-088/ios/ObjcApp/AppDelegate.mm", + "/home/me/objc-088/ios-xtool/Sources/App/AppMain.m": "/home/me/objc-088/ios/ObjcApp/main.m", + "/home/me/objc-088/ios-xtool/Sources/App/AppDelegate.h": "/home/me/objc-088/ios/ObjcApp/AppDelegate.h" + } + }, + "graph": { + "headerDirs": [ + "/home/me/objc-088/ios/build/xcframeworks/ReactHeadersTarget/include", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeDependenciesHeaders.xcframework/ios-arm64/Headers", + "/home/me/objc-088/ios/build/generated/ios/ReactCodegen", + "/home/me/objc-088/ios/build/generated/ios/ReactAppHeaders", + "/home/me/objc-088/ios/build/generated/ios/ReactAppDependencyProvider", + "/home/me/objc-088/ios/build/generated/autolinking/libs/RNDateTimePicker/include", + "/home/me/objc-088/ios/build/generated/autolinking/libs/RNGestureHandler/include", + "/home/me/objc-088/ios/build/generated/autolinking/libs/RNWorklets/Common/cpp", + "/home/me/objc-088/ios/build/generated/autolinking/libs/RNReanimated/include", + "/home/me/objc-088/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios", + "/home/me/objc-088/ios/build/generated/autolinking/libs/RNScreens/ios", + "/home/me/objc-088/ios/build/generated/autolinking/libs/RNSVG/apple", + "/home/me/objc-088/ios/build/generated/autolinking/libs/ReactNativeWebview/apple", + "/home/me/objc-088/ios-xtool/Sources/RNXtoolDevSupport/include" + ], + "moduleMaps": [ + "/home/me/objc-088/ios/build/xcframeworks/ReactHeadersTarget/include/module.modulemap", + "/home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/module.modulemap", + "/home/me/objc-088/ios/build/generated/ios/ReactAppHeaders/module.modulemap", + "/home/me/objc-088/ios/build/generated/autolinking/libs/RNScreens/ios/module.modulemap" + ], + "synthesized": [ + { + "module": "ReactCodegen", + "text": "module ReactCodegen {\n umbrella \"/home/me/objc-088/ios/build/generated/ios/ReactCodegen\"\n export *\n}\n" + }, + { + "module": "ReactAppDependencyProvider", + "text": "module ReactAppDependencyProvider {\n umbrella \"/home/me/objc-088/ios/build/generated/ios/ReactAppDependencyProvider\"\n export *\n}\n" + }, + { + "module": "RNDateTimePicker", + "text": "module RNDateTimePicker {\n umbrella header \"/home/me/objc-088/ios/build/generated/autolinking/libs/RNDateTimePicker/include/RNDateTimePicker/RNDateTimePicker.h\"\n export *\n}\n" + }, + { + "module": "RNGestureHandler", + "text": "module RNGestureHandler {\n umbrella header \"/home/me/objc-088/ios/build/generated/autolinking/libs/RNGestureHandler/include/RNGestureHandler/RNGestureHandler.h\"\n export *\n}\n" + }, + { + "module": "RNWorklets", + "text": "module RNWorklets {\n umbrella \"/home/me/objc-088/ios/build/generated/autolinking/libs/RNWorklets/Common/cpp\"\n export *\n}\n" + }, + { + "module": "RNReanimated", + "text": "module RNReanimated {\n umbrella \"/home/me/objc-088/ios/build/generated/autolinking/libs/RNReanimated/include\"\n export *\n}\n" + }, + { + "module": "ReactNativeSafeAreaContext", + "text": "module ReactNativeSafeAreaContext {\n umbrella \"/home/me/objc-088/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios\"\n export *\n}\n" + }, + { + "module": "RNSVG", + "text": "module RNSVG {\n umbrella \"/home/me/objc-088/ios/build/generated/autolinking/libs/RNSVG/apple\"\n export *\n}\n" + }, + { + "module": "ReactNativeWebview", + "text": "module ReactNativeWebview {\n umbrella \"/home/me/objc-088/ios/build/generated/autolinking/libs/ReactNativeWebview/apple\"\n export *\n}\n" + }, + { + "module": "RNXtoolDevSupport", + "text": "module RNXtoolDevSupport {\n umbrella header \"/home/me/objc-088/ios-xtool/Sources/RNXtoolDevSupport/include/RNXtoolDevSupport.h\"\n export *\n}\n" + } + ], + "targets": [ + "App", + "RNXtoolDevSupport", + "ReactHeaders", + "ReactNativeHeaders", + "ReactNativeDependenciesHeaders", + "ReactCodegen", + "ReactAppDependencyProvider", + "ReactAppHeaders", + "AutolinkedAggregate", + "Autolinked", + "RNDateTimePicker", + "RNGestureHandler", + "RNWorklets", + "RNReanimated", + "ReactNativeSafeAreaContext", + "RNScreens", + "RNSVG", + "ReactNativeWebview" + ], + "modules": [ + "React", + "CoreModules", + "RCTAnimation", + "RCTBlob", + "RCTDeprecation", + "RCTImage", + "RCTSettings", + "RCTSwiftUIWrapper", + "RCTText", + "RCTVibration", + "ReactCommon", + "React_RCTAppDelegate", + "ReactNativeHeaders_react", + "reactperflogger", + "yoga", + "ReactAppHeaders", + "RNScreens", + "ReactCodegen", + "ReactAppDependencyProvider", + "RNDateTimePicker", + "RNGestureHandler", + "RNWorklets", + "RNReanimated", + "ReactNativeSafeAreaContext", + "RNSVG", + "ReactNativeWebview", + "RNXtoolDevSupport" + ], + "unresolved": [] + }, + "toolchain": { + "clang": "/home/me/.local/share/swiftly/bin/clang", + "swiftc": "/home/me/.local/share/swiftly/bin/swiftc", + "sdk": "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk", + "swiftResources": "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift", + "swiftIncludes": [ + "/home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib" + ], + "swiftExtra": [ + "-Xfrontend", + "-enable-cross-import-overlays" + ], + "versions": "clang version 21.0.0 (https://github.com/swiftlang/llvm-project.git 51091bd668a61591b761afe08e2776476e20ff1c)\nTarget: x86_64-unknown-linux-gnu\nThread model: posix\nInstalledDir: /home/me/.local/share/swiftly/toolchains/6.4.1/usr/bin\nSwift version 6.4.1 (swift-6.4.1-RELEASE)\nTarget: x86_64-unknown-linux-gnu\nepoch=4,darwinTools=1.1.0,oam=1.4.1" + }, + "dir": "/home/me/objc-088/ios-xtool/.precheck", + "moduleCache": "/home/me/objc-088/ios-xtool/.precheck/ModuleCache/rn0.88.1-b534cbed0fc4" +} diff --git a/tests/fixtures/precheck/golden/objc-088/responses/1327f19f0bcfdca2b0edc983f55b1f87bc6668d9b41defbef7b7987f2db570ad-common-args.resp b/tests/fixtures/precheck/golden/objc-088/responses/1327f19f0bcfdca2b0edc983f55b1f87bc6668d9b41defbef7b7987f2db570ad-common-args.resp new file mode 100644 index 0000000..5cd24da --- /dev/null +++ b/tests/fixtures/precheck/golden/objc-088/responses/1327f19f0bcfdca2b0edc983f55b1f87bc6668d9b41defbef7b7987f2db570ad-common-args.resp @@ -0,0 +1 @@ +-std=c++20 -fobjc-arc -fmodules -fno-cxx-modules -gmodules -fmodules-cache-path=/home/me/objc-088/ios-xtool/.build/out/ModuleCache.noindex -fmodule-name=App -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG -fpascal-strings -O0 -DSWIFT_PACKAGE -DDEBUG=1 -DDEBUG=1 -DDEBUG=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=1 -g -fvisibility-inlines-hidden -I/home/me/objc-088/ios/build/xcframeworks/ReactHeadersTarget/include -I/home/me/objc-088/ios/build/generated/ios/ReactCodegen -I/home/me/objc-088/ios/build/generated/ios/ReactAppDependencyProvider -I/home/me/objc-088/ios/build/generated/autolinking/libs/RNDateTimePicker/include -I/home/me/objc-088/ios/build/generated/autolinking/libs/RNGestureHandler/include -I/home/me/objc-088/ios/build/generated/autolinking/libs/RNReanimated/include -I/home/me/objc-088/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios -I/home/me/objc-088/ios/build/generated/autolinking/libs/RNScreens/ios -I/home/me/objc-088/ios/build/generated/autolinking/libs/RNSVG/apple -I/home/me/objc-088/ios/build/generated/autolinking/libs/ReactNativeWebview/apple -I/home/me/objc-088/ios/build/generated/ios/ReactAppHeaders -I/home/me/objc-088/ios/build/generated/autolinking/libs/RNWorklets/Common/cpp -I/home/me/objc-088/ios-xtool/Sources/RNXtoolDevSupport/include -I/home/me/objc-088/ios-xtool/.build/out/Products/Debug-iphoneos/include -I/home/me/objc-088/ios-xtool/Sources/App/include -I/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources-normal/arm64 -I/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources/arm64 -I/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources -F/home/me/objc-088/ios-xtool/.build/out/Products/Debug-iphoneos/PackageFrameworks -F/home/me/objc-088/ios-xtool/.build/out/Products/Debug-iphoneos -iframework /home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks -iframework /home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk/Developer/Library/Frameworks -fmodule-map-file=/home/me/objc-088/ios/build/xcframeworks/ReactHeadersTarget/include/module.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactCodegen.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactAppDependencyProvider.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNDateTimePicker.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNGestureHandler.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNReanimated.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactNativeSafeAreaContext.modulemap -fmodule-map-file=/home/me/objc-088/ios/build/generated/autolinking/libs/RNScreens/ios/module.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNSVG.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactNativeWebview.modulemap -fmodule-map-file=/home/me/objc-088/ios/build/generated/ios/ReactAppHeaders/module.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNWorklets.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/AutolinkedAggregate.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNXtoolDevSupport.modulemap -DXcode -I /home/me/objc-088/ios-xtool/Sources/App/include -I /home/me/objc-088/ios/build/xcframeworks/ReactHeadersTarget/include/React -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/CoreModules -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTAnimation -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTBlob -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTDeprecation -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTImage -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSettings -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSwiftUIWrapper -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTText -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTVibration -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/ReactCommon -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/React_RCTAppDelegate -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/reactperflogger -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/yoga -I /home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos -I /home/me/objc-088/ios-xtool/Sources/App/include -I /home/me/objc-088/ios/build/xcframeworks/ReactHeadersTarget/include/React -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/CoreModules -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTAnimation -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTBlob -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTDeprecation -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTImage -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSettings -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSwiftUIWrapper -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTText -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTVibration -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/ReactCommon -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/React_RCTAppDelegate -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/reactperflogger -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/yoga -I /home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos -std=c++20 \ No newline at end of file diff --git a/tests/fixtures/precheck/golden/objc-088/responses/6f95552a3397ee1cec971b90cf334075d5f321c3a3b0689ad55c3d1e24702600-common-args.resp b/tests/fixtures/precheck/golden/objc-088/responses/6f95552a3397ee1cec971b90cf334075d5f321c3a3b0689ad55c3d1e24702600-common-args.resp new file mode 100644 index 0000000..0375034 --- /dev/null +++ b/tests/fixtures/precheck/golden/objc-088/responses/6f95552a3397ee1cec971b90cf334075d5f321c3a3b0689ad55c3d1e24702600-common-args.resp @@ -0,0 +1 @@ +-fobjc-arc -fmodules -gmodules -fmodules-cache-path=/home/me/objc-088/ios-xtool/.build/out/ModuleCache.noindex -fmodule-name=App -fpascal-strings -O0 -DSWIFT_PACKAGE -DDEBUG=1 -DDEBUG=1 -DDEBUG=1 -DOBJC_OLD_DISPATCH_PROTOTYPES=1 -g -I/home/me/objc-088/ios/build/xcframeworks/ReactHeadersTarget/include -I/home/me/objc-088/ios/build/generated/ios/ReactCodegen -I/home/me/objc-088/ios/build/generated/ios/ReactAppDependencyProvider -I/home/me/objc-088/ios/build/generated/autolinking/libs/RNDateTimePicker/include -I/home/me/objc-088/ios/build/generated/autolinking/libs/RNGestureHandler/include -I/home/me/objc-088/ios/build/generated/autolinking/libs/RNReanimated/include -I/home/me/objc-088/ios/build/generated/autolinking/libs/ReactNativeSafeAreaContext/ios -I/home/me/objc-088/ios/build/generated/autolinking/libs/RNScreens/ios -I/home/me/objc-088/ios/build/generated/autolinking/libs/RNSVG/apple -I/home/me/objc-088/ios/build/generated/autolinking/libs/ReactNativeWebview/apple -I/home/me/objc-088/ios/build/generated/ios/ReactAppHeaders -I/home/me/objc-088/ios/build/generated/autolinking/libs/RNWorklets/Common/cpp -I/home/me/objc-088/ios-xtool/Sources/RNXtoolDevSupport/include -I/home/me/objc-088/ios-xtool/.build/out/Products/Debug-iphoneos/include -I/home/me/objc-088/ios-xtool/Sources/App/include -I/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources-normal/arm64 -I/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources/arm64 -I/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/AppXtool.build/Debug-iphoneos/App-t.build/DerivedSources -F/home/me/objc-088/ios-xtool/.build/out/Products/Debug-iphoneos/PackageFrameworks -F/home/me/objc-088/ios-xtool/.build/out/Products/Debug-iphoneos -iframework /home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks -iframework /home/me/.swiftpm/swift-sdks/darwin.artifactbundle/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS27.1.sdk/Developer/Library/Frameworks -fmodule-map-file=/home/me/objc-088/ios/build/xcframeworks/ReactHeadersTarget/include/module.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactCodegen.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactAppDependencyProvider.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNDateTimePicker.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNGestureHandler.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNReanimated.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactNativeSafeAreaContext.modulemap -fmodule-map-file=/home/me/objc-088/ios/build/generated/autolinking/libs/RNScreens/ios/module.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNSVG.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/ReactNativeWebview.modulemap -fmodule-map-file=/home/me/objc-088/ios/build/generated/ios/ReactAppHeaders/module.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNWorklets.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/AutolinkedAggregate.modulemap -fmodule-map-file=/home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos/RNXtoolDevSupport.modulemap -DXcode -I /home/me/objc-088/ios-xtool/Sources/App/include -I /home/me/objc-088/ios/build/xcframeworks/ReactHeadersTarget/include/React -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/CoreModules -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTAnimation -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTBlob -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTDeprecation -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTImage -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSettings -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTSwiftUIWrapper -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTText -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/RCTVibration -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/ReactCommon -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/React_RCTAppDelegate -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/reactperflogger -I /home/me/objc-088/ios/build/xcframeworks/ReactNativeHeaders.xcframework/ios-arm64/Headers/yoga -I /home/me/objc-088/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos \ No newline at end of file diff --git a/tests/fixtures/precheck/graph/alias/dump-a.json b/tests/fixtures/precheck/graph/alias/dump-a.json new file mode 100644 index 0000000..79b5ca3 --- /dev/null +++ b/tests/fixtures/precheck/graph/alias/dump-a.json @@ -0,0 +1,58 @@ +{ + "dependencies": [ + { + "fileSystem": [ + { + "identity": "ios", + "nameForTargetDependencyResolutionOnly": "Foo", + "path": "/home/me/app/alias/b/ios", + "productFilter": null + } + ] + } + ], + "name": "AppXtool", + "packageKind": { + "root": [ + "/home/me/app/alias/a" + ] + }, + "products": [ + { + "name": "App", + "settings": [], + "targets": [ + "App" + ], + "type": { + "library": [ + "automatic" + ] + } + } + ], + "targets": [ + { + "dependencies": [ + { + "product": [ + "BarLib", + "Foo", + null, + null + ] + } + ], + "exclude": [], + "name": "App", + "packageAccess": true, + "path": "Sources/App", + "resources": [], + "settings": [], + "type": "regular" + } + ], + "toolsVersion": { + "_version": "6.0.0" + } +} diff --git a/tests/fixtures/precheck/graph/alias/dump-b.json b/tests/fixtures/precheck/graph/alias/dump-b.json new file mode 100644 index 0000000..0a6a25a --- /dev/null +++ b/tests/fixtures/precheck/graph/alias/dump-b.json @@ -0,0 +1,38 @@ +{ + "dependencies": [], + "name": "Bar", + "packageKind": { + "root": [ + "/home/me/app/alias/b/ios" + ] + }, + "products": [ + { + "name": "BarLib", + "settings": [], + "targets": [ + "BarLib" + ], + "type": { + "library": [ + "automatic" + ] + } + } + ], + "targets": [ + { + "dependencies": [], + "exclude": [], + "name": "BarLib", + "packageAccess": true, + "path": "Sources/BarLib", + "resources": [], + "settings": [], + "type": "regular" + } + ], + "toolsVersion": { + "_version": "6.0.0" + } +} diff --git a/tests/fixtures/precheck/graph/alias/show-dependencies.json b/tests/fixtures/precheck/graph/alias/show-dependencies.json new file mode 100644 index 0000000..6345094 --- /dev/null +++ b/tests/fixtures/precheck/graph/alias/show-dependencies.json @@ -0,0 +1,23 @@ +{ + "identity": "a", + "name": "AppXtool", + "url": "/home/me/app/alias/a", + "version": "unspecified", + "path": "/home/me/app/alias/a", + "traits": [ + "default" + ], + "dependencies": [ + { + "identity": "ios", + "name": "Bar", + "url": "/home/me/app/alias/b/ios", + "version": "unspecified", + "path": "/home/me/app/alias/b/ios", + "traits": [ + "default" + ], + "dependencies": [] + } + ] +} diff --git a/tests/fixtures/precheck/graph/describe-app.json b/tests/fixtures/precheck/graph/describe-app.json new file mode 100644 index 0000000..6b2adb3 --- /dev/null +++ b/tests/fixtures/precheck/graph/describe-app.json @@ -0,0 +1,86 @@ +{ + "dependencies" : [ + { + "identity" : "xcframeworks", + "path" : "/home/me/app/ios/build/xcframeworks", + "type" : "fileSystem" + }, + { + "identity" : "ios", + "path" : "/home/me/app/ios/build/generated/ios", + "type" : "fileSystem" + }, + { + "identity" : "autolinking", + "path" : "/home/me/app/ios/build/generated/autolinking", + "type" : "fileSystem" + }, + { + "identity" : "unreached-lib", + "path" : "/home/me/app/node_modules/unreached-lib", + "type" : "fileSystem" + } + ], + "manifest_display_name" : "AppXtool", + "name" : "AppXtool", + "path" : "/home/me/app/ios-xtool", + "platforms" : [ + { + "name" : "ios", + "version" : "15.1" + } + ], + "products" : [ + { + "name" : "App", + "targets" : [ + "App" + ], + "type" : { + "library" : [ + "automatic" + ] + } + } + ], + "targets" : [ + { + "c99name" : "RNXtoolDevSupport", + "module_type" : "ClangTarget", + "name" : "RNXtoolDevSupport", + "path" : "Sources/RNXtoolDevSupport", + "product_memberships" : [ + "App" + ], + "sources" : [ + "RNXtoolDevSupport.m" + ], + "type" : "library" + }, + { + "c99name" : "App", + "module_type" : "SwiftTarget", + "name" : "App", + "path" : "Sources/App", + "product_dependencies" : [ + "ReactHeaders", + "ReactNativeHeaders", + "ReactNativeDependenciesHeaders", + "ReactCodegen", + "ReactAppDependencyProvider", + "Autolinked" + ], + "product_memberships" : [ + "App" + ], + "sources" : [ + "AppDelegate.swift" + ], + "target_dependencies" : [ + "RNXtoolDevSupport" + ], + "type" : "library" + } + ], + "tools_version" : "6.0" +} diff --git a/tests/fixtures/precheck/graph/describe-executable.json b/tests/fixtures/precheck/graph/describe-executable.json new file mode 100644 index 0000000..2833225 --- /dev/null +++ b/tests/fixtures/precheck/graph/describe-executable.json @@ -0,0 +1,86 @@ +{ + "dependencies": [ + { + "identity": "xcframeworks", + "path": "/home/me/app/ios/build/xcframeworks", + "type": "fileSystem" + }, + { + "identity": "ios", + "path": "/home/me/app/ios/build/generated/ios", + "type": "fileSystem" + }, + { + "identity": "autolinking", + "path": "/home/me/app/ios/build/generated/autolinking", + "type": "fileSystem" + }, + { + "identity": "unreached-lib", + "path": "/home/me/app/node_modules/unreached-lib", + "type": "fileSystem" + } + ], + "manifest_display_name": "AppXtool", + "name": "AppXtool", + "path": "/home/me/app/ios-xtool", + "platforms": [ + { + "name": "ios", + "version": "15.1" + } + ], + "products": [ + { + "name": "App", + "targets": [ + "App" + ], + "type": { + "library": [ + "automatic" + ] + } + } + ], + "targets": [ + { + "c99name": "RNXtoolDevSupport", + "module_type": "ClangTarget", + "name": "RNXtoolDevSupport", + "path": "Sources/RNXtoolDevSupport", + "product_memberships": [ + "App" + ], + "sources": [ + "RNXtoolDevSupport.m" + ], + "type": "library" + }, + { + "c99name": "App", + "module_type": "SwiftTarget", + "name": "App", + "path": "Sources/App", + "product_dependencies": [ + "ReactHeaders", + "ReactNativeHeaders", + "ReactNativeDependenciesHeaders", + "ReactCodegen", + "ReactAppDependencyProvider", + "Autolinked" + ], + "product_memberships": [ + "App" + ], + "sources": [ + "main.swift" + ], + "target_dependencies": [ + "RNXtoolDevSupport" + ], + "type": "executable" + } + ], + "tools_version": "6.0" +} diff --git a/tests/fixtures/precheck/graph/dump-AppXtool.json b/tests/fixtures/precheck/graph/dump-AppXtool.json new file mode 100644 index 0000000..97e5d3e --- /dev/null +++ b/tests/fixtures/precheck/graph/dump-AppXtool.json @@ -0,0 +1,143 @@ +{ + "dependencies": [ + { + "fileSystem": [ + { + "identity": "xcframeworks", + "nameForTargetDependencyResolutionOnly": "ReactNative", + "path": "/home/me/app/ios/build/xcframeworks", + "productFilter": null + } + ] + }, + { + "fileSystem": [ + { + "identity": "ios", + "nameForTargetDependencyResolutionOnly": "React-GeneratedCode", + "path": "/home/me/app/ios/build/generated/ios", + "productFilter": null + } + ] + }, + { + "fileSystem": [ + { + "identity": "autolinking", + "nameForTargetDependencyResolutionOnly": "Autolinked", + "path": "/home/me/app/ios/build/generated/autolinking", + "productFilter": null + } + ] + }, + { + "fileSystem": [ + { + "identity": "unreached-lib", + "path": "/home/me/app/node_modules/unreached-lib", + "productFilter": null + } + ] + } + ], + "name": "AppXtool", + "packageKind": { + "root": [ + "/home/me/app/ios-xtool" + ] + }, + "products": [ + { + "name": "App", + "settings": [], + "targets": [ + "App" + ], + "type": { + "library": [ + "automatic" + ] + } + } + ], + "targets": [ + { + "dependencies": [ + { + "product": [ + "ReactHeaders", + "ReactNative", + null, + null + ] + }, + { + "product": [ + "ReactNativeHeaders", + "ReactNative", + null, + null + ] + }, + { + "product": [ + "ReactNativeDependenciesHeaders", + "ReactNative", + null, + null + ] + }, + { + "product": [ + "ReactCodegen", + "React-GeneratedCode", + null, + null + ] + }, + { + "product": [ + "ReactAppDependencyProvider", + "React-GeneratedCode", + null, + null + ] + }, + { + "product": [ + "Autolinked", + "Autolinked", + null, + null + ] + }, + { + "byName": [ + "RNXtoolDevSupport", + null + ] + } + ], + "exclude": [], + "name": "App", + "packageAccess": true, + "path": "Sources/App", + "resources": [], + "settings": [], + "type": "regular" + }, + { + "dependencies": [], + "exclude": [], + "name": "RNXtoolDevSupport", + "packageAccess": true, + "path": "Sources/RNXtoolDevSupport", + "resources": [], + "settings": [], + "type": "regular" + } + ], + "toolsVersion": { + "_version": "6.0.0" + } +} diff --git a/tests/fixtures/precheck/graph/dump-Autolinked.json b/tests/fixtures/precheck/graph/dump-Autolinked.json new file mode 100644 index 0000000..7095615 --- /dev/null +++ b/tests/fixtures/precheck/graph/dump-Autolinked.json @@ -0,0 +1,57 @@ +{ + "dependencies": [ + { + "fileSystem": [ + { + "identity": "rn-lib", + "path": "/home/me/app/node_modules/rn-lib", + "productFilter": null + } + ] + } + ], + "name": "Autolinked", + "packageKind": { + "root": [ + "/home/me/app/ios/build/generated/autolinking" + ] + }, + "products": [ + { + "name": "Autolinked", + "settings": [], + "targets": [ + "AutolinkedAggregate" + ], + "type": { + "library": [ + "automatic" + ] + } + } + ], + "targets": [ + { + "dependencies": [ + { + "product": [ + "RNLib", + "rn-lib", + null, + null + ] + } + ], + "exclude": [], + "name": "AutolinkedAggregate", + "packageAccess": true, + "path": "AutolinkedAggregate", + "resources": [], + "settings": [], + "type": "regular" + } + ], + "toolsVersion": { + "_version": "6.0.0" + } +} diff --git a/tests/fixtures/precheck/graph/dump-RNLib.json b/tests/fixtures/precheck/graph/dump-RNLib.json new file mode 100644 index 0000000..7731793 --- /dev/null +++ b/tests/fixtures/precheck/graph/dump-RNLib.json @@ -0,0 +1,93 @@ +{ + "dependencies": [ + { + "fileSystem": [ + { + "identity": "xcframeworks", + "nameForTargetDependencyResolutionOnly": "ReactNative", + "path": "/home/me/app/ios/build/xcframeworks", + "productFilter": null + } + ] + }, + { + "fileSystem": [ + { + "identity": "ios", + "nameForTargetDependencyResolutionOnly": "React-GeneratedCode", + "path": "/home/me/app/ios/build/generated/ios", + "productFilter": null + } + ] + } + ], + "name": "RNLib", + "packageKind": { + "root": [ + "/home/me/app/node_modules/rn-lib" + ] + }, + "products": [ + { + "name": "RNLib", + "settings": [], + "targets": [ + "RNLib" + ], + "type": { + "library": [ + "automatic" + ] + } + } + ], + "targets": [ + { + "dependencies": [ + { + "target": [ + "RNLibSwift", + null + ] + }, + { + "product": [ + "ReactAppHeaders", + "React-GeneratedCode", + null, + null + ] + }, + { + "product": [ + "ReactHeaders", + "ReactNative", + null, + null + ] + } + ], + "exclude": [], + "name": "RNLib", + "packageAccess": true, + "path": "ios", + "publicHeadersPath": "public", + "resources": [], + "settings": [], + "type": "regular" + }, + { + "dependencies": [], + "exclude": [], + "name": "RNLibSwift", + "packageAccess": true, + "path": "ios/swift", + "resources": [], + "settings": [], + "type": "regular" + } + ], + "toolsVersion": { + "_version": "6.0.0" + } +} diff --git a/tests/fixtures/precheck/graph/dump-React-GeneratedCode.json b/tests/fixtures/precheck/graph/dump-React-GeneratedCode.json new file mode 100644 index 0000000..234b0dc --- /dev/null +++ b/tests/fixtures/precheck/graph/dump-React-GeneratedCode.json @@ -0,0 +1,118 @@ +{ + "dependencies": [ + { + "fileSystem": [ + { + "identity": "xcframeworks", + "nameForTargetDependencyResolutionOnly": "ReactNative", + "path": "/home/me/app/ios/build/xcframeworks", + "productFilter": null + } + ] + } + ], + "name": "React-GeneratedCode", + "packageKind": { + "root": [ + "/home/me/app/ios/build/generated/ios" + ] + }, + "products": [ + { + "name": "ReactCodegen", + "settings": [], + "targets": [ + "ReactCodegen" + ], + "type": { + "library": [ + "automatic" + ] + } + }, + { + "name": "ReactAppDependencyProvider", + "settings": [], + "targets": [ + "ReactAppDependencyProvider" + ], + "type": { + "library": [ + "automatic" + ] + } + }, + { + "name": "ReactAppHeaders", + "settings": [], + "targets": [ + "ReactAppHeaders" + ], + "type": { + "library": [ + "automatic" + ] + } + } + ], + "targets": [ + { + "dependencies": [ + { + "product": [ + "ReactHeaders", + "ReactNative", + null, + null + ] + } + ], + "exclude": [], + "name": "ReactCodegen", + "packageAccess": true, + "path": "ReactCodegen", + "resources": [], + "settings": [], + "type": "regular" + }, + { + "dependencies": [ + { + "byName": [ + "ReactCodegen", + null + ] + } + ], + "exclude": [], + "name": "ReactAppDependencyProvider", + "packageAccess": true, + "path": "ReactAppDependencyProvider", + "resources": [], + "settings": [], + "type": "regular" + }, + { + "dependencies": [ + { + "product": [ + "ReactHeaders", + "ReactNative", + null, + null + ] + } + ], + "exclude": [], + "name": "ReactAppHeaders", + "packageAccess": true, + "path": "ReactAppHeaders", + "resources": [], + "settings": [], + "type": "regular" + } + ], + "toolsVersion": { + "_version": "6.0.0" + } +} diff --git a/tests/fixtures/precheck/graph/dump-ReactNative.json b/tests/fixtures/precheck/graph/dump-ReactNative.json new file mode 100644 index 0000000..e164cc9 --- /dev/null +++ b/tests/fixtures/precheck/graph/dump-ReactNative.json @@ -0,0 +1,90 @@ +{ + "dependencies": [], + "name": "ReactNative", + "packageKind": { + "root": [ + "/home/me/app/ios/build/xcframeworks" + ] + }, + "products": [ + { + "name": "ReactHeaders", + "settings": [], + "targets": [ + "ReactHeaders" + ], + "type": { + "library": [ + "automatic" + ] + } + }, + { + "name": "ReactNativeHeaders", + "settings": [], + "targets": [ + "ReactNativeHeaders" + ], + "type": { + "library": [ + "automatic" + ] + } + }, + { + "name": "ReactNativeDependenciesHeaders", + "settings": [], + "targets": [ + "ReactNativeDependenciesHeaders" + ], + "type": { + "library": [ + "automatic" + ] + } + } + ], + "targets": [ + { + "dependencies": [ + { + "byName": [ + "ReactNativeHeaders", + null + ] + } + ], + "exclude": [], + "name": "ReactHeaders", + "packageAccess": true, + "path": "ReactHeadersTarget", + "publicHeadersPath": "include", + "resources": [], + "settings": [], + "type": "regular" + }, + { + "dependencies": [], + "exclude": [], + "name": "ReactNativeHeaders", + "packageAccess": false, + "path": "ReactNativeHeaders.xcframework", + "resources": [], + "settings": [], + "type": "binary" + }, + { + "dependencies": [], + "exclude": [], + "name": "ReactNativeDependenciesHeaders", + "packageAccess": false, + "path": "ReactNativeDependenciesHeaders.xcframework", + "resources": [], + "settings": [], + "type": "binary" + } + ], + "toolsVersion": { + "_version": "6.0.0" + } +} diff --git a/tests/fixtures/precheck/graph/dump-UnreachedLib.json b/tests/fixtures/precheck/graph/dump-UnreachedLib.json new file mode 100644 index 0000000..bf03709 --- /dev/null +++ b/tests/fixtures/precheck/graph/dump-UnreachedLib.json @@ -0,0 +1,39 @@ +{ + "dependencies": [], + "name": "UnreachedLib", + "packageKind": { + "root": [ + "/home/me/app/node_modules/unreached-lib" + ] + }, + "products": [ + { + "name": "UnreachedLib", + "settings": [], + "targets": [ + "UnreachedLib" + ], + "type": { + "library": [ + "automatic" + ] + } + } + ], + "targets": [ + { + "dependencies": [], + "exclude": [], + "name": "UnreachedLib", + "packageAccess": true, + "path": "ios", + "publicHeadersPath": "include", + "resources": [], + "settings": [], + "type": "regular" + } + ], + "toolsVersion": { + "_version": "6.0.0" + } +} diff --git a/tests/fixtures/precheck/graph/show-dependencies.json b/tests/fixtures/precheck/graph/show-dependencies.json new file mode 100644 index 0000000..7819544 --- /dev/null +++ b/tests/fixtures/precheck/graph/show-dependencies.json @@ -0,0 +1,103 @@ +{ + "identity": "ios-xtool", + "name": "AppXtool", + "url": "/home/me/app/ios-xtool", + "version": "unspecified", + "path": "/home/me/app/ios-xtool", + "traits": [ + "default" + ], + "dependencies": [ + { + "identity": "xcframeworks", + "name": "ReactNative", + "url": "/home/me/app/ios/build/xcframeworks", + "version": "unspecified", + "path": "/home/me/app/ios/build/xcframeworks", + "traits": [ + "default" + ], + "dependencies": [] + }, + { + "identity": "ios", + "name": "React-GeneratedCode", + "url": "/home/me/app/ios/build/generated/ios", + "version": "unspecified", + "path": "/home/me/app/ios/build/generated/ios", + "traits": [ + "default" + ], + "dependencies": [ + { + "identity": "xcframeworks", + "name": "ReactNative", + "url": "/home/me/app/ios/build/xcframeworks", + "version": "unspecified", + "path": "/home/me/app/ios/build/xcframeworks", + "traits": [ + "default" + ], + "dependencies": [] + } + ] + }, + { + "identity": "autolinking", + "name": "Autolinked", + "url": "/home/me/app/ios/build/generated/autolinking", + "version": "unspecified", + "path": "/home/me/app/ios/build/generated/autolinking", + "traits": [ + "default" + ], + "dependencies": [ + { + "identity": "rn-lib", + "name": "RNLib", + "url": "/home/me/app/node_modules/rn-lib", + "version": "unspecified", + "path": "/home/me/app/node_modules/rn-lib", + "traits": [ + "default" + ], + "dependencies": [ + { + "identity": "xcframeworks", + "name": "ReactNative", + "url": "/home/me/app/ios/build/xcframeworks", + "version": "unspecified", + "path": "/home/me/app/ios/build/xcframeworks", + "traits": [ + "default" + ], + "dependencies": [] + }, + { + "identity": "ios", + "name": "React-GeneratedCode", + "url": "/home/me/app/ios/build/generated/ios", + "version": "unspecified", + "path": "/home/me/app/ios/build/generated/ios", + "traits": [ + "default" + ], + "dependencies": [] + } + ] + } + ] + }, + { + "identity": "unreached-lib", + "name": "UnreachedLib", + "url": "/home/me/app/node_modules/unreached-lib", + "version": "unspecified", + "path": "/home/me/app/node_modules/unreached-lib", + "traits": [ + "default" + ], + "dependencies": [] + } + ] +} diff --git a/tests/generate.test.ts b/tests/generate.test.ts index b6a03ae..4eced29 100644 --- a/tests/generate.test.ts +++ b/tests/generate.test.ts @@ -3,9 +3,10 @@ import { tmpdir } from "node:os"; import { join } from "node:path"; import { afterEach, describe, expect, it } from "vitest"; import { troubleshootingUrl } from "../src/docs.js"; -import { renderPackageSwift } from "../src/generate/packageSwift.js"; +import { appClangArgs, appSwiftArgs, renderPackageSwift } from "../src/generate/packageSwift.js"; import { renderXtoolYml } from "../src/generate/xtoolYml.js"; import { devSupportTemplatesDir, sceneDelegateClassNames, writeIosXtool } from "../src/generate/iosXtool.js"; +import { copyBareTarget } from "../src/generate/bareSources.js"; import { expoClangImporterInputs, type ClangImporterInputs } from "../src/generate/expoImporter.js"; import { IMPORTER_MARKER, scaffoldedImporterPaths } from "../src/generate/scaffoldImporter.js"; import { PODSPEC_FIXTURES, VENDORED_RN_SPM, scaffoldLibraries } from "./support/rnScaffold.js"; @@ -362,6 +363,41 @@ describe("renderPackageSwift", () => { }); }); +describe("the App target's compiler arguments", () => { + const app = { + mixed: true, bridgingHeader: "/p/App-Bridging-Header.h", defines: ["FOO=1", "BAR"], + headerSearchPaths: ["/p/include", "/p/hsp"], cxxStandard: "gnu++20", swiftHeadersDir: "/h", + }; + + it("gives the manifest's C and C++ flags as compiler arguments", () => { + expect(appClangArgs(app, undefined, true)).toEqual( + ["-DFOO=1", "-DBAR", "-I", "/p/include", "-I", "/p/hsp", "-I", app.swiftHeadersDir, "-std=gnu++20"], + ); + expect(appClangArgs(app, undefined, false)).toEqual( + ["-DFOO=1", "-DBAR", "-I", "/p/include", "-I", "/p/hsp", "-I", app.swiftHeadersDir], + ); + const clangImporter = { swiftHeadersDir: "/h", includeDirs: ["/e/include"], moduleMaps: ["/h/Expo.modulemap"] }; + expect(appClangArgs(app, expoInputs({ clangImporter }), false).slice(2)).toEqual([ + "-I", "/p/include", "-I", "/p/hsp", "-I", "/h", "-I", "/e/include", "-fmodule-map-file=/h/Expo.modulemap", "-F", "/p/ci", + ]); + expect(appClangArgs({ ...app, mixed: false }, undefined, true)).toEqual([]); + }); + + it("gives the Swift flags of a Debug build", () => { + const bare = appSwiftArgs(app, undefined); + expect(bare[0]).toBe("-DDEBUG"); + const at = bare.indexOf("-import-objc-header"); + expect(bare.slice(at, at + 4)).toEqual(["-import-objc-header", app.bridgingHeader, "-Xcc", "-I/p/include"]); + expect(bare).toContain("-DFOO=1"); + expect(bare).not.toContain("-DEXPO_CONFIGURATION_DEBUG"); + const expo = appSwiftArgs({ ...app, importerPaths: ["/i/one"] }, expoInputs()); + expect(expo).toContain("-DEXPO_CONFIGURATION_DEBUG"); + expect(expo.some((a) => a.includes("RELEASE"))).toBe(false); + expect(expo.slice(2, 4)).toEqual(["-F", "/p/ci"]); + expect(expo.slice(-2)).toEqual(["-Xcc", "-I/i/one"]); + }); +}); + describe("renderXtoolYml", () => { it("renders defaults", () => { const y = renderXtoolYml({ bundleIdentifier: "com.example.app" }); @@ -594,9 +630,10 @@ describe("writeIosXtool", () => { it("passes the Expo prebuild's bridging header to Swift", async () => { const header = `${DEFAULT_HEADER}#import "RNAppAuthAuthorizationFlowManager.h"\n`; const { paths, ctx } = await libApp(header); - await writeIosXtool(ctx); + const { origins } = await writeIosXtool(ctx); const copy = join(paths.sources, "LibApp-Bridging-Header.h"); expect(await readFile(copy, "utf8")).toBe(header); + expect(origins[copy]).toBe(join(ctx.project.iosTargetDir, "LibApp-Bridging-Header.h")); expect(await manifestOf(paths)).toContain(`.unsafeFlags(["-import-objc-header", "${copy}"]),`); }); @@ -817,6 +854,24 @@ describe("writeIosXtool", () => { expect(logs).toHaveLength(6); }); + it("returns the package input and the origins it generated", async () => { + const { app, paths, ctx } = await bareProject(); + const result = await writeIosXtool(ctx); + expect(result.pkg.app.headerSearchPaths[0]).toBe(join(paths.sources, "include")); + expect(result.pkg.iosDir).toBe(paths.ios); + expect(result.origins[join(paths.sources, "AppDelegate.swift")]).toBe(join(app, "AppDelegate.swift")); + expect(result.origins[join(paths.sources, "HelloWorld-Bridging-Header.h")]).toBe(join(app, "HelloWorld-Bridging-Header.h")); + + const expo = await expoProject("ios-target"); + const generated = await writeIosXtool(expo.ctx); + expect(generated.origins).toEqual({ + [join(expo.paths.sources, "AppDelegate.swift")]: join(expo.target, "AppDelegate.swift"), + [join(expo.paths.sources, "SceneDelegate.swift")]: join(expo.target, "SceneDelegate.swift"), + [join(expo.paths.sources, "ExpoModulesProvider.swift")]: join(expo.paths.expoDir, "ExpoModulesProvider.swift"), + }); + expect(generated.pkg.expo?.compileInterfacesDir).toBe(join(expo.paths.expoDir, "compile-interfaces")); + }); + it("writes a Swift-only bare target with the 6.0 manifest and drops a stale 6.5 one", async () => { // The pristine template: Swift sources only, no bridging header, no resources. const root = await mkdtemp(join(tmpdir(), "xt7-tpl-")); @@ -1037,6 +1092,29 @@ describe("writeIosXtool", () => { expect(await readFile(join(paths.sources, "AppMain.m"), "utf8")).toContain('#import "AppDelegate.h"'); }); + it("records where each copied file came from", async () => { + const root = await mkdtemp(join(tmpdir(), "xt7-origins-")); + tmps.push(root); + const ios = join(root, "ios"); + const sources = join(root, "ios-xtool", "Sources", "App"); + for (const rel of ["App/main.m", "App/AppDelegate.swift", "Shared/Theme.h"]) { + await mkdir(join(ios, rel, ".."), { recursive: true }); + await writeFile(join(ios, rel), "// code\n"); + } + const at = (relPath: string) => ({ absPath: join(ios, relPath), relPath }); + const bare = { + swiftSources: [at("App/AppDelegate.swift")], cSources: [at("App/main.m")], headers: [at("Shared/Theme.h")], + resources: [], skippedResources: [], defines: [], headerSearchPaths: [], ignoredSettings: [], + mixed: true, productModuleName: "App", + }; + const copied = await copyBareTarget(bare, ios, join(ios, "App"), sources, join(root, "ios-xtool", "Resources"), () => {}); + expect(copied.origins).toEqual({ + [join(sources, "AppDelegate.swift")]: join(ios, "App", "AppDelegate.swift"), + [join(sources, "AppMain.m")]: join(ios, "App", "main.m"), + [join(sources, "Shared", "Theme.h")]: join(ios, "Shared", "Theme.h"), + }); + }); + it("skips a header the project references but that does not exist, saying so", async () => { const { paths, ctx, logs } = await bareProject({ pbxproj: (src) => withMainGroupFile(src, "Gone.h") }); await writeIosXtool(ctx); diff --git a/tests/includeScan.test.ts b/tests/includeScan.test.ts new file mode 100644 index 0000000..375db58 --- /dev/null +++ b/tests/includeScan.test.ts @@ -0,0 +1,291 @@ +import { describe, expect, it } from "vitest"; +import { SWIFT_BUILD_DEFINES } from "../src/pipeline/precheckCommands.js"; +import { B1_DEFINES, definesOf, scanIncludes, type ScanEnv } from "../src/project/includeScan.js"; + +const env: ScanEnv = { defines: definesOf([]), hasInclude: () => undefined }; +const lines = (...l: string[]): string => l.join("\n"); +/** The spellings `scanIncludes` returns, with their certainty. */ +const found = (text: string, e: ScanEnv = env): [string, boolean][] => + scanIncludes(text, e).map((i) => [i.spelling, i.certain]); + +describe("scanIncludes", () => { + it("returns each include with its line and form", () => { + expect(scanIncludes(`#import "A.h"\n#include \n@import Foundation;\n`, env)).toEqual([ + { line: 1, spelling: "A.h", angle: false, certain: true }, + { line: 2, spelling: "B/C.h", angle: true, certain: true }, + ]); + }); + + it("drops includes in comments and under #if 0", () => { + const text = lines( + `// #import "X.h"`, + `/* a block comment`, + `#import "Y.h" */`, + `#if 0`, + `#import "Z.h"`, + `#endif`, + `#import "After.h"`, + ); + expect(scanIncludes(text, env)).toEqual([{ line: 7, spelling: "After.h", angle: false, certain: true }]); + }); + + it("follows #ifdef/#elif/#else with the known defines", () => { + expect(found(lines(`#if DEBUG`, `#import "Dbg.h"`, `#endif`))).toEqual([["Dbg.h", true]]); + expect(found(lines(`#ifdef SWIFT_PACKAGE`, `#import "Pkg.h"`, `#endif`))).toEqual([["Pkg.h", true]]); + expect(found(lines(`#if TARGET_OS_OSX`, `#import `, `#endif`))).toEqual([]); + expect( + found(lines(`#ifdef DEBUG`, `#import "Dbg.h"`, `#else`, `#import "Rel.h"`, `#endif`)), + ).toEqual([["Dbg.h", true]]); + const foo: ScanEnv = { defines: definesOf(["FOO=2"]), hasInclude: () => undefined }; + expect(found(lines(`#if FOO == 2`, `#import "Foo.h"`, `#endif`), foo)).toEqual([["Foo.h", true]]); + }); + + it("leaves a macro the generated App target does not define unknown", () => { + // Swift Build's App compile defines no RCT_NEW_ARCH_ENABLED: a branch on it is one B1 cannot evaluate. + expect(found(lines(`#ifdef RCT_NEW_ARCH_ENABLED`, `#import `, `#endif`))).toEqual([ + ["RNMyAppSpec/RNMyAppSpec.h", false], + ]); + expect(found(lines(`#if RCT_NEW_ARCH_ENABLED`, `#import "New.h"`, `#else`, `#import "Old.h"`, `#endif`))).toEqual([ + ["New.h", false], + ["Old.h", false], + ]); + // The App target's own define still counts. + const arch: ScanEnv = { defines: definesOf(["RCT_NEW_ARCH_ENABLED=1"]), hasInclude: () => undefined }; + expect(found(lines(`#ifdef RCT_NEW_ARCH_ENABLED`, `#import "New.h"`, `#endif`), arch)).toEqual([["New.h", true]]); + }); + + it("marks includes under a condition it cannot evaluate as uncertain", () => { + expect(found(lines(`#ifdef FB_SONARKIT_ENABLED`, `#import `, `#endif`))).toEqual([ + ["FlipperKit/FlipperClient.h", false], + ]); + expect(found(lines(`#if __has_include()`, `#import `, `#endif`))).toEqual([["X/Y.h", false]]); + expect(found(lines(`#if SOME_MACRO(1)`, `#import "M.h"`, `#endif`))).toEqual([["M.h", false]]); + expect( + found(lines(`#if UNKNOWN`, `#import "U.h"`, `#elif RCT_NEW_ARCH_ENABLED`, `#import "E.h"`, `#endif`)), + ).toEqual([ + ["U.h", false], + ["E.h", false], + ]); + expect(found(lines(`#if 0 && UNKNOWN`, `#import "No.h"`, `#endif`))).toEqual([]); + expect(found(lines(`#if 1 || UNKNOWN`, `#import "Yes.h"`, `#endif`))).toEqual([["Yes.h", true]]); + }); + + it("evaluates __has_include with the resolver", () => { + const text = lines( + `#if __has_include()`, + `#import `, + `#elif __has_include("RCTModuleProviders.h")`, + `#import "RCTModuleProviders.h"`, + `#endif`, + ); + const first: ScanEnv = { defines: definesOf([]), hasInclude: (s, angle) => angle && s.startsWith("ReactCodegen/") }; + expect(scanIncludes(text, first)).toEqual([ + { line: 2, spelling: "ReactCodegen/RCTModuleProviders.h", angle: true, certain: true }, + ]); + const none: ScanEnv = { defines: definesOf([]), hasInclude: () => false }; + expect(scanIncludes(text, none)).toEqual([]); + }); + + it("treats an include guard as taken", () => { + expect(found(lines(`#ifndef APP_H`, `#define APP_H`, `#import "B.h"`, `#endif`))).toEqual([["B.h", true]]); + expect(found(lines(`#pragma once`, `#import "B.h"`))).toEqual([["B.h", true]]); + }); + + it("does not report an include built from a macro", () => { + expect(scanIncludes(`#include MY_HEADER\n`, env)).toEqual([]); + }); + + it("reads CRLF, a BOM, spaced and continued directives", () => { + const text = + "\uFEFF" + + '#import "A.h"\r\n# import \r\n' + + '#if defined(DEBUG) && \\\r\n defined(SWIFT_PACKAGE)\r\n#import "C.h"\r\n#endif'; + expect(scanIncludes(text, env)).toEqual([ + { line: 1, spelling: "A.h", angle: false, certain: true }, + { line: 2, spelling: "B.h", angle: true, certain: true }, + { line: 5, spelling: "C.h", angle: false, certain: true }, + ]); + }); + + // Edges the brief leaves open. + + it("drops everything after an unterminated block comment", () => { + expect(found(lines(`#import "A.h"`, `/* never closed`, `#import "B.h"`))).toEqual([["A.h", true]]); + }); + + it("reads a directive after a comment on the same line, and an include with a trailing comment", () => { + expect(scanIncludes(lines(`/* lead */ #import "A.h" // why`, `#import /* note */`), env)).toEqual([ + { line: 1, spelling: "A.h", angle: false, certain: true }, + { line: 2, spelling: "B.h", angle: true, certain: true }, + ]); + }); + + it("drops the #else after a taken #if, and takes it after a false one", () => { + expect(found(lines(`#if 1`, `#import "T.h"`, `#else`, `#import "F.h"`, `#endif`))).toEqual([["T.h", true]]); + expect(found(lines(`#if 0`, `#import "T.h"`, `#else`, `#import "F.h"`, `#endif`))).toEqual([["F.h", true]]); + }); + + it("makes an #else after an unknown branch uncertain", () => { + expect(found(lines(`#ifdef UNKNOWN`, `#import "U.h"`, `#else`, `#import "E.h"`, `#endif`))).toEqual([ + ["U.h", false], + ["E.h", false], + ]); + }); + + it("ignores nested groups inside a false branch, even ones that would be taken", () => { + const text = lines( + `#if TARGET_OS_OSX`, + `#if 1`, + `#import "In.h"`, + `#else`, + `#import "Else.h"`, + `#endif`, + `#import "Out.h"`, + `#endif`, + `#import "After.h"`, + ); + expect(scanIncludes(text, env)).toEqual([{ line: 9, spelling: "After.h", angle: false, certain: true }]); + }); + + it("keeps an unknown outer group's includes uncertain even under a taken inner #if", () => { + expect(found(lines(`#ifdef UNKNOWN`, `#if 1`, `#import "In.h"`, `#endif`, `#endif`))).toEqual([["In.h", false]]); + }); + + it("follows an #elif chain to the first true branch only", () => { + const text = lines( + `#if TARGET_OS_OSX`, + `#import "Mac.h"`, + `#elif TARGET_OS_TV`, + `#import "TV.h"`, + `#elif TARGET_OS_IOS`, + `#import "IOS.h"`, + `#elif 1`, + `#import "Later.h"`, + `#else`, + `#import "Else.h"`, + `#endif`, + ); + expect(found(text)).toEqual([["IOS.h", true]]); + }); + + it("drops the branches after a true #elif that follows an unknown one", () => { + const text = lines( + `#if UNKNOWN`, + `#import "U.h"`, + `#elif 0`, + `#import "Zero.h"`, + `#elif 1`, + `#import "One.h"`, + `#else`, + `#import "Else.h"`, + `#endif`, + ); + expect(found(text)).toEqual([ + ["U.h", false], + ["One.h", false], + ]); + }); + + it("does not read #import inside a string literal, nor a comment opener inside one", () => { + const text = lines( + `NSString *s = @"#import \\"X.h\\" /* not a comment";`, + `const char *c = "// nor this";`, + `#import "Real.h"`, + ); + expect(scanIncludes(text, env)).toEqual([{ line: 3, spelling: "Real.h", angle: false, certain: true }]); + }); + + it("reads a digit separator as part of its number, not as a character literal", () => { + const text = lines( + `int n = 1'000; /* opens a comment`, + `#import "Hidden.h"`, + `*/`, + `char c = '"'; // "`, + `#import "Real.h"`, + ); + expect(found(text)).toEqual([["Real.h", true]]); + }); + + it("marks #include_next uncertain, and drops it in a false branch", () => { + expect(found(lines(`#include_next `, `#if 0`, `#include_next `, `#endif`))).toEqual([ + ["limits.h", false], + ]); + }); + + it("evaluates the three-valued operators", () => { + const at = (cond: string): [string, boolean][] => found(lines(`#if ${cond}`, `#import "C.h"`, `#endif`)); + expect(at(`UNKNOWN && 1`)).toEqual([["C.h", false]]); + expect(at(`UNKNOWN || 0`)).toEqual([["C.h", false]]); + expect(at(`!UNKNOWN`)).toEqual([["C.h", false]]); + expect(at(`!TARGET_OS_OSX && (DEBUG >= 1)`)).toEqual([["C.h", true]]); + expect(at(`TARGET_OS_IOS != 1 || TARGET_OS_TV`)).toEqual([]); + expect(at(`0x10 > 010 && 2 <= 2L`)).toEqual([["C.h", true]]); + expect(at(`defined DEBUG && !defined(TARGET_OS_OSX)`)).toEqual([]); + expect(at(`UNKNOWN == 1`)).toEqual([["C.h", false]]); + expect(at(`DEBUG + 1`)).toEqual([["C.h", false]]); + expect(at(``)).toEqual([["C.h", false]]); + expect(at(`__has_feature(objc_arc)`)).toEqual([["C.h", false]]); + }); + + it("does not trust a define the file itself changes", () => { + expect(found(lines(`#undef DEBUG`, `#ifdef DEBUG`, `#import "D.h"`, `#endif`))).toEqual([["D.h", false]]); + expect(found(lines(`#if 0`, `#undef DEBUG`, `#endif`, `#ifdef DEBUG`, `#import "D.h"`, `#endif`))).toEqual([ + ["D.h", true], + ]); + }); + + it("detects an include guard only as the file's first directive on an unknown name", () => { + expect(found(lines(`#import "A.h"`, `#ifndef APP_H`, `#define APP_H`, `#import "B.h"`, `#endif`))).toEqual([ + ["A.h", true], + ["B.h", false], + ]); + expect(found(lines(`#ifndef APP_H`, `#import "B.h"`, `#define APP_H`, `#endif`))).toEqual([["B.h", false]]); + expect(found(lines(`#ifndef DEBUG`, `#define DEBUG 1`, `#import "B.h"`, `#endif`))).toEqual([]); + }); +}); + +describe("definesOf", () => { + it("holds the compile's macros and the iOS values", () => { + expect([...B1_DEFINES]).toEqual([ + ["SWIFT_PACKAGE", "1"], + ["DEBUG", "1"], + ["TARGET_OS_MAC", "1"], + ["TARGET_OS_IPHONE", "1"], + ["TARGET_OS_IOS", "1"], + ["TARGET_OS_OSX", "0"], + ["TARGET_OS_MACCATALYST", "0"], + ["TARGET_OS_TV", "0"], + ["TARGET_OS_WATCH", "0"], + ["TARGET_OS_VISION", "0"], + ["TARGET_OS_SIMULATOR", "0"], + ]); + }); + + it("assumes exactly the macros every App compile of Swift Build gets", () => { + // A C-family file gets SWIFT_BUILD_DEFINES.clang, the bridging header through Swift's clang importer gets + // SWIFT_BUILD_DEFINES.importer: B1 assumes the macros both give, with the same value, and no other one. + const pairs = (list: readonly string[]) => + new Map(list.map((d) => (d.includes("=") ? [d.slice(0, d.indexOf("=")), d.slice(d.indexOf("=") + 1)] : [d, "1"]))); + const clang = pairs(SWIFT_BUILD_DEFINES.clang); + const importer = pairs(SWIFT_BUILD_DEFINES.importer); + const both = [...clang].filter(([k, v]) => importer.get(k) === v); + expect(both.length).toBeGreaterThan(0); + for (const [k, v] of both) expect(B1_DEFINES.get(k)).toBe(v); + const compileMacros = new Set([...clang.keys(), ...importer.keys()]); + const assumed = [...B1_DEFINES.keys()].filter((k) => !k.startsWith("TARGET_OS_")); + expect(assumed.filter((k) => !compileMacros.has(k))).toEqual([]); + expect(assumed.sort()).toEqual(both.map(([k]) => k).sort()); + expect(B1_DEFINES.has("RCT_NEW_ARCH_ENABLED")).toBe(false); + }); + + it("overlays the target's KEY and KEY=VALUE entries", () => { + const d = definesOf(["FOO", "BAR=2", "DEBUG=0", "EMPTY=", "$(inherited)"]); + expect(d.get("FOO")).toBe("1"); + expect(d.get("BAR")).toBe("2"); + expect(d.get("DEBUG")).toBe("0"); + expect(d.get("EMPTY")).toBe(""); + expect(d.has("$(inherited)")).toBe(false); + expect(d.get("TARGET_OS_IOS")).toBe("1"); + expect(B1_DEFINES.get("DEBUG")).toBe("1"); + }); +}); diff --git a/tests/precheck.test.ts b/tests/precheck.test.ts new file mode 100644 index 0000000..1b8927b --- /dev/null +++ b/tests/precheck.test.ts @@ -0,0 +1,783 @@ +import { cpSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { afterEach, describe, expect, it } from "vitest"; +import { writeIosXtool, type GeneratedApp } from "../src/generate/iosXtool.js"; +import { projectPaths, swiftHeadersDir, type ProjectPaths } from "../src/paths.js"; +import { runPrecheck, type PrecheckDeps } from "../src/pipeline/precheck.js"; +import { moduleCacheKey, precheckToolchain, type PrecheckToolchain } from "../src/pipeline/precheckCommands.js"; +import type { SwiftRunner } from "../src/pipeline/precheckGraph.js"; +import { PrecheckError } from "../src/pipeline/precheckReport.js"; +import { readProject } from "../src/project/index.js"; +import { objcApp } from "./support/objcApp.js"; + +const tmps: string[] = []; +afterEach(() => { + for (const d of tmps.splice(0)) rmSync(d, { recursive: true, force: true }); +}); + +const tempRoot = (): string => { + const root = realpathSync(mkdtempSync(path.join(tmpdir(), "xt-precheck-"))); + tmps.push(root); + return root; +}; + +const write = (file: string, text: string): void => { + mkdirSync(path.dirname(file), { recursive: true }); + writeFileSync(file, text); +}; + +/** A package of the fake graph: its regular targets, each with an `include` folder holding `headers`. */ +interface FakePackage { + name: string; + path: string; + /** `swift`: the target's folder holds a Swift file too (a mixed target). */ + targets: { name: string; headers: Record; swift?: boolean }[]; +} + +/** React Native's headers as the fake graph gives them: `` from a target named React. */ +function reactNative(root: string, extra: Record = {}): FakePackage { + return { + name: "ReactNative", + path: path.join(root, "ios", "build", "xcframeworks"), + targets: [{ name: "React", headers: { "React/RCTBundleURLProvider.h": "@interface RCTBundleURLProvider\n@end\n", ...extra } }], + }; +} + +/** Expo as the graph gives it: a target SwiftPM builds from Swift, with its clang half's headers. */ +function expoPackage(root: string): FakePackage { + return { name: "Expo", path: path.join(root, "expo"), targets: [{ name: "Expo", headers: { "Expo.h": "" }, swift: true }] }; +} + +/** + * SwiftPM as the precheck asks it: `describe` plans App as a library; `show-dependencies` lists `packages`; the root's + * App depends on every product of theirs (one per target). Each call is recorded by its subcommand. + */ +function fakeSwift(paths: ProjectPaths, packages: FakePackage[], calls: string[]): SwiftRunner { + for (const p of packages) { + for (const t of p.targets) { + mkdirSync(path.join(p.path, t.name, "include"), { recursive: true }); + for (const [rel, text] of Object.entries(t.headers)) write(path.join(p.path, t.name, "include", rel), text); + if (t.swift === true) write(path.join(p.path, t.name, `${t.name}.swift`), "public let x = 1\n"); + } + } + const json = (o: unknown) => ({ code: 0, stdout: JSON.stringify(o), stderr: "" }); + return async (args) => { + calls.push(args[1]!); + if (args[1] === "describe") return json({ name: "AppXtool", targets: [{ name: "App", type: "library" }] }); + if (args[1] === "show-dependencies") { + return json({ name: "appxtool", path: paths.iosXtool, dependencies: packages.map((p) => ({ name: p.name, path: p.path, dependencies: [] })) }); + } + const at = args[args.indexOf("--package-path") + 1]; + if (at === paths.iosXtool) { + return json({ + name: "AppXtool", + dependencies: packages.map((p) => ({ + fileSystem: [{ identity: path.basename(p.path).toLowerCase(), nameForTargetDependencyResolutionOnly: p.name, path: p.path }], + })), + products: [{ name: "App", targets: ["App"] }], + targets: [ + { + name: "App", + type: "regular", + path: "Sources/App", + dependencies: packages.flatMap((p) => p.targets.map((t) => ({ product: [t.name, p.name, null, null] }))), + }, + ], + }); + } + const p = packages.find((q) => q.path === at)!; + return json({ + name: p.name, + dependencies: [], + products: p.targets.map((t) => ({ name: t.name, targets: [t.name] })), + targets: p.targets.map((t) => ({ name: t.name, type: "regular", path: t.name, publicHeadersPath: "include", dependencies: [] })), + }); + }; +} + +/** + * An iPhoneOS SDK with UIKit and Foundation headers and the Swift standard library's module, and a clang whose + * `--version` names its InstalledDir, with `stdarg.h` in its resource headers (`installedDir: false`: no such line). + */ +function fakeToolchain(root: string, o: { installedDir?: boolean } = {}): PrecheckToolchain { + const sdk = path.join(root, "sdk", "iPhoneOS.sdk"); + for (const f of ["UIKit", "Foundation"]) write(path.join(sdk, "System", "Library", "Frameworks", `${f}.framework`, "Headers", `${f}.h`), ""); + mkdirSync(path.join(sdk, "usr", "lib", "swift", "Swift.swiftmodule"), { recursive: true }); + const bin = path.join(root, "toolchain", "usr", "bin"); + write(path.join(bin, "..", "lib", "clang", "21", "include", "stdarg.h"), ""); + const versions = o.installedDir === false ? "clang version 21.0.0\nSwift version 6.4.1" : `clang version 21.0.0\nInstalledDir: ${bin}\nSwift version 6.4.1`; + return { clang: "/t/bin/clang", swiftc: "/t/bin/swiftc", sdk, swiftResources: "/t/swift", swiftIncludes: [], swiftExtra: [], versions }; +} + +type Compiled = { tool: string; file: string; args: string[]; env: NodeJS.ProcessEnv }; + +interface Harness { + paths: ProjectPaths; + app: GeneratedApp; + logs: string[]; + calls: string[]; + compiled: Compiled[]; + run: (o?: { clean?: boolean; deps?: Partial; packages?: FakePackage[]; installedDir?: boolean }) => Promise; + dir: string; +} + +/** + * The precheck over `app` with fake SwiftPM, compilers and toolchain. `outputs(tool, file, n)` answers the n-th compile + * of a file (default: exit 0, no output); `calls` records the SwiftPM subcommands, then ` ` per compile. + */ +function harness( + paths: ProjectPaths, + app: GeneratedApp, + outputs: (tool: string, file: string, n: number, args: string[]) => { code: number; output: string } | undefined = () => undefined, +): Harness { + const logs: string[] = []; + const calls: string[] = []; + const compiled: Compiled[] = []; + const h: Harness = { + paths, + app, + logs, + calls, + compiled, + dir: path.join(paths.iosXtool, ".precheck"), + run: (o = {}) => + runPrecheck( + paths, + app, + { root: paths.root, rnVersion: "0.88.1", clean: o.clean ?? false, log: (s) => logs.push(s) }, + { + swift: fakeSwift(paths, o.packages ?? [reactNative(paths.root)], calls), + toolchain: async () => fakeToolchain(paths.root, { installedDir: o.installedDir }), + compile: async (cmd, args, opts) => { + const tool = path.basename(cmd); + const file = path.basename(args.at(-1)!); + const n = compiled.filter((c) => c.tool === tool && c.file === file).length; + compiled.push({ tool, file, args, env: opts.env }); + calls.push(`${tool} ${file}`); + return outputs(tool, file, n, args) ?? { code: 0, output: "" }; + }, + ...o.deps, + }, + ), + }; + return h; +} + +/** A hand-written bare app: `files` (relative to ios/App) copied into Sources/App, as generate copies a bare target. */ +function handApp(files: Record, o: { mixed?: boolean; bridgingHeader?: string } = {}): { paths: ProjectPaths; app: GeneratedApp } { + const root = tempRoot(); + const paths = projectPaths(root); + const origins: Record = {}; + for (const [rel, text] of Object.entries(files)) { + write(path.join(root, "ios", "App", rel), text); + write(path.join(paths.sources, rel), text); + origins[path.join(paths.sources, rel)] = path.join(root, "ios", "App", rel); + } + const app: GeneratedApp = { + pkg: { + iosDir: paths.ios, + frameworks: [], + iosMin: "16.4", + app: { + mixed: o.mixed ?? true, + defines: [], + headerSearchPaths: [], + swiftHeadersDir: swiftHeadersDir(paths.iosXtool), + ...(o.bridgingHeader !== undefined ? { bridgingHeader: path.join(paths.sources, o.bridgingHeader) } : {}), + }, + }, + origins, + }; + return { paths, app }; +} + +/** The project at `root` generated as `build` generates it. */ +async function generated(root: string): Promise<{ paths: ProjectPaths; app: GeneratedApp }> { + const project = await readProject(root); + const paths = projectPaths(root); + const app = await writeIosXtool({ project, paths, frameworks: [], metroPort: 8081, lanIp: "192.168.1.5", log: () => {} }); + return { paths, app }; +} + +const after = (args: string[], flag: string) => args.flatMap((a, n) => (a === flag ? [args[n + 1]] : [])); + +describe("runPrecheck", () => { + it("plans, reads the graph, then compiles Swift before the C family", async () => { + const { paths, app } = handApp({ + "AppDelegate.swift": "import UIKit\n@objc class Greeter: NSObject {}\n", + "Native.m": '#import "App-Swift.h"\n#import \n#include \n', + }); + const h = harness(paths, app, (tool, _file, _n, args) => { + // swiftc writes App-Swift.h where it is told to. + if (tool === "swiftc") write(after(args, "-emit-objc-header-path")[0]!, "// App\n"); + return undefined; + }); + await h.run(); + expect(h.calls).toEqual(["describe", "show-dependencies", "dump-package", "dump-package", "swiftc AppDelegate.swift", "clang Native.m"]); + expect(h.logs).toEqual([]); + // The synthesized module map of React's headers, the inputs and every command line are on disk. + expect(readFileSync(path.join(h.dir, "modulemaps", "React", "module.modulemap"), "utf8")).toContain("module React"); + expect(JSON.parse(readFileSync(path.join(h.dir, "inputs.json"), "utf8")).graph.targets).toEqual(["App", "React"]); + const log = readFileSync(path.join(h.dir, "precheck.log"), "utf8"); + expect(log).toContain("swift package describe --type json"); + expect(log).toContain(`/t/bin/clang -fno-color-diagnostics -fsyntax-only`); + expect(log).toContain(`/t/bin/swiftc -no-color-diagnostics -typecheck`); + // The compilers' temporary files go to .precheck/tmp, removed at the end. + expect(h.compiled.map((c) => c.env.TMPDIR)).toEqual([path.join(h.dir, "tmp"), path.join(h.dir, "tmp")]); + expect(existsSync(path.join(h.dir, "tmp"))).toBe(false); + }); + + it("stops on F3 in pass 2 before compiling", async () => { + const { paths, app } = await generated(objcApp("template")); + const h = harness(paths, app); + const err = await h.run().catch((e: unknown) => e); + expect(err).toBeInstanceOf(PrecheckError); + expect((err as Error).message).toContain("all of them in ios-xtool/.precheck/precheck.log"); + expect(h.logs).toEqual([ + expect.stringMatching( + /^✖ precheck — ios\/ObjcApp\/AppDelegate\.h:7 imports RCTAppDelegate\.h, which is in none of the App target's \d+ include folders \(listed in ios-xtool\/\.precheck\/precheck\.log\)$/, + ), + ]); + expect(h.compiled).toEqual([]); + const log = readFileSync(path.join(h.dir, "precheck.log"), "utf8"); + expect(log).toContain(path.join(paths.root, "ios", "build", "xcframeworks", "React", "include")); + }); + + it("leaves a miss under a graph target to the compile", async () => { + const { paths, app } = handApp({ "Native.m": "#import \n#import \n" }); + const h = harness(paths, app); + const codegen: FakePackage = { name: "React-GeneratedCode", path: path.join(paths.root, "ios", "build", "generated", "ios"), targets: [{ name: "ReactCodegen", headers: {} }] }; + await h.run({ packages: [reactNative(paths.root), codegen] }); + expect(h.logs).toEqual([ + "⚠ precheck — ios/App/Native.m:1 imports ReactCodegen/RCTModuleProviders.h, which rn-xtool did not find; ReactCodegen is a target of the package, so the compile decides", + ]); + expect(h.calls.filter((c) => c.startsWith("clang"))).toEqual(["clang Native.m"]); + }); + + it("skips Swift that imports a module SwiftPM builds", async () => { + const { paths, app } = handApp({ + "AppDelegate.swift": "import UIKit\n@preconcurrency import Expo\n", + "Bridge.m": '#import "Bridge.h"\n', + "Bridge.h": '#import "App-Swift.h"\n', + "Plain.m": "#import \n", + }); + const h = harness(paths, app); + await h.run({ packages: [reactNative(paths.root), expoPackage(paths.root)] }); + expect(h.logs).toEqual([ + "ℹ precheck — ios/App/AppDelegate.swift imports Expo, which SwiftPM builds: checked by xtool-build", + "ℹ precheck — ios/App/Bridge.m import App-Swift.h, which the Swift check did not write: checked by xtool-build", + ]); + expect(h.calls.filter((c) => !["describe", "show-dependencies", "dump-package"].includes(c))).toEqual(["clang Plain.m"]); + }); + + it("skips Swift that imports a mixed module of the graph", async () => { + const { paths, app } = handApp({ "AppDelegate.swift": "import UIKit\nimport MixedLib\n", "Plain.m": "#import \n" }); + const h = harness(paths, app); + const mixed: FakePackage = { name: "MixedLib", path: path.join(paths.root, "mixed"), targets: [{ name: "MixedLib", headers: { "MixedLib.h": "" }, swift: true }] }; + await h.run({ packages: [reactNative(paths.root), mixed] }); + expect(h.logs).toEqual(["ℹ precheck — ios/App/AppDelegate.swift imports MixedLib, which SwiftPM builds: checked by xtool-build"]); + expect(h.calls.filter((c) => c.startsWith("swiftc") || c.startsWith("clang"))).toEqual(["clang Plain.m"]); + }); + + it("says a Swift import of an SDK module without a framework is in no map", async () => { + const { paths, app } = handApp({ "AppDelegate.swift": "import UIKit\nimport CommonCrypto\n", "Plain.m": "#import \n" }); + // CommonCrypto as the SDK ships it: a clang module under usr/include, no framework folder, no .swiftmodule. + const sdk = path.join(paths.root, "sdk", "iPhoneOS.sdk"); + write(path.join(sdk, "usr", "include", "CommonCrypto", "module.modulemap"), 'module CommonCrypto { header "CommonCrypto.h" }\n'); + write(path.join(sdk, "usr", "include", "CommonCrypto", "CommonCrypto.h"), ""); + const h = harness(paths, app); + await h.run(); + expect(h.logs).toEqual([ + "ℹ precheck — ios/App/AppDelegate.swift imports CommonCrypto, which no module map of the package graph declares: checked by xtool-build", + ]); + expect(h.calls.filter((c) => c.startsWith("swiftc") || c.startsWith("clang"))).toEqual(["clang Plain.m"]); + }); + + it("skips a C-family file that imports a Swift-built module or one no map declares", async () => { + const { paths, app } = handApp({ + "A.m": "@import MixedLib;\n", + "X.m": '#import "Bridge.h"\n', + "Bridge.h": "@import Nowhere.Sub;\n", + "Also.m": "@import Nowhere;\n", + "Sdk.m": "@import UIKit;\n@import React;\n", + }); + const h = harness(paths, app); + const mixed: FakePackage = { name: "MixedLib", path: path.join(paths.root, "mixed"), targets: [{ name: "MixedLib", headers: { "MixedLib.h": "" }, swift: true }] }; + await h.run({ packages: [reactNative(paths.root), mixed] }); + expect(h.logs).toEqual([ + "ℹ precheck — ios/App/A.m imports the module MixedLib, which SwiftPM builds; checked by xtool-build", + "ℹ precheck — ios/App/X.m imports the module Nowhere, which no module map of the package graph declares; checked by xtool-build", + ]); + // An SDK framework and a module of the graph's maps compile; every skipped file is in the log. + expect(h.calls.filter((c) => c.startsWith("clang"))).toEqual(["clang Sdk.m"]); + expect(readFileSync(path.join(h.dir, "precheck.log"), "utf8")).toContain( + `# not compiled, imports the module Nowhere: ${path.join(paths.sources, "X.m")} ${path.join(paths.sources, "Also.m")}`, + ); + }); + + it("skips Swift when its bridging header imports a Swift-built module", async () => { + const { paths, app } = handApp( + { "AppDelegate.swift": "import UIKit\n", "Bridging.h": "@import MixedLib;\n" }, + { mixed: false, bridgingHeader: "Bridging.h" }, + ); + const h = harness(paths, app); + const mixed: FakePackage = { name: "MixedLib", path: path.join(paths.root, "mixed"), targets: [{ name: "MixedLib", headers: { "MixedLib.h": "" }, swift: true }] }; + await h.run({ packages: [reactNative(paths.root), mixed] }); + expect(h.logs).toEqual([ + "ℹ precheck — ios/App/Bridging.h imports the module MixedLib, which SwiftPM builds; checked by xtool-build", + "ℹ precheck — ios/App/Bridging.h imports MixedLib, which SwiftPM builds: checked by xtool-build", + ]); + expect(h.compiled).toEqual([]); + + // A module no map declares (an SDK module such as CommonCrypto, which has no framework) is not one SwiftPM builds. + const sdk = handApp({ "AppDelegate.swift": "import UIKit\n", "Bridging.h": "@import CommonCrypto;\n" }, { mixed: false, bridgingHeader: "Bridging.h" }); + const c = harness(sdk.paths, sdk.app); + await c.run(); + expect(c.logs).toEqual([ + "ℹ precheck — ios/App/Bridging.h imports the module CommonCrypto, which no module map of the package graph declares; checked by xtool-build", + "ℹ precheck — ios/App/Bridging.h imports CommonCrypto, which no module map of the package graph declares: checked by xtool-build", + ]); + expect(c.compiled).toEqual([]); + }); + + it("reads every import of a line with several", async () => { + const { paths, app } = handApp({ "AppDelegate.swift": "import UIKit; import Expo\n", "Plain.m": "#import \n" }); + const h = harness(paths, app); + await h.run({ packages: [reactNative(paths.root), expoPackage(paths.root)] }); + expect(h.logs).toEqual(["ℹ precheck — ios/App/AppDelegate.swift imports Expo, which SwiftPM builds: checked by xtool-build"]); + expect(h.calls.filter((c) => c.startsWith("swiftc"))).toEqual([]); + }); + + it("counts a header error several files report once", async () => { + const { paths, app } = handApp({ "A.m": '#import "Shared.h"\n', "B.m": '#import "Shared.h"\n', "Shared.h": "int x\n" }); + const shared = path.join(paths.sources, "Shared.h"); + const h = harness(paths, app, (_tool, file) => { + const from = path.join(paths.sources, file); + return { code: 1, output: `In file included from ${from}:1:\n${shared}:1:6: error: expected ';' after top level declarator\n1 error generated.\n` }; + }); + const err = await h.run().catch((e: unknown) => e); + expect((err as Error).message).toMatch(/^precheck: 1 error\(s\) /); + expect(h.logs).toEqual([ + "✖ precheck — ios/App/Shared.h:1: expected ';' after top level declarator", + " In file included from ios/App/A.m:1:", + ]); + }); + + it("runs no swiftc for a target without Swift files", async () => { + const { paths, app } = await generated(objcApp("template")); + const h = harness(paths, app); + await h.run({ packages: [reactNative(paths.root, { "RCTAppDelegate.h": "@interface RCTAppDelegate\n@end\n" })] }); + expect(h.logs).toEqual([]); + expect(h.calls.filter((c) => c.startsWith("swiftc"))).toEqual([]); + expect(h.calls.filter((c) => c.startsWith("clang")).sort()).toEqual(["clang AppDelegate.mm", "clang AppMain.m"]); + }); + + it("runs no clang for a Swift-only target", async () => { + const root = tempRoot(); + cpSync(path.join(import.meta.dirname, "fixtures", "bare"), root, { recursive: true }); + write(path.join(root, "node_modules", "react-native", "package.json"), JSON.stringify({ name: "react-native", version: "0.88.1" })); + const { paths, app } = await generated(root); + expect(app.pkg.app.bridgingHeader).toBeUndefined(); + const h = harness(paths, app); + // The template's imports: React, React_RCTAppDelegate and ReactAppDependencyProvider are modules of the graph. + const rn = reactNative(paths.root); + rn.targets.push({ name: "React_RCTAppDelegate", headers: {} }, { name: "ReactAppDependencyProvider", headers: {} }); + await h.run({ packages: [rn] }); + expect(h.logs).toEqual([]); + expect(h.calls.filter((c) => c.startsWith("clang"))).toEqual([]); + expect(h.calls.filter((c) => c.startsWith("swiftc"))).toEqual(["swiftc SceneDelegate.swift"]); + }); + + it("retries once without a stale module cache", async () => { + const { paths, app } = handApp({ "Native.m": "#import \n" }); + const cache = path.join(paths.iosXtool, ".precheck", "ModuleCache", moduleCacheKey("0.88.1", fakeToolchain(paths.root).versions)); + const stale = "fatal error: module file '/c/UIKit.pcm' is out of date and needs to be rebuilt"; + const seen: boolean[] = []; + const h = harness(paths, app, (_tool, _file, n) => { + seen.push(existsSync(cache)); + if (n === 0) { + mkdirSync(cache, { recursive: true }); + return { code: 1, output: `${stale}\n1 error generated.\n` }; + } + return undefined; + }); + await h.run(); + expect(seen).toEqual([false, false]); + expect(h.logs).toEqual([`ℹ precheck — the module cache was stale (${stale}); checked again without it`]); + expect(h.calls.filter((c) => c.startsWith("clang"))).toEqual(["clang Native.m", "clang Native.m"]); + }); + + it("prints errors only and names the log", async () => { + const { paths, app } = handApp({ "Native.m": "#import \n" }); + const file = path.join(paths.sources, "Native.m"); + const output = [ + `${file}:3:1: warning: unused variable 'x' [-Wunused-variable]`, + `${file}:5:2: error: use of undeclared identifier 'y'`, + `${file}:7:2: error: expected ';' after expression`, + "1 warning and 2 errors generated.", + ].join("\n"); + const h = harness(paths, app, () => ({ code: 1, output })); + const err = await h.run().catch((e: unknown) => e); + expect(err).toBeInstanceOf(PrecheckError); + expect((err as Error).message).toMatch(/^precheck: 2 error\(s\) .* all of them in ios-xtool\/\.precheck\/precheck\.log\)/); + expect(h.logs).toEqual([ + "✖ precheck — ios/App/Native.m:5: use of undeclared identifier 'y'", + "✖ precheck — ios/App/Native.m:7: expected ';' after expression", + ]); + expect(readFileSync(path.join(paths.iosXtool, ".precheck", "precheck.log"), "utf8")).toContain("warning: unused variable 'x'"); + }); + + it("empties the module cache on --clean", async () => { + const { paths, app } = handApp({ "Native.m": "#import \n" }); + const moduleCache = path.join(paths.iosXtool, ".precheck", "ModuleCache"); + const current = path.join(moduleCache, moduleCacheKey("0.88.1", fakeToolchain(paths.root).versions)); + const other = path.join(moduleCache, "rn0.88.0-000000000000"); + const fake = fakeToolchain(paths.root); + const runWith = async (clean: boolean) => { + for (const d of [current, other]) mkdirSync(d, { recursive: true }); + let atToolchain = true; + await harness(paths, app).run({ + clean, + deps: { + toolchain: async () => { + atToolchain = existsSync(moduleCache); + return fake; + }, + }, + }); + return atToolchain; + }; + expect(await runWith(true)).toBe(false); + // Without --clean the current key's cache stays; another key's goes. + expect(await runWith(false)).toBe(true); + expect(existsSync(current)).toBe(true); + expect(existsSync(other)).toBe(false); + }); + + it("names the dependencies the graph could not place, and goes on", async () => { + const { paths, app } = handApp({ "Native.m": "#import \n" }); + const h = harness(paths, app); + const swift = fakeSwift(paths, [reactNative(paths.root)], []); + await h.run({ + deps: { + swift: async (args, opts) => { + const r = await swift(args, opts); + if (args[1] !== "dump-package" || args[args.indexOf("--package-path") + 1] !== paths.iosXtool) return r; + const root = JSON.parse(r.stdout); + root.targets[0].dependencies.push({ product: ["Gone", "Nowhere", null, null] }); + return { ...r, stdout: JSON.stringify(root) }; + }, + }, + }); + expect(h.logs).toEqual(["ℹ precheck — 1 dependencies of App could not be placed (Gone of Nowhere): checked by xtool-build"]); + expect(h.calls).toEqual(["clang Native.m"]); + }); + + it("copies the module maps Swift Build wrote and drops the missing ones", async () => { + const { paths, app } = handApp({ "Bridging.h": "#import \n", "AppDelegate.swift": "import Expo\n" }, { mixed: false, bridgingHeader: "Bridging.h" }); + const built = swiftHeadersDir(paths.iosXtool); + write(path.join(built, "ExpoModulesCore.modulemap"), "module ExpoModulesCore {}\n"); + app.pkg.expo = { + compileInterfacesDir: path.join(paths.expoDir, "compile-interfaces"), + jsiHeaders: true, + clangImporter: { + swiftHeadersDir: built, + includeDirs: [], + moduleMaps: [path.join(built, "ExpoModulesCore.modulemap"), path.join(built, "ExpoCamera.modulemap")], + }, + }; + const h = harness(paths, app); + await h.run({ packages: [reactNative(paths.root), expoPackage(paths.root)] }); + const dir = path.join(paths.iosXtool, ".precheck", "swift-headers"); + expect(h.logs).toEqual([ + "ℹ precheck — ios/App/AppDelegate.swift imports Expo, which SwiftPM builds: checked by xtool-build", + "ℹ precheck — 1 module maps Swift Build writes are not there yet: files that need them are checked by xtool-build", + ]); + // The bridging header of a skipped Swift check is compiled by clang alone, with the copied map only. + expect(h.calls.filter((c) => c.startsWith("clang"))).toEqual(["clang Bridging.h"]); + const maps = h.compiled[0]!.args.filter((a) => a.startsWith("-fmodule-map-file=")); + expect(maps).toContain(`-fmodule-map-file=${path.join(dir, "ExpoModulesCore.modulemap")}`); + expect(maps.some((m) => m.includes("ExpoCamera"))).toBe(false); + expect(readFileSync(path.join(dir, "ExpoModulesCore.modulemap"), "utf8")).toBe("module ExpoModulesCore {}\n"); + }); + + it("keeps the copied module maps' headers where Swift Build wrote them", async () => { + const { paths, app } = handApp({ "X.m": "#import \n" }); + const built = swiftHeadersDir(paths.iosXtool); + const maps = { + ExpoUI: path.join(built, "ExpoUI.modulemap"), + Folder: path.join(built, "Nested", "Folder.modulemap"), + AppUse: path.join(built, "AppUse.modulemap"), + }; + write(path.join(built, "ExpoUI-Swift.h"), "// ExpoUI\n"); + write(maps.ExpoUI, 'module ExpoUI {\n header "ExpoUI-Swift.h"\n requires objc\n}\n'); + write( + maps.Folder, + 'module Folder [system] {\n umbrella "."\n private header "../Priv.h"\n textual header "T.h"\n exclude header "E.h"\n' + + ' umbrella header "/abs/Folder.h"\n extern module Ext "ext.modulemap"\n link "Folder"\n module * { export * }\n}\n', + ); + write(maps.AppUse, 'module AppUse {\n header "App-Swift.h"\n}\n'); + app.pkg.expo = { + compileInterfacesDir: path.join(paths.expoDir, "compile-interfaces"), + jsiHeaders: true, + clangImporter: { swiftHeadersDir: built, includeDirs: [], moduleMaps: Object.values(maps) }, + }; + await harness(paths, app).run(); + const copies = path.join(paths.iosXtool, ".precheck", "swift-headers"); + const copy = (rel: string) => readFileSync(path.join(copies, rel), "utf8"); + // A relative header names Swift Build's file, which the copy's folder does not hold. + expect(copy("ExpoUI.modulemap")).toBe(`module ExpoUI {\n header "${path.join(built, "ExpoUI-Swift.h")}"\n requires objc\n}\n`); + expect(existsSync(path.join(built, "ExpoUI-Swift.h"))).toBe(true); + // Every path form is rewritten against the map's own folder; absolute paths, `link` and the rest stay as they are. + const nested = path.join(built, "Nested"); + expect(copy(path.join("Nested", "Folder.modulemap"))).toBe( + `module Folder [system] {\n umbrella "${nested}"\n private header "${path.join(built, "Priv.h")}"\n` + + ` textual header "${path.join(nested, "T.h")}"\n exclude header "${path.join(nested, "E.h")}"\n` + + ` umbrella header "/abs/Folder.h"\n extern module Ext "${path.join(nested, "ext.modulemap")}"\n link "Folder"\n` + + " module * { export * }\n}\n", + ); + // The App's own Swift header is the one the precheck writes. + expect(copy("AppUse.modulemap")).toBe(`module AppUse {\n header "${path.join(copies, "App-Swift.h")}"\n}\n`); + }); + + it("names Swift Build's module map once it is there, the synthesized one before", async () => { + const { paths, app } = handApp({ "X.m": "#import \n" }); + const built = swiftHeadersDir(paths.iosXtool); + app.pkg.expo = { + compileInterfacesDir: path.join(paths.expoDir, "compile-interfaces"), + jsiHeaders: true, + clangImporter: { swiftHeadersDir: built, includeDirs: [], moduleMaps: [path.join(built, "React.modulemap")] }, + }; + const dir = path.join(paths.iosXtool, ".precheck"); + const synthesized = `-fmodule-map-file=${path.join(dir, "modulemaps", "React", "module.modulemap")}`; + const copied = `-fmodule-map-file=${path.join(dir, "swift-headers", "React.modulemap")}`; + const maps = (h: Harness) => h.compiled[0]!.args.filter((a) => a.startsWith("-fmodule-map-file=")); + + const before = harness(paths, app); + await before.run(); + expect(maps(before)).toEqual([synthesized]); + + write(path.join(built, "React.modulemap"), "module React {}\n"); + const after = harness(paths, app); + await after.run(); + expect(maps(after)).toEqual([copied]); + }); + + it("leaves an angle miss to the compile when clang's own headers cannot be found", async () => { + const { paths, app } = await generated(objcApp("template")); + const h = harness(paths, app); + await h.run({ installedDir: false }); + expect(h.logs).toEqual([ + "⚠ precheck — ios/ObjcApp/AppDelegate.h:7 imports RCTAppDelegate.h, which rn-xtool did not find; the compile decides", + ]); + expect(h.calls.filter((c) => c.startsWith("clang")).sort()).toEqual(["clang AppDelegate.mm", "clang AppMain.m"]); + }); + + it("leaves a file that imports a module whose map is not there yet to xtool-build", async () => { + const { paths, app } = handApp({ "X.m": '#import "Bridge.h"\n', "Bridge.h": "@import Expo;\n", "Y.m": "#import \n" }); + const built = swiftHeadersDir(paths.iosXtool); + app.pkg.expo = { + compileInterfacesDir: path.join(paths.expoDir, "compile-interfaces"), + jsiHeaders: true, + clangImporter: { swiftHeadersDir: built, includeDirs: [], moduleMaps: [path.join(built, "Expo.modulemap")] }, + }; + const h = harness(paths, app); + await h.run(); + expect(h.logs).toEqual([ + "ℹ precheck — 1 module maps Swift Build writes are not there yet: ios/App/X.m are checked by xtool-build", + ]); + expect(h.calls.filter((c) => c.startsWith("clang"))).toEqual(["clang Y.m"]); + expect(h.compiled[0]!.args.some((a) => a.includes("Expo.modulemap"))).toBe(false); + }); + + it("leaves Swift to xtool-build when its bridging header waits for a module map", async () => { + const { paths, app } = handApp( + { "AppDelegate.swift": "import UIKit\n", "Bridging.h": "@import Expo;\n" }, + { mixed: false, bridgingHeader: "Bridging.h" }, + ); + const built = swiftHeadersDir(paths.iosXtool); + app.pkg.expo = { + compileInterfacesDir: path.join(paths.expoDir, "compile-interfaces"), + jsiHeaders: true, + clangImporter: { swiftHeadersDir: built, includeDirs: [], moduleMaps: [path.join(built, "Expo.modulemap")] }, + }; + const h = harness(paths, app); + await h.run(); + expect(h.logs).toEqual([ + "ℹ precheck — 1 module maps Swift Build writes are not there yet: ios/App/Bridging.h, ios/App/AppDelegate.swift are checked by xtool-build", + ]); + expect(h.compiled).toEqual([]); + }); + + it("does not stop on a header nothing compiles", async () => { + const { paths, app } = handApp({ "Native.m": "#import \n", "Orphan.h": '#import "Nope.h"\n' }); + const h = harness(paths, app); + await h.run(); + expect(h.logs).toEqual([ + "⚠ precheck — ios/App/Orphan.h:1 imports Nope.h, which nothing compiles; checked by xtool-build if it is ever included", + ]); + expect(h.calls.filter((c) => c.startsWith("clang"))).toEqual(["clang Native.m"]); + }); + + it("resolves each file's includes in the order of the compile that reads it", async () => { + // Shared.h is both in the app's own folder (a search path of the target) and in React's headers. + const files = { + "Native.m": '#import "Shared.h"\n#import \n', + "Bridging.h": '#import "Shared.h"\n', + "Fwd/Shared.h": '#import "AppOnly.h"\n', + }; + const shared = { "Shared.h": "#import \n" }; + const withFwd = (o: { bridgingHeader?: string }) => { + const { paths, app } = handApp(files, o); + app.pkg.app.headerSearchPaths = [path.join(paths.sources, "Fwd")]; + return { paths, app }; + }; + + // clang searches the graph's folders before the target's own (Swift Build's order): Native.m reads React's copy. + const objc = withFwd({}); + const h = harness(objc.paths, objc.app); + await h.run({ packages: [reactNative(objc.paths.root, shared)] }); + expect(h.logs).toEqual([ + "⚠ precheck — ios/App/Fwd/Shared.h:1 imports AppOnly.h, which nothing compiles; checked by xtool-build if it is ever included", + ]); + expect(h.calls.filter((c) => c.startsWith("clang"))).toEqual(["clang Native.m"]); + + // Swift's clang importer searches the target's folders first: the bridging header reads the app's copy. + const bridged = withFwd({ bridgingHeader: "Bridging.h" }); + const b = harness(bridged.paths, bridged.app); + await expect(b.run({ packages: [reactNative(bridged.paths.root, shared)] })).rejects.toThrow(/^precheck: 1 error\(s\)/); + expect(b.logs).toEqual([ + expect.stringMatching( + /^✖ precheck — ios\/App\/Fwd\/Shared\.h:1 imports AppOnly\.h, which is in none of the App target's \d+ include folders \(listed in ios-xtool\/\.precheck\/precheck\.log\)$/, + ), + ]); + const log = readFileSync(path.join(b.dir, "precheck.log"), "utf8"); + expect(log).toContain("# pass 2: ios/App/Native.m searches"); + expect(log).toContain("# pass 2: ios/App/Bridging.h searches"); + }); + + it("tells a header both compiles reach once, with the most severe verdict", async () => { + // Native.m (the target's order) reaches Fwd/Shared.h only under a condition the precheck cannot evaluate, and its + // "Shared.h" is React's copy; the bridging header (the importer's order) surely reads the app's Fwd/Shared.h. + const { paths, app } = handApp( + { + "Native.m": '#import "Shared.h"\n#ifdef SOME_FLAG\n#import "Fwd/Shared.h"\n#endif\n#import \n', + "Bridging.h": '#import "Shared.h"\n', + "Fwd/Shared.h": '#import "AppOnly.h"\n', + }, + { bridgingHeader: "Bridging.h" }, + ); + app.pkg.app.headerSearchPaths = [path.join(paths.sources, "Fwd")]; + const h = harness(paths, app); + await expect(h.run({ packages: [reactNative(paths.root, { "Shared.h": "#import \n" })] })).rejects.toThrow(/^precheck: 1 error\(s\)/); + const log = readFileSync(path.join(h.dir, "precheck.log"), "utf8"); + const count = (root: string) => Number(new RegExp(`# pass 2: ${root} searches (\\d+) include folders`).exec(log)?.[1]); + // Both compiles judge the include: the target's as uncertain, the importer's as a miss. + expect(count("ios/App/Native\\.m")).toBeGreaterThan(0); + expect(h.logs).toEqual([ + `✖ precheck — ios/App/Fwd/Shared.h:1 imports AppOnly.h, which is in none of the App target's ${count("ios/App/Bridging\\.h")} include folders (listed in ios-xtool/.precheck/precheck.log)`, + ]); + expect(h.compiled).toEqual([]); + }); + + it("does not stop on a header only an uncertain condition includes", async () => { + const { paths, app } = handApp({ + "Native.m": '#if __has_include()\n#import "Opt.h"\n#endif\n#import \n', + "Opt.h": "#import \n", + }); + const h = harness(paths, app); + await h.run(); + expect(h.logs).toEqual([ + "⚠ precheck — ios/App/Opt.h:1 imports Missing/Missing.h, which only a condition the precheck cannot evaluate includes; the compile decides", + ]); + expect(h.calls.filter((c) => c.startsWith("clang"))).toEqual(["clang Native.m"]); + }); + + it("names the exit on a stop it did not plan", async () => { + const exit = "; if xtool-build builds this app, build with rn-xtool build --skip-precheck and report it with rn-xtool doctor --report"; + const { paths, app } = handApp({ "Native.m": "#import \n" }); + const thrown = await harness(paths, app) + .run({ deps: { swift: async () => { throw new Error("ENOSPC: no space left on device, write"); } } }) + .catch((e: unknown) => e); + expect(thrown).toBeInstanceOf(PrecheckError); + expect((thrown as Error).message).toBe(`ENOSPC: no space left on device, write${exit}`); + // The log keeps the original message. + expect(readFileSync(path.join(paths.iosXtool, ".precheck", "precheck.log"), "utf8")).toContain( + "# stopped: ENOSPC: no space left on device, write\n", + ); + + // rn-xtool's own reading of SwiftPM's answers is not certain either. + const unread = await harness(paths, app) + .run({ deps: { swift: async () => ({ code: 1, stdout: "", stderr: "error: boom" }) } }) + .catch((e: unknown) => e); + expect((unread as Error).message).toBe(`precheck — SwiftPM refused the generated package (ios-xtool/Package.swift):\nerror: boom${exit}`); + + // A missing toolchain fails xtool-build the same way: its line names rn-xtool setup only. + const noClang = await harness(paths, app) + .run({ deps: { toolchain: () => precheckToolchain({ PATH: "" }) } }) + .catch((e: unknown) => e); + expect(noClang).toBeInstanceOf(PrecheckError); + expect((noClang as Error).message).toBe("precheck — clang was not found on the Swift toolchain's PATH; run rn-xtool setup"); + + // A stop that names the exit already keeps its message. + const stop = await harness(paths, app, () => ({ code: 1, output: "error: x" })) + .run() + .catch((e: unknown) => e); + expect((stop as Error).message).toMatch(/^precheck: 1 error\(s\) .*--skip-precheck and report it with rn-xtool doctor --report$/); + }); + + it("names the exit when the log cannot be written", async () => { + const exit = "; if xtool-build builds this app, build with rn-xtool build --skip-precheck and report it with rn-xtool doctor --report"; + const full = (): never => { + throw new Error("ENOSPC: no space left on device, write"); + }; + const { paths, app } = handApp({ "Native.m": "#import \n" }); + + // The log write fails first (the disk fills): the stop line cannot be logged either. + const appendFails = await harness(paths, app) + .run({ deps: { logWriter: () => full } }) + .catch((e: unknown) => e); + expect(appendFails).toBeInstanceOf(PrecheckError); + expect((appendFails as Error).message).toBe(`ENOSPC: no space left on device, write${exit}`); + + // The log cannot be opened at all. + const openFails = await harness(paths, app) + .run({ deps: { logWriter: full } }) + .catch((e: unknown) => e); + expect((openFails as Error).message).toBe(`ENOSPC: no space left on device, write${exit}`); + + // Its folder cannot be made: ios-xtool/.precheck is a file. + rmSync(path.join(paths.iosXtool, ".precheck"), { recursive: true, force: true }); + writeFileSync(path.join(paths.iosXtool, ".precheck"), ""); + const mkdirFails = await harness(paths, app) + .run() + .catch((e: unknown) => e); + expect(mkdirFails).toBeInstanceOf(PrecheckError); + expect((mkdirFails as Error).message).toMatch(new RegExp(`${exit.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}$`)); + }); + + it("shows the errors and the stop when the log fails while they are reported", async () => { + const { paths, app } = handApp({ "Native.m": "#import \n" }); + const logged: string[] = []; + const writer = () => (text: string) => { + if (text.startsWith("✖") || text.startsWith("# stopped")) throw new Error("ENOSPC: no space left on device, write"); + logged.push(text); + }; + const h = harness(paths, app, () => ({ code: 1, output: `${path.join(paths.sources, "Native.m")}:1:2: error: boom\n` })); + const thrown = await h.run({ deps: { logWriter: writer } }).catch((e: unknown) => e); + expect(h.logs).toEqual(["✖ precheck — ios/App/Native.m:1: boom"]); + expect((thrown as Error).message).toMatch(/^precheck: 1 error\(s\) .*--skip-precheck and report it with rn-xtool doctor --report$/); + }); + + it("names a compiler that fails without a diagnostic", async () => { + const { paths, app } = handApp({ "Native.m": "#import \n" }); + const lines = Array.from({ length: 25 }, (_, n) => `line ${n + 1}`); + const h = harness(paths, app, () => ({ code: 139, output: lines.join("\n") })); + await expect(h.run()).rejects.toThrow(/^precheck: 1 error\(s\)/); + expect(h.logs).toEqual([ + "✖ precheck — ios/App/Native.m: compiler exited 139 without a diagnostic rn-xtool could read", + ...lines.slice(5).map((l) => ` ${l}`), + ]); + }); +}); diff --git a/tests/precheckCommands.test.ts b/tests/precheckCommands.test.ts new file mode 100644 index 0000000..40370b9 --- /dev/null +++ b/tests/precheckCommands.test.ts @@ -0,0 +1,476 @@ +import { chmodSync, existsSync, mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { afterEach, describe, expect, it, vi } from "vitest"; +import { isExecutable, sdkBundle } from "../src/commands/setup.js"; +import type { AppTargetInputs, ExpoPackageInputs } from "../src/generate/packageSwift.js"; +import type { GeneratedApp } from "../src/generate/iosXtool.js"; +import { + clangArgs, + compileIncludeDirs, + moduleCacheKey, + precheckIncludeDirs, + precheckToolchain, + swiftcArgs, + type PrecheckInputs, +} from "../src/pipeline/precheckCommands.js"; +import type { PrecheckGraph } from "../src/pipeline/precheckGraph.js"; +import { toolEnv } from "../src/tools/exec.js"; +import { SWIFT_TEST_TIMEOUT_MS, SWIFT_TIMEOUT_MS, tool } from "./support/tools.js"; + +const HEADERS = "/p/app/ios-xtool/.build/out/Intermediates.noindex/GeneratedModuleMaps-iphoneos"; +const DIR = "/p/app/ios-xtool/.precheck"; +const CACHE = `${DIR}/ModuleCache/rn0.88.1-0123456789ab`; + +function inputs(app: Partial = {}, expo?: ExpoPackageInputs): PrecheckInputs { + const target: AppTargetInputs = { + mixed: true, + bridgingHeader: "/p/app/ios-xtool/Sources/App/App-Bridging-Header.h", + defines: ["COCOAPODS=1"], + headerSearchPaths: ["/p/app/ios/App", "/p/My Apps/inc"], + swiftHeadersDir: HEADERS, + ...app, + }; + const generated: GeneratedApp = { + pkg: { iosDir: "/p/app/ios", frameworks: [], iosMin: "16.4", app: target, expo }, + origins: {}, + }; + const graph: PrecheckGraph = { + headerDirs: ["/p/pkgs/React/include"], + moduleMaps: ["/p/pkgs/React/include/module.modulemap"], + synthesized: [{ module: "ReactCodegen", text: "module ReactCodegen {}\n" }], + targets: ["React", "ReactCodegen"], + modules: ["React", "ReactCodegen"], + unresolved: [], + }; + return { + app: generated, + graph, + toolchain: { + clang: "/t/bin/clang", + swiftc: "/t/bin/swiftc", + sdk: "/t/sdk/iPhoneOS.sdk", + swiftResources: "/t/sdk/swift", + swiftIncludes: ["/t/sdk/Platform Lib"], + swiftExtra: ["-Xfrontend", "-enable-cross-import-overlays"], + versions: "v", + }, + dir: DIR, + moduleCache: CACHE, + }; +} + +/** The value after each `flag` element. */ +const after = (args: string[], flag: string) => args.flatMap((a, n) => (a === flag ? [args[n + 1]] : [])); + +describe("the precheck's command lines", () => { + it("compiles Objective-C++ as Swift Build does", () => { + const mm = clangArgs(inputs(), "/p/app/ios-xtool/Sources/App/AppDelegate.mm"); + for (const flag of ["-fsyntax-only", "-fobjc-arc", "-fmodules", "-fno-cxx-modules", "-std=c++20", "-DDEBUG=1"]) { + expect(mm).toContain(flag); + } + expect(after(mm, "-x")).toEqual(["objective-c++"]); + expect(after(mm, "-target")).toEqual(["arm64-apple-ios16.4"]); + expect(after(mm, "-isysroot")).toEqual(["/t/sdk/iPhoneOS.sdk"]); + // -fno-cxx-modules leaves the module cache unused: clang warns about the flag. + expect(mm.some((a) => a.startsWith("-fmodules-cache-path="))).toBe(false); + expect(mm.at(-1)).toBe("/p/app/ios-xtool/Sources/App/AppDelegate.mm"); + expect(mm).toContain("-fmodule-name=App"); + expect(after(mm, "-iframework")).toEqual(["/t/Library/Frameworks", "/t/sdk/iPhoneOS.sdk/Developer/Library/Frameworks"]); + + const m = clangArgs(inputs(), "/p/app/ios-xtool/Sources/App/main.m"); + expect(after(m, "-x")).toEqual(["objective-c"]); + expect(m).toContain("-fobjc-arc"); + expect(m).toContain("-fmodules"); + expect(m.some((a) => a.startsWith("-std="))).toBe(false); + expect(m).not.toContain("-fno-cxx-modules"); + expect(m).toContain(`-fmodules-cache-path=${CACHE}`); + + const cpp = clangArgs(inputs(), "/p/app/ios-xtool/Sources/App/x.cpp"); + expect(after(cpp, "-x")).toEqual(["c++"]); + expect(cpp).not.toContain("-fobjc-arc"); + expect(cpp).toContain("-fno-cxx-modules"); + expect(cpp).toContain("-std=c++20"); + expect(cpp.some((a) => a.startsWith("-fmodules-cache-path="))).toBe(false); + expect(after(clangArgs(inputs(), "/p/a/x.c"), "-x")).toEqual(["c"]); + expect(after(clangArgs(inputs(), "/p/a/x.h"), "-x")).toEqual(["objective-c"]); + }); + + it("uses the precheck's Swift header folder", () => { + const i = inputs(); + for (const args of [clangArgs(i, "/p/a/x.m"), precheckIncludeDirs(i)]) { + expect(args.some((a) => a.includes(HEADERS))).toBe(false); + } + expect(after(clangArgs(i, "/p/a/x.m"), "-I")).toContain(`${DIR}/swift-headers`); + expect(precheckIncludeDirs(i)).toEqual([ + "/p/app/ios/App", + "/p/My Apps/inc", + `${DIR}/swift-headers`, + "/p/pkgs/React/include", + ]); + }); + + it("moves the Swift header folder inside joined arguments", () => { + const expo: ExpoPackageInputs = { + compileInterfacesDir: "/p/app/ios-xtool/.expo/interfaces", + jsiHeaders: false, + clangImporter: { + swiftHeadersDir: HEADERS, + includeDirs: ["/p/expo/pod-headers"], + moduleMaps: [`${HEADERS}/ExpoModulesCore.modulemap`], + }, + }; + const i = inputs({}, expo); + const clang = clangArgs(i, "/p/a/x.m"); + const swiftc = swiftcArgs(i, ["/p/a/AppDelegate.swift"]); + for (const args of [clang, swiftc]) expect(args.some((a) => a.includes(HEADERS))).toBe(false); + expect(clang).toContain(`-fmodule-map-file=${DIR}/swift-headers/ExpoModulesCore.modulemap`); + expect(after(swiftc, "-Xcc")).toContain(`-I${DIR}/swift-headers`); + expect(after(swiftc, "-Xcc")).toContain(`-fmodule-map-file=${DIR}/swift-headers/ExpoModulesCore.modulemap`); + // A path that only starts with the same characters is another folder. + const sibling = inputs({ headerSearchPaths: [`${HEADERS}-other`] }); + expect(after(clangArgs(sibling, "/p/a/x.m"), "-I")).toContain(`${HEADERS}-other`); + }); + + it("names the graph's folders and module maps, synthesized ones included", () => { + const i = inputs(); + const synthesized = `${DIR}/modulemaps/ReactCodegen/module.modulemap`; + const clang = clangArgs(i, "/p/a/x.m"); + expect(after(clang, "-I")).toContain("/p/pkgs/React/include"); + expect(clang).toContain("-fmodule-map-file=/p/pkgs/React/include/module.modulemap"); + expect(clang).toContain(`-fmodule-map-file=${synthesized}`); + const swiftc = swiftcArgs(i, ["/p/a/AppDelegate.swift"]); + // Swift Build gives the importer a clang target's headers, and Swift no search path for them. + expect(after(swiftc, "-I")).not.toContain("/p/pkgs/React/include"); + expect(after(swiftc, "-Xcc")).toContain("-I/p/pkgs/React/include"); + expect(after(swiftc, "-Xcc")).toContain(`-fmodule-map-file=${synthesized}`); + }); + + it("names one module map per module, Swift Build's own before a synthesized one", () => { + // Task 13's third false stop: Expo's ExpoUI, a mixed target, had its synthesized map and Swift Build's copied one. + const expoUI = "/p/expo/ExpoUI/root/ios"; + const expo: ExpoPackageInputs = { + compileInterfacesDir: "/p/app/ios-xtool/.expo/interfaces", + jsiHeaders: false, + clangImporter: { swiftHeadersDir: HEADERS, includeDirs: [], moduleMaps: [`${HEADERS}/ExpoUI.modulemap`, `${HEADERS}/React.modulemap`] }, + }; + const i = inputs({}, expo); + i.graph = { + ...i.graph, + headerDirs: [...i.graph.headerDirs, expoUI], + synthesized: [...i.graph.synthesized, { module: "ExpoUI", text: `module ExpoUI {\n umbrella "${expoUI}"\n export *\n}\n` }], + modules: [...i.graph.modules, "ExpoUI"], + }; + const maps = (args: string[]) => args.filter((a) => a.startsWith("-fmodule-map-file=")); + for (const args of [clangArgs(i, "/p/a/x.m"), swiftcArgs(i, ["/p/a/A.swift"])]) { + // React's map on disk wins over Swift Build's importer map; ExpoUI's importer map over its synthesized one. + expect(maps(args)).toEqual([ + `-fmodule-map-file=${DIR}/swift-headers/ExpoUI.modulemap`, + "-fmodule-map-file=/p/pkgs/React/include/module.modulemap", + `-fmodule-map-file=${DIR}/modulemaps/ReactCodegen/module.modulemap`, + ]); + // Swift Build gives the App no header folder for a module whose map it writes. + expect(args.some((a) => a.endsWith(expoUI))).toBe(false); + expect(args.filter((a) => a.endsWith("/p/pkgs/React/include")).length).toBeGreaterThan(0); + } + // The importer map left out takes its -Xcc with it. + expect(after(swiftcArgs(i, ["/p/a/A.swift"]), "-Xcc")).not.toContain("-Xcc"); + + // Not written yet (the precheck drops Swift Build's map from the command): the synthesized one stands in. + const waiting = clangArgs(i, "/p/a/x.m", new Set(["ExpoUI"])); + expect(maps(waiting)).toContain(`-fmodule-map-file=${DIR}/modulemaps/ExpoUI/module.modulemap`); + expect(after(waiting, "-I")).toContain(expoUI); + }); + + it("typechecks Swift with the bridging header and writes App-Swift.h", () => { + const args = swiftcArgs(inputs(), ["/p/a/AppDelegate.swift", "/p/a/View.swift"]); + expect(args[0]).toBe("-typecheck"); + // Task 13's first false stop: a one-file App is not its main file ('main' attribute … top-level code). + expect(args).toContain("-parse-as-library"); + expect(after(args, "-module-name")).toEqual(["App"]); + expect(after(args, "-target")).toEqual(["arm64-apple-ios16.4"]); + expect(after(args, "-sdk")).toEqual(["/t/sdk/iPhoneOS.sdk"]); + const sdk = args.indexOf("-sdk"); + expect(args.slice(sdk + 2, sdk + 8)).toEqual(["-resource-dir", "/t/sdk/swift", "-Xcc", "-resource-dir", "-Xcc", "/t/sdk/swift/clang"]); + // The triple's include paths and the developer frameworks come after the target's own flags, as in Swift Build. + expect(after(args, "-Isystem")).toEqual(["/t/sdk/Platform Lib"]); + expect(args.indexOf("-Isystem")).toBeGreaterThan(args.indexOf("-import-objc-header")); + expect(after(args, "-F")).toEqual(["/t/Library/Frameworks", "/t/sdk/iPhoneOS.sdk/Developer/Library/Frameworks"]); + expect(after(args, "-enable-experimental-feature")).toEqual(["DebugDescriptionMacro"]); + // The generated package's identity, as SwiftPM spells it (`ios-xtool` → `ios_xtool`). + expect(after(args, "-package-name")).toEqual(["ios_xtool"]); + expect(after(args, "-swift-version")).toEqual(["5"]); + expect(after(args, "-module-cache-path")).toEqual([CACHE]); + expect(after(args, "-import-objc-header")).toEqual(["/p/app/ios-xtool/Sources/App/App-Bridging-Header.h"]); + expect(after(args, "-emit-objc-header-path")).toEqual([`${DIR}/swift-headers/App-Swift.h`]); + expect(args).toContain("-enable-cross-import-overlays"); + expect(args.slice(-2)).toEqual(["/p/a/AppDelegate.swift", "/p/a/View.swift"]); + }); + + it("defines what Swift Build defines for a package target in Debug", () => { + const xcc = (args: string[]) => after(args, "-Xcc").filter((a) => a.startsWith("-D")); + const importer = ["-DSWIFT_PACKAGE", "-DDEBUG=1", "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG"]; + // Task 13's second false stop: React Native's headers hide RCTDevMenuConfiguration's initializer without DEBUG=1. + const swiftOnly = swiftcArgs(inputs({ mixed: false, bridgingHeader: undefined }), ["/p/a/A.swift"]); + expect(xcc(swiftOnly)).toEqual(importer); + for (const d of ["-DSWIFT_PACKAGE", "-DDEBUG", "-DSWIFT_MODULE_RESOURCE_BUNDLE_UNAVAILABLE", "-DXcode"]) expect(swiftOnly).toContain(d); + // A mixed target's cSettings give Swift Build the App's own macros; its bridging header gives them again. + expect(xcc(swiftcArgs(inputs(), ["/p/a/A.swift"]))).toEqual([...importer, "-DCOCOAPODS=1", "-DCOCOAPODS=1"]); + + const clang = ["-DSWIFT_PACKAGE", "-DDEBUG=1", "-DOBJC_OLD_DISPATCH_PROTOTYPES=1", "-DXcode"]; + const defines = (args: string[]) => args.filter((a) => a.startsWith("-D")); + expect(defines(clangArgs(inputs(), "/p/a/x.m"))).toEqual([...clang, "-DCOCOAPODS=1"]); + expect(defines(clangArgs(inputs(), "/p/a/x.mm"))).toEqual([...clang, "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG", "-DCOCOAPODS=1"]); + // A Swift-only target's bridging header gets what the importer gets. + expect(defines(clangArgs(inputs({ mixed: false }), "/p/a/B.h"))).toEqual([...importer, "-DCOCOAPODS=1"]); + }); + + it("gives a Swift-only target's bridging header what Swift gives it", () => { + const i = inputs({ mixed: false }); + const args = clangArgs(i, "/p/app/ios-xtool/Sources/App/App-Bridging-Header.h"); + expect(after(args, "-x")).toEqual(["objective-c"]); + expect(args).toContain("-I/p/My Apps/inc"); + expect(args).toContain("-DCOCOAPODS=1"); + expect(args).not.toContain("-Xcc"); + expect(args).not.toContain("-import-objc-header"); + // Swift's clang importer compiles no file of module App. + expect(args.some((a) => a.startsWith("-fmodule-name="))).toBe(false); + }); + + it("gives a mixed target's bridging header what Swift gives it, not a C-family file's flags", () => { + const i = inputs(); + const bridging = clangArgs(i, "/p/app/ios-xtool/Sources/App/App-Bridging-Header.h"); + // The importer's macros (expo-58-bridging's swiftDriver: -Xcc -D…), then the bridging header's own -Xcc -D. + expect(bridging.filter((a) => a.startsWith("-D"))).toEqual([ + "-DSWIFT_PACKAGE", + "-DDEBUG=1", + "-D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG", + "-DCOCOAPODS=1", + ]); + expect(bridging.some((a) => a.startsWith("-fmodule-name="))).toBe(false); + expect(bridging).toContain("-I/p/My Apps/inc"); + // A C-family file of the same target keeps the target's. + const m = clangArgs(i, "/p/a/x.m"); + expect(m).toContain("-fmodule-name=App"); + expect(m).toContain("-DOBJC_OLD_DISPATCH_PROTOTYPES=1"); + }); + + it("orders a file's include folders as the compile that reads it", () => { + const i = inputs(); + const bridging = "/p/app/ios-xtool/Sources/App/App-Bridging-Header.h"; + const graph = "/p/pkgs/React/include"; + // A file of the target: the graph's folders first (objc-088's `.resp`). + expect(compileIncludeDirs(i, "/p/a/x.m")[0]).toBe(graph); + expect(after(clangArgs(i, "/p/a/x.m"), "-I")[0]).toBe(graph); + // The bridging header: the target's own first, as swiftc's importer gets them (expo-58-bridging's swiftDriver). + const own = compileIncludeDirs(i, bridging); + expect(own.slice(0, 2)).toEqual(["/p/app/ios/App", "/p/My Apps/inc"]); + expect(own.indexOf(graph)).toBeGreaterThan(1); + const line = clangArgs(i, bridging); + expect(line.indexOf("-I/p/My Apps/inc")).toBeLessThan(line.indexOf(graph)); + const importer = after(swiftcArgs(i, ["/p/a/A.swift"]), "-Xcc").filter((a) => a.startsWith("-I")); + expect(importer.indexOf("-I/p/My Apps/inc")).toBeLessThan(importer.indexOf(`-I${graph}`)); + // Every folder pass 2 searched before is still searched, after the line's own. + expect(new Set(compileIncludeDirs(i, bridging))).toEqual(new Set([...own, ...precheckIncludeDirs(i)])); + }); + + it("gives an Expo Swift-only target's bridging header the compile-interfaces frameworks", () => { + const expo: ExpoPackageInputs = { compileInterfacesDir: "/p/app/ios-xtool/.expo/My Interfaces", jsiHeaders: false }; + const args = clangArgs(inputs({ mixed: false }, expo), "/p/app/ios-xtool/Sources/App/App-Bridging-Header.h"); + expect(after(args, "-F")).toEqual(["/p/app/ios-xtool/.expo/My Interfaces"]); + expect(args).toContain("-DCOCOAPODS=1"); + expect(args).not.toContain("-Xcc"); + }); + + it("keeps a folder with spaces one argument", () => { + const i = inputs(); + expect(after(clangArgs(i, "/p/a/x.m"), "-I")).toContain("/p/My Apps/inc"); + expect(after(swiftcArgs(i, ["/p/a/A.swift"]), "-Xcc")).toContain("-I/p/My Apps/inc"); + expect(clangArgs(i, "/p/My Apps/x.m").at(-1)).toBe("/p/My Apps/x.m"); + }); + + it("keys the module cache by React Native and the toolchain", () => { + const key = moduleCacheKey("0.88.1", "clang 21\nswift 6.4\nepoch=4"); + expect(key).toMatch(/^rn0\.88\.1-[0-9a-f]{12}$/); + expect(moduleCacheKey("0.88.1", "clang 21\nswift 6.4\nepoch=4")).toBe(key); + expect(moduleCacheKey("0.88.1", "clang 22\nswift 6.4\nepoch=4")).not.toBe(key); + expect(moduleCacheKey("0.88.0", "clang 21\nswift 6.4\nepoch=4")).not.toBe(key); + }); +}); + +describe("precheckToolchain", () => { + let t = ""; + afterEach(() => { + vi.unstubAllEnvs(); + if (t) rmSync(t, { recursive: true, force: true }); + t = ""; + }); + + /** A temp Darwin SDK bundle (through XDG_CONFIG_HOME) and a bin folder with fake clang and swiftc. */ + function fakeSetup(sdkRoot: string, makeSdk: boolean): { env: NodeJS.ProcessEnv; bundle: string } { + t = mkdtempSync(path.join(tmpdir(), "precheck-toolchain-")); + vi.stubEnv("XDG_CONFIG_HOME", path.join(t, "config")); + const bundle = sdkBundle(); + mkdirSync(path.join(bundle, "toolset"), { recursive: true }); + if (makeSdk) mkdirSync(path.join(bundle, sdkRoot), { recursive: true }); + if (makeSdk) mkdirSync(path.join(bundle, "Toolchain/usr/lib/swift"), { recursive: true }); + const triple = (root: string) => ({ + sdkRootPath: root, + toolsetPaths: ["toolset.json"], + swiftResourcesPath: "Toolchain/usr/lib/swift", + includeSearchPaths: ["Platforms/iPhoneOS.platform/usr/lib"], + }); + writeFileSync( + path.join(bundle, "swift-sdk.json"), + JSON.stringify({ + schemaVersion: "4.0", + targetTriples: { "arm64-apple-macosx": triple("Mac/MacOSX.sdk"), "arm64-apple-ios": triple(sdkRoot) }, + }), + ); + writeFileSync( + path.join(bundle, "toolset.json"), + JSON.stringify({ + schemaVersion: "1.0", + rootPath: "toolset/bin", + swiftCompiler: { extraCLIOptions: ["-Xfrontend", "-enable-cross-import-overlays", "-use-ld=lld"] }, + }), + ); + writeFileSync(path.join(bundle, "darwin-sdk-version.txt"), "epoch=4,darwinTools=1.1.0\n"); + const bin = path.join(t, "bin"); + mkdirSync(bin); + for (const name of ["clang", "swiftc"]) { + writeFileSync(path.join(bin, name), `#!/bin/sh\necho "fake ${name} 1.0"\n`); + chmodSync(path.join(bin, name), 0o755); + } + return { env: { PATH: bin }, bundle }; + } + + it("names a missing compiler and a missing SDK", async () => { + await expect(precheckToolchain({ PATH: "" })).rejects.toThrow( + "precheck — clang was not found on the Swift toolchain's PATH; run rn-xtool setup", + ); + const { env, bundle } = fakeSetup("Platforms/iPhoneOS.platform/SDKs/iPhoneOS27.1.sdk", false); + const sdk = path.join(bundle, "Platforms/iPhoneOS.platform/SDKs/iPhoneOS27.1.sdk"); + await expect(precheckToolchain(env)).rejects.toThrow( + `precheck — the iPhoneOS SDK was not found in the Darwin SDK (${sdk}); run rn-xtool setup --xcode-xip `, + ); + rmSync(path.join(env.PATH!, "swiftc")); + await expect(precheckToolchain(env)).rejects.toThrow( + "precheck — swiftc was not found on the Swift toolchain's PATH; run rn-xtool setup", + ); + }); + + it("names a Darwin SDK without an iPhoneOS entry", async () => { + const { env, bundle } = fakeSetup("x.sdk", true); + writeFileSync(path.join(bundle, "swift-sdk.json"), JSON.stringify({ schemaVersion: "4.0", targetTriples: {} })); + await expect(precheckToolchain(env)).rejects.toThrow( + `precheck — the iPhoneOS SDK was not found in the Darwin SDK (${path.join(bundle, "swift-sdk.json")})`, + ); + }); + + it("names missing Swift resources", async () => { + const { env, bundle } = fakeSetup("x.sdk", true); + const resources = path.join(bundle, "Toolchain/usr/lib/swift"); + rmSync(resources, { recursive: true }); + await expect(precheckToolchain(env)).rejects.toThrow( + `precheck — the Swift resources were not found in the Darwin SDK (${resources}); run rn-xtool setup --xcode-xip `, + ); + }); + + it("reads the SDK, the toolset's Swift options and the versions", async () => { + const { env, bundle } = fakeSetup("Platforms/iPhoneOS.platform/SDKs/iPhoneOS27.1.sdk", true); + const tc = await precheckToolchain(env); + expect(tc.clang).toBe(path.join(env.PATH!, "clang")); + expect(tc.swiftc).toBe(path.join(env.PATH!, "swiftc")); + expect(tc.sdk).toBe(path.join(bundle, "Platforms/iPhoneOS.platform/SDKs/iPhoneOS27.1.sdk")); + expect(tc.swiftExtra).toEqual(["-Xfrontend", "-enable-cross-import-overlays"]); + expect(tc.swiftResources).toBe(path.join(bundle, "Toolchain/usr/lib/swift")); + expect(tc.swiftIncludes).toEqual([path.join(bundle, "Platforms/iPhoneOS.platform/usr/lib")]); + expect(tc.versions).toBe("fake clang 1.0\nfake swiftc 1.0\nepoch=4,darwinTools=1.1.0"); + }); +}); + +const IOS_SDK = path.join(sdkBundle(), "Developer", "Platforms", "iPhoneOS.platform", "Developer", "SDKs", "iPhoneOS.sdk"); +const HAS_IOS_TOOLS = existsSync(IOS_SDK) && tool("clang", ["--version"], { env: toolEnv() }).status === 0; + +describe.skipIf(!HAS_IOS_TOOLS)( + `the installed toolchain${HAS_IOS_TOOLS ? "" : " (needs the Darwin SDK and the Swift toolchain's clang: rn-xtool setup)"}`, + () => { + it("finds the compilers and the iPhoneOS SDK", async () => { + const tc = await precheckToolchain(); + expect(isExecutable(tc.clang)).toBe(true); + expect(isExecutable(tc.swiftc)).toBe(true); + expect(existsSync(tc.sdk)).toBe(true); + expect(tc.swiftExtra.some((o) => o.startsWith("-use-ld="))).toBe(false); + expect(tc.versions).toMatch(/clang version/); + expect(tc.versions).toMatch(/Swift version/); + }); + + it( + "typechecks Swift and compiles Objective-C against the iPhoneOS SDK", + async () => { + const tc = await precheckToolchain(); + const t = mkdtempSync(path.join(tmpdir(), "precheck-real-")); + try { + const dir = path.join(t, ".precheck"); + const i = (mixed: boolean): PrecheckInputs => ({ + ...inputs(), + app: { + pkg: { + iosDir: path.join(t, "ios"), + frameworks: [], + iosMin: "16.4", + app: { mixed, defines: [], headerSearchPaths: [], swiftHeadersDir: path.join(t, "build-headers") }, + }, + origins: {}, + }, + graph: { headerDirs: [], moduleMaps: [], synthesized: [], targets: [], modules: [], unresolved: [] }, + toolchain: tc, + dir, + moduleCache: path.join(dir, "ModuleCache", moduleCacheKey("0.88.1", tc.versions)), + }); + const swift = path.join(t, "A.swift"); + writeFileSync(swift, "import Foundation\n"); + const typecheck = tool(tc.swiftc, swiftcArgs(i(false), [swift]), { env: toolEnv(), timeout: SWIFT_TIMEOUT_MS }); + expect(typecheck.stderr).toBe(""); + expect(typecheck.status).toBe(0); + expect(existsSync(path.join(dir, "swift-headers", "App-Swift.h"))).toBe(true); + + // One file with an @main type, as the bare template's AppDelegate.swift: a library's file, not main.swift. + const main = path.join(t, "AppDelegate.swift"); + writeFileSync(main, "import UIKit\n\n@main\nclass AppDelegate: UIResponder, UIApplicationDelegate {}\n"); + const library = tool(tc.swiftc, swiftcArgs(i(false), [main]), { env: toolEnv(), timeout: SWIFT_TIMEOUT_MS }); + expect(library.stderr).toBe(""); + expect(library.status).toBe(0); + + // A `package` declaration needs the package's name, as Swift Build passes it. + const pkg = path.join(t, "Access.swift"); + writeFileSync(pkg, "package func packageOnly() {}\n"); + const packageCheck = tool(tc.swiftc, swiftcArgs(i(false), [pkg]), { env: toolEnv(), timeout: SWIFT_TIMEOUT_MS }); + expect(packageCheck.stderr).toBe(""); + expect(packageCheck.status).toBe(0); + + // A bridging header's debug-only declaration, as React Native's headers keep theirs under DEBUG. + const bridging = path.join(t, "Bridging.h"); + writeFileSync(bridging, "#if DEBUG\nstatic inline int precheckDebugOnly(void) { return 1; }\n#endif\n"); + const debug = path.join(t, "Debug.swift"); + writeFileSync(debug, "func debugOnly() -> Int32 { precheckDebugOnly() }\n"); + const withBridging: PrecheckInputs = { ...i(false), app: { ...i(false).app } }; + withBridging.app.pkg = { ...withBridging.app.pkg, app: { ...withBridging.app.pkg.app, bridgingHeader: bridging } }; + const debugCheck = tool(tc.swiftc, swiftcArgs(withBridging, [debug]), { env: toolEnv(), timeout: SWIFT_TIMEOUT_MS }); + expect(debugCheck.stderr).toBe(""); + expect(debugCheck.status).toBe(0); + + const objc = path.join(t, "B.m"); + writeFileSync(objc, "#import \n"); + const compile = tool(tc.clang, clangArgs(i(true), objc), { env: toolEnv(), timeout: SWIFT_TIMEOUT_MS }); + expect(compile.stderr).toBe(""); + expect(compile.status).toBe(0); + } finally { + rmSync(t, { recursive: true, force: true }); + } + }, + SWIFT_TEST_TIMEOUT_MS, + ); + }, +); diff --git a/tests/precheckGolden.test.ts b/tests/precheckGolden.test.ts new file mode 100644 index 0000000..dd919cd --- /dev/null +++ b/tests/precheckGolden.test.ts @@ -0,0 +1,370 @@ +// Row 39: the precheck's command lines against Swift Build's own, captured from six reference builds (Task 13). Each +// fixture under `fixtures/precheck/golden//` holds the precheck's `inputs.json` of that build and Swift Build's +// argv per App compile (`commands.json`: the Swift driver's from its task store, since a Swift compile writes no +// response file, and each `CompileC`'s, whose `@…-common-args.resp` is in `responses/`). The golden is never edited +// to match the builder: a difference is fixed in `precheckCommands.ts`/`precheckGraph.ts`, or, when only the build +// folders explain it, normalised below with the command it came from. + +import { existsSync, readdirSync, readFileSync } from "node:fs"; +import path from "node:path"; +import { describe, expect, it } from "vitest"; +import { clangArgs, swiftcArgs, type PrecheckInputs } from "../src/pipeline/precheckCommands.js"; + +const GOLDEN = path.join(import.meta.dirname, "fixtures", "precheck", "golden"); + +interface Commands { + /** `builtin-SwiftDriver -- swiftc …` of the App target. */ + swiftDriver: string[][]; + /** The App target's `CompileC` tasks: `clang …` with `@-common-args.resp`. */ + compileC: { description: string; tool: string; argsFrom: string; args: string[] }[]; +} + +/** Compared flags whose value is the next element. */ +const PAIRED = new Set([ + "-I", + "-F", + "-iquote", + "-isystem", + // Swift's system import path (`-Isystem `), as Swift Build passes the triple's include paths. + "-Isystem", + "-include", + "-target", + "-isysroot", + "-sdk", + "-x", + "-import-objc-header", + "-swift-version", + "-module-name", + "-Xfrontend", + "-Xcc", + "-enable-experimental-feature", + // `package` access needs it (Swift Build: `-package-name ios_xtool`). + "-package-name", + // The platform's and the SDK's developer frameworks, as Swift Build's clang gets them (objc-088's `.resp`). + "-iframework", +]); +/** Compared flags with their value joined. */ +const JOINED = /^(-D|-U|-I|-F|-fmodule-map-file=|-std=|-fmodule-name=)/; +/** Compared flags without a value: these, and every `-enable-…`. */ +const BARE = new Set([ + "-fobjc-arc", + "-fno-objc-arc", + "-fmodules", + "-fno-cxx-modules", + "-fcxx-modules", + // Task 13's first false stop: without it a one-file module's file is main.swift ('main' attribute … top-level code). + "-parse-as-library", +]); + +/** + * Every other flag of either side: ignored, and listed here so that a flag neither compared nor listed fails the test. + * Each takes the next element as its value when `true`. + */ +const IGNORED: Record = { + // swiftc: what Swift Build's driver writes, and how it schedules its jobs and module builds. + "-resource-dir": true, + "-module-cache-path": true, + "-external-plugin-path": true, + "-index-store-path": true, + "-output-file-map": true, + "-clang-scanner-module-cache-path": true, + "-sdk-module-cache-path": true, + "-emit-module-path": true, + "-dependency-scan-serialize-diagnostics-path": true, + "-clang-build-session-file": true, + "-const-gather-protocols-list": true, + "-emit-objc-header-path": true, + "-working-directory": true, + "-typecheck": false, + "-no-color-diagnostics": false, + "-Onone": false, + "-g": false, + "-c": false, + "-incremental": false, + "-save-temps": false, + "-color-diagnostics": false, + "-explicit-module-build": false, + "-emit-dependencies": false, + "-emit-module": false, + "-serialize-diagnostics": false, + "-validate-clang-modules-once": false, + "-emit-const-values": false, + "-emit-objc-header": false, + "-experimental-emit-module-separately": false, + "-disable-cmo": false, + // clang: diagnostics, warnings, outputs and code generation; -fsyntax-only checks without them. + "-MT": true, + "-MF": true, + "--serialize-diagnostics": true, + "-o": true, + "-fsyntax-only": false, + "-fno-color-diagnostics": false, + "-fmessage-length=0": false, + "-fdiagnostics-show-note-include-stack": false, + "-fmacro-backtrace-limit=0": false, + "-fcolor-diagnostics": false, + "-fmodules-validate-once-per-build-session": false, + "-fstrict-aliasing": false, + "-gmodules": false, + "-fpascal-strings": false, + "-O0": false, + "-fvisibility-inlines-hidden": false, + "-MMD": false, +}; +/** Ignored flag families: warnings, the module cache's pruning and session (the cache paths are dropped), `-j`. */ +const IGNORED_PREFIX = /^(-W|-fmodules-prune-|-fbuild-session-file=|-fmodules-cache-path=|-j\d+$)/; + +/** + * A path as both sides can name it, or null when the flag that names it is dropped: + * - Swift Build's `GeneratedModuleMaps-` and the precheck's `swift-headers` → `` (brief); + * - a module map under `.build`, the precheck's synthesized one and its copy of Swift Build's importer map in + * `swift-headers` (expo-58-bridging's swiftDriver: the copy is the same file) → `>` (brief); + * - a binary target's xcframework `Headers` → `>`, one per binary target; Swift Build's + * `Products//include`, where it copies those headers (every swiftDriver: `-Xcc -I…/Products/Debug-iphoneos/ + * include`; objc-088's `.resp` files), stands for each of them (`withBinaryHeaders`); the xcframework's + * `module.modulemap` dropped, as clang finds the copy's in that folder (same commands); + * - the rest of Swift Build's `Products/` folder and the App's `DerivedSources`: what other targets built and + * what Swift Build derives, none of it there before xtool-build (every swiftDriver's `-I`/`-F`/`-Xcc -I`; objc-088's + * `.resp` `-I`/`-F`) → dropped. No reference has a framework-type binary target (whose framework Swift Build copies + * there), so the drop hides no framework search path. + */ +function normalisePath(p: string, moduleMap: boolean): string | null { + if (moduleMap) { + if (/\.xcframework\/[^/]+\/Headers\/module\.modulemap$/.test(p)) return null; + const synthesized = /\/\.precheck\/modulemaps\/([^/]+)\/module\.modulemap$/.exec(p); + if (synthesized) return ``; + const generated = /\/(?:\.build\/.*|\.precheck\/swift-headers)\/([^/]+)\.modulemap$/.exec(p); + if (generated) return ``; + } + const binary = /\/([^/]+)\.xcframework\/[^/]+\/Headers$/.exec(p); + if (binary) return ``; + if (/\/\.build\/out\/Products\/[^/]+(\/|$)/.test(p) || /\/App-t\.build\/DerivedSources(-normal)?(\/|$)/.test(p)) return null; + return p + .replace(/\/ios-xtool\/\.build\/out\/Intermediates\.noindex\/GeneratedModuleMaps-[^/]+/, "/") + .replace(/\/ios-xtool\/\.precheck\/swift-headers/, "/"); +} + +/** + * Swift Build's flags for what the driver writes and how it schedules its jobs, which `-typecheck` neither writes nor + * runs (every swiftDriver): batch mode, `@testable` access, and the debugging options a `.swiftmodule` keeps. + */ +const OUTPUT_ONLY = new Set(["-enable-batch-mode", "-enable-testing", "-Xfrontend -serialize-debugging-options"]); + +/** One flag (`-I`, `-Xcc -DDEBUG=1`, `-target arm64-apple-ios16.4`) normalised, or null when it is dropped. */ +function normaliseFlag(flag: string, value?: string): string | null { + if (OUTPUT_ONLY.has(value === undefined ? flag : `${flag} ${value}`)) return null; + if (flag === "-Xcc") { + // The importer's module cache pruning (every swiftDriver): dropped with the module cache paths. + if (IGNORED_PREFIX.test(value!)) return null; + const inner = normaliseFlag(value!); + return inner === null ? null : `-Xcc ${inner}`; + } + if (flag === "-I" || flag === "-F") return normaliseFlag(`${flag}${value}`); + if (value !== undefined) return `${flag} ${value}`; + const joined = /^(-I|-F|-fmodule-map-file=)(.+)$/.exec(flag); + if (joined) { + const p = normalisePath(joined[2]!, joined[1] === "-fmodule-map-file="); + return p === null ? null : `${joined[1]}${p}`; + } + return flag; +} + +/** + * The compared flags of an argv, normalised and each once; `?` for one neither compared nor ignored. A + * `-fmodule-map-file=` is kept per map, so two maps of one module show as two, and a binary target's header folder per + * flag, so a binary target named twice, or left out, shows. + */ +function flags(argv: string[]): string[] { + const out: string[] = []; + for (let n = 0; n < argv.length; n++) { + const a = argv[n]!; + let flag: string | null; + if (PAIRED.has(a)) flag = normaliseFlag(a, argv[++n]); + else if (BARE.has(a) || a.startsWith("-enable-") || JOINED.test(a)) flag = normaliseFlag(a); + else if (a in IGNORED) { + if (IGNORED[a]) n++; + continue; + } else if (IGNORED_PREFIX.test(a) || !a.startsWith("-")) continue; + else flag = `?${a}`; + if (flag !== null) out.push(flag); + } + const seen = new Set(); + return out.filter((f) => { + if (f.includes("-fmodule-map-file= { + const at = left.indexOf(x); + if (at < 0) return true; + left.splice(at, 1); + return false; + }); +} + +/** What Swift Build passes and the precheck does not (`missing`), and the reverse (`extra`), compared flags only. */ +export function compareFlags(ours: string[], theirs: string[]): { missing: string[]; extra: string[] } { + const a = flags(ours); + const b = flags(theirs); + return { missing: without(b, a), extra: without(a, b) }; +} + +/** + * The include folders `argv` names with the flags in `kinds` (`-I` for clang; `-I` and `-F` for swiftc; `-Xcc -I` for + * swiftc's importer), in order: ` `, each at its first place, dropped ones left out. clang + * searches them in this order, so a header two of them hold resolves to the first. With `graph`, each run of the + * package graph's header folders is one ` ` at the run's place: Swift Build orders them by the package + * graph, which the fixtures do not hold (`inputs.json` has the folders, in rn-xtool's order), so the order inside a + * run is not compared, but a graph folder placed among the target's own folders still shows; `compareFlags` compares + * the folders a run holds. + */ +function includeOrder(argv: string[], kinds: string[], graph: ReadonlySet = new Set()): string[] { + const seen = new Set(); + const out: string[] = []; + for (let n = 0; n < argv.length; n++) { + const a = argv[n]!; + if (a === "-Isystem") { + n++; + continue; + } + let kind: string | undefined; + let folder: string | undefined; + if (a === "-Xcc") { + const value = argv[++n] ?? ""; + if (kinds.includes("-Xcc -I") && value.startsWith("-I")) [kind, folder] = ["-Xcc -I", value.slice(2)]; + } else { + kind = kinds.find((k) => !k.startsWith("-Xcc") && (a === k || a.startsWith(k))); + if (kind !== undefined) folder = a === kind ? argv[++n]! : a.slice(kind.length); + } + if (kind === undefined || folder === undefined) continue; + const p = normalisePath(folder, false); + if (p === null) continue; + const concrete = `${kind} ${p}`; + if (seen.has(concrete)) continue; + seen.add(concrete); + const entry = graph.has(p) ? `${kind} ` : concrete; + if (entry.endsWith(" ") && out.at(-1) === entry) continue; + out.push(entry); + } + return out; +} + +/** The graph's header folders of `inputs`, normalised (its binary targets' as `withBinaryHeaders` names them). */ +const graphFolders = (inputs: PrecheckInputs): Set => new Set(inputs.graph.headerDirs.flatMap((d) => normalisePath(d, false) ?? [])); + +/** + * Swift Build's `argv` with its `Products//include` (`-I`, `-I `, `-Xcc -I`) named once per + * binary target of the graph whose headers it copies there: the xcframework `Headers` folders of `inputs.graph`. + */ +function withBinaryHeaders(argv: string[], inputs: PrecheckInputs): string[] { + const binaries = inputs.graph.headerDirs.filter((d) => /\.xcframework\/[^/]+\/Headers$/.test(d)); + const products = /\/\.build\/out\/Products\/[^/]+\/include$/; + const out: string[] = []; + for (let n = 0; n < argv.length; n++) { + const a = argv[n]!; + if (a === "-Xcc" && argv[n + 1]?.startsWith("-I") && products.test(argv[n + 1]!.slice(2))) { + out.push(...binaries.flatMap((d) => ["-Xcc", `-I${d}`])); + n++; + } else if (a === "-I" && products.test(argv[n + 1] ?? "")) { + out.push(...binaries.flatMap((d) => ["-I", d])); + n++; + } else if (a.startsWith("-I") && products.test(a.slice(2))) { + out.push(...binaries.map((d) => `-I${d}`)); + } else { + out.push(a); + } + } + return out; +} + +/** `argv` with each `@.resp` replaced by its arguments (one line, space-separated, from `responses/`). */ +function expandResponses(ref: string, argv: string[]): string[] { + return argv.flatMap((a) => { + if (!a.startsWith("@")) return [a]; + // The Swift driver's `@App.SwiftFileList` lists the sources: positional, not compared. + if (a.endsWith(".SwiftFileList")) return []; + const file = path.join(GOLDEN, ref, "responses", path.basename(a)); + return readFileSync(file, "utf8").trim().split(/\s+/); + }); +} + +/** + * `theirs` without the module maps Swift Build writes for the graph's Swift targets (a target with no module of the + * graph) that `ours` does not name: each names that target's generated `-Swift.h`, which only Swift Build's compile of + * the target writes (objc-088's `.resp` files: AutolinkedAggregate). Expo's importer maps, which the precheck names + * too, stay. + */ +function withoutSwiftTargetMaps(theirs: string[], ours: string[], inputs: PrecheckInputs): string[] { + const modules = new Set(inputs.graph.modules); + const swiftTargets = new Set(inputs.graph.targets.filter((t) => !modules.has(t))); + const named = new Set(ours.flatMap((a) => /\/([^/]+)\.modulemap$/.exec(a)?.[1] ?? [])); + return theirs.filter((a) => { + const m = /^-fmodule-map-file=.*\/GeneratedModuleMaps-[^/]+\/([^/]+)\.modulemap$/.exec(a); + return m === null || !swiftTargets.has(m[1]!) || named.has(m[1]!); + }); +} + +describe("compareFlags", () => { + const out = "/home/me/app/ios-xtool/.build/out"; + const precheck = "/home/me/app/ios-xtool/.precheck"; + + it("compares the flag classes after normalisation and ignores the rest", () => { + const theirs = ["-I", `${out}/Intermediates.noindex/GeneratedModuleMaps-iphoneos`, `-fmodule-map-file=${out}/x/ExpoUI.modulemap`]; + const ours = [`-I${precheck}/swift-headers`, `-fmodule-map-file=${precheck}/modulemaps/ExpoUI/module.modulemap`, "-fsyntax-only"]; + expect(compareFlags([...ours, "-Wall", "-DA", "-DA"], [...theirs, "-O0", "-DA"])).toEqual({ missing: [], extra: [] }); + expect(compareFlags(["-x", "objective-c"], ["-x", "objective-c++"])).toEqual({ missing: ["-x objective-c++"], extra: ["-x objective-c"] }); + }); + + it("counts two maps of one module, and names a flag it does not know", () => { + const maps = [`-fmodule-map-file=${precheck}/swift-headers/ExpoUI.modulemap`, `-fmodule-map-file=${precheck}/modulemaps/ExpoUI/module.modulemap`]; + expect(compareFlags(maps, [`-fmodule-map-file=${out}/x/ExpoUI.modulemap`, "-fnew-flag"])).toEqual({ + missing: ["?-fnew-flag"], + extra: ["-fmodule-map-file="], + }); + }); +}); + +const refs = readdirSync(GOLDEN).filter((r) => existsSync(path.join(GOLDEN, r, "commands.json"))); + +describe("the precheck's command lines against Swift Build's (row 39)", () => { + it("has all six references", () => { + expect(refs.sort()).toEqual(["bare-085", "bare-086", "bare-087", "bare-088", "expo-58-bridging", "objc-088"]); + // Each reference compares at least one command: an empty commands.json would pass its tests vacuously. + for (const ref of refs) { + const { swiftDriver, compileC } = JSON.parse(readFileSync(path.join(GOLDEN, ref, "commands.json"), "utf8")) as Commands; + expect(swiftDriver.length + compileC.length, ref).toBeGreaterThan(0); + } + }); + + for (const ref of refs) { + const inputs = JSON.parse(readFileSync(path.join(GOLDEN, ref, "inputs.json"), "utf8")) as PrecheckInputs; + const commands = JSON.parse(readFileSync(path.join(GOLDEN, ref, "commands.json"), "utf8")) as Commands; + const swiftFiles = Object.keys(inputs.app.origins).filter((f) => f.endsWith(".swift")); + + for (const argv of commands.swiftDriver) { + it(`${ref}: swiftc gets Swift Build's flags`, () => { + // `builtin-SwiftDriver -- …` + const theirs = withBinaryHeaders(expandResponses(ref, argv.slice(argv.indexOf("--") + 2)), inputs); + expect(compareFlags(swiftcArgs(inputs, swiftFiles), theirs)).toEqual({ missing: [], extra: [] }); + expect(includeOrder(swiftcArgs(inputs, swiftFiles), ["-I", "-F"])).toEqual(includeOrder(theirs, ["-I", "-F"])); + const importer = (argv: string[]) => includeOrder(argv, ["-Xcc -I"], graphFolders(inputs)); + expect(importer(swiftcArgs(inputs, swiftFiles))).toEqual(importer(theirs)); + }); + } + for (const task of commands.compileC) { + const file = task.args[task.args.indexOf("-c") + 1]!; + it(`${ref}: ${path.basename(file)} gets Swift Build's flags`, () => { + const ours = clangArgs(inputs, file); + const theirs = withBinaryHeaders(withoutSwiftTargetMaps(expandResponses(ref, task.args.slice(1)), ours, inputs), inputs); + expect(compareFlags(ours, theirs)).toEqual({ missing: [], extra: [] }); + expect(includeOrder(ours, ["-I"], graphFolders(inputs))).toEqual(includeOrder(theirs, ["-I"], graphFolders(inputs))); + }); + } + } +}); diff --git a/tests/precheckGraph.test.ts b/tests/precheckGraph.test.ts new file mode 100644 index 0000000..b1d992c --- /dev/null +++ b/tests/precheckGraph.test.ts @@ -0,0 +1,443 @@ +import { mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { afterAll, beforeAll, describe, expect, it, vi } from "vitest"; +import { graphHeaders, planManifest, readPackageGraph, type DumpedPackage, type SwiftRunner } from "../src/pipeline/precheckGraph.js"; +import { PrecheckError } from "../src/pipeline/precheckReport.js"; +import { headersXcframeworkInfoPlist } from "../src/pipeline/rnArtifacts.js"; +import { devEnv } from "../src/tools/xtool.js"; + +// Two dump-package runs at a time, so the bound shows with six packages. +vi.mock("node:os", async (importOriginal) => { + const actual = await importOriginal(); + return { ...actual, default: { ...actual, availableParallelism: () => 2 }, availableParallelism: () => 2 }; +}); + +const FIXTURES = path.join(import.meta.dirname, "fixtures", "precheck", "graph"); +const FIXTURE_ROOT = "/home/me/app"; + +let t = ""; +/** The fixtures' graph as readPackageGraph reads it. */ +let graph: { root: DumpedPackage; packages: DumpedPackage[] }; +beforeAll(async () => { + t = mkdtempSync(path.join(tmpdir(), "precheck-graph-")); + makeTree(t); + graph = await readPackageGraph(path.join(t, "ios-xtool"), path.join(t, "scratch"), fakeSwift(t).run); +}); +afterAll(() => rmSync(t, { recursive: true, force: true })); + +const write = (file: string, text = "") => { + mkdirSync(path.dirname(file), { recursive: true }); + writeFileSync(file, text); +}; + +/** A fixture's text with the fixtures' project root moved to `root`. */ +const fixture = (name: string, root: string) => readFileSync(path.join(FIXTURES, name), "utf8").replaceAll(FIXTURE_ROOT, root); + +const DEVICE = { LibraryIdentifier: "ios-arm64", SupportedPlatform: "ios", SupportedArchitectures: ["arm64"] }; +const SIMULATOR = { + LibraryIdentifier: "ios-arm64_x86_64-simulator", + SupportedPlatform: "ios", + SupportedPlatformVariant: "simulator", + SupportedArchitectures: ["arm64", "x86_64"], +}; + +/** The folders the fixtures' packages name, as the generated project lays them out. */ +function makeTree(root: string): void { + write(path.join(root, "ios-xtool/Sources/App/AppDelegate.swift"), "import UIKit\n"); + write(path.join(root, "ios-xtool/Sources/RNXtoolDevSupport/RNXtoolDevSupport.m")); + const xcf = path.join(root, "ios/build/xcframeworks"); + write(path.join(xcf, "ReactHeadersTarget/include/React/RCTBridge.h")); + for (const [name, map] of [ + ["ReactNativeHeaders", 'module React {\n module React_RCTAppDelegate {\n header "React_RCTAppDelegate/RCTAppDelegate.h"\n export *\n }\n export *\n}\n'], + ["ReactNativeDependenciesHeaders", "// the dependencies' headers\nframework module ReactNativeDependencies {\n umbrella \".\"\n export *\n}\n"], + ] as const) { + const dir = path.join(xcf, `${name}.xcframework`); + write(path.join(dir, "Info.plist"), headersXcframeworkInfoPlist(name, [SIMULATOR, DEVICE])); + write(path.join(dir, "ios-arm64/Headers/module.modulemap"), map); + write(path.join(dir, "ios-arm64_x86_64-simulator/Headers/module.modulemap"), map); + } + const gen = path.join(root, "ios/build/generated/ios"); + write(path.join(gen, "ReactCodegen/include/ReactCodegen/ReactCodegen.h")); + write(path.join(gen, "ReactCodegen/include/ReactCodegen/RCTModuleProviders.h")); + write(path.join(gen, "ReactCodegen/ReactCodegen.mm")); + write(path.join(gen, "ReactAppDependencyProvider/include/RCTAppDependencyProvider.h")); + write(path.join(gen, "ReactAppHeaders/include/ReactAppHeaders.h")); + write(path.join(root, "ios/build/generated/autolinking/AutolinkedAggregate/AutolinkedAggregate.m")); + const lib = path.join(root, "node_modules/rn-lib/ios"); + write(path.join(lib, "public/module.modulemap"), 'module RNLib {\n umbrella header "RNLib.h"\n export *\n}\n'); + write(path.join(lib, "public/RNLib.h")); + write(path.join(lib, "swift/RNLib.swift")); + write(path.join(root, "node_modules/unreached-lib/ios/include/UnreachedLib.h")); + write(path.join(root, "alias/a/Sources/App/AppDelegate.swift")); + write(path.join(root, "alias/b/ios/Sources/BarLib/include/BarLib.h")); +} + +/** Each fixture package's folder (as show-dependencies names it) → its dump-package output. */ +const DUMPS: Record = { + "ios-xtool": "dump-AppXtool.json", + "ios/build/xcframeworks": "dump-ReactNative.json", + "ios/build/generated/ios": "dump-React-GeneratedCode.json", + "ios/build/generated/autolinking": "dump-Autolinked.json", + "node_modules/rn-lib": "dump-RNLib.json", + "node_modules/unreached-lib": "dump-UnreachedLib.json", +}; + +/** The alias fixtures: the root names its dependency `Foo`, whose manifest is `Bar`, in a folder named `ios`. */ +const ALIAS_DUMPS: Record = { + "alias/a": "alias/dump-a.json", + "alias/b/ios": "alias/dump-b.json", +}; + +interface Call { + args: string[]; + cwd: string; + env: NodeJS.ProcessEnv; +} + +/** A SwiftRunner over the fixtures; `answer` overrides a command's result. */ +function fakeSwift( + root: string, + answer: (args: string[]) => { code: number; stdout: string; stderr: string } | undefined = () => undefined, + dumps: Record = DUMPS, + shown = "show-dependencies.json", +) { + const calls: Call[] = []; + let inFlight = 0; + let maxInFlight = 0; + const run: SwiftRunner = async (args, opts) => { + calls.push({ args, cwd: opts.cwd, env: opts.env }); + inFlight++; + maxInFlight = Math.max(maxInFlight, inFlight); + await new Promise((r) => setTimeout(r, 5)); + inFlight--; + const given = answer(args); + if (given) return given; + if (args[1] === "show-dependencies") return { code: 0, stdout: fixture(shown, root), stderr: "" }; + if (args[1] === "dump-package") { + const rel = path.relative(root, args[args.indexOf("--package-path") + 1]!); + return { code: 0, stdout: fixture(dumps[rel]!, root), stderr: "" }; + } + throw new Error(`unexpected swift ${args.join(" ")}`); + }; + return { run, calls, maxInFlight: () => maxInFlight }; +} + +describe("precheckGraph", () => { + it("plans the package and refuses an executable App target", async () => { + const ios = path.join(t, "ios-xtool"); + // SwiftPM prints the plan and exits 1 when a `main` file makes App an executable target. + const exe = fakeSwift(t, () => ({ + code: 1, + stdout: fixture("describe-executable.json", t), + stderr: + "warning: 'ios-xtool': 'App' was identified as an executable target given the presence of a 'main' file.\n" + + "error: 'ios-xtool': library product 'App' should not contain executable targets (it has 'App')\n", + })); + const err = await planManifest(ios, exe.run).catch((e: unknown) => e); + expect(err).toBeInstanceOf(PrecheckError); + expect((err as Error).message).toBe( + "precheck — SwiftPM plans the App target as an executable target (a file named main); xtool links the app's entry point from the App library", + ); + expect(exe.calls).toEqual([{ args: ["package", "describe", "--type", "json"], cwd: ios, env: devEnv(ios) }]); + + const refused = fakeSwift(t, () => ({ + code: 1, + stdout: "", + stderr: "warning: 'ios-xtool': ignoring this\nerror: 'ios-xtool': target 'App' has overlapping sources: Sources/App/x.h\n", + })); + const refusal = await planManifest(ios, refused.run).catch((e: unknown) => e); + expect(refusal).toBeInstanceOf(PrecheckError); + expect((refusal as Error).message).toBe( + "precheck — SwiftPM refused the generated package (ios-xtool/Package.swift):\n" + + "error: 'ios-xtool': target 'App' has overlapping sources: Sources/App/x.h", + ); + + const silent = fakeSwift(t, () => ({ code: 0, stdout: "", stderr: "" })); + const noPlan = await planManifest(ios, silent.run).catch((e: unknown) => e); + expect(noPlan).toBeInstanceOf(PrecheckError); + expect((noPlan as Error).message).toContain("precheck — SwiftPM gave no plan for the generated package (ios-xtool/Package.swift)"); + + const app = fakeSwift(t, () => ({ code: 0, stdout: fixture("describe-app.json", t), stderr: "" })); + await expect(planManifest(ios, app.run)).resolves.toBeUndefined(); + }); + + it("collects the header folders reachable from App", () => { + const g = graphHeaders(graph); + const xcf = path.join(t, "ios/build/xcframeworks"); + const gen = path.join(t, "ios/build/generated/ios"); + expect(g.headerDirs).toEqual([ + path.join(xcf, "ReactHeadersTarget/include"), + path.join(xcf, "ReactNativeHeaders.xcframework/ios-arm64/Headers"), + path.join(xcf, "ReactNativeDependenciesHeaders.xcframework/ios-arm64/Headers"), + path.join(gen, "ReactCodegen/include"), + path.join(gen, "ReactAppDependencyProvider/include"), + path.join(t, "node_modules/rn-lib/ios/public"), + path.join(gen, "ReactAppHeaders/include"), + ]); + expect(g.moduleMaps).toEqual([ + path.join(xcf, "ReactNativeHeaders.xcframework/ios-arm64/Headers/module.modulemap"), + path.join(xcf, "ReactNativeDependenciesHeaders.xcframework/ios-arm64/Headers/module.modulemap"), + path.join(t, "node_modules/rn-lib/ios/public/module.modulemap"), + ]); + expect(JSON.stringify(g)).not.toContain("unreached-lib"); + }); + + it("synthesizes a module map as SwiftPM does", () => { + const g = graphHeaders(graph); + const gen = path.join(t, "ios/build/generated/ios"); + const xcf = path.join(t, "ios/build/xcframeworks"); + expect(g.synthesized).toEqual([ + { module: "ReactHeaders", text: `module ReactHeaders {\n umbrella "${xcf}/ReactHeadersTarget/include"\n export *\n}\n` }, + { + module: "ReactCodegen", + text: `module ReactCodegen {\n umbrella header "${gen}/ReactCodegen/include/ReactCodegen/ReactCodegen.h"\n export *\n}\n`, + }, + { + module: "ReactAppDependencyProvider", + text: `module ReactAppDependencyProvider {\n umbrella "${gen}/ReactAppDependencyProvider/include"\n export *\n}\n`, + }, + { + module: "ReactAppHeaders", + text: `module ReactAppHeaders {\n umbrella header "${gen}/ReactAppHeaders/include/ReactAppHeaders.h"\n export *\n}\n`, + }, + ]); + + // The module name is the target's C99 name, as SwiftPM spells it. + const lib = path.join(t, "c99"); + write(path.join(lib, "Sources/my-lib/include/my_lib.h")); + const app = { name: "App", type: "regular", dependencies: [{ byName: ["my-lib", null] }] }; + const own = graphHeaders({ + root: { name: "C99", path: lib, dependencies: [], products: [], targets: [app, { name: "my-lib", type: "regular", dependencies: [] }] }, + packages: [], + }); + expect(own.synthesized).toEqual([ + { module: "my_lib", text: `module my_lib {\n umbrella header "${lib}/Sources/my-lib/include/my_lib.h"\n export *\n}\n` }, + ]); + }); + + it("prefers the flat umbrella header, as SwiftPM does", () => { + const lib = path.join(t, "flat-first"); + write(path.join(lib, "Sources/Both/include/Both.h")); + write(path.join(lib, "Sources/Both/include/Both/Both.h")); + const app = { name: "App", type: "regular", dependencies: [{ byName: ["Both", null] }] }; + const g = graphHeaders({ + root: { name: "Flat", path: lib, dependencies: [], products: [], targets: [app, { name: "Both", type: "regular", dependencies: [] }] }, + packages: [], + }); + expect(g.synthesized).toEqual([ + { module: "Both", text: `module Both {\n umbrella header "${lib}/Sources/Both/include/Both.h"\n export *\n}\n` }, + ]); + }); + + it("synthesizes no module map for a module a map on disk declares", () => { + // Two maps of one module are a redefinition: the one on disk is the module's. + const lib = path.join(t, "declared"); + write(path.join(lib, "Sources/Maps/include/module.modulemap"), "module Maps {}\nmodule Other {}\n"); + write(path.join(lib, "Sources/Other/include/Other.h")); + const app = { name: "App", type: "regular", dependencies: [{ byName: ["Maps", null] }, { byName: ["Other", null] }] }; + const targets = [app, ...["Maps", "Other"].map((name) => ({ name, type: "regular", dependencies: [] }))]; + const g = graphHeaders({ root: { name: "Declared", path: lib, dependencies: [], products: [], targets }, packages: [] }); + expect(g.synthesized).toEqual([]); + expect(g.moduleMaps).toEqual([path.join(lib, "Sources/Maps/include/module.modulemap")]); + expect(g.headerDirs).toEqual([path.join(lib, "Sources/Maps/include"), path.join(lib, "Sources/Other/include")]); + expect(g.modules).toEqual(["Maps", "Other"]); + }); + + it("lists the graph's targets and modules", () => { + const g = graphHeaders(graph); + // Target names and product names: an angle include's first component is usually a product's (``). + expect(g.targets).toEqual([ + "App", + "RNXtoolDevSupport", + "ReactHeaders", + "ReactNativeHeaders", + "ReactNativeDependenciesHeaders", + "ReactCodegen", + "ReactAppDependencyProvider", + "ReactAppHeaders", + "AutolinkedAggregate", + "Autolinked", + "RNLib", + "RNLibSwift", + "UnreachedLib", + ]); + expect(g.modules).toEqual([ + "React", + "ReactNativeDependencies", + "RNLib", + "ReactHeaders", + "ReactCodegen", + "ReactAppDependencyProvider", + "ReactAppHeaders", + ]); + }); + + it("lists the modules of the targets SwiftPM builds from Swift", () => { + expect(graphHeaders(graph).swiftModules).toEqual(["RNLibSwift"]); + + const lib = path.join(t, "swift-modules"); + // A Swift target with an include folder (a synthesized map), a clang-only one, an Expo-style mixed target whose + // public headers folder is its whole folder, one whose `sources` list names its Swift, one whose Swift is excluded + // or in a dot folder, and a Swift-only target without headers. + write(path.join(lib, "Sources/X/Foo.swift")); + write(path.join(lib, "Sources/X/include/X.h")); + write(path.join(lib, "Sources/C/C.m")); + write(path.join(lib, "Sources/C/include/C.h")); + write(path.join(lib, "root/ios/Mix.swift")); + write(path.join(lib, "root/ios/Mix.h")); + write(path.join(lib, "root/ios/module.modulemap"), "module MixObjC {\n header \"Mix.h\"\n}\n"); + write(path.join(lib, "pager/ios/Pager.swift")); + write(path.join(lib, "pager/ios/Pager.h")); + write(path.join(lib, "Sources/E/E.m")); + write(path.join(lib, "Sources/E/include/E.h")); + write(path.join(lib, "Sources/E/Tests/ETests.swift")); + write(path.join(lib, "Sources/D/D.m")); + write(path.join(lib, "Sources/D/include/D.h")); + write(path.join(lib, "Sources/D/.build/Gen.swift")); + write(path.join(lib, "Sources/S/S.swift")); + const names = ["X", "C", "Mix", "Pager", "E", "D", "S"]; + const app = { name: "App", type: "regular", dependencies: names.map((n) => ({ byName: [n, null] })) }; + const targets = [ + app, + { name: "X", type: "regular", dependencies: [] }, + { name: "C", type: "regular", dependencies: [] }, + { name: "Mix", type: "regular", path: "root/ios", publicHeadersPath: ".", dependencies: [] }, + { name: "Pager", type: "regular", path: "pager", sources: ["ios/Pager.swift", "ios/Pager.h"], publicHeadersPath: "ios", dependencies: [] }, + { name: "E", type: "regular", exclude: ["Tests"], dependencies: [] }, + { name: "D", type: "regular", dependencies: [] }, + { name: "S", type: "regular", dependencies: [] }, + ]; + const g = graphHeaders({ root: { name: "SwiftModules", path: lib, dependencies: [], products: [], targets }, packages: [] }); + expect(g.modules).toEqual(expect.arrayContaining(["X", "C", "MixObjC", "Pager", "E", "D"])); + expect(g.swiftModules).toEqual(["X", "Mix", "MixObjC", "Pager", "S"]); + }); + + it("follows symlinked folders and leaves resources out when it looks for Swift", async () => { + const lib = path.join(t, "swift-links"); + // L's Swift is in a folder outside the target, linked in; Loop links to itself; R's only Swift file is a resource. + write(path.join(lib, "Sources/L/L.m")); + write(path.join(lib, "Sources/L/include/L.h")); + write(path.join(lib, "elsewhere/LSwift.swift")); + symlinkSync(path.join(lib, "elsewhere"), path.join(lib, "Sources/L/Swift")); + write(path.join(lib, "Sources/Loop/Loop.m")); + write(path.join(lib, "Sources/Loop/include/Loop.h")); + symlinkSync(path.join(lib, "Sources/Loop"), path.join(lib, "Sources/Loop/again")); + write(path.join(lib, "Sources/R/R.m")); + write(path.join(lib, "Sources/R/include/R.h")); + write(path.join(lib, "Sources/R/Assets/Template.swift")); + const names = ["L", "Loop", "R"]; + const targets = [ + { name: "App", type: "regular", dependencies: names.map((n) => ({ byName: [n, null] })) }, + { name: "L", type: "regular", dependencies: [] }, + { name: "Loop", type: "regular", dependencies: [] }, + { name: "R", type: "regular", resources: ["Assets"], dependencies: [] }, + ]; + const g = graphHeaders({ root: { name: "SwiftLinks", path: lib, dependencies: [], products: [], targets }, packages: [] }); + expect(g.modules).toEqual(expect.arrayContaining(["L", "Loop", "R"])); + expect(g.swiftModules).toEqual(["L"]); + + // dump-package names a resource by its path and rule. + const ios = path.join(t, "ios-xtool"); + const dump = JSON.parse(fixture("dump-AppXtool.json", t)) as { targets: Record[] }; + dump.targets[0]!.resources = [{ path: "Assets", rule: { process: {} } }, { path: "Info.plist", rule: { copy: {} } }]; + const swift = fakeSwift(t, (args) => + args[1] === "dump-package" && args[args.indexOf("--package-path") + 1] === ios ? { code: 0, stdout: JSON.stringify(dump), stderr: "" } : undefined, + ); + const read = await readPackageGraph(ios, path.join(t, "scratch-resources"), swift.run); + expect(read.root.targets[0]!.resources).toEqual(["Assets", "Info.plist"]); + }); + + it("runs dump-package with a scratch path outside the library", async () => { + const ios = path.join(t, "ios-xtool"); + const scratch = path.join(t, "scratch"); + const swift = fakeSwift(t); + const graph = await readPackageGraph(ios, scratch, swift.run); + + expect(swift.calls[0]).toEqual({ args: ["package", "show-dependencies", "--format", "json"], cwd: ios, env: devEnv(ios) }); + const dumps = swift.calls.slice(1); + expect(dumps.map((c) => c.args)).toEqual( + Object.keys(DUMPS).map((rel, n) => [ + "package", + "dump-package", + "--package-path", + path.join(t, rel), + "--scratch-path", + path.join(scratch, String(n)), + ]), + ); + for (const c of dumps) expect(c).toMatchObject({ cwd: ios, env: devEnv(ios) }); + expect(swift.maxInFlight()).toBe(2); + const read = await readPackageGraph(ios, scratch, fakeSwift(t).run); + expect([read.root, ...read.packages].map((p) => [p.name, p.path])).toEqual( + ["AppXtool", "ReactNative", "React-GeneratedCode", "Autolinked", "RNLib", "UnreachedLib"].map((name, n) => [name, path.join(t, Object.keys(DUMPS)[n]!)]), + ); + // The package-level dependencies, as the manifest names them: the alias SwiftPM resolves `package:` against. + expect(read.root.dependencies[0]).toEqual({ identity: "xcframeworks", name: "ReactNative", path: path.join(t, "ios/build/xcframeworks") }); + expect(read.packages[2]!.dependencies).toEqual([{ identity: "rn-lib", path: path.join(t, "node_modules/rn-lib") }]); + + const broken = fakeSwift(t, (args) => + args.includes(path.join(t, "node_modules/rn-lib")) + ? { code: 1, stdout: "", stderr: "error: Invalid manifest (compiled with: …)\nPackage.swift:3:1: error: cannot find 'Pakage' in scope\n" } + : undefined, + ); + const err = await readPackageGraph(ios, scratch, broken.run).catch((e: unknown) => e); + expect(err).toBeInstanceOf(PrecheckError); + expect((err as Error).message).toBe( + `precheck — SwiftPM could not read the package RNLib (${path.join(t, "node_modules/rn-lib")}):\n` + + "error: Invalid manifest (compiled with: …)\nPackage.swift:3:1: error: cannot find 'Pakage' in scope", + ); + }); + + it("resolves a product's package through the name the depending manifest gives it", async () => { + const swift = fakeSwift(t, () => undefined, ALIAS_DUMPS, "alias/show-dependencies.json"); + const aliased = await readPackageGraph(path.join(t, "alias/a"), path.join(t, "alias-scratch"), swift.run); + const g = graphHeaders(aliased); + expect(g.headerDirs).toEqual([path.join(t, "alias/b/ios/Sources/BarLib/include")]); + expect(g.unresolved).toEqual([]); + }); + + it("names an xcframework whose Info.plist it cannot read", () => { + const lib = path.join(t, "broken-xcframework"); + write(path.join(lib, "Broken.xcframework/Info.plist"), "AvailableLibraries"); + write(path.join(lib, "Gone.xcframework/ios-arm64/Headers/Gone.h")); + const app = { name: "App", type: "regular", dependencies: [{ byName: ["Broken", null] }] }; + const targets = (name: string) => [ + { ...app, dependencies: [{ byName: [name, null] }] }, + { name, type: "binary", path: `${name}.xcframework`, dependencies: [] }, + ]; + for (const name of ["Broken", "Gone"]) { + let err: unknown; + try { + graphHeaders({ root: { name: "Bin", path: lib, dependencies: [], products: [], targets: targets(name) }, packages: [] }); + } catch (e) { + err = e; + } + expect(err).toBeInstanceOf(PrecheckError); + expect((err as Error).message).toMatch( + new RegExp(`^precheck — rn-xtool could not read the xcframework ${name} \\(${path.join(lib, `${name}.xcframework`)}\\): `), + ); + } + // A binary target that is no xcframework folder (a zip archive) gives no headers, as before. + const zip = graphHeaders({ + root: { name: "Bin", path: lib, dependencies: [], products: [], targets: [{ ...app, dependencies: [{ byName: ["Z", null] }] }, { name: "Z", type: "binary", path: "Z.zip", dependencies: [] }] }, + packages: [], + }); + expect(zip.headerDirs).toEqual([]); + }); + + it("lists the references it cannot place, without stopping", () => { + const dir = path.join(t, "unplaced"); + const app = { + name: "App", + type: "regular", + dependencies: [{ product: ["Gone", "Missing", null, null] }, { byName: ["Nowhere", null] }, { product: ["NoSuch", "Present", null, null] }], + }; + const g = graphHeaders({ + root: { name: "Root", path: dir, dependencies: [{ identity: "present", path: path.join(dir, "present") }], products: [], targets: [app] }, + packages: [{ name: "Present", path: path.join(dir, "present"), dependencies: [], products: [], targets: [] }], + }); + expect(g.unresolved).toEqual(["Gone of Missing", "Nowhere", "NoSuch of Present"]); + expect(g.headerDirs).toEqual([]); + }); +}); diff --git a/tests/precheckReport.test.ts b/tests/precheckReport.test.ts new file mode 100644 index 0000000..95565b2 --- /dev/null +++ b/tests/precheckReport.test.ts @@ -0,0 +1,276 @@ +import { describe, expect, it } from "vitest"; +import { + parseDiagnostics, + precheckErrorLines, + precheckStop, + PrecheckError, + STALE_MODULE_CACHE, + type Diagnostic, +} from "../src/pipeline/precheckReport.js"; + +const same = (file: string): string => file; + +describe("parseDiagnostics", () => { + it("keeps the include stack of an error in a library header (F4)", () => { + const output = [ + "In file included from /p/ios-xtool/Sources/App/AppDelegate.mm:3:", + "In file included from /rn/RCTAppDelegate.h:9:", + "/rn/react/utils/hash_combine.h:21:3: error: unknown type name 'requires'", + " 21 | requires std::is_integral_v", + " | ^", + "1 error generated.", + "", + ].join("\n"); + expect(parseDiagnostics(output)).toEqual([ + { + file: "/rn/react/utils/hash_combine.h", + line: 21, + message: "unknown type name 'requires'", + stack: [ + "In file included from /p/ios-xtool/Sources/App/AppDelegate.mm:3:", + "In file included from /rn/RCTAppDelegate.h:9:", + ], + }, + ]); + }); + + it("drops warnings and notes", () => { + const output = [ + "/p/a/x.m:2:33: warning: unused variable 'y' [-Wunused-variable]", + " 2 | int y;", + " | ^", + "/p/a/x.m:4:1: note: previous definition is here", + "/p/a/x.m:5:7: error: redefinition of 'z'", + "1 warning and 1 error generated.", + ].join("\n"); + expect(parseDiagnostics(output)).toEqual([{ file: "/p/a/x.m", line: 5, message: "redefinition of 'z'", stack: [] }]); + }); + + it("reads a fatal error for a missing include with its stack", () => { + const output = [ + "In file included from /p/a/AppDelegate.mm:1:", + "/p/a/AppDelegate.h:2:9: fatal error: 'React/RCTBridge.h' file not found", + " 2 | #import ", + " | ^~~~~~~~~~~~~~~~~~~", + "1 error generated.", + ].join("\n"); + expect(parseDiagnostics(output)).toEqual([ + { + file: "/p/a/AppDelegate.h", + line: 2, + message: "'React/RCTBridge.h' file not found", + stack: ["In file included from /p/a/AppDelegate.mm:1:"], + }, + ]); + }); + + it("traces a module build back to the app's import", () => { + const output = [ + "While building module 'Foo' imported from /p/a/x.m:1:", + "In file included from :1:", + "In file included from /p/mod/foo.h:1:", + "/p/mod/bar.h:1:24: error: use of undeclared identifier 'nope'", + " 1 | int bad(void) { return nope; }", + " | ^~~~", + "/p/a/x.m:1:9: fatal error: could not build module 'Foo'", + "2 errors generated.", + ].join("\n"); + expect(parseDiagnostics(output)).toEqual([ + { + file: "/p/mod/bar.h", + line: 1, + message: "use of undeclared identifier 'nope'", + stack: [ + "While building module 'Foo' imported from /p/a/x.m:1:", + "In file included from :1:", + "In file included from /p/mod/foo.h:1:", + ], + }, + { file: "/p/a/x.m", line: 1, message: "could not build module 'Foo'", stack: [] }, + ]); + }); + + it("reads swiftc's errors and skips its excerpts, including their `- error: lines", () => { + const output = [ + "/p/a/A.swift:1:14: error: cannot convert value of type 'String' to specified type 'Int'", + "1 | let x: Int = \"a\"", + " | `- error: cannot convert value of type 'String' to specified type 'Int'", + "2 | func f() { g() }", + "3 | ", + "", + ].join("\n"); + expect(parseDiagnostics(output)).toEqual([ + { file: "/p/a/A.swift", line: 1, message: "cannot convert value of type 'String' to specified type 'Int'", stack: [] }, + ]); + }); + + it("keeps errors without a file or a column, as file '' and line 0", () => { + const output = [ + "error: generate-pch command failed with exit code 1 (use -v to see invocation)", + ":0: error: failed to emit precompiled header '/p/t/a.pch' for bridging header '/p/a/B.h'", + "clang: error: no such file or directory: '/p/a/x.m'", + "/p/a/A.swift:7: error: no column here", + ].join("\n"); + expect(parseDiagnostics(output)).toEqual([ + { file: "", line: 0, message: "generate-pch command failed with exit code 1 (use -v to see invocation)", stack: [] }, + { file: "", line: 0, message: "failed to emit precompiled header '/p/t/a.pch' for bridging header '/p/a/B.h'", stack: [] }, + { file: "", line: 0, message: "no such file or directory: '/p/a/x.m'", stack: [] }, + { file: "/p/a/A.swift", line: 7, message: "no column here", stack: [] }, + ]); + }); + + it("keeps a message that itself contains error:, and ignores one inside a source excerpt", () => { + const output = [ + "/p/a/x.m:3:5: error: expected ';' after 'error: x'", + " 3 | NSLog(@\"/p/b.m:9:1: error: not a diagnostic\")", + " | ^", + ].join("\n"); + expect(parseDiagnostics(output)).toEqual([ + { file: "/p/a/x.m", line: 3, message: "expected ';' after 'error: x'", stack: [] }, + ]); + }); + + it("reads CRLF output", () => { + const output = "In file included from /p/a/x.mm:1:\r\n/p/a/y.h:4:2: error: bad\r\n 4 | x\r\n"; + expect(parseDiagnostics(output)).toEqual([ + { file: "/p/a/y.h", line: 4, message: "bad", stack: ["In file included from /p/a/x.mm:1:"] }, + ]); + }); + + it("keeps the same error twice when clang reports it for two translation units", () => { + const err = "/p/a/two.h:1:18: error: incompatible pointer to integer conversion [-Wint-conversion]"; + const output = [err, "1 error generated.", err, "1 error generated."].join("\n"); + expect(parseDiagnostics(output)).toHaveLength(2); + }); + + it("keeps swiftc's include trail from a bridging header in the stack", () => { + // swiftc -typecheck A.swift -import-objc-header Bridge.h; Bridge.h imports lib/Top.h, which imports a broken Mid.h. + const output = [ + "error: generate-pch command failed with exit code 1 (use -v to see invocation)", + "/p/app/Bridge.h:1:9: note: in file included from /p/app/Bridge.h:1:", + "1 | #import \"lib/Top.h\"", + " | `- note: in file included from /p/app/Bridge.h:1:", + "2 | ", + "", + "/p/app/lib/Top.h:1:9: note: in file included from /p/app/lib/Top.h:1:", + "1 | #import \"Mid.h\"", + " | `- note: in file included from /p/app/lib/Top.h:1:", + "2 | ", + "", + "1 error generated.", + "/p/app/lib/Mid.h:1:24: error: use of undeclared identifier 'nope'", + "1 | int bad(void) { return nope; }", + " | `- error: use of undeclared identifier 'nope'", + "2 | ", + "", + ":0: error: failed to emit precompiled header '/p/t/a.pch' for bridging header '/p/app/Bridge.h'", + ].join("\n"); + expect(parseDiagnostics(output)).toEqual([ + { file: "", line: 0, message: "generate-pch command failed with exit code 1 (use -v to see invocation)", stack: [] }, + { + file: "/p/app/lib/Mid.h", + line: 1, + message: "use of undeclared identifier 'nope'", + stack: ["In file included from /p/app/Bridge.h:1:", "In file included from /p/app/lib/Top.h:1:"], + }, + { file: "", line: 0, message: "failed to emit precompiled header '/p/t/a.pch' for bridging header '/p/app/Bridge.h'", stack: [] }, + ]); + }); + + it("still drops swiftc's other notes", () => { + const output = [ + "/p/a/A.swift:3:6: note: 'f()' declared here", + "/p/a/A.swift:5:1: error: missing argument", + ].join("\n"); + expect(parseDiagnostics(output)).toEqual([{ file: "/p/a/A.swift", line: 5, message: "missing argument", stack: [] }]); + }); + + it("starts a fresh stack at each diagnostic", () => { + const output = [ + "In file included from /p/a/x.mm:1:", + "/p/a/y.h:4:2: warning: dropped", + "/p/a/y.h:5:2: error: after a warning", + ].join("\n"); + expect(parseDiagnostics(output)).toEqual([{ file: "/p/a/y.h", line: 5, message: "after a warning", stack: [] }]); + }); +}); + +describe("precheckErrorLines", () => { + const diag = (n: number): Diagnostic => ({ file: `/p/a/f${n}.m`, line: n, message: `bad ${n}`, stack: [] }); + + it("prints the first ten and counts the rest", () => { + const lines = precheckErrorLines( + Array.from({ length: 12 }, (_, i) => diag(i + 1)), + same, + ); + expect(lines.filter((l) => l.startsWith("✖ precheck — "))).toHaveLength(10); + expect(lines[0]).toBe("✖ precheck — /p/a/f1.m:1: bad 1"); + expect(lines.at(-1)).toBe("… and 2 more"); + expect(lines.join("\n")).not.toContain("f11.m"); + }); + + it("adds no count when there are ten or fewer", () => { + expect(precheckErrorLines([diag(1)], same)).toEqual(["✖ precheck — /p/a/f1.m:1: bad 1"]); + }); + + it("names the copy's source file", () => { + const display = (file: string): string => file.replace("/p/ios-xtool/Sources/App/AppMain.m", "ios/ObjcApp/main.m"); + const lines = precheckErrorLines( + [ + { + file: "/rn/React/RCTBridge.h", + line: 12, + message: "unknown type name 'X'", + stack: ["In file included from /p/ios-xtool/Sources/App/AppMain.m:3:"], + }, + { file: "/p/ios-xtool/Sources/App/AppMain.m", line: 7, message: "bad", stack: [] }, + ], + display, + ); + expect(lines).toEqual([ + "✖ precheck — /rn/React/RCTBridge.h:12: unknown type name 'X'", + " In file included from ios/ObjcApp/main.m:3:", + "✖ precheck — ios/ObjcApp/main.m:7: bad", + ]); + }); + + it("names a module build's importer through display", () => { + const display = (file: string): string => file.replace("/p/copy/", "ios/"); + const lines = precheckErrorLines( + [{ file: "/p/mod/bar.h", line: 1, message: "m", stack: ["While building module 'Foo' imported from /p/copy/x.m:1:"] }], + display, + ); + expect(lines[1]).toBe(" While building module 'Foo' imported from ios/x.m:1:"); + }); + + it("prints a file-less error by its message", () => { + expect(precheckErrorLines([{ file: "", line: 0, message: "generate-pch command failed", stack: [] }], same)).toEqual([ + "✖ precheck — generate-pch command failed", + ]); + }); +}); + +describe("precheckStop", () => { + it("names --skip-precheck in the stop", () => { + expect(precheckStop(3, "ios-xtool/.precheck/precheck.log").message).toContain("rn-xtool build --skip-precheck"); + }); + + it("says the plan's whole message", () => { + const stop = precheckStop(3, "ios-xtool/.precheck/precheck.log"); + expect(stop).toBeInstanceOf(PrecheckError); + expect(stop.message).toBe( + "precheck: 3 error(s) in the app's own sources before xtool-build (the first ten are above; all of them in " + + "ios-xtool/.precheck/precheck.log). If xtool-build compiles these files, this is a false stop: build with " + + "rn-xtool build --skip-precheck and report it with rn-xtool doctor --report", + ); + }); +}); + +describe("STALE_MODULE_CACHE", () => { + it("knows clang's stale-cache messages", () => { + expect(STALE_MODULE_CACHE.test("module file '/p/mc/Foo.pcm' is out of date and needs to be rebuilt")).toBe(true); + expect(STALE_MODULE_CACHE.test("file '/p/h.h' has been modified since the module file '/p/mc/Foo.pcm' was built")).toBe(true); + expect(STALE_MODULE_CACHE.test("malformed or corrupted AST file: 'x'")).toBe(true); + expect(STALE_MODULE_CACHE.test("unknown type name 'requires'")).toBe(false); + }); +}); diff --git a/tests/precheckToolchain.test.ts b/tests/precheckToolchain.test.ts new file mode 100644 index 0000000..1c928f1 --- /dev/null +++ b/tests/precheckToolchain.test.ts @@ -0,0 +1,137 @@ +/** + * The precheck with the real `clang` and `swiftc` and the Darwin SDK, on a tiny App target built from SDK headers only + * (SwiftPM's answers are faked: the target depends on no package). + */ +import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { execa } from "execa"; +import { afterAll, beforeAll, describe, expect, it } from "vitest"; +import { sdkBundle } from "../src/commands/setup.js"; +import type { GeneratedApp } from "../src/generate/iosXtool.js"; +import { projectPaths, swiftHeadersDir, type ProjectPaths } from "../src/paths.js"; +import { runPrecheck, type PrecheckDeps } from "../src/pipeline/precheck.js"; +import type { SwiftRunner } from "../src/pipeline/precheckGraph.js"; +import { PrecheckError } from "../src/pipeline/precheckReport.js"; +import { toolEnv } from "../src/tools/exec.js"; +import { SWIFT_TEST_TIMEOUT_MS, tool } from "./support/tools.js"; + +const IOS_SDK = path.join(sdkBundle(), "Developer", "Platforms", "iPhoneOS.platform", "Developer", "SDKs", "iPhoneOS.sdk"); +const HAS_IOS_TOOLS = existsSync(IOS_SDK) && tool("clang", ["--version"], { env: toolEnv() }).status === 0; + +/** SwiftPM's answers for a package whose App target depends on nothing. */ +const swift: SwiftRunner = async (args) => { + const json = (o: unknown) => ({ code: 0, stdout: JSON.stringify(o), stderr: "" }); + if (args[1] === "describe") return json({ name: "AppXtool", targets: [{ name: "App", type: "library" }] }); + if (args[1] === "show-dependencies") return json({ name: "appxtool", dependencies: [] }); + return json({ + name: "AppXtool", + dependencies: [], + products: [{ name: "App", targets: ["App"] }], + targets: [{ name: "App", type: "regular", path: "Sources/App", dependencies: [] }], + }); +}; + +/** The compile as the precheck runs it, for a test that changes its command line. */ +const compile: PrecheckDeps["compile"] = async (cmd, args, o) => { + const r = await execa(cmd, args, { cwd: o.cwd, env: o.env, extendEnv: false, reject: false, all: true }); + return { code: r.exitCode ?? 1, output: r.all ?? "" }; +}; + +/** A C++20 header: a `requires` clause, as React Native's headers have (F4). */ +const CXX20 = "template \n requires(sizeof(T) > 0)\nstruct Sized {};\n"; +/** A header that imports a module, as F5's library header does. */ +const AT_IMPORT = "@import Foundation;\n"; + +describe.skipIf(!HAS_IOS_TOOLS)( + `the precheck on the real toolchain${HAS_IOS_TOOLS ? "" : " (needs the Darwin SDK and the Swift toolchain's clang: rn-xtool setup)"}`, + () => { + let root = ""; + let paths: ProjectPaths; + beforeAll(() => { + root = realpathSync(mkdtempSync(path.join(tmpdir(), "xt-precheck-real-"))); + paths = projectPaths(root); + }); + afterAll(() => { + if (root) rmSync(root, { recursive: true, force: true }); + }); + + /** The App target with `files` (relative to ios/App) copied into Sources/App; the run's terminal lines in `logs`. */ + async function precheck(files: Record, deps: Partial = {}): Promise<{ logs: string[]; error?: unknown }> { + rmSync(paths.sources, { recursive: true, force: true }); + const origins: Record = {}; + for (const [rel, text] of Object.entries(files)) { + for (const file of [path.join(root, "ios", "App", rel), path.join(paths.sources, rel)]) { + mkdirSync(path.dirname(file), { recursive: true }); + writeFileSync(file, text); + } + origins[path.join(paths.sources, rel)] = path.join(root, "ios", "App", rel); + } + const app: GeneratedApp = { + pkg: { + iosDir: paths.ios, + frameworks: [], + iosMin: "16.4", + app: { mixed: true, defines: [], headerSearchPaths: [], swiftHeadersDir: swiftHeadersDir(paths.iosXtool) }, + }, + origins, + }; + const logs: string[] = []; + const opts = { root, rnVersion: "0.88.1", clean: false, log: (s: string) => logs.push(s) }; + try { + await runPrecheck(paths, app, opts, { swift, ...deps }); + return { logs }; + } catch (error) { + return { logs, error }; + } + } + + it( + "F4: an Objective-C++ file that needs C++20 fails without the manifest's -std and passes with it", + async () => { + const files = { "Sized.h": CXX20, "Uses.mm": '#import \n#import "Sized.h"\n' }; + // Swift Build's F4: the target's C++ standard not applied, clang's default instead. + const withoutStd = await precheck(files, { compile: (cmd, args, o) => compile(cmd, args.filter((a) => !a.startsWith("-std=")), o) }); + expect(withoutStd.error).toBeInstanceOf(PrecheckError); + expect(withoutStd.logs[0]).toMatch(/^✖ precheck — ios\/App\/Sized\.h:2: /); + expect(withoutStd.logs[1]).toBe(" In file included from ios/App/Uses.mm:2:"); + + const withStd = await precheck(files); + expect(withStd.error).toBeUndefined(); + expect(withStd.logs).toEqual([]); + }, + SWIFT_TEST_TIMEOUT_MS, + ); + + it( + "F5: an @import in a header a .mm includes fails as in Swift Build", + async () => { + const { logs, error } = await precheck({ "Mod.h": AT_IMPORT, "Uses.mm": '#import "Mod.h"\n' }); + expect(error).toBeInstanceOf(PrecheckError); + expect(logs).toEqual([ + expect.stringMatching(/^✖ precheck — ios\/App\/Mod\.h:1: use of '@import' when modules are disabled/), + " In file included from ios/App/Uses.mm:1:", + ]); + expect(readFileSync(path.join(paths.iosXtool, ".precheck", "precheck.log"), "utf8")).toContain("-fno-cxx-modules"); + }, + SWIFT_TEST_TIMEOUT_MS, + ); + + it( + "writes App-Swift.h from swiftc -typecheck", + async () => { + const { logs, error } = await precheck({ + "Greeter.swift": "import Foundation\n\n@objc public class Greeter: NSObject {\n @objc public func hello() -> String { \"hi\" }\n}\n", + "Uses.m": '#import \n#import "App-Swift.h"\n\nstatic NSString *greet(void) { return [[Greeter new] hello]; }\n', + }); + expect(error).toBeUndefined(); + expect(logs).toEqual([]); + const header = path.join(paths.iosXtool, ".precheck", "swift-headers", "App-Swift.h"); + expect(readFileSync(header, "utf8")).toContain("@interface Greeter"); + // swiftc's temporary folders went with the run's TMPDIR. + expect(existsSync(path.join(paths.iosXtool, ".precheck", "tmp"))).toBe(false); + }, + SWIFT_TEST_TIMEOUT_MS, + ); + }, +); diff --git a/tests/project/pbxproj.test.ts b/tests/project/pbxproj.test.ts index 48bb17d..6ada0b3 100644 --- a/tests/project/pbxproj.test.ts +++ b/tests/project/pbxproj.test.ts @@ -3,7 +3,15 @@ import { tmpdir } from "node:os"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { afterEach, describe, expect, it } from "vitest"; -import { buildSetting, openPbxproj, readTargetContent, resolveBuildSettingValue, resolveSetting } from "../../src/project/pbxproj.js"; +import { DetectError } from "../../src/project/detect.js"; +import { + appXcconfigWarnings, + buildSetting, + openPbxproj, + readTargetContent, + resolveBuildSettingValue, + resolveSetting, +} from "../../src/project/pbxproj.js"; const fixtures = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "fixtures"); const templateIos = path.join(fixtures, "bare", "ios"); @@ -424,3 +432,97 @@ describe("readTargetContent", () => { expect(rel(content().swiftSources)).toContain("HelloWorld/MainView.swift"); }); }); + +describe("the app target's shape", () => { + const withObjc = () => readFile(path.join(fixtures, "pbxproj", "with-objc.pbxproj"), "utf8"); + const XCCONFIG_REF = "C50000000000000000000A01"; + const TARGET_DEBUG_BASE = "baseConfigurationReference = 3B4392A12AC88292D35C810B /* Pods-HelloWorld.debug.xcconfig */;"; + const PROJECT_DEBUG = "83CBBA201A601CBA00E9B192 /* Debug */ = {\n\t\t\tisa = XCBuildConfiguration;\n"; + + /** with-objc.pbxproj with ios/Config/App.xcconfig in the main group, the base of the target's and/or project's Debug. */ + async function withAppXcconfig(o: { target: boolean; project: boolean }): Promise { + let src = (await withObjc()) + .replace( + "/* End PBXFileReference section */", + `\t\t${XCCONFIG_REF} = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = Config/App.xcconfig; sourceTree = ""; };\n/* End PBXFileReference section */`, + ) + .replace("83CBB9F61A601CBA00E9B192 = {\n\t\t\tisa = PBXGroup;\n\t\t\tchildren = (\n", `$&\t\t\t\t${XCCONFIG_REF},\n`); + expect(src).toContain(`\t\t\t\t${XCCONFIG_REF},\n`); + if (o.target) { + expect(src).toContain(TARGET_DEBUG_BASE); + src = src.replace(TARGET_DEBUG_BASE, `baseConfigurationReference = ${XCCONFIG_REF};`); + } + if (o.project) { + expect(src).toContain(PROJECT_DEBUG); + src = src.replace(PROJECT_DEBUG, `$&\t\t\tbaseConfigurationReference = ${XCCONFIG_REF};\n`); + } + return src; + } + + /** A temp project root holding ios/HelloWorld.xcodeproj/project.pbxproj and `files` (paths relative to ios/). */ + async function rootWith(pbxproj: string, files: Record = {}): Promise { + const root = await mkdtemp(path.join(tmpdir(), "rn-xtool-xcconfig-")); + tempDirs.push(root); + await mkdir(path.join(root, "ios", "HelloWorld.xcodeproj"), { recursive: true }); + await writeFile(path.join(root, "ios", "HelloWorld.xcodeproj", "project.pbxproj"), pbxproj); + for (const [rel, text] of Object.entries(files)) { + await mkdir(path.dirname(path.join(root, "ios", rel)), { recursive: true }); + await writeFile(path.join(root, "ios", rel), text); + } + return root; + } + const warnings = (root: string) => appXcconfigWarnings(openPbxproj(path.join(root, "ios")), root); + + it("warns about an xcconfig that sets a setting rn-xtool reads", async () => { + const root = await rootWith(await withAppXcconfig({ target: true, project: true }), { + "Config/App.xcconfig": 'HEADER_SEARCH_PATHS = $(inherited) Vendor\nOTHER_LDFLAGS = -lz\n#include "Base.xcconfig"', + // Base.xcconfig includes App.xcconfig back, and an optional file that is not there. + "Config/Base.xcconfig": 'GCC_PREPROCESSOR_DEFINITIONS[config=Debug] = X=1\n#include? "App.xcconfig"\n#include? "Local.xcconfig"', + }); + expect(warnings(root)).toEqual([ + "⚠ ios/Config/App.xcconfig sets HEADER_SEARCH_PATHS, GCC_PREPROCESSOR_DEFINITIONS for the app target; rn-xtool does not read xcconfig files", + ]); + }); + + it("says nothing about CocoaPods' xcconfigs or one that sets nothing rn-xtool reads", async () => { + expect(warnings(await rootWith(await withObjc()))).toEqual([]); + const root = await rootWith(await withAppXcconfig({ target: true, project: false }), { + "Config/App.xcconfig": + "OTHER_LDFLAGS = -lz\nMY_HEADER_SEARCH_PATHS = Vendor\n// HEADER_SEARCH_PATHS = Vendor\n" + + '#include "../Pods/Target Support Files/Pods-HelloWorld/Pods-HelloWorld.debug.xcconfig"', + "Pods/Target Support Files/Pods-HelloWorld/Pods-HelloWorld.debug.xcconfig": "HEADER_SEARCH_PATHS = Pods/Headers", + }); + expect(warnings(root)).toEqual([]); + }); + + it("names an xcconfig it cannot read", async () => { + const root = await rootWith(await withAppXcconfig({ target: false, project: true })); + expect(warnings(root)).toEqual([ + "⚠ ios/Config/App.xcconfig (the app target's base configuration) could not be read; rn-xtool does not read xcconfig files", + ]); + }); + + it("refuses a synchronized folder in the app target", async () => { + const SYNCED = "C60000000000000000000A01"; + const src = (await readFile(path.join(fixtures, "objc-app", "ios", "ObjcApp.xcodeproj", "project.pbxproj"), "utf8")) + .replace( + "/* Begin PBXGroup section */", + "/* Begin PBXFileSystemSynchronizedRootGroup section */\n" + + `\t\t${SYNCED} /* ObjcApp */ = {isa = PBXFileSystemSynchronizedRootGroup; path = ObjcApp; sourceTree = ""; };\n` + + "/* End PBXFileSystemSynchronizedRootGroup section */\n\n/* Begin PBXGroup section */", + ) + .replace("\t\t\t\t13B07FAE1A68108700A75B9A /* ObjcApp */,\n\t\t\t\t83CBBA001A601CBA00E9B192", `\t\t\t\t${SYNCED} /* ObjcApp */,\n\t\t\t\t83CBBA001A601CBA00E9B192`) + .replace("\t\t\tdependencies = (\n\t\t\t);\n", `$&\t\t\tfileSystemSynchronizedGroups = (\n\t\t\t\t${SYNCED} /* ObjcApp */,\n\t\t\t);\n`) + .replace(/(isa = PBXSourcesBuildPhase;\n\t\t\tbuildActionMask = 2147483647;\n\t\t\tfiles = \()[^)]*\)/, "$1\n\t\t\t)"); + expect(src.match(new RegExp(SYNCED, "g"))).toHaveLength(3); + expect(src).not.toContain("AppDelegate.mm in Sources */,"); + const ios = await iosWith(["ObjcApp"], src); + const content = () => readTargetContent(openPbxproj(ios), ios); + expect(content).toThrow(DetectError); + expect(content).toThrow( + "The app target ObjcApp takes its files from the synchronized folder ObjcApp (an Xcode 16 folder group); " + + "rn-xtool reads only the files a target lists. Convert the folder to a group (Xcode: Convert to Group) " + + "so the target lists its files", + ); + }); +}); diff --git a/tests/report.test.ts b/tests/report.test.ts index 35094f7..d4d857c 100644 --- a/tests/report.test.ts +++ b/tests/report.test.ts @@ -8,6 +8,7 @@ import { capabilityChecks, renderReport, type DoctorProbes, type ProjectProbe } import { MissingBundleIdentifierError } from "../src/project/index.js"; import { doctorReport, + precheckReportLine, realReportEnv, recordingProbes, redact, @@ -152,6 +153,7 @@ describe("doctorReport", () => { `xtool: ${XTOOL_VERSION}`, "ruby: 9.9.9", "podspec reader: not recorded", + "precheck: not recorded", "os: Ubuntu 24.04.1 LTS, Linux 6.8.0-45-generic, x64", "project: expo, Expo SDK 58, expo 58.0.21, react-native 0.88.1", "✔ node — 24.15.0", @@ -258,11 +260,12 @@ describe("doctorReport", () => { it("says the toolchain was not checked with --project", async () => { const lines = (await doctorReport("/home/me/apps/demo", { env, probes, projectOnly: true })).split("\n"); - expect(lines.slice(4, 10)).toEqual([ + expect(lines.slice(4, 11)).toEqual([ "swift: not checked (--project)", "xtool: not checked (--project)", "ruby: 9.9.9", "podspec reader: not recorded", + "precheck: not recorded", "os: Ubuntu 24.04.1 LTS, Linux 6.8.0-45-generic, x64", "project: expo, Expo SDK 58, expo 58.0.21, react-native 0.88.1", ]); @@ -290,13 +293,14 @@ describe("doctorReport", () => { ); const lines = (await doctorReport(root, { env, probes })).split("\n"); const at = lines.indexOf(`xtool: ${XTOOL_VERSION}`); - expect(lines.slice(at + 1, at + 5)).toEqual([ + expect(lines.slice(at + 1, at + 6)).toEqual([ "ruby: 9.9.9", "podspec reader: reduced: RN_XTOOL_PODSPEC_READER=reduced is set (last rn-spm, 2 podspecs)", "podspec ENV:", " node_modules/x/X.podspec: RCT_NEW_ARCH_ENABLED, USE_FRAMEWORKS", + "precheck: not recorded", ]); - expect(lines[at + 5]).toMatch(/^os: /); + expect(lines[at + 6]).toMatch(/^os: /); // Inside the block: the fence closes after them. expect(lines.indexOf("```")).toBeGreaterThan(at + 4); @@ -307,6 +311,30 @@ describe("doctorReport", () => { expect(ruby.some((l) => l.startsWith("podspec ENV:"))).toBe(false); }); + it("records whether the last build skipped the precheck", async () => { + const root = await tempDir("rn-xtool-report-precheck-"); + const state = { version: 1, metroPort: 8081, lanIp: "10.0.0.7", bundleIdentifier: "com.example.app", builtAt: "" }; + const precheckLine = async (precheck?: string): Promise => { + await mkdir(path.join(root, "ios-xtool"), { recursive: true }); + await writeFile(path.join(root, "ios-xtool", ".rn-xtool-state.json"), JSON.stringify({ ...state, precheck })); + const lines = (await doctorReport(root, { env, probes })).split("\n"); + const at = lines.indexOf("podspec reader: not recorded"); + expect(lines[at + 2]).toMatch(/^os: /); + expect(lines.indexOf("```", 1)).toBeGreaterThan(at + 1); + return lines[at + 1]; + }; + expect(await precheckLine("skipped")).toBe("precheck: skipped with --skip-precheck (last build)"); + expect(await precheckLine("run")).toBe("precheck: run (last build)"); + // A state from before the precheck, an unreadable one, none at all: not recorded. + expect(await precheckLine(undefined)).toBe("precheck: not recorded"); + await writeFile(path.join(root, "ios-xtool", ".rn-xtool-state.json"), "{ not json"); + expect((await doctorReport(root, { env, probes })).split("\n")).toContain("precheck: not recorded"); + await rm(path.join(root, "ios-xtool"), { recursive: true }); + expect((await doctorReport(root, { env, probes })).split("\n")).toContain("precheck: not recorded"); + expect((await doctorReport(undefined, { env, probes })).split("\n")).toContain("precheck: not recorded"); + expect(precheckReportLine(undefined)).toBe("precheck: not recorded"); + }); + it("records no reader without a project", async () => { const lines = (await doctorReport(undefined, { env, probes })).split("\n"); expect(lines).toContain("podspec reader: not recorded"); diff --git a/tests/start.test.ts b/tests/start.test.ts index 4742685..8996e63 100644 --- a/tests/start.test.ts +++ b/tests/start.test.ts @@ -581,6 +581,15 @@ describe("run", () => { expect(calls).toEqual(["build:true", "install", "start"]); }); + it("passes --skip-precheck through to build", async () => { + const build = vi.fn(async () => {}); + const { overrides } = fresh({ readState: async () => undefined, build }); + await runCommand("/p", { skipPrecheck: true }, overrides); + expect(build).toHaveBeenCalledWith("/p", { clean: undefined, skipPrecheck: true }); + await runCommand("/p", {}, overrides); + expect(build).toHaveBeenLastCalledWith("/p", { clean: undefined, skipPrecheck: undefined }); + }); + it("reinstalls when a different iPhone is connected over USB", async () => { const { calls, overrides } = fresh({ readState: async () => ({ ...state, installedUdid: "00008030-0000000000000001" }), diff --git a/tests/support/objcApp.ts b/tests/support/objcApp.ts new file mode 100644 index 0000000..d603d62 --- /dev/null +++ b/tests/support/objcApp.ts @@ -0,0 +1,34 @@ +/** + * The Objective-C fixture app (React Native's pre-0.77 Objective-C template, MIT) copied into a temp project root. + * `template`: the template's layout (`ios/ObjcApp/{main.m,AppDelegate.h,AppDelegate.mm}`); `root-group`: the trial's + * layout, those three files next to `ios/ObjcApp.xcodeproj` and in the project's main group (Info.plist stays in + * `ios/ObjcApp`). + */ +import { cpSync, copyFileSync, mkdirSync, mkdtempSync, realpathSync, renameSync, rmSync, writeFileSync } from "node:fs"; +import { tmpdir } from "node:os"; +import path from "node:path"; +import { afterAll } from "vitest"; + +const FIXTURES = path.join(import.meta.dirname, "..", "fixtures"); +const ROOT_GROUP_FILES = ["main.m", "AppDelegate.h", "AppDelegate.mm"]; + +const tmp: string[] = []; +afterAll(() => { + for (const d of tmp.splice(0)) rmSync(d, { recursive: true, force: true }); +}); + +/** The temp project root (its real path), with `node_modules/react-native/package.json` at 0.88.1 and nothing else installed. */ +export function objcApp(layout: "template" | "root-group"): string { + const root = realpathSync(mkdtempSync(path.join(tmpdir(), "xt-objc-"))); + tmp.push(root); + cpSync(path.join(FIXTURES, "objc-app"), root, { recursive: true }); + const rn = path.join(root, "node_modules", "react-native"); + mkdirSync(rn, { recursive: true }); + writeFileSync(path.join(rn, "package.json"), JSON.stringify({ name: "react-native", version: "0.88.1" })); + if (layout === "root-group") { + const ios = path.join(root, "ios"); + copyFileSync(path.join(FIXTURES, "pbxproj", "objc-root-group.pbxproj"), path.join(ios, "ObjcApp.xcodeproj", "project.pbxproj")); + for (const name of ROOT_GROUP_FILES) renameSync(path.join(ios, "ObjcApp", name), path.join(ios, name)); + } + return root; +}