Skip to content

Commit

Permalink
fix(cli): check Pods Manifest.lock earlier (#3374)
Browse files Browse the repository at this point in the history
  • Loading branch information
tido64 authored Oct 2, 2024
1 parent 52d0318 commit cc857ea
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 19 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-bats-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rnx-kit/cli": patch
---

Check Pods Manifest.lock earlier
6 changes: 6 additions & 0 deletions .changeset/wet-carrots-happen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@rnx-kit/tools-apple": patch
---

Added a new function, `checkPodsManifestLock`, for checking whether the
CocoaPods sandbox is in sync with its `Podfile.lock`
22 changes: 17 additions & 5 deletions packages/cli/src/build/apple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,21 @@ export function runBuild(
buildParams: AppleBuildParams,
logger: Ora
): Promise<BuildResult> {
return import("@rnx-kit/tools-apple").then(({ xcodebuild }) => {
const log = (message: string) => logger.info(message);
const build = xcodebuild(xcworkspace, buildParams, log);
return watch(build, logger, () => ({ xcworkspace, args: build.spawnargs }));
});
return import("@rnx-kit/tools-apple").then(
({ checkPodsManifestLock, xcodebuild }) => {
if (!checkPodsManifestLock(xcworkspace)) {
logger.fail(
"CocoaPods sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation."
);
return Promise.resolve(1);
}

const log = (message: string) => logger.info(message);
const build = xcodebuild(xcworkspace, buildParams, log);
return watch(build, logger, () => ({
xcworkspace,
args: build.spawnargs,
}));
}
);
}
2 changes: 1 addition & 1 deletion packages/cli/src/build/watcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function watch<T>(
logger.succeed("Build succeeded");
resolve(onSuccess());
} else {
logger.fail(Buffer.concat(errors).toString());
logger.fail(Buffer.concat(errors).toString().trim());
process.exitCode = code ?? 1;
resolve(code);
}
Expand Down
27 changes: 14 additions & 13 deletions packages/tools-apple/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@ import * as tools from "@rnx-kit/tools-apple";
<!-- The following table can be updated by running `yarn update-readme` -->
<!-- @rnx-kit/api start -->

| Category | Function | Description |
| -------- | ------------------------------------------------------------------ | ----------------------------------------------------------------------------------------- |
| ios | `bootSimulator(simulator)` | Boots the simulator with the specified UDID. |
| ios | `getAvailableSimulators(search)` | Returns a list of available iOS simulators. |
| ios | `getDevices()` | Returns a list of available iOS simulators and physical devices. |
| ios | `install(device, app)` | Installs the specified app bundle on specified simulator or physical device. |
| ios | `launch(device, app)` | Launches the specified app bundle on specified simulator or physical device. |
| ios | `selectDevice(deviceNameOrPlatformIdentifier, deviceType, logger)` | Returns the simulator or physical device with the specified name. |
| xcode | `getBuildSettings(xcworkspace, params)` | Returns build settings for specified Xcode workspace and the parameters used to build it. |
| xcode | `getDeveloperDirectory()` | Returns the path to the active developer directory. |
| xcode | `getDevicePlatformIdentifier(buildParams)` | Returns device platform identifier for specified platform and destination. |
| xcode | `parsePlist(app)` | Parses and returns the information property list of specified bundle. |
| xcode | `xcodebuild(xcworkspace, params, log)` | Builds the specified `.xcworkspace`. |
| Category | Function | Description |
| --------- | ------------------------------------------------------------------ | ----------------------------------------------------------------------------------------- |
| cocoapods | `checkPodsManifestLock(xcworkspace)` | Returns whether the CocoaPods sandbox is in sync with its `Podfile.lock`. |
| ios | `bootSimulator(simulator)` | Boots the simulator with the specified UDID. |
| ios | `getAvailableSimulators(search)` | Returns a list of available iOS simulators. |
| ios | `getDevices()` | Returns a list of available iOS simulators and physical devices. |
| ios | `install(device, app)` | Installs the specified app bundle on specified simulator or physical device. |
| ios | `launch(device, app)` | Launches the specified app bundle on specified simulator or physical device. |
| ios | `selectDevice(deviceNameOrPlatformIdentifier, deviceType, logger)` | Returns the simulator or physical device with the specified name. |
| xcode | `getBuildSettings(xcworkspace, params)` | Returns build settings for specified Xcode workspace and the parameters used to build it. |
| xcode | `getDeveloperDirectory()` | Returns the path to the active developer directory. |
| xcode | `getDevicePlatformIdentifier(buildParams)` | Returns device platform identifier for specified platform and destination. |
| xcode | `parsePlist(app)` | Parses and returns the information property list of specified bundle. |
| xcode | `xcodebuild(xcworkspace, params, log)` | Builds the specified `.xcworkspace`. |

<!-- @rnx-kit/api end -->
5 changes: 5 additions & 0 deletions packages/tools-apple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
"typescript": "./src/index.ts",
"default": "./lib/index.js"
},
"./cocoapods": {
"types": "./lib/cocoapods.d.ts",
"typescript": "./src/cocoapods.ts",
"default": "./lib/cocoapods.js"
},
"./ios": {
"types": "./lib/ios.d.ts",
"typescript": "./src/ios.ts",
Expand Down
45 changes: 45 additions & 0 deletions packages/tools-apple/src/cocoapods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import * as fs from "node:fs";
import * as path from "node:path";

function equalFiles(aPath: string, bPath: string): boolean {
if (fs.lstatSync(aPath).size !== fs.lstatSync(bPath).size) {
return false;
}

const af = fs.openSync(aPath, "r");
const bf = fs.openSync(bPath, "r");

const bufsize = 16 * 1024;
const aBuf = Buffer.alloc(bufsize);
const bBuf = Buffer.alloc(bufsize);

try {
let aRead = 0;
do {
aRead = fs.readSync(af, aBuf, 0, aBuf.length, null);
const bRead = fs.readSync(bf, bBuf, 0, bBuf.length, null);
if (aRead !== bRead || !aBuf.equals(bBuf)) {
return false;
}
} while (aRead > 0);
} finally {
fs.closeSync(af);
fs.closeSync(bf);
}

return true;
}

/**
* Returns whether the CocoaPods sandbox is in sync with its `Podfile.lock`.
*/
export function checkPodsManifestLock(xcworkspace: string): boolean {
const workspaceDir = path.dirname(xcworkspace);
const podfileLock = path.join(workspaceDir, "Podfile.lock");
const manifestLock = path.join(workspaceDir, "Pods", "Manifest.lock");
return (
fs.existsSync(podfileLock) &&
fs.existsSync(manifestLock) &&
equalFiles(podfileLock, manifestLock)
);
}
1 change: 1 addition & 0 deletions packages/tools-apple/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { checkPodsManifestLock } from "./cocoapods.js";
export {
bootSimulator,
getAvailableSimulators,
Expand Down

0 comments on commit cc857ea

Please sign in to comment.