|
| 1 | +[cmdletbinding()] |
| 2 | +# PowerShell Script to clone, build and package PowerShell from specified fork and branch |
| 3 | +param ( |
| 4 | + [string] $location = "$pwd\vscode-powershell", |
| 5 | + [string] $destination = "$env:WORKSPACE", |
| 6 | + [switch] $Wait |
| 7 | +) |
| 8 | + |
| 9 | +if(-not $env:homedrive) |
| 10 | +{ |
| 11 | + Write-Verbose "fixing empty home paths..." -Verbose |
| 12 | + $profileParts = $env:userprofile -split ':' |
| 13 | + $env:homedrive = $profileParts[0]+':' |
| 14 | + $env:homepath = $profileParts[1] |
| 15 | +} |
| 16 | + |
| 17 | +if(! (Test-Path $destination)) |
| 18 | +{ |
| 19 | + Write-Verbose "Creating destination $destination" -Verbose |
| 20 | + $null = New-Item -Path $destination -ItemType Directory |
| 21 | +} |
| 22 | + |
| 23 | +#BUG BUG: External binaries should be retrieved via nuget package or similar |
| 24 | +$editorServicesPath = Join-Path $location -ChildPath '..\PowerShellEditorServices' |
| 25 | +git clone --quiet https://github.com/PowerShell/PowerShellEditorServices $editorServicesPath |
| 26 | + |
| 27 | +Write-Verbose "homedrive : ${env:homedrive}" |
| 28 | +Write-Verbose "homepath : ${env:homepath}" |
| 29 | + |
| 30 | +# Don't use CIM_PhysicalMemory, docker containers may cache old values |
| 31 | +$memoryMB = (Get-CimInstance win32_computersystem).TotalPhysicalMemory /1MB |
| 32 | +$requiredMemoryMB = 2048 |
| 33 | +if($memoryMB -lt $requiredMemoryMB) |
| 34 | +{ |
| 35 | + throw "Building powershell requires at least $requiredMemoryMB MiB of memory and only $memoryMB MiB is present." |
| 36 | +} |
| 37 | +Write-Verbose "Running with $memoryMB MB memory." -Verbose |
| 38 | + |
| 39 | +try{ |
| 40 | + Install-Module InvokeBuild -Scope CurrentUser |
| 41 | + Import-module InvokeBuild -Verbose |
| 42 | + Set-Location $location |
| 43 | + |
| 44 | + Invoke-Build |
| 45 | + |
| 46 | + Get-ChildItem $location\PowerShell-*.vsix | Select-Object -ExpandProperty FullName | ForEach-Object { |
| 47 | + $file = $_ |
| 48 | + Write-Verbose "Copying $file to $destination" -verbose |
| 49 | + Copy-Item -Path $file -Destination "$destination\" -Force |
| 50 | + } |
| 51 | +} |
| 52 | +finally |
| 53 | +{ |
| 54 | + Write-Verbose "Beginning build clean-up..." -verbose |
| 55 | + if($Wait.IsPresent) |
| 56 | + { |
| 57 | + $path = Join-Path $PSScriptRoot -ChildPath 'delete-to-continue.txt' |
| 58 | + $null = New-Item -Path $path -ItemType File |
| 59 | + Write-Verbose "Computer name: $env:COMPUTERNAME" -Verbose |
| 60 | + Write-Verbose "Delete $path to exit." -Verbose |
| 61 | + while(Test-Path -LiteralPath $path) |
| 62 | + { |
| 63 | + Start-Sleep -Seconds 60 |
| 64 | + } |
| 65 | + } |
| 66 | +} |
0 commit comments