various coverity fixes
[RRG-proxmark3.git] / appveyor.yml
blobb07bce303b0210f240d91fa6c35bb64532b6a39d
1 version: 3.0.1.{build}
2 image: Visual Studio 2019
3 clone_folder: C:\ProxSpace\pm3\proxmark
4 cache:
5   - C:\ps-cache -> appveyor.yml
6 environment:
7   proxspace_url: https://github.com/Gator96100/ProxSpace/archive/master.zip
8   proxspace_zip_file: \proxspace.zip
9   proxspace_zip_folder_name: ProxSpace-*
10   proxspace_path: C:\ProxSpace
11   proxspace_home_path: \ProxSpace\pm3
12   proxspace_cache_path: C:\ps-cache
13   wsl_git_path: C:\proxmark
14   APPVEYOR_SAVE_CACHE_ON_ERROR: true
16 init:
17 - ps: >-
18     $psversiontable
20     #Get-ChildItem Env:
22     $releasename=""
24     $env:APPVEYOR_REPO_COMMIT_SHORT = $env:APPVEYOR_REPO_COMMIT.Substring(0, 8)
26     if ($env:appveyor_repo_tag -match "true"){
27       $releasename=$env:APPVEYOR_REPO_TAG_NAME + "/"
28     }
30     $releasename+=$env:APPVEYOR_BUILD_VERSION + " [" + $env:APPVEYOR_REPO_COMMIT_SHORT + "]"
32     Write-Host "repository: $env:appveyor_repo_name branch:$env:APPVEYOR_REPO_BRANCH release: $releasename" -ForegroundColor Yellow
34     Add-AppveyorMessage -Message "[$env:APPVEYOR_REPO_COMMIT_SHORT]$env:appveyor_repo_name($env:APPVEYOR_REPO_BRANCH)" -Category Information -Details "repository: $env:appveyor_repo_name branch: $env:APPVEYOR_REPO_BRANCH release: $releasename"
36     # iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
37 clone_script:
38 - ps: >-
39     
40     Function GitClone($Text, $Folder) {
41         Write-Host "$Text" -NoNewLine
42         if(-not $env:appveyor_pull_request_number) {
43             git clone -q --branch=$env:appveyor_repo_branch https://github.com/$env:appveyor_repo_name.git $Folder
44             cd $Folder
45             git checkout -qf $env:appveyor_repo_commit
46         } else {
47             git clone -q https://github.com/$env:appveyor_repo_name.git $Folder
48             cd $Folder
49             git fetch -q origin +refs/pull/$env:appveyor_pull_request_number/merge:
50             git checkout -qf FETCH_HEAD
51         }
52         Write-Host "[ OK ]" -ForegroundColor Green 
53     }
54     
55     $WSLjob = Start-Job -Name WSLInstall -ScriptBlock { 
56         Function WSLExec($Text, $Cmd) {
57             Write-Host "$Text" 
58             wsl -- bash -c $Cmd
59             Write-Host "$Text" -NoNewLine 
60             Write-Host "[ OK ]" -ForegroundColor Green
61         }
62     
63         $WSLInstallTime=[System.Environment]::TickCount
64         WSLExec "WSL update..." "sudo apt-get update 1>/dev/null"
65         WSLExec "WSL upgrade..." "sudo apt-get upgrade -y 1>/dev/null" 
66         WSLExec "WSL cleanup..." "sudo apt-get auto-remove -y 1>/dev/null" 
67         WSLExec "WSL install..." "sudo apt-get -y install --reinstall --no-install-recommends git ca-certificates build-essential pkg-config libreadline-dev gcc-arm-none-eabi libnewlib-dev libbz2-dev qtbase5-dev cmake libpython3-dev python3 python3-pip python3-dev libpython3-all-dev 1>/dev/null" 
68         WSLExec "WSL QT fix..." "sudo strip --remove-section=.note.ABI-tag /usr/lib/x86_64-linux-gnu/libQt5Core.so.5"
69         WSLExec "WSL install python dependencies..." "sudo python3 -m pip install --upgrade pip 1>/dev/null"
70         WSLExec "WSL install pip..." "sudo python3 -m pip install setuptools 1>/dev/null"
71         WSLExec "WSL install pip continue..." "sudo python3 -m pip install ansicolors sslcrypto 1>/dev/null"
73         Add-AppveyorMessage -Message "WSL setup took $(([System.Environment]::TickCount-$WSLInstallTime) / 1000) sec" -Category Information
74         New-Item -ItemType "file" -Path "C:\WSL-Finished.txt" -Force | Out-Null
75     }
76     
77     $env:PSInstallTime=[System.Environment]::TickCount
78     
79     Write-Host "ProxSpace: Removing folder..." -NoNewLine
80     
81     cd \
82     
83     Remove-Item -Recurse -Force -Path $env:proxspace_path -ErrorAction SilentlyContinue
84     
85     Write-Host "[ OK ]" -ForegroundColor Green
87     Write-Host "ProxSpace: downloading..." -NoNewLine
88     
89     [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
90     
91     Invoke-WebRequest "$env:proxspace_url" -outfile "$env:proxspace_zip_file"
92     
93     Write-Host "[ OK ]" -ForegroundColor Green
94     
95     Write-Host "ProxSpace: extracting..." -NoNewLine
96     
97     Expand-Archive -LiteralPath "$env:proxspace_zip_file" -DestinationPath "\"
98     
99     Remove-Item "$env:proxspace_zip_file"
100     
101     Write-Host "[ OK ]" -ForegroundColor Green
102     
103     Write-Host "ProxSpace: renaming folder..." -NoNewLine
104     
105     Get-ChildItem -Path "\$env:proxspace_zip_folder_name" | Rename-Item -NewName (Split-Path $env:proxspace_path -Leaf)
106     
107     Write-Host "[ OK ]" -ForegroundColor Gree 
108     
109     $psversion = (Select-String -Pattern 'PSVERSION=' -SimpleMatch -Path "$env:proxspace_path\setup\09-proxspace_setup.post").Line.Split("""")[1]
110     
111     Write-Host "ProxSpace version: $psversion" -ForegroundColor Yellow
112     
113     GitClone "ProxSpace: Cloning repository <$env:appveyor_repo_name> to $env:appveyor_build_folder ..." $env:appveyor_build_folder
114     
115     GitClone "WSL: Cloning repository <$env:appveyor_repo_name> to $env:wsl_git_path ..." $env:wsl_git_path
116     
118 install:
119 - ps: >-
120     
121     Function ExecUpdate($Text, $firstStart) {
122         Write-Host "$Text"
123         
124         $PSjob = Start-Job -Name PSInstall -ScriptBlock { 
125             cd $env:proxspace_path
126             ./runme64.bat -c "exit"
127         }
128         
129         $StartTime=[System.Environment]::TickCount
130         Start-Sleep -s 10
131         while($true) {            
132             if ($PSjob.State -eq 'Completed') {
133                 Write-Host "$Text" -NoNewLine 
134                 Write-Host "[ OK ]" -ForegroundColor Green
135                 break
136             }
137             
138             if ($PSjob.State -eq 'Failed') {
139                 Write-Host "$Text" -NoNewLine 
140                 Write-Host "[ Failed ]" -ForegroundColor Red
141                 break
142             }
143             
144             if ($firstStart -And (Test-Path "$env:proxspace_path\msys2\etc\pacman.conf.pacnew")) {
145                 Start-Sleep -s 5
146                 Stop-Job -Job $PSjob
147                 Start-Sleep -s 5
148                 Write-Host "$Text" -NoNewLine 
149                 Write-Host "Exit by pacman.conf" -ForegroundColor Green
150                 break           
151             }
152             
153             if ([System.Environment]::TickCount-$StartTime -gt 1000000) {
154                 Stop-Job -Job $PSjob
155                 Write-Host "$Text" -NoNewLine 
156                 Write-host "Exit by timeout" -ForegroundColor Yellow
157                 break
158             }
159             
160             Start-Sleep -s 5
161             Receive-Job -Name WSLInstall -ErrorAction SilentlyContinue
162         }
163         #Receive-Job -Wait -Name PSInstall
164     }
165     
166     Function GitClone($Text, $Folder) {
167         Write-Host "$Text" -NoNewLine
168         if(-not $env:appveyor_pull_request_number) {
169             git clone -q --branch=$env:appveyor_repo_branch https://github.com/$env:appveyor_repo_name.git $Folder
170             cd $Folder
171             git checkout -qf $env:appveyor_repo_commit
172         } else {
173             git clone -q https://github.com/$env:appveyor_repo_name.git $Folder
174             cd $Folder
175             git fetch -q origin +refs/pull/$env:appveyor_pull_request_number/merge:
176             git checkout -qf FETCH_HEAD
177         }
178         Write-Host "[ OK ]" -ForegroundColor Green 
179     }
180     
181     Write-Host "ProxSpace: move cache..." -NoNewLine
182     
183     New-Item -ItemType Directory -Force -Path "$env:proxspace_path\msys2\var\cache\" | Out-Null
184     
185     Copy-Item -Path "$env:proxspace_cache_path\*" -Destination "$env:proxspace_path\msys2\var\cache\" -Force -Recurse -ErrorAction SilentlyContinue
186     
187     Write-Host "[ OK ]" -ForegroundColor Gree 
189     ExecUpdate "ProxSpace: initial msys2 startup..." $true
190     
191     ExecUpdate "ProxSpace: installing required packages..." $false    
192     
193     Add-AppveyorMessage -Message "ProxSpace download and update took $(([System.Environment]::TickCount-$env:PSInstallTime) / 1000) sec" -Category Information
195 build_script:
196 - ps: >-
198     $pmfolder = Split-Path $env:appveyor_build_folder -Leaf
199     
200     Function ExecMinGWCmd($Cmd) {
201         cd $env:proxspace_path
202         ./runme64.bat -c "cd $pmfolder && $Cmd"
203     }
204     
205     Function ExecCheck($Name) {
206         $testspass = ($LASTEXITCODE -eq 0)
207     
208         $global:TestsPassed=$testspass
210         if ($testspass) {
211             Add-AppveyorTest -Name $Name -Framework NUnit -Filename $Name -Outcome Passed -Duration "$([System.Environment]::TickCount-$TestTime)"
212             Write-Host "$Name [ OK ]" -ForegroundColor Green
213         } else {
214             Add-AppveyorTest -Name $Name -Framework NUnit -Filename $Name -Outcome Failed -Duration "$([System.Environment]::TickCount-$TestTime)"
215             Write-Host "$Name [ ERROR ]" -ForegroundColor Red
216             throw "Tests error."
217         }
218     }
219     
220     $WSLjob = Start-Job -Name WSLCompile -ScriptBlock { 
221         Function ExecWSLCmd($Cmd) {
222             cd $env:wsl_git_path   
223             wsl -- bash -c $Cmd
224         }
225         
226         Function ExecCheck($Name) {
227             $testspass = ($LASTEXITCODE -eq 0)
228         
229             $global:TestsPassed=$testspass
230     
231             if ($testspass) {
232                 Add-AppveyorTest -Name $Name -Framework NUnit -Filename $Name -Outcome Passed -Duration "$([System.Environment]::TickCount-$TestTime)"
233                 Write-Host "$Name [ OK ]" -ForegroundColor Green
234             } else {
235                 Add-AppveyorTest -Name $Name -Framework NUnit -Filename $Name -Outcome Failed -Duration "$([System.Environment]::TickCount-$TestTime)"
236                 Write-Host "$Name [ ERROR ]" -ForegroundColor Red
237                 throw "Tests error."
238             }
239         }
240         
241         #WSL: wait for installation to finish
242         if(!(Test-Path "C:\WSL-Finished.txt")){
243             Write-Host "Waiting for WSL installation to finish..." -NoNewLine
244             while(!(Test-Path "C:\WSL-Finished.txt")) {
245                 Start-Sleep -s 5
246             }
247             Remove-Item -Force "C:\WSL-Finished.txt" -ErrorAction SilentlyContinue
248             Write-Host "$Name [ OK ]" -ForegroundColor Green       
249         }
250     
251         #Windows Subsystem for Linux (WSL)
252         Write-Host "---------- WSL make ----------" -ForegroundColor Yellow   
253         $TestTime=[System.Environment]::TickCount
254         ExecWSLCmd "make clean;make V=1"  
255         #some checks
256         if(!(Test-Path "$env:wsl_git_path\client\proxmark3")){
257             throw "Main file proxmark3 not exists."
258         }
259         
260         ExecWSLCmd "make check"
261         ExecCheck "WSL make Tests"
262         Start-Sleep -s 2  
263         Write-Host "---------- WSL btaddon ----------" -ForegroundColor Yellow   
264         $TestTime=[System.Environment]::TickCount   
265         ExecWSLCmd "make clean;make V=1 PLATFORM_EXTRAS=BTADDON"  
266         ExecWSLCmd "make check"
267         ExecCheck "WSL BTaddon Tests"   
268         Start-Sleep -s 2  
269         Write-Host "---------- WSL make clean ----------" -ForegroundColor Yellow  
270         ExecWSLCmd 'make clean'  
271         Write-Host "---------- WSL cmake ----------" -ForegroundColor Yellow  
272         $TestTime=[System.Environment]::TickCount 
273         ExecWSLCmd 'mkdir -p client/build; cd client/build; cmake ..; make VERBOSE=1;' 
274         Write-Host "---------- WSL cmake tests ----------" -ForegroundColor Yellow
275         ExecWSLCmd './tools/pm3_tests.sh --clientbin client/build/proxmark3 client'  
276         ExecCheck "WSL cmake Tests"
277     }
278     
279     #ProxSpace
280     
281     Write-Host "ProxSpace: create new cache..." -NoNewLine
282     
283     cd $env:proxspace_path
284     
285     ./runme64.bat -c "yes | pacman -Sc > /dev/null 2>&1"
287     Remove-Item -Recurse -Force -Path "$env:proxspace_cache_path" -ErrorAction SilentlyContinue
288     
289     Move-Item -Path "$env:proxspace_path\msys2\var\cache" -Destination "$env:proxspace_cache_path" -Force
290     
291     Write-Host "[ OK ]" -ForegroundColor Gree 
292     
293     Write-Host "---------- PS make ----------" -ForegroundColor Yellow
294     
295     $TestTime=[System.Environment]::TickCount  
296     
297     ExecMinGWCmd "make clean;make V=1"
299     if(!(Test-Path "$env:proxspace_home_path\$pmfolder\client\proxmark3.exe")){
301         throw "Main file proxmark3.exe not exists."
303     }
305     ExecMinGWCmd 'make check'
307     ExecCheck "PS make Tests"
308     
309     Write-Host "---------- PS btaddon ----------" -ForegroundColor Yellow
310     
311     $TestTime=[System.Environment]::TickCount
313     ExecMinGWCmd 'make clean;make V=1 PLATFORM_EXTRAS=BTADDON'
315     ExecMinGWCmd 'make check'
316     
317     ExecCheck "PS BTaddon Tests"
318     
319     Write-Host "---------- PS make clean ----------" -ForegroundColor Yellow
320     
321     ExecMinGWCmd 'make clean'
322     
323     Write-Host "---------- PS cmake ----------" -ForegroundColor Yellow
324     
325     $TestTime=[System.Environment]::TickCount
326     
327     ExecMinGWCmd 'mkdir -p client/build; cd client/build; cmake -G""MSYS Makefiles"" ..; make VERBOSE=1;'
328     
329     Write-Host "---------- PS cmake tests ----------" -ForegroundColor Yellow
331     ExecMinGWCmd './tools/pm3_tests.sh --clientbin client/build/proxmark3.exe client'
332     
333     ExecCheck "PS cmake Tests"
334     
335     Receive-Job -Wait -Name WSLInstall -ErrorAction SilentlyContinue
336     
337     Receive-Job -Wait -Job $WSLjob
338     
339 test_script:
340 - ps: >-
341     if ($global:TestsPassed) {
342       Write-Host "Tests [ OK ]" -ForegroundColor Green
343     } else {
344       Write-Host "Tests [ ERROR ]" -ForegroundColor Red
345       throw "Tests error."
346     }
347 on_success:
348 - ps: Write-Host "Build success..." -ForegroundColor Green
349 on_failure:
350 - ps: Write-Host "Build error." -ForegroundColor Red
351 on_finish:
352 - ps: # $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))