From 6633266c41d8a659585639154cbb35180fb944d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Trys=C5=82a?= Date: Wed, 5 Jun 2019 15:40:09 +0200 Subject: [PATCH] add bundle prefix to RAM bundles --- .../src/main/jni/react/jni/CatalystInstanceImpl.cpp | 1 - ReactAndroid/src/main/jni/react/jni/FileRAMBundle.cpp | 9 ++++++--- ReactAndroid/src/main/jni/react/jni/FileRAMBundle.h | 2 +- ReactCommon/cxxreact/BundleRegistry.cpp | 3 ++- ReactCommon/cxxreact/IndexedRAMBundle.cpp | 5 ++++- ReactCommon/cxxreact/IndexedRAMBundle.h | 2 +- ReactCommon/cxxreact/RAMBundle.h | 2 +- 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp b/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp index beedb92c4b13..2be972c7c17f 100644 --- a/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp +++ b/ReactAndroid/src/main/jni/react/jni/CatalystInstanceImpl.cpp @@ -175,7 +175,6 @@ void CatalystInstanceImpl::jniLoadScriptFromAssets( jni::alias_ref assetManager, const std::string& assetURL, bool loadSynchronously) { - std::unique_ptr bundleLoader = std::make_unique(assetManager); instance_->runApplication(assetURL, std::move(bundleLoader), loadSynchronously); } diff --git a/ReactAndroid/src/main/jni/react/jni/FileRAMBundle.cpp b/ReactAndroid/src/main/jni/react/jni/FileRAMBundle.cpp index dd8df379f475..69c88577f770 100644 --- a/ReactAndroid/src/main/jni/react/jni/FileRAMBundle.cpp +++ b/ReactAndroid/src/main/jni/react/jni/FileRAMBundle.cpp @@ -105,14 +105,17 @@ BundleType FileRAMBundle::getBundleType() const { return BundleType::FileRAMBundle; } -FileRAMBundle::Module FileRAMBundle::getModule(uint32_t moduleId) const { +FileRAMBundle::Module FileRAMBundle::getModule(uint32_t moduleId, const char* bundlePrefix) const { // can be nullptr for default constructor. FBASSERTMSGF( assetManager_ != nullptr, "Unbundle has not been initialized with an asset manager"); auto sourceUrl = folly::to(moduleId, ".js"); - auto fileName = moduleDirectory_ + sourceUrl; + if (bundlePrefix) { + sourceUrl = folly::to(bundlePrefix, "-", sourceUrl); + } + auto asset = openAsset(assetManager_, fileName.c_str(), AASSET_MODE_BUFFER); const char* buffer = nullptr; @@ -122,7 +125,7 @@ FileRAMBundle::Module FileRAMBundle::getModule(uint32_t moduleId) const { if (buffer == nullptr) { throw ModuleNotFound(moduleId); } - return {sourceUrl, std::string(buffer, AAsset_getLength(asset.get()))}; + return { sourceUrl, std::string(buffer, AAsset_getLength(asset.get())) }; } } // namespace react diff --git a/ReactAndroid/src/main/jni/react/jni/FileRAMBundle.h b/ReactAndroid/src/main/jni/react/jni/FileRAMBundle.h index f245f8e36e69..500348661340 100644 --- a/ReactAndroid/src/main/jni/react/jni/FileRAMBundle.h +++ b/ReactAndroid/src/main/jni/react/jni/FileRAMBundle.h @@ -25,7 +25,7 @@ class FileRAMBundle : public RAMBundle { std::string getSourcePath() const override; std::string getSourceURL() const override; std::unique_ptr getStartupScript() const override; - Module getModule(uint32_t moduleId) const override; + Module getModule(uint32_t moduleId, const char* bundlePrefix) const override; BundleType getBundleType() const override; private: diff --git a/ReactCommon/cxxreact/BundleRegistry.cpp b/ReactCommon/cxxreact/BundleRegistry.cpp index 24d1409a3a0f..92baf1435617 100644 --- a/ReactCommon/cxxreact/BundleRegistry.cpp +++ b/ReactCommon/cxxreact/BundleRegistry.cpp @@ -156,7 +156,8 @@ BundleRegistry::GetModuleLambda BundleRegistry::makeGetModuleLambda(std::string " is not a RAM bundle - GetModuleLambda cannot be used on it"); } - return ramBundle->getModule(moduleId); + auto bundlePrefix = bundleName == "seg-0" ? nullptr : bundleName.c_str(); + return ramBundle->getModule(moduleId, bundlePrefix); }; } diff --git a/ReactCommon/cxxreact/IndexedRAMBundle.cpp b/ReactCommon/cxxreact/IndexedRAMBundle.cpp index 9a7818dd32c5..42d5d487e534 100644 --- a/ReactCommon/cxxreact/IndexedRAMBundle.cpp +++ b/ReactCommon/cxxreact/IndexedRAMBundle.cpp @@ -95,9 +95,12 @@ std::string IndexedRAMBundle::getSourcePath() const { return sourcePath_; } -IndexedRAMBundle::Module IndexedRAMBundle::getModule(uint32_t moduleId) const { +IndexedRAMBundle::Module IndexedRAMBundle::getModule(uint32_t moduleId, const char* bundlePrefix) const { Module ret; ret.name = folly::to(moduleId, ".js"); + if (bundlePrefix) { + ret.name = folly::to(bundlePrefix, "-", ret.name); + } ret.code = getModuleCode(moduleId); return ret; } diff --git a/ReactCommon/cxxreact/IndexedRAMBundle.h b/ReactCommon/cxxreact/IndexedRAMBundle.h index c823904f7ed5..ffe44eea1819 100644 --- a/ReactCommon/cxxreact/IndexedRAMBundle.h +++ b/ReactCommon/cxxreact/IndexedRAMBundle.h @@ -24,7 +24,7 @@ class IndexedRAMBundle : public RAMBundle { std::string getSourceURL() const override; std::string getSourcePath() const override; std::unique_ptr getStartupScript() const override; - Module getModule(uint32_t moduleId) const override; + Module getModule(uint32_t moduleId, const char* bundlePrefix) const override; BundleType getBundleType() const override; private: diff --git a/ReactCommon/cxxreact/RAMBundle.h b/ReactCommon/cxxreact/RAMBundle.h index c1e9932dec36..dcacd4442b0d 100644 --- a/ReactCommon/cxxreact/RAMBundle.h +++ b/ReactCommon/cxxreact/RAMBundle.h @@ -30,7 +30,7 @@ class RAMBundle : public Bundle { */ virtual std::string getSourcePath() const = 0; virtual std::unique_ptr getStartupScript() const = 0; - virtual Module getModule(uint32_t moduleId) const = 0; + virtual Module getModule(uint32_t moduleId, const char* bundlePrefix) const = 0; }; } // react