From 7b7f384e1bbab955a1369d2723a95753437fe053 Mon Sep 17 00:00:00 2001 From: Inhwan Lee Date: Tue, 17 Jan 2017 17:20:10 +0900 Subject: [PATCH] Implement metadata plugin for appfw If application has specific metadata, appfw will call plugin that implemented Only working for AOT with below metadata "http://tizen.org/metadata/prefer_dotnet_aot" Change-Id: I31a13b678ecfff3f430c4fad2656e5f358479cbf --- NativeLauncher/CMakeLists.txt | 15 ++++- NativeLauncher/inc/utils.h | 1 - .../installer-plugin/prefer_dotnet_aot_plugin.cc | 69 ++++++++++++++++++++++ NativeLauncher/util/utils.cc | 2 +- packaging/dotnet-launcher.spec | 4 ++ 5 files changed, 88 insertions(+), 3 deletions(-) mode change 100644 => 100755 NativeLauncher/CMakeLists.txt mode change 100644 => 100755 NativeLauncher/inc/utils.h create mode 100755 NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc mode change 100644 => 100755 NativeLauncher/util/utils.cc mode change 100644 => 100755 packaging/dotnet-launcher.spec diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt old mode 100644 new mode 100755 index 3c35c5f..5398487 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -7,7 +7,7 @@ IF(DEFINED NO_TIZEN) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DNO_TIZEN") ELSE(DEFINED NO_TIZEN) INCLUDE(FindPkgConfig) - PKG_CHECK_MODULES(${PROJECT_NAME} REQUIRED aul pkgmgr-info pkgmgr-installer dlog ecore bundle dlog launchpad elementary) + PKG_CHECK_MODULES(${PROJECT_NAME} REQUIRED aul pkgmgr-info pkgmgr-installer dlog ecore bundle dlog launchpad elementary glib-2.0) ENDIF(DEFINED NO_TIZEN) FOREACH(flag ${${PROJECT_NAME}_CFLAGS}) @@ -99,10 +99,23 @@ ADD_LIBRARY(${INSTALLER_PLUGIN} SHARED ${${INSTALLER_PLUGIN}_SOURCE_FILES}) SET_TARGET_PROPERTIES(${INSTALLER_PLUGIN} PROPERTIES COMPILE_FLAGS "-fPIC") TARGET_LINK_LIBRARIES(${INSTALLER_PLUGIN} ${${PROJECT_NAME}_LDFLAGS}) + +SET(PREFER_DOTNET_AOT_PLUGIN "prefer_dotnet_aot_plugin") +SET(${PREFER_DOTNET_AOT_PLUGIN}_SOURCE_FILES + util/utils.cc + installer-plugin/common.cc + installer-plugin/prefer_dotnet_aot_plugin.cc +) +ADD_LIBRARY(${PREFER_DOTNET_AOT_PLUGIN} SHARED ${${PREFER_DOTNET_AOT_PLUGIN}_SOURCE_FILES}) +SET_TARGET_PROPERTIES(${PREFER_DOTNET_AOT_PLUGIN} PROPERTIES COMPILE_FLAGS "-fPIC") +TARGET_LINK_LIBRARIES(${PREFER_DOTNET_AOT_PLUGIN} ${${PROJECT_NAME}_LDFLAGS}) + + IF(NOT DEFINED NO_TIZEN) INSTALL(TARGETS ${DOTNET_LAUNCHER} DESTINATION ${BINDIR}) INSTALL(TARGETS ${NITOOL} DESTINATION ${BINDIR}) INSTALL(TARGETS ${INSTALLER_PLUGIN} DESTINATION ${INSTALL_PLUGIN_DIR}) + INSTALL(TARGETS ${PREFER_DOTNET_AOT_PLUGIN} DESTINATION ${INSTALL_MDPLUGIN_DIR}) INSTALL(FILES dotnet.loader DESTINATION ${LOADERDIR}) INSTALL(FILES dotnet.launcher DESTINATION ${LOADERDIR}) INSTALL(FILES dotnet.debugger DESTINATION ${LOADERDIR}) diff --git a/NativeLauncher/inc/utils.h b/NativeLauncher/inc/utils.h old mode 100644 new mode 100755 index 3e56112..b66a708 --- a/NativeLauncher/inc/utils.h +++ b/NativeLauncher/inc/utils.h @@ -41,5 +41,4 @@ std::string JoinStrings(const std::vector& strings, const char* con typedef std::function FileReader; void ScanFilesInDir(const char* directory, FileReader reader, unsigned int depth); - #endif // __UTILS_H__ diff --git a/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc b/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc new file mode 100755 index 0000000..f180739 --- /dev/null +++ b/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2016 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 "common.h" +#include "log.h" +#include "utils.h" + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "NETCORE_INSTALLER_PLUGIN" + +#include +#include +#include +#include + +typedef struct Metadata { + const char *key; + const char *value; +} Metadata; + +const std::string VALUE_TRUE = "true"; +const std::string mdKey = "http://tizen.org/metadata/prefer_dotnet_aot"; +extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL (const char *pkgid, const char *appid, GList *list) +{ + + GList *tag = NULL; + bool mdValue = false; + Metadata *mdInfo = NULL; + tag = g_list_first(list); + while (tag) { + mdInfo = (Metadata*)tag->data; + if(mdInfo->key == mdKey && mdInfo->value == VALUE_TRUE) { + _DBG("Prefer dotnet application AOT set TRUE"); + mdValue = true; + } + tag = g_list_next(tag); + } + + if (mdValue) { + if (create_ni_under_pkg_root(pkgid) != 0) + { + _ERR("Failed to get root path from [%s]", pkgid); + return -1; + } else { + _DBG("Complete make application to native image"); + } + } + return 0; +} + +extern "C" int PKGMGR_MDPARSER_PLUGIN_UPGRADE (const char *pkgid, const char *appid, GList *list) +{ + return PKGMGR_MDPARSER_PLUGIN_INSTALL(pkgid, appid, list); +} diff --git a/NativeLauncher/util/utils.cc b/NativeLauncher/util/utils.cc old mode 100644 new mode 100755 index 48810d9..212f1d6 --- a/NativeLauncher/util/utils.cc +++ b/NativeLauncher/util/utils.cc @@ -349,4 +349,4 @@ void ScanFilesInDir(const char* directory, FileReader reader, unsigned int depth } closedir(dir); -} +} \ No newline at end of file diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec old mode 100644 new mode 100755 index ac73341..7a40c06 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -16,6 +16,7 @@ BuildRequires: pkgconfig(launchpad) BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(pkgmgr-installer) BuildRequires: pkgconfig(elementary) +BuildRequires: pkgconfig(glib-2.0) BuildRequires: aul-devel BuildRequires: dotnet-build-tools @@ -33,6 +34,7 @@ Requires(preun): /usr/bin/systemctl %define _runtime_dir /opt/usr/share/dotnet/shared/Microsoft.NETCore.App/1.0.0 %define _preload_dir /opt/usr/share/dotnet.tizen/preload %define _install_plugin_dir /usr/etc/package-manager/parserlib +%define _install_mdplugin_dir /etc/package-manager/parserlib/metadata ExcludeArch: %{ix86} aarch64 @@ -57,6 +59,7 @@ cmake \ -DCORECLR_LAUNCHER_ASSEMBLY_PATH=%{_bindir}/Tizen.Runtime.Coreclr.dll \ -DMONO_LAUNCHER_ASSEMBLY_PATH=%{_bindir}/Tizen.Runtime.Mono.dll \ -DINSTALL_PLUGIN_DIR=%{_install_plugin_dir} \ + -DINSTALL_MDPLUGIN_DIR=%{_install_mdplugin_dir} \ -DVERSION=%{version} \ NativeLauncher @@ -90,5 +93,6 @@ install -p -m 644 Tizen.Runtime/bin/Tizen.Runtime.Mono.dll %{buildroot}%{_bindir %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/dotnet-launcher %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/nitool %caps(cap_mac_admin,cap_setgid=ei) %{_install_plugin_dir}/libui-application.so +%caps(cap_mac_admin,cap_setgid=ei) %{_install_mdplugin_dir}/libprefer_dotnet_aot_plugin.so %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.Coreclr.dll %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/Tizen.Runtime.Mono.dll -- 2.7.4