--- /dev/null
+/*
+ * 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
}
}
-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) {
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;
}
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 int crossgen(const std::string& dllPath, const std::string& appPath, bool enableR2R)
+static int 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());
}
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 -1;
}
+ if (isAppNI) {
+ absNiPath = getAppNIPath(absNiPath);
+ }
+
pid_t pid = fork();
if (pid == -1)
return -1;
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);
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();
}
};
std::string libDir = concatPath(pkgRoot, "lib");
std::string paths[] = {binDir, libDir};
- createNiUnderDirs(paths, 2, enableR2R);
+ createNiUnderDirs(paths, 2, enableR2R, true);
return 0;
}
std::string libDir = concatPath(pkgRoot, "lib");
std::string paths = binDir + ":" + libDir;
- return crossgen(dllPath, paths, enableR2R);
+ return crossgen(dllPath, paths, enableR2R, true);
}
void removeNiPlatform()
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 0;
}
if (ret != PMINFO_R_OK)
return -1;
- 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 -1;
#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 {
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;
}
bool CoreRuntime::initializeCoreClr(const char* appId,
const char* assemblyProbePaths,
+ const char* NIProbePaths,
const char* pinvokeProbePaths,
const char* tpaList)
{
const char *propertyValues[] = {
tpaList,
assemblyProbePaths,
- assemblyProbePaths,
+ NIProbePaths,
pinvokeProbePaths,
"UseLatestBehaviorWhenTFMNotSpecified"
};