1 $ErrorActionPreference="Stop"
3 $script:INSTALL_DIR="$env:APPVEYOR_BUILD_FOLDER\work\install"
4 $CMAKE_INSTALL_ROOT="`"$INSTALL_DIR`"" -replace "\\", "/"
5 $env:PATH="$env:PATH;$script:INSTALL_DIR"
7 if(!$env:CI -eq "true")
9 function Push-AppveyorArtifact()
11 Write-Host "Push-AppveyorArtifact $ARGS"
13 function Start-FileDownload([string] $url, [string] $out)
17 $out = $url.SubString($url.LastIndexOf("/"))
19 wget $url -Outfile $out
25 $OldErrorActionPreference=$ErrorActionPreference
26 $ErrorActionPreference="Continue"
28 Write-Host $Args[0], $Args[1..(($Args.Count)-1)]
29 & $Args[0] $Args[1..(($Args.Count)-1)]
30 if(!$LastExitCode -eq 0)
34 $ErrorActionPreference=$OldErrorActionPreference
37 #Set environment variables for Visual Studio Command Prompt
38 #http://stackoverflow.com/questions/2124753/how-i-can-use-powershell-with-the-visual-studio-command-prompt
39 function BAT-CALL([string] $path, [string] $arg)
41 Write-Host "Calling `"$path`" `"$arg`""
42 cmd /c "$path" "$arg" `&`& set `|`| exit 1|
46 #Write-Host "ENV:\$($v[0])=$($v[1])"
47 set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
50 if($LastExitCode -eq 1) {
51 Write-Error "$path not found."
62 return "C:\Qt\$ver\$env:COMPILER\"
67 [string] $compiler=$env:COMPILER
69 $script:QT_BINARY_DIRS = @($qtDir)
71 BAT-CALL "$qtDir\bin\qtenv2.bat"
73 if ($compiler.StartsWith("mingw"))
75 # supported values are
78 #remove sh.exe from path
79 $env:PATH=$env:PATH -replace "C:\\Program Files \(x86\)\\Git\\bin", ""
80 $script:MAKE="mingw32-make"
81 $script:CMAKE_GENERATOR="MinGW Makefiles"
82 $script:STRIP=@("strip", "-s")
83 if ($compiler -eq "mingw49_32")
85 $script:QT_BINARY_DIRS += (Resolve-Path "$qtDir\..\..\Tools\mingw492_32\opt\")
87 elseif ($compiler -eq "mingw53_32")
89 $script:QT_BINARY_DIRS += (Resolve-Path "$qtDir\..\..\Tools\mingw530_32\opt\")
92 elseif ($compiler.StartsWith("msvc"))
95 if($compiler.EndsWith("64"))
100 "msvc2010" = "VS100COMNTOOLS";
101 "msvc2012" = "VS110COMNTOOLS";
102 "msvc2013" = "VS120COMNTOOLS";
103 "msvc2015" = "VS140COMNTOOLS"
106 $compilerVar = $compilerDirs[$compiler.Split("_")[0]]
107 $compilerDir = (get-item -path "env:\$($compilerVar)").Value
108 BAT-CALL "$compilerDir\..\..\VC\vcvarsall.bat" $arch
110 $script:CMAKE_GENERATOR="NMake Makefiles"
113 $script:QT_BINARY_DIRS += ("C:\OpenSSL-Win32")
117 $script:QT_BINARY_DIRS += ("C:\OpenSSL-Win64")
122 function Install-ChocolatelyModule([string] $module, [string[]] $myargs)
124 Write-Host "Install chocolately package $module"
125 LogExec cinst $module @myargs -y
128 function Install-CmakeGitModule([string] $url, [hashtable] $arguments)
130 $module = $url.SubString($url.LastIndexOf("/")+1)
131 $module = $module.Substring(0,$module.Length - 4)
132 if(!$arguments.Contains("branch"))
134 $arguments["branch"] = "master"
136 if(!$arguments.Contains("buildType"))
138 $arguments["buildType"] = "Release"
140 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\build\$module
141 pushd $env:APPVEYOR_BUILD_FOLDER\work\git
142 LogExec git clone -q --depth 1 --branch ([string]$arguments["branch"]) $url $module
144 pushd $env:APPVEYOR_BUILD_FOLDER\work\build\$module
145 LogExec cmake -G $script:CMAKE_GENERATOR ("-DCMAKE_BUILD_TYPE=`"{0}`"" -f [string]$arguments["buildType"]) $env:APPVEYOR_BUILD_FOLDER\work\git\$module -DCMAKE_INSTALL_PREFIX="$CMAKE_INSTALL_ROOT" $arguments["options"]
146 LogExec $script:MAKE install
150 function Init([string[]] $chocoDeps, [System.Collections.Specialized.OrderedDictionary] $cmakeModules)
153 $script:CMAKE_GENERATOR=""
156 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\image | Out-Null
157 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\build | Out-Null
161 if($chocoDeps -contains "ninja") {
162 $script:CMAKE_GENERATOR="Ninja"
166 if ( !(Test-Path "$env:APPVEYOR_BUILD_FOLDER\work\install" ) )
168 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\install | Out-Null
169 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\git | Out-Null
171 foreach($module in $chocoDeps) {
172 if($module -eq "nsis")
174 Install-ChocolatelyModule "nsis.portable" @("-pre")
177 Install-ChocolatelyModule $module
180 foreach($key in $cmakeModules.Keys) {
181 Install-CmakeGitModule $key $cmakeModules[$key]
184 [string] $compiler=$env:COMPILER
185 if($compiler.StartsWith("msvc"))
187 Write-Host "Downloading vcredist.exe"
188 if ($compiler.StartsWith("msvc2015"))
190 if($compiler.EndsWith("64"))
192 Start-FileDownload https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x64.exe $env:APPVEYOR_BUILD_FOLDER\work\install\vcredist.exe
196 Start-FileDownload https://download.microsoft.com/download/9/3/F/93FCF1E7-E6A4-478B-96E7-D4B285925B00/vc_redist.x86.exe $env:APPVEYOR_BUILD_FOLDER\work\install\vcredist.exe
201 if($compiler.EndsWith("64"))
203 Start-FileDownload http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x64.exe $env:APPVEYOR_BUILD_FOLDER\work\install\vcredist.exe
207 Start-FileDownload http://download.microsoft.com/download/2/E/6/2E61CFA4-993B-4DD4-91DA-3737CD5CD6E3/vcredist_x86.exe $env:APPVEYOR_BUILD_FOLDER\work\install\vcredist.exe
214 function relativePath([string] $root, [string] $path)
217 $out = Resolve-Path -Relative $path
222 function StripFile([string] $name)
225 if( $name.EndsWith(".dll") -or $name.EndsWith(".exe"))
227 Write-Host "strip file $name"
228 LogExec @script:STRIP $name
233 function Get-DeployImageName()
235 $version = Get-Version
236 if($env:APPVEYOR_REPO_TAG -eq "true") {
237 return "$env:APPVEYOR_PROJECT_NAME`_$version`_Qt$env:QT_VER`_$env:COMPILER"
239 return "$env:APPVEYOR_PROJECT_NAME`_$env:APPVEYOR_REPO_BRANCH`_$version`_Qt$env:QT_VER`_$env:COMPILER"
243 function Get-Version()
245 if($env:APPVEYOR_REPO_TAG -eq "true") {
246 return $env:APPVEYOR_REPO_TAG_NAME
248 $commit = ([string]$env:APPVEYOR_REPO_COMMIT).SubString(0,6)
253 function CmakeImageInstall()
255 $imageName = Get-DeployImageName
256 $destDir = "$env:APPVEYOR_BUILD_FOLDER\work\cmakeDeployImage\$imageName"
257 $env:DESTDIR = $destDir
258 LogExec $script:MAKE install
260 if(!$LastExitCode -eq 0)
262 Write-Error "Build Failed"
265 $prefix=$script:INSTALL_DIR
266 if( $prefix.substring(1,1) -eq ":")
268 $prefix=$prefix.substring(3)
270 Write-Host "move $destDir\$prefix to $destDir"
271 mv -Force "$destDir\$prefix\*" "$destDir"
272 $rootLeftOver = $prefix.substring(0, $prefix.indexOf("\"))
273 rm -Recurse "$destDir\$rootLeftOver"
276 function CreateDeployImage([string[]] $whiteList, [string[]] $blackList)
278 $imageName = Get-DeployImageName
279 $deployPath = "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName"
281 function copyWithWhitelist([string] $root)
283 $files = ls $root -Recurse
284 foreach($fileName in $files.FullName)
286 $relPath = (relativePath $root $fileName).SubString(2)
287 if($whiteList | Where {$relPath -match $_})
289 if($blackList | Where {$relPath -match $_})
293 if(!(Test-Path $deployPath\$relPath))
295 Write-Host "copy $fileName to $deployPath\$relPath"
296 mkdir -Force (Split-Path -Parent $deployPath\$relPath) | Out-Null
297 cp -Force $fileName $deployPath\$relPath
298 StripFile $deployPath\$relPath
303 Write-Host "CreateDeployImage $imageName"
304 mkdir $deployPath | Out-Null
306 copyWithWhitelist "$env:APPVEYOR_BUILD_FOLDER\work\cmakeDeployImage\$imageName"
307 copyWithWhitelist "$env:APPVEYOR_BUILD_FOLDER\work\install\"
308 foreach($folder in $script:QT_BINARY_DIRS)
310 copyWithWhitelist $folder
312 Write-Host "Deploy path $deployPath"
316 function 7ZipDeployImage()
318 $imageName = Get-DeployImageName
319 LogExec 7za a "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName.7z" "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName"
320 Push-AppveyorArtifact "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName.7z"
323 function NsisDeployImage([string] $scriptName)
325 $imageName = Get-DeployImageName
326 $installerName = "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName.exe"
327 $version = Get-Version
328 if(([string]$env:COMPILER).StartsWith("msvc"))
330 $redist = "$env:APPVEYOR_BUILD_FOLDER\work\install\vcredist.exe"
334 if($env:COMPILER.EndsWith("64"))
336 $defaultinstdir = "`$PROGRAMFILES64"
338 $defaultinstdir = "`$PROGRAMFILES"
340 LogExec makensis.exe /DgitDir=$env:APPVEYOR_BUILD_FOLDER /Dsetupname=$installerName /Dcaption=$imageName /Dversion=$version /Dcompiler=$env:COMPILER /Dvcredist=$redist /Ddefaultinstdir=$defaultinstdir /Dsrcdir=$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName $scriptName
341 Push-AppveyorArtifact $installerName
344 # based on http://thesurlyadmin.com/2013/01/07/remove-empty-directories-recursively/
345 function DeleteEmptyFodlers([string] $root)
348 foreach($Folder in (Get-ChildItem -Path $root -Recurse -Directory))
350 $Folders += New-Object PSObject -Property @{
352 Depth = ($Folder.FullName.Split("\")).Count
355 $Folders = $Folders | Sort Depth -Descending
357 foreach($Folder in $Folders)
359 If ($Folder.Object.GetFileSystemInfos().Count -eq 0)
361 Write-Host "Delete empty dir:" $Folder.Object.FullName
362 Remove-Item -Path $Folder.Object.FullName -Force
368 Write-Host "CMAKE_INSTALL_ROOT: $CMAKE_INSTALL_ROOT"
369 Write-Host "Image-Name: ", (Get-DeployImageName)
371 Export-ModuleMember -Function @("Init","CmakeImageInstall", "CreateDeployImage", "LogExec", "7ZipDeployImage", "NsisDeployImage", "DeleteEmptyFodlers") -Variable @("CMAKE_INSTALL_ROOT")