Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add public api #84

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
)

Expand Down
19 changes: 11 additions & 8 deletions deps/node/node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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'
Expand Down
8 changes: 0 additions & 8 deletions deps/node/src/lwnode/aul-event-receiver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
63 changes: 63 additions & 0 deletions deps/node/src/lwnode/lwnode-public.cc
Original file line number Diff line number Diff line change
@@ -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 <uv.h>

#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
13 changes: 7 additions & 6 deletions deps/node/src/node_main_lw.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
*/

#include <cstdio>
#include "lwnode.h"
#include "lwnode/aul-event-receiver.h"
#include "lwnode/lwnode-public.h"
#include "node.h"

// UNIX
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion escargot.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
'libraries': [
'-lpthread',
'<@(escargot_libs)',
'-Wl,-rpath,\$$ORIGIN/<(output_dir)',
'-Wl,-rpath,\$$ORIGIN/../<(output_dir)',
'-Wl,-rpath,../lib',
'-Wl,-rpath,\$$ORIGIN',
],
Expand Down
37 changes: 37 additions & 0 deletions include/lwnode/lwnode-public.h
Original file line number Diff line number Diff line change
@@ -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 <string>

#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
5 changes: 1 addition & 4 deletions include/lwnode/lwnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@
#include <memory>
#include <string>
#include <unordered_map>
#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<v8::Object> target,
Expand Down
2 changes: 1 addition & 1 deletion packaging/lwnode.spec
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ BuildRequires: libasan
# Initialize the variables
%{!?target: %define target lwnode}
%{!?lib_type: %define lib_type shared} # <shared|static>
%{!?static_escargot: %define static_escargot 0}
%{!?static_escargot: %define static_escargot 1}
%{!?debug: %define debug 0}

%description
Expand Down