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

Make BundlerConsistencyTests stop building/copying self-contained project unnecessarily #91829

Merged
merged 1 commit into from
Sep 11, 2023
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
1 change: 1 addition & 0 deletions eng/Subsets.props
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@
<!-- Host.pretest subset (consumes live built libraries assets so needs to come after libraries) -->
<ItemGroup Condition="$(_subset.Contains('+host.pretest+'))">
<ProjectToBuild Include="$(InstallerProjectRoot)tests\Assets\Projects\AppWithSubDirs\AppWithSubDirs.csproj" Category="host" />
<ProjectToBuild Include="$(InstallerProjectRoot)tests\Assets\Projects\HelloWorld\HelloWorld.csproj" Category="host" />
</ItemGroup>

<!-- Host.tests subset (consumes live built libraries assets so needs to come after libraries) -->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>$(NetCoreAppCurrent)</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>

</Project>
18 changes: 18 additions & 0 deletions src/installer/tests/Assets/Projects/HelloWorld/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.InteropServices;

namespace HelloWorld
{
public static class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Hello World!");
Console.WriteLine(string.Join(Environment.NewLine, args));
Console.WriteLine(RuntimeInformation.FrameworkDescription);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.DotNet.CoreSetup.Test;
using BundleTests.Helpers;
using System.Runtime.InteropServices;
using System.Text;

namespace Microsoft.NET.HostModel.Tests
{
Expand Down Expand Up @@ -120,6 +121,27 @@ public void TestWithRelativePathsDirSeparator()
BundleRun(fixture, publishDir);
}

[Fact]
public void TestWithAdditionalContentAfterBundleMetadata()
{
var fixture = sharedTestState.TestFixture.Copy();
string singleFile = BundleHelper.BundleApp(fixture);

using (var file = File.OpenWrite(singleFile))
{
file.Position = file.Length;
var blob = Encoding.UTF8.GetBytes("Mock signature at the end of the bundle");
file.Write(blob, 0, blob.Length);
}

Command.Create(singleFile)
.CaptureStdErr()
.CaptureStdOut()
.Execute()
.Should().Pass()
.And.HaveStdOutContaining("Hello World!");
}

public class SharedTestState : IDisposable
{
public TestProjectFixture TestFixture { get; set; }
Expand Down

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/installer/tests/TestUtils/Binaries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static class AppHost
public static class CoreClr
{
public static string FileName = GetSharedLibraryFileNameForCurrentPlatform("coreclr");
public static string FilePath = Path.Combine(RepoDirectoriesProvider.Default.HostArtifacts, FileName);
public static string FilePath = Path.Combine(new DotNetCli(RepoDirectoriesProvider.Default.BuiltDotnet).GreatestVersionSharedFxPath, FileName);

public static string MockName = GetSharedLibraryFileNameForCurrentPlatform("mockcoreclr");
public static string MockPath = Path.Combine(RepoDirectoriesProvider.Default.HostTestArtifacts, MockName);
Expand Down
19 changes: 14 additions & 5 deletions src/installer/tests/TestUtils/SingleFileTestApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ private static SingleFileTestApp Create(string appName, bool selfContained)
};
}

public static IReadOnlyList<FileSpec> GetRuntimeFilesToBundle()
{
var runtimeAssemblies = Binaries.GetRuntimeFiles().Assemblies;
List<FileSpec> fileSpecs = new List<FileSpec>();
foreach (var asset in runtimeAssemblies)
{
fileSpecs.Add(new FileSpec(asset, Path.GetFileName(asset)));
}

fileSpecs.Sort((a, b) => string.CompareOrdinal(a.BundleRelativePath, b.BundleRelativePath));
return fileSpecs;
}

public string Bundle(BundleOptions options, Version? bundleVersion = null)
{
string bundleDirectory = SharedFramework.CalculateUniqueTestDirectory(Path.Combine(Location, "bundle"));
Expand All @@ -81,11 +94,7 @@ public string Bundle(BundleOptions options, Version? bundleVersion = null)
// If this is a self-contained app, add the runtime assemblies to the bundle
if (selfContained)
{
var runtimeAssemblies = Binaries.GetRuntimeFiles().Assemblies;
foreach (var asset in runtimeAssemblies)
{
fileSpecs.Add(new FileSpec(asset, Path.GetFileName(asset)));
}
fileSpecs.AddRange(GetRuntimeFilesToBundle());
}

// Sort the file specs to keep the bundle construction deterministic.
Expand Down
9 changes: 9 additions & 0 deletions src/installer/tests/TestUtils/TestApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ public static TestApp CreateEmpty(string name)
};
}

public static TestApp CreateFromBuiltAssets(string appName)
{
TestApp app = CreateEmpty(appName);
TestArtifact.CopyRecursive(
Path.Combine(RepoDirectoriesProvider.Default.TestAssetsOutput, appName),
app.Location);
return app;
}

public void PopulateFrameworkDependent(string fxName, string fxVersion, Action<NetCoreAppBuilder> customizer = null)
{
var builder = NetCoreAppBuilder.PortableForNETCoreApp(this);
Expand Down