From 8b984ca2c45b20e5cecb7bc27fb1337aa262cedf Mon Sep 17 00:00:00 2001 From: Christian Falch Date: Wed, 26 Feb 2025 08:19:39 -0800 Subject: [PATCH] Glue all the scripts together. (#49671) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/49671 This change refactors the script to prebuild ios dependencies by adding a script that glues all the steps together. bypass-github-export-checks ## Changelog: [INTERNAL] - Add script to orchestrate all the steps Test Plan: Tested in this `AppDelegate.mm`: Imports: ```obj-c #import "AppDelegate.h" #import #import #include #include #include #include #import ``` Code: ```obj-c - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { std::string input = "3.1416 xyz "; double_conversion::DoubleToStringConverter::EcmaScriptConverter(); LOG(INFO) << "Hello from GLOG"; fmt::print("Hello, world from FMT!\n"); BOOST_ASSERT(100 == 100); double result; fast_float::from_chars(input.data(), input.data() + input.size(), result); LOG(INFO) << "Answer :" << result; NSArray *frameworks = [NSBundle allFrameworks]; for (NSBundle *framework in frameworks) { NSString *frameworkName = framework.bundleURL.lastPathComponent; if ([frameworkName isEqualToString: @"ReactNativeDependencies.framework"]) { NSBundle *bundle = [NSBundle bundleWithURL:[framework bundleURL]]; NSURL *bundleURL = [bundle URLForResource:@"ReactNativeDependencies_glog" withExtension:@"bundle"]; NSBundle *resourceBundle = [NSBundle bundleWithURL:bundleURL]; NSURL* url = [resourceBundle URLForResource:@"PrivacyInfo" withExtension:@"xcprivacy"]; if (url == nil) { throw [NSException exceptionWithName:@"ResourceNotFoundException" reason:@"Could not find PrivacyInfo.xcprivacy in ReactNativeDependencies_glog bundle" userInfo:nil]; } break; } } return YES; } ``` Reviewed By: cortinico Differential Revision: D70175842 Pulled By: cipolleschi fbshipit-source-id: e4bb4ad5d12e7ceaaca0eeee7ce6dc7269aa7bad --- scripts/releases/prebuild/index.js | 78 ++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 scripts/releases/prebuild/index.js diff --git a/scripts/releases/prebuild/index.js b/scripts/releases/prebuild/index.js new file mode 100644 index 00000000000..2911eb0f24e --- /dev/null +++ b/scripts/releases/prebuild/index.js @@ -0,0 +1,78 @@ +/** + * 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 + * @format + * @oncall react_native + */ + +const {buildDepenencies} = require('./build'); +const {getCLIConfiguration} = require('./cli'); +const {createFramework} = require('./compose-framework'); +const {cleanFolder} = require('./folders'); +const {setupDependencies} = require('./setupDependencies'); +const {createSwiftPackageFile} = require('./swift-package'); +const path = require('path'); + +require('../../babel-register').registerForScript(); + +const THIRD_PARTY_PATH = 'packages/react-native/third-party'; +const BUILD_DESTINATION = '.build'; + +const SCHEME = 'ReactNativeDependencies'; + +/** + * Main entry point + */ +async function main() { + const cli = await getCLIConfiguration(); + if (cli == null) { + return 0; + } + + const buildFolder = path.resolve(THIRD_PARTY_PATH, BUILD_DESTINATION); + const rootFolder = path.resolve(THIRD_PARTY_PATH); + + if (cli.tasks.setup) { + await cleanFolder(rootFolder); + await setupDependencies(cli.dependencies, rootFolder); + } + + if (cli.tasks.swiftpackage) { + // Create Package.swift file + await createSwiftPackageFile(SCHEME, cli.dependencies, rootFolder); + } + + if (cli.tasks.build) { + await cleanFolder(buildFolder); + await buildDepenencies( + SCHEME, + cli.configuration, + cli.dependencies, + cli.platforms, + rootFolder, + buildFolder, + ); + } + + if (cli.tasks.compose) { + await createFramework( + SCHEME, + cli.configuration, + cli.dependencies, + rootFolder, + buildFolder, + ); + } + + console.log(''); + console.log('🏁 Done!'); +} + +if (require.main === module) { + // eslint-disable-next-line no-void + void main(); +}