Skip to content

Commit

Permalink
Unify supplimentary bundle path creation logic between Android and iOS
Browse files Browse the repository at this point in the history
Differential Revision: D5941546

fbshipit-source-id: c9b8fab887f480faa373c26a1d5ba310e8acde78
  • Loading branch information
fromcelticpark authored and facebook-github-bot committed Oct 4, 2017
1 parent adde2ed commit 9e01d72
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
3 changes: 1 addition & 2 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
12 changes: 0 additions & 12 deletions ReactAndroid/src/main/jni/react/jni/JniRAMBundleRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "JniRAMBundleRegistry.h"

#include <libgen.h>

#include <folly/Conv.h>
#include <folly/Memory.h>

Expand All @@ -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),
Expand Down
10 changes: 5 additions & 5 deletions ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
17 changes: 17 additions & 0 deletions ReactCommon/cxxreact/RAMBundleRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

#include "RAMBundleRegistry.h"

#include <libgen.h>

namespace facebook {
namespace react {

Expand All @@ -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
1 change: 1 addition & 0 deletions ReactCommon/cxxreact/RAMBundleRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
Expand Down

0 comments on commit 9e01d72

Please sign in to comment.