#include <wait.h>
#include <dirent.h>
#include <sys/stat.h>
+#include <sys/time.h>
+#include <sys/resource.h>
#include <algorithm>
#include <string>
std::string prevPath;
prevPath = getBaseName(absDllPath);
- niDirPath = concatPath(prevPath, APP_NI_SUB_DIR);
+ niDirPath = concatPath(prevPath, APP_NI_SUB_TMP_DIR);
if (opt->flags & NI_FLAGS_APP_UNDER_RO_AREA) {
niDirPath = replaceAll(niDirPath, getBaseName(__pm->getAppRootPath()), __READ_ONLY_APP_UPDATE_DIR);
}
}
+ 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());
}
return NI_ERROR_NONE;
}
+void setPriority(NIOption* opt)
+{
+ pid_t pid = getpid();
+ if (setpriority(PRIO_PROCESS, pid, opt->priority) == 0) {
+ std::string str = " ";
+ if (opt->priority <= -20) {
+ str = " highest ";
+ } else if (opt->priority >= 19) {
+ str = " lowest ";
+ }
+ _SOUT("Success to set the%spriority of the process. pid : [%d], priority : [%d]", str.c_str(), pid, getpriority(PRIO_PROCESS, pid));
+ } else {
+ _SERR("Failed to set the priority of the process. pid : [%d], priority : [%d]", pid, getpriority(PRIO_PROCESS, pid));
+ }
+}
+
static ni_error_e crossgen2PipeLine(const std::vector<std::string>& dllList, const std::vector<std::string>& refPaths, NIOption* opt)
{
// fork crossgen2
return NI_ERROR_ABNORMAL_PROCESS_TERMINATION;
}
} else {
+ if (opt->flags & NI_FLAGS_SET_PRIORITY) {
+ setPriority(opt);
+ }
std::vector<const char*> argv;
makeArgs(argv, refPaths, opt);
argv.push_back(CROSSGEN_OPT_OUT_NEAR_INPUT);
return NI_ERROR_ABNORMAL_PROCESS_TERMINATION;
}
} else {
+ if (opt->flags & NI_FLAGS_SET_PRIORITY) {
+ setPriority(opt);
+ }
std::vector<const char*> argv;
makeArgs(argv, refPaths, 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;
}
if (rename(niTmpCoreLib.c_str(), coreLib.c_str())) {
_SERR("Failed to rename from System.Private.CoreLib.ni.dll.tmp to Private.CoreLib.dll");
return NI_ERROR_CORE_NI_FILE;
- }
+ }
} else {
if (rename(niCoreLib.c_str(), coreLib.c_str())) {
_SERR("Failed to rename from System.Private.CoreLib.ni.dll to Private.CoreLib.dll");
return NI_ERROR_NONE;
}
+static void renameAppNITmpPath(NIOption* opt)
+{
+ std::string niTmpPath = __pm->getAppRootPath() + "/bin/" + APP_NI_SUB_TMP_DIR;
+ std::string niPath = __pm->getAppRootPath() + "/bin/" + APP_NI_SUB_DIR;
+
+ if (opt->flags & NI_FLAGS_APP_UNDER_RO_AREA) {
+ niTmpPath = replaceAll(niTmpPath, getBaseName(__pm->getAppRootPath()), __READ_ONLY_APP_UPDATE_DIR);
+ niPath = replaceAll(niPath, getBaseName(__pm->getAppRootPath()), __READ_ONLY_APP_UPDATE_DIR);
+ }
+
+ if (isDirectory(niTmpPath)) {
+ if (rename(niTmpPath.c_str(), niPath.c_str())) {
+ _SERR("Fail to rename from .native_image_tmp to .native_image");
+ }
+ }
+}
+
static ni_error_e doAOTList(std::vector<std::string>& dllList, const std::string& refPaths, NIOption* opt)
{
ni_error_e ret = NI_ERROR_NONE;
}
}
- if (ret == NI_ERROR_NONE && opt->flags & NI_FLAGS_INPUT_BUBBLE) {
- for (auto &dll : dllList) {
- std::string tmpFile;
- std::string niFile;
- if (opt->flags & NI_FLAGS_APPNI) {
- niFile = getAppNIFilePath(dll, opt);
- } else {
- niFile = getNIFilePath(dll);
- }
- tmpFile = niFile + ".tmp";
+ if (ret == NI_ERROR_NONE) {
+ if (opt->flags & NI_FLAGS_INPUT_BUBBLE) {
+ for (auto &dll : dllList) {
+ std::string tmpFile;
+ std::string niFile;
+ if (opt->flags & NI_FLAGS_APPNI) {
+ niFile = getAppNIFilePath(dll, opt);
+ } else {
+ niFile = getNIFilePath(dll);
+ }
+ tmpFile = niFile + ".tmp";
- if (exist(tmpFile)) {
- moveFile(tmpFile, niFile);
- _SOUT("Native image %s generated successfully.", niFile.c_str());
+ if (exist(tmpFile)) {
+ moveFile(tmpFile, niFile);
+ _SOUT("Native image %s generated successfully.", niFile.c_str());
+ }
}
}
+ if (opt->flags & NI_FLAGS_APPNI) {
+ renameAppNITmpPath(opt);
+ }
}
return ret;
{
auto convert = [](const std::string& path, const std::string& filename) {
if (isNativeImage(path)) {
- if (remove(path.c_str())) {
- _SERR("Failed to remove %s", path.c_str());
+ std::string assemblyPath = changeExtension(path, ".ni.dll", ".dll");
+ if (exist(assemblyPath)) {
+ if (remove(path.c_str())) {
+ _SERR("Failed to remove %s", path.c_str());
+ }
+ } else {
+ _SOUT("%s cannot be removed because there is no %s", path.c_str(), assemblyPath.c_str());
}
}
};
if (ret != PMINFO_R_OK)
return NI_ERROR_UNKNOWN;
- ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, AOT_METADATA_KEY, METADATA_VALUE);
+ ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, AOT_METADATA_KEY, METADATA_VALUE_TRUE);
if (ret != PMINFO_R_OK) {
pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
return NI_ERROR_UNKNOWN;
static int regenTacCb(pkgmgrinfo_appinfo_h handle, void *userData)
{
char *pkgId = NULL;
+ char *root = NULL;
NIOption **pOpt = (NIOption**)userData;
int ret = pkgmgrinfo_appinfo_get_pkgid(handle, &pkgId);
return -1;
}
+ ret = pkgmgrinfo_appinfo_get_root_path(handle, &root);
+ if (ret != PMINFO_R_OK) {
+ _SERR("Failed to get root path");
+ return -1;
+ }
+
+ std::string binPath = concatPath(std::string(root), "bin");
+ if (exist(concatPath(binPath, PRE_COMPILED_PACKAGE_FILE))) {
+ _INFO("The %s is a Pre-Compiled package. So, skip the TAC", pkgId);
+ return 0;
+ }
+
sqlite3 *tac_db = openDB(TAC_APP_LIST_DB);
if (!tac_db) {
_SERR("Sqlite open error");
return NI_ERROR_UNKNOWN;
}
- ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, TAC_METADATA_KEY, METADATA_VALUE);
+ ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, TAC_METADATA_KEY, METADATA_VALUE_TRUE);
if (ret != PMINFO_R_OK) {
pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
return NI_ERROR_UNKNOWN;