From 41d0e29ece8438f8a0eb529c6f32fa6e1c961081 Mon Sep 17 00:00:00 2001 From: Woongsuk Cho Date: Thu, 3 Feb 2022 14:09:41 +0900 Subject: [PATCH] Add --rm-origin-after-ni option Add option to remove original dll after creating native image for reducing storage consumption. This option doesnot work with --ni-pkg option because app can be re-compiled. --- NativeLauncher/inc/ni_common.h | 1 + NativeLauncher/launcher/lib/core_runtime.cc | 4 ++-- NativeLauncher/tool/dotnettool.cc | 11 +++++++++++ NativeLauncher/tool/ni_common.cc | 16 +++++++++++++++- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/NativeLauncher/inc/ni_common.h b/NativeLauncher/inc/ni_common.h index 725ae7c..65b21f0 100644 --- a/NativeLauncher/inc/ni_common.h +++ b/NativeLauncher/inc/ni_common.h @@ -38,6 +38,7 @@ #define NI_FLAGS_MIBC 0x0100 #define NI_FLAGS_PRINT_CMD 0x0200 #define NI_FLAGS_SKIP_RO_APP 0x0400 +#define NI_FLAGS_RM_ORIGIN_AFTER_NI 0x0800 typedef std::function afterCreate; diff --git a/NativeLauncher/launcher/lib/core_runtime.cc b/NativeLauncher/launcher/lib/core_runtime.cc index 87d5919..385bb60 100644 --- a/NativeLauncher/launcher/lib/core_runtime.cc +++ b/NativeLauncher/launcher/lib/core_runtime.cc @@ -549,12 +549,12 @@ int CoreRuntime::launch(const char* appId, const char* root, const char* path, i _ERR("executable path is null"); return -1; } - +#if 0 if (!isFile(path)) { _ERR("File not exist : %s", path); return -1; } - +#endif // VD has their own signal handler. if (!pluginHasLogControl()) { registerSigHandler(); diff --git a/NativeLauncher/tool/dotnettool.cc b/NativeLauncher/tool/dotnettool.cc index 99bc00c..7844988 100644 --- a/NativeLauncher/tool/dotnettool.cc +++ b/NativeLauncher/tool/dotnettool.cc @@ -73,6 +73,9 @@ void DisplayUsage() { " --print-cmd - Print command and options\n" " --skip-ro-app - Skip re-generate NI for apps installed RO area\n" " (This option works with --ni-regen-all-app only)\n" + " --rm-origin-after-ni - Remove original dll after creating native image\n" + " Note!: --ni-pkg option doesnot support --rm-origin-after-ni option.\n" + " (Use only for assemblies that will not be AOTed again afterward.)" "\n" "Usage: dotnettool [options] [command] [arguments]\n" "\n" @@ -131,6 +134,8 @@ int main(int argc, char* argv[]) opt->flags |= NI_FLAGS_PRINT_CMD; } else if (arg == "--skip-ro-app") { opt->flags |= NI_FLAGS_SKIP_RO_APP; + } else if (arg == "--rm-origin-after-ni") { + opt->flags |= NI_FLAGS_RM_ORIGIN_AFTER_NI; } else if (arg == "--mibc") { ++i; if (i >= argc) { @@ -236,6 +241,12 @@ int main(int argc, char* argv[]) } //sh-3.2# dotnettool --ni-pkg [pkgId] [pkgId] ... else if (cmd == "--ni-pkg") { + if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) { + _SERR("--ni-pkg option doesnot support --rm-origin-after-ni option"); + DisplayUsage(); + return -1; + } + if (args.size() < 1) { _SERR("Package name is missing"); } diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc index 4796ad3..800a223 100644 --- a/NativeLauncher/tool/ni_common.cc +++ b/NativeLauncher/tool/ni_common.cc @@ -492,6 +492,12 @@ static ni_error_e crossgen2PostAction(const std::string& dllPath, const std::str } } + if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) { + if (!removeFile(dllPath)) { + _SERR("Fail to remove original file : %s", dllPath.c_str()); + } + } + if (!(opt->flags & NI_FLAGS_INPUT_BUBBLE && opt->flags & NI_FLAGS_NO_PIPELINE)) { _SOUT("Native image %s generated successfully.", outFile.c_str()); } @@ -647,7 +653,15 @@ static ni_error_e createCoreLibNI(NIOption* opt) if (!isFile(coreLibBackup) && !isR2RImage(coreLib)) { if (crossgen2NoPipeLine(dllList, refPaths, opt) == NI_ERROR_NONE) { - if (rename(coreLib.c_str(), coreLibBackup.c_str())) { + if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) { + std::ofstream output(coreLibBackup); + if (!exist(coreLibBackup)) { + _SERR("Failed to create System.Private.CoreLib.dll.Backup"); + return NI_ERROR_CORE_NI_FILE; + } + copySmackAndOwnership(__pm->getRuntimePath(), coreLibBackup, false); + output.close(); + } else if (rename(coreLib.c_str(), coreLibBackup.c_str())) { _SERR("Failed to rename from System.Private.CoreLib.dll to System.Private.CoreLib.dll.Backup"); return NI_ERROR_CORE_NI_FILE; } -- 2.7.4