Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow runtimeconfig StartupHooks and Environment StartupHooks to both be present #61461

Merged
merged 4 commits into from
Nov 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions src/installer/tests/HostActivation.Tests/StartupHooks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class StartupHooks : IClassFixture<StartupHooks.SharedTestState>
{
private SharedTestState sharedTestState;
private string startupHookVarName = "DOTNET_STARTUP_HOOKS";
private string startupHookRuntimeConfigName = "STARTUP_HOOKS";
private string startupHookSupport = "System.StartupHookProvider.IsSupported";

public StartupHooks(StartupHooks.SharedTestState fixture)
Expand Down Expand Up @@ -105,6 +106,59 @@ public void Muxer_activation_of_Multiple_StartupHooks_Succeeds()
.And.HaveStdOutContaining("Hello World");
}

[Fact]
public void Muxer_activation_of_RuntimeConfig_StartupHook_Succeeds()
{
var fixture = sharedTestState.PortableAppFixture.Copy();
var dotnet = fixture.BuiltDotnet;
var appDll = fixture.TestProject.AppDll;

var startupHookFixture = sharedTestState.StartupHookFixture.Copy();
var startupHookDll = startupHookFixture.TestProject.AppDll;

RuntimeConfig.FromFile(fixture.TestProject.RuntimeConfigJson)
.WithProperty(startupHookRuntimeConfigName, startupHookDll)
.Save();

// RuntimeConfig defined startup hook
dotnet.Exec(appDll)
.CaptureStdOut()
.CaptureStdErr()
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello from startup hook!")
.And.HaveStdOutContaining("Hello World");
}

[Fact]
public void Muxer_activation_of_RuntimeConfig_And_Environment_StartupHooks_Succeeds()
{
var fixture = sharedTestState.PortableAppFixture.Copy();
var dotnet = fixture.BuiltDotnet;
var appDll = fixture.TestProject.AppDll;

var startupHookFixture = sharedTestState.StartupHookFixture.Copy();
var startupHookDll = startupHookFixture.TestProject.AppDll;

RuntimeConfig.FromFile(fixture.TestProject.RuntimeConfigJson)
.WithProperty(startupHookRuntimeConfigName, startupHookDll)
.Save();

var startupHook2Fixture = sharedTestState.StartupHookWithDependencyFixture.Copy();
var startupHook2Dll = startupHook2Fixture.TestProject.AppDll;

// RuntimeConfig and Environment startup hook
dotnet.Exec(appDll)
.EnvironmentVariable(startupHookVarName, startupHook2Dll)
.CaptureStdOut()
.CaptureStdErr()
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello from startup hook!")
.And.HaveStdOutContaining("Hello from startup hook with dependency!")
.And.HaveStdOutContaining("Hello World");
}

// Empty startup hook variable
[Fact]
public void Muxer_activation_of_Empty_StartupHook_Variable_Succeeds()
Expand Down
15 changes: 9 additions & 6 deletions src/native/corehost/hostpolicy/hostpolicy_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,14 @@ int hostpolicy_context_t::initialize(hostpolicy_init_t &hostpolicy_init, const a
pal::string_t startup_hooks;
if (pal::getenv(_X("DOTNET_STARTUP_HOOKS"), &startup_hooks))
{
if (!coreclr_properties.add(common_property::StartUpHooks, startup_hooks.c_str()))
const pal::char_t *config_startup_hooks;
if (coreclr_properties.try_get(common_property::StartUpHooks, &config_startup_hooks))
{
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::StartUpHooks));
return StatusCode::LibHostDuplicateProperty;
startup_hooks.push_back(PATH_SEPARATOR);
startup_hooks.append(config_startup_hooks);
}

coreclr_properties.add(common_property::StartUpHooks, startup_hooks.c_str());
}

// Single-File Bundle Probe
Expand All @@ -297,7 +300,7 @@ int hostpolicy_context_t::initialize(hostpolicy_init_t &hostpolicy_init, const a

if (!coreclr_properties.add(common_property::BundleProbe, ptr_stream.str().c_str()))
{
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::StartUpHooks));
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::BundleProbe));
tomdegoede marked this conversation as resolved.
Show resolved Hide resolved
return StatusCode::LibHostDuplicateProperty;
}
}
Expand All @@ -312,7 +315,7 @@ int hostpolicy_context_t::initialize(hostpolicy_init_t &hostpolicy_init, const a

if (!coreclr_properties.add(common_property::PInvokeOverride, ptr_stream.str().c_str()))
{
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::StartUpHooks));
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::PInvokeOverride));
return StatusCode::LibHostDuplicateProperty;
}
}
Expand All @@ -321,7 +324,7 @@ int hostpolicy_context_t::initialize(hostpolicy_init_t &hostpolicy_init, const a
#if defined(HOSTPOLICY_EMBEDDED)
if (!coreclr_properties.add(common_property::HostPolicyEmbedded, _X("true")))
{
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::StartUpHooks));
log_duplicate_property_error(coreclr_property_bag_t::common_property_to_string(common_property::HostPolicyEmbedded));
return StatusCode::LibHostDuplicateProperty;
}
#endif
Expand Down