Skip to content

Commit

Permalink
Implement API exclusion. Add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
carlossanlop committed Feb 7, 2025
1 parent 829fac3 commit f3de9ae
Show file tree
Hide file tree
Showing 15 changed files with 577 additions and 92 deletions.
16 changes: 12 additions & 4 deletions sdk.sln
Original file line number Diff line number Diff line change
Expand Up @@ -1893,14 +1893,22 @@ Global
{692B71D8-9C31-D1EE-6C1B-570A12B18E39}.Debug|x86.Build.0 = Debug|Any CPU
{692B71D8-9C31-D1EE-6C1B-570A12B18E39}.Release|Any CPU.ActiveCfg = Release|Any CPU
{692B71D8-9C31-D1EE-6C1B-570A12B18E39}.Release|Any CPU.Build.0 = Release|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Release|Any CPU.Build.0 = Release|Any CPU
{692B71D8-9C31-D1EE-6C1B-570A12B18E39}.Release|x64.ActiveCfg = Release|Any CPU
{692B71D8-9C31-D1EE-6C1B-570A12B18E39}.Release|x64.Build.0 = Release|Any CPU
{692B71D8-9C31-D1EE-6C1B-570A12B18E39}.Release|x86.ActiveCfg = Release|Any CPU
{692B71D8-9C31-D1EE-6C1B-570A12B18E39}.Release|x86.Build.0 = Release|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Debug|x64.ActiveCfg = Debug|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Debug|x64.Build.0 = Debug|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Debug|x86.ActiveCfg = Debug|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Debug|x86.Build.0 = Debug|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Release|Any CPU.Build.0 = Release|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Release|x64.ActiveCfg = Release|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Release|x64.Build.0 = Release|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Release|x86.ActiveCfg = Release|Any CPU
{3DF5A9B8-6F90-4CFB-4518-0E97982B6748}.Release|x86.Build.0 = Release|Any CPU
{E5A15C4C-DCAD-4A5A-93E5-A56822910D82}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E5A15C4C-DCAD-4A5A-93E5-A56822910D82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E5A15C4C-DCAD-4A5A-93E5-A56822910D82}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ internal class GenAPIDiffConfigurationBinder : BinderBase<DiffConfiguration>
private readonly Option<string> _optionOutputFolderPath;
private readonly Option<string> _optionTableOfContentsTitle;
private readonly Option<string[]?> _optionAttributesToExclude;
private readonly Option<string[]?> _optionApisToExclude;
private readonly Option<bool> _optionAddPartialModifier;
private readonly Option<bool> _optionHideImplicitDefaultConstructors;
private readonly Option<bool> _optionDebug;
Expand All @@ -27,6 +28,7 @@ internal GenAPIDiffConfigurationBinder(Option<string> optionBeforeAssembliesFold
Option<string> optionOutputFolderPath,
Option<string> optionTableOfContentsTitle,
Option<string[]?> optionAttributesToExclude,
Option<string[]?> optionApisToExclude,
Option<bool> optionAddPartialModifier,
Option<bool> optionHideImplicitDefaultConstructors,
Option<bool> optionDebug)
Expand All @@ -38,6 +40,7 @@ internal GenAPIDiffConfigurationBinder(Option<string> optionBeforeAssembliesFold
_optionOutputFolderPath = optionOutputFolderPath;
_optionTableOfContentsTitle = optionTableOfContentsTitle;
_optionAttributesToExclude = optionAttributesToExclude;
_optionApisToExclude = optionApisToExclude;
_optionAddPartialModifier = optionAddPartialModifier;
_optionHideImplicitDefaultConstructors = optionHideImplicitDefaultConstructors;
_optionDebug = optionDebug;
Expand All @@ -52,6 +55,7 @@ protected override DiffConfiguration GetBoundValue(BindingContext bindingContext
OutputFolderPath: bindingContext.ParseResult.GetValueForOption(_optionOutputFolderPath) ?? throw new NullReferenceException("Null output directory."),
TableOfContentsTitle: bindingContext.ParseResult.GetValueForOption(_optionTableOfContentsTitle) ?? throw new NullReferenceException("Null table of contents title."),
AttributesToExclude: bindingContext.ParseResult.GetValueForOption(_optionAttributesToExclude),
ApisToExclude: bindingContext.ParseResult.GetValueForOption(_optionApisToExclude),
AddPartialModifier: bindingContext.ParseResult.GetValueForOption(_optionAddPartialModifier),
HideImplicitDefaultConstructors: bindingContext.ParseResult.GetValueForOption(_optionHideImplicitDefaultConstructors),
Debug: bindingContext.ParseResult.GetValueForOption(_optionDebug)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,20 @@ public static async Task Main(string[] args)
IsRequired = true
};

Option<string[]?> optionAttributesToExclude = new(["--attributesToExclude", "-ate"], () => null)
Option<string[]?> optionAttributesToExclude = new(["--attributesToExclude", "-eattrs"], () => null)
{
Description = "Attributes to exclude from the diff.",
Arity = ArgumentArity.ZeroOrMore,
IsRequired = false
};

Option<string[]?> optionApisToExclude = new(["--apisToExclude", "-eapis"], () => null)
{
Description = "APIs to exclude from the diff.",
Arity = ArgumentArity.ZeroOrMore,
IsRequired = false
};

Option<bool> optionAddPartialModifier = new(["--addPartialModifier", "-apm"], () => false)
{
Description = "Add the 'partial' modifier to types."
Expand All @@ -89,6 +96,7 @@ public static async Task Main(string[] args)
rootCommand.Add(optionOutputFolderPath);
rootCommand.Add(optionTableOfContentsTitle);
rootCommand.Add(optionAttributesToExclude);
rootCommand.Add(optionApisToExclude);
rootCommand.Add(optionAddPartialModifier);
rootCommand.Add(optionHideImplicitDefaultConstructors);
rootCommand.Add(optionDebug);
Expand All @@ -100,6 +108,7 @@ public static async Task Main(string[] args)
optionOutputFolderPath,
optionTableOfContentsTitle,
optionAttributesToExclude,
optionApisToExclude,
optionAddPartialModifier,
optionHideImplicitDefaultConstructors,
optionDebug);
Expand All @@ -113,6 +122,7 @@ private static void HandleCommand(DiffConfiguration diffConfig)
var log = new ConsoleLog(MessageImportance.Normal);

string attributesToExclude = diffConfig.AttributesToExclude != null ? string.Join(", ", diffConfig.AttributesToExclude) : string.Empty;
string apisToExclude = diffConfig.ApisToExclude != null ? string.Join(", ", diffConfig.ApisToExclude) : string.Empty;

// Custom ordering to match help menu.
log.LogMessage("Selected options:");
Expand All @@ -122,6 +132,7 @@ private static void HandleCommand(DiffConfiguration diffConfig)
log.LogMessage($" - 'After' reference assemblies: {diffConfig.AfterAssemblyReferencesFolderPath}");
log.LogMessage($" - Output: {diffConfig.OutputFolderPath}");
log.LogMessage($" - Attributes to exclude: {attributesToExclude}");
log.LogMessage($" - APIs to exclude: {apisToExclude}");
log.LogMessage($" - Table of contents title: {diffConfig.TableOfContentsTitle}");
log.LogMessage($" - Add partial modifier to types: {diffConfig.AddPartialModifier}");
log.LogMessage($" - Hide implicit default constructors: {diffConfig.HideImplicitDefaultConstructors}");
Expand All @@ -141,6 +152,7 @@ private static void HandleCommand(DiffConfiguration diffConfig)
diffConfig.OutputFolderPath,
diffConfig.TableOfContentsTitle,
diffConfig.AttributesToExclude,
diffConfig.ApisToExclude,
diffConfig.AddPartialModifier,
diffConfig.HideImplicitDefaultConstructors,
writeToDisk: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public record DiffConfiguration(
string OutputFolderPath,
string TableOfContentsTitle,
string[]? AttributesToExclude,
string[]? ApisToExclude,
bool AddPartialModifier,
bool HideImplicitDefaultConstructors,
bool Debug
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public static class DiffGeneratorFactory
/// <param name="outputFolderPath"></param>
/// <param name="tableOfContentsTitle"></param>
/// <param name="attributesToExclude">An optional list of attributes to avoid showing in the diff. If <see langword="null"/>, the default list of attributes to exclude <see cref="DiffGeneratorFactory.DefaultAttributesToExclude"/> is used. If an empty list, no attributes are excluded.</param>
/// <param name="apisToExclude">An optional list of APIs to avoid showing in the diff.</param>
/// <param name="addPartialModifier"></param>
/// <param name="hideImplicitDefaultConstructors"></param>
/// <param name="writeToDisk">If <see langword="true"/>, when calling <see cref="IDiffGenerator.Run"/>, the generated markdown files get written to disk, and no item is added to the <see cref="IDiffGenerator.Run"/> dictionary. If <see langword="false"/>, when calling <see cref="IDiffGenerator.Run"/>, the generated markdown files get added to the <see cref="IDiffGenerator.Run"/> dictionary (with the file path as the dictionary key) and none of them is written to disk. This is meant for testing purposes.</param>
Expand All @@ -51,6 +52,7 @@ public static IDiffGenerator Create(ILog log,
string outputFolderPath,
string tableOfContentsTitle,
string[]? attributesToExclude,
string[]? apisToExclude,
bool addPartialModifier,
bool hideImplicitDefaultConstructors,
bool writeToDisk,
Expand All @@ -64,6 +66,7 @@ public static IDiffGenerator Create(ILog log,
outputFolderPath,
tableOfContentsTitle,
attributesToExclude,
apisToExclude,
addPartialModifier,
hideImplicitDefaultConstructors,
writeToDisk,
Expand All @@ -74,31 +77,34 @@ public static IDiffGenerator Create(ILog log,
/// Creates a new instance of <see cref="IDiffGenerator"/> that writes the diff to memory.
/// </summary>
/// <param name="log"></param>
/// <param name="attributesToExclude">An optional list of attributes to avoid showing in the diff. If <see langword="null"/>, the default list of attributes to exclude <see cref="DiffGeneratorFactory.DefaultAttributesToExclude"/> is used. If an empty list, no attributes are excluded.</param>
/// <param name="beforeLoader"></param>
/// <param name="afterLoader"></param>
/// <param name="beforeAssemblySymbols"></param>
/// <param name="afterAssemblySymbols"></param>
/// <param name="attributesToExclude">An optional list of attributes to avoid showing in the diff. If <see langword="null"/>, the default list of attributes to exclude <see cref="DiffGeneratorFactory.DefaultAttributesToExclude"/> is used. If an empty list, no attributes are excluded.</param>
/// <param name="apisToExclude">An optional list of APIs to avoid showing in the diff.</param>
/// <param name="addPartialModifier"></param>
/// <param name="hideImplicitDefaultConstructors"></param>
/// <param name="diagnosticOptions"></param>
/// <returns></returns>
public static IDiffGenerator Create(ILog log,
string[]? attributesToExclude,
IAssemblySymbolLoader beforeLoader,
IAssemblySymbolLoader afterLoader,
Dictionary<string, IAssemblySymbol> beforeAssemblySymbols,
Dictionary<string, IAssemblySymbol> afterAssemblySymbols,
string[]? attributesToExclude,
string[]? apisToExclude,
bool addPartialModifier,
bool hideImplicitDefaultConstructors,
IEnumerable<KeyValuePair<string, ReportDiagnostic>>? diagnosticOptions = null)
{
return new MemoryOutputDiffGenerator(log,
attributesToExclude,
beforeLoader,
afterLoader,
beforeAssemblySymbols,
afterAssemblySymbols,
attributesToExclude,
apisToExclude,
addPartialModifier,
hideImplicitDefaultConstructors,
diagnosticOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ internal sealed class FileOutputDiffGenerator : IDiffGenerator
private readonly string _outputFolderPath;
private readonly string _tableOfContentsTitle;
private readonly string[] _attributesToExclude;
private readonly string[] _apisToExclude;
private readonly bool _addPartialModifier;
private readonly bool _hideImplicitDefaultConstructors;
private readonly bool _writeToDisk;
Expand All @@ -38,6 +39,7 @@ internal sealed class FileOutputDiffGenerator : IDiffGenerator
/// <param name="outputFolderPath"></param>
/// <param name="tableOfContentsTitle"></param>
/// <param name="attributesToExclude">An optional list of attributes to avoid showing in the diff. If <see langword="null"/>, the default list of attributes to exclude <see cref="DiffGeneratorFactory.DefaultAttributesToExclude"/> is used. If an empty list, no attributes are excluded.</param>
/// <param name="apisToExclude">An optional list of APIs to avoid showing in the diff.</param>
/// <param name="addPartialModifier"></param>
/// <param name="hideImplicitDefaultConstructors"></param>
/// <param name="writeToDisk">If <see langword="true"/>, when calling <see cref="Run"/>, the generated markdown files get written to disk, and no item is added to the <see cref="Run"/> dictionary. If <see langword="false"/>, when calling <see cref="Run"/>, the generated markdown files get added to the <see cref="Run"/> dictionary (with the file path as the dictionary key) and none of them is written to disk. This is meant for testing purposes.</param>
Expand All @@ -50,6 +52,7 @@ internal FileOutputDiffGenerator(ILog log,
string outputFolderPath,
string tableOfContentsTitle,
string[]? attributesToExclude,
string[]? apisToExclude,
bool addPartialModifier,
bool hideImplicitDefaultConstructors,
bool writeToDisk,
Expand All @@ -64,6 +67,7 @@ internal FileOutputDiffGenerator(ILog log,
_outputFolderPath = outputFolderPath;
_tableOfContentsTitle = tableOfContentsTitle;
_attributesToExclude = attributesToExclude ?? DiffGeneratorFactory.DefaultAttributesToExclude;
_apisToExclude = apisToExclude ?? [];
_addPartialModifier = addPartialModifier;
_hideImplicitDefaultConstructors = hideImplicitDefaultConstructors;
_writeToDisk = writeToDisk;
Expand Down Expand Up @@ -95,11 +99,12 @@ public void Run()
diagnosticOptions: _diagnosticOptions);

MemoryOutputDiffGenerator generator = new(_log,
_attributesToExclude,
beforeLoader,
afterLoader,
beforeAssemblySymbols,
afterAssemblySymbols,
_attributesToExclude,
_apisToExclude,
_addPartialModifier,
_hideImplicitDefaultConstructors,
_diagnosticOptions);
Expand Down
Loading

0 comments on commit f3de9ae

Please sign in to comment.