Incorporate build.FullCLR.ps1 in PowerShellGitHubDev.psm1

This commit fixes #652
This commit is contained in:
Sergei Vorobev 2016-03-11 16:19:05 -08:00
parent d7195fc258
commit b28d96d700
4 changed files with 154 additions and 111 deletions

View file

@ -19,10 +19,12 @@ try {
function Start-PSBuild
{
[CmdletBinding(DefaultParameterSetName='CoreCLR')]
param(
[switch]$Restore,
[switch]$Clean,
[string]$Output = "$PSScriptRoot/bin",
[string]$Output,
# These runtimes must match those in project.json
# We do not use ValidateScript since we want tab completion
[ValidateSet("ubuntu.14.04-x64",
@ -31,61 +33,172 @@ function Start-PSBuild
"win10-x64",
"osx.10.10-x64",
"osx.10.11-x64")]
[string]$Runtime
[Parameter(ParameterSetName='CoreCLR')]
[string]$Runtime,
[Parameter(ParameterSetName='FullCLR')]
[switch]$FullCLR,
[Parameter(ParameterSetName='FullCLR')]
[string]$cmakeGenerator = "Visual Studio 12 2013",
[Parameter(ParameterSetName='FullCLR')]
[ValidateSet("Debug",
"Release")]
[string]$msbuildConfiguration = "Release"
)
if (-Not (Get-Command "dotnet" -ErrorAction SilentlyContinue)) {
throw "Build dependency 'dotnet' not found in PATH! See: https://dotnet.github.io/getting-started/"
function precheck([string]$command, [string]$missedMessage)
{
$c = Get-Command $command -ErrorAction SilentlyContinue
if (-not $c)
{
Write-Warning $missedMessage
return $false
}
else
{
return $true
}
}
# simplify ParameterSetNames, set output
if ($PSCmdlet.ParameterSetName -eq 'FullCLR')
{
$FullCLR = $true
}
if (-not $Output)
{
if ($FullCLR) { $Output = "$PSScriptRoot\binFull" } else { $Output = "$PSScriptRoot\bin" }
}
# verify we have all tools in place to do the build
$precheck = precheck 'dotnet' "Build dependency 'dotnet' not found in PATH! See: https://dotnet.github.io/getting-started/"
if ($FullCLR)
{
# cmake is needed to build powershell.exe
$precheck = $precheck -and (precheck 'cmake' 'cmake not found. You can install it from https://chocolatey.org/packages/cmake.portable')
# msbuild is needed to build powershell.exe
$precheck = $precheck -and (precheck 'msbuild' 'msbuild not found. Install Visual Studio and add msbuild to $env:PATH')
}
if (-not $precheck) { return }
# handle clean
if ($Clean) {
Remove-Item -Force -Recurse $Output
Remove-Item -Force -Recurse $Output -ErrorAction SilentlyContinues
}
New-Item -Force -Type Directory $Output | Out-Null
$Top = "$PSScriptRoot/src/Microsoft.PowerShell.Linux.Host"
# handle Restore
if ($FullCLR)
{
$Top = "$PSScriptRoot\src\Microsoft.PowerShell.ConsoleHost"
$framework = 'net451'
}
else
{
$Top = "$PSScriptRoot/src/Microsoft.PowerShell.Linux.Host"
$framework = 'netstandardapp1.5'
}
if ($Restore -Or -Not (Test-Path "$Top/project.lock.json")) {
dotnet restore $PSScriptRoot
}
if ($IsLinux -Or $IsOSX) {
$InstallCommand = if ($IsLinux) { "apt-get" } elseif ($IsOSX) { "brew" }
foreach ($Dependency in "cmake", "g++") {
if (-Not (Get-Command $Dependency -ErrorAction SilentlyContinue)) {
throw "Build dependency '$Dependency' not found in PATH! Run '$InstallCommand install $Dependency'"
# Build native components
if (-not $FullCLR)
{
Write-Verbose "Start CoreCLR build"
if ($IsLinux -Or $IsOSX) {
$InstallCommand = if ($IsLinux) { "apt-get" } elseif ($IsOSX) { "brew" }
foreach ($Dependency in "cmake", "g++") {
if (-Not (Get-Command $Dependency -ErrorAction SilentlyContinue)) {
throw "Build dependency '$Dependency' not found in PATH! Run '$InstallCommand install $Dependency'"
}
}
$Ext = if ($IsLinux) { "so" } elseif ($IsOSX) { "dylib" }
$Native = "$PSScriptRoot/src/libpsl-native"
$Lib = "$Native/src/libpsl-native.$Ext"
Write-Verbose "Building $Lib"
try {
Push-Location $Native
cmake -DCMAKE_BUILD_TYPE=Debug .
make -j
make test
} finally {
Pop-Location
}
if (-Not (Test-Path $Lib)) { throw "Compilation of $Lib failed" }
Copy-Item $Lib $Output
}
}
else
{
Write-Verbose "Start building native powershell.exe"
$build = "$PSScriptRoot/build"
if ($Clean) {
Remove-Item -Force -Recurse $build -ErrorAction SilentlyContinue
}
$Ext = if ($IsLinux) { "so" } elseif ($IsOSX) { "dylib" }
$Native = "$PSScriptRoot/src/libpsl-native"
$Lib = "$Native/src/libpsl-native.$Ext"
Write-Host "Building $Lib"
mkdir $build -ErrorAction SilentlyContinue
$origPWD = $pwd
try
{
cd $build
try {
Push-Location $Native
cmake -DCMAKE_BUILD_TYPE=Debug .
make -j
make test
} finally {
Pop-Location
if ($cmakeGenerator)
{
cmake -G "$cmakeGenerator" ..\src\powershell-native
}
else
{
cmake ..\src\powershell-native
}
msbuild powershell.vcxproj /p:Configuration=$msbuildConfiguration
cp -rec $msbuildConfiguration\* $BINFULL
}
finally
{
cd $origPWD
}
if (-Not (Test-Path $Lib)) { throw "Compilation of $Lib failed" }
Copy-Item $Lib $Output
}
Write-Host "Building PowerShell"
$Arguments = "--framework", "netstandardapp1.5", "--output", $Output
Write-Verbose "Building PowerShell"
$Arguments = "--framework", $framework, "--output", $Output
if ($IsLinux -Or $IsOSX) { $Arguments += "--configuration", "Linux" }
if ($Runtime) { $Arguments += "--runtime", $Runtime }
if ($FullCLR)
{
# there is a problem with code signing:
# AssemblyKeyFileAttribute file path cannot be correctly located, if `dotnet publish $TOP` syntax is used
# we workaround it with calling `dotnet publish` from $TOP directory instead.
$origPWD = $pwd
cd $Top
}
else
{
$Arguments += $Top
}
$Arguments += $Top
Write-Verbose "Run dotnet publish $Arguments from $pwd"
dotnet publish $Arguments
# this try-finally is part of workaround about AssemblyKeyFileAttribute issue
try
{
dotnet publish $Arguments
}
finally
{
if ($FullCLR) { cd $origPWD }
}
}
function Start-PSPackage

View file

@ -141,8 +141,9 @@ test on OS X, but some developers use PowerShell on 10.10 and 10.11.
**The command `dotnet restore` must be done at least once from the top directory
to obtain all the necessary .NET packages.**
Build with `./build.sh` on Linux and OS X, `./build.ps1` for Core PowerShell on
Windows, and `./build.FullCLR.ps1` for Full PowerShell on Windows.
Build with `./build.sh` on Linux and OS X.
`Start-PSBuild` from module `.\PowerShellGitHubDev.psm1` on Windows.
Specifically:
@ -161,9 +162,13 @@ In PowerShell:
```powershell
cd PowerShell
dotnet restore
./build.ps1
Import-Module .\PowerShellGitHubDev.psm1
Start-PSBuild # build CoreCLR version
Start-PSBuild -FullCLR # build FullCLR version
```
**Tip:** use `Start-PSBuild -Verbose` switch to see more information about build process.
### PowerShellGitHubDev
Alternatively, the `PowerShellGitHubDev.psm1` module contains a `Start-PSBuild`

View file

@ -26,7 +26,7 @@ build_script:
dotnet --version
Import-Module .\PowerShellGitHubDev.psm1
Start-PSBuild
- ps: .\build.fullCLR.ps1
Start-PSBuild -FullCLR
test_script:
- ps: |
@ -39,7 +39,6 @@ test_script:
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFile))
#
# FullCLR
Import-Module .\PowerShellGitHubDev.psm1
$testResultsFile = ".\TestsResults.FullCLR.xml"
Start-DevPSGitHub -binDir $pwd\binFull -NoNewWindow -ArgumentList '-command', "Import-Module .\bin\Modules\Pester; Import-Module .\bin\Modules\Microsoft.PowerShell.Platform; Invoke-Pester test/fullCLR -OutputFormat NUnitXml -OutputFile $testResultsFile"
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFile))

View file

@ -1,74 +0,0 @@
param(
# "" is for default generator on the platform
[ValidateSet(
"",
"Visual Studio 12 2013",
"Visual Studio 12 2013 Win64",
"Visual Studio 14 2015",
"Visual Studio 14 2015 Win64")]
[string]$cmakeGenerator = "Visual Studio 12 2013",
[ValidateSet(
"Debug",
"Release")]
[string]$msbuildConfiguration = "Release"
)
$origPWD = $pwd
try
{
$prechecks = $true
# check per-requests
if (-not (get-command cmake -ErrorAction SilentlyContinue))
{
Write-Warning 'cmake not found. You can install it from https://chocolatey.org/packages/cmake.portable'
$prechecks = $false
}
if (-not (get-command msbuild -ErrorAction SilentlyContinue))
{
Write-Warning 'msbuild not found. Install Visual Studio and add msbuild to $env:PATH'
$prechecks = $false
}
if (-not (get-command dotnet -ErrorAction SilentlyContinue))
{
Write-Warning 'dotnet not found. Install it from http://dotnet.github.io/getting-started/'
$prechecks = $false
}
if (-not $prechecks)
{
return
}
# end per-requests
$BINFULL = "$pwd/binFull"
$BUILD = "$pwd/build"
mkdir $BINFULL -ErrorAction SilentlyContinue
# Publish PowerShell
cd src\Microsoft.PowerShell.ConsoleHost
dotnet publish --framework net451 --output $BINFULL
mkdir $build -ErrorAction SilentlyContinue
cd $build
if ($cmakeGenerator)
{
cmake -G "$cmakeGenerator" ..\src\powershell-native
}
else
{
cmake ..\src\powershell-native
}
msbuild powershell.vcxproj /p:Configuration=$msbuildConfiguration
cp -rec $msbuildConfiguration\* $BINFULL
}
finally
{
cd $origPWD
}