Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

LibGit2Sharp update to 0.26.0 (2) #1713

Merged
merged 8 commits into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,24 @@ Task("Copy-Files")
MSBuildSettings = parameters.MSBuildSettings
});

DotNetCorePublish("./src/GitVersionTask/GitVersionTask.csproj", new DotNetCorePublishSettings
{
Framework = parameters.FullFxVersion,
NoBuild = true,
NoRestore = true,
Configuration = parameters.Configuration,
MSBuildSettings = parameters.MSBuildSettings
});

// .NET Core
DotNetCorePublish("./src/GitVersionTask/GitVersionTask.csproj", new DotNetCorePublishSettings
{
Framework = parameters.CoreFxVersion,
NoBuild = true,
NoRestore = true,
Configuration = parameters.Configuration,
MSBuildSettings = parameters.MSBuildSettings
});
var ilMergeDir = parameters.Paths.Directories.ArtifactsBinFullFxILMerge;
var portableDir = parameters.Paths.Directories.ArtifactsBinFullFxPortable.Combine("tools");
var cmdlineDir = parameters.Paths.Directories.ArtifactsBinFullFxCmdline.Combine("tools");
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

</PropertyGroup>
<PropertyGroup>
<PackageVersion_LibGit2Sharp>0.25.0-preview-0033</PackageVersion_LibGit2Sharp>
<PackageVersion_LibGit2Sharp>0.26.0</PackageVersion_LibGit2Sharp>
<PackageVersion_JetBrainsAnnotations>2019.1.1</PackageVersion_JetBrainsAnnotations>
<PackageVersion_YamlDotNet>6.1.1</PackageVersion_YamlDotNet>
</PropertyGroup>
Expand Down
4 changes: 0 additions & 4 deletions src/Docker/net472/linux/debian-9/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ FROM mono:5.14
LABEL maintainers="GitTools Maintainers"
ARG contentFolder

RUN sed -i '/jessie-updates/d' /etc/apt/sources.list && apt-get update && \
apt-get install -y libgit2-dev && \
ln -s /usr/lib/x86_64-linux-gnu/libgit2.so /lib/x86_64-linux-gnu/libgit2-15e1193.so

WORKDIR /app
COPY $contentFolder/ ./

Expand Down
8 changes: 3 additions & 5 deletions src/Docker/netcoreapp2.1/linux/centos-7/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
FROM centos:7
LABEL maintainers="GitTools Maintainers"

ENV DOTNET_VERSION='2.1'
ENV DOTNET_VERSION='2.1'
ARG contentFolder

# https://dotnet.microsoft.com/download/linux-package-manager/rhel/sdk-current
RUN rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm \
&& yum update cache

# if you need SDK use dotnet-sdk-$DOTNET_VERSION
RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64 unzip libgit2-devel.x86_64 \
RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64 \
&& yum clean all \
&& rm -rf /tmp/*

RUN ln -s /usr/lib64/libgit2.so /usr/lib64/libgit2-15e1193.so

WORKDIR /app
COPY $contentFolder/ ./

ENTRYPOINT ["dotnet", "GitVersion.dll"]
ENTRYPOINT ["dotnet", "GitVersion.dll"]
4 changes: 0 additions & 4 deletions src/Docker/netcoreapp2.1/linux/debian-9/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ FROM mcr.microsoft.com/dotnet/core/runtime:2.1
LABEL maintainers="GitTools Maintainers"
ARG contentFolder

RUN apt-get update && \
apt-get install -y libgit2-dev && \
ln -s /usr/lib/x86_64-linux-gnu/libgit2.so /lib/x86_64-linux-gnu/libgit2-15e1193.so

WORKDIR /app
COPY $contentFolder/ ./

Expand Down
10 changes: 4 additions & 6 deletions src/Docker/netcoreapp2.1/linux/fedora-27/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
FROM fedora:27
LABEL maintainers="GitTools Maintainers"

ENV DOTNET_VERSION='2.1'
ENV DOTNET_VERSION='2.1'
ARG contentFolder

# https://dotnet.microsoft.com/download/linux-package-manager/rhel/sdk-current
RUN rpm -Uvh https://packages.microsoft.com/config/fedora/27/packages-microsoft-prod.rpm
RUN rpm -Uvh https://packages.microsoft.com/config/fedora/27/packages-microsoft-prod.rpm

# if you need SDK use dotnet-sdk-$DOTNET_VERSION
RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64 unzip libgit2-devel.x86_64 \
RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64\
&& yum clean all \
&& rm -rf /tmp/*

RUN ln -s /usr/lib64/libgit2.so /usr/lib64/libgit2-15e1193.so

WORKDIR /app
COPY $contentFolder/ ./

ENTRYPOINT ["dotnet", "GitVersion.dll"]
ENTRYPOINT ["dotnet", "GitVersion.dll"]
4 changes: 1 addition & 3 deletions src/Docker/netcoreapp2.2/linux/centos-7/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,10 @@ RUN rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-pro
&& yum update cache

# if you need SDK use dotnet-sdk-$DOTNET_VERSION
RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64 unzip libgit2-devel.x86_64 \
RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64 \
&& yum clean all \
&& rm -rf /tmp/*

RUN ln -s /usr/lib64/libgit2.so /usr/lib64/libgit2-15e1193.so

WORKDIR /app
COPY $contentFolder/ ./

Expand Down
4 changes: 0 additions & 4 deletions src/Docker/netcoreapp2.2/linux/debian-9/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ FROM mcr.microsoft.com/dotnet/core/runtime:2.2
LABEL maintainers="GitTools Maintainers"
ARG contentFolder

RUN apt-get update && \
apt-get install -y libgit2-dev && \
ln -s /usr/lib/x86_64-linux-gnu/libgit2.so /lib/x86_64-linux-gnu/libgit2-15e1193.so

WORKDIR /app
COPY $contentFolder/ ./

Expand Down
6 changes: 2 additions & 4 deletions src/Docker/netcoreapp2.2/linux/fedora-27/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@ ENV DOTNET_VERSION='2.2'
ARG contentFolder

# https://dotnet.microsoft.com/download/linux-package-manager/rhel/sdk-current
RUN rpm -Uvh https://packages.microsoft.com/config/fedora/27/packages-microsoft-prod.rpm
RUN rpm -Uvh https://packages.microsoft.com/config/fedora/27/packages-microsoft-prod.rpm

# if you need SDK use dotnet-sdk-$DOTNET_VERSION
RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64 unzip libgit2-devel.x86_64 \
RUN yum install -y dotnet-runtime-$DOTNET_VERSION.x86_64 \
&& yum clean all \
&& rm -rf /tmp/*

RUN ln -s /usr/lib64/libgit2.so /usr/lib64/libgit2-15e1193.so

WORKDIR /app
COPY $contentFolder/ ./

Expand Down
6 changes: 6 additions & 0 deletions src/GitVersion.sln
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitVersionTask", "GitVersio
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitVersion.Tool", "GitVersionExe\GitVersion.Tool.csproj", "{929263FD-5CD2-42E1-BF3D-E0C1B0320DA4}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GitVersionTask.MsBuild", "GitVersionTask.MsBuild\GitVersionTask.MsBuild.csproj", "{0F1AEC4E-E81D-4F84-B2E8-3415A1A4DBF4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -68,6 +70,10 @@ Global
{929263FD-5CD2-42E1-BF3D-E0C1B0320DA4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{929263FD-5CD2-42E1-BF3D-E0C1B0320DA4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{929263FD-5CD2-42E1-BF3D-E0C1B0320DA4}.Release|Any CPU.Build.0 = Release|Any CPU
{0F1AEC4E-E81D-4F84-B2E8-3415A1A4DBF4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0F1AEC4E-E81D-4F84-B2E8-3415A1A4DBF4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0F1AEC4E-E81D-4F84-B2E8-3415A1A4DBF4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0F1AEC4E-E81D-4F84-B2E8-3415A1A4DBF4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
1 change: 1 addition & 0 deletions src/GitVersionCore.Tests/Mocks/MockRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ public IQueryableCommitLog Commits
public ObjectDatabase ObjectDatabase { get; set; }
public NoteCollection Notes { get; set; }
public SubmoduleCollection Submodules { get; set; }
public WorktreeCollection Worktrees { get; set; }
public Rebase Rebase { get; private set; }

public Ignore Ignore
Expand Down
21 changes: 21 additions & 0 deletions src/GitVersionTask.MsBuild/GitVersionTask.MsBuild.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net461;netstandard2.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="15.9.20" />
<PackageReference Include="Microsoft.Build.Tasks.Core" Version="15.9.20" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="2.1.0" />
</ItemGroup>

<ItemGroup>
<InternalsVisibleTo Include="GitVersionTask" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\GitVersionCore\GitVersionCore.csproj" />
</ItemGroup>

</Project>
13 changes: 13 additions & 0 deletions src/GitVersionTask.MsBuild/GitVersionTaskBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace GitVersionTask.MsBuild
{
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;

public abstract class GitVersionTaskBase : Task
{
[Required]
public string SolutionDirectory { get; set; }

public bool NoFetch { get; set; }
}
}
87 changes: 87 additions & 0 deletions src/GitVersionTask.MsBuild/LibGit2Sharp/GitLoaderContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// This code originally copied from https://raw.githubusercontent.com/dotnet/sourcelink/master/src/Microsoft.Build.Tasks.Git/GitLoaderContext.cs
#if !NET461
namespace GitVersionTask.MsBuild.LibGit2Sharp
{
using System;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Loader;
using RuntimeEnvironment = Microsoft.DotNet.PlatformAbstractions.RuntimeEnvironment;

public sealed class GitLoaderContext : AssemblyLoadContext
{
private readonly string[] assemblies;
public static GitLoaderContext Instance { get; private set; }

private GitLoaderContext(string[] assemblies) => this.assemblies = assemblies;

public static void Init(params string[] assemblies) => Instance = new GitLoaderContext(assemblies);

protected override Assembly Load(AssemblyName assemblyName)
{
if (assemblies.Contains(assemblyName.Name))
{
var path = Path.Combine(Path.GetDirectoryName(typeof(GitLoaderContext).Assembly.Location), assemblyName.Name + ".dll");
return LoadFromAssemblyPath(path);
}

return Default.LoadFromAssemblyName(assemblyName);
}

protected override IntPtr LoadUnmanagedDll(string unmanagedDllName)
{
var modulePtr = IntPtr.Zero;

if (unmanagedDllName.StartsWith("git2-", StringComparison.Ordinal) ||
unmanagedDllName.StartsWith("libgit2-", StringComparison.Ordinal))
{
var directory = GetNativeLibraryDirectory();
var extension = GetNativeLibraryExtension();

if (!unmanagedDllName.EndsWith(extension, StringComparison.Ordinal))
{
unmanagedDllName += extension;
}

var nativeLibraryPath = Path.Combine(directory, unmanagedDllName);
if (!File.Exists(nativeLibraryPath))
{
nativeLibraryPath = Path.Combine(directory, "lib" + unmanagedDllName);
}

modulePtr = LoadUnmanagedDllFromPath(nativeLibraryPath);
}

return modulePtr != IntPtr.Zero ? modulePtr : base.LoadUnmanagedDll(unmanagedDllName);
}

private static string GetNativeLibraryDirectory()
{
var dir = Path.GetDirectoryName(typeof(GitLoaderContext).Assembly.Location);
return Path.Combine(dir, "runtimes", RuntimeIdMap.GetNativeLibraryDirectoryName(RuntimeEnvironment.GetRuntimeIdentifier()), "native");
}

private static string GetNativeLibraryExtension()
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
return ".dll";
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
return ".dylib";
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return ".so";
}

throw new PlatformNotSupportedException();
}
}
}
#endif
90 changes: 90 additions & 0 deletions src/GitVersionTask.MsBuild/LibGit2Sharp/LibGit2SharpLoader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// This code originally copied and adapted from https://raw.githubusercontent.com/dotnet/sourcelink/master/src/Microsoft.Build.Tasks.Git/TaskImplementation.cs

namespace GitVersionTask.MsBuild.LibGit2Sharp
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

public class LibGit2SharpLoader
{
private static string taskDirectory;

public static LibGit2SharpLoader Instance { get; private set; }
public Assembly Assembly { get; }

public static void LoadAssembly(string tasksAssembly) => Instance = new LibGit2SharpLoader(tasksAssembly);

private LibGit2SharpLoader(string tasksAssembly)
{
taskDirectory = Path.GetDirectoryName(typeof(LibGit2SharpLoader).Assembly.Location);
#if NET461
nullVersion = new Version(0, 0, 0, 0);
loaderLog = new List<string>();

AppDomain.CurrentDomain.AssemblyResolve += AssemblyResolve;

var assemblyName = typeof(LibGit2SharpLoader).Assembly.GetName();
assemblyName.Name = tasksAssembly;
Assembly = Assembly.Load(assemblyName);
#else
var operationsPath = Path.Combine(taskDirectory, tasksAssembly + ".dll");
Assembly = GitLoaderContext.Instance.LoadFromAssemblyPath(operationsPath);
#endif
}


#if NET461

private static Version nullVersion;

private static List<string> loaderLog;

private static void Log(ResolveEventArgs args, string outcome)
{
lock (loaderLog)
{
loaderLog.Add($"Loading '{args.Name}' referenced by '{args.RequestingAssembly}': {outcome}.");
}
}

public static string[] GetLog()
{
lock (loaderLog)
{
return loaderLog.ToArray();
}
}

private static Assembly AssemblyResolve(object sender, ResolveEventArgs args)
{
// Limit resolution scope to minimum to affect the rest of msbuild as little as possible.
// Only resolve System.* assemblies from the task directory that are referenced with 0.0.0.0 version (from netstandard.dll).

var referenceName = new AssemblyName(args.Name);
if (!referenceName.Name.StartsWith("System.", StringComparison.OrdinalIgnoreCase))
{
Log(args, "not System");
return null;
}

if (referenceName.Version != nullVersion)
{
Log(args, "not null version");
return null;
}

var referencePath = Path.Combine(taskDirectory, referenceName.Name + ".dll");
if (!File.Exists(referencePath))
{
Log(args, $"file '{referencePath}' not found");
return null;
}

Log(args, $"loading from '{referencePath}'");
return Assembly.Load(AssemblyName.GetAssemblyName(referencePath));
}
#endif
}
}
Loading