From 01a8bef3766572e04108b35b12564f9ce986ebae Mon Sep 17 00:00:00 2001 From: Mateo Torres-Ruiz Date: Fri, 28 Aug 2020 13:57:39 -0700 Subject: [PATCH] Do not add bundle deps file to APP_CONTEXT_DEPS_FILES on single-file apps (#41430) * App Context deps file should be empty for single file apps --- .../corehost/cli/hostpolicy/deps_resolver.cpp | 9 +++++---- src/installer/corehost/cli/hostpolicy/deps_resolver.h | 2 +- .../corehost/cli/hostpolicy/hostpolicy_context.cpp | 2 +- .../Assets/TestProjects/SingleFileApiTests/Program.cs | 5 +++++ .../NativeHosting/GetFunctionPointer.cs | 4 ++-- .../NativeHosting/LoadAssemblyAndGetFunctionPointer.cs | 2 +- .../AppHost.Bundle.Tests/SingleFileApiTests.cs | 18 ++++++++++++++++++ src/installer/tests/TestUtils/TestProjectFixture.cs | 4 ++-- 8 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/installer/corehost/cli/hostpolicy/deps_resolver.cpp b/src/installer/corehost/cli/hostpolicy/deps_resolver.cpp index 21c06a5..04ef9c7 100644 --- a/src/installer/corehost/cli/hostpolicy/deps_resolver.cpp +++ b/src/installer/corehost/cli/hostpolicy/deps_resolver.cpp @@ -729,18 +729,19 @@ void deps_resolver_t::resolve_additional_deps(const arguments_t& args, const dep } } -void deps_resolver_t::get_app_fx_definition_range(fx_definition_vector_t::iterator *begin, fx_definition_vector_t::iterator *end) const +void deps_resolver_t::get_app_context_deps_files_range(fx_definition_vector_t::iterator *begin, fx_definition_vector_t::iterator *end) const { assert(begin != nullptr && end != nullptr); auto begin_iter = m_fx_definitions.begin(); auto end_iter = m_fx_definitions.end(); - if (m_host_mode == host_mode_t::libhost + if ((m_host_mode == host_mode_t::libhost || bundle::info_t::is_single_file_bundle()) && begin_iter != end_iter) { - // In a libhost scenario the app definition shouldn't be - // included in the creation of the application. + // Neither in a libhost scenario nor in a bundled app + // the deps files should be exposed in the app context + // properties. assert(begin_iter->get() == &get_app(m_fx_definitions)); ++begin_iter; } diff --git a/src/installer/corehost/cli/hostpolicy/deps_resolver.h b/src/installer/corehost/cli/hostpolicy/deps_resolver.h index 6798a50..9bc7c8c 100644 --- a/src/installer/corehost/cli/hostpolicy/deps_resolver.h +++ b/src/installer/corehost/cli/hostpolicy/deps_resolver.h @@ -160,7 +160,7 @@ public: return get_app(m_fx_definitions).get_deps_file(); } - void get_app_fx_definition_range(fx_definition_vector_t::iterator *begin, fx_definition_vector_t::iterator *end) const; + void get_app_context_deps_files_range(fx_definition_vector_t::iterator *begin, fx_definition_vector_t::iterator *end) const; const fx_definition_vector_t& get_fx_definitions() const { diff --git a/src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp b/src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp index f7daa5d..ee8ad42 100644 --- a/src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp +++ b/src/installer/corehost/cli/hostpolicy/hostpolicy_context.cpp @@ -152,7 +152,7 @@ int hostpolicy_context_t::initialize(hostpolicy_init_t &hostpolicy_init, const a fx_definition_vector_t::iterator fx_begin; fx_definition_vector_t::iterator fx_end; - resolver.get_app_fx_definition_range(&fx_begin, &fx_end); + resolver.get_app_context_deps_files_range(&fx_begin, &fx_end); pal::string_t app_context_deps_str; fx_definition_vector_t::iterator fx_curr = fx_begin; diff --git a/src/installer/tests/Assets/TestProjects/SingleFileApiTests/Program.cs b/src/installer/tests/Assets/TestProjects/SingleFileApiTests/Program.cs index 7b4ed44..e5ed680 100644 --- a/src/installer/tests/Assets/TestProjects/SingleFileApiTests/Program.cs +++ b/src/installer/tests/Assets/TestProjects/SingleFileApiTests/Program.cs @@ -31,6 +31,11 @@ namespace SingleFileApiTests return; } break; + + case "appcontext": + var deps_files = AppContext.GetData("APP_CONTEXT_DEPS_FILES"); + Console.WriteLine("APP_CONTEXT_DEPS_FILES: " + deps_files); + return; } Console.WriteLine("test failure"); diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/GetFunctionPointer.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/GetFunctionPointer.cs index 150943d..4ddfc2f 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/GetFunctionPointer.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/GetFunctionPointer.cs @@ -232,13 +232,13 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting ApplicationFixture = new TestProjectFixture("AppWithCustomEntryPoints", RepoDirectories) .EnsureRestored(RepoDirectories.CorehostPackages) - .PublishProject(selfContained: "false"); + .PublishProject(selfContained: false); ComponentWithNoDependenciesFixture = new TestProjectFixture("ComponentWithNoDependencies", RepoDirectories) .EnsureRestored(RepoDirectories.CorehostPackages) .PublishProject(); SelfContainedApplicationFixture = new TestProjectFixture("AppWithCustomEntryPoints", RepoDirectories) .EnsureRestored(RepoDirectories.CorehostPackages) - .PublishProject(selfContained: "true"); + .PublishProject(selfContained: true); ComponentTypeName = $"Component.Component, {ComponentWithNoDependenciesFixture.TestProject.AssemblyName}"; FunctionPointerTypeName = $"AppWithCustomEntryPoints.Program, {ApplicationFixture.TestProject.AssemblyName}"; } diff --git a/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs b/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs index 4b70a88..48ceea8 100644 --- a/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs +++ b/src/installer/tests/HostActivation.Tests/NativeHosting/LoadAssemblyAndGetFunctionPointer.cs @@ -255,7 +255,7 @@ namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.NativeHosting .PublishProject(); SelfContainedApplicationFixture = new TestProjectFixture("StandaloneApp", RepoDirectories) .EnsureRestored(RepoDirectories.CorehostPackages) - .PublishProject(selfContained: "true"); + .PublishProject(selfContained: true); ComponentTypeName = $"Component.Component, {ComponentWithNoDependenciesFixture.TestProject.AssemblyName}"; } diff --git a/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/SingleFileApiTests.cs b/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/SingleFileApiTests.cs index ece250d..5d5f6b8 100644 --- a/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/SingleFileApiTests.cs +++ b/src/installer/tests/Microsoft.NET.HostModel.Tests/AppHost.Bundle.Tests/SingleFileApiTests.cs @@ -50,6 +50,24 @@ namespace AppHost.Bundle.Tests } [Fact] + public void AppContext_Deps_Files_Bundled_Self_Contained() + { + var fixture = sharedTestState.TestFixture.Copy(); + var singleFile = BundleHelper.BundleApp(fixture); + + Command.Create(singleFile, "appcontext") + .CaptureStdErr() + .CaptureStdOut() + .Execute() + .Should() + .Pass() + .And + .NotHaveStdOutContaining("SingleFileApiTests.deps.json") + .And + .NotHaveStdOutContaining("Microsoft.NETCore.App.deps.json"); + } + + [Fact] public void GetEnvironmentArgs_0_Returns_Bundled_Executable_Path() { var fixture = sharedTestState.TestFixture.Copy(); diff --git a/src/installer/tests/TestUtils/TestProjectFixture.cs b/src/installer/tests/TestUtils/TestProjectFixture.cs index 2b03d2b..25574f3 100644 --- a/src/installer/tests/TestUtils/TestProjectFixture.cs +++ b/src/installer/tests/TestUtils/TestProjectFixture.cs @@ -254,7 +254,7 @@ namespace Microsoft.DotNet.CoreSetup.Test DotNetCli dotnet = null, string runtime = null, string framework = null, - string selfContained = null, + bool? selfContained = null, string outputDirectory = null, bool singleFile = false, bool restore = false) @@ -291,7 +291,7 @@ namespace Microsoft.DotNet.CoreSetup.Test if (selfContained != null) { publishArgs.Add("--self-contained"); - publishArgs.Add(selfContained); + publishArgs.Add(selfContained.Value ? "true" : "false"); } if (outputDirectory != null) -- 2.7.4