From c99e92a6a844463ef8e932736b5cccd9bf4f8107 Mon Sep 17 00:00:00 2001 From: Senthil Date: Wed, 4 May 2016 18:54:53 -0700 Subject: [PATCH] Prefer servicing for native dll search order --- src/corehost/cli/deps_resolver.cpp | 32 ++++++++++++++++++++++-------- src/corehost/cli/deps_resolver.h | 4 ++++ src/corehost/common/utils.cpp | 5 +++++ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/corehost/cli/deps_resolver.cpp b/src/corehost/cli/deps_resolver.cpp index 9d2c7223f..5a29940ae 100644 --- a/src/corehost/cli/deps_resolver.cpp +++ b/src/corehost/cli/deps_resolver.cpp @@ -49,7 +49,9 @@ void add_unique_path( deps_entry_t::asset_types asset_type, const pal::string_t& path, std::unordered_set* existing, - pal::string_t* output) + pal::string_t* serviced, + pal::string_t* non_serviced, + const pal::string_t& svc_dir) { // Resolve sym links. pal::string_t real = path; @@ -62,9 +64,18 @@ void add_unique_path( trace::verbose(_X("Adding to %s path: %s"), deps_entry_t::s_known_asset_types[asset_type], real.c_str()); - output->append(real); + if (starts_with(real, svc_dir, false)) + { + serviced->append(real); + serviced->push_back(PATH_SEPARATOR); + } + else + { + non_serviced->append(real); + non_serviced->push_back(PATH_SEPARATOR); + } + - output->push_back(PATH_SEPARATOR); existing->insert(real); } @@ -502,6 +513,9 @@ void deps_resolver_t::resolve_probe_dirs( }; std::function& action = is_resources ? resources : native; std::unordered_set items; + pal::string_t core_servicing = m_core_servicing; + pal::realpath(&core_servicing); + pal::string_t non_serviced; std::vector empty(0); const auto& entries = m_deps->get_entries(asset_type); @@ -536,7 +550,7 @@ void deps_resolver_t::resolve_probe_dirs( m_api_set_paths.insert(result_dir); } - add_unique_path(asset_type, result_dir, &items, output); + add_unique_path(asset_type, result_dir, &items, output, &non_serviced, core_servicing); } }; std::for_each(entries.begin(), entries.end(), add_package_cache_entry); @@ -551,7 +565,7 @@ void deps_resolver_t::resolve_probe_dirs( { if (entry.is_rid_specific && entry.asset_type == asset_type && entry.to_rel_path(m_app_dir, &candidate)) { - add_unique_path(asset_type, action(candidate), &items, output); + add_unique_path(asset_type, action(candidate), &items, output, &non_serviced, core_servicing); } // App called out an explicit API set dependency. @@ -566,7 +580,7 @@ void deps_resolver_t::resolve_probe_dirs( track_api_sets = m_api_set_paths.empty(); // App local path - add_unique_path(asset_type, m_app_dir, &items, output); + add_unique_path(asset_type, m_app_dir, &items, output, &non_serviced, core_servicing); // If API sets is not found (i.e., empty) in the probe paths above: // 1. For standalone app, do nothing as all are sxs. @@ -581,11 +595,13 @@ void deps_resolver_t::resolve_probe_dirs( { m_api_set_paths.insert(m_fx_dir); } - add_unique_path(asset_type, m_fx_dir, &items, output); + add_unique_path(asset_type, m_fx_dir, &items, output, &non_serviced, core_servicing); } // CLR path - add_unique_path(asset_type, clr_dir, &items, output); + add_unique_path(asset_type, clr_dir, &items, output, &non_serviced, core_servicing); + + output->append(non_serviced); } diff --git a/src/corehost/cli/deps_resolver.h b/src/corehost/cli/deps_resolver.h index 2640d1612..05edf945f 100644 --- a/src/corehost/cli/deps_resolver.h +++ b/src/corehost/cli/deps_resolver.h @@ -31,6 +31,7 @@ public: , m_portable(init.is_portable) , m_deps(nullptr) , m_fx_deps(nullptr) + , m_core_servicing(args.core_servicing) { m_deps_file = args.deps_path; if (m_portable) @@ -150,6 +151,9 @@ private: pal::string_t m_package_cache; + // Servicing root, could be empty on platforms that don't support or when errors occur. + pal::string_t m_core_servicing; + // Special entry for api-sets std::unordered_set m_api_set_paths; diff --git a/src/corehost/common/utils.cpp b/src/corehost/common/utils.cpp index 7c11f830b..60488607e 100644 --- a/src/corehost/common/utils.cpp +++ b/src/corehost/common/utils.cpp @@ -37,6 +37,11 @@ bool ends_with(const pal::string_t& value, const pal::string_t& suffix, bool mat bool starts_with(const pal::string_t& value, const pal::string_t& prefix, bool match_case) { + if (prefix.empty()) + { + // Cannot start with an empty string. + return false; + } auto cmp = match_case ? pal::strncmp : pal::strncasecmp; return (value.size() >= prefix.size()) && cmp(value.c_str(), prefix.c_str(), prefix.size()) == 0;