Permalink
Browse files

Unify supplimentary bundle path creation logic between Android and iOS

Differential Revision: D5941546

fbshipit-source-id: c9b8fab887f480faa373c26a1d5ba310e8acde78
  • Loading branch information...
fromcelticpark authored and facebook-github-bot committed Oct 4, 2017
1 parent adde2ed commit 9e01d721034ab9c8ef045f28d0706776f301c7d6
@@ -1190,8 +1190,7 @@ - (void)executeApplicationScript:(NSData *)script
[self->_performanceLogger markStopForTag:RCTPLRAMBundleLoad];
[self->_performanceLogger setValue:scriptStr->size() forTag:RCTPLRAMStartupCodeSize];
if (self->_reactInstance) {
std::string baseDirectoryPath = sourceUrlStr.stringByDeletingLastPathComponent.UTF8String;
auto registry = std::make_unique<JSIndexedRAMBundleRegistry>(std::move(ramBundle), baseDirectoryPath);
auto registry = std::make_unique<JSIndexedRAMBundleRegistry>(std::move(ramBundle), sourceUrlStr.UTF8String);
self->_reactInstance->loadRAMBundle(std::move(registry), std::move(scriptStr),
sourceUrlStr.UTF8String, !async);
}
@@ -2,8 +2,6 @@
#include "JniRAMBundleRegistry.h"
#include <libgen.h>
#include <folly/Conv.h>
#include <folly/Memory.h>
@@ -12,16 +10,6 @@
namespace facebook {
namespace react {
static std::string jsBundlesDir(const std::string& entryFile) {
std::string dir = dirname(entryFile.c_str());
std::string entryName = basename(entryFile.c_str());
entryName.erase(entryName.find("."), std::string::npos);
std::string path = "js-bundles/" + entryName + "/";
// android's asset manager does not work with paths that start with a dot
return dir == "." ? path : dir + "/" + path;
}
JniRAMBundleRegistry::JniRAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, AAssetManager *assetManager, const std::string& entryFile) :
RAMBundleRegistry(std::move(mainBundle)),
m_assetManager(assetManager),
@@ -10,12 +10,12 @@
namespace facebook {
namespace react {
std::unique_ptr<JSModulesUnbundle> JSIndexedRAMBundleRegistry::bundleById(uint32_t index) const {
return folly::make_unique<JSIndexedRAMBundle>(bundlePathById(index).c_str());
}
JSIndexedRAMBundleRegistry::JSIndexedRAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, const std::string& entryFile):
RAMBundleRegistry(std::move(mainBundle)), m_baseDirectoryPath(jsBundlesDir(entryFile)) {}
std::string JSIndexedRAMBundleRegistry::bundlePathById(uint32_t index) const {
return m_baseDirectoryPath + "/js-bundles/" + toString(index) + ".jsbundle";
std::unique_ptr<JSModulesUnbundle> JSIndexedRAMBundleRegistry::bundleById(uint32_t index) const {
std::string bundlePathById = m_baseDirectoryPath + toString(index) + ".jsbundle";
return folly::make_unique<JSIndexedRAMBundle>(bundlePathById.c_str());
}
} // namespace react
@@ -13,16 +13,11 @@ namespace react {
class RN_EXPORT JSIndexedRAMBundleRegistry: public RAMBundleRegistry {
public:
JSIndexedRAMBundleRegistry(
std::unique_ptr<JSModulesUnbundle> mainBundle,
std::string baseDirectoryPath):
RAMBundleRegistry(std::move(mainBundle)), m_baseDirectoryPath(baseDirectoryPath) {}
JSIndexedRAMBundleRegistry(std::unique_ptr<JSModulesUnbundle> mainBundle, const std::string& entryFile);
protected:
virtual std::unique_ptr<JSModulesUnbundle> bundleById(uint32_t index) const override;
private:
std::string bundlePathById(uint32_t index) const;
std::string m_baseDirectoryPath;
};
@@ -2,6 +2,8 @@
#include "RAMBundleRegistry.h"
#include <libgen.h>
namespace facebook {
namespace react {
@@ -23,5 +25,20 @@ JSModulesUnbundle *RAMBundleRegistry::getBundle(uint32_t bundleId) const {
return m_bundles.at(bundleId).get();
}
std::string RAMBundleRegistry::jsBundlesDir(std::string entryFile) {
char *pEntryFile = const_cast<char *>(entryFile.c_str());
std::string dir = dirname(pEntryFile);
std::string entryName = basename(pEntryFile);
std::size_t dotPosition = entryName.find(".");
if (dotPosition != std::string::npos) {
entryName.erase(dotPosition, std::string::npos);
}
std::string path = "js-bundles/" + entryName + "/";
// android's asset manager does not work with paths that start with a dot
return dir == "." ? path : dir + "/" + path;
}
} // namespace react
} // namespace facebook
@@ -28,6 +28,7 @@ class RN_EXPORT RAMBundleRegistry : noncopyable {
JSModulesUnbundle::Module getModule(uint32_t bundleId, uint32_t moduleId);
virtual ~RAMBundleRegistry() {};
protected:
std::string jsBundlesDir(std::string entryFile);
virtual std::unique_ptr<JSModulesUnbundle> bundleById(uint32_t index) const {
throw std::runtime_error("Please, override this method in a subclass to support multiple RAM bundles.");
}

0 comments on commit 9e01d72

Please sign in to comment.