Navigation Menu

Skip to content

Commit

Permalink
Added iOS support for loading multiple RAM bundles
Browse files Browse the repository at this point in the history
Differential Revision: D5850970

fbshipit-source-id: 88ab6fe3822f1bc4195007f8ec83177a84c27569
  • Loading branch information
fromcelticpark authored and facebook-github-bot committed Sep 21, 2017
1 parent 7982191 commit 1aeb767
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 6 deletions.
5 changes: 3 additions & 2 deletions React/CxxBridge/RCTCxxBridge.mm
Expand Up @@ -35,8 +35,8 @@
#import <cxxreact/JSBundleType.h>
#import <cxxreact/JSCExecutor.h>
#import <cxxreact/JSIndexedRAMBundle.h>
#include <cxxreact/JSIndexedRAMBundleRegistry.h>
#import <cxxreact/Platform.h>
#import <cxxreact/RAMBundleRegistry.h>
#import <jschelpers/Value.h>

#import "NSDataBigString.h"
Expand Down Expand Up @@ -1185,7 +1185,8 @@ - (void)executeApplicationScript:(NSData *)script
[self->_performanceLogger markStopForTag:RCTPLRAMBundleLoad];
[self->_performanceLogger setValue:scriptStr->size() forTag:RCTPLRAMStartupCodeSize];
if (self->_reactInstance) {
auto registry = std::make_unique<RAMBundleRegistry>(std::move(ramBundle));
std::string baseDirectoryPath = sourceUrlStr.stringByDeletingLastPathComponent.UTF8String;
auto registry = std::make_unique<JSIndexedRAMBundleRegistry>(std::move(ramBundle), baseDirectoryPath);
self->_reactInstance->loadRAMBundle(std::move(registry), std::move(scriptStr),
sourceUrlStr.UTF8String, !async);
}
Expand Down
14 changes: 14 additions & 0 deletions React/React.xcodeproj/project.pbxproj
Expand Up @@ -1102,6 +1102,7 @@
C654505E1F3BD9280090799B /* RCTManagedPointer.h in Headers */ = {isa = PBXBuildFile; fileRef = C654505D1F3BD9280090799B /* RCTManagedPointer.h */; };
C654505F1F3BD9280090799B /* RCTManagedPointer.h in Headers */ = {isa = PBXBuildFile; fileRef = C654505D1F3BD9280090799B /* RCTManagedPointer.h */; };
C669D8981F72E3DE006748EB /* RAMBundleRegistry.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6D380181F71D75B00621378 /* RAMBundleRegistry.h */; };
C669D8B91F72E4B7006748EB /* JSIndexedRAMBundleRegistry.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */; };
C6827DF61EF17CCC00D66BEF /* RCTJSEnvironment.h in Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
C6827DF71EF17CCC00D66BEF /* RCTJSEnvironment.h in Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
C6827DFB1EF1800E00D66BEF /* RCTJSEnvironment.h in Copy Headers */ = {isa = PBXBuildFile; fileRef = C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */; };
Expand All @@ -1110,6 +1111,10 @@
C6D3801B1F71D76200621378 /* RAMBundleRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = C6D380181F71D75B00621378 /* RAMBundleRegistry.h */; };
C6D3801C1F71D76700621378 /* RAMBundleRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D380191F71D75B00621378 /* RAMBundleRegistry.cpp */; };
C6D3801D1F71D76800621378 /* RAMBundleRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D380191F71D75B00621378 /* RAMBundleRegistry.cpp */; };
C6D380201F71D91D00621378 /* JSIndexedRAMBundleRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */; };
C6D380211F71D91E00621378 /* JSIndexedRAMBundleRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */; };
C6D380221F71D92300621378 /* JSIndexedRAMBundleRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D3801F1F71D91600621378 /* JSIndexedRAMBundleRegistry.cpp */; };
C6D380231F71D92400621378 /* JSIndexedRAMBundleRegistry.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C6D3801F1F71D91600621378 /* JSIndexedRAMBundleRegistry.cpp */; };
CF2731C01E7B8DE40044CA4F /* RCTDeviceInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = CF2731BE1E7B8DE40044CA4F /* RCTDeviceInfo.h */; };
CF2731C11E7B8DE40044CA4F /* RCTDeviceInfo.m in Sources */ = {isa = PBXBuildFile; fileRef = CF2731BF1E7B8DE40044CA4F /* RCTDeviceInfo.m */; };
CF2731C21E7B8DEF0044CA4F /* RCTDeviceInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = CF2731BE1E7B8DE40044CA4F /* RCTDeviceInfo.h */; };
Expand Down Expand Up @@ -1609,6 +1614,7 @@
dstPath = include/cxxreact;
dstSubfolderSpec = 16;
files = (
C669D8B91F72E4B7006748EB /* JSIndexedRAMBundleRegistry.h in Copy Headers */,
C669D8981F72E3DE006748EB /* RAMBundleRegistry.h in Copy Headers */,
3DA981A01E5B0E34004F2374 /* CxxModule.h in Copy Headers */,
3DA981A11E5B0E34004F2374 /* CxxNativeModule.h in Copy Headers */,
Expand Down Expand Up @@ -2103,6 +2109,8 @@
C6827DF51EF17CCC00D66BEF /* RCTJSEnvironment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTJSEnvironment.h; sourceTree = "<group>"; };
C6D380181F71D75B00621378 /* RAMBundleRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RAMBundleRegistry.h; sourceTree = "<group>"; };
C6D380191F71D75B00621378 /* RAMBundleRegistry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RAMBundleRegistry.cpp; sourceTree = "<group>"; };
C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = JSIndexedRAMBundleRegistry.h; sourceTree = "<group>"; };
C6D3801F1F71D91600621378 /* JSIndexedRAMBundleRegistry.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSIndexedRAMBundleRegistry.cpp; sourceTree = "<group>"; };
CF2731BE1E7B8DE40044CA4F /* RCTDeviceInfo.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTDeviceInfo.h; sourceTree = "<group>"; };
CF2731BF1E7B8DE40044CA4F /* RCTDeviceInfo.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTDeviceInfo.m; sourceTree = "<group>"; };
E3BBC8EB1ADE6F47001BBD81 /* RCTTextDecorationLineType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RCTTextDecorationLineType.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2771,6 +2779,8 @@
3D92B0AB1E03699D0018521A /* JSExecutor.h */,
3D92B0C61E03699D0018521A /* JSIndexedRAMBundle.cpp */,
3D92B0C71E03699D0018521A /* JSIndexedRAMBundle.h */,
C6D3801F1F71D91600621378 /* JSIndexedRAMBundleRegistry.cpp */,
C6D3801E1F71D91600621378 /* JSIndexedRAMBundleRegistry.h */,
3D92B0C81E03699D0018521A /* JSModulesUnbundle.h */,
3D92B0C91E03699D0018521A /* MessageQueueThread.h */,
3D92B0CA1E03699D0018521A /* MethodCall.cpp */,
Expand Down Expand Up @@ -3002,6 +3012,7 @@
27595AC61E575C7800CCE2B1 /* JsArgumentHelpers.h in Headers */,
27595AD71E575C7800CCE2B1 /* SampleCxxModule.h in Headers */,
27595AD21E575C7800CCE2B1 /* MethodCall.h in Headers */,
C6D380211F71D91E00621378 /* JSIndexedRAMBundleRegistry.h in Headers */,
3D3030221DF8294C00D6DDAE /* JSBundleType.h in Headers */,
27595ACA1E575C7800CCE2B1 /* JSCMemory.h in Headers */,
3D74547D1E54758900E74ADD /* JSBigString.h in Headers */,
Expand Down Expand Up @@ -3091,6 +3102,7 @@
27595AAB1E575C7800CCE2B1 /* JsArgumentHelpers.h in Headers */,
27595ABC1E575C7800CCE2B1 /* SampleCxxModule.h in Headers */,
27595AB71E575C7800CCE2B1 /* MethodCall.h in Headers */,
C6D380201F71D91D00621378 /* JSIndexedRAMBundleRegistry.h in Headers */,
3D3CD9471DE5FC7800167DC4 /* oss-compat-util.h in Headers */,
27595AAF1E575C7800CCE2B1 /* JSCMemory.h in Headers */,
3D74547C1E54758900E74ADD /* JSBigString.h in Headers */,
Expand Down Expand Up @@ -3953,6 +3965,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C6D380221F71D92300621378 /* JSIndexedRAMBundleRegistry.cpp in Sources */,
3DC159E51E83E1E9007B1282 /* JSBigString.cpp in Sources */,
13F8877B1E29726200C3C7A1 /* JSIndexedRAMBundle.cpp in Sources */,
13F8877D1E29726200C3C7A1 /* ModuleRegistry.cpp in Sources */,
Expand All @@ -3978,6 +3991,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C6D380231F71D92400621378 /* JSIndexedRAMBundleRegistry.cpp in Sources */,
3DC159E61E83E1FA007B1282 /* JSBigString.cpp in Sources */,
13F8878E1E29726300C3C7A1 /* JSIndexedRAMBundle.cpp in Sources */,
13F887901E29726300C3C7A1 /* ModuleRegistry.cpp in Sources */,
Expand Down
1 change: 1 addition & 0 deletions ReactCommon/cxxreact/Android.mk
Expand Up @@ -18,6 +18,7 @@ LOCAL_SRC_FILES := \
JSCTracing.cpp \
JSCUtils.cpp \
JSIndexedRAMBundle.cpp \
JSIndexedRAMBundleRegistry.cpp \
MethodCall.cpp \
ModuleRegistry.cpp \
NativeToJsBridge.cpp \
Expand Down
1 change: 1 addition & 0 deletions ReactCommon/cxxreact/BUCK
Expand Up @@ -80,6 +80,7 @@ CXXREACT_PUBLIC_HEADERS = [
"JSCExecutor.h",
"JSCNativeModules.h",
"JSIndexedRAMBundle.h",
"JSIndexedRAMBundleRegistry.h",
"JSModulesUnbundle.h",
"MessageQueueThread.h",
"MethodCall.h",
Expand Down
1 change: 0 additions & 1 deletion ReactCommon/cxxreact/JSIndexedRAMBundle.cpp
Expand Up @@ -3,7 +3,6 @@
#include "JSIndexedRAMBundle.h"

#include "oss-compat-util.h"
#include "JSBigString.h"

namespace facebook {
namespace react {
Expand Down
4 changes: 1 addition & 3 deletions ReactCommon/cxxreact/JSIndexedRAMBundle.h
Expand Up @@ -5,6 +5,7 @@
#include <fstream>
#include <memory>

#include <cxxreact/JSBigString.h>
#include <cxxreact/JSModulesUnbundle.h>

#ifndef RN_EXPORT
Expand All @@ -14,9 +15,6 @@
namespace facebook {
namespace react {

class JSBigString;
class JSBigBufferString;

class RN_EXPORT JSIndexedRAMBundle : public JSModulesUnbundle {
public:
// Throws std::runtime_error on failure.
Expand Down
22 changes: 22 additions & 0 deletions ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.cpp
@@ -0,0 +1,22 @@
// Copyright 2004-present Facebook. All Rights Reserved.

#include "JSIndexedRAMBundleRegistry.h"

#include <cxxreact/JSIndexedRAMBundle.h>
#include <folly/Memory.h>

#include "oss-compat-util.h"

namespace facebook {
namespace react {

std::unique_ptr<JSModulesUnbundle> JSIndexedRAMBundleRegistry::bundleById(uint32_t index) const {
return folly::make_unique<JSIndexedRAMBundle>(bundlePathById(index).c_str());
}

std::string JSIndexedRAMBundleRegistry::bundlePathById(uint32_t index) const {
return m_baseDirectoryPath + "/js-bundles/" + toString(index) + ".jsbundle";
}

} // namespace react
} // namespace facebook
26 changes: 26 additions & 0 deletions ReactCommon/cxxreact/JSIndexedRAMBundleRegistry.h
@@ -0,0 +1,26 @@
// Copyright 2004-present Facebook. All Rights Reserved.

#pragma once

#include <cxxreact/RAMBundleRegistry.h>

namespace facebook {
namespace react {

class JSIndexedRAMBundleRegistry: public RAMBundleRegistry {
public:
JSIndexedRAMBundleRegistry(
std::unique_ptr<JSModulesUnbundle> mainBundle,
std::string baseDirectoryPath):
RAMBundleRegistry(std::move(mainBundle)), m_baseDirectoryPath(baseDirectoryPath) {}

protected:
virtual std::unique_ptr<JSModulesUnbundle> bundleById(uint32_t index) const override;
private:
std::string bundlePathById(uint32_t index) const;

std::string m_baseDirectoryPath;
};

} // namespace react
} // namespace facebook

0 comments on commit 1aeb767

Please sign in to comment.