summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author조웅석/Common Platform Lab(SR)/Principal Engineer/삼성전자 <ws77.cho@samsung.com>2019-06-11 16:55:27 +0900
committerGitHub Enterprise <noreply-CODE@samsung.com>2019-06-11 16:55:27 +0900
commitd109edcd7cfe4c685efc306d2a3bfcb7da7d23b3 (patch)
tree24532f1546bd48c5540748ba641467315e79c651
parentb7cc274a63de6834bb8708fd6459e0d78c7e0c0b (diff)
parent7fd60cb80cf17a78a2a7701f91b2fa1ac7f0a2bf (diff)
downloadlauncher-d109edcd7cfe4c685efc306d2a3bfcb7da7d23b3.tar.gz
launcher-d109edcd7cfe4c685efc306d2a3bfcb7da7d23b3.tar.bz2
launcher-d109edcd7cfe4c685efc306d2a3bfcb7da7d23b3.zip
Merge pull request #61 from dotnet/use_app_ni_path
generate native image files in the .native_image folder for the pkg aot.
-rw-r--r--NativeLauncher/inc/launcher_env.h26
-rw-r--r--NativeLauncher/inc/utils.h2
-rw-r--r--NativeLauncher/installer-plugin/ni_common.cc101
-rw-r--r--NativeLauncher/installer-plugin/ni_common.h3
-rw-r--r--NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc4
-rw-r--r--NativeLauncher/launcher/dotnet/dotnet_launcher.cc9
-rw-r--r--NativeLauncher/launcher/dotnet/dotnet_launcher.h3
-rw-r--r--NativeLauncher/util/plugin_manager.cc2
8 files changed, 108 insertions, 42 deletions
diff --git a/NativeLauncher/inc/launcher_env.h b/NativeLauncher/inc/launcher_env.h
new file mode 100644
index 0000000..55f600d
--- /dev/null
+++ b/NativeLauncher/inc/launcher_env.h
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the License);
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef __LAUNCHER_ENV_H_
+#define __LAUNCHER_ENV_H_
+
+#define PLUGIN_PATH "/usr/share/dotnet.tizen/lib/libdotnet_plugin.so"
+#define ENV_FILE_PATH "/usr/share/dotnet.tizen/lib/coreclr_env.list"
+#define AOT_METADATA_KEY "http://tizen.org/metadata/prefer_dotnet_aot"
+#define AOT_METADATA_VALUE "true"
+#define APP_NI_SUB_DIR "/.native_image"
+
+#endif //__LAUNCHER_ENV_H_ \ No newline at end of file
diff --git a/NativeLauncher/inc/utils.h b/NativeLauncher/inc/utils.h
index d353f92..79e8489 100644
--- a/NativeLauncher/inc/utils.h
+++ b/NativeLauncher/inc/utils.h
@@ -21,6 +21,8 @@
#include <vector>
#include <functional>
+#include <launcher_env.h>
+
#ifndef PATH_SEPARATOR
#define PATH_SEPARATOR '/'
#endif
diff --git a/NativeLauncher/installer-plugin/ni_common.cc b/NativeLauncher/installer-plugin/ni_common.cc
index cf3e85e..29f0b82 100644
--- a/NativeLauncher/installer-plugin/ni_common.cc
+++ b/NativeLauncher/installer-plugin/ni_common.cc
@@ -69,7 +69,27 @@ static void waitInterval()
}
}
-static std::string getNiFileName(const std::string& dllPath)
+static void updateNiFileInfo(const std::string& dllPath, const std::string& niPath)
+{
+ char* label = NULL;
+
+ // change smack label
+ if (smack_getlabel(dllPath.c_str(), &label, SMACK_LABEL_ACCESS) == 0) {
+ if (smack_setlabel(niPath.c_str(), label, SMACK_LABEL_ACCESS) < 0) {
+ fprintf(stderr, "Fail to set smack label\n");
+ }
+ free(label);
+ }
+
+ // change owner and groups for generated ni file.
+ struct stat info;
+ if (!stat(dllPath.c_str(), &info)) {
+ if (chown(niPath.c_str(), info.st_uid, info.st_gid) == -1)
+ fprintf(stderr, "Failed to change owner and group name\n");
+ }
+}
+
+static std::string getNiFilePath(const std::string& dllPath)
{
size_t index = dllPath.find_last_of(".");
if (index == std::string::npos) {
@@ -86,9 +106,32 @@ static std::string getNiFileName(const std::string& dllPath)
return niPath;
}
+static std::string getAppNIPath(const std::string& niPath)
+{
+ size_t index = niPath.find_last_of("/");
+ if (index == std::string::npos) {
+ fprintf(stderr, "dllPath doesnot contains path info\n");
+ return "";
+ }
+
+ std::string prevPath = niPath.substr(0, index);
+ std::string fileName = niPath.substr(index, niPath.length());
+ std::string niDirPath = prevPath + APP_NI_SUB_DIR;
+
+ if (!isFileExist(niDirPath)) {
+ if (mkdir(niDirPath.c_str(), 0755) == 0) {
+ updateNiFileInfo(prevPath, niDirPath);
+ } else {
+ fprintf(stderr, "Fail to create app ni directory (%s)\n", niDirPath.c_str());
+ }
+ }
+
+ return niDirPath + fileName;
+}
+
static bool niExist(const std::string& path)
{
- std::string f = getNiFileName(path);
+ std::string f = getNiFilePath(path);
if (f.empty()) {
return false;
}
@@ -109,27 +152,7 @@ static bool niExist(const std::string& path)
return false;
}
-static void updateNiFileInfo(const std::string& dllPath, const std::string& niPath)
-{
- char* label = NULL;
-
- // change smack label
- if (smack_getlabel(dllPath.c_str(), &label, SMACK_LABEL_ACCESS) == 0) {
- if (smack_setlabel(niPath.c_str(), label, SMACK_LABEL_ACCESS) < 0) {
- fprintf(stderr, "Fail to set smack label\n");
- }
- free(label);
- }
-
- // change owner and groups for generated ni file.
- struct stat info;
- if (!stat(dllPath.c_str(), &info)) {
- if (chown(niPath.c_str(), info.st_uid, info.st_gid) == -1)
- fprintf(stderr, "Failed to change owner and group name\n");
- }
-}
-
-static ni_error_e crossgen(const std::string& dllPath, const std::string& appPath, bool enableR2R)
+static ni_error_e crossgen(const std::string& dllPath, const std::string& appPath, bool enableR2R, bool isAppNI = false)
{
if (!isFileExist(dllPath)) {
fprintf(stderr, "dll file is not exist : %s\n", dllPath.c_str());
@@ -147,12 +170,16 @@ static ni_error_e crossgen(const std::string& dllPath, const std::string& appPat
}
std::string absDllPath = absolutePath(dllPath);
- std::string absNiPath = getNiFileName(dllPath);
+ std::string absNiPath = getNiFilePath(dllPath);
if (absNiPath.empty()) {
fprintf(stderr, "Fail to get ni file name\n");
return NI_ERROR_UNKNOWN;
}
+ if (isAppNI) {
+ absNiPath = getAppNIPath(absNiPath);
+ }
+
pid_t pid = fork();
if (pid == -1)
return NI_ERROR_UNKNOWN;
@@ -349,7 +376,7 @@ ni_error_e createNiDll(const std::string& dllPath, bool enableR2R)
return crossgen(dllPath, std::string(), enableR2R);
}
-void createNiUnderDirs(const std::string rootPaths[], int count, bool enableR2R)
+void createNiUnderDirs(const std::string rootPaths[], int count, bool enableR2R, bool isAppNI)
{
createCoreLibNI(enableR2R);
@@ -362,8 +389,8 @@ void createNiUnderDirs(const std::string rootPaths[], int count, bool enableR2R)
if (appPaths.back() == ':')
appPaths.pop_back();
- auto convert = [&appPaths, enableR2R](const std::string& path, const char* name) {
- if (!crossgen(path, appPaths.c_str(), enableR2R)) {
+ auto convert = [&appPaths, enableR2R, isAppNI](const std::string& path, const char* name) {
+ if (!crossgen(path, appPaths.c_str(), enableR2R, isAppNI)) {
waitInterval();
}
};
@@ -385,7 +412,7 @@ ni_error_e createNiUnderPkgRoot(const std::string& pkgName, bool enableR2R)
std::string libDir = concatPath(pkgRoot, "lib");
std::string paths[] = {binDir, libDir};
- createNiUnderDirs(paths, 2, enableR2R);
+ createNiUnderDirs(paths, 2, enableR2R, true);
return NI_ERROR_NONE;
}
@@ -402,7 +429,7 @@ ni_error_e createNiDllUnderPkgRoot(const std::string& pkgName, const std::string
std::string libDir = concatPath(pkgRoot, "lib");
std::string paths = binDir + ":" + libDir;
- return crossgen(dllPath, paths, enableR2R);
+ return crossgen(dllPath, paths, enableR2R, true);
}
void removeNiPlatform()
@@ -456,6 +483,20 @@ ni_error_e removeNiUnderPkgRoot(const std::string& pkgName)
removeNiUnderDirs(paths, 2);
+ std::string binNIDir = binDir + APP_NI_SUB_DIR;
+ if (isFileExist(binNIDir)) {
+ if (rmdir(binNIDir.c_str()) != 0) {
+ fprintf(stderr, "Failed to remove app ni dir [%s]\n", binNIDir.c_str());
+ }
+ }
+
+ std::string libNIDir = libDir + APP_NI_SUB_DIR;
+ if (isFileExist(libNIDir)) {
+ if (rmdir(libNIDir.c_str()) != 0) {
+ fprintf(stderr, "Failed to remove app ni dir [%s]\n", libNIDir.c_str());
+ }
+ }
+
return NI_ERROR_NONE;
}
@@ -468,7 +509,7 @@ ni_error_e regenerateAppNI(bool enableR2R)
if (ret != PMINFO_R_OK)
return NI_ERROR_UNKNOWN;
- ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, "http://tizen.org/metadata/prefer_dotnet_aot", "true");
+ ret = pkgmgrinfo_appinfo_metadata_filter_add(handle, AOT_METADATA_KEY, AOT_METADATA_VALUE);
if (ret != PMINFO_R_OK) {
pkgmgrinfo_appinfo_metadata_filter_destroy(handle);
return NI_ERROR_UNKNOWN;
diff --git a/NativeLauncher/installer-plugin/ni_common.h b/NativeLauncher/installer-plugin/ni_common.h
index 0981090..3f3de82 100644
--- a/NativeLauncher/installer-plugin/ni_common.h
+++ b/NativeLauncher/installer-plugin/ni_common.h
@@ -71,8 +71,9 @@ ni_error_e createNiDll(const std::string& dllPath, bool enableR2R);
* @param[i] rootPaths directories whicn contains DLLs
* @param[i] count number of rootPath
* @param[i] enableR2R enable ready-to-run mode
+ * @param[i] isAppNI if you want to create ni files under nativeImage directory, set it true
*/
-void createNiUnderDirs(const std::string rootPaths[], int count, bool enableR2R);
+void createNiUnderDirs(const std::string rootPaths[], int count, bool enableR2R, bool isAppNI = false);
/**
* @brief create native images for specific package. (All DLLs)
diff --git a/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc b/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc
index 799861a..a4592b4 100644
--- a/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc
+++ b/NativeLauncher/installer-plugin/prefer_dotnet_aot_plugin.cc
@@ -33,8 +33,6 @@ typedef struct Metadata {
const char *value;
} Metadata;
-const std::string valueType = "true";
-const std::string mdKey = "http://tizen.org/metadata/prefer_dotnet_aot";
extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *appId, GList *list)
{
GList *tag = NULL;
@@ -43,7 +41,7 @@ extern "C" int PKGMGR_MDPARSER_PLUGIN_INSTALL(const char *pkgId, const char *app
tag = g_list_first(list);
while (tag) {
mdInfo = (Metadata*)tag->data;
- if (mdInfo->key == mdKey && mdInfo->value == valueType) {
+ if (mdInfo->key == AOT_METADATA_KEY && mdInfo->value == AOT_METADATA_VALUE) {
_DBG("Prefer dotnet application AOT set TRUE");
mdValue = true;
}
diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc
index 48252e8..feae81d 100644
--- a/NativeLauncher/launcher/dotnet/dotnet_launcher.cc
+++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.cc
@@ -45,9 +45,6 @@
#include "path_manager.h"
#include "log_manager.h"
-#define PLUGIN_PATH "/usr/share/dotnet.tizen/lib/libdotnet_plugin.so"
-#define ENV_FILE_PATH "/usr/share/dotnet.tizen/lib/coreclr_env.list"
-
namespace tizen {
namespace runtime {
namespace dotnetcore {
@@ -393,11 +390,12 @@ int CoreRuntime::initialize(bool standalone)
std::string appBin = concatPath(appRoot, "bin");
std::string appLib = concatPath(appRoot, "lib");
std::string probePath = appBin + ":" + appLib;
+ std::string NIprobePath = appBin + APP_NI_SUB_DIR + ":" + appLib + APP_NI_SUB_DIR;
std::string tpa = getTPA();
std::string nativeLibPath = getExtraNativeLibDirs(appRoot) + ":" + appBin + ":" + appLib + ":" + __nativeLibDirectory;
std::string appName = std::string("dotnet-launcher-") + std::to_string(getpid());
- if (!initializeCoreClr(appName.c_str(), probePath.c_str(), nativeLibPath.c_str(), tpa.c_str())) {
+ if (!initializeCoreClr(appName.c_str(), probePath.c_str(), NIprobePath.c_str(), nativeLibPath.c_str(), tpa.c_str())) {
_ERR("Failed to initialize coreclr");
return -1;
}
@@ -416,6 +414,7 @@ int CoreRuntime::initialize(bool standalone)
bool CoreRuntime::initializeCoreClr(const char* appId,
const char* assemblyProbePaths,
+ const char* NIProbePaths,
const char* pinvokeProbePaths,
const char* tpaList)
{
@@ -430,7 +429,7 @@ bool CoreRuntime::initializeCoreClr(const char* appId,
const char *propertyValues[] = {
tpaList,
assemblyProbePaths,
- assemblyProbePaths,
+ NIProbePaths,
pinvokeProbePaths,
"UseLatestBehaviorWhenTFMNotSpecified"
};
diff --git a/NativeLauncher/launcher/dotnet/dotnet_launcher.h b/NativeLauncher/launcher/dotnet/dotnet_launcher.h
index e230914..e9e6c5d 100644
--- a/NativeLauncher/launcher/dotnet/dotnet_launcher.h
+++ b/NativeLauncher/launcher/dotnet/dotnet_launcher.h
@@ -35,7 +35,8 @@ class CoreRuntime
int launch(const char* appId, const char* root, const char* path, int argc, char* argv[]);
private:
- bool initializeCoreClr(const char* appId, const char* assemblyProbePaths, const char* pinvokeProbePaths, const char* tpaList);
+
+ bool initializeCoreClr(const char* appId, const char* assemblyProbePaths, const char* NIProbePaths, const char* pinvokeProbePaths, const char* tpaList);
void preloadTypes();
coreclr_initialize_ptr initializeClr;
coreclr_execute_assembly_ptr executeAssembly;
diff --git a/NativeLauncher/util/plugin_manager.cc b/NativeLauncher/util/plugin_manager.cc
index 5065adb..f8f008b 100644
--- a/NativeLauncher/util/plugin_manager.cc
+++ b/NativeLauncher/util/plugin_manager.cc
@@ -22,8 +22,6 @@
static PluginFunc* __pluginFunc = NULL;
static void* __pluginLib;
-#define PLUGIN_PATH "/usr/share/dotnet.tizen/lib/libdotnet_plugin.so"
-
int initializePluginManager(const char* mode)
{
if (isFileExist(PLUGIN_PATH)) {