Fail when additional deps files are not valid and revert to 2.0.x roll-forward to...
authorSteve Harter <steveharter@users.noreply.github.com>
Thu, 1 Mar 2018 20:31:08 +0000 (14:31 -0600)
committerGitHub <noreply@github.com>
Thu, 1 Mar 2018 20:31:08 +0000 (14:31 -0600)
Commit migrated from https://github.com/dotnet/core-setup/commit/33faff7395812843eda06316af3518d215fa345e

src/installer/corehost/cli/deps_format.cpp
src/installer/corehost/cli/deps_format.h
src/installer/corehost/cli/deps_resolver.cpp
src/installer/corehost/cli/deps_resolver.h
src/installer/corehost/cli/libhost.h
src/installer/test/HostActivationTests/GivenThatICareAboutMultilevelSharedFxLookup.cs

index 59c1a4b..192ea0a 100644 (file)
@@ -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.
index f98d4db..c877227 100644 (file)
@@ -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_
index 13b4a35..bb9c37c 100644 (file)
@@ -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<pal::string_t> list;
index 796a5a6..3067c74 100644 (file)
@@ -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;
     }
index c18c61e..5be16db 100644 (file)
@@ -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
         {
index 5799695..a027d16 100644 (file)
@@ -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: