Delete unused libraries when installing the application (#269)
author최종헌/Common Platform Lab(SR)/Engineer/삼성전자 <j-h.choi@samsung.com>
Tue, 18 Aug 2020 07:46:43 +0000 (16:46 +0900)
committer이형주/Common Platform Lab(SR)/Staff Engineer/삼성전자 <leee.lee@samsung.com>
Tue, 18 Aug 2020 07:46:43 +0000 (16:46 +0900)
Change-Id: I984b1ba19f2190504b912ee9a70a501e978c0d71

NativeLauncher/CMakeLists.txt
NativeLauncher/dotnet-launcher.info
NativeLauncher/installer-plugin/delete_unused_library_plugin.cc [new file with mode: 0644]
NativeLauncher/tool/tac_common.cc
packaging/dotnet-launcher.spec

index 11945bf..e3254ee 100644 (file)
@@ -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})
index d7aa1cc..067a4b6 100644 (file)
@@ -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 (file)
index 0000000..d016f89
--- /dev/null
@@ -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 <regex>
+#include <vector>
+
+#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<std::string> 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;
+}
index 72c6c71..4cc26fd 100644 (file)
@@ -15,7 +15,6 @@
  */
 
 #include <fstream>
-#include <regex>
 #include <json/json.h>
 #include <pkgmgr-info.h>
 #include <pkgmgr_installer_info.h>
@@ -430,44 +429,18 @@ std::vector<std::string> depsJsonParser(const std::string& rootPath, const std::
 std::vector<std::string> getLibrariesInfo(const std::string& rootPath)
 {
        std::vector<std::string> LibrariesInfo;
-       std::vector<std::string> 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;
 }
index 8670b5e..54cda09 100644 (file)
@@ -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