From 2a7cbd353aa37570365eb80a5d4b9207b69c9fe7 Mon Sep 17 00:00:00 2001 From: Aaron Oneal Date: Tue, 4 Jun 2013 17:56:13 -0700 Subject: [PATCH 1/7] [docs] Do not import samples by default or the docfixer "import-samples" arg is meaningless --- tools/docfixer/AppleDocMerger.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/docfixer/AppleDocMerger.cs b/tools/docfixer/AppleDocMerger.cs index 3045d718..536e8873 100644 --- a/tools/docfixer/AppleDocMerger.cs +++ b/tools/docfixer/AppleDocMerger.cs @@ -23,7 +23,7 @@ public class Options // Default options public Options () { - ImportSamples = true; + ImportSamples = false; QuickSummaries = true; CancellationToken = System.Threading.CancellationToken.None; } From 3ff136880e39f27e947a826f5810a6cd3f623051 Mon Sep 17 00:00:00 2001 From: Aaron Oneal Date: Tue, 4 Jun 2013 17:57:48 -0700 Subject: [PATCH 2/7] [docs] AppleDocMerger: Check for null (don't die just because a type isn't found in the apple docs) --- tools/docfixer/AppleDocMerger.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/docfixer/AppleDocMerger.cs b/tools/docfixer/AppleDocMerger.cs index 536e8873..89e3ada8 100644 --- a/tools/docfixer/AppleDocMerger.cs +++ b/tools/docfixer/AppleDocMerger.cs @@ -382,6 +382,9 @@ public string GetAppleDocFor (TypeDefinition t) { var path = db.CreateCommand ("select zkpath from znode join ztoken on znode.z_pk == ztoken.zparentnode where ztoken.ztokenname like \"" + t.Name + "\"").ExecuteScalar (); + if (path == null) + return null; + return Path.Combine (options.DocBase, "..", path); } From 2aab374d8798ca7c98b53833c11267e84ac8196f Mon Sep 17 00:00:00 2001 From: Aaron Oneal Date: Tue, 4 Jun 2013 18:01:59 -0700 Subject: [PATCH 3/7] [docs] AppleDocMerger: Null fix to create ProcessingContext When running from ProcessNSO in document-generated-code instead of the one in AppleDocMerger, the context hasn't been created yet. This creates it to avoid a null reference exception. --- tools/docfixer/AppleDocMerger.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/docfixer/AppleDocMerger.cs b/tools/docfixer/AppleDocMerger.cs index 89e3ada8..6e5c6998 100644 --- a/tools/docfixer/AppleDocMerger.cs +++ b/tools/docfixer/AppleDocMerger.cs @@ -717,6 +717,9 @@ string GetRealAppleDocPath (TypeDefinition t) } appledocpath = FixAppleDocPath (t, appledocpath); } + if (context == null) + context = new ProcessingContext (); + context.CurrentAppleDocPath = appledocpath; return appledocpath; From 7998167f1386a296ec55e480df9ec564149aadd6 Mon Sep 17 00:00:00 2001 From: Aaron Oneal Date: Tue, 4 Jun 2013 18:03:48 -0700 Subject: [PATCH 4/7] [docs] AppleDocMerger make the missing type count configurable If a specific number of types are missing AppleDocMerger throws. This was hard-coded before and now this is configurable via the command-line which is useful when building against different documentation sets. --- tools/docfixer/AppleDocMerger.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/docfixer/AppleDocMerger.cs b/tools/docfixer/AppleDocMerger.cs index 6e5c6998..0fd388bf 100644 --- a/tools/docfixer/AppleDocMerger.cs +++ b/tools/docfixer/AppleDocMerger.cs @@ -26,6 +26,7 @@ public Options () ImportSamples = false; QuickSummaries = true; CancellationToken = System.Threading.CancellationToken.None; + ThrowOnMissingTypeCount = 90; } // Instruct the merger to take samples from a known repository and use them while merging to replace inline apple samples @@ -59,6 +60,9 @@ public Options () // Token used to end prematurely the process if needed public CancellationToken CancellationToken { get; set; } + + // Consider it an error (throw) if this many types or more were missing + public int ThrowOnMissingTypeCount { get; set; } } class ProcessingContext @@ -112,8 +116,8 @@ public AppleDocMerger (Options options) throw new ArgumentException (string.Format ("DocBase '{0}' isn't valid", options.DocBase), "options.DocBase"); var dbPath = Path.Combine (options.DocBase, "..", "..", "docSet.dsidx"); - if (!File.Exists (dbPath)) - throw new ArgumentException ("DocBase doesn't contain a valid database file", "options.DocBase"); + if (!File.Exists (dbPath)) + throw new ArgumentException ("DocBase doesn't contain a valid database file", "options.DocBase"); db = new SQLiteConnection (dbPath); var samplesPath = string.IsNullOrEmpty (options.SamplesRepositoryPath) ? Path.Combine (options.DocBase, "samples.zip") : options.SamplesRepositoryPath; @@ -172,7 +176,7 @@ public void MergeDocumentation () if (!options.ImportSamples) samples.Close (!options.DebugDocs); - if (numOfMissingAppleDocumentation > 90) { + if (numOfMissingAppleDocumentation > options.ThrowOnMissingTypeCount) { throw new ApplicationException (string.Format ("Too many types were not found on this run ({0}), should be around 60-70 (mostly CoreImage, 3 UIKits, 2 CoreAnimation, 1 Foundation, 1 Bluetooth, 1 iAd", numOfMissingAppleDocumentation)); } From 9e168a4d0aec786de56b5bc8ff335a697a8f49ae Mon Sep 17 00:00:00 2001 From: Aaron Oneal Date: Tue, 4 Jun 2013 18:05:08 -0700 Subject: [PATCH 5/7] [docs] Enable missing type count configuration from the docfixer command-line --- tools/docfixer/docfixer.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/docfixer/docfixer.cs b/tools/docfixer/docfixer.cs index baf22bae..2e9cc113 100644 --- a/tools/docfixer/docfixer.cs +++ b/tools/docfixer/docfixer.cs @@ -52,6 +52,9 @@ public static int Main2 (string[] args) { "use-raw-doc", "Process uncompiled mdoc documentation rather than a bundle", v => useRawDoc = v != null}, + { "allow-missing=", + "Allow this many types to be missing before considering it an error", + v => mergerOptions.ThrowOnMissingTypeCount = Int32.Parse(v)}, { "v|verbose", "Verbose output", v => mergerOptions.MergingPathCallback = v != null ? p => Console.WriteLine (p) : (Action)null }, From a863fb8f4ed173dcb4a7213db14d5d7cdb1d1390 Mon Sep 17 00:00:00 2001 From: Aaron Oneal Date: Tue, 4 Jun 2013 18:09:26 -0700 Subject: [PATCH 6/7] [docs] docfixer: Make the compiled doc bundle configurable from the command-line Additionally, this patch sets the default archive for MonoMac and MonoTouch eliminating the need to compile in docfixer.mm.cs or docvixer.mt.cs. The invoker is also notified if the doc bundle does not exist. --- tools/docfixer/docfixer.cs | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/tools/docfixer/docfixer.cs b/tools/docfixer/docfixer.cs index 2e9cc113..3f0d117f 100644 --- a/tools/docfixer/docfixer.cs +++ b/tools/docfixer/docfixer.cs @@ -31,6 +31,7 @@ public static int Main2 (string[] args) { bool show_help = false; bool useRawDoc = false; + string docBundle = null; var mergerOptions = new AppleDocMerger.Options (); var options = new OptionSet () { @@ -52,6 +53,9 @@ public static int Main2 (string[] args) { "use-raw-doc", "Process uncompiled mdoc documentation rather than a bundle", v => useRawDoc = v != null}, + { "doc-bundle=", + "Process a bundle rather than uncompiled mdoc documentation", + v => docBundle = v}, { "allow-missing=", "Allow this many types to be missing before considering it an error", v => mergerOptions.ThrowOnMissingTypeCount = Int32.Parse(v)}, @@ -73,7 +77,7 @@ public static int Main2 (string[] args) return 1; } - if (string.IsNullOrEmpty (monodocPath) || show_help) { + if (string.IsNullOrEmpty (monodocPath) || show_help || (useRawDoc && !string.IsNullOrEmpty(docBundle))) { ShowHelp (options); return 0; } @@ -81,8 +85,21 @@ public static int Main2 (string[] args) IMdocArchive mdocArchive = null; if (useRawDoc) mdocArchive = new MDocDirectoryArchive (Path.Combine (monodocPath, "en")); - else - mdocArchive = MDocZipArchive.ExtractAndLoad (Path.Combine (monodocPath, ArchiveName)); + else { + string bundlePath; + if (!string.IsNullOrEmpty(docBundle)) { + bundlePath = Path.Combine(monodocPath, docBundle); + } else { + bundlePath = Path.Combine(monodocPath, "monomac-lib.zip"); + if (!File.Exists(bundlePath)) + bundlePath = Path.Combine(monodocPath, "MonoTouch-lib.zip"); + } + if (!File.Exists(bundlePath)) { + Console.Error.WriteLine("{0} does not exist", bundlePath); + return 1; + } + mdocArchive = MDocZipArchive.ExtractAndLoad (bundlePath); + } mergerOptions.MonodocArchive = mdocArchive; var merger = new AppleDocMerger (mergerOptions); merger.MergeDocumentation (); From e72d4b74e5842f393532f04fbaab174ead272500 Mon Sep 17 00:00:00 2001 From: Aaron Oneal Date: Tue, 4 Jun 2013 18:13:35 -0700 Subject: [PATCH 7/7] [docs] document-generated-code: Make namespace prefix and Apple doc location command-line configurable This removes references to MonoTouch and makes the namespace configurable from the command-line. Additionally, the Apple docs location can also be specified when a merge should be performed. This eliminates the "appledocs" parameter in favor of "apple-doc-dir" for consistency with docfixer. --- tools/docfixer/document-generated-code.cs | 52 ++++++++++++----------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/tools/docfixer/document-generated-code.cs b/tools/docfixer/document-generated-code.cs index 839a6eaa..777dc7a9 100644 --- a/tools/docfixer/document-generated-code.cs +++ b/tools/docfixer/document-generated-code.cs @@ -34,21 +34,13 @@ using macdoc; class DocumentGeneratedCode { -#if MONOMAC - Type nso = typeof (MonoMac.Foundation.NSObject); - const string ns = "MonoMac"; - const string docBase = "/Developer/Documentation/DocSets/com.apple.adc.documentation.AppleSnowLeopard.CoreReference.docset"; -#else - Type nso = typeof (MonoTouch.Foundation.NSObject); - const string ns = "MonoTouch"; - const string docBase = "/Library/Developer/Shared/Documentation/DocSets/com.apple.adc.documentation.AppleiOS5_0.iOSLibrary.docset"; -#endif - static void Help () { - Console.WriteLine ("Usage is: document-generated-code [--appledocs] temp.dll path-to-documentation"); + Console.WriteLine ("Usage is: document-generated-code --ns-prefix= [--apple-doc-dir=] temp.dll path-to-documentation"); } + static string ns; + static string docBase; static string assembly_dir; static Assembly assembly; static bool mergeAppledocs; @@ -63,16 +55,15 @@ static string GetPath (string ns, string typeName, bool notification = false) static string GetMdocPath (Type t, bool notification = false) { - var ns = t.Namespace; - var typeName = t.FullName.Substring (ns.Length+1); - if (ns == "MonoTouch.Foundation"){ + var typeName = t.Name; + if (t.Namespace == ns){ if (typeName == "NSString2") typeName = "NSString"; if (typeName == "NSObject2") typeName = "NSObject"; } - return GetPath (ns, typeName, notification); + return GetPath (t.Namespace, typeName, notification); } static XDocument GetDoc (Type t, bool notification = false) @@ -195,7 +186,7 @@ static XElement GetXmlNodeFromExport (Type t, XDocument xdoc, string selector) { return (from m in xdoc.XPathSelectElements ("Type/Members/Member") let a = m.XPathSelectElement ("Attributes/Attribute/AttributeName") - where a != null && a.Value.IndexOf ("MonoTouch.Foundation.Export(\"" + selector + "\"") != -1 + where a != null && a.Value.IndexOf (ns + ".Foundation.Export(\"" + selector + "\"") != -1 select m).FirstOrDefault (); } @@ -305,7 +296,7 @@ public static void ProcessNotification (Type t, XDocument xdoc, PropertyInfo pi) var evengArgsType = DocumentNotificationNestedType (t, pi, body.ToString ()); remarks.RemoveAll (); - remarks.Add (XElement.Parse ("This constant can be used with the to register a listener for this notification. This is an NSString instead of a string, because these values can be used as tokens in some native libraries instead of being used purely for their actual string content. The 'notification' parameter to the callback contains extra information that is specific to the notification type.")); + remarks.Add (XElement.Parse ("This constant can be used with the to register a listener for this notification. This is an NSString instead of a string, because these values can be used as tokens in some native libraries instead of being used purely for their actual string content. The 'notification' parameter to the callback contains extra information that is specific to the notification type.")); remarks.Add (XElement.Parse (String.Format ("If you want to subscribe to this notification, you can use the convenience . method which offers strongly typed access to the parameters of the notification.", t.Name, name))); remarks.Add (XElement.Parse ("The following example shows how to use the strongly typed Notifications class, to take the guesswork out of the available properties in the notification:")); remarks.Add (XElement.Parse (String.Format ("\n" + @@ -359,9 +350,9 @@ public static string DocumentNotificationNestedType (Type t, PropertyInfo pi, st class_summary.Add (XElement.Parse ("Notification posted by the class.")); class_remarks.RemoveAll (); class_remarks.Add (XElement.Parse ("This is a static class which contains various helper methods that allow developers to observe events posted " + - "in the iOS notification hub ().")); + "in the iOS notification hub ().")); class_remarks.Add (XElement.Parse ("The methods defined in this class post events invoke the provided method or lambda with a " + - " parameter which contains strongly typed properties for the notification arguments.")); + " parameter which contains strongly typed properties for the notification arguments.")); var notifications = from prop in t.GetProperties () let propName = prop.Name @@ -398,7 +389,7 @@ public static string DocumentNotificationNestedType (Type t, PropertyInfo pi, st handler.Value = "Method to invoke when the notification is posted."; summary.Value = "Registers a method to be notified when the " + notification.Item2 + " notification is posted."; returns.RemoveAll (); - returns.Add (XElement.Parse ("The returned NSObject represents the registered notification. Either call Dispose on the object to stop receiving notifications, or pass it to ")); + returns.Add (XElement.Parse ("The returned NSObject represents the registered notification. Either call Dispose on the object to stop receiving notifications, or pass it to ")); remarks.RemoveAll (); remarks.Add (XElement.Parse ("The following example shows how you can use this method in your code")); @@ -805,12 +796,25 @@ public static int Main (string [] args) Help (); return 0; } - if (arg == "--appledocs"){ + if (arg == "--debugdoc"){ + debugDoc = true; + continue; + } + if (arg.StartsWith("--apple-doc-dir")) { mergeAppledocs = true; + var split = arg.Split('='); + if (split.Length == 2) + docBase = split[1]; + else + docBase = args[++i]; continue; } - if (arg == "--debugdoc"){ - debugDoc = true; + if (arg.StartsWith("--ns-prefix")) { + var split = arg.Split('='); + if (split.Length == 2) + ns = split[1]; + else + ns = args[++i]; continue; } @@ -820,7 +824,7 @@ public static int Main (string [] args) dir = arg; } - if (dir == null){ + if (dir == null || ns == null || (mergeAppledocs && docBase == null)){ Help (); return 1; }