diff options
author | nulltoken <emeric.fermas@gmail.com> | 2012-03-31 20:25:19 +0400 |
---|---|---|
committer | nulltoken <emeric.fermas@gmail.com> | 2012-04-01 01:01:10 +0400 |
commit | 2ca19130998281001615901598cc600e5d6dbbcd (patch) | |
tree | 0ee4ce0eee5dacbf4afee2972ef454283e1d486e | |
parent | 412010c9316301bb3f7b588bf61018141bd41d9f (diff) |
Add Repository.Version static property
This property returns a string containing the LibGit2Sharp version number, the commit hash it's been built against (if available), the libgit2 commit hash and the processor architecture.
-rw-r--r-- | CI-build.msbuild | 9 | ||||
-rw-r--r-- | LibGit2Sharp/Core/NativeMethods.cs | 16 | ||||
-rw-r--r-- | LibGit2Sharp/LibGit2Sharp.csproj | 6 | ||||
-rw-r--r-- | LibGit2Sharp/Repository.cs | 40 | ||||
-rw-r--r-- | LibGit2Sharp/libgit2_hash.txt | 1 | ||||
-rw-r--r-- | LibGit2Sharp/libgit2sharp_hash.txt | 1 | ||||
-rw-r--r-- | build.libgit2sharp.cmd | 3 | ||||
-rw-r--r-- | nuget.package/build.nuget.package.cmd | 3 |
8 files changed, 74 insertions, 5 deletions
diff --git a/CI-build.msbuild b/CI-build.msbuild index 5bb49e15..4dc2ca43 100644 --- a/CI-build.msbuild +++ b/CI-build.msbuild @@ -9,7 +9,14 @@ <UsingTask AssemblyFile="$(MSBuildProjectDirectory)/Lib/xUnit/xunit.runner.msbuild.dll" TaskName="Xunit.Runner.MSBuild.xunit" /> <Target Name="Clean"> - <!-- Workaround for xbuild --> + <Message Text="Commit SHA = $(CommitSha)" /> + + <WriteLinesToFile Condition="'$(CommitSha)' != ''" + File="$(RootDir)\LibGit2Sharp\libgit2sharp_hash.txt" + Lines="$(CommitSha)" + Overwrite="true" /> + + <!-- Workaround for xbuild --> <Exec Condition=" ('$(OS)' != 'Windows_NT') " Command=" rm -r -f $(DeployFolder) " /> <Exec Condition=" ('$(OS)' != 'Windows_NT') " Command=" rm -r -f $(TestBuildDir) " /> diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs index a9864750..9778d306 100644 --- a/LibGit2Sharp/Core/NativeMethods.cs +++ b/LibGit2Sharp/Core/NativeMethods.cs @@ -18,8 +18,7 @@ namespace LibGit2Sharp.Core { string originalAssemblypath = new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath; - //TODO: When amd64 version of libgit2.dll is available, value this depending of the size of an IntPtr - const string currentArchSubPath = "NativeBinaries/x86"; + string currentArchSubPath = "NativeBinaries/" + ProcessorArchitecture; string path = Path.Combine(Path.GetDirectoryName(originalAssemblypath), currentArchSubPath); @@ -37,6 +36,19 @@ namespace LibGit2Sharp.Core git_threads_shutdown(); } + public static string ProcessorArchitecture + { + get + { + //TODO: When amd64 version of libgit2.dll is available, uncomment the following lines + //if (IntPtr.Size == 8) + //{ + // return "amd64"; + //} + + return "x86"; + } + } private static bool IsRunningOnLinux() { // see http://mono-project.com/FAQ%3a_Technical#Mono_Platforms diff --git a/LibGit2Sharp/LibGit2Sharp.csproj b/LibGit2Sharp/LibGit2Sharp.csproj index 3f3b2a23..042125cc 100644 --- a/LibGit2Sharp/LibGit2Sharp.csproj +++ b/LibGit2Sharp/LibGit2Sharp.csproj @@ -132,6 +132,12 @@ <ItemGroup> <CodeAnalysisDictionary Include="CustomDictionary.xml" /> </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="libgit2_hash.txt" /> + </ItemGroup> + <ItemGroup> + <EmbeddedResource Include="libgit2sharp_hash.txt" /> + </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <PropertyGroup> <PreBuildEvent> diff --git a/LibGit2Sharp/Repository.cs b/LibGit2Sharp/Repository.cs index b2c35db3..e44f1d06 100644 --- a/LibGit2Sharp/Repository.cs +++ b/LibGit2Sharp/Repository.cs @@ -1,5 +1,7 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Reflection; using LibGit2Sharp.Core; using LibGit2Sharp.Core.Compat; using LibGit2Sharp.Core.Handles; @@ -22,6 +24,7 @@ namespace LibGit2Sharp private readonly Lazy<RepositoryInformation> info; private readonly bool isBare; private readonly List<SafeHandleBase> handlesToCleanup = new List<SafeHandleBase>(); + private static readonly Lazy<string> versionRetriever = new Lazy<string>(RetrieveVersion); /// <summary> /// Initializes a new instance of the <see cref = "Repository" /> class. @@ -356,5 +359,42 @@ namespace LibGit2Sharp { handlesToCleanup.Add(handleToCleanup); } + + /// <summary> + /// Gets the current LibGit2Sharp version. + /// <para> + /// The format of the version number is as follows: + /// <para>Major.Minor.Patch-LibGit2Sharp_abbrev_hash-libgit2_abbrev_hash (x86|amd64)</para> + /// </para> + /// </summary> + public static string Version + { + get { return versionRetriever.Value; } + } + + private static string RetrieveVersion() + { + Assembly assembly = typeof(Repository).Assembly; + + Version version = assembly.GetName().Version; + + string libgit2Hash = ReadContentFromResource(assembly, "libgit2_hash.txt"); + string libgit2sharpHash = ReadContentFromResource(assembly, "libgit2sharp_hash.txt"); + + return string.Format("{0}-{1}-{2} ({3})", + version.ToString(3), + libgit2sharpHash.Substring(0, 7), + libgit2Hash.Substring(0,7), + NativeMethods.ProcessorArchitecture + ); + } + + private static string ReadContentFromResource(Assembly assembly, string partialResourceName) + { + using (var sr = new StreamReader(assembly.GetManifestResourceStream(string.Format("LibGit2Sharp.{0}", partialResourceName)))) + { + return sr.ReadLine(); + } + } } } diff --git a/LibGit2Sharp/libgit2_hash.txt b/LibGit2Sharp/libgit2_hash.txt new file mode 100644 index 00000000..dab8956f --- /dev/null +++ b/LibGit2Sharp/libgit2_hash.txt @@ -0,0 +1 @@ +a17e882fab4e190d5a052cbc9cf6a238a9166a7c diff --git a/LibGit2Sharp/libgit2sharp_hash.txt b/LibGit2Sharp/libgit2sharp_hash.txt new file mode 100644 index 00000000..0faec602 --- /dev/null +++ b/LibGit2Sharp/libgit2sharp_hash.txt @@ -0,0 +1 @@ +unknown diff --git a/build.libgit2sharp.cmd b/build.libgit2sharp.cmd index bca19e16..f1d19c36 100644 --- a/build.libgit2sharp.cmd +++ b/build.libgit2sharp.cmd @@ -3,8 +3,9 @@ SETLOCAL SET BASEDIR=%~dp0 SET FrameworkVersion=v4.0.30319 SET FrameworkDir=%SystemRoot%\Microsoft.NET\Framework +SET CommitSha=%~1 -"%FrameworkDir%\%FrameworkVersion%\msbuild.exe" "%BASEDIR%CI-build.msbuild" +"%FrameworkDir%\%FrameworkVersion%\msbuild.exe" "%BASEDIR%CI-build.msbuild" /property:CommitSha=%CommitSha% ENDLOCAL diff --git a/nuget.package/build.nuget.package.cmd b/nuget.package/build.nuget.package.cmd index 0a498a31..e36c3f15 100644 --- a/nuget.package/build.nuget.package.cmd +++ b/nuget.package/build.nuget.package.cmd @@ -1,6 +1,7 @@ SETLOCAL SET BASEDIR=%~dp0 SET SRCDIR=%BASEDIR%..\LibGit2Sharp\ +SET CommitSha=%~1 REM the nuspec file needs to be next to the csproj, so copy it there during the pack operation COPY "%BASEDIR%LibGit2Sharp.nuspec" "%SRCDIR%" @@ -9,7 +10,7 @@ PUSHD "%BASEDIR%" DEL *.nupkg -CMD /c "..\build.libgit2sharp.cmd" +CMD /c "..\build.libgit2sharp.cmd %CommitSha%" IF %ERRORLEVEL% NEQ 0 GOTO EXIT |