Add --ni-pkg-with-path option accepted/tizen/unified/20240828.164026 accepted/tizen/unified/dev/20240829.043822 accepted/tizen/unified/x/20240829.020417
authorWoongsuk Cho <ws77.cho@samsung.com>
Wed, 14 Aug 2024 11:37:14 +0000 (20:37 +0900)
committer조웅석/MDE Lab(SR)/삼성전자 <ws77.cho@samsung.com>
Wed, 28 Aug 2024 05:34:27 +0000 (14:34 +0900)
When a package needs to be AOTed in an unpacked state,
there are cases where it is necessary to use the rootpath instead of the pkgid for AppNI.

To support this case, API and dotnettool option are added.

NativeLauncher/inc/ni_common.h
NativeLauncher/tool/dotnettool.cc
NativeLauncher/tool/ni_common.cc

index 94ae7e4bb9b6440b3375aef8fd0b3ca92949257b..1fdbf3323edbc76cd599c28a1e97ed28d6816de5 100644 (file)
@@ -116,6 +116,15 @@ ni_error_e createNIUnderDirs(const std::string& rootPaths, NIOption* opt);
  */
 ni_error_e createNIUnderPkgRoot(const std::string& pkgId, NIOption* opt);
 
+/**
+ * @brief create native images for all DLLs in a package with specified path.
+ * @param[in] rootPath path of package
+ * @param[in] flags additional flags for the image generator
+ * @parma[in] rpk if true, generate RPK native image (default value is false)
+ * @return ni_error_e
+ */
+ni_error_e createNIUnderPkgRootWithPath(const std::string& rootPath, NIOption* opt, bool rpk = false);
+
 /**
  * @brief remove platform native images (.NETCore + TizenFX)
  */
index 75111a4d8791f8f99d384579198739e780113e59..d65454a96e3a86201004279c4a0701a23ce52538 100644 (file)
@@ -39,6 +39,8 @@ void DisplayUsage() {
                "       --ni-dll                  - Create NI for DLL\n"
                "       --ni-pkg                  - Create NI for package\n"
                "                                   (If package is installed under RO area, NI files are generated under RW area)\n"
+               "       --ni-pkg-with-path        - Create NI for package with root path\n"
+               "                                   (If package is installed under RO area, NI files are generated under RW area)\n"
                "       --ni-dir                  - Create NI for directory\n"
                "       --ni-reset-system         - Remove System NI files\n"
                "       --ni-reset-all-app        - Remove All App NI files\n"
@@ -160,6 +162,27 @@ static void dotnettool_ni_pkg(NIOption* opt)
        }
 }
 
+//sh-3.2# dotnettool --ni-pkg-with-path [path] [path] ...
+static void dotnettool_ni_pkg_with_path(NIOption* opt)
+{
+       if (opt->flags & NI_FLAGS_RM_ORIGIN_AFTER_NI) {
+               _SERR("App AOTC options cannot be used with --rm-origin-after-ni option");
+               DisplayUsage();
+               return;
+       }
+       if (args.size() < 1) {
+               _SERR("Package name is missing");
+       }
+       while (it != args.end()) {
+               std::string path = std::string(*it);
+               if (createNIUnderPkgRootWithPath(path, opt) != NI_ERROR_NONE) {
+                       _SERR("Failed to generate app NI from path[%s]", path.c_str());
+                       break;
+               }
+               it = args.erase(it);
+       }
+}
+
 //sh-3.2# dotnettool --ni-dir [AssemblyDirectory] [AssemblyDirectory] ...
 static void dotnettool_ni_dir(NIOption* opt)
 {
@@ -458,6 +481,9 @@ int main(int argc, char* argv[])
        else if (cmd == "--ni-pkg") {
                dotnettool_ni_pkg(opt);
        }
+       else if (cmd == "--ni-pkg-with-path") {
+               dotnettool_ni_pkg_with_path(opt);
+       }
        else if (cmd == "--ni-dir") {
                dotnettool_ni_dir(opt);
        }
index 36e39cb087856dddde70adba53d6794dd5dc2b46..b14418528dc0626dc4725fffe9d8223b933b6414 100644 (file)
@@ -1052,6 +1052,17 @@ ni_error_e createNIUnderDirs(const std::string& rootPaths, NIOption* opt)
 }
 
 ni_error_e createNIUnderPkgRoot(const std::string& pkgId, NIOption* opt)
+{
+       std::string rootPath = getRootPath(pkgId);
+       if (rootPath.empty()) {
+               _SERR("Failed to get root path from [%s]", pkgId.c_str());
+               return NI_ERROR_INVALID_PACKAGE;
+       }
+
+       return createNIUnderPkgRootWithPath(rootPath, opt, isRPK(pkgId));
+}
+
+ni_error_e createNIUnderPkgRootWithPath(const std::string& rootPath, NIOption* opt, bool rpk)
 {
        if (!isR2RImage(concatPath(__pm->getRuntimePath(), "System.Private.CoreLib.dll"))) {
                _SERR("The native image of System.Private.CoreLib does not exist.\n"
@@ -1060,9 +1071,8 @@ ni_error_e createNIUnderPkgRoot(const std::string& pkgId, NIOption* opt)
                return NI_ERROR_CORE_NI_FILE;
        }
 
-       std::string rootPath = getRootPath(pkgId);
        if (rootPath.empty()) {
-               _SERR("Failed to get root path from [%s]", pkgId.c_str());
+               _SERR("Failed. rootPath should be set");
                return NI_ERROR_INVALID_PACKAGE;
        }
        __pm->setAppRootPath(rootPath);
@@ -1074,13 +1084,13 @@ ni_error_e createNIUnderPkgRoot(const std::string& pkgId, NIOption* opt)
        }
 
        std::string targetDirs;
-       if (isRPK(pkgId)) {
+       if (rpk) {
                opt->flags &= ~NI_FLAGS_APPNI; // added to exclude logic of APP_NI
                opt->flags |= NI_FLAGS_NO_PIPELINE; // added the flag to set the output path
 
                std::string paths = getResourcePaths(rootPath);
                if (paths.empty()) {
-                       _SERR("Failed to get rpk paths from [%s]", pkgId.c_str());
+                       _SERR("Failed to get rpk paths from rootPath[%s]", rootPath.c_str());
                        return NI_ERROR_UNKNOWN;
                }
                targetDirs = paths;