From 43e25ae5716a739fde9290a4b27e6c0d4f17f53b Mon Sep 17 00:00:00 2001 From: schellap Date: Fri, 18 Mar 2016 02:36:18 -0700 Subject: [PATCH] Add support for runtime config -- Remove GC Server Default --- src/corehost/cli/deps_format.cpp | 1 - src/corehost/cli/fxr/fx_muxer.cpp | 2 -- src/corehost/cli/hostpolicy.cpp | 31 ++++++++-------- src/corehost/cli/runtime_config.cpp | 55 +++++++++++++++++------------ src/corehost/cli/runtime_config.h | 11 ++++-- src/corehost/common/utils.h | 2 ++ 6 files changed, 60 insertions(+), 42 deletions(-) diff --git a/src/corehost/cli/deps_format.cpp b/src/corehost/cli/deps_format.cpp index f9e02ffa4..889d51425 100644 --- a/src/corehost/cli/deps_format.cpp +++ b/src/corehost/cli/deps_format.cpp @@ -104,7 +104,6 @@ void deps_json_t::reconcile_libraries_with_targets( pal::string_t get_own_rid() { -#define _STRINGIFY(s) _X(s) #if defined(TARGET_RUNTIME_ID) return _STRINGIFY(TARGET_RUNTIME_ID); #else diff --git a/src/corehost/cli/fxr/fx_muxer.cpp b/src/corehost/cli/fxr/fx_muxer.cpp index 59d840e28..b815e5d72 100644 --- a/src/corehost/cli/fxr/fx_muxer.cpp +++ b/src/corehost/cli/fxr/fx_muxer.cpp @@ -13,8 +13,6 @@ #include "cpprest/json.h" #include "error_codes.h" -typedef web::json::value json_value; - pal::string_t fx_muxer_t::resolve_fx_dir(const pal::string_t& muxer_dir, runtime_config_t* runtime) { trace::verbose(_X("--- Resolving FX directory from muxer dir [%s]"), muxer_dir.c_str()); diff --git a/src/corehost/cli/hostpolicy.cpp b/src/corehost/cli/hostpolicy.cpp index 7cf161fba..7e1fc9a6b 100644 --- a/src/corehost/cli/hostpolicy.cpp +++ b/src/corehost/cli/hostpolicy.cpp @@ -51,17 +51,14 @@ int run(const corehost_init_t* init, const runtime_config_t& config, const argum return StatusCode::ResolverResolveFailure; } - // TODO: config.get_runtime_properties(); - // Build CoreCLR properties - const char* property_keys[] = { + std::vector property_keys = { "TRUSTED_PLATFORM_ASSEMBLIES", "APP_PATHS", "APP_NI_PATHS", "NATIVE_DLL_SEARCH_DIRECTORIES", "PLATFORM_RESOURCE_ROOTS", "AppDomainCompatSwitch", - "SERVER_GC", // Workaround: mscorlib does not resolve symlinks for AppContext.BaseDirectory dotnet/coreclr/issues/2128 "APP_CONTEXT_BASE_DIRECTORY", "APP_CONTEXT_DEPS_FILES" @@ -72,13 +69,9 @@ int run(const corehost_init_t* init, const runtime_config_t& config, const argum auto native_dirs_cstr = pal::to_stdstring(probe_paths.native); auto resources_dirs_cstr = pal::to_stdstring(probe_paths.resources); - // Workaround for dotnet/cli Issue #488 and #652 - pal::string_t server_gc; - std::string server_gc_cstr = (pal::getenv(_X("COREHOST_SERVER_GC"), &server_gc) && !server_gc.empty()) ? pal::to_stdstring(server_gc) : "0"; - std::string deps = pal::to_stdstring(resolver.get_deps_file() + _X(";") + resolver.get_fx_deps_file()); - const char* property_values[] = { + std::vector property_values = { // TRUSTED_PLATFORM_ASSEMBLIES tpa_paths_cstr.c_str(), // APP_PATHS @@ -91,15 +84,25 @@ int run(const corehost_init_t* init, const runtime_config_t& config, const argum resources_dirs_cstr.c_str(), // AppDomainCompatSwitch "UseLatestBehaviorWhenTFMNotSpecified", - // SERVER_GC - server_gc_cstr.c_str(), // APP_CONTEXT_BASE_DIRECTORY app_base_cstr.c_str(), // APP_CONTEXT_DEPS_FILES, deps.c_str(), }; - size_t property_size = sizeof(property_keys) / sizeof(property_keys[0]); + + std::vector cfg_keys; + std::vector cfg_values; + config.config_kv(&cfg_keys, &cfg_values); + + for (int i = 0; i < cfg_keys.size(); ++i) + { + property_keys.push_back(cfg_keys[i].c_str()); + property_values.push_back(cfg_values[i].c_str()); + } + + size_t property_size = property_keys.size(); + assert(property_keys.size() == property_values.size()); // Bind CoreCLR if (!coreclr::bind(clr_path)) @@ -129,8 +132,8 @@ int run(const corehost_init_t* init, const runtime_config_t& config, const argum auto hr = coreclr::initialize( own_path.c_str(), "clrhost", - property_keys, - property_values, + property_keys.data(), + property_values.data(), property_size, &host_handle, &domain_id); diff --git a/src/corehost/cli/runtime_config.cpp b/src/corehost/cli/runtime_config.cpp index e27c5a3a0..c929cd9c7 100644 --- a/src/corehost/cli/runtime_config.cpp +++ b/src/corehost/cli/runtime_config.cpp @@ -7,49 +7,55 @@ #include "runtime_config.h" #include -typedef web::json::value json_value; - runtime_config_t::runtime_config_t(const pal::string_t& path) : m_fx_roll_fwd(true) , m_path(path) , m_portable(false) - , m_gc_server(_X("0")) { m_valid = ensure_parsed(); } -void parse_fx(const json_value& opts, pal::string_t* name, pal::string_t* version, bool* roll_fwd, bool* portable) +bool runtime_config_t::parse_opts(const json_value& opts) { - name->clear(); - version->clear(); - *roll_fwd = true; - *portable = false; - if (opts.is_null()) { - return; + return true; } const auto& opts_obj = opts.as_object(); + + auto properties = opts_obj.find(_X("configProperties")); + if (properties != opts_obj.end()) + { + const auto& prop_obj = properties->second.as_object(); + for (const auto& property : prop_obj) + { + m_properties[property.first] = property.second.is_string() + ? property.second.as_string() + : property.second.to_string(); + } + } + auto framework = opts_obj.find(_X("framework")); if (framework == opts_obj.end()) { - return; + return true; } - *portable = true; + m_portable = true; const auto& fx_obj = framework->second.as_object(); - *name = fx_obj.at(_X("name")).as_string(); - *version = fx_obj.at(_X("version")).as_string(); + m_fx_name = fx_obj.at(_X("name")).as_string(); + m_fx_ver = fx_obj.at(_X("version")).as_string(); auto value = fx_obj.find(_X("rollForward")); if (value == fx_obj.end()) { - return; + return true; } - *roll_fwd = value->second.as_bool(); + m_fx_roll_fwd = value->second.as_bool(); + return true; } bool runtime_config_t::ensure_parsed() @@ -74,7 +80,7 @@ bool runtime_config_t::ensure_parsed() const auto iter = json.find(_X("runtimeOptions")); if (iter != json.end()) { - parse_fx(iter->second, &m_fx_name, &m_fx_ver, &m_fx_roll_fwd, &m_portable); + parse_opts(iter->second); } } catch (...) @@ -84,12 +90,6 @@ bool runtime_config_t::ensure_parsed() return true; } -const pal::string_t& runtime_config_t::get_gc_server() const -{ - assert(m_valid); - return m_gc_server; -} - const pal::string_t& runtime_config_t::get_fx_name() const { assert(m_valid); @@ -112,3 +112,12 @@ bool runtime_config_t::get_portable() const { return m_portable; } + +void runtime_config_t::config_kv(std::vector* keys, std::vector* values) const +{ + for (const auto& kv : m_properties) + { + keys->push_back(pal::to_stdstring(kv.first)); + values->push_back(pal::to_stdstring(kv.second)); + } +} diff --git a/src/corehost/cli/runtime_config.h b/src/corehost/cli/runtime_config.h index bdb14fda1..04c582aba 100644 --- a/src/corehost/cli/runtime_config.h +++ b/src/corehost/cli/runtime_config.h @@ -2,6 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. #include "pal.h" +#include "cpprest/json.h" + +typedef web::json::value json_value; class runtime_config_t { @@ -14,11 +17,15 @@ public: const pal::string_t& get_fx_name() const; bool get_fx_roll_fwd() const; bool get_portable() const; + bool parse_opts(const json_value& opts); + void config_kv(std::vector*, std::vector*) const; private: bool ensure_parsed(); - - pal::string_t m_gc_server; + + std::unordered_map m_properties; + std::vector m_prop_keys; + std::vector m_prop_values; pal::string_t m_fx_name; pal::string_t m_fx_ver; bool m_fx_roll_fwd; diff --git a/src/corehost/common/utils.h b/src/corehost/common/utils.h index 2239946cb..29aee0487 100644 --- a/src/corehost/common/utils.h +++ b/src/corehost/common/utils.h @@ -6,6 +6,8 @@ #include "pal.h" +#define _STRINGIFY(s) _X(s) + bool ends_with(const pal::string_t& value, const pal::string_t& suffix, bool match_case); bool starts_with(const pal::string_t& value, const pal::string_t& prefix, bool match_case); pal::string_t get_executable(const pal::string_t& filename);