Skip to content

Commit b11adc4

Browse files
committed
Merge remote-tracking branch 'origin/master' into pr/440-update-libgit2sharp-to-support-alpine-3-9-rid
2 parents 3c6bb73 + d383815 commit b11adc4

File tree

5 files changed

+79
-9
lines changed

5 files changed

+79
-9
lines changed

src/Cake.GitVersioning/Cake.GitVersioning.csproj

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
<PackageIcon>cake-contrib-medium.png</PackageIcon>
1414
<PackageProjectUrl>http://github.com/dotnet/Nerdbank.GitVersioning</PackageProjectUrl>
1515
<SignAssembly>false</SignAssembly>
16-
<!-- We include the whole OutputPath in this tools package. -->
17-
<IncludeBuildOutput>false</IncludeBuildOutput>
16+
1817
<TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);PackBuildOutputs</TargetsForTfmSpecificContentInPackage>
18+
<LibGit2SharpNativeBinaries>$(NuGetPackageRoot)libgit2sharp.nativebinaries\$(LibGit2SharpNativeVersion)\</LibGit2SharpNativeBinaries>
19+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
1920
</PropertyGroup>
2021

2122
<!-- This is a tools package and should express no dependencies. -->
@@ -36,6 +37,15 @@
3637

3738
<ItemGroup>
3839
<None Include="cake-contrib-medium.png" Pack="true" PackagePath="" />
40+
41+
<!-- Include native binaries -->
42+
<None Include="$(LibGit2SharpNativeBinaries)runtimes\**\*.*" Pack="true" PackagePath="lib\netstandard2.0\lib\" LinkBase="lib" />
43+
44+
<!-- Additional copies to work around DllNotFoundException on Mono (https://github.com/AArnott/Nerdbank.GitVersioning/issues/222) -->
45+
<None Include="$(LibGit2SharpNativeBinaries)runtimes\osx\native\*.dylib" Pack="true" PackagePath="lib\netstandard2.0\lib\osx\" LinkBase="lib\osx" />
46+
<None Include="$(LibGit2SharpNativeBinaries)runtimes\linux-x64\native\*.so" Pack="true" PackagePath="lib\netstandard2.0\lib\linux\x86_64\" LinkBase="lib\linux\x86_64" />
47+
<None Include="$(LibGit2SharpNativeBinaries)runtimes\win-x64\native\*.dll" Pack="true" PackagePath="lib\netstandard2.0\lib\win32\x64\" LinkBase="lib\win32\x64" />
48+
<None Include="$(LibGit2SharpNativeBinaries)runtimes\win-x86\native\*.dll" Pack="true" PackagePath="lib\netstandard2.0\lib\win32\x86\" LinkBase="lib\win32\x86" />
3949
</ItemGroup>
4050

4151
<ItemGroup>
@@ -44,9 +54,21 @@
4454

4555
<Target Name="PackBuildOutputs" DependsOnTargets="SatelliteDllsProjectOutputGroup;DebugSymbolsProjectOutputGroup">
4656
<ItemGroup>
47-
<TfmSpecificPackageFile Include="$(OutputPath)\**\*" Exclude="$(OutputPath)\**\*.xml;$(OutputPath)\**\*.pdb;$(OutputPath)\**\Cake.Core.dll">
48-
<PackagePath>lib\$(TargetFramework)\</PackagePath>
57+
<TfmSpecificPackageFile
58+
Include="
59+
$(OutputPath)LibGit2Sharp.dll*;
60+
$(OutputPath)Nerdbank.GitVersioning.*dll;
61+
$(OutputPath)Newtonsoft.Json.dll;
62+
$(OutputPath)Validation.dll;
63+
"
64+
65+
Exclude="
66+
$(OutputPath)Microsoft.*.dll
67+
$(OutputPath)System.*.dll
68+
"
69+
>
70+
<PackagePath>lib\$(TargetFramework)</PackagePath>
4971
</TfmSpecificPackageFile>
5072
</ItemGroup>
5173
</Target>
52-
</Project>
74+
</Project>

src/Cake.GitVersioning/GitVersioningAliases.cs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77
namespace Cake.GitVersioning
88
{
9+
using System;
10+
using System.Linq;
11+
12+
using Validation;
13+
914
/// <summary>
1015
/// Contains functionality for using Nerdbank.GitVersioning.
1116
/// </summary>
@@ -30,7 +35,35 @@ public static VersionOracle GitVersioningGetVersion(this ICakeContext context, s
3035
{
3136
var fullProjectDirectory = (new DirectoryInfo(projectDirectory)).FullName;
3237

33-
GitExtensions.HelpFindLibGit2NativeBinaries(Path.GetDirectoryName(Assembly.GetAssembly(typeof(GitVersioningAliases)).Location));
38+
string directoryName = Path.GetDirectoryName(Assembly.GetAssembly(typeof(GitVersioningAliases)).Location);
39+
40+
if (string.IsNullOrWhiteSpace(directoryName))
41+
{
42+
throw new InvalidOperationException("Could not locate the Cake.GitVersioning library");
43+
}
44+
45+
// Even after adding the folder containing the native libgit2 DLL to the PATH, DllNotFoundException is still thrown
46+
// Workaround this by copying the contents of the found folder to the current directory
47+
GitExtensions.HelpFindLibGit2NativeBinaries(directoryName, out var attemptedDirectory);
48+
49+
// The HelpFindLibGit2NativeBinaries method throws if the directory does not exist
50+
var directoryInfo = new DirectoryInfo(attemptedDirectory);
51+
52+
// There should only be a single file in the directory, but we do not know its extension
53+
// So, we will just get a list of all files rather than trying to determine the correct name and extension
54+
// If there are other files there for some reason, it should not matter as long as we don't overwrite anything in the current directory
55+
var fileInfos = directoryInfo.GetFiles();
56+
57+
foreach (var fileInfo in fileInfos)
58+
{
59+
// Copy the file to the Cake.GitVersioning DLL directory, without overwriting anything
60+
string destFileName = Path.Combine(directoryName, fileInfo.Name);
61+
62+
if (!File.Exists(destFileName))
63+
{
64+
File.Copy(fileInfo.FullName, destFileName);
65+
}
66+
}
3467

3568
return VersionOracle.Create(fullProjectDirectory, null, CloudBuild.Active);
3669
}

src/Directory.Build.props

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
<EmbedUntrackedSources>true</EmbedUntrackedSources>
2020
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
2121
</PropertyGroup>
22+
<PropertyGroup>
23+
<!-- LibGit2Sharp Native Binary version - used in both main project and Cake addin -->
24+
<LibGit2SharpNativeVersion>2.0.306</LibGit2SharpNativeVersion>
25+
</PropertyGroup>
2226
<ItemGroup>
2327
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" PrivateAssets="All" />
2428
</ItemGroup>

src/NerdBank.GitVersioning/GitExtensions.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,18 @@ public static IEnumerable<Commit> GetCommitsFromVersion(this Repository repo, Ve
353353
/// <exception cref="ArgumentException">Thrown if the provided path does not lead to an existing directory.</exception>
354354
public static void HelpFindLibGit2NativeBinaries(string basePath)
355355
{
356-
if (!TryHelpFindLibGit2NativeBinaries(basePath, out string attemptedDirectory))
356+
HelpFindLibGit2NativeBinaries(basePath, out string _);
357+
}
358+
359+
/// <summary>
360+
/// Assists the operating system in finding the appropriate native libgit2 module.
361+
/// </summary>
362+
/// <param name="basePath">The path to the directory that contains the lib folder.</param>
363+
/// <param name="attemptedDirectory">Receives the directory that native binaries are expected.</param>
364+
/// <exception cref="ArgumentException">Thrown if the provided path does not lead to an existing directory.</exception>
365+
public static void HelpFindLibGit2NativeBinaries(string basePath, out string attemptedDirectory)
366+
{
367+
if (!TryHelpFindLibGit2NativeBinaries(basePath, out attemptedDirectory))
357368
{
358369
throw new ArgumentException($"Unable to find native binaries under directory: \"{attemptedDirectory}\".");
359370
}
@@ -366,7 +377,7 @@ public static void HelpFindLibGit2NativeBinaries(string basePath)
366377
/// <returns><c>true</c> if the libgit2 native binaries have been found; <c>false</c> otherwise.</returns>
367378
public static bool TryHelpFindLibGit2NativeBinaries(string basePath)
368379
{
369-
return TryHelpFindLibGit2NativeBinaries(basePath, out string attemptedDirectory);
380+
return TryHelpFindLibGit2NativeBinaries(basePath, out string _);
370381
}
371382

372383
/// <summary>

src/Nerdbank.GitVersioning.Tasks/Nerdbank.GitVersioning.Tasks.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<Target Name="SetNuSpecProperties" BeforeTargets="GenerateNuspec" DependsOnTargets="GetBuildVersion">
2020
<PropertyGroup>
21-
<LibGit2SharpNativeBinaries>$(NuGetPackageRoot)libgit2sharp.nativebinaries\2.0.306\</LibGit2SharpNativeBinaries>
21+
<LibGit2SharpNativeBinaries>$(NuGetPackageRoot)libgit2sharp.nativebinaries\$(LibGit2SharpNativeVersion)\</LibGit2SharpNativeBinaries>
2222
<NuspecProperties>$(NuspecProperties);Version=$(Version);commit=$(GitCommitId);BaseOutputPath=$(OutputPath);LibGit2SharpNativeBinaries=$(LibGit2SharpNativeBinaries)</NuspecProperties>
2323
</PropertyGroup>
2424
</Target>

0 commit comments

Comments
 (0)