Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 13 additions & 0 deletions src/installer/corehost/cli/hostpolicy/deps_resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -877,6 +877,19 @@ bool deps_resolver_t::resolve_probe_dirs(
}
}

// If this is a single-file app, add the app's dir to the native search directories.
if (bundle::info_t::is_single_file_bundle() && !is_resources)
{
auto bundle = bundle::runner_t::app();
add_unique_path(asset_type, bundle->base_path(), &items, output, &non_serviced, core_servicing);

// Add the extraction path if it exists.
if (pal::directory_exists(bundle->extraction_path()))
{
add_unique_path(asset_type, bundle->extraction_path(), &items, output, &non_serviced, core_servicing);
Comment thread
elinor-fung marked this conversation as resolved.
Outdated
}
}

output->append(non_serviced);

return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ public static int Main(string[] args)
Console.WriteLine("AppContext.BaseDirectory: " + AppContext.BaseDirectory);
break;

case "native_search_dirs":
var native_search_dirs = AppContext.GetData("NATIVE_DLL_SEARCH_DIRECTORIES");
Console.WriteLine("NATIVE_DLL_SEARCH_DIRECTORIES: " + native_search_dirs);
break;

default:
Console.WriteLine("test failure");
return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@
<RuntimeFrameworkVersion>$(MNAVersion)</RuntimeFrameworkVersion>
</PropertyGroup>

</Project>
<ItemGroup>
<None Condition="'$(AddFile)' != ''" Include="$(AddFile)">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,14 @@ public SharedTestStateBase()
RepoDirectories = new RepoDirectoriesProvider();
}

public TestProjectFixture PreparePublishedSelfContainedTestProject(string projectName)
public TestProjectFixture PreparePublishedSelfContainedTestProject(string projectName, params string[] extraArgs)
{
var testFixture = new TestProjectFixture(projectName, RepoDirectories);
testFixture
.EnsureRestoredForRid(testFixture.CurrentRid, RepoDirectories.CorehostPackages)
.PublishProject(runtime: testFixture.CurrentRid,
outputDirectory: BundleHelper.GetPublishPath(testFixture));
outputDirectory: BundleHelper.GetPublishPath(testFixture),
extraArgs: extraArgs);

return testFixture;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,52 @@ public void GetCommandLineArgs_0_Non_Bundled_App()
.HaveStdOutContaining(appPath);
}

[Fact]
public void AppContext_Native_Search_Dirs_Contains_Bundle_Dir()
Comment thread
mateoatr marked this conversation as resolved.
{
var fixture = sharedTestState.TestFixture.Copy();
Bundler bundler = BundleHelper.BundleApp(fixture, out string singleFile);
string extractionDir = BundleHelper.GetExtractionDir(fixture, bundler).Name;
string bundleDir = BundleHelper.GetBundleDir(fixture).FullName;

// If we don't extract anything to disk, the extraction dir shouldn't
// appear in the native search dirs.
Command.Create(singleFile, "native_search_dirs")
.CaptureStdErr()
.CaptureStdOut()
Comment thread
mateoatr marked this conversation as resolved.
.Execute()
.Should().Pass()
.And.HaveStdOutContaining(bundleDir)
Comment thread
mateoatr marked this conversation as resolved.
.And.NotHaveStdOutContaining(extractionDir);
}

[Fact]
public void AppContext_Native_Search_Dirs_Contains_Bundle_And_Extraction_Dirs()
{
var fixture = sharedTestState.TestFixture.Copy();
Bundler bundler = BundleHelper.BundleApp(fixture, out string singleFile, BundleOptions.BundleNativeBinaries);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to make sure the bundle actually has something to extract so that it creates/adds the extraction directory? By default, we won't have anything to extract on Linux, right?

string extractionDir = BundleHelper.GetExtractionDir(fixture, bundler).Name;
string bundleDir = BundleHelper.GetBundleDir(fixture).FullName;

Command.Create(singleFile, "native_search_dirs")
.CaptureStdErr()
.CaptureStdOut()
.Execute()
.Should().Pass()
.And.HaveStdOutContaining(extractionDir)
.And.HaveStdOutContaining(bundleDir);
}

public class SharedTestState : SharedTestStateBase, IDisposable
{
public TestProjectFixture TestFixture { get; set; }

public SharedTestState()
{
TestFixture = PreparePublishedSelfContainedTestProject("SingleFileApiTests");
// We include mockcoreclr in our project to test native binaries extraction.
string mockCoreClrPath = Path.Combine(RepoDirectories.Artifacts, "corehost_test",
RuntimeInformationExtensions.GetSharedLibraryFileNameForCurrentPlatform("mockcoreclr"));
TestFixture = PreparePublishedSelfContainedTestProject("SingleFileApiTests", $"/p:AddFile={mockCoreClrPath}");
}

public void Dispose()
Expand Down
8 changes: 7 additions & 1 deletion src/installer/tests/TestUtils/TestProjectFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ public TestProjectFixture PublishProject(
bool? selfContained = null,
string outputDirectory = null,
bool singleFile = false,
bool restore = false)
bool restore = false,
params string[] extraArgs)
{
dotnet = dotnet ?? SdkDotnet;
outputDirectory = outputDirectory ?? TestProject.OutputDirectory;
Expand Down Expand Up @@ -308,6 +309,11 @@ public TestProjectFixture PublishProject(
publishArgs.Add($"/p:TestTargetRid={RepoDirProvider.TargetRID}");
publishArgs.Add($"/p:MNAVersion={RepoDirProvider.MicrosoftNETCoreAppVersion}");

foreach (var arg in extraArgs)
{
publishArgs.Add(arg);
}

dotnet.Publish(publishArgs.ToArray())
.WorkingDirectory(TestProject.ProjectDirectory)
.Environment("NUGET_PACKAGES", RepoDirProvider.NugetPackages)
Expand Down