2016-02-22 01:41:25 -08:00
|
|
|
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
|
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
|
|
|
|
#include "pal.h"
|
|
|
|
#include "utils.h"
|
|
|
|
#include "trace.h"
|
|
|
|
#include "libhost.h"
|
|
|
|
|
2016-04-07 16:20:51 -07:00
|
|
|
void get_runtime_config_paths_from_file(const pal::string_t& file, pal::string_t* cfg, pal::string_t* dev_cfg)
|
2016-02-22 01:41:25 -08:00
|
|
|
{
|
2016-03-17 01:37:39 -07:00
|
|
|
auto name = get_filename_without_ext(file);
|
2016-04-07 16:20:51 -07:00
|
|
|
|
2016-02-22 01:41:25 -08:00
|
|
|
auto json_name = name + _X(".runtimeconfig.json");
|
2016-04-01 07:14:14 -07:00
|
|
|
auto dev_json_name = name + _X(".runtimeconfig.dev.json");
|
2016-04-07 16:20:51 -07:00
|
|
|
|
2016-03-17 01:37:39 -07:00
|
|
|
auto json_path = get_directory(file);
|
2016-04-01 07:14:14 -07:00
|
|
|
auto dev_json_path = json_path;
|
2016-02-22 01:41:25 -08:00
|
|
|
|
|
|
|
append_path(&json_path, json_name.c_str());
|
2016-04-01 07:14:14 -07:00
|
|
|
append_path(&dev_json_path, dev_json_name.c_str());
|
2016-04-07 16:20:51 -07:00
|
|
|
|
2016-04-01 07:14:14 -07:00
|
|
|
trace::verbose(_X("Runtime config is cfg=%s dev=%s"), json_path.c_str(), dev_json_path.c_str());
|
|
|
|
|
|
|
|
dev_cfg->assign(dev_json_path);
|
2016-04-07 16:20:51 -07:00
|
|
|
cfg -> assign(json_path);
|
2016-02-22 01:41:25 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
host_mode_t detect_operating_mode(const int argc, const pal::char_t* argv[], pal::string_t* p_own_dir)
|
|
|
|
{
|
|
|
|
pal::string_t own_path;
|
|
|
|
if (!pal::get_own_executable_path(&own_path) || !pal::realpath(&own_path))
|
|
|
|
{
|
|
|
|
trace::error(_X("Failed to locate current executable"));
|
|
|
|
return host_mode_t::invalid;
|
|
|
|
}
|
|
|
|
|
|
|
|
pal::string_t own_name = get_filename(own_path);
|
|
|
|
pal::string_t own_dir = get_directory(own_path);
|
|
|
|
if (p_own_dir)
|
|
|
|
{
|
|
|
|
p_own_dir->assign(own_dir);
|
|
|
|
}
|
|
|
|
|
2016-03-29 14:47:53 -07:00
|
|
|
pal::string_t own_dll_filename = get_executable(own_name) + _X(".dll");
|
2016-02-22 01:41:25 -08:00
|
|
|
pal::string_t own_dll = own_dir;
|
|
|
|
append_path(&own_dll, own_dll_filename.c_str());
|
2016-03-23 18:00:52 -07:00
|
|
|
trace::info(_X("Own DLL path=[%s]"), own_dll.c_str());
|
2016-02-22 01:41:25 -08:00
|
|
|
if (coreclr_exists_in_dir(own_dir) || pal::file_exists(own_dll))
|
|
|
|
{
|
|
|
|
pal::string_t own_deps_json = own_dir;
|
|
|
|
pal::string_t own_deps_filename = strip_file_ext(own_name) + _X(".deps.json");
|
|
|
|
pal::string_t own_config_filename = strip_file_ext(own_name) + _X(".runtimeconfig.json");
|
|
|
|
append_path(&own_deps_json, own_deps_filename.c_str());
|
|
|
|
if (trace::is_enabled())
|
|
|
|
{
|
|
|
|
trace::info(_X("Detecting mode... CoreCLR present in own dir [%s] and checking if [%s] file present=[%d]"),
|
|
|
|
own_dir.c_str(), own_deps_filename.c_str(), pal::file_exists(own_deps_json));
|
|
|
|
}
|
|
|
|
return ((pal::file_exists(own_deps_json) || !pal::file_exists(own_config_filename)) && pal::file_exists(own_dll)) ? host_mode_t::standalone : host_mode_t::split_fx;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return host_mode_t::muxer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-06 04:24:23 -07:00
|
|
|
void try_patch_roll_forward_in_dir(const pal::string_t& cur_dir, const fx_ver_t& start_ver, pal::string_t* max_str)
|
2016-03-28 02:59:57 -07:00
|
|
|
{
|
|
|
|
pal::string_t path = cur_dir;
|
|
|
|
|
|
|
|
if (trace::is_enabled())
|
|
|
|
{
|
|
|
|
pal::string_t start_str = start_ver.as_str();
|
2016-04-06 04:24:23 -07:00
|
|
|
trace::verbose(_X("Reading patch roll forward candidates in dir [%s] for version [%s]"), path.c_str(), start_str.c_str());
|
2016-03-28 02:59:57 -07:00
|
|
|
}
|
|
|
|
|
2016-04-06 04:24:23 -07:00
|
|
|
pal::string_t maj_min_star = start_ver.patch_glob();
|
2016-03-28 02:59:57 -07:00
|
|
|
|
|
|
|
std::vector<pal::string_t> list;
|
|
|
|
pal::readdir(path, maj_min_star, &list);
|
|
|
|
|
|
|
|
fx_ver_t max_ver = start_ver;
|
|
|
|
fx_ver_t ver(-1, -1, -1);
|
|
|
|
for (const auto& str : list)
|
|
|
|
{
|
2016-04-06 04:24:23 -07:00
|
|
|
trace::verbose(_X("Considering patch roll forward candidate version [%s]"), str.c_str());
|
|
|
|
if (fx_ver_t::parse(str, &ver, true))
|
2016-03-28 02:59:57 -07:00
|
|
|
{
|
|
|
|
max_ver = std::max(ver, max_ver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
max_str->assign(max_ver.as_str());
|
|
|
|
|
|
|
|
if (trace::is_enabled())
|
|
|
|
{
|
|
|
|
pal::string_t start_str = start_ver.as_str();
|
2016-04-06 04:24:23 -07:00
|
|
|
trace::verbose(_X("Patch roll forwarded [%s] -> [%s] in [%s]"), start_str.c_str(), max_str->c_str(), path.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void try_prerelease_roll_forward_in_dir(const pal::string_t& cur_dir, const fx_ver_t& start_ver, pal::string_t* max_str)
|
|
|
|
{
|
|
|
|
pal::string_t path = cur_dir;
|
|
|
|
|
|
|
|
if (trace::is_enabled())
|
|
|
|
{
|
|
|
|
pal::string_t start_str = start_ver.as_str();
|
|
|
|
trace::verbose(_X("Reading prerelease roll forward candidates in dir [%s] for version [%s]"), path.c_str(), start_str.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
pal::string_t maj_min_pat_star = start_ver.prerelease_glob();
|
|
|
|
|
|
|
|
std::vector<pal::string_t> list;
|
|
|
|
pal::readdir(path, maj_min_pat_star, &list);
|
|
|
|
|
|
|
|
fx_ver_t max_ver = start_ver;
|
|
|
|
fx_ver_t ver(-1, -1, -1);
|
|
|
|
for (const auto& str : list)
|
|
|
|
{
|
|
|
|
trace::verbose(_X("Considering prerelease roll forward candidate version [%s]"), str.c_str());
|
|
|
|
if (fx_ver_t::parse(str, &ver, false)
|
|
|
|
&& ver.is_prerelease()) // Pre-release can roll forward to only pre-release
|
|
|
|
{
|
|
|
|
max_ver = std::max(ver, max_ver);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
max_str->assign(max_ver.as_str());
|
|
|
|
|
|
|
|
if (trace::is_enabled())
|
|
|
|
{
|
|
|
|
pal::string_t start_str = start_ver.as_str();
|
|
|
|
trace::verbose(_X("Prerelease roll forwarded [%s] -> [%s] in [%s]"), start_str.c_str(), max_str->c_str(), path.c_str());
|
2016-03-28 02:59:57 -07:00
|
|
|
}
|
|
|
|
}
|