diff options
author | Lukasz Kostyra <l.kostyra@samsung.com> | 2017-09-21 14:35:29 +0200 |
---|---|---|
committer | Lukasz Kostyra <l.kostyra@samsung.com> | 2017-10-16 10:29:11 +0200 |
commit | 1e56d1851ee81add03dc4322ca40cc85fa2ccf50 (patch) | |
tree | c2e12b6d9f3f7c17f979b8346714237e6bf770c5 | |
parent | f546589431b12295e0afed1ee57e3aea2c2af7c2 (diff) | |
download | libteec-1e56d1851ee81add03dc4322ca40cc85fa2ccf50.tar.gz libteec-1e56d1851ee81add03dc4322ca40cc85fa2ccf50.tar.bz2 libteec-1e56d1851ee81add03dc4322ca40cc85fa2ccf50.zip |
Add packaging and rpm building
Change-Id: I117d5ac482a98008cd6bf8835b1d0006c4aaf983
-rw-r--r-- | packaging/webapi-plugins-teec.spec | 75 | ||||
-rw-r--r-- | plugins.manifest | 5 | ||||
-rw-r--r-- | src/teec/libteec_api.js | 2 | ||||
-rw-r--r-- | src/teec/teec.gyp | 27 | ||||
-rw-r--r-- | src/tizen-wrt.gyp | 16 | ||||
-rw-r--r-- | src/tool/desc_gentool.cc | 239 | ||||
-rw-r--r-- | src/tool/tool.gyp | 25 |
7 files changed, 388 insertions, 1 deletions
diff --git a/packaging/webapi-plugins-teec.spec b/packaging/webapi-plugins-teec.spec new file mode 100644 index 0000000..4a0ea10 --- /dev/null +++ b/packaging/webapi-plugins-teec.spec @@ -0,0 +1,75 @@ +%bcond_with wayland + +%define _manifestdir %{TZ_SYS_RW_PACKAGES} +%define _desktop_icondir %{TZ_SYS_SHARE}/icons/default/small + +%define crosswalk_extensions tizen-extensions-crosswalk + +%define crosswalk_extensions_path %{_libdir}/%{crosswalk_extensions} + +Name: webapi-plugins-teec +Version: 0.1 +Release: 0 +License: Apache-2.0 and BSD-2.0 and MIT +Group: Development/Libraries +Summary: Tizen Web plugin for TEF client library TEEC +Source0: %{name}-%{version}.tar.gz + +%ifarch %{arm} aarch64 +# ARM +%define tizen_is_emulator 0 +%else +# I586 +%define tizen_is_emulator 1 +%endif + +BuildRequires: ninja +BuildRequires: pkgconfig(webapi-plugins) +BuildRequires: tef-libteec + +%description +Tizen TEF Framework Client API plugin + +%prep +%setup -q + +%build + +export GYP_GENERATORS='ninja' +GYP_OPTIONS="--depth=. -Dtizen=1 -Dextension_build_type=Debug -Dextension_host_os=%{profile} -Dprivilege_engine=%{tizen_privilege_engine}" +GYP_OPTIONS="$GYP_OPTIONS -Ddisplay_type=%{display_type}" +GYP_OPTIONS="$GYP_OPTIONS -Dcrosswalk_extensions_path=%{crosswalk_extensions_path}" + +# feature flags +GYP_OPTIONS="$GYP_OPTIONS -Dtizen_is_emulator=%{?tizen_is_emulator}" + +/usr/include/webapi-plugins/tools/gyp/gyp $GYP_OPTIONS src/tizen-wrt.gyp + +ninja -C out/Default %{?_smp_mflags} + +%install + +# Extensions. +mkdir -p %{buildroot}%{crosswalk_extensions_path} +install -p -m 644 ./out/Default/libtizen*.so %{buildroot}%{crosswalk_extensions_path} + +# execute desc_gentool +LD_LIBRARY_PATH=$LD_LIBRARY_PATH:%{buildroot}%{crosswalk_extensions_path} out/Default/desc_gentool \ + %{crosswalk_extensions_path} \ + %{buildroot}%{crosswalk_extensions_path} > teec_plugin.json + +# temporary plugins description for lazy loading +install -p -m 644 teec_plugin.json %{buildroot}%{crosswalk_extensions_path}/teec_plugin.json + +%post +#append ocal plugin.json to plugin.json of system +head %{crosswalk_extensions_path}/plugins.json -n -2 > tmp.json +echo " }," >> tmp.json +tail %{crosswalk_extensions_path}/teec_plugin.json -n +2 >> tmp.json +rm -f %{crosswalk_extensions_path}/plugins.json +mv -f tmp.json %{crosswalk_extensions_path}/plugins.json + +%files +%{crosswalk_extensions_path}/libtizen*.so +%{crosswalk_extensions_path}/teec_plugin.json +%manifest plugins.manifest diff --git a/plugins.manifest b/plugins.manifest new file mode 100644 index 0000000..f5a44ec --- /dev/null +++ b/plugins.manifest @@ -0,0 +1,5 @@ +<manifest> + <request> + <domain name="_"/> + </request> +</manifest> diff --git a/src/teec/libteec_api.js b/src/teec/libteec_api.js index 44dab9c..68811dd 100644 --- a/src/teec/libteec_api.js +++ b/src/teec/libteec_api.js @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/teec/teec.gyp b/src/teec/teec.gyp new file mode 100644 index 0000000..a6ab469 --- /dev/null +++ b/src/teec/teec.gyp @@ -0,0 +1,27 @@ +{ + 'includes':[ + '/usr/include/webapi-plugins/src/common/common.gypi', + ], + 'targets': [ + { + 'target_name': 'tizen_teec', + 'type': 'loadable_module', + 'sources': [ + 'libteec_api.js', + 'libteec_extension.cc', + 'libteec_extension.h', + 'libteec_instance.cc', + 'libteec_instance.h', + ], + 'include_dirs': [ + '../', + '<(SHARED_INTERMEDIATE_DIR)', + ], + 'variables': { + 'packages': [ + 'webapi-plugins', + ], + }, + }, + ], +} diff --git a/src/tizen-wrt.gyp b/src/tizen-wrt.gyp new file mode 100644 index 0000000..c35f164 --- /dev/null +++ b/src/tizen-wrt.gyp @@ -0,0 +1,16 @@ +{ + 'includes':[ + '/usr/include/webapi-plugins/src/common/common.gypi', + ], + 'targets': [ + { + 'target_name': 'extensions', + 'type': 'none', + 'dependencies': [ + 'tool/tool.gyp:*', + 'teec/teec.gyp:*', + ], + 'conditions': [], + }, + ], +} diff --git a/src/tool/desc_gentool.cc b/src/tool/desc_gentool.cc new file mode 100644 index 0000000..9417e50 --- /dev/null +++ b/src/tool/desc_gentool.cc @@ -0,0 +1,239 @@ +/* + * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved + * + * 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 <iostream> +#include <string> +#include <vector> +#include <map> +#include <functional> + +#include <dlfcn.h> +#include <dirent.h> +#include <unistd.h> +#include <stdio.h> +#include <errno.h> + +#include <common/extension.h> + +static std::string prefix_ = "libtizen"; +static std::string postfix_ = ".so"; +static std::vector<std::string> apinamespaces = {"tizen", "xwalk", "webapis"}; + +typedef common::Extension *(*CreateExtensionFunc)(void); + +struct module_description { + std::string name; + std::string lib; + std::vector<std::string> entries; +}; + + +static XW_Extension ext = 0; +static std::map<XW_Extension, module_description> descriptions; + +#ifndef JSON_MINIFY + #define PRINT_TAB() std::cout << "\t" +#else + #define PRINT_TAB() +#endif + +void print_json() { + std::cout << "[" << std::endl; + for (const auto& kv : descriptions) { + const module_description &desc = kv.second; + + std::string::size_type n = desc.name.find('.'); + std::string ns = + n == std::string::npos ? desc.name : desc.name.substr(0, n); + + if (std::find(apinamespaces.begin(), apinamespaces.end(), ns) == + apinamespaces.end()) { + continue; + } + + PRINT_TAB(); + std::cout << "{" << std::endl; + PRINT_TAB(); + PRINT_TAB(); + std::cout << "\"name\":\"" << desc.name << "\"," << std::endl; + PRINT_TAB(); + PRINT_TAB(); + std::cout << "\"lib\":\"" << desc.lib << "\"," << std::endl; + PRINT_TAB(); + PRINT_TAB(); + std::cout << "\"entry_points\": ["; + for (std::vector<std::string>::size_type i=0; i<desc.entries.size(); i++) { + if (i != 0) { + std::cout << ","; + } + std::cout << "\"" << desc.entries[i] << "\""; + } + std::cout << "]" << std::endl; + PRINT_TAB(); + std::cout << "}"; + if (kv.first != ext) { + std::cout << ","; + } + std::cout << std::endl; + } + std::cout << "]" << std::endl; +} + +const void* get_interface(const char* name) { + if (!strcmp(name, XW_CORE_INTERFACE_1)) { + static const XW_CoreInterface coreInterface1 = { + [](XW_Extension extension, const char* name) { + module_description *desc = &descriptions[extension]; + desc->name = name; + }, + [](XW_Extension extension, const char* api) {}, + [](XW_Extension extension, XW_CreatedInstanceCallback created, + XW_DestroyedInstanceCallback destroyed) {}, + [](XW_Extension extension, XW_ShutdownCallback shutdown_callback) {}, + [](XW_Instance instance, void* data) {}, + [](XW_Instance instance) -> void* { return nullptr; } + }; + return &coreInterface1; + } + + if (!strcmp(name, XW_INTERNAL_ENTRY_POINTS_INTERFACE_1)) { + static const XW_Internal_EntryPointsInterface entryPointsInterface1 = { + [](XW_Extension extension, const char** entries) { + module_description *desc = &descriptions[extension]; + for (int i=0; entries[i]; i++) { + desc->entries.push_back(std::string(entries[i])); + } + } + }; + return &entryPointsInterface1; + } + + if (!strcmp(name, XW_MESSAGING_INTERFACE_1)) { + static const XW_MessagingInterface_1 messagingInterface1 = { + [](XW_Extension extension, XW_HandleMessageCallback handle_message) { + }, + [](XW_Instance instance, const char* message) { + } + }; + return &messagingInterface1; + } + + if (!strcmp(name, XW_INTERNAL_SYNC_MESSAGING_INTERFACE_1)) { + static const XW_Internal_SyncMessagingInterface syncMessagingInterface1 = { + [](XW_Extension extension, XW_HandleSyncMessageCallback handle_sync_msg) { + }, + [](XW_Instance instance, const char* reply){ + } + }; + return &syncMessagingInterface1; + } + + if (!strcmp(name, XW_INTERNAL_RUNTIME_INTERFACE_1)) { + static const XW_Internal_RuntimeInterface_1 runtimeInterface1 = { + [](XW_Extension extension, const char* key, char* value, size_t vlen) { + } + }; + return &runtimeInterface1; + } + + if (!strcmp(name, XW_INTERNAL_PERMISSIONS_INTERFACE_1)) { + static const XW_Internal_PermissionsInterface_1 permissionsInterface1 = { + [](XW_Extension extension, const char* api_name) -> int { + return XW_ERROR; + }, + [](XW_Extension extension, const char* perm_table) -> int { + return XW_ERROR; + } + }; + return &permissionsInterface1; + } + + return NULL; +} + +int main(int argc, char* argv[]) { + if (argc < 3) { + std::cerr << "Need tizen crosswalk path" << std::endl; + return -1; + } + std::string lib_path = argv[1]; + if (lib_path.empty()) { + std::cerr << "Invalid libpath for tec." << std::endl; + return -1; + } + + std::string tec_path = argv[2]; + if (tec_path.empty()) { + std::cerr << "Invalid tizen crosswalk path" << std::endl; + return -1; + } + + struct dirent** namelist; + int num_entries = scandir(tec_path.c_str(), &namelist, NULL, alphasort); + if( num_entries >= 0 ) { + for( int i = 0; i < num_entries; ++i ) { + std::string fname = namelist[i]->d_name; + + if (fname.size() >= prefix_.size() + postfix_.size() && + !fname.compare(0, prefix_.size(), prefix_) && + !fname.compare(fname.size() - postfix_.size(), postfix_.size(), + postfix_)) { + std::string so_path = tec_path + "/" + fname; + void *handle = dlopen(so_path.c_str(), RTLD_LAZY); + if (handle == NULL) { + std::cerr << "cannot open " << so_path << std::endl; + char* error = dlerror(); + std::cerr << "Error >>" << ((error == NULL) ? "NULL" : error) << std::endl; + return -1; + } + + XW_Initialize_Func initialize = reinterpret_cast<XW_Initialize_Func>( + dlsym(handle, "XW_Initialize")); + + if (!initialize) { + std::cerr << "Can not loading extension " << fname << std::endl; + } else { + ext++; + descriptions[ext] = module_description(); + descriptions[ext].lib = lib_path + "/" + fname; + int ret = initialize(ext, get_interface); + if (ret != XW_OK) { + std::cerr << "Error loading extension " << fname << std::endl; + } + } + + // some Shared libraries have static finalizer. + // __attribute__((destructor)) this gcc extension makes finalizer. + // if close it, it can makes segfault. + // True, It's shared object's problem. but we can't fix it. + // so don't close it in only this tool. just finish process. + // + // dlclose(handle); + } + free(namelist[i]); + } + free(namelist); + print_json(); + } else { + perror("scandir"); + if( errno == ENOENT ) + std::cerr << "path not exist : " << tec_path << std::endl; + return -1; + } + + // it would be need for ignore loaded libraries destructor + _exit(0); +} diff --git a/src/tool/tool.gyp b/src/tool/tool.gyp new file mode 100644 index 0000000..ed978ce --- /dev/null +++ b/src/tool/tool.gyp @@ -0,0 +1,25 @@ +{ + 'target_defaults': { + 'variables': {'packages': ['dlog']}, + 'includes': [ + '/usr/include/webapi-plugins/src/common/pkg-config.gypi' + ] + }, + 'targets' : [ + { + 'target_name': 'desc_gentool', + 'cflags': [ + '-std=c++0x', + '-Wall' + ], + 'link_settings': {'libraries': [ '-ldl'], }, + 'include_dirs': [ + '/usr/include/webapi-plugins/src/' + ], + 'type': 'executable', + 'sources': [ + 'desc_gentool.cc' + ] + } + ] +} |