mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
[ios][prebuild] add release/debug switch script
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
This commit is contained in:
@@ -62,8 +62,7 @@ Pod::Spec.new do |s|
|
||||
CONFIG="Debug"
|
||||
fi
|
||||
|
||||
# TODO(T228219721): Add this for React Native Core as well
|
||||
##### "$NODE_BINARY" "$REACT_NATIVE_PATH/third-party-podspecs/replace_dependencies_version.js" -c "$CONFIG" -r "#{version}" -p "$PODS_ROOT"
|
||||
"$NODE_BINARY" "$REACT_NATIVE_PATH/scripts/replace-rncore-version.js" -c "$CONFIG" -r "#{version}" -p "$PODS_ROOT"
|
||||
EOS
|
||||
}
|
||||
|
||||
@@ -73,7 +72,7 @@ Pod::Spec.new do |s|
|
||||
# always run the script without warning
|
||||
script_phase[:always_out_of_date] = "1"
|
||||
end
|
||||
|
||||
|
||||
s.script_phase = script_phase
|
||||
end
|
||||
end
|
||||
|
||||
@@ -125,8 +125,8 @@ class ReactNativeCoreUtils
|
||||
|
||||
url = stable_tarball_url(@@react_native_version, :debug)
|
||||
rncore_log("Using tarball from URL: #{url}")
|
||||
download_stable_rndeps(@@react_native_path, @@react_native_version, :debug)
|
||||
download_stable_rndeps(@@react_native_path, @@react_native_version, :release)
|
||||
download_stable_rncore(@@react_native_path, @@react_native_version, :debug)
|
||||
download_stable_rncore(@@react_native_path, @@react_native_version, :release)
|
||||
return {:http => url}
|
||||
end
|
||||
|
||||
@@ -157,9 +157,9 @@ class ReactNativeCoreUtils
|
||||
end
|
||||
end
|
||||
|
||||
def self.download_stable_rndeps(react_native_path, version, configuration)
|
||||
def self.download_stable_rncore(react_native_path, version, configuration)
|
||||
tarball_url = stable_tarball_url(version, configuration)
|
||||
download_rndeps_tarball(react_native_path, tarball_url, version, configuration)
|
||||
download_rncore_tarball(react_native_path, tarball_url, version, configuration)
|
||||
end
|
||||
|
||||
def self.podspec_source_download_prebuilt_nightly_tarball(version)
|
||||
@@ -168,14 +168,14 @@ class ReactNativeCoreUtils
|
||||
return {:http => url}
|
||||
end
|
||||
|
||||
def self.download_rndeps_tarball(react_native_path, tarball_url, version, configuration)
|
||||
def self.download_rncore_tarball(react_native_path, tarball_url, version, configuration)
|
||||
destination_path = configuration == nil ?
|
||||
"#{artifacts_dir()}/reactnative-core-debug.tar.gz-#{version}.tar.gz" :
|
||||
"#{artifacts_dir()}/reactnative-core-debug.tar.gz-#{version}-#{configuration}.tar.gz"
|
||||
"#{artifacts_dir()}/reactnative-core-#{version}.tar.gz" :
|
||||
"#{artifacts_dir()}/reactnative-core-#{version}-#{configuration}.tar.gz"
|
||||
|
||||
unless File.exist?(destination_path)
|
||||
# Download to a temporary file first so we don't cache incomplete downloads.
|
||||
tmp_file = "#{artifacts_dir()}/reactnative-core-debug.tar.gz.download"
|
||||
tmp_file = "#{artifacts_dir()}/reactnative-core.download"
|
||||
`mkdir -p "#{artifacts_dir()}" && curl "#{tarball_url}" -Lo "#{tmp_file}" && mv "#{tmp_file}" "#{destination_path}"`
|
||||
end
|
||||
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* 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.
|
||||
*
|
||||
* @flow strict-local
|
||||
* @format
|
||||
*/
|
||||
|
||||
'use strict';
|
||||
|
||||
const {execSync} = require('child_process');
|
||||
const fs = require('fs');
|
||||
const yargs = require('yargs');
|
||||
|
||||
const LAST_BUILD_FILENAME = 'React-Core-prebuilt/.last_build_configuration';
|
||||
|
||||
function validateBuildConfiguration(configuration /*: string */) {
|
||||
if (!['Debug', 'Release'].includes(configuration)) {
|
||||
throw new Error(`Invalid configuration ${configuration}`);
|
||||
}
|
||||
}
|
||||
|
||||
function validateVersion(version /*: ?string */) {
|
||||
if (version == null || version === '') {
|
||||
throw new Error('Version cannot be empty');
|
||||
}
|
||||
}
|
||||
|
||||
function shouldReplaceRnCoreConfiguration(configuration /*: string */) {
|
||||
const fileExists = fs.existsSync(LAST_BUILD_FILENAME);
|
||||
|
||||
if (fileExists) {
|
||||
console.log(`Found ${LAST_BUILD_FILENAME} file`);
|
||||
const oldConfiguration = fs.readFileSync(LAST_BUILD_FILENAME).toString();
|
||||
if (oldConfiguration === configuration) {
|
||||
console.log(
|
||||
'Same config of the previous build. No need to replace React-Core-prebuilt',
|
||||
);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Assumption: if there is no stored last build, we assume that it was build for debug.
|
||||
if (!fileExists && configuration === 'Debug') {
|
||||
console.log(
|
||||
'No previous build detected, but Debug Configuration. No need to replace React-Core-prebuilt',
|
||||
);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function replaceRNCoreConfiguration(
|
||||
configuration /*: string */,
|
||||
version /*: string */,
|
||||
podsRoot /*: string */,
|
||||
) {
|
||||
// Filename comes from rncore.rb
|
||||
const tarballURLPath = `${podsRoot}/ReactNativeCore-artifacts/reactnative-core-${version.toLowerCase()}-${configuration.toLowerCase()}.tar.gz`;
|
||||
|
||||
const finalLocation = 'React-Core-prebuilt';
|
||||
console.log('Preparing the final location', finalLocation);
|
||||
fs.rmSync(finalLocation, {force: true, recursive: true});
|
||||
fs.mkdirSync(finalLocation, {recursive: true});
|
||||
|
||||
console.log('Extracting the tarball', tarballURLPath);
|
||||
execSync(`tar -xf ${tarballURLPath} -C ${finalLocation}`);
|
||||
}
|
||||
|
||||
function updateLastBuildConfiguration(configuration /*: string */) {
|
||||
console.log(`Updating ${LAST_BUILD_FILENAME} with ${configuration}`);
|
||||
fs.writeFileSync(LAST_BUILD_FILENAME, configuration);
|
||||
}
|
||||
|
||||
function main(
|
||||
configuration /*: string */,
|
||||
version /*: string */,
|
||||
podsRoot /*: string */,
|
||||
) {
|
||||
validateBuildConfiguration(configuration);
|
||||
validateVersion(version);
|
||||
|
||||
if (!shouldReplaceRnCoreConfiguration(configuration)) {
|
||||
return;
|
||||
}
|
||||
|
||||
replaceRNCoreConfiguration(configuration, version, podsRoot);
|
||||
updateLastBuildConfiguration(configuration);
|
||||
console.log('Done replacing React Native prebuilt');
|
||||
}
|
||||
|
||||
// This script is executed in the Pods folder, which is usually not synched to Github, so it should be ok
|
||||
const argv = yargs
|
||||
.option('c', {
|
||||
alias: 'configuration',
|
||||
description:
|
||||
'Configuration to use to download the right React-Core prebuilt version. Allowed values are "Debug" and "Release".',
|
||||
})
|
||||
.option('r', {
|
||||
alias: 'reactNativeVersion',
|
||||
description:
|
||||
'The Version of React Native associated with the React-Core prebuilt tarball.',
|
||||
})
|
||||
.option('p', {
|
||||
alias: 'podsRoot',
|
||||
description: 'The path to the Pods root folder',
|
||||
})
|
||||
.usage('Usage: $0 -c Debug -r <version> -p <path/to/react-native>').argv;
|
||||
|
||||
// $FlowFixMe[prop-missing]
|
||||
const configuration = argv.configuration;
|
||||
// $FlowFixMe[prop-missing]
|
||||
const version = argv.reactNativeVersion;
|
||||
// $FlowFixMe[prop-missing]
|
||||
const podsRoot = argv.podsRoot;
|
||||
|
||||
main(configuration, version, podsRoot);
|
||||
Reference in New Issue
Block a user