Skip to content

Commit

Permalink
HostModel: Remove depricated API (#33545)
Browse files Browse the repository at this point in the history
Some depricated APIs were maintained in #33413 so that SDK build is green.
Now that the SDK is updated dotnet/sdk#10849, remove the unused APIs.

Also move out a test-only methods from the product to the test helpers.
  • Loading branch information
swaroop-sridhar authored Mar 13, 2020
1 parent 7a60846 commit 1e84da6
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,5 @@ public static void CopyFile(string sourcePath, string destinationPath)
// Copy file to destination path so it inherits the same attributes/permissions.
File.Copy(sourcePath, destinationPath, overwrite: true);
}

// The SDK calls into BinaryUtils.GetWindowsGraphicalUserInterfaceBit()
// Keep this method until the HostModel changes reach SDK repo, and the code there
// is updated to use PEUtils.GetWindowsGraphicalUserInterfaceBit()
public static unsafe UInt16 GetWindowsGraphicalUserInterfaceBit(string filePath)
{
return PEUtils.GetWindowsGraphicalUserInterfaceBit(filePath);
}

}
}
47 changes: 0 additions & 47 deletions src/installer/managed/Microsoft.NET.HostModel/Bundle/Bundler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@ public class Bundler
// Assemblies are 16 bytes aligned, so that their sections can be memory-mapped cache aligned.
public const int AssemblyAlignment = 16;

// This constructor will be deleted once the SDK is changed to use the new constructor
public Bundler(string hostName,
string outputDir,
bool embedPDBs,
bool diagnosticOutput)
:this(hostName, outputDir,
BundleOptions.BundleAllContent | ((embedPDBs) ? BundleOptions.BundleSymbolFiles : BundleOptions.None),
diagnosticOutput: diagnosticOutput)
{
}

public Bundler(string hostName,
string outputDir,
BundleOptions options = BundleOptions.None,
Expand Down Expand Up @@ -280,42 +269,6 @@ public string GenerateBundle(IReadOnlyList<FileSpec> fileSpecs)

return bundlePath;
}

string RelativePath(string dirFullPath, string fileFullPath)
{
// This function is used in lieu of Path.GetRelativePath because
// * Path.GetRelativePath() doesn't exist in netstandard2.0
// * This implementation is pretty much only intended for testing.
// SDK integration invokes GenerateBundle(fileSpecs) directly.
//
// In later revisions, we should target netstandard2.1, and replace
// this function with Path.GetRelativePath().

return fileFullPath.Substring(dirFullPath.TrimEnd(Path.DirectorySeparatorChar).Length).TrimStart(Path.DirectorySeparatorChar);
}

/// <summary>
/// Generate a bundle containind the (embeddable) files in sourceDir
/// </summary>
public string GenerateBundle(string sourceDir)
{
// Convert sourceDir to absolute path
sourceDir = Path.GetFullPath(sourceDir);

// Get all files in the source directory and all sub-directories.
string[] sources = Directory.GetFiles(sourceDir, searchPattern: "*", searchOption: SearchOption.AllDirectories);

// Sort the file names to keep the bundle construction deterministic.
Array.Sort(sources, StringComparer.Ordinal);

List<FileSpec> fileSpecs = new List<FileSpec>(sources.Length);
foreach (var file in sources)
{
fileSpecs.Add(new FileSpec(file, RelativePath(sourceDir, file)));
}

return GenerateBundle(fileSpecs);
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private void Bundle_Extraction_To_Specific_Path_Succeeds()
// Publish the bundle
var bundleDir = BundleHelper.GetBundleDir(fixture);
var bundler = new Bundler(hostName, bundleDir.FullName, BundleOptions.BundleAllContent);
string singleFile = bundler.GenerateBundle(publishPath);
string singleFile = BundleHelper.GenerateBundle(bundler, publishPath);

// Compute bundled files
var bundledFiles = bundler.BundleManifest.Files.Select(file => file.RelativePath).ToList();
Expand Down Expand Up @@ -77,7 +77,7 @@ private void Bundle_extraction_is_reused()
// Publish the bundle
var bundleDir = BundleHelper.GetBundleDir(fixture);
var bundler = new Bundler(hostName, bundleDir.FullName, BundleOptions.BundleAllContent);
string singleFile = bundler.GenerateBundle(publishPath);
string singleFile = BundleHelper.GenerateBundle(bundler, publishPath);

// Create a directory for extraction.
var extractBaseDir = BundleHelper.GetExtractDir(fixture);
Expand Down Expand Up @@ -130,7 +130,7 @@ private void Bundle_extraction_can_recover_missing_files()
// Publish the bundle
var bundleDir = BundleHelper.GetBundleDir(fixture);
var bundler = new Bundler(hostName, bundleDir.FullName, BundleOptions.BundleAllContent);
string singleFile = bundler.GenerateBundle(publishPath);
string singleFile = BundleHelper.GenerateBundle(bundler, publishPath);

// Compute bundled files
List<string> bundledFiles = bundler.BundleManifest.Files.Select(file => file.RelativePath).ToList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.DotNet.CoreSetup.Test;
using Microsoft.NET.HostModel.Bundle;
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;

Expand Down Expand Up @@ -54,6 +55,27 @@ public static DirectoryInfo GetExtractDir(TestProjectFixture fixture)
return Directory.CreateDirectory(Path.Combine(fixture.TestProject.ProjectDirectory, "extract"));
}

/// Generate a bundle containind the (embeddable) files in sourceDir
public static string GenerateBundle(Bundler bundler, string sourceDir)
{
// Convert sourceDir to absolute path
sourceDir = Path.GetFullPath(sourceDir);

// Get all files in the source directory and all sub-directories.
string[] sources = Directory.GetFiles(sourceDir, searchPattern: "*", searchOption: SearchOption.AllDirectories);

// Sort the file names to keep the bundle construction deterministic.
Array.Sort(sources, StringComparer.Ordinal);

List<FileSpec> fileSpecs = new List<FileSpec>(sources.Length);
foreach (var file in sources)
{
fileSpecs.Add(new FileSpec(file, Path.GetRelativePath(sourceDir, file)));
}

return bundler.GenerateBundle(fileSpecs);
}

// Bundle to a single-file
// In several tests, the single-file bundle is created explicitly using Bundle API
// instead of the SDK via /p:PublishSingleFile=true.
Expand All @@ -72,7 +94,7 @@ public static string BundleApp(TestProjectFixture fixture,
var bundleDir = GetBundleDir(fixture);

var bundler = new Bundler(hostName, bundleDir.FullName, options, targetFrameworkVersion: targetFrameworkVersion);
string singleFile = bundler.GenerateBundle(publishPath);
string singleFile = GenerateBundle(bundler, publishPath);
return singleFile;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,17 @@ private void RunTheApp(string path)
.HaveStdOutContaining("Wow! We now say hello to the big world and you.");
}

private void BundleRun(TestProjectFixture fixture, string publishDir, string singleFileDir)
private void BundleRun(TestProjectFixture fixture, string publishPath, string singleFileDir)
{
var hostName = BundleHelper.GetHostName(fixture);

// Run the App normally
RunTheApp(Path.Combine(publishDir, hostName));
RunTheApp(Path.Combine(publishPath, hostName));

// Bundle to a single-file
// Bundle all content, until the host can handle other scenarios.
Bundler bundler = new Bundler(hostName, singleFileDir, BundleOptions.BundleAllContent);
string singleFile = bundler.GenerateBundle(publishDir);
string singleFile = BundleHelper.GenerateBundle(bundler, publishPath);

// Run the extracted app
RunTheApp(singleFile);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public void TestFilesAlwaysBundled(BundleOptions options)
var bundleDir = BundleHelper.GetBundleDir(fixture);

var bundler = new Bundler(hostName, bundleDir.FullName, options);
bundler.GenerateBundle(publishPath);
BundleHelper.GenerateBundle(bundler, publishPath);

bundler.BundleManifest.Contains($"{appName}.dll").Should().BeTrue();
bundler.BundleManifest.Contains($"{appName}.deps.json").Should().BeTrue();
Expand All @@ -125,8 +125,8 @@ public void TestFilesNeverBundled(BundleOptions options)
File.Copy(Path.Combine(publishPath, $"{appName}.runtimeconfig.json"),
Path.Combine(publishPath, $"{appName}.runtimeconfig.dev.json"));

var bundler = new Bundler(hostName, bundleDir.FullName, options);
bundler.GenerateBundle(publishPath);
var bundler = new Bundler(hostName, bundleDir.FullName, options);
BundleHelper.GenerateBundle(bundler, publishPath);

bundler.BundleManifest.Contains($"{appName}.runtimeconfig.dev.json").Should().BeFalse();
}
Expand All @@ -144,7 +144,7 @@ public void TestBundlingSymbols(BundleOptions options)
var bundleDir = BundleHelper.GetBundleDir(fixture);

var bundler = new Bundler(hostName, bundleDir.FullName, options);
bundler.GenerateBundle(publishPath);
BundleHelper.GenerateBundle(bundler, publishPath);

bundler.BundleManifest.Contains($"{appName}.pdb").Should().Be(options.HasFlag(BundleOptions.BundleSymbolFiles));
}
Expand All @@ -162,7 +162,7 @@ public void TestBundlingNativeBinaries(BundleOptions options)
var bundleDir = BundleHelper.GetBundleDir(fixture);

var bundler = new Bundler(hostName, bundleDir.FullName, options);
bundler.GenerateBundle(publishPath);
BundleHelper.GenerateBundle(bundler, publishPath);

bundler.BundleManifest.Contains($"{hostfxr}").Should().Be(options.HasFlag(BundleOptions.BundleNativeBinaries));
}
Expand All @@ -178,7 +178,7 @@ public void TestAssemblyAlignment()
var bundleDir = BundleHelper.GetBundleDir(fixture);

var bundler = new Bundler(hostName, bundleDir.FullName, BundleOptions.BundleAllContent);
bundler.GenerateBundle(BundleHelper.GetPublishPath(fixture));
BundleHelper.GenerateBundle(bundler, publishPath);

bundler.BundleManifest.Files.ForEach(file =>
Assert.True((file.Type != FileType.Assembly) || (file.Offset % Bundler.AssemblyAlignment == 0)));
Expand All @@ -191,9 +191,10 @@ public void TestWithAdditionalContentAfterBundleMetadata()

var hostName = BundleHelper.GetHostName(fixture);
var bundleDir = BundleHelper.GetBundleDir(fixture);
string publishPath = BundleHelper.GetPublishPath(fixture);

var bundler = new Bundler(hostName, bundleDir.FullName, BundleOptions.BundleAllContent);
string singleFile = bundler.GenerateBundle(BundleHelper.GetPublishPath(fixture));
string singleFile = BundleHelper.GenerateBundle(bundler, publishPath);

using (var file = File.OpenWrite(singleFile))
{
Expand Down

0 comments on commit 1e84da6

Please sign in to comment.