Add support for runtime config

-- Remove GC Server Default
This commit is contained in:
schellap 2016-03-18 02:36:18 -07:00 committed by Senthil
parent 3a63972af1
commit 43e25ae571
6 changed files with 60 additions and 42 deletions

View file

@ -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

View file

@ -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());

View file

@ -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<const char*> 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<const char*> 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<std::string> cfg_keys;
std::vector<std::string> 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);

View file

@ -7,49 +7,55 @@
#include "runtime_config.h"
#include <cassert>
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<std::string>* keys, std::vector<std::string>* values) const
{
for (const auto& kv : m_properties)
{
keys->push_back(pal::to_stdstring(kv.first));
values->push_back(pal::to_stdstring(kv.second));
}
}

View file

@ -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::string>*, std::vector<std::string>*) const;
private:
bool ensure_parsed();
pal::string_t m_gc_server;
std::unordered_map<pal::string_t, pal::string_t> m_properties;
std::vector<std::string> m_prop_keys;
std::vector<std::string> m_prop_values;
pal::string_t m_fx_name;
pal::string_t m_fx_ver;
bool m_fx_roll_fwd;

View file

@ -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);