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"
72 if ($compiler.StartsWith("mingw49"))
74 #remove sh.exe from path
75 $env:PATH=$env:PATH -replace "C:\\Program Files \(x86\)\\Git\\bin", ""
76 $script:MAKE="mingw32-make"
77 $script:CMAKE_GENERATOR="MinGW Makefiles"
78 $script:STRIP=@("strip", "-s")
79 $script:QT_BINARY_DIRS += (Resolve-Path "$qtDir\..\..\Tools\mingw492_32\opt\")
81 elseif ($compiler.StartsWith("msvc"))
84 if($compiler.EndsWith("64"))
89 "msvc2010" = "VS100COMNTOOLS";
90 "msvc2012" = "VS110COMNTOOLS";
91 "msvc2013" = "VS120COMNTOOLS";
92 "msvc2015" = "VS140COMNTOOLS"
95 $compilerVar = $compilerDirs[$compiler.Split("_")[0]]
96 $compilerDir = (get-item -path "env:\$($compilerVar)").Value
97 BAT-CALL "$compilerDir\..\..\VC\vcvarsall.bat" $arch
99 $script:CMAKE_GENERATOR="NMake Makefiles"
102 $script:QT_BINARY_DIRS += ("C:\OpenSSL-Win32")
106 $script:QT_BINARY_DIRS += ("C:\OpenSSL-Win64")
111 function Install-ChocolatelyModule([string] $module, [string[]] $myargs)
113 Write-Host "Install chocolately package $module"
114 LogExec cinst $module @myargs -y
117 function Install-CmakeGitModule([string] $url, [hashtable] $arguments)
119 $module = $url.SubString($url.LastIndexOf("/")+1)
120 $module = $module.Substring(0,$module.Length - 4)
121 if(!$arguments.Contains("branch"))
123 $arguments["branch"] = "master"
125 if(!$arguments.Contains("buildType"))
127 $arguments["buildType"] = "Release"
129 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\build\$module
130 pushd $env:APPVEYOR_BUILD_FOLDER\work\git
131 LogExec git clone -q --depth 1 --branch ([string]$arguments["branch"]) $url $module
133 pushd $env:APPVEYOR_BUILD_FOLDER\work\build\$module
134 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"]
135 LogExec $script:MAKE install
139 function Init([string[]] $chocoDeps, [System.Collections.Specialized.OrderedDictionary] $cmakeModules)
142 $script:CMAKE_GENERATOR=""
145 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\image | Out-Null
146 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\build | Out-Null
150 if($chocoDeps -contains "ninja") {
151 $script:CMAKE_GENERATOR="Ninja"
155 if ( !(Test-Path "$env:APPVEYOR_BUILD_FOLDER\work\install" ) )
157 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\install | Out-Null
158 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\git | Out-Null
160 foreach($module in $chocoDeps) {
161 if($module -eq "nsis")
163 Install-ChocolatelyModule "nsis.portable" @("-pre")
166 Install-ChocolatelyModule $module
169 foreach($key in $cmakeModules.Keys) {
170 Install-CmakeGitModule $key $cmakeModules[$key]
173 [string] $compiler=$env:COMPILER
174 if($compiler.StartsWith("msvc"))
176 Write-Host "Downloading vcredist.exe"
177 if ($compiler.StartsWith("msvc2015"))
179 if($compiler.EndsWith("64"))
181 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
185 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
190 if($compiler.EndsWith("64"))
192 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
196 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
203 function relativePath([string] $root, [string] $path)
206 $out = Resolve-Path -Relative $path
211 function StripFile([string] $name)
214 if( $name.EndsWith(".dll") -or $name.EndsWith(".exe"))
216 Write-Host "strip file $name"
217 LogExec @script:STRIP $name
222 function Get-DeployImageName()
224 $version = Get-Version
225 if($env:APPVEYOR_REPO_TAG -eq "true") {
226 return "$env:APPVEYOR_PROJECT_NAME`_$version`_Qt$env:QT_VER`_$env:COMPILER"
228 return "$env:APPVEYOR_PROJECT_NAME`_$env:APPVEYOR_REPO_BRANCH`_$version`_Qt$env:QT_VER`_$env:COMPILER"
232 function Get-Version()
234 if($env:APPVEYOR_REPO_TAG -eq "true") {
235 return $env:APPVEYOR_REPO_TAG_NAME
237 $commit = ([string]$env:APPVEYOR_REPO_COMMIT).SubString(0,6)
242 function CmakeImageInstall()
244 $imageName = Get-DeployImageName
245 $destDir = "$env:APPVEYOR_BUILD_FOLDER\work\cmakeDeployImage\$imageName"
246 $env:DESTDIR = $destDir
247 LogExec $script:MAKE install
249 if(!$LastExitCode -eq 0)
251 Write-Error "Build Failed"
254 $prefix=$script:INSTALL_DIR
255 if( $prefix.substring(1,1) -eq ":")
257 $prefix=$prefix.substring(3)
259 Write-Host "move $destDir\$prefix to $destDir"
260 mv -Force "$destDir\$prefix\*" "$destDir"
261 $rootLeftOver = $prefix.substring(0, $prefix.indexOf("\"))
262 rm -Recurse "$destDir\$rootLeftOver"
265 function CreateDeployImage([string[]] $whiteList, [string[]] $blackList)
267 $imageName = Get-DeployImageName
268 $deployPath = "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName"
270 function copyWithWhitelist([string] $root)
272 $files = ls $root -Recurse
273 foreach($fileName in $files.FullName)
275 $relPath = (relativePath $root $fileName).SubString(2)
276 if($whiteList | Where {$relPath -match $_})
278 if($blackList | Where {$relPath -match $_})
282 if(!(Test-Path $deployPath\$relPath))
284 Write-Host "copy $fileName to $deployPath\$relPath"
285 mkdir -Force (Split-Path -Parent $deployPath\$relPath) | Out-Null
286 cp -Force $fileName $deployPath\$relPath
287 StripFile $deployPath\$relPath
292 Write-Host "CreateDeployImage $imageName"
293 mkdir $deployPath | Out-Null
295 copyWithWhitelist "$env:APPVEYOR_BUILD_FOLDER\work\cmakeDeployImage\$imageName"
296 copyWithWhitelist "$env:APPVEYOR_BUILD_FOLDER\work\install\"
297 foreach($folder in $script:QT_BINARY_DIRS)
299 copyWithWhitelist $folder
301 Write-Host "Deploy path $deployPath"
305 function 7ZipDeployImage()
307 $imageName = Get-DeployImageName
308 LogExec 7za a "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName.7z" "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName"
309 Push-AppveyorArtifact "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName.7z"
312 function NsisDeployImage([string] $scriptName)
314 $imageName = Get-DeployImageName
315 $installerName = "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName.exe"
316 $version = Get-Version
317 if(([string]$env:COMPILER).StartsWith("msvc"))
319 $redist = "$env:APPVEYOR_BUILD_FOLDER\work\install\vcredist.exe"
323 if($env:COMPILER.EndsWith("64"))
325 $defaultinstdir = "`$PROGRAMFILES64"
327 $defaultinstdir = "`$PROGRAMFILES"
329 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
330 Push-AppveyorArtifact $installerName
333 # based on http://thesurlyadmin.com/2013/01/07/remove-empty-directories-recursively/
334 function DeleteEmptyFodlers([string] $root)
337 foreach($Folder in (Get-ChildItem -Path $root -Recurse -Directory))
339 $Folders += New-Object PSObject -Property @{
341 Depth = ($Folder.FullName.Split("\")).Count
344 $Folders = $Folders | Sort Depth -Descending
346 foreach($Folder in $Folders)
348 If ($Folder.Object.GetFileSystemInfos().Count -eq 0)
350 Write-Host "Delete empty dir:" $Folder.Object.FullName
351 Remove-Item -Path $Folder.Object.FullName -Force
357 Write-Host "CMAKE_INSTALL_ROOT: $CMAKE_INSTALL_ROOT"
358 Write-Host "Image-Name: ", (Get-DeployImageName)
360 Export-ModuleMember -Function @("Init","CmakeImageInstall", "CreateDeployImage", "LogExec", "7ZipDeployImage", "NsisDeployImage", "DeleteEmptyFodlers") -Variable @("CMAKE_INSTALL_ROOT")