Skip to content

Commit d84ebf0

Browse files
committed
feat: add public api
Signed-off-by: Hosung Kim [email protected]
1 parent 0573ce7 commit d84ebf0

File tree

9 files changed

+122
-29
lines changed

9 files changed

+122
-29
lines changed

configure.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def setupCLIOptions(parser):
223223
lwnode_optgroup.add_option(
224224
'--escargot-lib-type',
225225
choices=['shared_lib', 'static_lib'],
226-
default='shared_lib',
226+
default='static_lib',
227227
help='shared_lib | static_lib (%default)',
228228
)
229229

deps/node/node.gyp

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -387,20 +387,13 @@
387387
[ 'lwnode=="true"', {
388388
'cflags': ['-Wno-write-strings'],
389389
'sources': [
390-
'src/node_main_lw.cc',
391-
'src/lwnode/aul-event-receiver.cc'
390+
'src/node_main_lw.cc'
392391
],
393392
}, {
394393
'sources': [
395394
'src/node_main.cc'
396395
],
397396
}],
398-
['target_os=="tizen"', {
399-
'dependencies': [
400-
'<(lwnode_jsengine_path)/deps/tizen.gyp:dlog',
401-
'<(lwnode_jsengine_path)/deps/tizen.gyp:appcommon',
402-
],
403-
}],
404397
# /@lwnode
405398
[ 'error_on_warn=="true"', {
406399
'cflags': ['-Werror'],
@@ -799,7 +792,17 @@
799792
'<(lwnode_jsengine_path)/escargotshim.gyp:escargotshim',
800793
'<(lwnode_jsengine_path)/deps/node-bindings/node_bindings.gyp:node_bindings',
801794
],
795+
'sources': [
796+
'src/lwnode/aul-event-receiver.cc',
797+
'src/lwnode/lwnode-public.cc',
798+
],
802799
'conditions': [
800+
['target_os=="tizen"', {
801+
'dependencies': [
802+
'<(lwnode_jsengine_path)/deps/tizen.gyp:dlog',
803+
'<(lwnode_jsengine_path)/deps/tizen.gyp:appcommon',
804+
],
805+
}],
803806
['external_builtins=="true"', {
804807
'variables': {
805808
'archive_filename%': '<(node_core_target_name).dat'

deps/node/src/lwnode/aul-event-receiver.cc

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,6 @@ bool AULEventReceiver::start(int argc, char* argv[]) {
101101
LWNODE_DEV_LOG(parsed_bundle);
102102
LWNODE_DEV_LOG("appid:", appid_);
103103

104-
char* path = app_get_resource_path();
105-
if (uv_chdir(path) != 0) {
106-
LWNODE_DEV_LOGF("ERROR: Failed to change directory. (%d)", -errno);
107-
free(path);
108-
exit(-errno);
109-
}
110-
free(path);
111-
112104
assert(!appid_.empty());
113105
} else {
114106
initLoggerOutput(false);

deps/node/src/lwnode/lwnode-public.cc

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) 2024-present Samsung Electronics Co., Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include <uv.h>
18+
19+
#include "lwnode-public.h"
20+
#include "lwnode.h"
21+
#include "lwnode/aul-event-receiver.h"
22+
#include "node.h"
23+
#include "trace.h"
24+
25+
namespace lwnode {
26+
27+
bool ParseAULEvent(int argc, char** argv) {
28+
bool result = AULEventReceiver::getInstance()->start(argc, argv);
29+
if (result) {
30+
LWNode::SystemInfo::getInstance()->add("aul");
31+
}
32+
33+
return result;
34+
}
35+
36+
bool InitScriptRootPath(const std::string path) {
37+
#if defined(HOST_TIZEN)
38+
int result;
39+
if (path.empty()) {
40+
char* path = app_get_resource_path();
41+
result = uv_chdir(path);
42+
free(path);
43+
} else {
44+
result = uv_chdir(path.c_str());
45+
}
46+
47+
if (result != 0) {
48+
LWNODE_DEV_LOGF("ERROR: Failed to change directory. (%d)\n", -errno);
49+
50+
return false;
51+
}
52+
53+
return true;
54+
#else
55+
return false;
56+
#endif
57+
}
58+
59+
int Start(int argc, char** argv) {
60+
return node::Start(argc, argv);
61+
}
62+
63+
} // namespace LWNode

deps/node/src/node_main_lw.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616

1717
#include <cstdio>
18-
#include "lwnode.h"
19-
#include "lwnode/aul-event-receiver.h"
18+
#include "lwnode/lwnode-public.h"
2019
#include "node.h"
2120

2221
// UNIX
@@ -72,13 +71,15 @@ int main(int argc, char* argv[]) {
7271
setvbuf(stdout, nullptr, _IONBF, 0);
7372
setvbuf(stderr, nullptr, _IONBF, 0);
7473

75-
if (AULEventReceiver::getInstance()->start(argc, argv)) {
76-
LWNode::SystemInfo::getInstance()->add("aul");
74+
if (lwnode::ParseAULEvent(argc, argv)) {
75+
if (!lwnode::InitScriptRootPath()) {
76+
exit(-errno);
77+
}
7778

7879
char* args[] = {"", "index.js", nullptr};
79-
return node::Start(2, args);
80+
return lwnode::Start(2, args);
8081
}
8182

8283
// started by command line
83-
return node::Start(argc, argv);
84+
return lwnode::Start(argc, argv);
8485
}

escargot.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
'libraries': [
6161
'-lpthread',
6262
'<@(escargot_libs)',
63-
'-Wl,-rpath,\$$ORIGIN/<(output_dir)',
63+
'-Wl,-rpath,\$$ORIGIN/../<(output_dir)',
6464
'-Wl,-rpath,../lib',
6565
'-Wl,-rpath,\$$ORIGIN',
6666
],

include/lwnode/lwnode-public.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright (c) 2024-present Samsung Electronics Co., Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include <string>
20+
21+
#ifndef LWNODE_EXPORT
22+
#define LWNODE_EXPORT __attribute__((visibility("default")))
23+
#endif
24+
25+
namespace lwnode {
26+
27+
LWNODE_EXPORT bool ParseAULEvent(int argc, char** argv);
28+
29+
// Support only Tizen platform.
30+
// Sets the path of the root directory of the JavaScript. If you do not put the
31+
// path argument, the root path is the app's resource path
32+
// by default. Be sure to call this function before lwnode::Start function.
33+
LWNODE_EXPORT bool InitScriptRootPath(const std::string path = "");
34+
35+
LWNODE_EXPORT int Start(int argc, char** argv);
36+
37+
} // namespace lwnode

include/lwnode/lwnode.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@
2121
#include <memory>
2222
#include <string>
2323
#include <unordered_map>
24+
#include "lwnode-public.h"
2425

2526
namespace Escargot {
2627
class ContextRef;
2728
class ValueRef;
2829
} // namespace Escargot
2930

30-
#ifndef LWNODE_EXPORT
31-
#define LWNODE_EXPORT __attribute__((visibility("default")))
32-
#endif
33-
3431
namespace LWNode {
3532

3633
void InitializeProcessMethods(v8::Local<v8::Object> target,

packaging/lwnode.spec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ BuildRequires: libasan
6969
# Initialize the variables
7070
%{!?target: %define target lwnode}
7171
%{!?lib_type: %define lib_type shared} # <shared|static>
72-
%{!?static_escargot: %define static_escargot 0}
72+
%{!?static_escargot: %define static_escargot 1}
7373
%{!?debug: %define debug 0}
7474

7575
%description

0 commit comments

Comments
 (0)