Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/api-doc-tools.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/mdoc
diff options
context:
space:
mode:
authorXiao Luo <basehello@icloud.com>2021-01-29 11:55:38 +0300
committerXiao Luo <basehello@icloud.com>2021-01-29 11:55:38 +0300
commit52dd21b8b0995f41226c33aef69f5d90b2ce3ddc (patch)
treef679f969b746409447b0ebec0c5efdda3b7cc886 /mdoc
parent37ae438b80fa2b6e0c9518605c452e653a316006 (diff)
Remove the .NET Core platform assemblies in the external\Test folder. Add .NET Core platform assemblies from the installation path of the .NET Core by the custom DefaultAssemblyResolver for WSL, macOS, and Ubuntu OS environment.
Diffstat (limited to 'mdoc')
-rw-r--r--mdoc/Mono.Documentation/Updater/Formatters/MemberFormatter.cs2
-rw-r--r--mdoc/mdoc.Test/BasicTests.cs2
-rw-r--r--mdoc/mdoc.Test/DotnetCoreAssemblyResolver.cs94
-rw-r--r--mdoc/mdoc.Test/ExternalAssemblyResolver.cs25
-rw-r--r--mdoc/mdoc.Test/mdoc.Test.csproj2
5 files changed, 97 insertions, 28 deletions
diff --git a/mdoc/Mono.Documentation/Updater/Formatters/MemberFormatter.cs b/mdoc/Mono.Documentation/Updater/Formatters/MemberFormatter.cs
index 28730405..faf87874 100644
--- a/mdoc/Mono.Documentation/Updater/Formatters/MemberFormatter.cs
+++ b/mdoc/Mono.Documentation/Updater/Formatters/MemberFormatter.cs
@@ -336,7 +336,7 @@ namespace Mono.Documentation.Updater
}
insertNested = true;
- TypeReference declDef = decl.Resolve();
+ TypeReference declDef = decl.Resolve () ?? decl;
AppendTypeName (buf, declDef, context);
int ac = DocUtils.GetGenericArgumentCount (declDef);
int c = ac - prev;
diff --git a/mdoc/mdoc.Test/BasicTests.cs b/mdoc/mdoc.Test/BasicTests.cs
index 22328b37..6238a5a0 100644
--- a/mdoc/mdoc.Test/BasicTests.cs
+++ b/mdoc/mdoc.Test/BasicTests.cs
@@ -22,7 +22,7 @@ namespace mdoc.Test
if (!moduleCash.ContainsKey(filepath))
{
var fullpath = Path.Combine (Path.GetDirectoryName (this.GetType ().Module.Assembly.Location), filepath);
- var resolver = new ExternalAssemblyResolver ();
+ var resolver = new DotnetCoreAssemblyResolver ();
var testAssemblyPath = Path.GetDirectoryName (this.GetType ().Module.Assembly.Location);
resolver.AddSearchDirectory (testAssemblyPath);
diff --git a/mdoc/mdoc.Test/DotnetCoreAssemblyResolver.cs b/mdoc/mdoc.Test/DotnetCoreAssemblyResolver.cs
new file mode 100644
index 00000000..f22f0702
--- /dev/null
+++ b/mdoc/mdoc.Test/DotnetCoreAssemblyResolver.cs
@@ -0,0 +1,94 @@
+using Mono.Cecil;
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+namespace mdoc.Test
+{
+ // Fix DefaultAssemblyResolver don't load .NET Core Assemblies in macOS, WSL, and Ubuntu OS environment.
+ public class DotnetCoreAssemblyResolver : DefaultAssemblyResolver
+ {
+ public DotnetCoreAssemblyResolver()
+ {
+ AddDotnetCoreSearchDirectory();
+ }
+
+ private void AddDotnetCoreSearchDirectory()
+ {
+ if (Environment.OSVersion.Platform == PlatformID.Unix ||
+ Environment.OSVersion.Platform == PlatformID.MacOSX)
+ {
+ foreach (var item in GetDotnetCorePlatformAssembliesPath())
+ {
+ AddSearchDirectory(item);
+ }
+ }
+ }
+
+ private IEnumerable<string> GetDotnetCorePlatformAssembliesPath()
+ {
+ foreach (var installedSdkVersion in GetInstalledSdkVersions())
+ {
+ if (File.Exists(Path.Combine(installedSdkVersion, "System.dll")))
+ {
+ yield return installedSdkVersion;
+ }
+ }
+ }
+
+ private string[] GetInstalledSdkVersions()
+ {
+ var dotnetCorePackagesPath = GetDotnetCorePath();
+ if (Directory.Exists(dotnetCorePackagesPath))
+ {
+ return Directory.GetDirectories(dotnetCorePackagesPath);
+ }
+
+ return Array.Empty<string>();
+ }
+
+ private static string GetDotnetCorePath()
+ {
+ var dotnetCorePath = GetMacOSDotnetCorePath();
+ if (string.IsNullOrEmpty(dotnetCorePath))
+ {
+ dotnetCorePath = GetLinuxDotnetCorePath();
+ }
+
+ if (!Directory.Exists(dotnetCorePath))
+ {
+ throw new DirectoryNotFoundException($"The path of .NET Core was not found, do you have .NET Core installed? {dotnetCorePath}");
+ }
+
+ return dotnetCorePath;
+ }
+
+ private static string GetMacOSDotnetCorePath()
+ {
+ var macOSDotnetCorePath = GetAzureMacOSDotnetCorePath();
+ if (string.IsNullOrEmpty(macOSDotnetCorePath))
+ {
+ // Hard code the path of .NET Core for macOS.
+ macOSDotnetCorePath = "/usr/local/share/dotnet/shared/Microsoft.NETCore.App";
+ }
+
+ return Directory.Exists(macOSDotnetCorePath) ? macOSDotnetCorePath : string.Empty;
+ }
+
+ private static string GetAzureMacOSDotnetCorePath()
+ {
+ var azureMacOSDotnetCorePath = Environment.GetEnvironmentVariable("DOTNET_ROOT");
+ if (!string.IsNullOrEmpty(azureMacOSDotnetCorePath))
+ {
+ return Path.Combine(azureMacOSDotnetCorePath, "shared/Microsoft.NETCore.App");
+ }
+
+ return string.Empty;
+ }
+
+ private static string GetLinuxDotnetCorePath()
+ {
+ return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "dotnet/shared/Microsoft.NETCore.App");
+ }
+ }
+}
diff --git a/mdoc/mdoc.Test/ExternalAssemblyResolver.cs b/mdoc/mdoc.Test/ExternalAssemblyResolver.cs
deleted file mode 100644
index 92888e36..00000000
--- a/mdoc/mdoc.Test/ExternalAssemblyResolver.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using Mono.Cecil;
-using System.IO;
-
-namespace mdoc.Test
-{
- public class ExternalAssemblyResolver : DefaultAssemblyResolver
- {
- private const string ExternalTestAssemblyDirectory = "../../../../external/Test";
-
- public ExternalAssemblyResolver()
- {
- AddExternalSearchDirectory();
- }
-
- private void AddExternalSearchDirectory()
- {
- AddSearchDirectory(GetExternalAssemblyPath(ExternalTestAssemblyDirectory));
- }
-
- private string GetExternalAssemblyPath(string externalTestAssemblyDirectory)
- {
- return Path.Combine(Path.GetDirectoryName(this.GetType().Module.Assembly.Location), externalTestAssemblyDirectory);
- }
- }
-}
diff --git a/mdoc/mdoc.Test/mdoc.Test.csproj b/mdoc/mdoc.Test/mdoc.Test.csproj
index 11f94ee3..5daf4464 100644
--- a/mdoc/mdoc.Test/mdoc.Test.csproj
+++ b/mdoc/mdoc.Test/mdoc.Test.csproj
@@ -77,7 +77,7 @@
<Compile Include="CppWinRtMembersTests.cs" />
<Compile Include="CppWinRtFormatterTests.cs" />
<Compile Include="Enumeration\AttachedEntityTests.cs" />
- <Compile Include="ExternalAssemblyResolver.cs" />
+ <Compile Include="DotnetCoreAssemblyResolver.cs" />
<Compile Include="FrameworkIndexHelperTests.cs" />
<Compile Include="DocUtilsFSharpTests.cs" />
<Compile Include="DocUtilsTests.cs" />