Welcome to mirror list, hosted at ThFree Co, Russian Federation.

build.libgit2.ps1 - github.com/mono/libgit-binary.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2f1bca8f61becfb606616ea27e3e5e65488e2ab1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<#
.SYNOPSIS
    Builds a version of libgit2 and copies it to the nuget packaging directory.
.PARAMETER vs
    Version of Visual Studio project files to generate. Cmake supports "10", "11" and "12" (default).
#>

Param(
    [string]$vs = '12'
)

Set-StrictMode -Version Latest

$projectDirectory = Split-Path $MyInvocation.MyCommand.Path
$libgit2Directory = Join-Path $projectDirectory "external\libgit2"
$x86Directory = Join-Path $projectDirectory "windows"
#$x64Directory = Join-Path $projectDirectory "windows64"
$hashFile = Join-Path $projectDirectory "libgit2_hash.txt"
$sha = Get-Content $hashFile 
$binaryFilename = "git2-" + $sha.Substring(0,7)
$configuration = "RelWithDebInfo"

function Run-Command([scriptblock]$Command, [switch]$Fatal, [switch]$Quiet) {
    $output = ""
    if ($Quiet) {
        $output = & $Command 2>&1
    } else {
        & $Command
    }

    if (!$Fatal) {
        return
    }

    $exitCode = 0
    if ($LastExitCode -ne 0) {
        $exitCode = $LastExitCode
    } elseif (!$?) {
        $exitCode = 1
    } else {
        return
    }

    $error = "``$Command`` failed"
    if ($output) {
        Write-Host -ForegroundColor yellow $output
        $error += ". See output above."
    }
    Throw $error
}

function Find-CMake {
    # Look for cmake.exe in $Env:PATH.
    $cmake = @(Get-Command cmake.exe)[0] 2>$null
    if ($cmake) {
        $cmake = $cmake.Definition
    } else {
        # Look for the highest-versioned cmake.exe in its default location.
        $cmake = @(Resolve-Path (Join-Path ${Env:ProgramFiles(x86)} "CMake *\bin\cmake.exe"))
        if ($cmake) {
            $cmake = $cmake[-1].Path
        }
    }
    if (!$cmake) {
        throw "Error: Can't find cmake.exe"
    }
    $cmake
}

function Ensure-Property($expected, $propertyValue, $propertyName, $path) {
    if ($propertyValue -eq $expected) {
        return
    }

    throw "Error: Invalid '$propertyName' property in generated '$path' (Expected: $expected - Actual: $propertyValue)"
}

function Assert-Consistent-Naming($expected, $path) {
    $dll = get-item $path

    Ensure-Property $expected $dll.Name "Name" $dll.Fullname
    Ensure-Property $expected $dll.VersionInfo.InternalName "VersionInfo.InternalName" $dll.Fullname
    Ensure-Property $expected $dll.VersionInfo.OriginalFilename "VersionInfo.OriginalFilename" $dll.Fullname
}

function Check-Newer-Binaries {
    $old = Get-Item "$x86Directory\*.dll"
    $oldSha = $old.Name.Substring("git2-".Length).Substring(0, 7)
    try {
        Push-Location $libgit2Directory
        & git merge-base --is-ancestor $sha $oldSha
        if ($LastExitCode -eq 0) {
            Write-Output "Binaries are newer in the output directory."
            Exit
        }
    } finally {
        Pop-Location
    }
}

if (Test-Path(Join-Path $x86Directory "$binaryFilename.dll")) {
    Write-Output "Binaries are the same as in output directory."
    Exit
}

Check-Newer-Binaries

try {
    Push-Location $libgit2Directory

    $cmake = Find-CMake

    Write-Output "Building 32-bit..."
    Run-Command { & remove-item build -recurse -force }
    Run-Command { & mkdir build }
    cd build
    Run-Command -Fatal { & $cmake -G "Visual Studio $vs" -D ENABLE_TRACE=ON -D "LIBGIT2_FILENAME=$binaryFilename" -DSTDCALL=ON -D "EMBED_SSH_PATH=../libssh2" -DBUILD_CLAR:BOOL=OFF \ .. }
    Run-Command -Fatal { & $cmake --build . --config $configuration }
    cd $configuration
    Assert-Consistent-Naming "$binaryFilename.dll" "*.dll"

    Pop-Location

    Run-Command { & rm "$libgit2Directory\build\$configuration\*.exp" }
    if (Test-Path "$x86Directory\*") {
        Run-Command { & git rm "$x86Directory\*" }
    }
    Run-Command { & mkdir -fo "$x86Directory" }
    Run-Command { & copy -fo "$libgit2Directory\build\$configuration\*" -Destination $x86Directory -Exclude *.lib }
    Run-Command { & git stash save }
    Run-Command -Fatal { & git pull }
    Check-Newer-Binaries
    Run-Command -Fatal { & git stash pop }
    Run-Command -Fatal { & git add "$x86Directory" }
    Run-Command -Fatal { & git commit -m "Bumping Windows libgit2 to $sha" }
    Run-Command -Fatal { & git push }

    #Write-Output "Building 64-bit..."
    #cd ..
    #Run-Command { & mkdir build64 }
    #cd build64
    #Run-Command -Fatal { & $cmake -G "Visual Studio $vs Win64" -D THREADSAFE=ON -D ENABLE_TRACE=ON -D "LIBGIT2_FILENAME=$binaryFilename" -DSTDCALL=ON ../.. }
    #Run-Command -Fatal { & $cmake --build . --config $configuration }
    #cd $configuration
    #Assert-Consistent-Naming "$binaryFilename.dll" "*.dll"
    #Run-Command { & rm *.exp }
    #Run-Command { & rm $x64Directory\* }
    #Run-Command { & mkdir -fo $x64Directory }
    #Run-Command -Fatal { & copy -fo * $x64Directory -Exclude *.lib }

    Write-Output "Done!"
}
finally {
    Pop-Location
}