From 6a5ce95c4a386cc7a303790fc01602d4e3f26a18 Mon Sep 17 00:00:00 2001 From: Steve Harter Date: Thu, 1 Mar 2018 14:31:08 -0600 Subject: [PATCH] Fail when additional deps files are not valid and revert to 2.0.x roll-forward to use requested version instead of found (dotnet/core-setup#3743) Commit migrated from https://github.com/dotnet/core-setup/commit/33faff7395812843eda06316af3518d215fa345e --- src/installer/corehost/cli/deps_format.cpp | 1 + src/installer/corehost/cli/deps_format.h | 7 ++++ src/installer/corehost/cli/deps_resolver.cpp | 4 +- src/installer/corehost/cli/deps_resolver.h | 9 +++++ src/installer/corehost/cli/libhost.h | 2 +- .../GivenThatICareAboutMultilevelSharedFxLookup.cs | 43 ++++++++++++++++++++++ 6 files changed, 63 insertions(+), 3 deletions(-) diff --git a/src/installer/corehost/cli/deps_format.cpp b/src/installer/corehost/cli/deps_format.cpp index 59c1a4b..192ea0a 100644 --- a/src/installer/corehost/cli/deps_format.cpp +++ b/src/installer/corehost/cli/deps_format.cpp @@ -440,6 +440,7 @@ bool deps_json_t::has_package(const pal::string_t& name, const pal::string_t& ve // bool deps_json_t::load(bool portable, const pal::string_t& deps_path, const rid_fallback_graph_t& rid_fallback_graph) { + m_deps_file = deps_path; m_file_exists = pal::file_exists(deps_path); // If file doesn't exist, then assume parsed. diff --git a/src/installer/corehost/cli/deps_format.h b/src/installer/corehost/cli/deps_format.h index f98d4db..c877227 100644 --- a/src/installer/corehost/cli/deps_format.h +++ b/src/installer/corehost/cli/deps_format.h @@ -79,6 +79,11 @@ public: const deps_entry_t& try_ni(const deps_entry_t& entry) const; + pal::string_t get_deps_file() const + { + return m_deps_file; + } + private: bool load_standalone(const pal::string_t& deps_path, const json_value& json, const pal::string_t& target_name); bool load_portable(const pal::string_t& deps_path, const json_value& json, const pal::string_t& target_name, const rid_fallback_graph_t& rid_fallback_graph); @@ -107,6 +112,8 @@ private: rid_fallback_graph_t m_rid_fallback_graph; bool m_file_exists; bool m_valid; + + pal::string_t m_deps_file; }; #endif // __DEPS_FORMAT_H_ diff --git a/src/installer/corehost/cli/deps_resolver.cpp b/src/installer/corehost/cli/deps_resolver.cpp index 13b4a35..bb9c37c 100644 --- a/src/installer/corehost/cli/deps_resolver.cpp +++ b/src/installer/corehost/cli/deps_resolver.cpp @@ -632,11 +632,11 @@ void deps_resolver_t::resolve_additional_deps(const hostpolicy_init_t& init) { for (int i = 1; i < m_fx_definitions.size(); ++i) { - // We'll search deps files in 'base_dir'/shared/fx_name/fx_ver + // We'll search deps files in 'base_dir'/shared/fx_name/fx_requested_ver pal::string_t additional_deps_path_fx = additional_deps_path; append_path(&additional_deps_path_fx, _X("shared")); append_path(&additional_deps_path_fx, m_fx_definitions[i]->get_name().c_str()); - append_path(&additional_deps_path_fx, m_fx_definitions[i]->get_found_version().c_str()); + append_path(&additional_deps_path_fx, m_fx_definitions[i]->get_requested_version().c_str()); // Use requested version as that is what the app deployed with // The resulting list will be empty if 'additional_deps_path_fx' is not a valid directory path std::vector list; diff --git a/src/installer/corehost/cli/deps_resolver.h b/src/installer/corehost/cli/deps_resolver.h index 796a5a6..3067c74 100644 --- a/src/installer/corehost/cli/deps_resolver.h +++ b/src/installer/corehost/cli/deps_resolver.h @@ -100,6 +100,15 @@ public: } } + for (const auto& additional_deps : m_additional_deps) + { + if (!additional_deps->is_valid()) + { + errors->assign(_X("An error occurred while parsing: ") + additional_deps->get_deps_file()); + return false; + } + } + errors->clear(); return true; } diff --git a/src/installer/corehost/cli/libhost.h b/src/installer/corehost/cli/libhost.h index c18c61e..5be16db 100644 --- a/src/installer/corehost/cli/libhost.h +++ b/src/installer/corehost/cli/libhost.h @@ -191,7 +191,7 @@ public: { hi.fx_name = m_fx_names_cstr[1]; hi.fx_dir = m_fx_dirs_cstr[1]; - hi.fx_ver = m_fx_found_versions_cstr[1]; + hi.fx_ver = m_fx_requested_versions_cstr[1]; } else { diff --git a/src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSharedFxLookup.cs b/src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSharedFxLookup.cs index 5799695..a027d16 100644 --- a/src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSharedFxLookup.cs +++ b/src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSharedFxLookup.cs @@ -980,6 +980,49 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.MultilevelSharedFxLooku DeleteAvailableSharedFxVersions(_exeSharedUberFxBaseDir, "7777.0.0"); } + [Fact] + public void Additional_Deps_Lightup_Folder_With_Roll_Forward_And_Bad_JsonFile() + { + var fixture = PreviouslyBuiltAndRestoredPortableTestProjectFixture + .Copy(); + + var dotnet = fixture.BuiltDotnet; + var appDll = fixture.TestProject.AppDll; + + // Add version in the exe folder + AddAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.0.1"); + + // Set desired version = 9999.0.0 + string runtimeConfig = Path.Combine(fixture.TestProject.OutputDirectory, "SharedFxLookupPortableApp.runtimeconfig.json"); + SetRuntimeConfigJson(runtimeConfig, "9999.0.0"); + + // Create a deps.json file in the folder "additionalDeps\shared\Microsoft.NETCore.App\9999.0.0" + string additionalDepsRootPath = Path.Combine(_exeSharedFxBaseDir, "additionalDeps"); + string additionalDepsPath = Path.Combine(additionalDepsRootPath, "shared", "Microsoft.NETCore.App", "9999.0.0", "myAddtionalDeps.deps.json"); + FileInfo additionalDepsFile = new FileInfo(additionalDepsPath); + additionalDepsFile.Directory.Create(); + File.WriteAllText(additionalDepsFile.FullName, "THIS IS A BAD JSON FILE"); + + // Version: NetCoreApp 9999.0.0 + // Exe: NetCoreApp 9999.0.1 + // Expected: 9999.0.1 + // Expected: the "specified" location (9999.0.0) is used to find the lightup folder, not the "found" location (9999.0.1) + dotnet.Exec("exec", "--additional-deps", additionalDepsRootPath, appDll) + .WorkingDirectory(_currentWorkingDir) + .EnvironmentVariable("COREHOST_TRACE", "1") + .CaptureStdOut() + .CaptureStdErr() + .Execute() + .Should() + .Fail() + .And + .HaveStdErrContaining(Path.Combine(_exeSelectedMessage, "9999.0.1")) + .And + .HaveStdErrContaining($"Error initializing the dependency resolver: An error occurred while parsing: {additionalDepsPath}"); + + DeleteAvailableSharedFxVersions(_exeSharedFxBaseDir, "9999.0.1", "additionalDeps"); + } + // This method adds a list of new framework version folders in the specified // sharedFxBaseDir. The files are copied from the _buildSharedFxDir. // Remarks: -- 2.7.4