From 1f01ada26771af3b3ab1086c201e21a2d135784a Mon Sep 17 00:00:00 2001 From: Aaron Bockover Date: Wed, 19 Feb 2014 13:54:01 -0500 Subject: [PATCH] mono-api-html: support ignoring added members Use Mono.Options as well. --- mcs/tools/corcompare/mono-api-html/ApiDiff.cs | 52 +++++++++++++++---- .../mono-api-html/MemberComparer.cs | 2 + .../mono-api-html/mono-api-html.csproj | 5 +- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/mcs/tools/corcompare/mono-api-html/ApiDiff.cs b/mcs/tools/corcompare/mono-api-html/ApiDiff.cs index ecfcceaa663..cd66e9ecd9d 100644 --- a/mcs/tools/corcompare/mono-api-html/ApiDiff.cs +++ b/mcs/tools/corcompare/mono-api-html/ApiDiff.cs @@ -33,6 +33,9 @@ using System; using System.IO; +using System.Collections.Generic; + +using Mono.Options; namespace Xamarin.ApiDiff { @@ -54,36 +57,65 @@ namespace Xamarin.ApiDiff { public static string BaseType { get; set; } public static int Indent { get; set; } + + static List ignoreAdded = new List (); + public static List IgnoreAdded { + get { return ignoreAdded; } + } } class Program { public static int Main (string[] args) { - if (args.Length < 2) { - Console.WriteLine ("mono-api-html reference.xml assembly.xml [diff.html]"); + var showHelp = false; + string diff = null; + List extra = null; + + var options = new OptionSet { + { "h|help", "Show this help", v => showHelp = true }, + { "d|diff=", "HTML diff file out output (omit for stdout)", v => diff = v }, + { "i|ignore-added=", "Ignore added members with a given name", v => State.IgnoreAdded.Add (v) } + }; + + try { + extra = options.Parse (args); + } catch (OptionException e) { + Console.WriteLine ("Option error: {0}", e.Message); + showHelp = true; + } + + if (showHelp || extra == null || extra.Count < 2 || extra.Count > 3) { + Console.WriteLine (@"Usage: mono-api-html [options] [diff.html]"); + Console.WriteLine (); + Console.WriteLine ("Available options:"); + options.WriteOptionDescriptions (Console.Out); + Console.WriteLine (); return 1; } + var input = extra [0]; + var output = extra [1]; + if (extra.Count == 3 && diff == null) + diff = extra [2]; + try { - string input = args [0]; - string output = args [1]; var ac = new AssemblyComparer (input, output); - if (args.Length > 2) { - string diff = String.Empty; + if (diff != null) { + string diffHtml = String.Empty; using (var writer = new StringWriter ()) { State.Output = writer; ac.Compare (); - diff = State.Output.ToString (); + diffHtml = State.Output.ToString (); } - if (diff.Length > 0) { - using (var file = new StreamWriter (args [2])) { + if (diffHtml.Length > 0) { + using (var file = new StreamWriter (diff)) { if (ac.SourceAssembly == ac.TargetAssembly) { file.WriteLine ("

{0}.dll

", ac.SourceAssembly); } else { file.WriteLine ("

{0}.dll vs {1}.dll

", ac.SourceAssembly, ac.TargetAssembly); } - file.Write (diff); + file.Write (diffHtml); } } } else { diff --git a/mcs/tools/corcompare/mono-api-html/MemberComparer.cs b/mcs/tools/corcompare/mono-api-html/MemberComparer.cs index 8dcdff546d3..1c9ceef5e4c 100644 --- a/mcs/tools/corcompare/mono-api-html/MemberComparer.cs +++ b/mcs/tools/corcompare/mono-api-html/MemberComparer.cs @@ -109,6 +109,8 @@ namespace Xamarin.ApiDiff { bool a = false; foreach (var item in target) { SetContext (item); + if (State.IgnoreAdded.Contains (GetDescription (item))) + continue; if (!a) { BeforeAdding (); a = true; diff --git a/mcs/tools/corcompare/mono-api-html/mono-api-html.csproj b/mcs/tools/corcompare/mono-api-html/mono-api-html.csproj index 6a205f2956a..32206ffc687 100644 --- a/mcs/tools/corcompare/mono-api-html/mono-api-html.csproj +++ b/mcs/tools/corcompare/mono-api-html/mono-api-html.csproj @@ -49,6 +49,9 @@ + + Options.cs + - \ No newline at end of file + -- 2.25.1