Skip to content

Commit b518210

Browse files
committed
- Added isDebug field
- Include the inspector code in the framework - Build scripts stop on first error - Fix OTHER_CFLAGS for arm64 builds
1 parent f461125 commit b518210

File tree

19 files changed

+76
-50
lines changed

19 files changed

+76
-50
lines changed

AppWithModules/Source Files/main.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@ int main(int argc, char *argv[]) {
2020

2121
NSString* applicationPath = [[NSBundle mainBundle] resourcePath];
2222

23+
bool isDebug =
24+
#ifdef DEBUG
25+
true;
26+
#else
27+
false;
28+
#endif
29+
2330
[NativeScript start:metadataPtr
2431
fromApplicationPath:applicationPath
2532
fromNativesPtr:startNativesPtr
2633
fromNativesSize:nativesSize
2734
fromSnapshotPtr:startSnapshotPtr
28-
fromSnapshotSize:snapshotSize];
35+
fromSnapshotSize:snapshotSize
36+
isDebug:isDebug];
2937

3038
return 0;
3139
}

NativeScript/NativeScript.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
@interface NativeScript : NSObject
44

5-
+ (void)start:(void*)metadataPtr fromApplicationPath:(NSString*)path fromNativesPtr:(const char*)nativesPtr fromNativesSize:(size_t)nativesSize fromSnapshotPtr:(const char*)snapshotPtr fromSnapshotSize:(size_t)snapshotSize;
5+
+ (void)start:(void*)metadataPtr fromApplicationPath:(NSString*)path fromNativesPtr:(const char*)nativesPtr fromNativesSize:(size_t)nativesSize fromSnapshotPtr:(const char*)snapshotPtr fromSnapshotSize:(size_t)snapshotSize isDebug:(bool)value;
66
+ (bool)liveSync;
77

88
@end

NativeScript/NativeScript.mm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ @implementation NativeScript
1010

1111
static Runtime* runtime_ = nullptr;
1212

13-
+ (void)start:(void*)metadataPtr fromApplicationPath:(NSString*)path fromNativesPtr:(const char*)nativesPtr fromNativesSize:(size_t)nativesSize fromSnapshotPtr:(const char*)snapshotPtr fromSnapshotSize:(size_t)snapshotSize {
13+
+ (void)start:(void*)metadataPtr fromApplicationPath:(NSString*)path fromNativesPtr:(const char*)nativesPtr fromNativesSize:(size_t)nativesSize fromSnapshotPtr:(const char*)snapshotPtr fromSnapshotSize:(size_t)snapshotSize isDebug:(bool)isDebug {
1414
NSString* appPath = [path stringByAppendingPathComponent:@"app"];
1515
const char* baseDir = [appPath UTF8String];
1616

17-
Runtime::Initialize(metadataPtr, nativesPtr, nativesSize, snapshotPtr, snapshotSize);
17+
Runtime::Initialize(metadataPtr, nativesPtr, nativesSize, snapshotPtr, snapshotSize, isDebug);
1818
runtime_ = new Runtime();
19+
runtime_->SetIsDebug(isDebug);
1920
runtime_->InitAndRunMainScript(baseDir);
2021
}
2122

NativeScript/runtime/ArgConverter.mm

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
}
6060

6161
Local<Value> ArgConverter::ConvertArgument(Isolate* isolate, BaseDataWrapper* wrapper) {
62-
// TODO: Check the actual DataWrapper type
6362
if (wrapper == nullptr) {
6463
return Null(isolate);
6564
}

NativeScript/runtime/Console.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
#include "Console.h"
22
#include "Helpers.h"
3-
#ifdef DEBUG
43
#include "v8-log-agent-impl.h"
5-
#endif
64

75
using namespace v8;
86

97
namespace tns {
108

11-
void Console::Init(Isolate* isolate) {
9+
void Console::Init(Isolate* isolate, bool isDebug) {
10+
isDebug_ = isDebug;
1211
Local<Context> context = isolate->GetCurrentContext();
1312
Context::Scope context_scope(context);
1413
Local<Object> console = Object::New(isolate);
@@ -30,9 +29,9 @@ void Console::LogCallback(const FunctionCallbackInfo<Value>& args) {
3029
Local<Value> value = args[0];
3130
Isolate* isolate = args.GetIsolate();
3231
std::string str = tns::ToString(isolate, value);
33-
#ifdef DEBUG
34-
v8_inspector::V8LogAgentImpl::EntryAdded(str, "info", "", 0);
35-
#endif
32+
if (isDebug_) {
33+
v8_inspector::V8LogAgentImpl::EntryAdded(str, "info", "", 0);
34+
}
3635
printf("%s", str.c_str());
3736
}
3837

@@ -51,4 +50,6 @@ void Console::AttachLogFunction(Isolate* isolate, Local<Object> console, const s
5150
}
5251
}
5352

53+
bool Console::isDebug_ = false;
54+
5455
}

NativeScript/runtime/Console.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ namespace tns {
77

88
class Console {
99
public:
10-
static void Init(v8::Isolate* isolate);
10+
static void Init(v8::Isolate* isolate, bool isDebug_);
1111
private:
1212
static void AttachLogFunction(v8::Isolate* isolate, v8::Local<v8::Object> console, const std::string name);
1313
static void LogCallback(const v8::FunctionCallbackInfo<v8::Value>& args);
14+
static bool isDebug_;
1415
};
1516

1617
}

NativeScript/runtime/FFICall.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "FFICall.h"
2+
#include "ArgConverter.h"
23
#include <sstream>
34

45
namespace tns {
@@ -69,9 +70,7 @@ ffi_type* FFICall::GetArgumentType(const TypeEncoding* typeEncoding, bool isStru
6970
}
7071
case BinaryTypeEncodingType::StructDeclarationReference: {
7172
const char* structName = typeEncoding->details.declarationReference.name.valuePtr();
72-
const GlobalTable* globalTable = MetaFile::instance()->globalTable();
73-
// TODO: cache metadata
74-
const Meta* meta = globalTable->findMeta(structName);
73+
const Meta* meta = ArgConverter::GetMeta(structName);
7574
assert(meta->type() == MetaType::Struct);
7675
const StructMeta* structMeta = static_cast<const StructMeta*>(meta);
7776

NativeScript/runtime/Runtime.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Runtime {
2424
return this->baseDir_;
2525
}
2626

27-
static void Initialize(void* metadataPtr, const char* nativesPtr, size_t nativesSize, const char* snapshotPtr, size_t snapshotSize);
27+
static void Initialize(void* metadataPtr, const char* nativesPtr, size_t nativesSize, const char* snapshotPtr, size_t snapshotSize, bool isDebug);
2828

2929
static Runtime* GetCurrentRuntime() {
3030
return currentRuntime_;
@@ -36,6 +36,7 @@ class Runtime {
3636
static size_t nativesSize_;
3737
static const char* snapshotPtr_;
3838
static size_t snapshotSize_;
39+
static bool isDebug_;
3940

4041
static thread_local Runtime* currentRuntime_;
4142

NativeScript/runtime/Runtime.mm

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,20 @@
1919
using namespace v8;
2020
using namespace std;
2121

22-
#ifdef DEBUG
2322
#include "v8-inspector-platform.h"
2423
#include "JsV8InspectorClient.h"
25-
#endif
2624

2725
namespace tns {
2826

2927
SimpleAllocator allocator_;
3028

31-
void Runtime::Initialize(void* metadataPtr, const char* nativesPtr, size_t nativesSize, const char* snapshotPtr, size_t snapshotSize) {
29+
void Runtime::Initialize(void* metadataPtr, const char* nativesPtr, size_t nativesSize, const char* snapshotPtr, size_t snapshotSize, bool isDebug) {
3230
MetaFile::setInstance(metadataPtr);
3331
nativesPtr_ = nativesPtr;
3432
nativesSize_ = nativesSize;
3533
snapshotPtr_ = snapshotPtr;
3634
snapshotSize_ = snapshotSize;
35+
isDebug_ = isDebug;
3736
}
3837

3938
Runtime::Runtime() {
@@ -47,11 +46,11 @@
4746
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count();
4847
printf("Runtime initialization took %llims\n", duration);
4948

50-
#ifdef DEBUG
51-
v8_inspector::JsV8InspectorClient* inspectorClient = new v8_inspector::JsV8InspectorClient(this->isolate_, baseDir);
52-
inspectorClient->init();
53-
inspectorClient->connect();
54-
#endif
49+
if (isDebug_) {
50+
v8_inspector::JsV8InspectorClient* inspectorClient = new v8_inspector::JsV8InspectorClient(this->isolate_, baseDir);
51+
inspectorClient->init();
52+
inspectorClient->connect();
53+
}
5554

5655
{
5756
Isolate* isolate = this->GetIsolate();
@@ -71,12 +70,9 @@
7170

7271
void Runtime::Init(const string& baseDir) {
7372
if (!mainThreadInitialized_) {
74-
Runtime::platform_ =
75-
#ifdef DEBUG
76-
v8_inspector::V8InspectorPlatform::CreateDefaultPlatform();
77-
#else
78-
platform::NewDefaultPlatform().release();
79-
#endif
73+
Runtime::platform_ = isDebug_
74+
? v8_inspector::V8InspectorPlatform::CreateDefaultPlatform()
75+
: platform::NewDefaultPlatform().release();
8076

8177
V8::InitializePlatform(Runtime::platform_);
8278
V8::Initialize();
@@ -121,7 +117,7 @@
121117
baseDir_ = baseDir;
122118
DefineGlobalObject(context);
123119
DefineCollectFunction(context);
124-
Console::Init(isolate);
120+
Console::Init(isolate, isDebug_);
125121
this->moduleInternal_.Init(isolate, baseDir);
126122

127123
ArgConverter::Init(isolate, MetadataBuilder::StructPropertyGetterCallback, MetadataBuilder::StructPropertySetterCallback);
@@ -233,6 +229,7 @@
233229
}
234230

235231
Platform* Runtime::platform_ = nullptr;
232+
bool Runtime::isDebug_ = false;
236233
const char* Runtime::nativesPtr_ = nullptr;
237234
size_t Runtime::nativesSize_ = 0;
238235
const char* Runtime::snapshotPtr_ = nullptr;

TestApp/Source Files/main.m

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,20 @@ int main(int argc, char *argv[]) {
2020

2121
NSString* applicationPath = [[NSBundle mainBundle] resourcePath];
2222

23+
bool isDebug =
24+
#ifdef DEBUG
25+
true;
26+
#else
27+
false;
28+
#endif
29+
2330
[NativeScript start:metadataPtr
2431
fromApplicationPath:applicationPath
2532
fromNativesPtr:startNativesPtr
2633
fromNativesSize:nativesSize
2734
fromSnapshotPtr:startSnapshotPtr
28-
fromSnapshotSize:snapshotSize];
35+
fromSnapshotSize:snapshotSize
36+
isDebug:isDebug];
2937

3038
return 0;
3139
}

0 commit comments

Comments
 (0)