From 29738547c5989f3110b0401efcf29548b808b3cd Mon Sep 17 00:00:00 2001 From: Woongsuk Cho Date: Tue, 16 Oct 2018 10:59:08 +0900 Subject: [PATCH] add ni regeneration feature to support FOTA Change-Id: I0e3a9100d1f486effd8414aad293367f873ad85c --- NativeLauncher/installer-plugin/common.cc | 85 +++++++++++++++++++++++++++++++ NativeLauncher/installer-plugin/common.h | 3 ++ NativeLauncher/installer-plugin/nitool.cc | 4 ++ 3 files changed, 92 insertions(+) diff --git a/NativeLauncher/installer-plugin/common.cc b/NativeLauncher/installer-plugin/common.cc index f1d212e..3cda7b3 100644 --- a/NativeLauncher/installer-plugin/common.cc +++ b/NativeLauncher/installer-plugin/common.cc @@ -233,6 +233,32 @@ static bool niExist(const std::string& path, std::string& ni) return false; } +static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData) +{ + char *pkgId = NULL; + int ret = 0; + + ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId); + if (ret != PMINFO_R_OK) { + fprintf(stderr, "Failed to get pkgid\n"); + return -1; + } + + if (removeNiUnderPkgRoot(pkgId) != 0) { + fprintf(stderr, "Failed to remove previous dlls from [%s]\n", pkgId); + return -1; + } + + if (createNiUnderPkgRoot(pkgId) != 0) { + fprintf(stderr, "Failed to get root path from [%s]\n", pkgId); + return -1; + } else { + fprintf(stderr, "Complete make application to native image\n"); + } + + return 0; +} + static void createCoreLibNI() { std::string coreLib = concatPath(__RUNTIME_DIR, "System.Private.CoreLib.dll"); @@ -373,3 +399,62 @@ int createNiUnderPkgRoot(const char* pkgName) return 0; } + +void removeNiUnderDirs(const std::string rootPaths[], int count) +{ + auto convert = [](const std::string& path, std::string name) { + std::string ni; + if (isNativeImage(path)) { + if (remove(path.c_str())) { + fprintf(stderr, "Failed to remove %s\n", path.c_str()); + } + } + }; + + for (int i = 0; i < count; i++) + scanFilesInDir(rootPaths[i].c_str(), convert, -1); +} + +int removeNiUnderPkgRoot(const std::string& pkgName) +{ + std::string pkgRoot; + if (getRootPath(pkgName.c_str(), pkgRoot) < 0) + return -1; + + std::string binDir = concatPath(pkgRoot, "bin"); + std::string libDir = concatPath(pkgRoot, "lib"); + std::string paths[] = {binDir, libDir}; + + removeNiUnderDirs(paths, 2); + + return 0; +} + +int regenerateAppNI() +{ + int ret = 0; + pkgmgrinfo_appinfo_metadata_filter_h handle; + + ret = pkgmgrinfo_appinfo_metadata_filter_create(&handle); + if (ret != PMINFO_R_OK) + return -1; + + ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, "http://tizen.org/metadata/prefer_dotnet_aot", "true"); + if (ret != PMINFO_R_OK) { + pkgmgrinfo_appinfo_metadata_filter_destroy(handle); + return -1; + } + + ret = pkgmgrinfo_appinfo_metadata_filter_foreach(handle, appAotCb, NULL); + if (ret != PMINFO_R_OK) { + fprintf(stderr, "Failed pkgmgrinfo_appinfo_metadata_filter_foreach\n"); + pkgmgrinfo_appinfo_metadata_filter_destroy(handle); + return -1; + } + + fprintf(stderr, "Success pkgmgrinfo_appinfo_metadata_filter_foreach\n"); + + pkgmgrinfo_appinfo_metadata_filter_destroy(handle); + return 0; +} + diff --git a/NativeLauncher/installer-plugin/common.h b/NativeLauncher/installer-plugin/common.h index d36ae69..550e2f0 100644 --- a/NativeLauncher/installer-plugin/common.h +++ b/NativeLauncher/installer-plugin/common.h @@ -26,5 +26,8 @@ void createNiUnderDirs(const char* rootPaths[], int count); int createNiUnderPkgRoot(const char* pkgName); void createNiPlatform(); void createNiSelect(const char* dllPath); +void removeNiUnderDirs(const std::string rootPaths[], int count); +int removeNiUnderPkgRoot(const std::string& pkgId); +int regenerateAppNI(); #endif /* __INSTALLER_PLUGIN_COMMON_H__ */ diff --git a/NativeLauncher/installer-plugin/nitool.cc b/NativeLauncher/installer-plugin/nitool.cc index c34a696..9149623 100644 --- a/NativeLauncher/installer-plugin/nitool.cc +++ b/NativeLauncher/installer-plugin/nitool.cc @@ -45,6 +45,7 @@ static void help(const char *argv0) " --system - Create NI under System DLLs\n" " --dll - Create NI for DLL\n" " --pkg - Create NI for package\n" + " --regen-all-app - Re-generate All App NI files\n" "\n" "Example:\n" "Create native image for dlls and exes under platform directories\n" @@ -71,6 +72,9 @@ int main(int argc, char* argv[]) dllMode = true; } else if (cmdOptionExists(argv, argv+argc, "--pkg")) { pkgMode = true; + } else if (cmdOptionExists(argv, argv+argc, "--regen-all-app")) { + regenerateAppNI(); + return 0; } else { help(argv[0]); return 1; -- 2.7.4