forked from cloudbase/FreeRDP-Windows-Build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BuildUtils.ps1
151 lines (133 loc) · 3.71 KB
/
BuildUtils.ps1
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
# Copyright 2012 Cloudbase Solutions Srl
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
function CheckRemoveDir($path)
{
if (Test-Path $path) {
Remove-Item -Recurse -Force $path
}
}
function GitClonePull($path, $url, $branch="master")
{
Write-Host "Cloning / pulling: $url, branch: $branch"
$needspull = $true
if (!(Test-Path -path $path))
{
git clone -b $branch $url
if ($LastExitCode) { throw "git clone failed" }
$needspull = $false
}
if ($needspull)
{
pushd .
try
{
cd $path
$branchFound = (git branch) -match "(.*\s)?$branch"
if ($LastExitCode) { throw "git branch failed" }
git reset --hard
if ($LastExitCode) { throw "git reset failed" }
git clean -f -d
if ($LastExitCode) { throw "git clean failed" }
if($branchFound)
{
git checkout $branch
if ($LastExitCode) { throw "git checkout failed" }
}
else
{
git checkout -b $branch origin/$branch
if ($LastExitCode) { throw "git checkout failed" }
}
git pull
if ($LastExitCode) { throw "git pull failed" }
}
finally
{
popd
}
}
}
function Expand7z($archive, $outputDir = ".")
{
pushd .
try
{
cd $outputDir
&7z.exe x -y $archive
if ($LastExitCode) { throw "7z.exe failed on archive: $archive"}
}
finally
{
popd
}
}
function SetVCVars($version="12.0")
{
pushd "$ENV:ProgramFiles (x86)\Microsoft Visual Studio $version\VC\"
try
{
cmd /c "vcvarsall.bat&set" |
foreach {
if ($_ -match "=") {
$v = $_.split("="); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
}
}
}
finally
{
popd
}
}
function ExecRetry($command, $maxRetryCount = 10, $retryInterval=2)
{
$currErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = "Continue"
$retryCount = 0
while ($true)
{
try
{
& $command
break
}
catch [System.Exception]
{
$retryCount++
if ($retryCount -ge $maxRetryCount)
{
$ErrorActionPreference = $currErrorActionPreference
throw
}
else
{
Write-Error $_.Exception
Start-Sleep $retryInterval
}
}
}
$ErrorActionPreference = $currErrorActionPreference
}
function DownloadFile($url, $dest)
{
Write-Host "Downloading: $url"
$webClient = New-Object System.Net.webclient
$webClient.DownloadFile($url, $dest)
}
function ChechFileHash($path, $hash, $algorithm="SHA1") {
$h = Get-Filehash -Algorithm $algorithm $path
if ($h.Hash.ToUpper() -ne $hash.ToUpper()) {
throw "Hash comparison failed for file: $path"
}
}