Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
PR feedback
  • Loading branch information
Mateo Torres Ruiz committed Jul 9, 2021
commit fe17786981d9c652617f15d5217e31284523b110
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static void Main(string[] args)
continue;
}

Console.WriteLine($"AppContext.GetData({propertyName}) = {System.AppContext.GetData(propertyName)}");
Console.WriteLine($"AppContext.GetData({propertyName}) = {propertyValue}");
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/installer/tests/HostActivation.Tests/DotNetBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,22 @@ public DotNetBuilder AddFramework(
return this;
}

public DotNetBuilder AddMockSDK(
string version,
string MNAVersion)
{
string path = Path.Combine(_path, "sdk", version);
Directory.CreateDirectory(path);

File.Create(Path.Combine(path, "dotnet.dll"));

RuntimeConfig dotnetRuntimeConfig = new RuntimeConfig(Path.Combine(path, "dotnet.runtimeconfig.json"));
dotnetRuntimeConfig.WithFramework(new RuntimeConfig.Framework("Microsoft.NETCore.App", MNAVersion));
dotnetRuntimeConfig.Save();

return this;
}

public DotNetCli Build()
{
return new DotNetCli(_path);
Expand Down
26 changes: 26 additions & 0 deletions src/installer/tests/HostActivation.Tests/RuntimeProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System;
using System.IO;
using Microsoft.DotNet.Cli.Build;
using Xunit;

namespace Microsoft.DotNet.CoreSetup.Test.HostActivation
Expand Down Expand Up @@ -68,6 +69,17 @@ public void DuplicateConfigProperty_AppConfigValueUsed()
.And.HaveStdOutContaining($"AppContext.GetData({sharedState.FrameworkTestPropertyName}) = {sharedState.AppTestPropertyValue}");
}

[Fact]
public void HostFxrPathProperty_SetWhenRunningSDKCommand()
{
var dotnet = sharedState.MockSDK;
dotnet.Exec("--info")
.EnableTracingAndCaptureOutputs()
.Execute()
.Should().Pass()
.And.HaveStdErrContaining($"Property {sharedState.HostFxrPathPropertyName} = {dotnet.GreatestVersionHostFxrFilePath}");
}

[Fact]
public void HostFxrPathProperty_NotVisibleFromApp()
{
Expand Down Expand Up @@ -107,6 +119,7 @@ public class SharedTestState : IDisposable
{
public TestProjectFixture RuntimePropertiesFixture { get; }
public RepoDirectoriesProvider RepoDirectories { get; }
public DotNetCli MockSDK { get; }

public string AppTestPropertyName => "APP_TEST_PROPERTY";
public string AppTestPropertyValue => "VALUE_FROM_APP";
Expand All @@ -121,6 +134,19 @@ public SharedTestState()
copiedDotnet = Path.Combine(TestArtifact.TestArtifactsPath, "runtimeProperties");
SharedFramework.CopyDirectory(Path.Combine(TestArtifact.TestArtifactsPath, "sharedFrameworkPublish"), copiedDotnet);

MockSDK = new DotNetBuilder(copiedDotnet, Path.Combine(TestArtifact.TestArtifactsPath, "sharedFrameworkPublish"), "exe")
.AddMicrosoftNETCoreAppFrameworkMockCoreClr("9999.0.0")
.AddMockSDK("9999.0.0-dev", "9999.0.0")
.Build();

File.WriteAllText(Path.Combine(MockSDK.BinPath, "global.json"),
@"
{
""sdk"": {
""version"": ""9999.0.0-dev""
}
}");

RepoDirectories = new RepoDirectoriesProvider(builtDotnet: copiedDotnet);

RuntimePropertiesFixture = new TestProjectFixture("RuntimeProperties", RepoDirectories)
Expand Down
9 changes: 8 additions & 1 deletion src/native/corehost/fxr/corehost_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ corehost_init_t::corehost_init_t(
const pal::string_t& additional_deps_serialized,
const std::vector<pal::string_t>& probe_paths,
const host_mode_t mode,
const fx_definition_vector_t& fx_definitions)
const fx_definition_vector_t& fx_definitions,
const std::vector<std::pair<pal::string_t, pal::string_t>>& additional_properties)
: m_tfm(get_app(fx_definitions).get_runtime_config().get_tfm())
, m_deps_file(deps_file)
, m_additional_deps_serialized(additional_deps_serialized)
Expand All @@ -35,6 +36,12 @@ corehost_init_t::corehost_init_t(
{
make_cstr_arr(m_probe_paths, &m_probe_paths_cstr);

for (const auto& additional_property : additional_properties)
{
m_clr_keys.push_back(additional_property.first);
m_clr_values.push_back(additional_property.second);
}

size_t fx_count = fx_definitions.size();
m_fx_names.reserve(fx_count);
m_fx_dirs.reserve(fx_count);
Expand Down
3 changes: 2 additions & 1 deletion src/native/corehost/fxr/corehost_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ class corehost_init_t
const pal::string_t& additional_deps_serialized,
const std::vector<pal::string_t>& probe_paths,
const host_mode_t mode,
const fx_definition_vector_t& fx_definitions);
const fx_definition_vector_t& fx_definitions,
const std::vector<std::pair<pal::string_t, pal::string_t>>& additional_properties);

const host_interface_t& get_host_init_data();

Expand Down
24 changes: 22 additions & 2 deletions src/native/corehost/fxr/fx_muxer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ namespace
const pal::string_t &app_candidate,
const opt_map_t &opts,
host_mode_t mode,
const bool is_sdk_command,
/*out*/ pal::string_t &hostpolicy_dir,
/*out*/ std::unique_ptr<corehost_init_t> &init)
{
Expand Down Expand Up @@ -473,6 +474,17 @@ namespace
}
}

std::vector<std::pair<pal::string_t, pal::string_t>> additional_properties;
if (is_sdk_command)
{
pal::dll_t fxr;
pal::string_t fxr_path;
pal::get_loaded_library(LIBFXR_NAME, "hostfxr_main", &fxr, &fxr_path);

// We pass the loaded hostfxr path to the SDK can load it without relying on dlopen/LoadLibrary to find it.
additional_properties.push_back(std::make_pair(_X("HOSTFXR_PATH"), fxr_path));
}

const known_options opts_probe_path = known_options::additional_probing_path;
std::vector<pal::string_t> spec_probe_paths = opts.count(opts_probe_path) ? opts.find(opts_probe_path)->second : std::vector<pal::string_t>();
std::vector<pal::string_t> probe_realpaths = get_probe_realpaths(fx_definitions, spec_probe_paths);
Expand All @@ -485,7 +497,7 @@ namespace
return StatusCode::CoreHostLibMissingFailure;
}

init.reset(new corehost_init_t(host_command, host_info, deps_file, additional_deps_serialized, probe_realpaths, mode, fx_definitions));
init.reset(new corehost_init_t(host_command, host_info, deps_file, additional_deps_serialized, probe_realpaths, mode, fx_definitions, additional_properties));

return StatusCode::Success;
}
Expand All @@ -498,6 +510,7 @@ namespace
int new_argc,
const pal::char_t** new_argv,
host_mode_t mode,
const bool is_sdk_command,
pal::char_t out_buffer[],
int32_t buffer_size,
int32_t* required_buffer_size)
Expand All @@ -510,6 +523,7 @@ namespace
app_candidate,
opts,
mode,
is_sdk_command,
hostpolicy_dir,
init);
if (rc != StatusCode::Success)
Expand Down Expand Up @@ -572,6 +586,7 @@ int fx_muxer_t::execute(
argv,
new_argoff,
mode,
false,
result_buffer,
buffer_size,
required_buffer_size);
Expand Down Expand Up @@ -621,7 +636,8 @@ namespace
}

const pal::string_t additional_deps_serialized;
init.reset(new corehost_init_t(pal::string_t{}, host_info, deps_file, additional_deps_serialized, probe_realpaths, mode, fx_definitions));
const std::vector<std::pair<pal::string_t, pal::string_t>> additional_properties;
init.reset(new corehost_init_t(pal::string_t{}, host_info, deps_file, additional_deps_serialized, probe_realpaths, mode, fx_definitions, additional_properties));

return StatusCode::Success;
}
Expand Down Expand Up @@ -725,6 +741,7 @@ int fx_muxer_t::initialize_for_app(
host_info.app_path,
opts,
mode,
false,
hostpolicy_dir,
init);
if (rc != StatusCode::Success)
Expand Down Expand Up @@ -978,6 +995,7 @@ int fx_muxer_t::handle_exec_host_command(
const pal::char_t* argv[],
int argoff,
host_mode_t mode,
const bool is_sdk_command,
pal::char_t result_buffer[],
int32_t buffer_size,
int32_t* required_buffer_size)
Expand Down Expand Up @@ -1006,6 +1024,7 @@ int fx_muxer_t::handle_exec_host_command(
new_argc,
new_argv,
mode,
is_sdk_command,
result_buffer,
buffer_size,
required_buffer_size);
Expand Down Expand Up @@ -1096,6 +1115,7 @@ int fx_muxer_t::handle_cli(
new_argv.data(),
new_argoff,
host_mode_t::muxer,
true,
nullptr /*result_buffer*/,
0 /*buffer_size*/,
nullptr/*required_buffer_size*/);
Expand Down
1 change: 1 addition & 0 deletions src/native/corehost/fxr/fx_muxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class fx_muxer_t
const pal::char_t* argv[],
int argoff,
host_mode_t mode,
const bool is_sdk_command,
pal::char_t result_buffer[],
int32_t buffer_size,
int32_t* required_buffer_size);
Expand Down
3 changes: 1 addition & 2 deletions src/native/corehost/hostpolicy/coreclr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ namespace
_X("RUNTIME_IDENTIFIER"),
_X("BUNDLE_PROBE"),
_X("HOSTPOLICY_EMBEDDED"),
_X("PINVOKE_OVERRIDE"),
_X("HOSTFXR_PATH")
_X("PINVOKE_OVERRIDE")
};

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

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