forked from basho/riak-go-client
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make.ps1
185 lines (165 loc) · 5.43 KB
/
make.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<#
.SYNOPSIS
Powershell script to build Riak Go Client on Windows
.DESCRIPTION
This script ensures that your build environment is sane and will run 'go' correctly depending on parameters passed to this script.
.PARAMETER Target
Target to build. Can be one of the following:
* ProtoGen - generate *.pb.go files from *.proto files.
Requires Go protoc utility (https://github.com/golang/protobuf)
* Format - run *.go files through 'go fmt'
* Test - Run 'go vet' and all tests (default target)
* UnitTest - Run unit tests
* IntegrationTest - Run live integration tests
* IntegrationTestHll - Run Hyperloglog integration tests
* TimeseriesTest - Run live timeseries tests
.PARAMETER Verbose
Use to increase verbosity.
.EXAMPLE
C:\Users\Bashoman> cd go\src\github.com\basho\riak-go-client
C:\Users\Bashoman\go\src\github.com\basho\riak-go-client>.\make.ps1 -Target Protoc -Verbose
.NOTES
Author: Luke Bakken
Date: June 1, 2015
#>
[CmdletBinding()]
Param(
[Parameter(Mandatory=$False, Position=0)]
[ValidateSet('ProtoGen', 'Format',
'Test', 'UnitTest', 'IntegrationTest', 'IntegrationTestHll', 'TimeseriesTest',
IgnoreCase = $True)]
[string]$Target = 'Test'
)
Set-StrictMode -Version Latest
$package = 'github.com/basho/riak-go-client'
$IsDebug = $DebugPreference -ne 'SilentlyContinue'
$IsVerbose = $VerbosePreference -ne 'SilentlyContinue'
# Note:
# Set to Continue to see DEBUG messages
if ($IsVerbose) {
$DebugPreference = 'Continue'
}
trap
{
Write-Error -ErrorRecord $_
exit 1
}
function Get-ScriptPath {
$scriptDir = Get-Variable PSScriptRoot -ErrorAction SilentlyContinue | ForEach-Object { $_.Value }
if (!$scriptDir) {
if ($MyInvocation.MyCommand.Path) {
$scriptDir = Split-Path $MyInvocation.MyCommand.Path -Parent
}
}
if (!$scriptDir) {
if ($ExecutionContext.SessionState.Module.Path) {
$scriptDir = Split-Path (Split-Path $ExecutionContext.SessionState.Module.Path)
}
}
if (!$scriptDir) {
$scriptDir = $PWD
}
return $scriptDir
}
function Do-ProtoGen {
$script_path = Get-ScriptPath
$rpb_path = Join-Path -Path $script_path -ChildPath 'rpb'
$proto_path = Join-Path -Path $script_path -ChildPath (Join-Path -Path 'riak_pb' -ChildPath 'src')
$proto_wild = Join-Path -Path $proto_path -ChildPath '*.proto'
Get-ChildItem $proto_wild | ForEach-Object {
$proto_file_basename = $_.BaseName
$rpb_path_tmp = Join-Path -Path $rpb_path -ChildPath $proto_file_basename
If (!(Test-Path $rpb_path_tmp)) {
New-Item $rpb_path_tmp -Type Directory -Force
}
Write-Verbose "protoc: --go_out=$rpb_path_tmp --proto_path=$proto_path $_"
& { protoc --go_out=$rpb_path_tmp --proto_path=$proto_path $_ }
if ($? -ne $True) {
throw "protoc.exe failed: $LastExitCode"
}
$rpb_file = Join-Path -Path $rpb_path_tmp -ChildPath "$proto_file_basename.pb.go"
Write-Verbose "post-processing $rpb_file"
(Get-Content $rpb_file) |
ForEach-Object {
$_ -Replace 'import proto "code.google.com/p/goprotobuf/proto"', 'import proto "github.com/golang/protobuf/proto"'
} | Set-Content $rpb_file
if ($_.Name -eq 'riak_search.proto' -or $_.Name -eq 'riak_kv.proto') {
(Get-Content $rpb_file) |
ForEach-Object {
$_ -Replace 'import riak "riak.pb"', 'import riak "github.com/basho/riak-go-client/rpb/riak"'
} | Set-Content $rpb_file
}
}
}
function Execute($cmd, $argz) {
Write-Verbose "$cmd $argz"
& $cmd $argz
if ($? -ne $True) {
throw "'$cmd $argz' failed: $LastExitCode"
}
Write-Debug "'$cmd $argz' exit code: $LastExitCode"
}
function Do-Format {
$script_path = Get-ScriptPath
Write-Verbose "go fmt $script_path"
$cmd = 'gofmt'
$argz = '-s', '-w', $script_path
Execute $cmd $argz
}
function Do-Vet {
$cmd = 'go.exe'
$script_path = Get-ScriptPath
$argz = 'tool', 'vet', '-shadow=true', '-shadowstrict=true', $script_path
Execute $cmd $argz
$argz = 'vet', $package
Execute $cmd $argz
}
function Do-UnitTest {
$v = ''
if ($IsVerbose) {
$v = '-v'
}
$cmd = 'go.exe'
$argz = 'test', $v, "$package/..."
Execute $cmd $argz
}
function Do-IntegrationTest {
$v = ''
if ($IsVerbose) {
$v = '-v'
}
$cmd = 'go.exe'
$argz = 'test', $v, '-tags=integration', "$package/..."
Execute $cmd $argz
}
function Do-IntegrationTestHll {
$v = ''
if ($IsVerbose) {
$v = '-v'
}
$cmd = 'go.exe'
$argz = 'test', $v, '-tags=integration_hll', "$package/..."
Execute $cmd $argz
}
function Do-TimeseriesTest {
$v = ''
if ($IsVerbose) {
$v = '-v'
}
$cmd = 'go.exe'
$argz = 'test', $v, '-tags=timeseries', "$package/..."
Execute $cmd $argz
}
Write-Debug "Target: $Target"
switch ($Target)
{
'ProtoGen' { Do-ProtoGen }
'Format' { Do-Format }
'Test' { Do-Vet; Do-IntegrationTest }
'UnitTest' { Do-Vet; Do-UnitTest }
'IntegrationTest' { Do-Vet; Do-IntegrationTest }
'IntegrationTestHll' { Do-Vet; Do-IntegrationTestHll }
'TimeseriesTest' { Do-Vet; Do-TimeseriesTest }
default { throw "Unknown target: $Target" }
}
exit 0