Skip to content

Automate the building of libgit2 native libraries with Powershell #169

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 22, 2012

Conversation

ben
Copy link
Member

@ben ben commented Oct 26, 2012

@aroben did a wonderful job with Update-NativeBinaries.ps1.

LibGit2Sharp embeds both x86 and amd64 versions of Windows libgit2 bins in the Lib/NativeLibraries directory.

This issue should try and make the PowerShell script handle the following

  • Make it build the both x86 and amd64 versions of libgit2
  • Run the correct version of test_clar.exe according to the platform

FWIW, passing parameter -G "Visual Studio 10 Win64" to cmake will make it build an amd64 version of the library.

Notes:

  • libgit2 build script requires Python to be installed in order to generate the tests.
  • One can trigger the hybrid build on a x86 platform provided the 64-Bit Visual C++ Toolset (also available as part of the Windows SDK) is installed

@ben
Copy link
Member

ben commented Oct 26, 2012

Grabbed the script from #235. It doesn't currently run the tests, but it does:

  • Fetch libgit2
  • Checkout the sha, if it exists as a commit
  • Build 32- and 64-bit variants of the library, and copy them to
    NativeBinaries
  • Update the libgit2_sha.txt file

@nulltoken
Copy link
Member Author

@dahlbyk I've been told you would know one thing or two about PowerShell ;-) Could you please lead this review?

FWIW the latest version of @aroben's script I've found is here

@ben
Copy link
Member

ben commented Oct 29, 2012

Updated to be more like @aroben's script (thanks!). This one is quite a bit nicer.

@ben
Copy link
Member

ben commented Oct 30, 2012

Thanks for the review @dahlbyk! I've addressed the issues you brought up, and added an option to build libgit2 in the "Debug" configuration (which helps when using a debugger to figure out interop).

@dahlbyk
Copy link
Member

dahlbyk commented Oct 30, 2012

👍👍

@nulltoken
Copy link
Member Author

@ben I may need some help here.

PS D:\LibGit2Sharp> .\UpdateLibgit2ToSha.ps1 1e99ce9ac7d7a73f629327d020034e4b2ed1374c
Fetching...
` & git fetch ` failed
At D:\LibGit2Sharp\UpdateLibgit2ToSha.ps1:49 char:10
+     Throw <<<<  $error
    + CategoryInfo          : OperationStopped: (` & git fetch ` failed:String) [], RuntimeException
    + FullyQualifiedErrorId : ` & git fetch ` failed

@dahlbyk
Copy link
Member

dahlbyk commented Nov 5, 2012

ben:libgit2-update-script...dahlbyk:libgit2-update-script has a few suggestions/proposals. The first (-test) doesn't seem to actually run tests (at least I couldn't get the build to fail), but it seems like a useful addition.

@ben
Copy link
Member

ben commented Nov 5, 2012

@dahlbyk Nice! I took the liberty of rolling your changes in, and implementing the unit-test-runner.

@dahlbyk
Copy link
Member

dahlbyk commented Nov 5, 2012

Ah, so that's how you run tests... 🆒

@nulltoken
Copy link
Member Author

@ben @dahlbyk I'd happily merge this.... but...

However, I'm still encountering an issue while running the script (see above). Would you please help me troubleshoot this issue? Maybe am I lacking a prerequisite, a correctly valued environment variable, ...?

@dahlbyk
Copy link
Member

dahlbyk commented Nov 7, 2012

The fetch fails consistently through the script, but works if you cd into libgit2 and fetch on your own?

@nulltoken
Copy link
Member Author

The fetch fails consistently through the script, but works if you cd into libgit2 and fetch on your own?

That's the point.

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS D:\LibGit2Sharp> git --version
git version 1.7.11.msysgit.1
PS D:\LibGit2Sharp> .\UpdateLibgit2ToSha.ps1 a5e85d86b7e13352c553b0a43bc36fee5880b5c7
Fetching...
` & git fetch ` failed
At D:\LibGit2Sharp\UpdateLibgit2ToSha.ps1:53 char:10
+     Throw <<<<  $error
    + CategoryInfo          : OperationStopped: (` & git fetch ` failed:String) [], RuntimeException
    + FullyQualifiedErrorId : ` & git fetch ` failed

PS D:\LibGit2Sharp> git fetch
PS D:\LibGit2Sharp> git fetch origin
remote: Counting objects: 40, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 30 (delta 23), reused 30 (delta 23)
Unpacking objects: 100% (30/30), done.
From https://github.com/libgit2/libgit2sharp
 + d357ac4...d23b339 benstraub/clone -> origin/benstraub/clone  (forced update)
PS D:\LibGit2Sharp>

Then, if I type cd libgit2 and then run git fetch, it works

PS D:\LibGit2Sharp\libgit2> git remote -v
origin  http://github.com/libgit2/libgit2.git (fetch)
origin  http://github.com/libgit2/libgit2.git (push)

@ben
Copy link
Member

ben commented Nov 7, 2012

@nulltoken, try it now. Your results are kind of strange, but this script should still work if you're disconnected but still have the desired libgit2 revision in your repo.

@nulltoken
Copy link
Member Author

This is going further...

PS D:\LibGit2Sharp> .\UpdateLibgit2ToSha.ps1 8a85378829cb3bd417b04cd690da8d7d470b6214
Fetching...
Verifying 8a85378829cb3bd417b04cd690da8d7d470b6214...
trace: built-in: git 'rev-parse' '--verify' '8a85378829cb3bd417b04cd690da8d7d470b6214'
Split-Path : Cannot find drive. A drive with the name '
    trap {
        Pop-Location
        break
    }
    $cmake = Find-CMake
    $ctest = Join-Path (Split-Path -Parent $cmake) "ctest.exe"
    Write-Output "Fetching..."
    Run-Command -Quiet { & git fetch }
    Write-Output "Verifying $sha..."
    $sha = git rev-parse --verify $sha
    if ($LASTEXITCODE -ne 0) {
        $mypath = split-path -leaf $MyInvocation.MyCommand.Definition
        throw "Error' does not exist.
At D:\LibGit2Sharp\UpdateLibgit2ToSha.ps1:97 char:23
+         $mypath = split-path <<<<  -leaf $MyInvocation.MyCommand.Definition
    + CategoryInfo          : ObjectNotFound: (
    trap {
        Po...
        throw "Error:String) [Split-Path], DriveNotFoundException
    + FullyQualifiedErrorId : DriveNotFound,Microsoft.PowerShell.Commands.SplitPathCommand

Error: invalid SHA. USAGE:  <SHA>
At D:\LibGit2Sharp\UpdateLibgit2ToSha.ps1:98 char:8
+         throw <<<<  "Error: invalid SHA. USAGE: $mypath <SHA>"
    + CategoryInfo          : OperationStopped: (Error: invalid SHA. USAGE:  <SHA>:String) [], RuntimeException
    + FullyQualifiedErrorId : Error: invalid SHA. USAGE:  <SHA>

@ben
Copy link
Member

ben commented Nov 8, 2012

@nulltoken can you try it again? I think I figured out the reason for the bad error message, but all of your git commands seem to be returning non-zero, which isn't helpful.

@nulltoken
Copy link
Member Author

😿

Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.

PS D:\LibGit2Sharp> git --version
git version 1.7.11.msysgit.1
PS D:\LibGit2Sharp> .\UpdateLibgit2ToSha.ps1 8ff2b0c75983160264ee7c45a01bde27cfbc91ea
Fetching...
Verifying 8ff2b0c75983160264ee7c45a01bde27cfbc91ea...
Error: invalid SHA. USAGE: UpdateLibgit2ToSha.ps1 <SHA>
PS D:\LibGit2Sharp> cd .\libgit2
PS D:\LibGit2Sharp\libgit2> git rev-parse --verify 8ff2b0c75983160264ee7c45a01bde27cfbc91ea

8ff2b0c75983160264ee7c45a01bde27cfbc91ea
PS D:\LibGit2Sharp\libgit2> echo $LASTEXITCODE, $?
1
False
PS D:\LibGit2Sharp\libgit2>

@ben
Copy link
Member

ben commented Nov 8, 2012

Okay, @nulltoken. One more time, please include your output.

@ben
Copy link
Member

ben commented Dec 3, 2012

Maybe someone else here has seen this issue. @nulltoken has a problem where running git rev-parse development from a bash prompt returns 0, but from powershell, it sets $LASTEXITCODE to 1, and $? to false. They appear to be referring to the same git.exe.

@dahlbyk
Copy link
Member

dahlbyk commented Dec 3, 2012

(I've never seen this)

@martinwoodward
Copy link
Member

@nulltoken, Out of interest, what do you get when you run Get-Command git | Format-List ?

@nulltoken
Copy link
Member Author

@martinwoodward Sorry for the late answer

PS C:\Users\OneAmongMany> Get-Command git | Format-List


Name            : git.exe
CommandType     : Application
Definition      : C:\Program Files\Git\cmd\git.exe
Extension       : .exe
Path            : C:\Program Files\Git\cmd\git.exe
FileVersionInfo : File:             C:\Program Files\Git\cmd\git.exe
                  InternalName:
                  OriginalFilename:
                  FileVersion:
                  FileDescription:
                  Product:
                  ProductVersion:
                  Debug:            False
                  Patched:          False
                  PreRelease:       False
                  PrivateBuild:     False
                  SpecialBuild:     False
                  Language:

@nulltoken
Copy link
Member Author

@ben I've completely reinstalled my Git setup. It now works. Congrats and ❤️!

Could you please rebase and cleanup a bit the commit history?

A call to ".\UpdateLibgit2ToSha.ps1 deadbeef" will:
- Fetch libgit2
- Checkout the sha, if it exists as a commit
- Build 32- and 64-bit variants of the library, and copy them to
NativeBinaries
- Update the libgit2_sha.txt file
@ben
Copy link
Member

ben commented Dec 22, 2012

I'm so glad!

Rebased and squashed into one commit.

@nulltoken nulltoken merged commit 17e8c95 into libgit2:vNext Dec 22, 2012
@nulltoken
Copy link
Member Author

Bam! Merged in vNext

💖

@ben ben deleted the libgit2-update-script branch December 23, 2012 19:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants