mono-api-html: support ignoring added members
authorAaron Bockover <abock@xamarin.com>
Wed, 19 Feb 2014 18:54:01 +0000 (13:54 -0500)
committerAaron Bockover <abock@xamarin.com>
Wed, 19 Feb 2014 19:22:44 +0000 (14:22 -0500)
Use Mono.Options as well.

mcs/tools/corcompare/mono-api-html/ApiDiff.cs
mcs/tools/corcompare/mono-api-html/MemberComparer.cs
mcs/tools/corcompare/mono-api-html/mono-api-html.csproj

index ecfcceaa66304f90209a1b44a88cb2ca2b04a4a6..cd66e9ecd9d5d4762a7492b001a1e76cb7af89ca 100644 (file)
@@ -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<string> ignoreAdded = new List<string> ();
+               public static List<string> 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<string> 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] <reference.xml> <assembly.xml> [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 ("<h1>{0}.dll</h1>", ac.SourceAssembly);
                                                        } else {
                                                                file.WriteLine ("<h1>{0}.dll vs {1}.dll</h1>", ac.SourceAssembly, ac.TargetAssembly);
                                                        }
-                                                       file.Write (diff);
+                                                       file.Write (diffHtml);
                                                }
                                        }
                                } else {
index 8dcdff546d3e777ce64dc73f24c979a59dcdfbe6..1c9ceef5e4c781521dc0d49b7a74f34e55fc19b4 100644 (file)
@@ -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;
index 6a205f2956add1bee3d670e6ceb43c40a97903d8..32206ffc687c30819c709134ad9dc451a10bf857 100644 (file)
@@ -49,6 +49,9 @@
     <Compile Include="AssemblyComparer.cs" />
     <Compile Include="ClassComparer.cs" />
     <Compile Include="ApiDiff.cs" />
+    <Compile Include="..\..\..\class\Mono.Options\Mono.Options\Options.cs">
+      <Link>Options.cs</Link>
+    </Compile>
   </ItemGroup>
   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
-</Project>
\ No newline at end of file
+</Project>