Remove nonmigrating projects

This commit is contained in:
Steve Sanderson 2018-11-27 10:27:33 +00:00
parent 6bfa6102f3
commit aca33b5c34
16 changed files with 1 additions and 719 deletions

3
.gitmodules vendored
View File

@ -1,3 +0,0 @@
[submodule "modules/jsinterop"]
path = modules/jsinterop
url = https://github.com/dotnet/jsinterop.git

View File

@ -17,8 +17,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Compon
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MonoSanityClient", "blazor\samples\MonoSanityClient\MonoSanityClient.csproj", "{06AAAE9E-96DE-4574-97DA-9C4C7D9FE990}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Blazor.BuildTools", "blazor\src\Microsoft.AspNetCore.Blazor.BuildTools\Microsoft.AspNetCore.Blazor.BuildTools.csproj", "{BB34336F-E68E-4411-9805-CAAA919F5EA1}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HostedInAspNet", "HostedInAspNet", "{4D367450-96E9-4C8C-8B56-EED8ADE3A20D}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HostedInAspNet.Client", "blazor\samples\HostedInAspNet.Client\HostedInAspNet.Client.csproj", "{B4335F7C-4E86-4559-821F-F1B1C75F5FAE}"
@ -91,20 +89,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Blazor
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Components.TagHelperWorkaround", "src\Microsoft.AspNetCore.Components.TagHelperWorkaround\Microsoft.AspNetCore.Components.TagHelperWorkaround.csproj", "{F71D78AB-A07E-415D-BF3F-1B9991628214}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mono.WebAssembly.Interop", "modules\jsinterop\src\Mono.WebAssembly.Interop\Mono.WebAssembly.Interop.csproj", "{37856984-9702-4062-B8B7-91A38AD8F2BF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.JSInterop", "modules\jsinterop\src\Microsoft.JSInterop\Microsoft.JSInterop.csproj", "{5F992F3C-4980-4E8E-BEE0-6EC08E369A57}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.JSInterop.JS", "modules\jsinterop\src\Microsoft.JSInterop.JS\Microsoft.JSInterop.JS.csproj", "{4A5D7F9D-9CED-44C1-983E-054D8E99A292}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "jsinterop", "jsinterop", "{1386F99B-3862-40C2-B24D-796C07DC7921}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "modules", "modules", "{F380B6B6-9486-42BC-9B24-C388F8BF13A3}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.JSInterop.Test", "modules\jsinterop\test\Microsoft.JSInterop.Test\Microsoft.JSInterop.Test.csproj", "{ECF02708-4CA4-44B3-B23F-274F4B417FA5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Blazor.Mono", "blazor\src\Microsoft.AspNetCore.Blazor.Mono\Microsoft.AspNetCore.Blazor.Mono.csproj", "{DEEAE26E-D00C-4A3C-BE12-7A51A63CE55E}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "blazor", "blazor", "{E5DDF29D-DFC9-43E3-AC3A-5B6D54B786D5}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "benchmarks", "benchmarks", "{DDE4B710-6936-4E17-9CA0-54C45333ED15}"
@ -167,14 +151,6 @@ Global
{06AAAE9E-96DE-4574-97DA-9C4C7D9FE990}.Release|Any CPU.Build.0 = Release|Any CPU
{06AAAE9E-96DE-4574-97DA-9C4C7D9FE990}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU
{06AAAE9E-96DE-4574-97DA-9C4C7D9FE990}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU
{BB34336F-E68E-4411-9805-CAAA919F5EA1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BB34336F-E68E-4411-9805-CAAA919F5EA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BB34336F-E68E-4411-9805-CAAA919F5EA1}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
{BB34336F-E68E-4411-9805-CAAA919F5EA1}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU
{BB34336F-E68E-4411-9805-CAAA919F5EA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BB34336F-E68E-4411-9805-CAAA919F5EA1}.Release|Any CPU.Build.0 = Release|Any CPU
{BB34336F-E68E-4411-9805-CAAA919F5EA1}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU
{BB34336F-E68E-4411-9805-CAAA919F5EA1}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU
{B4335F7C-4E86-4559-821F-F1B1C75F5FAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B4335F7C-4E86-4559-821F-F1B1C75F5FAE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B4335F7C-4E86-4559-821F-F1B1C75F5FAE}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
@ -389,46 +365,6 @@ Global
{F71D78AB-A07E-415D-BF3F-1B9991628214}.Release|Any CPU.Build.0 = Release|Any CPU
{F71D78AB-A07E-415D-BF3F-1B9991628214}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU
{F71D78AB-A07E-415D-BF3F-1B9991628214}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU
{37856984-9702-4062-B8B7-91A38AD8F2BF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{37856984-9702-4062-B8B7-91A38AD8F2BF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{37856984-9702-4062-B8B7-91A38AD8F2BF}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
{37856984-9702-4062-B8B7-91A38AD8F2BF}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU
{37856984-9702-4062-B8B7-91A38AD8F2BF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{37856984-9702-4062-B8B7-91A38AD8F2BF}.Release|Any CPU.Build.0 = Release|Any CPU
{37856984-9702-4062-B8B7-91A38AD8F2BF}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU
{37856984-9702-4062-B8B7-91A38AD8F2BF}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU
{5F992F3C-4980-4E8E-BEE0-6EC08E369A57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5F992F3C-4980-4E8E-BEE0-6EC08E369A57}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5F992F3C-4980-4E8E-BEE0-6EC08E369A57}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
{5F992F3C-4980-4E8E-BEE0-6EC08E369A57}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU
{5F992F3C-4980-4E8E-BEE0-6EC08E369A57}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5F992F3C-4980-4E8E-BEE0-6EC08E369A57}.Release|Any CPU.Build.0 = Release|Any CPU
{5F992F3C-4980-4E8E-BEE0-6EC08E369A57}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU
{5F992F3C-4980-4E8E-BEE0-6EC08E369A57}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU
{4A5D7F9D-9CED-44C1-983E-054D8E99A292}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4A5D7F9D-9CED-44C1-983E-054D8E99A292}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4A5D7F9D-9CED-44C1-983E-054D8E99A292}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
{4A5D7F9D-9CED-44C1-983E-054D8E99A292}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU
{4A5D7F9D-9CED-44C1-983E-054D8E99A292}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4A5D7F9D-9CED-44C1-983E-054D8E99A292}.Release|Any CPU.Build.0 = Release|Any CPU
{4A5D7F9D-9CED-44C1-983E-054D8E99A292}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU
{4A5D7F9D-9CED-44C1-983E-054D8E99A292}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU
{ECF02708-4CA4-44B3-B23F-274F4B417FA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ECF02708-4CA4-44B3-B23F-274F4B417FA5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECF02708-4CA4-44B3-B23F-274F4B417FA5}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
{ECF02708-4CA4-44B3-B23F-274F4B417FA5}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU
{ECF02708-4CA4-44B3-B23F-274F4B417FA5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECF02708-4CA4-44B3-B23F-274F4B417FA5}.Release|Any CPU.Build.0 = Release|Any CPU
{ECF02708-4CA4-44B3-B23F-274F4B417FA5}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU
{ECF02708-4CA4-44B3-B23F-274F4B417FA5}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU
{DEEAE26E-D00C-4A3C-BE12-7A51A63CE55E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DEEAE26E-D00C-4A3C-BE12-7A51A63CE55E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DEEAE26E-D00C-4A3C-BE12-7A51A63CE55E}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
{DEEAE26E-D00C-4A3C-BE12-7A51A63CE55E}.DebugNoVSIX|Any CPU.Build.0 = Debug|Any CPU
{DEEAE26E-D00C-4A3C-BE12-7A51A63CE55E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DEEAE26E-D00C-4A3C-BE12-7A51A63CE55E}.Release|Any CPU.Build.0 = Release|Any CPU
{DEEAE26E-D00C-4A3C-BE12-7A51A63CE55E}.ReleaseNoVSIX|Any CPU.ActiveCfg = Release|Any CPU
{DEEAE26E-D00C-4A3C-BE12-7A51A63CE55E}.ReleaseNoVSIX|Any CPU.Build.0 = Release|Any CPU
{8C5D8A27-E6E6-4E5B-9389-206B5519658C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8C5D8A27-E6E6-4E5B-9389-206B5519658C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C5D8A27-E6E6-4E5B-9389-206B5519658C}.DebugNoVSIX|Any CPU.ActiveCfg = Debug|Any CPU
@ -494,7 +430,6 @@ Global
{5A694793-3257-4D37-BB74-4A41B3894685} = {B867E038-B3CE-43E3-9292-61568C46CDEB}
{5BC2A10D-B6CA-43AE-B73C-2A41AE1039F9} = {ADA3AE29-F6DE-49F6-8C7C-B321508CAE8E}
{06AAAE9E-96DE-4574-97DA-9C4C7D9FE990} = {2A076721-6081-4517-8329-B9E5110D6DAC}
{BB34336F-E68E-4411-9805-CAAA919F5EA1} = {AD41FFD8-2C0C-4F0C-9537-25C2A3A7A1F4}
{4D367450-96E9-4C8C-8B56-EED8ADE3A20D} = {C7B9207E-BF85-422D-9EBC-E243C399F619}
{B4335F7C-4E86-4559-821F-F1B1C75F5FAE} = {4D367450-96E9-4C8C-8B56-EED8ADE3A20D}
{F8996835-41F7-4663-91DF-3B5652ADC37D} = {4D367450-96E9-4C8C-8B56-EED8ADE3A20D}
@ -530,12 +465,6 @@ Global
{6BDD3018-3961-488E-97D3-1FB7320A8AC6} = {E8EBA72C-D555-43AE-BC98-F0B2D05F6A07}
{CCEC81C4-1A3C-40DC-952F-074712C46180} = {DDE4B710-6936-4E17-9CA0-54C45333ED15}
{F71D78AB-A07E-415D-BF3F-1B9991628214} = {B867E038-B3CE-43E3-9292-61568C46CDEB}
{37856984-9702-4062-B8B7-91A38AD8F2BF} = {1386F99B-3862-40C2-B24D-796C07DC7921}
{5F992F3C-4980-4E8E-BEE0-6EC08E369A57} = {1386F99B-3862-40C2-B24D-796C07DC7921}
{4A5D7F9D-9CED-44C1-983E-054D8E99A292} = {1386F99B-3862-40C2-B24D-796C07DC7921}
{1386F99B-3862-40C2-B24D-796C07DC7921} = {F380B6B6-9486-42BC-9B24-C388F8BF13A3}
{ECF02708-4CA4-44B3-B23F-274F4B417FA5} = {ADA3AE29-F6DE-49F6-8C7C-B321508CAE8E}
{DEEAE26E-D00C-4A3C-BE12-7A51A63CE55E} = {AD41FFD8-2C0C-4F0C-9537-25C2A3A7A1F4}
{DDE4B710-6936-4E17-9CA0-54C45333ED15} = {E5DDF29D-DFC9-43E3-AC3A-5B6D54B786D5}
{C7B9207E-BF85-422D-9EBC-E243C399F619} = {E5DDF29D-DFC9-43E3-AC3A-5B6D54B786D5}
{AD41FFD8-2C0C-4F0C-9537-25C2A3A7A1F4} = {E5DDF29D-DFC9-43E3-AC3A-5B6D54B786D5}

View File

@ -1,5 +0,0 @@
<Project>
<PropertyGroup>
<BlazorBuildToolsExe>dotnet &quot;$(ArtifactsBinDir)Microsoft.AspNetCore.Blazor.BuildTools/netcoreapp2.1/Microsoft.AspNetCore.Blazor.BuildTools.dll&quot;</BlazorBuildToolsExe>
</PropertyGroup>
</Project>

View File

@ -1,96 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Extensions.CommandLineUtils;
using System;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace Microsoft.AspNetCore.Blazor.BuildTools.Cli.Commands
{
class CheckNodeJsInstalledCommand
{
private static Regex NodeVersionRegex = new Regex(@"^v(\d+\.\d+\.\d+)");
public static void Command(CommandLineApplication command)
{
command.Description = "Asserts that Node.js is installed.";
command.HelpOption("-?|-h|--help");
var minVersionOption = command.Option(
"-v|--version",
"Specifies a minimum acceptable version of Node.js.",
CommandOptionType.SingleValue);
command.OnExecute(() =>
{
var foundNodeVersion = GetInstalledNodeVersion();
if (foundNodeVersion == null)
{
return 1;
}
if (minVersionOption.HasValue())
{
var minVersion = new Version(minVersionOption.Value());
if (foundNodeVersion < minVersion)
{
Console.WriteLine($"ERROR: The installed version of Node.js is too old. Required version: {minVersion}; Found version: {foundNodeVersion}.");
return 1;
}
}
Console.WriteLine($"Found Node.js version {foundNodeVersion}");
return 0;
});
}
private static Version GetInstalledNodeVersion()
{
var versionString = InvokeNodeVersionCommand();
if (versionString == null)
{
return null;
}
var versionStringMatch = NodeVersionRegex.Match(versionString);
if (!versionStringMatch.Success)
{
Console.WriteLine($"ERROR: Got unparseable Node.js version string: {versionStringMatch}");
return null;
}
return new Version(versionStringMatch.Groups[1].Value);
}
private static string InvokeNodeVersionCommand()
{
try
{
var process = Process.Start(new ProcessStartInfo
{
FileName = "node",
Arguments = "-v",
RedirectStandardOutput = true
});
process.WaitForExit();
if (process.ExitCode != 0)
{
Console.WriteLine($"ERROR: The command 'node -v' exited with code {process.ExitCode}.");
return null;
}
else
{
return process.StandardOutput.ReadToEnd();
}
}
catch (Exception ex)
{
Console.WriteLine("ERROR: Node.js was not found. Ensure that Node.js is installed and that 'node' is present on the system PATH.");
Console.WriteLine("The underlying error was: " + ex.Message);
return null;
}
}
}
}

View File

@ -1,110 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Blazor.BuildTools.Core.ILWipe;
using Microsoft.Extensions.CommandLineUtils;
namespace Microsoft.AspNetCore.Blazor.BuildTools.Cli.Commands
{
static class ILWipeCommand
{
public static void Command(CommandLineApplication command)
{
command.Description = "Wipes code from .NET assemblies.";
command.HelpOption("-?|-h|--help");
var inputDirOption = command.Option(
"-i|--input",
"The directory containing assemblies from which code should be wiped.",
CommandOptionType.SingleValue);
var specFileOption = command.Option(
"-s|--spec",
"The directory containing spec files describing which members to wipe from the assemblies.",
CommandOptionType.SingleValue);
var verboseOption = command.Option(
"-v|--verbose",
"If set, logs additional information to the console.",
CommandOptionType.NoValue);
var listOption = command.Option(
"-l|--list",
"If set, just writes lists the assembly contents to disk.",
CommandOptionType.NoValue);
var outputOption = command.Option(
"-o|--output",
"The directory to which the wiped assembly files should be written.",
CommandOptionType.SingleValue);
command.OnExecute(() =>
{
var inputDir = GetRequiredOptionValue(inputDirOption);
var outputDir = GetRequiredOptionValue(outputOption);
var specDir = GetRequiredOptionValue(specFileOption);
var specFiles = Directory.EnumerateFiles(
specDir, "*.txt",
new EnumerationOptions { RecurseSubdirectories = true });
foreach (var specFilePath in specFiles)
{
var specFileRelativePath = Path.GetRelativePath(specDir, specFilePath);
var assemblyRelativePath = Path.ChangeExtension(specFileRelativePath, ".dll");
var inputAssemblyPath = Path.Combine(inputDir, assemblyRelativePath);
var outputAssemblyPath = Path.Combine(outputDir, assemblyRelativePath);
var inputAssemblySize = new FileInfo(inputAssemblyPath).Length;
if (listOption.HasValue())
{
var outputList = AssemblyItem
.ListContents(inputAssemblyPath)
.Select(item => item.ToString());
File.WriteAllLines(
Path.ChangeExtension(outputAssemblyPath, ".txt"),
outputList);
}
else
{
WipeAssembly.Exec(
inputAssemblyPath,
outputAssemblyPath,
specFilePath,
verboseOption.HasValue());
Console.WriteLine(
$"{assemblyRelativePath.PadRight(40)} " +
$"{FormatFileSize(inputAssemblySize)} ==> " +
$"{FormatFileSize(outputAssemblyPath)}");
}
}
return 0;
});
}
private static string FormatFileSize(string path)
{
return FormatFileSize(new FileInfo(path).Length);
}
private static string FormatFileSize(long length)
{
return string.Format("{0:0.000} MB", ((double)length) / (1024*1024));
}
private static string GetRequiredOptionValue(CommandOption option)
{
if (!option.HasValue())
{
throw new InvalidOperationException($"Missing value for required option '{option.LongName}'.");
}
return option.Value();
}
}
}

View File

@ -1,33 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNetCore.Blazor.BuildTools.Cli.Commands;
using Microsoft.Extensions.CommandLineUtils;
namespace Microsoft.AspNetCore.Blazor.BuildTools
{
static class Program
{
static int Main(string[] args)
{
var app = new CommandLineApplication
{
Name = "blazor-buildtools"
};
app.HelpOption("-?|-h|--help");
app.Command("checknodejs", CheckNodeJsInstalledCommand.Command);
app.Command("ilwipe", ILWipeCommand.Command);
if (args.Length > 0)
{
return app.Execute(args);
}
else
{
app.ShowHelp();
return 0;
}
}
}
}

View File

@ -1,92 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Mono.Cecil;
using System.Collections.Generic;
using System.Linq;
using Mono.Cecil.Cil;
namespace Microsoft.AspNetCore.Blazor.BuildTools.Core.ILWipe
{
class AssemblyItem
{
public static IEnumerable<AssemblyItem> ListContents(string assemblyPath)
{
var moduleDefinition = ModuleDefinition.ReadModule(assemblyPath);
return ListContents(moduleDefinition);
}
public static IEnumerable<AssemblyItem> ListContents(ModuleDefinition moduleDefinition)
{
return moduleDefinition.Types
.SelectMany(GetNestedTypesRecursive)
.SelectMany(type => type.Methods)
.Select(method => new AssemblyItem(method))
.OrderBy(item => item.ToString(), StringComparer.Ordinal);
}
public MethodDefinition Method { get; }
public AssemblyItem(MethodDefinition method)
{
Method = method ?? throw new ArgumentNullException(nameof(method));
}
public void WipeFromAssembly(MethodDefinition createMethodWipedException)
{
if (!Method.HasBody)
{
return; // Nothing to do
}
if (Method.HasCustomAttributes)
{
for (int i = 0; i < Method.CustomAttributes.Count; i++)
{
if (Method.CustomAttributes[i].AttributeType.FullName == "System.Runtime.CompilerServices.AsyncStateMachineAttribute")
{
Method.CustomAttributes.RemoveAt(i);
break;
}
}
}
// We don't want to actually remove the method definition from the assembly, because
// then you'd have an assembly that was invalid (it could contain calls to the method
// that no longer exists). Instead, remove all the instructions from its body, and
// replace it with "throw CreateMethodWipedException()". Then:
// [1] The method body is very short, while still definitely being valid (still OK for
// it to have any return type)
// [2] We've removed its references to other methods/types, so they are more likely
// to be actually removed fully by a subsequent IL linker pass
// [3] If the method is actually invoked at runtime, the stack trace will make clear
// which method is being excessively wiped
var il = Method.Body.GetILProcessor();
il.Body.Instructions.Clear();
il.Body.Variables.Clear();
il.Body.ExceptionHandlers.Clear();
il.Append(il.Create(OpCodes.Call, createMethodWipedException));
il.Append(il.Create(OpCodes.Throw));
}
public override string ToString()
{
var result = Method.ToString();
return result.Substring(result.IndexOf(' ') + 1);
}
public int CodeSize
=> Method.Body?.CodeSize ?? 0;
private static IEnumerable<TypeDefinition> GetNestedTypesRecursive(TypeDefinition type)
{
yield return type;
foreach (var descendant in type.NestedTypes.SelectMany(GetNestedTypesRecursive))
{
yield return descendant;
}
}
}
}

View File

@ -1,76 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Mono.Cecil;
using Mono.Cecil.Cil;
using System;
namespace Microsoft.AspNetCore.Blazor.BuildTools.Core.ILWipe
{
static class MethodWipedExceptionMethod
{
public static MethodDefinition AddToAssembly(ModuleDefinition moduleDefinition)
{
// Adds the following method to the assembly:
// namespace ILWipe
// {
// internal static class ILWipeHelpers
// {
// public static Exception CreateMethodWipedException()
// {
// return new NotImplementedException("Cannot call method because it was wiped. See stack trace for details.");
// }
// }
// }
var ilWipeHelpersType = new TypeDefinition("ILWipe", "ILWipeHelpers",
TypeAttributes.NotPublic | TypeAttributes.Class | TypeAttributes.Abstract | TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit,
moduleDefinition.TypeSystem.Object);
moduleDefinition.Types.Add(ilWipeHelpersType);
var methodAttributes =
MethodAttributes.Public |
MethodAttributes.HideBySig |
MethodAttributes.Static;
var createMethodWipedExceptionMethod = new MethodDefinition(
"CreateMethodWipedException",
methodAttributes,
ImportEquivalentTypeFromMscorlib(moduleDefinition, typeof(Exception)));
ilWipeHelpersType.Methods.Add(createMethodWipedExceptionMethod);
var notImplExceptionType = ImportEquivalentTypeFromMscorlib(moduleDefinition, typeof(NotImplementedException));
var notImplExceptionCtor = new MethodReference(".ctor", moduleDefinition.TypeSystem.Void, notImplExceptionType);
notImplExceptionCtor.HasThis = true;
notImplExceptionCtor.Parameters.Add(new ParameterDefinition(moduleDefinition.TypeSystem.String));
var il = createMethodWipedExceptionMethod.Body.GetILProcessor();
il.Append(il.Create(OpCodes.Ldstr, "Cannot invoke method because it was wiped. See stack trace for details."));
il.Append(il.Create(OpCodes.Newobj, notImplExceptionCtor));
il.Append(il.Create(OpCodes.Ret));
return createMethodWipedExceptionMethod;
}
static TypeReference ImportEquivalentTypeFromMscorlib(ModuleDefinition module, Type type)
{
// We have to do this instead of module.ImportReference(type), because the latter
// would try to reference it in System.Private.CoreLib because this tool itself
// compiles to target netcoreapp rather than netstandard
IMetadataScope mscorlibScope;
if (module.TryGetTypeReference(typeof(object).FullName, out var objectRef))
{
mscorlibScope = objectRef.Scope;
}
else if (module.Name == "mscorlib.dll")
{
mscorlibScope = module;
}
else
{
throw new InvalidOperationException($"Could not resolve System.Object type within '{module.FileName}'.");
}
var typeRef = new TypeReference(type.Namespace, type.Name, module, mscorlibScope, type.IsValueType);
return module.ImportReference(typeRef);
}
}
}

View File

@ -1,33 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.Linq;
namespace Microsoft.AspNetCore.Blazor.BuildTools.Core.ILWipe
{
class SpecList
{
private List<SpecListEntry> _itemSpecs;
public SpecList(string[] fromSpecLines)
{
var linesToUse = fromSpecLines.Where(
line => !string.IsNullOrWhiteSpace(line) && !line.StartsWith('#'));
_itemSpecs = new List<SpecListEntry>(
linesToUse.Select(line => new SpecListEntry(line)));
}
public bool IsEmpty
{
get => _itemSpecs.Count == 0;
}
public bool Match(AssemblyItem item)
{
// If this needs to be faster, consider implementing some kind of matching tree.
var lastMatchingSpec = _itemSpecs.LastOrDefault(spec => spec.IsMatch(item));
return lastMatchingSpec == null ? false : !lastMatchingSpec.Negated;
}
}
}

View File

@ -1,121 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
namespace Microsoft.AspNetCore.Blazor.BuildTools.Core.ILWipe
{
class SpecListEntry
{
public bool Negated { get; }
public string TypeName { get; }
public string MethodName { get; }
public string Args { get; }
public SpecListEntry(string parseSpecLine)
{
parseSpecLine = parseSpecLine.Trim();
if (parseSpecLine.StartsWith('!'))
{
Negated = true;
parseSpecLine = parseSpecLine.Substring(1);
}
var colonsPos = parseSpecLine.IndexOf("::");
if (colonsPos < 0)
{
TypeName = parseSpecLine;
}
else
{
TypeName = parseSpecLine.Substring(0, colonsPos);
parseSpecLine = parseSpecLine.Substring(colonsPos + 2);
var bracketPos = parseSpecLine.IndexOf('(');
if (bracketPos < 0)
{
MethodName = parseSpecLine;
}
else
{
MethodName = parseSpecLine.Substring(0, bracketPos);
Args = parseSpecLine.Substring(bracketPos + 1, parseSpecLine.Length - bracketPos - 2);
}
}
}
public bool IsMatch(AssemblyItem item)
{
return MatchesType(item)
&& MatchesMethod(item)
&& MatchesArgs(item);
}
private bool MatchesArgs(AssemblyItem item)
{
if (Args == null)
{
return true;
}
else
{
var methodString = item.Method.ToString();
var bracketPos = methodString.IndexOf('(');
var argsString = methodString.Substring(bracketPos + 1, methodString.Length - bracketPos - 2);
return string.Equals(argsString, Args, StringComparison.Ordinal);
}
}
private bool MatchesMethod(AssemblyItem item)
{
if (MethodName == null)
{
return true;
}
else if (MethodName.EndsWith('*'))
{
return item.Method.Name.StartsWith(
MethodName.Substring(0, MethodName.Length - 1),
StringComparison.Ordinal);
}
else
{
return string.Equals(item.Method.Name, MethodName, StringComparison.Ordinal);
}
}
private bool MatchesType(AssemblyItem item)
{
var declaringTypeFullName = item.Method.DeclaringType.FullName;
if (TypeName.EndsWith('*'))
{
// Wildcard match
return declaringTypeFullName.StartsWith(
TypeName.Substring(0, TypeName.Length - 1),
StringComparison.Ordinal);
}
else
{
// Exact match
if (string.Equals(
item.Method.DeclaringType.FullName,
TypeName,
StringComparison.Ordinal))
{
return true;
}
// If we're matching all members of the type, include nested types
if (MethodName == null && declaringTypeFullName.StartsWith(
$"{TypeName}/",
StringComparison.Ordinal))
{
return true;
}
return false;
}
}
}
}

View File

@ -1,55 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO;
using Mono.Cecil;
using System.Linq;
namespace Microsoft.AspNetCore.Blazor.BuildTools.Core.ILWipe
{
static class WipeAssembly
{
public static void Exec(string inputPath, string outputPath, string specFilePath, bool logVerbose)
{
if (string.IsNullOrEmpty(outputPath))
{
outputPath = Path.ChangeExtension(inputPath, ".wiped" + Path.GetExtension(inputPath));
}
var specLines = File.ReadAllLines(specFilePath);
var wipeSpecList = new SpecList(specLines);
var moduleDefinition = ModuleDefinition.ReadModule(inputPath);
if (!wipeSpecList.IsEmpty)
{
var createMethodWipedException = MethodWipedExceptionMethod.AddToAssembly(moduleDefinition);
var contents = AssemblyItem.ListContents(moduleDefinition).ToList();
foreach (var contentItem in contents)
{
var shouldWipe = wipeSpecList.Match(contentItem)
&& contentItem.Method != createMethodWipedException;
if (logVerbose)
{
Console.WriteLine($"{(shouldWipe ? "Wiping" : "Retaining")}: {contentItem}");
}
if (shouldWipe)
{
contentItem.WipeFromAssembly(createMethodWipedException);
}
}
}
// Also resolve referenced assemblies in the same directory
if (moduleDefinition.AssemblyResolver is DefaultAssemblyResolver resolver)
{
resolver.AddSearchDirectory(Path.GetDirectoryName(inputPath));
}
moduleDefinition.Write(outputPath);
}
}
}

View File

@ -1,14 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>Exe</OutputType>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.CommandLineUtils" Version="1.1.1" />
<PackageReference Include="Mono.Cecil" Version="0.10.0-beta7" />
</ItemGroup>
</Project>

View File

@ -13,10 +13,8 @@
"bin/Microsoft.AspNetCore.Components.Razor.Extensions/net461/Microsoft.AspNetCore.Components.Razor.Extensions.dll",
"bin/Microsoft.AspNetCore.Components.Razor.Extensions/netstandard2.0/Microsoft.AspNetCore.Components.Razor.Extensions.dll",
"bin/Microsoft.AspNetCore.Components/netstandard2.0/Microsoft.AspNetCore.Components.dll",
"bin/Microsoft.JSInterop/netstandard2.0/Microsoft.JSInterop.dll",
"bin/Microsoft.VisualStudio.BlazorExtension/Microsoft.VisualStudio.BlazorExtension.dll",
"bin/Microsoft.VisualStudio.LanguageServices.Blazor/net461/Microsoft.VisualStudio.LanguageServices.Blazor.dll",
"bin/Mono.WebAssembly.Interop/netstandard2.0/Mono.WebAssembly.Interop.dll"
"bin/Microsoft.VisualStudio.LanguageServices.Blazor/net461/Microsoft.VisualStudio.LanguageServices.Blazor.dll"
]
},
{

View File

@ -1,3 +0,0 @@
<Project>
<Import Project="..\Directory.Build.props" />
</Project>

View File

@ -1,3 +0,0 @@
<Project>
<Import Project="..\Directory.Build.targets" />
</Project>

@ -1 +0,0 @@
Subproject commit ce659765931a681031aaa504d26078bb6f3cd846