From d84ebf03470eef2a6e57ca1bb42616d3096b8dd9 Mon Sep 17 00:00:00 2001 From: Hosung Kim Date: Thu, 21 Nov 2024 14:57:22 +0900 Subject: [PATCH] feat: add public api MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Hosung Kim hs852.kim@samsung.com --- configure.py | 2 +- deps/node/node.gyp | 19 ++++--- deps/node/src/lwnode/aul-event-receiver.cc | 8 --- deps/node/src/lwnode/lwnode-public.cc | 63 ++++++++++++++++++++++ deps/node/src/node_main_lw.cc | 13 ++--- escargot.gyp | 2 +- include/lwnode/lwnode-public.h | 37 +++++++++++++ include/lwnode/lwnode.h | 5 +- packaging/lwnode.spec | 2 +- 9 files changed, 122 insertions(+), 29 deletions(-) create mode 100644 deps/node/src/lwnode/lwnode-public.cc create mode 100644 include/lwnode/lwnode-public.h diff --git a/configure.py b/configure.py index 609777d091..a6d466689b 100755 --- a/configure.py +++ b/configure.py @@ -223,7 +223,7 @@ def setupCLIOptions(parser): lwnode_optgroup.add_option( '--escargot-lib-type', choices=['shared_lib', 'static_lib'], - default='shared_lib', + default='static_lib', help='shared_lib | static_lib (%default)', ) diff --git a/deps/node/node.gyp b/deps/node/node.gyp index 9c5b2e7bcd..107f4f7c72 100644 --- a/deps/node/node.gyp +++ b/deps/node/node.gyp @@ -387,20 +387,13 @@ [ 'lwnode=="true"', { 'cflags': ['-Wno-write-strings'], 'sources': [ - 'src/node_main_lw.cc', - 'src/lwnode/aul-event-receiver.cc' + 'src/node_main_lw.cc' ], }, { 'sources': [ 'src/node_main.cc' ], }], - ['target_os=="tizen"', { - 'dependencies': [ - '<(lwnode_jsengine_path)/deps/tizen.gyp:dlog', - '<(lwnode_jsengine_path)/deps/tizen.gyp:appcommon', - ], - }], # /@lwnode [ 'error_on_warn=="true"', { 'cflags': ['-Werror'], @@ -799,7 +792,17 @@ '<(lwnode_jsengine_path)/escargotshim.gyp:escargotshim', '<(lwnode_jsengine_path)/deps/node-bindings/node_bindings.gyp:node_bindings', ], + 'sources': [ + 'src/lwnode/aul-event-receiver.cc', + 'src/lwnode/lwnode-public.cc', + ], 'conditions': [ + ['target_os=="tizen"', { + 'dependencies': [ + '<(lwnode_jsengine_path)/deps/tizen.gyp:dlog', + '<(lwnode_jsengine_path)/deps/tizen.gyp:appcommon', + ], + }], ['external_builtins=="true"', { 'variables': { 'archive_filename%': '<(node_core_target_name).dat' diff --git a/deps/node/src/lwnode/aul-event-receiver.cc b/deps/node/src/lwnode/aul-event-receiver.cc index a5a1f654ea..7ecb5e5c63 100644 --- a/deps/node/src/lwnode/aul-event-receiver.cc +++ b/deps/node/src/lwnode/aul-event-receiver.cc @@ -101,14 +101,6 @@ bool AULEventReceiver::start(int argc, char* argv[]) { LWNODE_DEV_LOG(parsed_bundle); LWNODE_DEV_LOG("appid:", appid_); - char* path = app_get_resource_path(); - if (uv_chdir(path) != 0) { - LWNODE_DEV_LOGF("ERROR: Failed to change directory. (%d)", -errno); - free(path); - exit(-errno); - } - free(path); - assert(!appid_.empty()); } else { initLoggerOutput(false); diff --git a/deps/node/src/lwnode/lwnode-public.cc b/deps/node/src/lwnode/lwnode-public.cc new file mode 100644 index 0000000000..1c3bc456c3 --- /dev/null +++ b/deps/node/src/lwnode/lwnode-public.cc @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024-present Samsung Electronics Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#include "lwnode-public.h" +#include "lwnode.h" +#include "lwnode/aul-event-receiver.h" +#include "node.h" +#include "trace.h" + +namespace lwnode { + +bool ParseAULEvent(int argc, char** argv) { + bool result = AULEventReceiver::getInstance()->start(argc, argv); + if (result) { + LWNode::SystemInfo::getInstance()->add("aul"); + } + + return result; +} + +bool InitScriptRootPath(const std::string path) { +#if defined(HOST_TIZEN) + int result; + if (path.empty()) { + char* path = app_get_resource_path(); + result = uv_chdir(path); + free(path); + } else { + result = uv_chdir(path.c_str()); + } + + if (result != 0) { + LWNODE_DEV_LOGF("ERROR: Failed to change directory. (%d)\n", -errno); + + return false; + } + + return true; +#else + return false; +#endif +} + +int Start(int argc, char** argv) { + return node::Start(argc, argv); +} + +} // namespace LWNode diff --git a/deps/node/src/node_main_lw.cc b/deps/node/src/node_main_lw.cc index 3e8e5909c7..8eb639139f 100644 --- a/deps/node/src/node_main_lw.cc +++ b/deps/node/src/node_main_lw.cc @@ -15,8 +15,7 @@ */ #include -#include "lwnode.h" -#include "lwnode/aul-event-receiver.h" +#include "lwnode/lwnode-public.h" #include "node.h" // UNIX @@ -72,13 +71,15 @@ int main(int argc, char* argv[]) { setvbuf(stdout, nullptr, _IONBF, 0); setvbuf(stderr, nullptr, _IONBF, 0); - if (AULEventReceiver::getInstance()->start(argc, argv)) { - LWNode::SystemInfo::getInstance()->add("aul"); + if (lwnode::ParseAULEvent(argc, argv)) { + if (!lwnode::InitScriptRootPath()) { + exit(-errno); + } char* args[] = {"", "index.js", nullptr}; - return node::Start(2, args); + return lwnode::Start(2, args); } // started by command line - return node::Start(argc, argv); + return lwnode::Start(argc, argv); } diff --git a/escargot.gyp b/escargot.gyp index 06397e373b..e08b3d681b 100755 --- a/escargot.gyp +++ b/escargot.gyp @@ -60,7 +60,7 @@ 'libraries': [ '-lpthread', '<@(escargot_libs)', - '-Wl,-rpath,\$$ORIGIN/<(output_dir)', + '-Wl,-rpath,\$$ORIGIN/../<(output_dir)', '-Wl,-rpath,../lib', '-Wl,-rpath,\$$ORIGIN', ], diff --git a/include/lwnode/lwnode-public.h b/include/lwnode/lwnode-public.h new file mode 100644 index 0000000000..f17727fb90 --- /dev/null +++ b/include/lwnode/lwnode-public.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2024-present Samsung Electronics Co., Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include + +#ifndef LWNODE_EXPORT +#define LWNODE_EXPORT __attribute__((visibility("default"))) +#endif + +namespace lwnode { + +LWNODE_EXPORT bool ParseAULEvent(int argc, char** argv); + +// Support only Tizen platform. +// Sets the path of the root directory of the JavaScript. If you do not put the +// path argument, the root path is the app's resource path +// by default. Be sure to call this function before lwnode::Start function. +LWNODE_EXPORT bool InitScriptRootPath(const std::string path = ""); + +LWNODE_EXPORT int Start(int argc, char** argv); + +} // namespace lwnode diff --git a/include/lwnode/lwnode.h b/include/lwnode/lwnode.h index 8c66b1010a..2bed3da6ba 100644 --- a/include/lwnode/lwnode.h +++ b/include/lwnode/lwnode.h @@ -21,16 +21,13 @@ #include #include #include +#include "lwnode-public.h" namespace Escargot { class ContextRef; class ValueRef; } // namespace Escargot -#ifndef LWNODE_EXPORT -#define LWNODE_EXPORT __attribute__((visibility("default"))) -#endif - namespace LWNode { void InitializeProcessMethods(v8::Local target, diff --git a/packaging/lwnode.spec b/packaging/lwnode.spec index ee5384b68c..dd37b5e9e8 100644 --- a/packaging/lwnode.spec +++ b/packaging/lwnode.spec @@ -69,7 +69,7 @@ BuildRequires: libasan # Initialize the variables %{!?target: %define target lwnode} %{!?lib_type: %define lib_type shared} # -%{!?static_escargot: %define static_escargot 0} +%{!?static_escargot: %define static_escargot 1} %{!?debug: %define debug 0} %description