Skip to content

Commit

Permalink
[release/5.0] Do not add bundle deps file to APP_CONTEXT_DEPS_FILES o…
Browse files Browse the repository at this point in the history
…n single-file apps (#41624)

* App Context deps file should be empty for single file apps
  • Loading branch information
github-actions[bot] authored Aug 31, 2020
1 parent 6b1b038 commit 3bcbbd5
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 11 deletions.
9 changes: 5 additions & 4 deletions src/installer/corehost/cli/hostpolicy/deps_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/installer/corehost/cli/hostpolicy/deps_resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class deps_resolver_t
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
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ public static void Main(string[] args)
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,13 +232,13 @@ public SharedTestState()

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}";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public SharedTestState()
.PublishProject();
SelfContainedApplicationFixture = new TestProjectFixture("StandaloneApp", RepoDirectories)
.EnsureRestored(RepoDirectories.CorehostPackages)
.PublishProject(selfContained: "true");
.PublishProject(selfContained: true);
ComponentTypeName = $"Component.Component, {ComponentWithNoDependenciesFixture.TestProject.AssemblyName}";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ public void CodeBaseThrows()
.HaveStdOutContaining("CodeBase NotSupported");
}

[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()
{
Expand Down
4 changes: 2 additions & 2 deletions src/installer/tests/TestUtils/TestProjectFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public TestProjectFixture PublishProject(
DotNetCli dotnet = null,
string runtime = null,
string framework = null,
string selfContained = null,
bool? selfContained = null,
string outputDirectory = null,
bool singleFile = false,
bool restore = false)
Expand Down Expand Up @@ -291,7 +291,7 @@ public TestProjectFixture PublishProject(
if (selfContained != null)
{
publishArgs.Add("--self-contained");
publishArgs.Add(selfContained);
publishArgs.Add(selfContained.Value ? "true" : "false");
}

if (outputDirectory != null)
Expand Down

0 comments on commit 3bcbbd5

Please sign in to comment.