forked from dropbox/dropbox-sdk-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildall.ps1
213 lines (181 loc) · 5.77 KB
/
buildall.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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
param (
[Parameter(Mandatory=$true)]
[string]$testSettings,
[switch]$doc = $false
)
$visualStudioVersion = $env:VisualStudioVersion
$pythonPath = "stone"
$nugetUrl = "http://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
$solutionDir = Resolve-Path "dropbox-sdk-dotnet"
$generatorDir = Resolve-Path "generator"
$sourceDir = "$solutionDir\Dropbox.Api"
$testsDir = "$solutionDir\Dropbox.Api.Tests"
$specDir = Resolve-Path "spec"
$nugetDir = "$solutionDir\.nuget"
$nugetPath = "$nugetDir\nuget.exe"
$nugetSpecPath = "$sourceDir\Dropbox.Api.nuspec"
$generatorPath = "$generatorDir\csharp.stoneg.py"
$generatorArgs = @("-m", "stone.cli", "-a:all", $generatorPath, $sourceDir)
$docBuildPath = Resolve-Path "doc\StoneDocs.shfbproj"
$majorVersion = "4.0"
$releaseVersion = "4.3.0"
$assemblyInfoPath = "$sourceDir\AppProperties\AssemblyInfo.cs"
$signKeyPath = "$sourceDir\dropbox_api_key.snk"
$builds = @(
@{Name = "Dropbox.Api"; Configuration="Release"; SignAssembly=$true; TestsName="Dropbox.Api.Tests"},
@{Name = "Dropbox.Api.Portable"; Configuration="Release"; SignAssembly=$true; TestName=$null},
@{Name = "Dropbox.Api.Portable40"; Configuration="Release"; SignAssembly=$true; TestName=$null},
@{Name = "Dropbox.Api.Doc"; Configuration="Debug"; SignAssembly=$false; TestName=$null}
)
function RunCommand($command)
{
return & $command
}
function EnsureVisualStudioVersion()
{
Write-Host "Checking Visual Studio version..."
if (!($visualStudioVersion -ge 12))
{
Write-Error "This requires a visual studio version 12.0 ""VS2013"" to be installed." -ErrorAction SilentlyContinue
Write-Error "Did you run vcvarsall.bat?" -ErrorAction Stop
}
}
function EnsureNuGetExists()
{
Write-Host "Checking nuget.exe..."
if (!(Test-Path $nugetPath))
{
Write-Host "Couldn't find nuget.exe. Downloading from $nugetUrl to $nugetPath"
if (!(Test-Path $nugetDir))
{
New-Item $nugetDir -ItemType Directory
}
(New-Object System.Net.WebClient).DownloadFile($nugetUrl, $nugetPath)
}
}
function EnsurePythonExists()
{
Write-Host "Checking Python environment..."
if (!(Get-Command "python" -ErrorAction SilentlyContinue)) {
Write-Error "Cannot find python.exe, do you need to check your path?" -ErrorAction Stop
}
}
function EnsurePipExists()
{
Write-Host "Checking pip..."
if (!(Get-Command "pip" -ErrorAction SilentlyContinue)) {
Write-Error "Cannot find pip.exe, do you need to check your path?" -ErrorAction Stop
}
}
function InstallStoneDependency()
{
RunCommand { pip "install" "ply>=3.4" "six>=1.3.0" "typing>=3.5.2" }
}
function GenerateProjectFiles()
{
Write-Host "Generating Dropbox.Api..."
[environment]::SetEnvironmentVariable("PYTHONPATH", $pythonPath)
$files = Get-ChildItem "$specDir\*" -Include *.stone | Select -ExpandProperty FullName
RunCommand { python $generatorArgs $files }
}
function RestoreNugetPackages()
{
Write-Host "Restoring nuget packages..."
RunCommand { & $nugetPath restore "$solutionDir\Dropbox.Api.sln" }
}
function RunMSBuild()
{
param (
[string] $buildPath,
[string] $config = "Debug",
[switch] $signAssembly = $false
)
RunCommand { msbuild "/t:Clean;Rebuild" "/verbosity:minimal" "/clp:ErrorsOnly" "/m" $buildPath "/p:Configuration=$config" "/p:AssemblyOriginatorKeyFile=$signKeyPath" "/p:SignAssembly=$signAssembly"}
}
function BuildPackage($build)
{
$name = $build.Name
$config = $build.Configuration
$testsName = $build.TestsName
$signAssembly = $build.SignAssembly
Write-Host "Building $name..."
RunMSBuild "$sourceDir\$name.csproj" $config -signAssembly $signAssembly
if ($testsName -ne $null)
{
RunVSUnitTests $testsName
}
}
function BuildPackages()
{
foreach ($build in $builds)
{
BuildPackage $build
}
}
function RunVSUnitTests($testsName)
{
Write-Host "Building $testsName..."
RunMSBuild "$testsDir/$testsName.csproj"
Write-Host "Running tests $testName..."
RunCommand { vstest.console "$testsDir\bin\Debug\$testsName.dll" "/Settings:$testSettings" }
}
function BuildDoc()
{
if ($doc)
{
Write-Host "Building Doc..."
RunMSBuild $docBuildPath
}
}
function PackNugetPackage()
{
Write-Host "Packing Nuget package..."
RunCommand { & $nugetPath pack $nugetSpecPath }
}
function GetAssemblyFileVersion($majorVersion)
{
$date = Get-Date
$start = [datetime]"01/01/2000"
$span = New-TimeSpan -Start $start -End $date
$minor = [int]($span.TotalDays)
return "$majorVersion.$minor"
}
function GetAssemblyVersion($majorVersion)
{
return "$majorVersion.0"
}
function UpdateAssemblyInfo()
{
$assemblyVersionNumber = GetAssemblyVersion $majorVersion
$fileVersionNumber = GetAssemblyFileVersion $majorVersion
Write-Host $fileVersionNumber
$assemblyVersionPattern = 'AssemblyVersion\(.*\)'
$fileVersionPattern = 'AssemblyFileVersion\(.*\)'
$assemblyVersion = 'AssemblyVersion("' + $assemblyVersionNumber + '")';
$fileVersion = 'AssemblyFileVersion("' + $fileVersionNumber + '")';
Write-Host "Updating AssemblyInfo.cs..."
(Get-Content $assemblyInfoPath) | ForEach-Object {
% {$_ -replace $assemblyVersionPattern, $assemblyVersion } |
% {$_ -replace $fileVersionPattern, $fileVersion }
} | Set-Content $assemblyInfoPath
}
function UpdateNugetSpec()
{
Write-Host "Updating nuspec file..."
$xml = [xml](Get-Content $nugetSpecPath)
$xml.SelectNodes('/package/metadata/version')[0].InnerXml = $releaseVersion
$xml.Save($nugetSpecPath)
}
EnsureNuGetExists
EnsurePythonExists
EnsurePipExists
InstallStoneDependency
EnsureVisualStudioVersion
GenerateProjectFiles
RestoreNugetPackages
UpdateAssemblyInfo
BuildPackages
BuildDoc
UpdateNugetSpec
PackNugetPackage