Skip to content

Commit c665a96

Browse files
chrfalchmotiz88
authored andcommitted
add release/debug switch script (#52498)
Summary: Fixes #T228219721 This commit adds the debug/release switch script like we have for rn deps and hermes for react-core prebuilt: - Added script: replace-rncore-version-js - Inserted script into React-Core-prebuilt podspec - Updated rncore.rb with correct filenames bypass-github-export-checks ## Changelog: [IOS] [ADDED] - add release/debug switch script for React-Core-prebuilt Pull Request resolved: #52498 Test Plan: Run in RNTester and switch between release/debug Reviewed By: rshest Differential Revision: D78012917 Pulled By: cipolleschi fbshipit-source-id: 71cad23cd41484a8253fc89d5dce8653649657a0
1 parent c9263e7 commit c665a96

3 files changed

Lines changed: 130 additions & 11 deletions

File tree

packages/react-native/React-Core-prebuilt.podspec

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,7 @@ Pod::Spec.new do |s|
6262
CONFIG="Debug"
6363
fi
6464
65-
# TODO(T228219721): Add this for React Native Core as well
66-
##### "$NODE_BINARY" "$REACT_NATIVE_PATH/third-party-podspecs/replace_dependencies_version.js" -c "$CONFIG" -r "#{version}" -p "$PODS_ROOT"
65+
"$NODE_BINARY" "$REACT_NATIVE_PATH/scripts/replace-rncore-version.js" -c "$CONFIG" -r "#{version}" -p "$PODS_ROOT"
6766
EOS
6867
}
6968

@@ -73,7 +72,7 @@ Pod::Spec.new do |s|
7372
# always run the script without warning
7473
script_phase[:always_out_of_date] = "1"
7574
end
76-
75+
7776
s.script_phase = script_phase
7877
end
7978
end

packages/react-native/scripts/cocoapods/rncore.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,8 @@ def self.podspec_source_download_prebuild_stable_tarball()
125125

126126
url = stable_tarball_url(@@react_native_version, :debug)
127127
rncore_log("Using tarball from URL: #{url}")
128-
download_stable_rndeps(@@react_native_path, @@react_native_version, :debug)
129-
download_stable_rndeps(@@react_native_path, @@react_native_version, :release)
128+
download_stable_rncore(@@react_native_path, @@react_native_version, :debug)
129+
download_stable_rncore(@@react_native_path, @@react_native_version, :release)
130130
return {:http => url}
131131
end
132132

@@ -162,9 +162,9 @@ def self.nightly_tarball_url(version)
162162
end
163163
end
164164

165-
def self.download_stable_rndeps(react_native_path, version, configuration)
165+
def self.download_stable_rncore(react_native_path, version, configuration)
166166
tarball_url = stable_tarball_url(version, configuration)
167-
download_rndeps_tarball(react_native_path, tarball_url, version, configuration)
167+
download_rncore_tarball(react_native_path, tarball_url, version, configuration)
168168
end
169169

170170
def self.podspec_source_download_prebuilt_nightly_tarball(version)
@@ -173,14 +173,14 @@ def self.podspec_source_download_prebuilt_nightly_tarball(version)
173173
return {:http => url}
174174
end
175175

176-
def self.download_rndeps_tarball(react_native_path, tarball_url, version, configuration)
176+
def self.download_rncore_tarball(react_native_path, tarball_url, version, configuration)
177177
destination_path = configuration == nil ?
178-
"#{artifacts_dir()}/reactnative-core-debug.tar.gz-#{version}.tar.gz" :
179-
"#{artifacts_dir()}/reactnative-core-debug.tar.gz-#{version}-#{configuration}.tar.gz"
178+
"#{artifacts_dir()}/reactnative-core-#{version}.tar.gz" :
179+
"#{artifacts_dir()}/reactnative-core-#{version}-#{configuration}.tar.gz"
180180

181181
unless File.exist?(destination_path)
182182
# Download to a temporary file first so we don't cache incomplete downloads.
183-
tmp_file = "#{artifacts_dir()}/reactnative-core-debug.tar.gz.download"
183+
tmp_file = "#{artifacts_dir()}/reactnative-core.download"
184184
`mkdir -p "#{artifacts_dir()}" && curl "#{tarball_url}" -Lo "#{tmp_file}" && mv "#{tmp_file}" "#{destination_path}"`
185185
end
186186

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*
7+
* @flow strict-local
8+
* @format
9+
*/
10+
11+
'use strict';
12+
13+
const {execSync} = require('child_process');
14+
const fs = require('fs');
15+
const yargs = require('yargs');
16+
17+
const LAST_BUILD_FILENAME = 'React-Core-prebuilt/.last_build_configuration';
18+
19+
function validateBuildConfiguration(configuration /*: string */) {
20+
if (!['Debug', 'Release'].includes(configuration)) {
21+
throw new Error(`Invalid configuration ${configuration}`);
22+
}
23+
}
24+
25+
function validateVersion(version /*: ?string */) {
26+
if (version == null || version === '') {
27+
throw new Error('Version cannot be empty');
28+
}
29+
}
30+
31+
function shouldReplaceRnCoreConfiguration(configuration /*: string */) {
32+
const fileExists = fs.existsSync(LAST_BUILD_FILENAME);
33+
34+
if (fileExists) {
35+
console.log(`Found ${LAST_BUILD_FILENAME} file`);
36+
const oldConfiguration = fs.readFileSync(LAST_BUILD_FILENAME).toString();
37+
if (oldConfiguration === configuration) {
38+
console.log(
39+
'Same config of the previous build. No need to replace React-Core-prebuilt',
40+
);
41+
return false;
42+
}
43+
}
44+
45+
// Assumption: if there is no stored last build, we assume that it was build for debug.
46+
if (!fileExists && configuration === 'Debug') {
47+
console.log(
48+
'No previous build detected, but Debug Configuration. No need to replace React-Core-prebuilt',
49+
);
50+
return false;
51+
}
52+
53+
return true;
54+
}
55+
56+
function replaceRNCoreConfiguration(
57+
configuration /*: string */,
58+
version /*: string */,
59+
podsRoot /*: string */,
60+
) {
61+
// Filename comes from rncore.rb
62+
const tarballURLPath = `${podsRoot}/ReactNativeCore-artifacts/reactnative-core-${version.toLowerCase()}-${configuration.toLowerCase()}.tar.gz`;
63+
64+
const finalLocation = 'React-Core-prebuilt';
65+
console.log('Preparing the final location', finalLocation);
66+
fs.rmSync(finalLocation, {force: true, recursive: true});
67+
fs.mkdirSync(finalLocation, {recursive: true});
68+
69+
console.log('Extracting the tarball', tarballURLPath);
70+
execSync(`tar -xf ${tarballURLPath} -C ${finalLocation}`);
71+
}
72+
73+
function updateLastBuildConfiguration(configuration /*: string */) {
74+
console.log(`Updating ${LAST_BUILD_FILENAME} with ${configuration}`);
75+
fs.writeFileSync(LAST_BUILD_FILENAME, configuration);
76+
}
77+
78+
function main(
79+
configuration /*: string */,
80+
version /*: string */,
81+
podsRoot /*: string */,
82+
) {
83+
validateBuildConfiguration(configuration);
84+
validateVersion(version);
85+
86+
if (!shouldReplaceRnCoreConfiguration(configuration)) {
87+
return;
88+
}
89+
90+
replaceRNCoreConfiguration(configuration, version, podsRoot);
91+
updateLastBuildConfiguration(configuration);
92+
console.log('Done replacing React Native prebuilt');
93+
}
94+
95+
// This script is executed in the Pods folder, which is usually not synched to Github, so it should be ok
96+
const argv = yargs
97+
.option('c', {
98+
alias: 'configuration',
99+
description:
100+
'Configuration to use to download the right React-Core prebuilt version. Allowed values are "Debug" and "Release".',
101+
})
102+
.option('r', {
103+
alias: 'reactNativeVersion',
104+
description:
105+
'The Version of React Native associated with the React-Core prebuilt tarball.',
106+
})
107+
.option('p', {
108+
alias: 'podsRoot',
109+
description: 'The path to the Pods root folder',
110+
})
111+
.usage('Usage: $0 -c Debug -r <version> -p <path/to/react-native>').argv;
112+
113+
// $FlowFixMe[prop-missing]
114+
const configuration = argv.configuration;
115+
// $FlowFixMe[prop-missing]
116+
const version = argv.reactNativeVersion;
117+
// $FlowFixMe[prop-missing]
118+
const podsRoot = argv.podsRoot;
119+
120+
main(configuration, version, podsRoot);

0 commit comments

Comments
 (0)