From: 최종헌/Common Platform Lab(SR)/Engineer/삼성전자 Date: Tue, 18 Aug 2020 07:46:43 +0000 (+0900) Subject: Delete unused libraries when installing the application (#269) X-Git-Tag: accepted/tizen/unified/20200820.034645~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;ds=sidebyside;h=9604424274a177bdcd46345f3c989d8bea6ea34f;p=platform%2Fcore%2Fdotnet%2Flauncher.git Delete unused libraries when installing the application (#269) Change-Id: I984b1ba19f2190504b912ee9a70a501e978c0d71 --- diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index 11945bf..e3254ee 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -223,6 +223,14 @@ ADD_LIBRARY(${PREFER_NUGET_CACHE_PLUGIN} SHARED ${${PREFER_NUGET_CACHE_PLUGIN}_S SET_TARGET_PROPERTIES(${PREFER_NUGET_CACHE_PLUGIN} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_LIB}) TARGET_LINK_LIBRARIES(${PREFER_NUGET_CACHE_PLUGIN} ${${PROJECT_NAME}_LDFLAGS} ${DOTNET_LAUNCHER_UTIL} ${TAC_COMMON}) +SET(DELETE_UNUSED_LIBRARY_PLUGIN "delete_unused_library_plugin") +SET(${DELETE_UNUSED_LIBRARY_PLUGIN}_SOURCE_FILES + installer-plugin/delete_unused_library_plugin.cc +) +ADD_LIBRARY(${DELETE_UNUSED_LIBRARY_PLUGIN} SHARED ${${DELETE_UNUSED_LIBRARY_PLUGIN}_SOURCE_FILES}) +SET_TARGET_PROPERTIES(${DELETE_UNUSED_LIBRARY_PLUGIN} PROPERTIES COMPILE_FLAGS ${EXTRA_CFLAGS_LIB}) +TARGET_LINK_LIBRARIES(${DELETE_UNUSED_LIBRARY_PLUGIN} ${${PROJECT_NAME}_LDFLAGS} ${DOTNET_LAUNCHER_UTIL}) + CONFIGURE_FILE(dotnet-launcher.pc.in dotnet-launcher.pc @ONLY) INSTALL(TARGETS ${DOTNET_LAUNCHER_UTIL} DESTINATION ${LIBDIR}) @@ -237,6 +245,7 @@ INSTALL(TARGETS ${TPATOOL} DESTINATION ${BINDIR}) INSTALL(TARGETS ${DOTNETTOOL} DESTINATION ${BINDIR}) INSTALL(TARGETS ${PREFER_DOTNET_AOT_PLUGIN} DESTINATION ${INSTALL_MDPLUGIN_DIR}) INSTALL(TARGETS ${PREFER_NUGET_CACHE_PLUGIN} DESTINATION ${INSTALL_MDPLUGIN_DIR}) +INSTALL(TARGETS ${DELETE_UNUSED_LIBRARY_PLUGIN} DESTINATION ${INSTALL_PLUGIN_DIR}) INSTALL(FILES dotnet.loader DESTINATION ${LOADERDIR}) INSTALL(FILES dotnet.launcher DESTINATION ${LOADERDIR}) INSTALL(FILES dotnet.debugger DESTINATION ${LOADERDIR}) diff --git a/NativeLauncher/dotnet-launcher.info b/NativeLauncher/dotnet-launcher.info index d7aa1cc..067a4b6 100644 --- a/NativeLauncher/dotnet-launcher.info +++ b/NativeLauncher/dotnet-launcher.info @@ -1,2 +1,6 @@ +type="tag";name="ui-application";path="/etc/package-manager/parserlib/libdelete_unused_library_plugin.so" +type="tag";name="service-application";path="/etc/package-manager/parserlib/libdelete_unused_library_plugin.so" +type="tag";name="widget-application";path="/etc/package-manager/parserlib/libdelete_unused_library_plugin.so" +type="tag";name="watch-application";path="/etc/package-manager/parserlib/libdelete_unused_library_plugin.so" type="metadata";name="http://tizen.org/metadata/prefer_nuget_cache";path="/etc/package-manager/parserlib/metadata/libprefer_nuget_cache_plugin.so" type="metadata";name="http://tizen.org/metadata/prefer_dotnet_aot";path="/etc/package-manager/parserlib/metadata/libprefer_dotnet_aot_plugin.so" diff --git a/NativeLauncher/installer-plugin/delete_unused_library_plugin.cc b/NativeLauncher/installer-plugin/delete_unused_library_plugin.cc new file mode 100644 index 0000000..d016f89 --- /dev/null +++ b/NativeLauncher/installer-plugin/delete_unused_library_plugin.cc @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2020 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 "log.h" +#include "utils.h" + +#include +#include + +#ifdef LOG_TAG +#undef LOG_TAG +#endif +#define LOG_TAG "DOTNET_INSTALLER_PLUGIN" + +typedef struct _xmlDoc xmlDoc; +typedef xmlDoc* xmlDocPtr; + +bool pluginInstalled = false; + +extern "C" int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr doc, const char* pkgId) +{ + // Can be multiple apps in one package + if (pluginInstalled) { + _INFO("Plugin already installed"); + return 0; + } + pluginInstalled = true; + + std::string appType = getAppType(pkgId); + if (appType.empty()) { + _ERR("Failed to get app type from [%s]", pkgId); + return 0; + } + + if (appType.find("dotnet") == std::string::npos) { + return 0; + } + + std::string rootPath = getRootPath(pkgId); + if (rootPath.empty()) { + _ERR("Failed to get root path from [%s]", pkgId); + return 0; + } + + std::string runtimesDir = concatPath(rootPath, "bin/runtimes"); + if (!bf::exists(runtimesDir)) { + return 0; + } + + char buffer[128]; + sprintf(buffer, "(tizen|linux|unix|base|any)(.\\d.\\d.\\d)?(-%s)?", ARCHITECTURE_IDENTIFIER); + std::regex pattern(buffer); + + std::vector unusedDir; + try { + for (auto& path : bf::recursive_directory_iterator(runtimesDir)) { + std::string filepath = path.path().string(); + std::string targetDir = filepath.substr(filepath.rfind("/runtimes/") + 10); + if (!std::regex_match(targetDir.substr(0, targetDir.find('/')), pattern)) { + if (isDirectory(filepath)) { + unusedDir.push_back(filepath); + } + } + } + } catch (const bf::filesystem_error& error) { + _ERR("Failed to recursive directory: %s", error.what()); + } + + for (auto& path : unusedDir) { + if (!removeAll(path)) { + _ERR("Failed to remove of %s", path.c_str()); + } + } + unusedDir.clear(); + + return 0; +} +extern "C" int PKGMGR_PARSER_PLUGIN_UPGRADE(xmlDocPtr doc, const char* pkgId) +{ + return PKGMGR_PARSER_PLUGIN_INSTALL(doc, pkgId); +} +extern "C" int PKGMGR_PARSER_PLUGIN_UNINSTALL(xmlDocPtr doc, const char* pkgId) +{ + return 0; +} +extern "C" int PKGMGR_PARSER_PLUGIN_REMOVED(xmlDocPtr doc, const char* pkgId) +{ + return 0; +} +extern "C" int PKGMGR_PARSER_PLUGIN_CLEAN(xmlDocPtr doc, const char* pkgId) +{ + return 0; +} +extern "C" int PKGMGR_PARSER_PLUGIN_UNDO(xmlDocPtr doc, const char* pkgId) +{ + return 0; +} +extern "C" int PKGMGR_PARSER_PLUGIN_PRE_INSTALL(const char *pkgId) +{ + return 0; +} +extern "C" int PKGMGR_PARSER_PLUGIN_PRE_UPGRADE(const char *pkgId) +{ + return 0; +} +extern "C" int PKGMGR_PARSER_PLUGIN_PRE_UNINSTALL(const char *pkgId) +{ + return 0; +} +extern "C" int PKGMGR_PARSER_PLUGIN_POST_INSTALL(const char *pkgId) +{ + return 0; +} +extern "C" int PKGMGR_PARSER_PLUGIN_POST_UPGRADE(const char *pkgId) +{ + return 0; +} +extern "C" int PKGMGR_PARSER_PLUGIN_POST_UNINSTALL(const char *pkgId) +{ + return 0; +} diff --git a/NativeLauncher/tool/tac_common.cc b/NativeLauncher/tool/tac_common.cc index 72c6c71..4cc26fd 100644 --- a/NativeLauncher/tool/tac_common.cc +++ b/NativeLauncher/tool/tac_common.cc @@ -15,7 +15,6 @@ */ #include -#include #include #include #include @@ -430,44 +429,18 @@ std::vector depsJsonParser(const std::string& rootPath, const std:: std::vector getLibrariesInfo(const std::string& rootPath) { std::vector LibrariesInfo; - std::vector unusedDir; std::string runtimesDir = concatPath(rootPath, "bin/runtimes"); if (!bf::exists(runtimesDir)) return LibrariesInfo; - char buffer[128]; - sprintf(buffer, "(tizen|linux|unix|base|any)(.\\d.\\d.\\d)?(-%s)?", ARCHITECTURE_IDENTIFIER); - std::regex pattern(buffer); - - try { - for (auto& path : bf::recursive_directory_iterator(runtimesDir)) { - std::string filepath = path.path().string(); - std::size_t pos = filepath.rfind("/runtimes/"); - if (pos != std::string::npos) { - std::string targetDir = filepath.substr(pos + 10); - if (!std::regex_match(targetDir.substr(0, targetDir.find('/')), pattern)) { - if (isDirectory(filepath)) - unusedDir.push_back(filepath); - continue; - } - } - if (filepath.rfind(".so") == std::string::npos) - continue; - + auto convert = [&LibrariesInfo](const std::string& filepath, const std::string& filename) { + if (filepath.rfind(".so") != std::string::npos) { std::string buffer = SHA256(filepath); LibrariesInfo.push_back(filepath + ":" + buffer); - _INFO("Library : [%s] / SHA256 : [%s]", filepath.substr(filepath.rfind('/') + 1).c_str(), buffer.c_str()); + _INFO("Library : [%s] / SHA256 : [%s]", filename.c_str(), buffer.c_str()); } - } catch (const bf::filesystem_error& error) { - _ERR("Failed to recursive directory: %s", error.what()); - } - - for (auto& path : unusedDir) { - if (!removeAll(path)) { - _ERR("Failed to remove of %s", path.c_str()); - } - } - unusedDir.clear(); + }; + scanFilesInDirectory(runtimesDir, convert, -1); return LibrariesInfo; } diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 8670b5e..54cda09 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -54,6 +54,7 @@ Requires(preun): /usr/bin/systemctl %define _runtime_dir /usr/share/dotnet.tizen/netcoreapp %define _framework_dir /usr/share/dotnet.tizen/framework %define _install_mdplugin_dir /etc/package-manager/parserlib/metadata +%define _install_plugin_dir /etc/package-manager/parserlib %define _native_lib_dir /usr/share/dotnet.tizen/lib %define _dotnet_dir /opt/usr/dotnet %define _system_base_addr_file /opt/usr/dotnet.system.base.addr @@ -120,6 +121,7 @@ cmake \ -DFRAMEWORK_DIR=%{_framework_dir} \ -DCROSSGEN_PATH=%{_runtime_dir}/crossgen \ -DINSTALL_MDPLUGIN_DIR=%{_install_mdplugin_dir} \ + -DINSTALL_PLUGIN_DIR=%{_install_plugin_dir} \ -DDOTNET_DIR=%{_dotnet_dir} \ -DVERSION=%{version} \ -DNATIVE_LIB_DIR=%{_native_lib_dir} \ @@ -173,6 +175,7 @@ chsmack -t -a User::App::Shared /opt/etc/skel/.dotnet %{_bindir}/dotnettool %{_install_mdplugin_dir}/libprefer_nuget_cache_plugin.so %{_install_mdplugin_dir}/libprefer_dotnet_aot_plugin.so +%{_install_plugin_dir}/libdelete_unused_library_plugin.so %{_bindir}/dotnet-launcher %{_bindir}/dotnet-loader %{_bindir}/dotnet