summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author조웅석/Common Platform Lab(SR)/삼성전자 <ws77.cho@samsung.com>2022-02-09 14:37:26 +0900
committerGitHub Enterprise <noreply-CODE@samsung.com>2022-02-09 14:37:26 +0900
commitb4cc90d6abbcc2d5a1dbfbde241b01ffe01e0609 (patch)
treea22235a054417aa2bb8cb09ce083b87f70609e1c
parent7a0f9a714f4c9b96001a4e6ee6a207df3a465ac5 (diff)
downloadlauncher-b4cc90d6abbcc2d5a1dbfbde241b01ffe01e0609.tar.gz
launcher-b4cc90d6abbcc2d5a1dbfbde241b01ffe01e0609.tar.bz2
launcher-b4cc90d6abbcc2d5a1dbfbde241b01ffe01e0609.zip
Remove code that create SPC NI first (#373)
* Add isR2RImage insteadof ildasm Use internal API to reduce unnecessary fork * Remove code that create SPC NI first. crossgen2 can do AOTC without SPC native image. So, remove unnecessary code.
-rw-r--r--NativeLauncher/tool/dotnettool.cc2
-rw-r--r--NativeLauncher/tool/ni_common.cc163
-rwxr-xr-xtests/TCs/Utils.py2
3 files changed, 72 insertions, 95 deletions
diff --git a/NativeLauncher/tool/dotnettool.cc b/NativeLauncher/tool/dotnettool.cc
index e05076c..4ecba24 100644
--- a/NativeLauncher/tool/dotnettool.cc
+++ b/NativeLauncher/tool/dotnettool.cc
@@ -211,7 +211,7 @@ int main(int argc, char* argv[])
while (it != args.end()) {
std::string dll = std::string(*it);
int ret = createNIDll(dll, opt);
- if (ret != NI_ERROR_NONE) {
+ if (ret != NI_ERROR_NONE && ret != NI_ERROR_ALREADY_EXIST) {
_SERR("Failed to generate NI file [%s]", dll.c_str());
break;
}
diff --git a/NativeLauncher/tool/ni_common.cc b/NativeLauncher/tool/ni_common.cc
index 88fb06c..c4b535a 100644
--- a/NativeLauncher/tool/ni_common.cc
+++ b/NativeLauncher/tool/ni_common.cc
@@ -102,38 +102,6 @@ NIOption* getNIOption()
return __ni_option;
}
-static bool isCoreLibPrepared()
-{
- std::string coreLibBackup = concatPath(__pm->getRuntimePath(), "System.Private.CoreLib.dll.Backup");
- if (isFile(coreLibBackup)) {
- return true;
- } else {
- _SERR("The native image of System.Private.CoreLib does not exist\n"
- "Run the command to create the native image\n"
- "# dotnettool --ni-dll /usr/share/dotnet.tizen/netcoreapp/System.Private.CoreLib.dll\n");
- return false;
- }
-}
-
-static bool hasCoreLibNI()
-{
- std::string ildasm = concatPath(__pm->getRuntimePath(), "ildasm");
- std::string coreLib = concatPath(__pm->getRuntimePath(), "System.Private.CoreLib.dll");
- std::string cmd = ildasm + " " + coreLib + " -noil -stats | grep '.rsrc'";
-
- FILE *fp;
- fp = popen(cmd.c_str(), "r");
- if (fp != NULL) {
- char buff[1024];
- if (fgets(buff, sizeof(buff), fp) != NULL) {
- pclose(fp);
- return false;
- }
- pclose(fp);
- }
- return true;
-}
-
static void waitInterval()
{
// by the recommand, ignore small value for performance.
@@ -239,9 +207,7 @@ static bool checkNIExistence(const std::string& absDllPath)
// native image of System.Private.CoreLib.dll should have to overwrite
// original file to support new coreclr
if (absDllPath.find("System.Private.CoreLib.dll") != std::string::npos) {
- if (hasCoreLibNI()) {
- return true;
- }
+ return isR2RImage(absDllPath);
}
return false;
@@ -265,8 +231,6 @@ static bool checkDllExistInDir(const std::string& path)
* Get the list of managed files in the specific directory
* Absolute paths of managed files are stored at the result list.
* If native image already exist in the same directory, managed file is ignored.
- *
- * Note: System.Private.CoreLib is excluded from the result list.
*/
static ni_error_e getTargetDllList(const std::string& path, std::vector<std::string>& fileList)
{
@@ -276,9 +240,7 @@ static ni_error_e getTargetDllList(const std::string& path, std::vector<std::str
auto func = [&fileList](const std::string& f_path, const std::string& f_name) {
if (isManagedAssembly(f_path) && !checkNIExistence(f_path)) {
- if (f_path.find("System.Private.CoreLib") == std::string::npos) {
- fileList.push_back(getAbsolutePath(f_path));
- }
+ fileList.push_back(getAbsolutePath(f_path));
}
};
@@ -522,14 +484,47 @@ static ni_error_e crossgen2NoPipeLine(const std::vector<std::string>& dllList, c
return NI_ERROR_NONE;
}
+static ni_error_e createCoreLibNI(NIOption* opt)
+{
+ std::string coreLib = concatPath(__pm->getRuntimePath(), "System.Private.CoreLib.dll");
+ std::string niCoreLib = concatPath(__pm->getRuntimePath(), "System.Private.CoreLib.ni.dll");
+ std::string coreLibBackup = concatPath(__pm->getRuntimePath(), "System.Private.CoreLib.dll.Backup");
+
+ std::vector<std::string> dllList;
+ std::vector<std::string> refPaths;
+ dllList.push_back(getAbsolutePath(coreLib));
+
+ if (!isFile(coreLibBackup) && !isR2RImage(coreLib)) {
+ if (crossgen2NoPipeLine(dllList, refPaths, opt) == NI_ERROR_NONE && exist(niCoreLib)) {
+ if (rename(coreLib.c_str(), coreLibBackup.c_str())) {
+ _SERR("Failed to rename System.Private.CoreLib.dll");
+ return NI_ERROR_CORE_NI_FILE;
+ }
+ if (rename(niCoreLib.c_str(), coreLib.c_str())) {
+ _SERR("Failed to rename System.Private.CoreLib.ni.dll");
+ return NI_ERROR_CORE_NI_FILE;
+ }
+ } else {
+ _SERR("Failed to create native image for %s", coreLib.c_str());
+ return NI_ERROR_CORE_NI_FILE;
+ }
+ }
+ return NI_ERROR_NONE;
+}
+
static ni_error_e doAOTList(std::vector<std::string>& dllList, const std::string& refPaths, NIOption* opt)
{
+ ni_error_e ret = NI_ERROR_NONE;
+
if (dllList.empty()) {
return NI_ERROR_INVALID_PARAMETER;
}
// When performing AOT for one Dll, an error is returned when an error occurs.
// However, when processing multiple dlls at once, only the log for errors is output and skipped.
+ std::string coreLib = concatPath(__pm->getRuntimePath(), "System.Private.CoreLib.dll");
+ bool hasSPC = false;
+
for (auto it = dllList.begin(); it != dllList.end(); it++) {
std::string f = *it;
if (!isFile(f)) {
@@ -540,18 +535,43 @@ static ni_error_e doAOTList(std::vector<std::string>& dllList, const std::string
_SERR("Input file is not a dll file : %s", f.c_str());
dllList.erase(it--);
}
+ // handle System.Private.CoreLib.dll separately.
+ // dllList and path manager contain absolute path. So, there is no need to change path to absolute path
+ if (f == coreLib) {
+ hasSPC = true;
+ dllList.erase(it--);
+ }
+ }
+
+ // In the case of SPC, post-processing is required to change the name of the native image.
+ // In order to avoid repeatedly checking whether the generated native image is an SPC,
+ // the SPC native image generation is performed separately.
+ if (hasSPC) {
+ ret = createCoreLibNI(opt);
+ if (ret != NI_ERROR_NONE) {
+ return ret;
+ }
+ }
+
+ // if there is no proper input after processing dll list
+ if (dllList.empty()) {
+ if (hasSPC) {
+ return ret;
+ } else {
+ return NI_ERROR_INVALID_PARAMETER;
+ }
}
std::vector<std::string> paths;
splitPath(refPaths, paths);
if (opt->flags & NI_FLAGS_NO_PIPELINE) {
- crossgen2NoPipeLine(dllList, paths, opt);
+ ret = crossgen2NoPipeLine(dllList, paths, opt);
} else {
- crossgen2PipeLine(dllList, paths, opt);
+ ret = crossgen2PipeLine(dllList, paths, opt);
}
- return NI_ERROR_NONE;
+ return ret;
}
static ni_error_e doAOTFile(const std::string& dllFile, const std::string& refPaths, NIOption* opt)
@@ -566,6 +586,11 @@ static ni_error_e doAOTFile(const std::string& dllFile, const std::string& refPa
return NI_ERROR_INVALID_PARAMETER;
}
+ if (checkNIExistence(dllFile)) {
+ _SERR("Native image file is already exist : %s", dllFile.c_str());
+ return NI_ERROR_ALREADY_EXIST;
+ }
+
std::vector<std::string> dllList;
dllList.push_back(getAbsolutePath(dllFile));
return doAOTList(dllList, refPaths, opt);
@@ -599,30 +624,6 @@ static int appAotCb(pkgmgrinfo_appinfo_h handle, void *userData)
return 0;
}
-static ni_error_e createCoreLibNI(NIOption* opt)
-{
- std::string coreLib = concatPath(__pm->getRuntimePath(), "System.Private.CoreLib.dll");
- std::string niCoreLib = concatPath(__pm->getRuntimePath(), "System.Private.CoreLib.ni.dll");
- std::string coreLibBackup = concatPath(__pm->getRuntimePath(), "System.Private.CoreLib.dll.Backup");
-
- if (!isFile(coreLibBackup) && !hasCoreLibNI()) {
- if (doAOTFile(coreLib, std::string(), opt) == NI_ERROR_NONE && exist(niCoreLib)) {
- if (rename(coreLib.c_str(), coreLibBackup.c_str())) {
- _SERR("Failed to rename System.Private.CoreLib.dll");
- return NI_ERROR_CORE_NI_FILE;
- }
- if (rename(niCoreLib.c_str(), coreLib.c_str())) {
- _SERR("Failed to rename System.Private.CoreLib.ni.dll");
- return NI_ERROR_CORE_NI_FILE;
- }
- } else {
- _SERR("Failed to create native image for %s", coreLib.c_str());
- return NI_ERROR_CORE_NI_FILE;
- }
- }
- return NI_ERROR_NONE;
-}
-
ni_error_e initNICommon()
{
#if defined(__arm__) || defined(__aarch64__)
@@ -689,12 +690,7 @@ void finalizeNICommon()
ni_error_e createNIPlatform(NIOption* opt)
{
- ni_error_e ret = createCoreLibNI(opt);
- if (ret != NI_ERROR_NONE) {
- return ret;
- }
-
- ret = createNIUnderDirs(__pm->getRuntimePath(), opt);
+ ni_error_e ret = createNIUnderDirs(__pm->getRuntimePath(), opt);
if (ret != NI_ERROR_NONE) {
return ret;
}
@@ -704,14 +700,6 @@ ni_error_e createNIPlatform(NIOption* opt)
ni_error_e createNIDll(const std::string& dllPath, NIOption* opt)
{
- if (dllPath.find("System.Private.CoreLib.dll") != std::string::npos) {
- return createCoreLibNI(opt);
- }
-
- if (!isCoreLibPrepared()) {
- return NI_ERROR_CORE_NI_FILE;
- }
-
return doAOTFile(dllPath, std::string(), opt);
}
@@ -766,9 +754,6 @@ ni_error_e createNIUnderTAC(const std::string& targetPath, const std::string& re
ni_error_e createNIUnderDirs(const std::string& rootPaths, NIOption* opt)
{
ni_error_e ret = NI_ERROR_NONE;
- if (!isCoreLibPrepared()) {
- return NI_ERROR_CORE_NI_FILE;
- }
std::vector<std::string> fileList;
std::vector<std::string> paths;
@@ -834,7 +819,7 @@ void removeNIPlatform()
std::string coreLib = concatPath(__pm->getRuntimePath(), "System.Private.CoreLib.dll");
std::string coreLibBackup = concatPath(__pm->getRuntimePath(), "System.Private.CoreLib.dll.Backup");
- if (hasCoreLibNI()) {
+ if (isR2RImage(coreLib)) {
if (!isFile(coreLibBackup)) {
return;
}
@@ -919,10 +904,6 @@ ni_error_e removeNIUnderPkgRoot(const std::string& pkgId)
ni_error_e regenerateAppNI(NIOption* opt)
{
- if (!isCoreLibPrepared()) {
- return NI_ERROR_CORE_NI_FILE;
- }
-
int ret = 0;
pkgmgrinfo_appinfo_metadata_filter_h handle;
@@ -991,10 +972,6 @@ static int regenTacCb(pkgmgrinfo_appinfo_h handle, void *userData)
ni_error_e regenerateTACNI(NIOption* opt)
{
- if (!isCoreLibPrepared()) {
- return NI_ERROR_CORE_NI_FILE;
- }
-
removeNIUnderDirs(__DOTNET_DIR);
pkgmgrinfo_appinfo_metadata_filter_h handle;
diff --git a/tests/TCs/Utils.py b/tests/TCs/Utils.py
index ae6a785..0a25754 100755
--- a/tests/TCs/Utils.py
+++ b/tests/TCs/Utils.py
@@ -114,7 +114,7 @@ def create_spc_ni():
raw = cmd(f"shell find {RUNTIME_DIR} -name {SPC_DLL}.Backup")
if f"{RUNTIME_DIR}{SPC_DLL}.Backup" not in raw:
raw = cmd(f"shell dotnettool --ni-dll {RUNTIME_DIR}{SPC_DLL}")
- if "System.Private.CoreLib.dll generated successfully." not in raw:
+ if "System.Private.CoreLib.ni.dll generated successfully." not in raw:
return "FAIL"
raw = cmd(f"shell find {RUNTIME_DIR} -name {SPC_DLL}.Backup")