1+ # This file is part of the Zephir Parser.
2+ #
3+ # (c) Zephir Team <team@zephir-lang.com>
4+ #
5+ # For the full copyright and license information, please view the LICENSE
6+ # file that was distributed with this source code.
7+
18Function EnsureRequiredDirectoriesPresent {
29 If (-not (Test-Path ' C:\Downloads' )) {
310 New-Item - ItemType Directory - Force - Path ' C:\Downloads' | Out-Null
@@ -13,7 +20,7 @@ Function Ensure7ZipIsInstalled {
1320 $7zipInstallationDirectory = " ${Env: ProgramFiles} \7-Zip"
1421
1522 If (-not (Test-Path " $7zipInstallationDirectory " )) {
16- throw " The 7-zip file archiver is needed to use this module"
23+ Throw " The 7-zip file archiver is needed to use this module"
1724 }
1825
1926 $Env: Path += " ;$7zipInstallationDirectory "
@@ -25,7 +32,7 @@ Function EnsureChocolateyIsInstalled {
2532 $ChocolateyInstallationDirectory = " ${Env: ProgramData} \chocolatey\bin"
2633
2734 If (-not (Test-Path " $ChocolateyInstallationDirectory " )) {
28- throw " The choco is needed to use this module"
35+ Throw " The choco is needed to use this module"
2936 }
3037
3138 $Env: Path += " ;$ChocolateyInstallationDirectory "
@@ -37,7 +44,7 @@ Function EnsurePandocIsInstalled {
3744 $PandocInstallationDirectory = " ${Env: ProgramData} \chocolatey\bin"
3845
3946 If (-not (Test-Path " $PandocInstallationDirectory " )) {
40- throw " The pandoc is needed to use this module"
47+ Throw " The pandoc is needed to use this module"
4148 }
4249
4350 $Env: Path += " ;$PandocInstallationDirectory "
@@ -124,20 +131,20 @@ Function InitializeBuildVars {
124131 switch ($Env: VC_VERSION ) {
125132 ' 14' {
126133 If (-not (Test-Path $Env: VS120COMNTOOLS )) {
127- throw ' The VS120COMNTOOLS environment variable is not set. Check your MS VS installation'
134+ Throw ' The VS120COMNTOOLS environment variable is not set. Check your MS VS installation'
128135 }
129136 $Env: VSCOMNTOOLS = $Env: VS120COMNTOOLS
130137 break
131138 }
132139 ' 15' {
133140 If (-not (Test-Path $Env: VS140COMNTOOLS )) {
134- throw ' The VS140COMNTOOLS environment variable is not set. Check your MS VS installation'
141+ Throw ' The VS140COMNTOOLS environment variable is not set. Check your MS VS installation'
135142 }
136143 $Env: VSCOMNTOOLS = $Env: VS140COMNTOOLS
137144 break
138145 }
139146 default {
140- throw ' This script is designed to run with MS VS 14/15. Check your MS VS installation'
147+ Throw ' This script is designed to run with MS VS 14/15. Check your MS VS installation'
141148 break
142149 }
143150 }
@@ -205,7 +212,7 @@ Function PrepareReleasePackage {
205212 $7zipExitCode = $LASTEXITCODE
206213 If ($7zipExitCode -ne 0 ) {
207214 Set-Location " ${CurrentPath} "
208- throw " An error occurred while creating release zippbal to [${Env: RELEASE_ZIPBALL} .zip]. 7Zip Exit Code was [${7zipExitCode} ]"
215+ Throw " An error occurred while creating release zippbal to [${Env: RELEASE_ZIPBALL} .zip]. 7Zip Exit Code was [${7zipExitCode} ]"
209216 }
210217
211218 Move-Item " ${Env: RELEASE_ZIPBALL} .zip" - Destination " ${Env: APPVEYOR_BUILD_FOLDER} "
@@ -234,13 +241,19 @@ Function SetupPhpVersionString {
234241 $DestinationPath = " ${Env: Temp} \php-sha1sum.txt"
235242
236243 If (-not [System.IO.File ]::Exists($DestinationPath )) {
237- Write-Host " Downloading PHP SHA Sums: $RemoteUrl ..."
244+ Write-Host " Downloading PHP SHA Sums: ${ RemoteUrl} ..."
238245 DownloadFile $RemoteUrl $DestinationPath
239246 }
240247
241- $versions = Get-Content $DestinationPath | Where-Object { $_ -match " php-($Env: PHP_MINOR \.\d+)-src" } | ForEach-Object { $matches [1 ] }
248+ $VersionString = Get-Content $DestinationPath | Where-Object {
249+ $_ -match " php-($Env: PHP_MINOR \.\d+)-src"
250+ } | ForEach-Object { $matches [1 ] }
251+
252+ If ($VersionString -NotMatch ' \d+\.\d+\.\d+' ) {
253+ Throw " Unable to obtain PHP version string using pattern 'php-($Env: PHP_MINOR \.\d+)-src'"
254+ }
242255
243- $Env: PHP_VERSION = $versions .Split (' ' )[-1 ]
256+ $Env: PHP_VERSION = $VersionString .Split (' ' )[-1 ]
244257}
245258
246259Function TuneUpPhp {
@@ -250,7 +263,7 @@ Function TuneUpPhp {
250263 Write-Host " Tune up PHP: $IniFile " - foregroundcolor Cyan
251264
252265 If (-not [System.IO.File ]::Exists($IniFile )) {
253- throw " Unable to locate $IniFile file"
266+ Throw " Unable to locate $IniFile file"
254267 }
255268
256269 Write-Output " " | Out-File - Encoding " ASCII" - Append $IniFile
@@ -272,11 +285,11 @@ Function EnableExtension {
272285 $PhpExe = " ${Env: PHP_PATH} \php.exe"
273286
274287 If (-not [System.IO.File ]::Exists($IniFile )) {
275- throw " Unable to locate ${IniFile} "
288+ Throw " Unable to locate ${IniFile} "
276289 }
277290
278291 If (-not (Test-Path " ${ExtPath} " )) {
279- throw " Unable to locate extension path: ${ExtPath} "
292+ Throw " Unable to locate extension path: ${ExtPath} "
280293 }
281294
282295 Write-Output " [${Env: EXTENSION_NAME} ]" | Out-File - Encoding " ASCII" - Append $IniFile
@@ -288,7 +301,7 @@ Function EnableExtension {
288301 $PhpExitCode = $LASTEXITCODE
289302 If ($PhpExitCode -ne 0 ) {
290303 PrintPhpInfo
291- throw " An error occurred while enabling [${Env: EXTENSION_NAME} ] in [$IniFile ]. PHP Exit Code was [$PhpExitCode ]."
304+ Throw " An error occurred while enabling [${Env: EXTENSION_NAME} ] in [$IniFile ]. PHP Exit Code was [$PhpExitCode ]."
292305 }
293306 }
294307}
@@ -347,7 +360,7 @@ Function Expand-Item7zip {
347360 )
348361
349362 If (-not (Test-Path - Path $Archive - PathType Leaf)) {
350- throw " Specified archive File is invalid: [$Archive ]"
363+ Throw " Specified archive File is invalid: [$Archive ]"
351364 }
352365
353366 If (-not (Test-Path - Path $Destination - PathType Container)) {
@@ -358,7 +371,7 @@ Function Expand-Item7zip {
358371
359372 $7zipExitCode = $LASTEXITCODE
360373 If ($7zipExitCode -ne 0 ) {
361- throw " An error occurred while unzipping [$Archive ] to [$Destination ]. 7Zip Exit Code was [$7zipExitCode ]"
374+ Throw " An error occurred while unzipping [$Archive ] to [$Destination ]. 7Zip Exit Code was [$7zipExitCode ]"
362375 }
363376}
364377
@@ -374,7 +387,8 @@ Function DownloadFile {
374387 $RetryCount = 0
375388 $Completed = $false
376389
377- $WebClient = new-object System.Net.WebClient
390+ $WebClient = New-Object System.Net.WebClient
391+ $WebClient.Headers.Add (' User-Agent' , ' AppVeyor PowerShell Script' )
378392
379393 While (-not $Completed ) {
380394 Try {
0 commit comments