This repository has been archived by the owner on May 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 505
/
mdoc.targets
260 lines (242 loc) · 13 KB
/
mdoc.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
============================================================
SetupMDoc
Set all the variables needed for mdoc.
This runs during the build and package phases.
============================================================
-->
<Target Name="_MDocSetup">
<PropertyGroup>
<_ManagedExeLauncher Condition=" '$(OS)' != 'Windows_NT' And Exists ('/Library/Frameworks/Mono.framework/Versions/Current/bin/mono') ">/Library/Frameworks/Mono.framework/Versions/Current/bin/mono</_ManagedExeLauncher>
<_ManagedExeLauncher Condition=" '$(OS)' != 'Windows_NT' And Exists ('/usr/local/bin/mono') ">/usr/local/bin/mono</_ManagedExeLauncher>
<_ManagedExeLauncher Condition=" '$(OS)' != 'Windows_NT' And Exists ('/usr/bin/mono') ">/usr/bin/mono</_ManagedExeLauncher>
<_ManagedExeLauncher Condition=" '$(OS)' != 'Windows_NT' And '$(_ManagedExeLauncher)' == '' ">mono</_ManagedExeLauncher>
<MDocVersion Condition=" '%(Identity)' == 'mdoc' ">@(PackageReference -> '%(Version)')</MDocVersion>
<MDocPackagePath Condition=" '%(Name)' == 'mdoc' ">@(PackageDefinitions -> '%(ResolvedPath)')</MDocPackagePath>
<MDocPackagePath Condition=" '$(MDocPackagePath)' == '' ">$(NuGetPackageRoot)\mdoc\$(MDocVersion)</MDocPackagePath>
<MDocToolPath>$(MDocPackagePath)\tools\mdoc.exe</MDocToolPath>
<MDocOutputName>$(TargetName).xml</MDocOutputName>
<MDocOutputPath>$(TargetDir)$(MDocOutputName)</MDocOutputPath>
<_ShouldGenerateDocs Condition=" '$(MDocDocumentationDirectory)' != '' and Exists('$(MDocDocumentationDirectory)\index.xml') ">true</_ShouldGenerateDocs>
</PropertyGroup>
</Target>
<!--
============================================================
MDocGenerateDocs
Generated the XML documentation file using mdoc.
This runs during the build phase.
============================================================
-->
<Target Name="MDocGenerateDocs"
AfterTargets="CoreCompile" DependsOnTargets="_MDocSetup">
<ItemGroup Condition=" '$(_ShouldGenerateDocs)' == 'true' ">
<FileWrites Include="$(MDocOutputPath)" />
</ItemGroup>
<Exec Condition=" '$(_ShouldGenerateDocs)' == 'true' "
Command="$(_ManagedExeLauncher) "$(MDocToolPath)" export-msxdoc --debug --out="$(MDocOutputPath)" "$(MDocDocumentationDirectory)"" />
</Target>
<!--
============================================================
MDocAddFilesToPackage
Make sure the mdoc output goes into the final package.
This runs during the package phase.
============================================================
-->
<Target Name="MDocAddFilesToPackage"
BeforeTargets="_GetBuildOutputFilesWithTfm" DependsOnTargets="_MDocSetup">
<ItemGroup Condition=" '$(_ShouldGenerateDocs)' == 'true' ">
<BuildOutputInPackage Include="$(MDocOutputPath)" TargetFramework="$(TargetFramework)" TargetPath="$(MDocOutputName)" />
</ItemGroup>
</Target>
<!--
============================================================
MDocUpdateDocs
Update the docs in the documentation directory using the
compiled assemblies.
This runs as a separate task.
============================================================
-->
<Target Name="MDocUpdateDocs"
DependsOnTargets="_MDocSetup">
<!-- bits for resolving references on Windows -->
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
<FrameworkReferenceAssemblyPath>$(VsInstallRoot)\Common7\IDE\ReferenceAssemblies\Microsoft\Framework</FrameworkReferenceAssemblyPath>
<WindowsKitsReferenceAssemblyPath>$(MSBuildProgramFiles32)\Windows Kits\10\References\10.0.16299.0</WindowsKitsReferenceAssemblyPath>
</PropertyGroup>
<ItemGroup Condition=" '$(OS)' == 'Windows_NT' ">
<MDocReferenceAssembly Include="$(FrameworkReferenceAssemblyPath)\MonoAndroid\v1.0" />
<MDocReferenceAssembly Include="$(FrameworkReferenceAssemblyPath)\MonoAndroid\v13.0" />
<MDocReferenceAssembly Include="$(FrameworkReferenceAssemblyPath)\Xamarin.iOS\v1.0" />
<MDocReferenceAssembly Include="$(FrameworkReferenceAssemblyPath)\Xamarin.TVOS\v1.0" />
<MDocReferenceAssembly Include="$(FrameworkReferenceAssemblyPath)\Xamarin.WatchOS\v1.0" />
<MDocReferenceAssembly Include="$(FrameworkReferenceAssemblyPath)\Xamarin.Mac\v2.0" />
<MDocReferenceAssembly Include="$(WindowsKitsReferenceAssemblyPath)\Windows.Foundation.FoundationContract\5.0.0.0" />
<MDocReferenceAssembly Include="$(WindowsKitsReferenceAssemblyPath)\Windows.Foundation.UniversalApiContract\5.0.0.0" />
</ItemGroup>
<!-- the actual task -->
<PropertyGroup>
<BinConfigDir>$(MSBuildProjectDirectory)\bin\$(Configuration)\</BinConfigDir>
<TmpDir>$(MSBuildProjectDirectory)\tmp\</TmpDir>
</PropertyGroup>
<ItemGroup>
<MDocReferenceAssembly Include="$(BinConfigDir)monoandroid13.0" />
</ItemGroup>
<PropertyGroup>
<MDocReferenceAssemblies>@(MDocReferenceAssembly -> '--lib="%(Identity)"', ' ')</MDocReferenceAssemblies>
</PropertyGroup>
<RemoveDir Directories="$(TmpDir)" />
<MakeDir Directories="$(TmpDir)" />
<Copy SourceFiles="$(MDocDocumentationDirectory)\..\frameworks.xml" DestinationFolder="$(TmpDir)" />
<Copy SourceFiles="$(BinConfigDir)netstandard2.0\$(AssemblyName).dll" DestinationFolder="$(TmpDir)xamarin-essentials" />
<Copy SourceFiles="$(BinConfigDir)monoandroid13.0\$(AssemblyName).dll" DestinationFolder="$(TmpDir)xamarin-essentials-android" />
<Copy SourceFiles="$(BinConfigDir)xamarin.ios10\$(AssemblyName).dll" DestinationFolder="$(TmpDir)xamarin-essentials-ios" />
<Copy SourceFiles="$(BinConfigDir)xamarin.mac20\$(AssemblyName).dll" DestinationFolder="$(TmpDir)xamarin-essentials-macos" />
<Copy SourceFiles="$(BinConfigDir)xamarin.tvos10\$(AssemblyName).dll" DestinationFolder="$(TmpDir)xamarin-essentials-tvos" />
<Copy SourceFiles="$(BinConfigDir)xamarin.watchos10\$(AssemblyName).dll" DestinationFolder="$(TmpDir)xamarin-essentials-watchos" />
<Copy SourceFiles="$(BinConfigDir)uap10.0.16299\$(AssemblyName).dll" DestinationFolder="$(TmpDir)xamarin-essentials-uwp" />
<Exec Command="$(_ManagedExeLauncher) "$(MDocToolPath)" update --debug --lang=DocId --delete --frameworks="$(TmpDir)frameworks.xml" --out="$(MDocDocumentationDirectory)" $(MDocReferenceAssemblies)" />
<_FormatDocs DocsRoot="$(MDocDocumentationDirectory)" />
<_VerifyAllDocsAreComplete DocsRoot="$(MDocDocumentationDirectory)" />
</Target>
<!--
============================================================
MDocVerifyDocs
Makes sure all the docs are filled in.
This runs as a separate task.
============================================================
-->
<Target Name="MDocVerifyDocs"
DependsOnTargets="_MDocSetup">
<_FormatDocs DocsRoot="$(MDocDocumentationDirectory)" />
<_VerifyAllDocsAreComplete DocsRoot="$(MDocDocumentationDirectory)" />
</Target>
<!--
===================================================================================================================
_FormatDocs
Make sure the docs are all uniform after editing in various apps or tools.
===================================================================================================================
-->
<UsingTask TaskName="_FormatDocs" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<DocsRoot ParameterType="System.String" />
</ParameterGroup>
<Task>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Using Namespace="System.Xml" />
<Using Namespace="System.Xml.Linq" />
<Code Type="Fragment" Language="cs"><![CDATA[
foreach (var file in Directory.EnumerateFiles(DocsRoot, "*.xml", SearchOption.AllDirectories)) {
var xdoc = XDocument.Load(file);
// special case for Android resources: don't process
if (xdoc.Root.Name == "Type") {
var nameAttr = xdoc.Root.Attribute("FullName");
if (nameAttr != null && (nameAttr.Value == "Xamarin.Essentials.Resource" || nameAttr.Value.StartsWith("Xamarin.Essentials.Resource+"))) {
File.Delete(file);
continue;
}
}
if (xdoc.Root.Name == "Overview") {
foreach (var type in xdoc.Root.Descendants("Type").ToArray()) {
var nameAttr = type.Attribute("Name");
if (nameAttr != null && (nameAttr.Value == "Resource" || nameAttr.Value.StartsWith("Resource+"))) {
type.Remove();
}
}
}
if (xdoc.Root.Name == "Framework") {
foreach (var type in xdoc.Root.Descendants("Type").ToArray()) {
var nameAttr = type.Attribute("Name");
if (nameAttr != null && (nameAttr.Value == "Xamarin.Essentials.Resource" || nameAttr.Value.StartsWith("Xamarin.Essentials.Resource/"))) {
type.Remove();
}
}
}
// the tooling can't handle the ToPlatform* that differs only on return types
if (xdoc.Root.Name == "Type") {
var typeNameAttr = xdoc.Root.Attribute("FullName");
if (typeNameAttr != null && typeNameAttr.Value.EndsWith("Extensions")) {
foreach (var member in xdoc.Root.Descendants("Member").ToArray()) {
var memberNameAttr = member.Attribute("MemberName");
if (memberNameAttr != null && memberNameAttr.Value.StartsWith("ToPlatform")) {
member.Remove();
}
}
}
}
if (xdoc.Root.Name == "Overview") {
foreach (var member in xdoc.Root.Descendants("Member").ToArray()) {
var memberNameAttr = member.Attribute("MemberName");
if (memberNameAttr != null && memberNameAttr.Value.StartsWith("ToPlatform")) {
member.Remove();
}
}
}
if (xdoc.Root.Name == "Framework") {
foreach (var type in xdoc.Root.Descendants("Type").ToArray()) {
var typeNameAttr = type.Attribute("Name");
if (typeNameAttr != null && typeNameAttr.Value.EndsWith("Extensions")) {
foreach (var member in type.Descendants("Member").ToArray()) {
var memberNameAttr = member.Attribute("Id");
if (memberNameAttr != null && memberNameAttr.Value.Contains(".ToPlatform")) {
member.Remove();
}
}
}
}
}
var settings = new XmlWriterSettings {
Encoding = new UTF8Encoding(),
Indent = true,
NewLineChars = "\n",
OmitXmlDeclaration = true,
};
using (var writer = XmlWriter.Create(file, settings)) {
xdoc.Save(writer);
writer.Flush();
}
File.AppendAllText(file, "\n");
}
]]></Code>
</Task>
</UsingTask>
<!--
===================================================================================================================
_VerifyAllDocsAreComplete
Make sure the docs are all filled in.
===================================================================================================================
-->
<UsingTask TaskName="_VerifyAllDocsAreComplete" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll" >
<ParameterGroup>
<DocsRoot ParameterType="System.String" />
</ParameterGroup>
<Task>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Using Namespace="System.IO" />
<Using Namespace="System.Xml" />
<Using Namespace="System.Xml.Linq" />
<Code Type="Fragment" Language="cs"><![CDATA[
foreach (var file in Directory.EnumerateFiles(DocsRoot, "*.xml", SearchOption.AllDirectories)) {
var xdoc = XDocument.Load(file);
var incomplete = xdoc.Descendants("Docs").Where(x => x.Descendants().Any(d => d.Value == "To be added."));
foreach (var node in incomplete) {
if (node.Parent.Name == "Type" && xdoc.Root.Name == "Type") {
var typename = xdoc.Root.Attribute("FullName").Value;
Log.LogWarning("Missing docs for {0}.", typename);
} else if (node.Parent.Name == "Member" && xdoc.Root.Name == "Type") {
var typename = xdoc.Root.Attribute("FullName").Value;
var member = node.Parent.Attribute("MemberName").Value;
var memberType = node.Parent.Element("MemberType").Value.ToLower();
Log.LogWarning("Missing docs for {2} '{0}.{1}'.", typename, member, memberType);
} else {
Log.LogWarning("Missing docs in {0}.", file);
}
}
}
]]></Code>
</Task>
</UsingTask>
</Project>