From 9ed2d14adcb82441fbf080d2fc6b62c36ca47744 Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Mon, 9 Sep 2019 11:22:14 +0200 Subject: [PATCH 01/16] Linux: support broader range of distros/architectures by trying to load packed native libraries. LibGit2Sharp includes a number of native libraries that are built on different OSes. These native libraries have a dependency on OpenSSL and the system c-library. On x64, in case the Linux flavor is not known, a fallback is performed to the 'linux-x64' native library. This library is built with a dependency on OpenSSL 1.0. OpenSSL 1.0 is deprecated by OpenSSL 1.1, so on more recent version of Linux, the 'linux-x64' library fails to load. On arm64, native libraries are currently included for debian.* (OpenSSL 1.1) and ubuntu.18.04 (OpenSSL 1.0). Loading on other distros will fail. In both cases LibGit2Sharp is probably including a library that works, but the default resolution logic is not able to find it. By using the 'NativeLibrary' class (.NET Core 3.0) we can extend the resolution logic, and try to load the other native libraries that are packed with LibGit2Sharp. --- LibGit2Sharp/Core/NativeMethods.cs | 135 ++++++++++++++++++++++++++--- 1 file changed, 124 insertions(+), 11 deletions(-) diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 9fdd5db7..890df157 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -1,5 +1,6 @@ using System; using System.IO; +using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.ConstrainedExecution; using System.Runtime.InteropServices; @@ -29,25 +30,30 @@ static NativeMethods() { if (Platform.IsRunningOnNetFramework() || Platform.IsRunningOnNetCore()) { - string nativeLibraryDir = GlobalSettings.GetAndLockNativeLibraryPath(); - if (nativeLibraryDir != null) + // Use .NET Core 3.0+ NativeLibrary when available. + if (!TryUseNativeLibrary()) { - string nativeLibraryPath = Path.Combine(nativeLibraryDir, libgit2 + Platform.GetNativeLibraryExtension()); + // NativeLibrary is not available, fall back. + // Use GlobalSettings.NativeLibraryPath when set. // Try to load the .dll from the path explicitly. // If this call succeeds further DllImports will find the library loaded and not attempt to load it again. // If it fails the next DllImport will load the library from safe directories. + string nativeLibraryPath = GetGlobalSettingsNativeLibraryPath(); + if (nativeLibraryPath != null) + { #if NETFRAMEWORK - if (Platform.OperatingSystem == OperatingSystemType.Windows) + if (Platform.OperatingSystem == OperatingSystemType.Windows) #else - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) #endif - { - LoadWindowsLibrary(nativeLibraryPath); - } - else - { - LoadUnixLibrary(nativeLibraryPath, RTLD_NOW); + { + LoadWindowsLibrary(nativeLibraryPath); + } + else + { + LoadUnixLibrary(nativeLibraryPath, RTLD_NOW); + } } } } @@ -55,6 +61,113 @@ static NativeMethods() InitializeNativeLibrary(); } + private delegate bool TryLoadLibraryByNameDelegate(string libraryName, Assembly assembly, DllImportSearchPath? searchPath, out IntPtr handle); + private delegate bool TryLoadLibraryByPathDelegate(string libraryPath, out IntPtr handle); + + private static string GetGlobalSettingsNativeLibraryPath() + { + string nativeLibraryDir = GlobalSettings.GetAndLockNativeLibraryPath(); + if (nativeLibraryDir == null) + { + return null; + } + return Path.Combine(nativeLibraryDir, libgit2 + Platform.GetNativeLibraryExtension()); + } + + static TryLoadLibraryByNameDelegate _tryLoadLibraryByName; + static TryLoadLibraryByPathDelegate _tryLoadLibraryByPath; + + static bool TryLoadLibrary(string libraryName, Assembly assembly, DllImportSearchPath? searchPath, out IntPtr handle) + { + if (_tryLoadLibraryByName == null) + { + throw new NotSupportedException(); + } + return _tryLoadLibraryByName(libraryName, assembly, searchPath, out handle); + } + + static bool TryLoadLibrary(string libraryPath, out IntPtr handle) + { + if (_tryLoadLibraryByPath == null) + { + throw new NotSupportedException(); + } + return _tryLoadLibraryByPath(libraryPath, out handle); + } + + private static bool TryUseNativeLibrary() + { + // NativeLibrary is available in .NET Core 3.0+. + // We use reflection to use NativeLibrary so this library can target 'netstandard2.0'. + + Type dllImportResolverType = Type.GetType("System.Runtime.InteropServices.DllImportResolver, System.Runtime.InteropServices", throwOnError: false); + Type nativeLibraryType = Type.GetType("System.Runtime.InteropServices.NativeLibrary, System.Runtime.InteropServices", throwOnError: false); + var tryLoadLibraryByName = (TryLoadLibraryByNameDelegate)nativeLibraryType?.GetMethod("TryLoad", + new Type[] { typeof(string), typeof(Assembly), typeof(DllImportSearchPath?), typeof(IntPtr).MakeByRefType() })?.CreateDelegate(typeof(TryLoadLibraryByNameDelegate)); + var tryLoadLibraryByPath = (TryLoadLibraryByPathDelegate)nativeLibraryType?.GetMethod("TryLoad", + new Type[] { typeof(string), typeof(IntPtr).MakeByRefType() })?.CreateDelegate(typeof(TryLoadLibraryByPathDelegate)); + MethodInfo setDllImportResolver = nativeLibraryType?.GetMethod("SetDllImportResolver", new Type[] { typeof(Assembly), dllImportResolverType}); + + if (dllImportResolverType == null || + nativeLibraryType == null || + tryLoadLibraryByName == null || + tryLoadLibraryByPath == null || + setDllImportResolver == null) + { + return false; + } + + _tryLoadLibraryByPath = tryLoadLibraryByPath; + _tryLoadLibraryByName = tryLoadLibraryByName; + + // NativeMethods.SetDllImportResolver(typeof(NativeMethods).Assembly, ResolveDll); + object resolveDelegate = typeof(NativeMethods).GetMethod(nameof(ResolveDll), BindingFlags.NonPublic | BindingFlags.Static).CreateDelegate(dllImportResolverType); + setDllImportResolver.Invoke(null, new object[] { typeof(NativeMethods).Assembly, resolveDelegate }); + + return true; + } + + private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImportSearchPath? searchPath) + { + IntPtr handle = IntPtr.Zero; + if (libraryName == libgit2) + { + // Use GlobalSettings.NativeLibraryPath when set. + string nativeLibraryPath = GetGlobalSettingsNativeLibraryPath(); + if (nativeLibraryPath != null && + TryLoadLibrary(nativeLibraryPath, out handle)) + { + return handle; + } + + // Use Default DllImport resolution. + if (TryLoadLibrary(libraryName, assembly, searchPath, out handle)) + { + return handle; + } + + // We cary a number of .so files for Linux which are linked against various + // libc/OpenSSL libraries. Try them out. + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + // The libraries are located at 'runtimes//native/lib{libraryName}.so' + // The ends with the processor architecture. e.g. fedora-x64. + + string assemblyDirectory = Path.GetDirectoryName(typeof(NativeMethods).Assembly.Location); + string processorArchitecture = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(); + foreach (var runtimeFolder in Directory.GetDirectories(Path.Combine(assemblyDirectory, "runtimes"), $"*-{processorArchitecture}")) + { + string libPath = Path.Combine(runtimeFolder, "native", $"lib{libraryName}.so"); + if (TryLoadLibrary(libPath, out handle)) + { + return handle; + } + } + } + } + return handle; + } + public const int RTLD_NOW = 0x002; [DllImport("libdl", EntryPoint = "dlopen")] From 5b7e4e1756499dd990edcb255aee9b13f1a0d4ea Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Sat, 20 Apr 2019 20:17:49 -0400 Subject: [PATCH 02/16] Clean up project files --- LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 6 ++---- LibGit2Sharp/LibGit2Sharp.csproj | 8 +++----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index c31cb947..320a3fd9 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -21,13 +21,11 @@ - + - - PreserveNewest - + diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index c5000ebf..128bfe75 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -22,14 +22,12 @@ - - TextTemplatingFileGenerator - Objects.cs - - + + + From 4f3ed6518234dd8692d3cce7988e78f244534445 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Thu, 30 Jan 2020 13:02:28 -0700 Subject: [PATCH 03/16] Update to .NET SDK 3.1.100 --- LibGit2Sharp/LibGit2Sharp.csproj | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 128bfe75..69215040 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -14,6 +14,8 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb true ..\libgit2sharp.snk + square-logo.png + MIT @@ -22,6 +24,7 @@ + @@ -33,17 +36,10 @@ - + - - - https://raw.githubusercontent.com/mendix/libgit2sharp/master/square-logo.png - https://raw.githubusercontent.com/mendix/libgit2sharp/master/LICENSE.md - - - From 652b034fa3d99f1cb18cbf60c28ad9c057907719 Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Sat, 15 Feb 2020 14:09:33 -0700 Subject: [PATCH 04/16] Link to embedded license --- LibGit2Sharp/LibGit2Sharp.csproj | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 69215040..fbdf553d 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -15,7 +15,7 @@ true ..\libgit2sharp.snk square-logo.png - MIT + App_Readme/LICENSE.md @@ -25,9 +25,9 @@ - - - + + + From 6bf66f944f4e3b25faac007aa30e435b378eaf3d Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Sat, 20 Apr 2019 19:41:19 -0400 Subject: [PATCH 05/16] Update testing packages --- LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 13 +++++++------ appveyor.yml | 4 ++-- buildandtest.cmd | 2 +- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index 320a3fd9..a82c3e92 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -11,12 +11,13 @@ - - - - - - + + + + + + + diff --git a/appveyor.yml b/appveyor.yml index 6d5eebaf..d0cbdbe9 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -90,7 +90,7 @@ test_script: { .\packages\OpenCover\tools\OpenCover.Console.exe ` -register:user ` - "-target:""$Env:userprofile\.nuget\packages\xunit.runner.console\2.4.0\tools\net46\$runner""" ` + "-target:""$Env:userprofile\.nuget\packages\xunit.runner.console\2.4.1\tools\net46\$runner""" ` "-targetargs:""$Env:APPVEYOR_BUILD_FOLDER\bin\LibGit2Sharp.Tests\Release\net46\LibGit2Sharp.Tests.dll"" -noshadow" ` "-filter:+[LibGit2Sharp]* -[LibGit2Sharp.Tests]*" ` -hideskipped:All ` @@ -98,7 +98,7 @@ test_script: } ElseIf ($Env:SHOULD_RUN_COVERITY_ANALYSIS -eq $False) { - & "$Env:userprofile\.nuget\packages\xunit.runner.console\2.4.0\tools\net46\$runner" ` + & "$Env:userprofile\.nuget\packages\xunit.runner.console\2.4.1\tools\net46\$runner" ` "$Env:APPVEYOR_BUILD_FOLDER\bin\LibGit2Sharp.Tests\Release\net46\LibGit2Sharp.Tests.dll" -noshadow } } diff --git a/buildandtest.cmd b/buildandtest.cmd index 3bc1d665..6b4b37d5 100644 --- a/buildandtest.cmd +++ b/buildandtest.cmd @@ -31,7 +31,7 @@ dotnet build "%~dp0\" /v:minimal /nologo /property:ExtraDefine="%EXTRADEFINE%" @IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL% :: Run tests on Desktop and CoreCLR -"%userprofile%\.nuget\packages\xunit.runner.console\2.4.0\tools\net452\xunit.console.exe" "%~dp0bin\LibGit2Sharp.Tests\%Configuration%\net46\LibGit2Sharp.Tests.dll" -noshadow +"%userprofile%\.nuget\packages\xunit.runner.console\2.4.1\tools\net46\xunit.console.exe" "%~dp0bin\LibGit2Sharp.Tests\%Configuration%\net46\LibGit2Sharp.Tests.dll" -noshadow @IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL% dotnet test "%~dp0LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj" -f netcoreapp2.0 --no-restore --no-build @IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL% From 410d11a912ac6251670cf07d5049129a09f73cc3 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Sat, 20 Apr 2019 20:00:06 -0400 Subject: [PATCH 06/16] Move to netcoreapp2.1 for tests --- LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 4 ++-- appveyor.yml | 2 +- buildandtest.cmd | 2 +- buildandtest.sh | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index a82c3e92..a0703f6f 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -1,7 +1,7 @@  - net46;netcoreapp2.0 + net46;netcoreapp2.1 @@ -42,4 +42,4 @@ - + \ No newline at end of file diff --git a/appveyor.yml b/appveyor.yml index d0cbdbe9..3db8b2b8 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -103,7 +103,7 @@ test_script: } } -- dotnet test LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj -f netcoreapp2.0 --no-restore --no-build +- dotnet test LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj -f netcoreapp2.1 --no-restore --no-build after_test: - ps: | diff --git a/buildandtest.cmd b/buildandtest.cmd index 6b4b37d5..612161b8 100644 --- a/buildandtest.cmd +++ b/buildandtest.cmd @@ -33,7 +33,7 @@ dotnet build "%~dp0\" /v:minimal /nologo /property:ExtraDefine="%EXTRADEFINE%" :: Run tests on Desktop and CoreCLR "%userprofile%\.nuget\packages\xunit.runner.console\2.4.1\tools\net46\xunit.console.exe" "%~dp0bin\LibGit2Sharp.Tests\%Configuration%\net46\LibGit2Sharp.Tests.dll" -noshadow @IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL% -dotnet test "%~dp0LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj" -f netcoreapp2.0 --no-restore --no-build +dotnet test "%~dp0LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj" -f netcoreapp2.1 --no-restore --no-build @IF ERRORLEVEL 1 EXIT /B %ERRORLEVEL% EXIT /B %ERRORLEVEL% diff --git a/buildandtest.sh b/buildandtest.sh index a5501a04..24994cda 100755 --- a/buildandtest.sh +++ b/buildandtest.sh @@ -15,7 +15,7 @@ export Configuration=release # On linux we don't pack because we can't build for net40. # We just build for CoreCLR and run tests for it. dotnet restore -dotnet build LibGit2Sharp.Tests -f netcoreapp2.0 -property:ExtraDefine="$EXTRADEFINE" -fl -flp:verbosity=detailed -dotnet test LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj -f netcoreapp2.0 --no-restore --no-build +dotnet build LibGit2Sharp.Tests -f netcoreapp2.1 -property:ExtraDefine="$EXTRADEFINE" -fl -flp:verbosity=detailed +dotnet test LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj -f netcoreapp2.1 --no-restore --no-build exit $? From b9f8145b213758655fd04aa905581afd9efeb3c7 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Sat, 20 Apr 2019 20:50:32 -0400 Subject: [PATCH 07/16] Disable shadow copying so all tests pass in VS runner --- LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 4 +--- LibGit2Sharp.Tests/xunit.runner.json | 4 ++++ 2 files changed, 5 insertions(+), 3 deletions(-) create mode 100644 LibGit2Sharp.Tests/xunit.runner.json diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index a0703f6f..3503801c 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -23,10 +23,8 @@ - - - + diff --git a/LibGit2Sharp.Tests/xunit.runner.json b/LibGit2Sharp.Tests/xunit.runner.json new file mode 100644 index 00000000..e54567a3 --- /dev/null +++ b/LibGit2Sharp.Tests/xunit.runner.json @@ -0,0 +1,4 @@ +{ + "$schema": "https://xunit.github.io/schema/current/xunit.runner.schema.json", + "shadowCopy": false +} From e102c8f498cee7438673d8ea9d577613468ec17c Mon Sep 17 00:00:00 2001 From: Tom Deseyn Date: Mon, 9 Sep 2019 16:51:29 +0200 Subject: [PATCH 08/16] Fix netfx build --- LibGit2Sharp/Core/NativeMethods.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 890df157..e4a95004 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -61,9 +61,6 @@ static NativeMethods() InitializeNativeLibrary(); } - private delegate bool TryLoadLibraryByNameDelegate(string libraryName, Assembly assembly, DllImportSearchPath? searchPath, out IntPtr handle); - private delegate bool TryLoadLibraryByPathDelegate(string libraryPath, out IntPtr handle); - private static string GetGlobalSettingsNativeLibraryPath() { string nativeLibraryDir = GlobalSettings.GetAndLockNativeLibraryPath(); @@ -74,6 +71,9 @@ private static string GetGlobalSettingsNativeLibraryPath() return Path.Combine(nativeLibraryDir, libgit2 + Platform.GetNativeLibraryExtension()); } + private delegate bool TryLoadLibraryByNameDelegate(string libraryName, Assembly assembly, DllImportSearchPath? searchPath, out IntPtr handle); + private delegate bool TryLoadLibraryByPathDelegate(string libraryPath, out IntPtr handle); + static TryLoadLibraryByNameDelegate _tryLoadLibraryByName; static TryLoadLibraryByPathDelegate _tryLoadLibraryByPath; @@ -146,13 +146,14 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor return handle; } +#if NETFRAMEWORK +#else // We cary a number of .so files for Linux which are linked against various // libc/OpenSSL libraries. Try them out. if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { // The libraries are located at 'runtimes//native/lib{libraryName}.so' // The ends with the processor architecture. e.g. fedora-x64. - string assemblyDirectory = Path.GetDirectoryName(typeof(NativeMethods).Assembly.Location); string processorArchitecture = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(); foreach (var runtimeFolder in Directory.GetDirectories(Path.Combine(assemblyDirectory, "runtimes"), $"*-{processorArchitecture}")) @@ -164,6 +165,7 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor } } } +#endif } return handle; } From 0c04f6013b357019db834c7916e6f2cd619d22dd Mon Sep 17 00:00:00 2001 From: Frederik Carlier Date: Sat, 16 Nov 2019 22:22:31 +0100 Subject: [PATCH 09/16] Check whether the runtimes directory exists before accessing it --- LibGit2Sharp/Core/NativeMethods.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index e4a95004..7a9f0df8 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -156,12 +156,17 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor // The ends with the processor architecture. e.g. fedora-x64. string assemblyDirectory = Path.GetDirectoryName(typeof(NativeMethods).Assembly.Location); string processorArchitecture = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(); - foreach (var runtimeFolder in Directory.GetDirectories(Path.Combine(assemblyDirectory, "runtimes"), $"*-{processorArchitecture}")) + string runtimesDirectory = Path.Combine(assemblyDirectory, "runtimes"); + + if (Directory.Exists(runtimesDirectory)) { - string libPath = Path.Combine(runtimeFolder, "native", $"lib{libraryName}.so"); - if (TryLoadLibrary(libPath, out handle)) + foreach (var runtimeFolder in Directory.GetDirectories(runtimesDirectory, $"*-{processorArchitecture}")) { - return handle; + string libPath = Path.Combine(runtimeFolder, "native", $"lib{libraryName}.so"); + if (TryLoadLibrary(libPath, out handle)) + { + return handle; + } } } } From 290787a58178be6ba00f38682c5974d7e09a6c80 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Sat, 30 May 2020 15:11:10 -0400 Subject: [PATCH 10/16] Move to only netstandard2.0 target --- LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 10 +-- LibGit2Sharp/Core/NativeMethods.cs | 7 -- LibGit2Sharp/Core/Platform.cs | 86 +------------------ LibGit2Sharp/GlobalSettings.cs | 13 +-- LibGit2Sharp/LibGit2Sharp.csproj | 2 +- .../x64/NativeLibraryLoadTestApp.x64.csproj | 2 +- .../x86/NativeLibraryLoadTestApp.x86.csproj | 2 +- 7 files changed, 12 insertions(+), 110 deletions(-) diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index 3503801c..b670e712 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -1,17 +1,17 @@  - net46;netcoreapp2.1 + net472;netcoreapp2.1 - - + + - + @@ -22,7 +22,7 @@ - + diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index 7a9f0df8..51c6ee14 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -42,11 +42,7 @@ static NativeMethods() string nativeLibraryPath = GetGlobalSettingsNativeLibraryPath(); if (nativeLibraryPath != null) { -#if NETFRAMEWORK - if (Platform.OperatingSystem == OperatingSystemType.Windows) -#else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) -#endif { LoadWindowsLibrary(nativeLibraryPath); } @@ -146,8 +142,6 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor return handle; } -#if NETFRAMEWORK -#else // We cary a number of .so files for Linux which are linked against various // libc/OpenSSL libraries. Try them out. if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) @@ -170,7 +164,6 @@ private static IntPtr ResolveDll(string libraryName, Assembly assembly, DllImpor } } } -#endif } return handle; } diff --git a/LibGit2Sharp/Core/Platform.cs b/LibGit2Sharp/Core/Platform.cs index 52859cbe..e8d53647 100644 --- a/LibGit2Sharp/Core/Platform.cs +++ b/LibGit2Sharp/Core/Platform.cs @@ -13,30 +13,11 @@ internal enum OperatingSystemType internal static class Platform { public static string ProcessorArchitecture => IntPtr.Size == 8 ? "x64" : "x86"; -#if NETFRAMEWORK - private static bool? _isRunningOnMac; - private static bool IsRunningOnMac() => _isRunningOnMac ?? (_isRunningOnMac = TryGetIsRunningOnMac()) ?? false; -#endif public static OperatingSystemType OperatingSystem { get { -#if NETFRAMEWORK - var platform = (int)Environment.OSVersion.Platform; - if (platform <= 3 || platform == 5) - { - return OperatingSystemType.Windows; - } - if (IsRunningOnMac()) - { - return OperatingSystemType.MacOSX; - } - if (platform == 4 || platform == 6 || platform == 128) - { - return OperatingSystemType.Unix; - } -#else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { return OperatingSystemType.Windows; @@ -51,7 +32,7 @@ public static OperatingSystemType OperatingSystem { return OperatingSystemType.MacOSX; } -#endif + throw new PlatformNotSupportedException(); } } @@ -90,70 +71,5 @@ public static bool IsRunningOnNetFramework() /// public static bool IsRunningOnNetCore() => typeof(object).Assembly.GetName().Name != "mscorlib"; - -#if NETFRAMEWORK -#pragma warning disable IDE1006 // Naming Styles - [DllImport("libc")] - private static extern int sysctlbyname( - [MarshalAs(UnmanagedType.LPStr)] string property, - IntPtr output, - IntPtr oldLen, - IntPtr newp, - uint newlen); -#pragma warning restore IDE1006 // Naming Styles - - private static bool TryGetIsRunningOnMac() - { - const string OsType = "kern.ostype"; - const string MacOsType = "Darwin"; - - return MacOsType == GetOsType(); - - string GetOsType() - { - try - { - IntPtr - pointerLength = IntPtr.Zero, - pointerString = IntPtr.Zero; - - try - { - pointerLength = Marshal.AllocHGlobal(sizeof(int)); - - sysctlbyname(OsType, IntPtr.Zero, pointerLength, IntPtr.Zero, 0); - - var length = Marshal.ReadInt32(pointerLength); - - if (length <= 0) - { - return string.Empty; - } - - pointerString = Marshal.AllocHGlobal(length); - - sysctlbyname(OsType, pointerString, pointerLength, IntPtr.Zero, 0); - - return Marshal.PtrToStringAnsi(pointerString); - } - finally - { - if (pointerLength != IntPtr.Zero) - { - Marshal.FreeHGlobal(pointerLength); - } - if (pointerString != IntPtr.Zero) - { - Marshal.FreeHGlobal(pointerString); - } - } - } - catch - { - return null; - } - } - } -#endif } } diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs index f71646e7..56b02655 100644 --- a/LibGit2Sharp/GlobalSettings.cs +++ b/LibGit2Sharp/GlobalSettings.cs @@ -71,20 +71,13 @@ private static string GetExecutingAssemblyDirectory() /// Returns information related to the current LibGit2Sharp /// library. /// - public static Version Version - { - get - { - return version.Value; - } - } + public static Version Version => version.Value; /// /// Registers a new as a custom - /// smart-protocol transport with libgit2. Any Git remote with + /// smart-protocol transport with libgit2. Any Git remote with /// the scheme registered will delegate to the given transport - /// for all communication with the server. use this transport to communicate - /// with the server This is not commonly + /// for all communication with the server. This is not commonly /// used: some callers may want to re-use an existing connection to /// perform fetch / push operations to a remote. /// diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index fbdf553d..83b615bf 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -1,7 +1,7 @@  - netstandard2.0;net46 + netstandard2.0 true LibGit2Sharp brings all the might and speed of libgit2, a native Git implementation, to the managed world of .Net and Mono. LibGit2Sharp contributors diff --git a/NativeLibraryLoadTestApp/x64/NativeLibraryLoadTestApp.x64.csproj b/NativeLibraryLoadTestApp/x64/NativeLibraryLoadTestApp.x64.csproj index 5fb7e1b0..3bca18b3 100644 --- a/NativeLibraryLoadTestApp/x64/NativeLibraryLoadTestApp.x64.csproj +++ b/NativeLibraryLoadTestApp/x64/NativeLibraryLoadTestApp.x64.csproj @@ -2,7 +2,7 @@ Exe - net46 + net472 x64 diff --git a/NativeLibraryLoadTestApp/x86/NativeLibraryLoadTestApp.x86.csproj b/NativeLibraryLoadTestApp/x86/NativeLibraryLoadTestApp.x86.csproj index c7bef05c..0596f203 100644 --- a/NativeLibraryLoadTestApp/x86/NativeLibraryLoadTestApp.x86.csproj +++ b/NativeLibraryLoadTestApp/x86/NativeLibraryLoadTestApp.x86.csproj @@ -2,7 +2,7 @@ Exe - net46 + net472 x86 From c9cb52453b9dba5f5e2e6aa587f06ee39be56925 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Sat, 20 Apr 2019 21:36:59 -0400 Subject: [PATCH 11/16] Update version test to account for GitVersioning change --- LibGit2Sharp.Tests/GlobalSettingsFixture.cs | 8 ++++---- LibGit2Sharp/Version.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs index 381d13d6..55260a6f 100644 --- a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs +++ b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs @@ -22,9 +22,9 @@ public void CanGetMinimumCompiledInFeatures() public void CanRetrieveValidVersionString() { // Version string format is: - // Major.Minor.Patch[-previewTag]+g{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features) + // Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features) // Example output: - // "0.25.0-preview.52+g871d13a67f.libgit2-15e1193 (x86 - Threads, Https)" + // "0.25.0-preview.52+871d13a67f.libgit2-15e1193 (x86 - Threads, Https)" string versionInfo = GlobalSettings.Version.ToString(); @@ -33,14 +33,14 @@ public void CanRetrieveValidVersionString() // git2SharpHash: '871d13a67f' LibGit2Sharp hash. // arch: 'x86' or 'x64' libgit2 target. // git2Features: 'Threads, Ssh' libgit2 features compiled with. - string regex = @"^(?\d+\.\d+\.\d+(-[\w\-\.]+)?\+(g(?[a-f0-9]{10})\.)?libgit2-[a-f0-9]{7}) \((?\w+) - (?(?:\w*(?:, )*\w+)*)\)$"; + string regex = @"^(?\d+\.\d+\.\d+(-[\w\-\.]+)?\+((?[a-f0-9]{10})\.)?libgit2-[a-f0-9]{7}) \((?\w+) - (?(?:\w*(?:, )*\w+)*)\)$"; Assert.NotNull(versionInfo); Match regexResult = Regex.Match(versionInfo, regex); Assert.True(regexResult.Success, "The following version string format is enforced:" + - "Major.Minor.Patch[-previewTag]+g{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features). " + + "Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features). " + "But found \"" + versionInfo + "\" instead."); } diff --git a/LibGit2Sharp/Version.cs b/LibGit2Sharp/Version.cs index 747529e8..3795382a 100644 --- a/LibGit2Sharp/Version.cs +++ b/LibGit2Sharp/Version.cs @@ -55,7 +55,7 @@ private string RetrieveAbbrevShaFrom(string sha) /// /// /// The format of the version number is as follows: - /// Major.Minor.Patch[-previewTag]+g{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features) + /// Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features) /// /// public override string ToString() From 01b04379e3c8bf4206b25abb8eaf4e209e5065ac Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Thu, 12 Dec 2019 02:04:12 +0000 Subject: [PATCH 12/16] CommitFixture: use valid tree/commit libgit2 validates objects when signing; update our test to use a valid commit and tree object. --- LibGit2Sharp.Tests/CommitFixture.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/LibGit2Sharp.Tests/CommitFixture.cs b/LibGit2Sharp.Tests/CommitFixture.cs index 5533b723..f555e787 100644 --- a/LibGit2Sharp.Tests/CommitFixture.cs +++ b/LibGit2Sharp.Tests/CommitFixture.cs @@ -1058,8 +1058,8 @@ public void CanPrettifyAMessage() } private readonly string signedCommit = - "tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6\n" + - "parent 34734e478d6cf50c27c9d69026d93974d052c454\n" + + "tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n" + + "parent 8496071c1b46c854b31185ea97743be6a8774479\n" + "author Ben Burkert 1358451456 -0800\n" + "committer Ben Burkert 1358451456 -0800\n" + "gpgsig -----BEGIN PGP SIGNATURE-----\n" + @@ -1102,8 +1102,8 @@ public void CanPrettifyAMessage() "-----END PGP SIGNATURE-----"; private readonly string signedData = - "tree 6b79e22d69bf46e289df0345a14ca059dfc9bdf6\n" + - "parent 34734e478d6cf50c27c9d69026d93974d052c454\n" + + "tree 4b825dc642cb6eb9a060e54bf8d69288fbee4904\n" + + "parent 8496071c1b46c854b31185ea97743be6a8774479\n" + "author Ben Burkert 1358451456 -0800\n" + "committer Ben Burkert 1358451456 -0800\n" + "\n" + @@ -1155,7 +1155,7 @@ public void CanCreateACommitString() [Fact] public void CanCreateASignedCommit() { - string repoPath = InitNewRepository(); + string repoPath = SandboxStandardTestRepo(); using (var repo = new Repository(repoPath)) { var odb = repo.ObjectDatabase; From e706a66fa9d326981b0ec4f037bd03453f4c7818 Mon Sep 17 00:00:00 2001 From: Alexander Ovchinnikov <56644701+A-Ovchinnikov-mx@users.noreply.github.com> Date: Tue, 1 Jun 2021 14:27:21 +0200 Subject: [PATCH 13/16] Delete Travis, AppVeyor and Azure Pipelines CI --- .travis.yml | 35 ---------- appveyor.yml | 156 -------------------------------------------- azure-pipelines.yml | 25 ------- 3 files changed, 216 deletions(-) delete mode 100644 .travis.yml delete mode 100644 appveyor.yml delete mode 100644 azure-pipelines.yml diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 58886b70..00000000 --- a/.travis.yml +++ /dev/null @@ -1,35 +0,0 @@ -# Travis-CI Build for libgit2sharp -# see travis-ci.org for details - -language: csharp -dist: trusty -dotnet: 2.1.401 -mono: none -osx_image: xcode8.3 - -os: - - osx - - linux - -before_install: - - date -u - - uname -a - - env | sort - -install: - - git fetch --unshallow - -# Build libgit2, LibGit2Sharp and run the tests -script: - - ./buildandtest.sh 'LEAKS_IDENTIFYING' - -# Only watch the development branch -branches: - only: - - master - - /^maint.*/ - -# Notify of build changes -notifications: - email: - - emeric.fermas@gmail.com diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index 3db8b2b8..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,156 +0,0 @@ -version: '{build}' - -os: Visual Studio 2017 - -branches: - only: - - master - - /^maint.*/ - -configuration: release - -skip_tags: true - -nuget: - disable_publish_on_pr: true - -environment: - coveralls_token: - secure: ixIsBslo9NheDb5lJknF58EYdgvZ0r3/L0ecRiXjfXmjHBLvoSU6/ZRwaMM+BAlG - coverity_token: - secure: nuzUT+HecXGIi3KaPd/1hgFEZJan/j6+oNbPV75JKjk= - coverity_email: - secure: eGVilNg1Yuq+Xj+SW8r3WCtjnzhoDV0sNJkma4NRq7A= - matrix: - - publish_on_success: False - ExtraDefine: LEAKS_IDENTIFYING - - publish_on_success: True - -matrix: - fast_finish: true - -install: -- ps: | - Write-Host "Commit being built = " -NoNewLine - Write-Host $Env:APPVEYOR_REPO_COMMIT -ForegroundColor "Green" - Write-Host "Target branch = " -NoNewLine - Write-Host $Env:APPVEYOR_REPO_BRANCH -ForegroundColor "Green" - Write-Host "Is a Pull Request = " -NoNewLine - Write-Host $($Env:APPVEYOR_PULL_REQUEST_NUMBER -ne $null) -ForegroundColor "Green" - - $CommitDate = [DateTime]::Parse($Env:APPVEYOR_REPO_COMMIT_TIMESTAMP) - $BuildDate = $CommitDate.ToUniversalTime().ToString("yyyyMMddHHmmss") - Write-Host "Merge commit UTC timestamp = " -NoNewLine - Write-Host $BuildDate -ForegroundColor "Green" - - $Env:SHOULD_RUN_COVERITY_ANALYSIS = $($Env:APPVEYOR_SCHEDULED_BUILD -eq $True) - Write-Host "Should run Coverity analysis = " -NoNewLine - Write-Host $Env:SHOULD_RUN_COVERITY_ANALYSIS -ForegroundColor "Green" - - $Env:SHOULD_RUN_COVERALLS = $($Env:APPVEYOR_SCHEDULED_BUILD -eq $True) - Write-Host "Should run Coveralls = " -NoNewLine - Write-Host $Env:SHOULD_RUN_COVERALLS -ForegroundColor "Green" - - Write-Host "Identifying leaks = " -NoNewLine - Write-Host ($Env:ExtraDefine -eq "LEAKS_IDENTIFYING") -ForegroundColor "Green" - - Write-Host "Should publish on success = " -NoNewLine - Write-Host $Env:publish_on_success -ForegroundColor "Green" - - If ($Env:SHOULD_RUN_COVERALLS -eq $True) - { - nuget install OpenCover -Version 4.6.166 -ExcludeVersion -OutputDirectory .\packages - nuget install coveralls.net -Version 0.6.0 -ExcludeVersion -OutputDirectory .\packages - } - - If ($Env:SHOULD_RUN_COVERITY_ANALYSIS -eq $True) - { - cinst curl -y - } - -before_build: -- ps: | - msbuild "$Env:APPVEYOR_BUILD_FOLDER\LibGit2Sharp.sln" ` - /nologo /verbosity:quiet ` - /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" ` - /t:restore - -build_script: -- ps: | - & cov-build.exe --dir cov-int msbuild "$Env:APPVEYOR_BUILD_FOLDER\LibGit2Sharp.sln" ` - /nologo /verbosity:minimal /fl /flp:verbosity=normal ` - /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" ` - /t:build,pack - -test_script: -- ps: | - Foreach ($runner in 'xunit.console.exe','xunit.console.x86.exe') - { - If ($Env:SHOULD_RUN_COVERALLS -eq $True -and $Env:publish_on_success -eq $True) - { - .\packages\OpenCover\tools\OpenCover.Console.exe ` - -register:user ` - "-target:""$Env:userprofile\.nuget\packages\xunit.runner.console\2.4.1\tools\net46\$runner""" ` - "-targetargs:""$Env:APPVEYOR_BUILD_FOLDER\bin\LibGit2Sharp.Tests\Release\net46\LibGit2Sharp.Tests.dll"" -noshadow" ` - "-filter:+[LibGit2Sharp]* -[LibGit2Sharp.Tests]*" ` - -hideskipped:All ` - -output:opencoverCoverage.xml - } - ElseIf ($Env:SHOULD_RUN_COVERITY_ANALYSIS -eq $False) - { - & "$Env:userprofile\.nuget\packages\xunit.runner.console\2.4.1\tools\net46\$runner" ` - "$Env:APPVEYOR_BUILD_FOLDER\bin\LibGit2Sharp.Tests\Release\net46\LibGit2Sharp.Tests.dll" -noshadow - } - } - -- dotnet test LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj -f netcoreapp2.1 --no-restore --no-build - -after_test: -- ps: | - If ($Env:SHOULD_RUN_COVERALLS -eq $True -and $Env:publish_on_success -eq $True) - { - Write-Host "Uploading code coverage result..." -ForegroundColor "Green" - - .\packages\coveralls.net\tools\csmacnz.Coveralls.exe ` - --opencover -i opencoverCoverage.xml ` - --repoToken $Env:coveralls_token ` - --useRelativePaths ` - --basePath "$Env:APPVEYOR_BUILD_FOLDER\"` - } - - If ($Env:SHOULD_RUN_COVERITY_ANALYSIS -eq $True -and $Env:publish_on_success -eq $True) - { - 7z a "$Env:APPVEYOR_BUILD_FOLDER\$Env:APPVEYOR_PROJECT_NAME.zip" "$Env:APPVEYOR_BUILD_FOLDER\cov-int\" - - # cf. http://stackoverflow.com/a/25045154/335418 - Remove-item alias:curl - - Write-Host "Uploading Coverity analysis result..." -ForegroundColor "Green" - - curl --silent --show-error ` - --output curl-out.txt ` - --form token="$Env:coverity_token" ` - --form email="$Env:coverity_email" ` - --form "file=@$Env:APPVEYOR_BUILD_FOLDER\$Env:APPVEYOR_PROJECT_NAME.zip" ` - --form version="$Env:APPVEYOR_REPO_COMMIT" ` - --form description="CI server scheduled build." ` - https://scan.coverity.com/builds?project=libgit2%2Flibgit2sharp - - cat .\curl-out.txt - } - -on_finish: -- ps: Push-AppveyorArtifact "msbuild.log" - -on_success: -- ps: | - if ($Env:publish_on_success -eq $True) - { - Get-ChildItem "bin\LibGit2Sharp\$env:configuration\*.nupkg" |% { Push-AppveyorArtifact $_.FullName -FileName $_.Name } - } - -notifications: -- provider: Email - to: - - emeric.fermas@gmail.com - on_build_status_changed: true diff --git a/azure-pipelines.yml b/azure-pipelines.yml deleted file mode 100644 index 5d703aad..00000000 --- a/azure-pipelines.yml +++ /dev/null @@ -1,25 +0,0 @@ -trigger: -- master -- maint/* - -variables: - solution: '**/*.sln' - buildPlatform: 'Any CPU' - buildConfiguration: 'Release' - -jobs: -- job: Windows - pool: - vmImage: 'VS2017-Win2016' - steps: - - script: buildandtest.cmd -- job: Linux - pool: - vmImage: 'Ubuntu 16.04' - steps: - - script: ./buildandtest.sh -- job: macOS - pool: - vmImage: 'macOS 10.13' - steps: - - script: ./buildandtest.sh From c9275695cca4dd2a85638d8bbbfeb0c945542ff7 Mon Sep 17 00:00:00 2001 From: Alexander Ovchinnikov <56644701+A-Ovchinnikov-mx@users.noreply.github.com> Date: Wed, 2 Jun 2021 01:23:14 +0200 Subject: [PATCH 14/16] Enable loading arm64 libgit2 --- LibGit2Sharp.Tests/GlobalSettingsFixture.cs | 6 +++--- LibGit2Sharp/Core/Platform.cs | 23 ++++++++++++++++++++- LibGit2Sharp/GlobalSettings.cs | 2 +- LibGit2Sharp/LibGit2Sharp.csproj | 2 +- LibGit2Sharp/Version.cs | 2 +- 5 files changed, 28 insertions(+), 7 deletions(-) diff --git a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs index 55260a6f..4fbed0c7 100644 --- a/LibGit2Sharp.Tests/GlobalSettingsFixture.cs +++ b/LibGit2Sharp.Tests/GlobalSettingsFixture.cs @@ -22,7 +22,7 @@ public void CanGetMinimumCompiledInFeatures() public void CanRetrieveValidVersionString() { // Version string format is: - // Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features) + // Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64|arm64 - features) // Example output: // "0.25.0-preview.52+871d13a67f.libgit2-15e1193 (x86 - Threads, Https)" @@ -31,7 +31,7 @@ public void CanRetrieveValidVersionString() // The GlobalSettings.Version returned string should contain : // version: '0.25.0[-previewTag]' LibGit2Sharp version number. // git2SharpHash: '871d13a67f' LibGit2Sharp hash. - // arch: 'x86' or 'x64' libgit2 target. + // arch: 'x86', 'x64' or 'arm64' libgit2 target. // git2Features: 'Threads, Ssh' libgit2 features compiled with. string regex = @"^(?\d+\.\d+\.\d+(-[\w\-\.]+)?\+((?[a-f0-9]{10})\.)?libgit2-[a-f0-9]{7}) \((?\w+) - (?(?:\w*(?:, )*\w+)*)\)$"; @@ -40,7 +40,7 @@ public void CanRetrieveValidVersionString() Match regexResult = Regex.Match(versionInfo, regex); Assert.True(regexResult.Success, "The following version string format is enforced:" + - "Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features). " + + "Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64|arm64 - features). " + "But found \"" + versionInfo + "\" instead."); } diff --git a/LibGit2Sharp/Core/Platform.cs b/LibGit2Sharp/Core/Platform.cs index e8d53647..aab4b8f1 100644 --- a/LibGit2Sharp/Core/Platform.cs +++ b/LibGit2Sharp/Core/Platform.cs @@ -12,7 +12,28 @@ internal enum OperatingSystemType internal static class Platform { - public static string ProcessorArchitecture => IntPtr.Size == 8 ? "x64" : "x86"; + public static string ProcessorArchitecture + { + get + { + if (RuntimeInformation.ProcessArchitecture == Architecture.X86) + { + return "x86"; + } + + if (RuntimeInformation.ProcessArchitecture == Architecture.X64) + { + return "x64"; + } + + if (RuntimeInformation.ProcessArchitecture == Architecture.Arm64) + { + return "arm64"; + } + + throw new PlatformNotSupportedException(); + } + } public static OperatingSystemType OperatingSystem { diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs index 56b02655..ee43efc1 100644 --- a/LibGit2Sharp/GlobalSettings.cs +++ b/LibGit2Sharp/GlobalSettings.cs @@ -159,7 +159,7 @@ public static LogConfiguration LogConfiguration /// /// Sets a path for loading native binaries on .NET Framework or .NET Core. /// When specified, native library will first be searched under the given path. - /// On .NET Framework a subdirectory corresponding to the architecture ("x86" or "x64") is appended, + /// On .NET Framework a subdirectory corresponding to the architecture ("x86", "x64" or "arm64") is appended, /// otherwise the native library is expected to be found in the directory as specified. /// /// If the library is not found it will be searched in standard search paths: diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 83b615bf..2b78ba4d 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -34,7 +34,7 @@ - + diff --git a/LibGit2Sharp/Version.cs b/LibGit2Sharp/Version.cs index 3795382a..7d64ae57 100644 --- a/LibGit2Sharp/Version.cs +++ b/LibGit2Sharp/Version.cs @@ -55,7 +55,7 @@ private string RetrieveAbbrevShaFrom(string sha) /// /// /// The format of the version number is as follows: - /// Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64 - features) + /// Major.Minor.Patch[-previewTag]+{LibGit2Sharp_abbrev_hash}.libgit2-{libgit2_abbrev_hash} (x86|x64|arm64 - features) /// /// public override string ToString() From b82cd4c8456b38878bd4f5d3a80780c51632ca92 Mon Sep 17 00:00:00 2001 From: Alexander Ovchinnikov <56644701+A-Ovchinnikov-mx@users.noreply.github.com> Date: Wed, 2 Jun 2021 14:36:37 +0200 Subject: [PATCH 15/16] Bump version --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 1d058541..a9d8c893 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/AArnott/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.110.11", + "version": "1.110.20", "cloudBuild": { "buildNumber": { "enabled": true From f154641a2fab4ca5f7ad74b71348a3698323b21f Mon Sep 17 00:00:00 2001 From: Alexander Ovchinnikov <56644701+A-Ovchinnikov-mx@users.noreply.github.com> Date: Wed, 2 Jun 2021 15:05:39 +0200 Subject: [PATCH 16/16] Use .NET 5.0 for tests --- LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj | 8 ++++---- LibGit2Sharp/LibGit2Sharp.csproj | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj index b670e712..d45756f4 100644 --- a/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj +++ b/LibGit2Sharp.Tests/LibGit2Sharp.Tests.csproj @@ -1,13 +1,13 @@  - net472;netcoreapp2.1 + net472;net5.0 - - + + @@ -22,7 +22,7 @@ - + diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 2b78ba4d..7625c654 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -36,7 +36,7 @@ - +