mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
fix: make an interrupted React-Core-prebuilt swap recoverable (#57831)
Summary: `replace-rncore-version.js` writes `.last_build_configuration` only after it has already replaced `React.xcframework`, so a build cancelled between those two steps leaves the marker naming a flavor that is no longer on disk, and when the marker is absent entirely the script assumes the on-disk flavor is Debug. Either state makes the next build for that configuration take the "no need to replace" path and link against the other configuration's core, which fails with undefined C++ symbols for `Props`, `DebugStringConvertible` and the Fabric vtables, and nothing corrects it afterwards because the pod directory survives a clean. This change writes the marker before the framework is touched, using a value that is not a valid configuration, so a later run can tell that the previous swap did not finish and replaces again. The fresh install path now also records the configuration it assumed instead of leaving that state implicit, which is sound because a swap can no longer leave the marker missing. Fixes https://github.com/react/react-native/issues/57598. ## Changelog: [IOS] [FIXED] - Recover React-Core-prebuilt configuration swaps that were interrupted before the marker was updated Pull Request resolved: https://github.com/react/react-native/pull/57831 Test Plan: Four new cases in `packages/react-native/scripts/__tests__/replace-rncore-version-test.js`, driven through the real CLI entry point the podspec `[RNCore]` build phase uses, so no new export was needed and the production diff is logic only. Against unmodified upstream two of them fail, one with `ENOENT` on `.last_build_configuration` because the skip path never wrote the marker, and one showing the marker still naming the stale flavor after a failed swap. With the change the file is 8 passed, including all 4 pre-existing tests. `prettier --check` is clean on both files. The actual iOS link failure needs a prebuilt-core CocoaPods install and an Xcode build, so that was not reproduced locally. Reviewed By: cipolleschi Differential Revision: D114900617 Pulled By: fabriziocucci fbshipit-source-id: 5d7f9b7be9cf1dd1728daa1e98ff51b87b924d2c
This commit is contained in:
1 parent
5821fcaf5d
commit
a772a7ca16
2 files changed
+97
-2
No files matched your search
@@ -19,6 +19,18 @@ const path = require('node:path');
|
||||
const VERSION = '0.87.0-test';
|
||||
const SLICE = 'ios-arm64_x86_64-simulator';
|
||||
const BINARY = path.join(SLICE, 'React.framework', 'React');
|
||||
const SCRIPT = require.resolve('../replace-rncore-version.js');
|
||||
const MARKER = path.join('React-Core-prebuilt', '.last_build_configuration');
|
||||
|
||||
// Runs the script the way the "[RNCore] Replace React Native Core for the right
|
||||
// configuration" build phase does, from Pods/ and through the CLI entry point.
|
||||
function runScriptPhase(podsRoot, configuration) {
|
||||
return execFileSync(
|
||||
process.execPath,
|
||||
[SCRIPT, '-c', configuration, '-r', VERSION, '-p', podsRoot],
|
||||
{cwd: podsRoot, encoding: 'utf8'},
|
||||
);
|
||||
}
|
||||
|
||||
function writeFile(filePath, contents) {
|
||||
fs.mkdirSync(path.dirname(filePath), {recursive: true});
|
||||
@@ -119,6 +131,73 @@ describe('replaceRNCoreConfiguration', () => {
|
||||
expect(fs.readFileSync(expoModuleMap, 'utf8')).toBe('module React {}\n');
|
||||
});
|
||||
|
||||
// Regression tests for #57598. The marker used to be written only after the
|
||||
// framework had already been replaced, so a build cancelled in between left it
|
||||
// naming a flavor that was no longer on disk. Every later build for that
|
||||
// flavor then took the "nothing to do" path and linked against the other
|
||||
// configuration's core, which fails with undefined C++ symbols and which a
|
||||
// clean does not undo because the pod directory survives it.
|
||||
describe('marker bookkeeping', () => {
|
||||
const marker = () => path.join(podsRoot, MARKER);
|
||||
const binary = () =>
|
||||
fs.readFileSync(path.join(pod, 'React.xcframework', BINARY), 'utf8');
|
||||
|
||||
it('records the configuration when it skips a fresh install', () => {
|
||||
// `pod install` leaves the debug flavor and no marker, so a Debug build
|
||||
// has nothing to swap. It still has to write down what is on disk,
|
||||
// otherwise the state stays implicit and stays unverifiable.
|
||||
expect(fs.existsSync(marker())).toBe(false);
|
||||
|
||||
runScriptPhase(podsRoot, 'Debug');
|
||||
|
||||
expect(fs.readFileSync(marker(), 'utf8')).toBe('Debug');
|
||||
expect(binary()).toBe('binary-Debug');
|
||||
});
|
||||
|
||||
it('invalidates the marker before it touches the framework', () => {
|
||||
fs.writeFileSync(marker(), 'Debug');
|
||||
// Drop the tarball so the Release run fails once it is already under way,
|
||||
// standing in for a build cancelled part way through the swap.
|
||||
fs.rmSync(
|
||||
path.join(
|
||||
podsRoot,
|
||||
'ReactNativeCore-artifacts',
|
||||
`reactnative-core-${VERSION.toLowerCase()}-release.tar.gz`,
|
||||
),
|
||||
);
|
||||
|
||||
expect(() => runScriptPhase(podsRoot, 'Release')).toThrow();
|
||||
|
||||
// The marker must no longer claim Debug: the framework may already have
|
||||
// been swapped, and a Debug build that trusts it would silently skip.
|
||||
expect(fs.readFileSync(marker(), 'utf8')).not.toBe('Debug');
|
||||
});
|
||||
|
||||
it('replaces the framework when the marker shows an unfinished swap', () => {
|
||||
buildTarball(podsRoot, 'Debug');
|
||||
// A swap that was interrupted: the Release flavor is on disk and the
|
||||
// marker never got its final value.
|
||||
replaceRNCoreConfiguration('Release', VERSION, podsRoot);
|
||||
fs.writeFileSync(marker(), 'in-progress');
|
||||
expect(binary()).toBe('binary-Release');
|
||||
|
||||
runScriptPhase(podsRoot, 'Debug');
|
||||
|
||||
expect(binary()).toBe('binary-Debug');
|
||||
expect(fs.readFileSync(marker(), 'utf8')).toBe('Debug');
|
||||
});
|
||||
|
||||
it('still skips when the marker already matches the configuration', () => {
|
||||
fs.writeFileSync(marker(), 'Release');
|
||||
const before = binary();
|
||||
|
||||
const output = runScriptPhase(podsRoot, 'Release');
|
||||
|
||||
expect(output).toContain('No need to replace React-Core-prebuilt');
|
||||
expect(binary()).toBe(before);
|
||||
});
|
||||
});
|
||||
|
||||
it('fails when the tarball has no React.xcframework', () => {
|
||||
const stage = fs.mkdtempSync(path.join(podsRoot, 'stage-bad-'));
|
||||
writeFile(path.join(stage, 'unrelated.txt'), 'nope');
|
||||
|
||||
+18
-2
@@ -18,6 +18,9 @@ const yargs = require('yargs');
|
||||
|
||||
const LAST_BUILD_FILENAME = 'React-Core-prebuilt/.last_build_configuration';
|
||||
|
||||
// Not a valid configuration, so finding it means the swap did not finish.
|
||||
const REPLACEMENT_IN_PROGRESS = 'in-progress';
|
||||
|
||||
function validateBuildConfiguration(configuration /*: string */) {
|
||||
if (!['Debug', 'Release'].includes(configuration)) {
|
||||
throw new Error(`Invalid configuration ${configuration}`);
|
||||
@@ -42,10 +45,12 @@ function shouldReplaceRnCoreConfiguration(configuration /*: string */) {
|
||||
);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Assumption: if there is no stored last build, we assume that it was build for debug.
|
||||
if (!fileExists && configuration === 'Debug') {
|
||||
// With no marker the on-disk flavor is Debug: the podspec installs the debug
|
||||
// tarball (see resolve_podspec_source in scripts/cocoapods/rncore.rb).
|
||||
if (configuration === 'Debug') {
|
||||
console.log(
|
||||
'No previous build detected, but Debug Configuration. No need to replace React-Core-prebuilt',
|
||||
);
|
||||
@@ -130,6 +135,10 @@ function updateLastBuildConfiguration(configuration /*: string */) {
|
||||
fs.writeFileSync(LAST_BUILD_FILENAME, configuration);
|
||||
}
|
||||
|
||||
function markReplacementInProgress() /*: void */ {
|
||||
fs.writeFileSync(LAST_BUILD_FILENAME, REPLACEMENT_IN_PROGRESS);
|
||||
}
|
||||
|
||||
function main(
|
||||
configuration /*: string */,
|
||||
version /*: string */,
|
||||
@@ -139,9 +148,16 @@ function main(
|
||||
validateVersion(version);
|
||||
|
||||
if (!shouldReplaceRnCoreConfiguration(configuration)) {
|
||||
// A fresh install leaves no marker; record the flavor we skipped on.
|
||||
if (!fs.existsSync(LAST_BUILD_FILENAME)) {
|
||||
updateLastBuildConfiguration(configuration);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Invalidate before touching the framework so an interrupted swap is
|
||||
// detectable on the next run.
|
||||
markReplacementInProgress();
|
||||
replaceRNCoreConfiguration(configuration, version, podsRoot);
|
||||
updateLastBuildConfiguration(configuration);
|
||||
console.log('Done replacing React Native prebuilt');
|
||||
|
||||
Reference in new issue
Block a user