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 appveyor-retry cinst $module @myargs -y
126 # Retry installation in case it fails; remove 'appveyor-retry' to run in a generic manner
127 # See http://help.appveyor.com/discussions/suggestions/816-generic-wrapper-for-retry#comment_40579488
128 # And https://github.com/appveyor/ci/issues/418
131 function Install-CmakeGitModule([string] $url, [hashtable] $arguments)
133 $module = $url.SubString($url.LastIndexOf("/")+1)
134 $module = $module.Substring(0,$module.Length - 4)
135 if(!$arguments.Contains("branch"))
137 $arguments["branch"] = "master"
139 if(!$arguments.Contains("buildType"))
141 $arguments["buildType"] = "Release"
143 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\build\$module
144 pushd $env:APPVEYOR_BUILD_FOLDER\work\git
145 LogExec git clone -q --depth 1 --branch ([string]$arguments["branch"]) $url $module
147 pushd $env:APPVEYOR_BUILD_FOLDER\work\build\$module
148 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"]
149 LogExec $script:MAKE install
153 function Init([string[]] $chocoDeps, [System.Collections.Specialized.OrderedDictionary] $cmakeModules)
156 $script:CMAKE_GENERATOR=""
159 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\image | Out-Null
160 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\build | Out-Null
164 if($chocoDeps -contains "ninja") {
165 $script:CMAKE_GENERATOR="Ninja"
169 if ( !(Test-Path "$env:APPVEYOR_BUILD_FOLDER\work\install" ) )
171 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\install | Out-Null
172 mkdir -Force $env:APPVEYOR_BUILD_FOLDER\work\git | Out-Null
174 foreach($module in $chocoDeps) {
175 if($module -eq "nsis")
177 Install-ChocolatelyModule "nsis.portable" @("-pre")
180 Install-ChocolatelyModule $module
183 foreach($key in $cmakeModules.Keys) {
184 Install-CmakeGitModule $key $cmakeModules[$key]
187 [string] $compiler=$env:COMPILER
188 if($compiler.StartsWith("msvc"))
190 Write-Host "Downloading vcredist.exe"
191 if ($compiler.StartsWith("msvc2015"))
193 if($compiler.EndsWith("64"))
195 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
199 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
204 if($compiler.EndsWith("64"))
206 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
210 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
217 function relativePath([string] $root, [string] $path)
220 $out = Resolve-Path -Relative $path
225 function StripFile([string] $name)
228 if( $name.EndsWith(".dll") -or $name.EndsWith(".exe"))
230 Write-Host "strip file $name"
231 LogExec @script:STRIP $name
236 function Get-DeployImageName()
238 $version = Get-Version
239 if($env:APPVEYOR_REPO_TAG -eq "true") {
240 return "$env:APPVEYOR_PROJECT_NAME`_$version`_Qt$env:QT_VER`_$env:COMPILER"
242 return "$env:APPVEYOR_PROJECT_NAME`_$env:APPVEYOR_REPO_BRANCH`_$version`_Qt$env:QT_VER`_$env:COMPILER"
246 function Get-Version()
248 if($env:APPVEYOR_REPO_TAG -eq "true") {
249 return $env:APPVEYOR_REPO_TAG_NAME
251 $commit = ([string]$env:APPVEYOR_REPO_COMMIT).SubString(0,6)
256 function CmakeImageInstall()
258 $imageName = Get-DeployImageName
259 $destDir = "$env:APPVEYOR_BUILD_FOLDER\work\cmakeDeployImage\$imageName"
260 $env:DESTDIR = $destDir
261 LogExec $script:MAKE install
263 if(!$LastExitCode -eq 0)
265 Write-Error "Build Failed"
268 $prefix=$script:INSTALL_DIR
269 if( $prefix.substring(1,1) -eq ":")
271 $prefix=$prefix.substring(3)
273 Write-Host "move $destDir\$prefix to $destDir"
274 mv -Force "$destDir\$prefix\*" "$destDir"
275 $rootLeftOver = $prefix.substring(0, $prefix.indexOf("\"))
276 rm -Recurse "$destDir\$rootLeftOver"
279 function CreateDeployImage([string[]] $whiteList, [string[]] $blackList)
281 $imageName = Get-DeployImageName
282 $deployPath = "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName"
284 function copyWithWhitelist([string] $root)
286 $files = ls $root -Recurse
287 foreach($fileName in $files.FullName)
289 $relPath = (relativePath $root $fileName).SubString(2)
290 if($whiteList | Where {$relPath -match $_})
292 if($blackList | Where {$relPath -match $_})
296 if(!(Test-Path $deployPath\$relPath))
298 Write-Host "copy $fileName to $deployPath\$relPath"
299 mkdir -Force (Split-Path -Parent $deployPath\$relPath) | Out-Null
300 cp -Force $fileName $deployPath\$relPath
301 StripFile $deployPath\$relPath
306 Write-Host "CreateDeployImage $imageName"
307 mkdir $deployPath | Out-Null
309 copyWithWhitelist "$env:APPVEYOR_BUILD_FOLDER\work\cmakeDeployImage\$imageName"
310 copyWithWhitelist "$env:APPVEYOR_BUILD_FOLDER\work\install\"
311 foreach($folder in $script:QT_BINARY_DIRS)
313 copyWithWhitelist $folder
315 Write-Host "Deploy path $deployPath"
319 function 7ZipDeployImage()
321 $imageName = Get-DeployImageName
322 LogExec 7za a "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName.7z" "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName"
323 Push-AppveyorArtifact "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName.7z"
326 function NsisDeployImage([string] $scriptName)
328 $imageName = Get-DeployImageName
329 $installerName = "$env:APPVEYOR_BUILD_FOLDER\work\deployImage\$imageName.exe"
330 $version = Get-Version
331 if(([string]$env:COMPILER).StartsWith("msvc"))
333 $redist = "$env:APPVEYOR_BUILD_FOLDER\work\install\vcredist.exe"
337 if($env:COMPILER.EndsWith("64"))
339 $defaultinstdir = "`$PROGRAMFILES64"
341 $defaultinstdir = "`$PROGRAMFILES"
343 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
344 Push-AppveyorArtifact $installerName
347 # based on http://thesurlyadmin.com/2013/01/07/remove-empty-directories-recursively/
348 function DeleteEmptyFodlers([string] $root)
351 foreach($Folder in (Get-ChildItem -Path $root -Recurse -Directory))
353 $Folders += New-Object PSObject -Property @{
355 Depth = ($Folder.FullName.Split("\")).Count
358 $Folders = $Folders | Sort Depth -Descending
360 foreach($Folder in $Folders)
362 If ($Folder.Object.GetFileSystemInfos().Count -eq 0)
364 Write-Host "Delete empty dir:" $Folder.Object.FullName
365 Remove-Item -Path $Folder.Object.FullName -Force
371 Write-Host "CMAKE_INSTALL_ROOT: $CMAKE_INSTALL_ROOT"
372 Write-Host "Image-Name: ", (Get-DeployImageName)
374 Export-ModuleMember -Function @("Init","CmakeImageInstall", "CreateDeployImage", "LogExec", "7ZipDeployImage", "NsisDeployImage", "DeleteEmptyFodlers") -Variable @("CMAKE_INSTALL_ROOT")