From 103aaa4d8e1fcfa0180654834ab2e65ba55ef7c5 Mon Sep 17 00:00:00 2001 From: Andrew Stanton-Nurse Date: Thu, 19 Nov 2015 09:33:43 -0800 Subject: [PATCH] add default values for DOTNET_HOME in corehost fixes #234 --- src/corehost/inc/pal.h | 2 ++ src/corehost/inc/utils.h | 1 + src/corehost/src/args.cpp | 8 ++++++++ src/corehost/src/main.cpp | 6 +++--- src/corehost/src/pal.unix.cpp | 26 ++++++++++++++++++++++++++ src/corehost/src/pal.windows.cpp | 18 ++++++++++++++++++ src/corehost/src/utils.cpp | 8 ++++++++ 7 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/corehost/inc/pal.h b/src/corehost/inc/pal.h index e6ba1914a..f863a31f4 100644 --- a/src/corehost/inc/pal.h +++ b/src/corehost/inc/pal.h @@ -108,6 +108,8 @@ namespace pal bool load_library(const char_t* path, dll_t& dll); proc_t get_symbol(dll_t library, const char* name); void unload_library(dll_t library); + + bool find_coreclr(pal::string_t& recv); } #endif // PAL_H diff --git a/src/corehost/inc/utils.h b/src/corehost/inc/utils.h index 49abe8bba..8a9c6a022 100644 --- a/src/corehost/inc/utils.h +++ b/src/corehost/inc/utils.h @@ -11,5 +11,6 @@ pal::string_t get_executable(const pal::string_t& filename); pal::string_t get_directory(const pal::string_t& path); pal::string_t get_filename(const pal::string_t& path); void append_path(pal::string_t& path1, const pal::char_t* path2); +bool coreclr_exists_in_dir(const pal::string_t& candidate); #endif diff --git a/src/corehost/src/args.cpp b/src/corehost/src/args.cpp index d10bb6215..924b68af5 100644 --- a/src/corehost/src/args.cpp +++ b/src/corehost/src/args.cpp @@ -79,6 +79,14 @@ bool parse_arguments(const int argc, const pal::char_t* argv[], arguments_t& arg append_path(home_str, _X("coreclr")); args.clr_path.assign(home_str); } + else + { + // Use platform-specific search algorithm + if (pal::find_coreclr(home_str)) + { + args.clr_path.assign(home_str); + } + } return true; } diff --git a/src/corehost/src/main.cpp b/src/corehost/src/main.cpp index 514071147..ae1ef51de 100644 --- a/src/corehost/src/main.cpp +++ b/src/corehost/src/main.cpp @@ -214,14 +214,14 @@ int main(const int argc, const pal::char_t* argv[]) trace::info(_X("preparing to launch: %s"), app_name.c_str()); trace::info(_X("using app base: %s"), app_base.c_str()); - // Check for and load tpa file + // Check for and load deps file pal::string_t tpafile_path; get_tpafile_path(app_base, app_name, tpafile_path); - trace::info(_X("checking for TPA File at: %s"), tpafile_path.c_str()); + trace::info(_X("checking for .deps File at: %s"), tpafile_path.c_str()); tpafile tpa; if (!tpa.load(tpafile_path)) { - trace::error(_X("invalid TPA file")); + trace::error(_X("invalid .deps file")); return 1; } return run(args, app_base, tpa); diff --git a/src/corehost/src/pal.unix.cpp b/src/corehost/src/pal.unix.cpp index c00c55170..170cf1758 100644 --- a/src/corehost/src/pal.unix.cpp +++ b/src/corehost/src/pal.unix.cpp @@ -19,6 +19,32 @@ #define symlinkEntrypointExecutable "/proc/curproc/exe" #endif +bool coreclr_exists_in_dir(const pal::string_t& candidate) +{ + pal::string_t test(candidate); + append_path(test, _X("runtime")); + append_path(test, LIBCORECLR_NAME); + return pal::file_exists(test); +} + +bool pal::find_coreclr(pal::string_t& recv) +{ + pal::string_t candidate; + pal::string_t test; + + // Try %LocalAppData%\dotnet + if (pal::getenv(_X("LocalAppData"), candidate)) { + append_path(candidate, _X("dotnet")); + if (coreclr_exists_in_dir(candidate)) { + recv.assign(candidate); + return true; + } + } + + // TODO: Try somewhere in Program Files, see https://github.com/dotnet/cli/issues/249 + return false; +} + bool pal::load_library(const char_t* path, dll_t& dll) { dll = dlopen(path, RTLD_LAZY); diff --git a/src/corehost/src/pal.windows.cpp b/src/corehost/src/pal.windows.cpp index bb2ebb815..d56ed8051 100644 --- a/src/corehost/src/pal.windows.cpp +++ b/src/corehost/src/pal.windows.cpp @@ -10,6 +10,24 @@ static std::wstring_convert, wchar_t> g_converter; +bool pal::find_coreclr(pal::string_t& recv) +{ + pal::string_t candidate; + pal::string_t test; + + // Try %LocalAppData%\dotnet + if (pal::getenv(_X("LocalAppData"), candidate)) { + append_path(candidate, _X("dotnet")); + if (coreclr_exists_in_dir(candidate)) { + recv.assign(candidate); + return true; + } + } + + // TODO: Try somewhere in Program Files, see https://github.com/dotnet/cli/issues/249 + return false; +} + bool pal::load_library(const char_t* path, dll_t& dll) { dll = ::LoadLibraryW(path); diff --git a/src/corehost/src/utils.cpp b/src/corehost/src/utils.cpp index 4f53e9100..742c2c893 100644 --- a/src/corehost/src/utils.cpp +++ b/src/corehost/src/utils.cpp @@ -3,6 +3,14 @@ #include "utils.h" +bool coreclr_exists_in_dir(const pal::string_t& candidate) +{ + pal::string_t test(candidate); + append_path(test, _X("runtime")); + append_path(test, LIBCORECLR_NAME); + return pal::file_exists(test); +} + bool ends_with(const pal::string_t& value, const pal::string_t& suffix) { return suffix.length() <= value.length() &&