From: CHUNSEOK LEE Date: Wed, 19 Jul 2017 22:36:39 +0000 (+0900) Subject: remove Self-Contained Deployment launcher X-Git-Tag: submit/tizen/20170720.005404~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cc9146e37b31738fba3ef3ef88fae623568525e0;p=platform%2Fcore%2Fdotnet%2Flauncher.git remove Self-Contained Deployment launcher Change-Id: I88bb4540725a62cbe331225654a55be0dd2702b3 Signed-off-by: CHUNSEOK LEE --- diff --git a/NativeLauncher/CMakeLists.txt b/NativeLauncher/CMakeLists.txt index e453d9a..6d78c6f 100644 --- a/NativeLauncher/CMakeLists.txt +++ b/NativeLauncher/CMakeLists.txt @@ -7,7 +7,7 @@ IF(DEFINED NO_TIZEN) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -DNO_TIZEN") ELSE(DEFINED NO_TIZEN) INCLUDE(FindPkgConfig) - PKG_CHECK_MODULES(${PROJECT_NAME} REQUIRED aul pkgmgr-info pkgmgr-installer dlog ecore bundle dlog launchpad elementary glib-2.0 capi-appfw-app-control capi-appfw-service-application) + PKG_CHECK_MODULES(${PROJECT_NAME} REQUIRED aul pkgmgr-info pkgmgr-installer dlog ecore bundle dlog launchpad elementary glib-2.0) ENDIF(DEFINED NO_TIZEN) FOREACH(flag ${${PROJECT_NAME}_CFLAGS}) @@ -80,20 +80,6 @@ ADD_EXECUTABLE(${DOTNET_LAUNCHER} ${${DOTNET_LAUNCHER}_SOURCE_FILES}) SET_TARGET_PROPERTIES(${DOTNET_LAUNCHER} PROPERTIES COMPILE_FLAGS "-fPIE") -SET(SCD_LAUNCHER "scd-launcher") -SET(${SCD_LAUNCHER}_SOURCE_FILES - launcher/dotnet/scd_launcher.cc -) -ADD_EXECUTABLE(${SCD_LAUNCHER} ${${SCD_LAUNCHER}_SOURCE_FILES}) -SET_TARGET_PROPERTIES(${SCD_LAUNCHER} PROPERTIES COMPILE_FLAGS "-fPIE") - - -IF(NOT DEFINED NO_TIZEN) - TARGET_LINK_LIBRARIES(${SCD_LAUNCHER} capi-appfw-app-control dlog appcore-agent) -ENDIF(NOT DEFINED NO_TIZEN) -TARGET_LINK_LIBRARIES(${SCD_LAUNCHER} ${${PROJECT_NAME}_LDFLAGS} "-pie -ldl -lpthread") - - IF(NOT DEFINED NO_TIZEN) TARGET_LINK_LIBRARIES(${DOTNET_LAUNCHER} aul) ENDIF(NOT DEFINED NO_TIZEN) @@ -137,7 +123,6 @@ TARGET_LINK_LIBRARIES(${PREFER_DOTNET_AOT_PLUGIN} ${${PROJECT_NAME}_LDFLAGS}) IF(NOT DEFINED NO_TIZEN) INSTALL(TARGETS ${DOTNET_LAUNCHER} DESTINATION ${BINDIR}) - INSTALL(TARGETS ${SCD_LAUNCHER} DESTINATION ${BINDIR}) INSTALL(TARGETS ${NITOOL} DESTINATION ${BINDIR}) # INSTALL(TARGETS ${INSTALLER_PLUGIN} DESTINATION ${INSTALL_PLUGIN_DIR}) INSTALL(TARGETS ${PREFER_DOTNET_AOT_PLUGIN} DESTINATION ${INSTALL_MDPLUGIN_DIR}) diff --git a/NativeLauncher/launcher/dotnet/scd_launcher.cc b/NativeLauncher/launcher/dotnet/scd_launcher.cc deleted file mode 100644 index 7bbd883..0000000 --- a/NativeLauncher/launcher/dotnet/scd_launcher.cc +++ /dev/null @@ -1,580 +0,0 @@ -/* - * 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. - */ - -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - -// for serive_app -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include "dotnet_launcher.h" - -using namespace std; - - -bool isDebugMode = false; -char *coreclrGdbjit[PATH_MAX]; -char *rootPath; - -bool service_app_create(void *data) -{ - // Todo: add your code here. - return true; -} - -void service_app_terminate(void *data) -{ - // Todo: add your code here. - - return; -} - -void service_app_control(app_control_h appControl, void *data) -{ - // Get _DEBUG_ value - char* buf[82]; - int ret = app_control_get_extra_data(appControl, "_SCD_DEBUG_", buf); - - if (ret == APP_CONTROL_ERROR_NONE) - if (strcmp(*buf, "1") == 0) - isDebugMode = true; - - if (isDebugMode) - ret = app_control_get_extra_data(appControl, "_SCD_CORECLR_GDBJIT_", coreclrGdbjit); - - service_app_exit(); - return; -} - - -// -// A simple CoreCLR host that runs a managed binary with the same name as this executable but with the *.dll extension -// The dll binary must contain a main entry point. -// - -#ifndef SUCCEEDED -#define SUCCEEDED(Status) ((Status) >= 0) -#endif // !SUCCEEDED - -static const char * const __CORECLR_DLL = "libcoreclr.so"; -// Name of the environment variable controlling server GC. -// If set to 1, server GC is enabled on startup. If 0, server GC is -// disabled. Server GC is off by default. -static const char* __SERVER_GC_VAR = "CORECLR_SERVER_GC"; -#define symlinkEntrypointExecutable "/proc/self/exe" - -bool getEntrypointExecutableabsolutePath(std::string& entrypointExecutable) -{ - bool result = false; - - entrypointExecutable.clear(); - - // Get path to the executable for the current process using - // platform specific means. - - // On Linux, fetch the entry point EXE absolute path, inclusive of filename. - char exe[PATH_MAX]; - ssize_t res = readlink(symlinkEntrypointExecutable, exe, PATH_MAX - 1); - if (res != -1) { - exe[res] = '\0'; - entrypointExecutable.assign(exe); - result = true; - } else { - result = false; - } - - return result; -} - -bool getabsolutePath(const char* path, std::string& absolutePath) -{ - bool result = false; - - char realPath[PATH_MAX]; - if (realpath(path, realPath) != nullptr && realPath[0] != '\0') { - absolutePath.assign(realPath); - // realpath should return canonicalized path without the trailing slash - assert(absolutePath.back() != '/'); - - result = true; - } - - return result; -} - -bool getDirectory(const char* absolutePath, std::string& directory) -{ - directory.assign(absolutePath); - size_t lastSlash = directory.rfind('/'); - if (lastSlash != std::string::npos) { - directory.erase(lastSlash); - return true; - } - - return false; -} - -bool getClrFilesabsolutePath(const char* currentExePath, const char* clrFilesPath, std::string& clrFilesAbsolutePath) -{ - std::string clrFilesRelativePath; - const char* clrFilesPathLocal = clrFilesPath; - if (clrFilesPathLocal == nullptr) { - // There was no CLR files path specified, use the folder of the corerun/coreconsole - if (!getDirectory(currentExePath, clrFilesRelativePath)) { - perror("Failed to get directory from argv[0]"); - return false; - } - - clrFilesPathLocal = clrFilesRelativePath.c_str(); - - // TODO: consider using an env variable (if defined) as a fall-back. - // The windows version of the corerun uses core_root env variable - } - - if (!getabsolutePath(clrFilesPathLocal, clrFilesAbsolutePath)) { - perror("Failed to convert CLR files path to absolute path"); - return false; - } - - return true; -} - -void addFilesFromDirectoryToTpaList(const char* directory, std::string& tpaList) -{ - const char * const tpaExtensions[] = { - ".ni.dll", // Probe for .ni.dll first so that it's preferred if ni and il coexist in the same dir - ".dll", - ".ni.exe", - ".exe", - }; - - DIR* dir = opendir(directory); - if (dir == nullptr) - return; - - std::set addedAssemblies; - - // Walk the directory for each extension separately so that we first get files with .ni.dll extension, - // then files with .dll extension, etc. - for (unsigned int extIndex = 0; extIndex < sizeof(tpaExtensions) / sizeof(tpaExtensions[0]); extIndex++) { - const char* ext = tpaExtensions[extIndex]; - int extLength = strlen(ext); - - struct dirent* entry; - - // For all entries in the directory - while ((entry = readdir(dir)) != nullptr) { - // We are interested in files only - switch (entry->d_type) { - case DT_REG: - break; - - // Handle symlinks and file systems that do not support d_type - case DT_LNK: - case DT_UNKNOWN: - { - std::string fullFileName; - - fullFileName.append(directory); - fullFileName.append("/"); - fullFileName.append(entry->d_name); - - struct stat sb; - if (stat(fullFileName.c_str(), &sb) == -1) - continue; - - if (!S_ISREG(sb.st_mode)) - continue; - } - break; - - default: - continue; - } - - std::string fileName(entry->d_name); - - // Check if the extension matches the one we are looking for - int extPos = fileName.length() - extLength; - if ((extPos <= 0) || (fileName.compare(extPos, extLength, ext) != 0)) - continue; - - std::string fileNameWithoutExt(fileName.substr(0, extPos)); - - // Make sure if we have an assembly with multiple extensions present, - // we insert only one version of it. - if (addedAssemblies.find(fileNameWithoutExt) == addedAssemblies.end()) { - addedAssemblies.insert(fileNameWithoutExt); - - tpaList.append(directory); - tpaList.append("/"); - tpaList.append(fileName); - tpaList.append(":"); - } - } - - // Rewind the directory stream to be able to iterate over it for the next extension - rewinddir(dir); - } - - closedir(dir); -} - -int executeManagedAssembly(const char* currentExeAbsolutePath, - const char* clrFilesAbsolutePath, - const char* managedAssemblyAbsolutePath, - int managedAssemblyArgc, - const char** managedAssemblyArgv) -{ - // Indicates failure - int exitCode = -1; - -#ifdef __arm__ - // libunwind library is used to unwind stack frame, but libunwind for ARM - // does not support ARM vfpv3/NEON registers in DWARF format correctly. - // Therefore let's disable stack unwinding using DWARF information - // See https://github.com/dotnet/coreclr/issues/6698 - // - // libunwind use following methods to unwind stack frame. - // UNW_ARM_METHOD_ALL 0xFF - // UNW_ARM_METHOD_DWARF 0x01 - // UNW_ARM_METHOD_FRAME 0x02 - // UNW_ARM_METHOD_EXIDX 0x04 - putenv(const_cast("UNW_ARM_UNWIND_METHOD=6")); -#endif // __arm__ - - std::string coreClrDllPath(clrFilesAbsolutePath); - coreClrDllPath.append("/"); - coreClrDllPath.append(__CORECLR_DLL); - - if (coreClrDllPath.length() >= PATH_MAX) { - fprintf(stderr, "Absolute path to libcoreclr.so too long\n"); - return -1; - } - - // Get just the path component of the managed assembly path - std::string appPath; - getDirectory(managedAssemblyAbsolutePath, appPath); - - std::string tpaList; - // Construct native search directory paths - std::string nativeDllSearchDirs(appPath); - char *coreLibraries = getenv("CORE_LIBRARIES"); - if (coreLibraries) { - nativeDllSearchDirs.append(":"); - nativeDllSearchDirs.append(coreLibraries); - if (std::strcmp(coreLibraries, clrFilesAbsolutePath) != 0) - addFilesFromDirectoryToTpaList(coreLibraries, tpaList); - } - nativeDllSearchDirs.append(":"); - nativeDllSearchDirs.append(clrFilesAbsolutePath); - - addFilesFromDirectoryToTpaList(clrFilesAbsolutePath, tpaList); - - void* __coreclrLib = dlopen(coreClrDllPath.c_str(), RTLD_NOW | RTLD_LOCAL); - if (__coreclrLib != nullptr) { - coreclr_initialize_ptr initializeCoreCLR = (coreclr_initialize_ptr)dlsym(__coreclrLib, "coreclr_initialize"); - coreclr_execute_assembly_ptr executeAssembly = (coreclr_execute_assembly_ptr)dlsym(__coreclrLib, "coreclr_execute_assembly"); - coreclr_shutdown_ptr shutdownCoreCLR = (coreclr_shutdown_ptr)dlsym(__coreclrLib, "coreclr_shutdown"); - - if (initializeCoreCLR == nullptr) { - fprintf(stderr, "Function coreclr_initialize not found in the libcoreclr.so\n"); - } else if (executeAssembly == nullptr) { - fprintf(stderr, "Function coreclr_execute_assembly not found in the libcoreclr.so\n"); - } else if (shutdownCoreCLR == nullptr) { - fprintf(stderr, "Function coreclr_shutdown not found in the libcoreclr.so\n"); - } else { - // Check whether we are enabling server GC (off by default) - const char* useServerGc = std::getenv(__SERVER_GC_VAR); - if (useServerGc == nullptr) - useServerGc = "0"; - - // CoreCLR expects strings "true" and "false" instead of "1" and "0". - useServerGc = std::strcmp(useServerGc, "1") == 0 ? "true" : "false"; - - // Allowed property names: - // APPBASE - // - The base path of the application from which the exe and other assemblies will be loaded - // - // TRUSTED_PLATFORM_ASSEMBLIES - // - The list of complete paths to each of the fully trusted assemblies - // - // APP_PATHS - // - The list of paths which will be probed by the assembly loader - // - // APP_NI_PATHS - // - The list of additional paths that the assembly loader will probe for ngen images - // - // NATIVE_DLL_SEARCH_DIRECTORIES - // - The list of paths that will be probed for native DLLs called by PInvoke - // - const char *propertyKeys[] = { - "TRUSTED_PLATFORM_ASSEMBLIES", - "APP_PATHS", - "APP_NI_PATHS", - "NATIVE_DLL_SEARCH_DIRECTORIES", - "System.GC.Server", - }; - const char *propertyValues[] = { - // TRUSTED_PLATFORM_ASSEMBLIES - tpaList.c_str(), - // APP_PATHS - appPath.c_str(), - // APP_NI_PATHS - appPath.c_str(), - // NATIVE_DLL_SEARCH_DIRECTORIES - nativeDllSearchDirs.c_str(), - // System.GC.Server - useServerGc, - }; - - void* hostHandle; - unsigned int domainId; - - int st = initializeCoreCLR(currentExeAbsolutePath, - "unixcorerun", - sizeof(propertyKeys) / sizeof(propertyKeys[0]), - propertyKeys, - propertyValues, - &hostHandle, - &domainId); - - if (!SUCCEEDED(st)) { - fprintf(stderr, "coreclr_initialize failed - status: 0x%08x\n", st); - exitCode = -1; - } else { - st = executeAssembly(hostHandle, - domainId, - managedAssemblyArgc, - managedAssemblyArgv, - managedAssemblyAbsolutePath, - (unsigned int*)&exitCode); - - if (!SUCCEEDED(st)) { - fprintf(stderr, "coreclr_execute_assembly failed - status: 0x%08x\n", st); - exitCode = -1; - } - - st = shutdownCoreCLR(hostHandle, domainId); - if (!SUCCEEDED(st)) { - fprintf(stderr, "coreclr_shutdown failed - status: 0x%08x\n", st); - exitCode = -1; - } - } - } - - if (dlclose(__coreclrLib) != 0) { - fprintf(stderr, "Warning - dlclose failed\n"); - } - } else { - const char* error = dlerror(); - fprintf(stderr, "dlopen failed to open the libcoreclr.so with error %s\n", error); - } - - return exitCode; -} - - -// Display the help text -void displayUsage() -{ - fprintf(stderr, - "Runs executables on CoreCLR\n\n" - "Usage: [OPTIONS] [ARGUMENTS]\n" - "Runs .dll on CoreCLR.\n\n" - "Options:\n" - "-_c path to libcoreclr.so and the managed CLR assemblies.\n" - "-_h show this help message. \n"); -} - -// Parse the command line arguments -bool parseArguments(const int argc, - const char* argv[], - const char** clrFilesPath, - int* managedAssemblyArgc, - const char*** managedAssemblyArgv) -{ - bool success = true; - - *clrFilesPath = nullptr; - *managedAssemblyArgv = nullptr; - *managedAssemblyArgc = 0; - - for (int i = 1; i < argc; i++) { - // Check for options. Options to the Unix coreconsole are prefixed with '-_' to match the convention - // used in the Windows version of coreconsole. - if (strncmp(argv[i], "-_", 2) == 0) { - // Path to the libcoreclr.so and the managed CLR assemblies - if (strcmp(argv[i], "-_c") == 0) { - i++; - if (i < argc) { - *clrFilesPath = argv[i]; - } else { - fprintf(stderr, "Option %s: missing path\n", argv[i - 1]); - success = false; - break; - } - } else if (strcmp(argv[i], "-_h") == 0) { - displayUsage(); - success = false; - break; - } else { - fprintf(stderr, "Unknown option %s\n", argv[i]); - success = false; - break; - } - } else { - // We treat everything starting from the first non-option argument as arguments - // to the managed assembly. - *managedAssemblyArgc = argc - i; - if (*managedAssemblyArgc != 0) - *managedAssemblyArgv = &argv[i]; - - break; - } - } - - return success; -} - -int main(const int argc, const char* argv[]) -{ - /// service_app_begin - char *rootPath = getenv("AUL_ROOT_PATH"); - char *secondPass = getenv("SECONDPASS"); - - // This routine check whether _SCD_DEBUG_ flag is set(1) or not. - // In second pass, this routine is skipped. - if (secondPass == NULL) { - // run service_app routine to extract _SCD_DEBUG_ - char ad[50] = {0, }; - service_app_lifecycle_callback_s eventCallback; - eventCallback.create = service_app_create; - eventCallback.terminate = service_app_terminate; - eventCallback.app_control = service_app_control; - // FIXME: casting of argv is safe ? - service_app_main(argc, (char**)argv, &eventCallback, ad); - - char buf[PATH_MAX]; - vector vargs; - int status = 0; - - if (isDebugMode) { - dlog_print(DLOG_INFO, "dotnet", "debugmode on\n"); - setenv("CORECLR_GDBJIT", *coreclrGdbjit, 1); - - string curPath(getenv("PATH")); - string newPath("/home/owner/share/tmp/sdk_tools/lldb/bin:"); - newPath.append(curPath); - setenv("PATH", newPath.c_str(), 1); - - vargs.push_back("/home/owner/share/tmp/sdk_tools/lldb/bin/lldb-server"); - vargs.push_back("g"); - vargs.push_back("--platform=host"); - vargs.push_back("*:1234"); - vargs.push_back("--"); - } - snprintf(buf, sizeof(buf), "%s/bin/%s", rootPath, basename(rootPath)); - vargs.push_back(buf); - - // Pass app argument to lldb-server as it is - for (int i = 1; i < argc; i++) - vargs.push_back(argv[i]); - - const char** newArgs = &vargs[0]; - setenv("SECONDPASS", "1", 1); - status = execvp(newArgs[0], (char *const *)newArgs); - if (status == -1) - dlog_print(DLOG_ERROR, "dotnet", "execvp error"); - dlog_print(DLOG_INFO, "dotnet", "something wrong errno: %d\n", errno); - } - /// service_app_end - - // Make sure we have a full path for argv[0]. - std::string argv0AbsolutePath; - std::string entryPointExecutablePath; - - if (!getEntrypointExecutableabsolutePath(entryPointExecutablePath)) { - perror("Could not get full path to current executable"); - return -1; - } - - if (!getabsolutePath(entryPointExecutablePath.c_str(), argv0AbsolutePath)) { - perror("Could not normalize full path to current executable"); - return -1; - } - - // We will try to load the managed assembly with the same name as this executable - // but with the .dll extension. - std::string programPath(argv0AbsolutePath); - programPath.append(".dll"); - const char* managedAssemblyAbsolutePath = programPath.c_str(); - - // Check if the specified managed assembly file exists - struct stat sb; - if (stat(managedAssemblyAbsolutePath, &sb) == -1) { - perror("Managed assembly not found"); - return -1; - } - - // Verify that the managed assembly path points to a file - if (!S_ISREG(sb.st_mode)) { - fprintf(stderr, "The specified managed assembly is not a file\n"); - return -1; - } - - const char* clrFilesPath; - const char** managedAssemblyArgv; - int managedAssemblyArgc; - if (!parseArguments(argc, argv, &clrFilesPath, &managedAssemblyArgc, &managedAssemblyArgv)) - return -1; - - std::string clrFilesAbsolutePath; - if (!getClrFilesabsolutePath(argv0AbsolutePath.c_str(), clrFilesPath, clrFilesAbsolutePath)) - return -1; - - int exitCode = executeManagedAssembly(argv0AbsolutePath.c_str(), - clrFilesAbsolutePath.c_str(), - managedAssemblyAbsolutePath, - managedAssemblyArgc, - managedAssemblyArgv); - - return exitCode; -} diff --git a/packaging/dotnet-launcher.spec b/packaging/dotnet-launcher.spec index 6d4216e..7f4d46c 100644 --- a/packaging/dotnet-launcher.spec +++ b/packaging/dotnet-launcher.spec @@ -20,14 +20,6 @@ BuildRequires: pkgconfig(glib-2.0) BuildRequires: aul-devel BuildRequires: dotnet-build-tools -# Required by scd-launcher -BuildRequires: appcore-agent -BuildRequires: pkgconfig(appcore-agent) -BuildRequires: pkgconfig(capi-appfw-app-control) -BuildRequires: pkgconfig(capi-appfw-application) -BuildRequires: pkgconfig(capi-appfw-service-application) - - Requires: aul Requires(post): /sbin/ldconfig @@ -49,11 +41,6 @@ ExcludeArch: aarch64 %description Launchpad plugin for launching dotnet apps -%package -n scd-launcher -Summary: self-contained dotnet launcher -%description -n scd-launcher -launching dotnet apps without dotent runtime installed - %prep %setup -q @@ -112,6 +99,3 @@ ln -sf %{_libdir}/libsqlite3.so.0 %{buildroot}%{_native_lib_dir}/libsqlite3.so %{_bindir}/Tizen.Runtime.dll %endif %caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/dotnet-launcher - -%files -n scd-launcher -%caps(cap_mac_admin,cap_setgid=ei) %{_bindir}/scd-launcher