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

Add runtime property HOSTFXR_PATH #55369

Merged
merged 5 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ public static void Main(string[] args)

foreach (string propertyName in args)
{
var propertyValue = (string)System.AppContext.GetData(propertyName);
if (string.IsNullOrEmpty(propertyValue))
{
Console.WriteLine($"Property '{propertyName}' was not found.");
continue;
}

Console.WriteLine($"AppContext.GetData({propertyName}) = {System.AppContext.GetData(propertyName)}");
elinor-fung marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
32 changes: 20 additions & 12 deletions src/installer/tests/HostActivation.Tests/RuntimeProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public void AppConfigProperty_AppCanGetData()
var dotnet = fixture.BuiltDotnet;
var appDll = fixture.TestProject.AppDll;
dotnet.Exec(appDll, sharedState.AppTestPropertyName)
.EnvironmentVariable("COREHOST_TRACE", "1")
.CaptureStdErr()
.CaptureStdOut()
.EnableTracingAndCaptureOutputs()
.Execute()
.Should().Pass()
.And.HaveStdErrContaining($"Property {sharedState.AppTestPropertyName} = {sharedState.AppTestPropertyValue}")
Expand All @@ -43,9 +41,7 @@ public void FrameworkConfigProperty_AppCanGetData()
var dotnet = fixture.BuiltDotnet;
var appDll = fixture.TestProject.AppDll;
dotnet.Exec(appDll, sharedState.FrameworkTestPropertyName)
.EnvironmentVariable("COREHOST_TRACE", "1")
.CaptureStdErr()
.CaptureStdOut()
.EnableTracingAndCaptureOutputs()
.Execute()
.Should().Pass()
.And.HaveStdErrContaining($"Property {sharedState.FrameworkTestPropertyName} = {sharedState.FrameworkTestPropertyValue}")
Expand All @@ -65,15 +61,28 @@ public void DuplicateConfigProperty_AppConfigValueUsed()
var dotnet = fixture.BuiltDotnet;
var appDll = fixture.TestProject.AppDll;
dotnet.Exec(appDll, sharedState.FrameworkTestPropertyName)
.EnvironmentVariable("COREHOST_TRACE", "1")
.CaptureStdErr()
.CaptureStdOut()
.EnableTracingAndCaptureOutputs()
.Execute()
.Should().Pass()
.And.HaveStdErrContaining($"Property {sharedState.FrameworkTestPropertyName} = {sharedState.AppTestPropertyValue}")
.And.HaveStdOutContaining($"AppContext.GetData({sharedState.FrameworkTestPropertyName}) = {sharedState.AppTestPropertyValue}");
}

[Fact]
public void HostFxrPathProperty_NotVisibleFromApp()
{
var fixture = sharedState.RuntimePropertiesFixture
.Copy();

var dotnet = fixture.BuiltDotnet;
var appDll = fixture.TestProject.AppDll;
dotnet.Exec(appDll, sharedState.HostFxrPathPropertyName)
.EnableTracingAndCaptureOutputs()
.Execute()
.Should().Pass()
.And.HaveStdOutContaining($"Property '{sharedState.HostFxrPathPropertyName}' was not found.");
}

[Fact]
public void DuplicateCommonProperty_Fails()
{
Expand All @@ -88,9 +97,7 @@ public void DuplicateCommonProperty_Fails()
var dotnet = fixture.BuiltDotnet;
var appDll = fixture.TestProject.AppDll;
dotnet.Exec(appDll)
.EnvironmentVariable("COREHOST_TRACE", "1")
.CaptureStdErr()
.CaptureStdOut()
.EnableTracingAndCaptureOutputs()
.Execute()
.Should().Fail()
.And.HaveStdErrContaining($"Duplicate runtime property found: {name}");
Expand All @@ -105,6 +112,7 @@ public class SharedTestState : IDisposable
public string AppTestPropertyValue => "VALUE_FROM_APP";
public string FrameworkTestPropertyName => "FRAMEWORK_TEST_PROPERTY";
public string FrameworkTestPropertyValue => "VALUE_FROM_FRAMEWORK";
public string HostFxrPathPropertyName => "HOSTFXR_PATH";

private readonly string copiedDotnet;

Expand Down
3 changes: 2 additions & 1 deletion src/native/corehost/hostpolicy/coreclr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ namespace
_X("RUNTIME_IDENTIFIER"),
_X("BUNDLE_PROBE"),
_X("HOSTPOLICY_EMBEDDED"),
_X("PINVOKE_OVERRIDE")
_X("PINVOKE_OVERRIDE"),
_X("HOSTFXR_PATH")
};

static_assert((sizeof(PropertyNameMapping) / sizeof(*PropertyNameMapping)) == static_cast<size_t>(common_property::Last), "Invalid property count");
Expand Down
1 change: 1 addition & 0 deletions src/native/corehost/hostpolicy/coreclr.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ enum class common_property
BundleProbe,
HostPolicyEmbedded,
PInvokeOverride,
HostFxrPath,
// Sentinel value - new values should be defined above
Last
};
Expand Down
10 changes: 10 additions & 0 deletions src/native/corehost/hostpolicy/hostpolicy_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,16 @@ int hostpolicy_context_t::initialize(hostpolicy_init_t &hostpolicy_init, const a
}
}

// We pass the loaded hostfxr path to the SDK can load it without relying on dlopen/LoadLibrary to find it.
if (host_mode == host_mode_t::muxer &&
(pal::strcmp(get_filename(application).c_str(), _X("dotnet.dll")) == 0))
elinor-fung marked this conversation as resolved.
Show resolved Hide resolved
{
pal::dll_t fxr;
pal::string_t fxr_path;
pal::get_loaded_library(LIBFXR_NAME, "hostfxr_main", &fxr, &fxr_path);
coreclr_properties.add(common_property::HostFxrPath, fxr_path.c_str());
elinor-fung marked this conversation as resolved.
Show resolved Hide resolved
}

#if defined(NATIVE_LIBS_EMBEDDED)
// PInvoke Override
if (bundle::info_t::is_single_file_bundle())
Expand Down