ci: refactor build.ps1 #19336

Refactor `build.ps1` into a more modular design

9728f3b558/.github/workflows/ci.yml (L283-L296)

- Separate CI steps.
- Remove unneeded code related to setting up CMake.
- Use parallel/incremental builds.
- Fix github's cache.
- Clear the way for the possibility of replacing this file with a cmake-preset:
  https://github.com/neovim/neovim/pull/19128
This commit is contained in:
kylo252
2022-07-18 00:07:35 +02:00
committed by GitHub
parent 13abe20b5f
commit 9f4b19b6d0
3 changed files with 162 additions and 144 deletions

View File

@@ -269,6 +269,7 @@ jobs:
env: env:
DEPS_BUILD_DIR: ${{ format('{0}/nvim-deps', github.workspace) }} DEPS_BUILD_DIR: ${{ format('{0}/nvim-deps', github.workspace) }}
DEPS_PREFIX: ${{ format('{0}/nvim-deps/usr', github.workspace) }} DEPS_PREFIX: ${{ format('{0}/nvim-deps/usr', github.workspace) }}
CMAKE_BUILD_TYPE: "RelWithDebInfo"
name: windows (MSVC_64) name: windows (MSVC_64)
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@@ -278,7 +279,20 @@ jobs:
path: ${{ env.DEPS_BUILD_DIR }} path: ${{ env.DEPS_BUILD_DIR }}
key: ${{ hashFiles('cmake.deps\**') }} key: ${{ hashFiles('cmake.deps\**') }}
- name: Run CI - name: Build deps
run: powershell ci\build.ps1 run: .\ci\build.ps1 -BuildDeps
env:
CONFIGURATION: MSVC_64 - name: Build nvim
run: .\ci\build.ps1 -Build
- name: Install test deps
continue-on-error: false
run: .\ci\build.ps1 -EnsureTestDeps
- if: "!cancelled()"
name: Run tests
run: .\ci\build.ps1 -Test
- if: "!cancelled()"
name: Run old tests
run: .\ci\build.ps1 -TestOld

View File

@@ -138,7 +138,7 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
with: with:
fetch-depth: 0 fetch-depth: 0
- run: powershell ci\build.ps1 -NoTests - run: powershell ci\build.ps1 -Package
- uses: actions/upload-artifact@v3 - uses: actions/upload-artifact@v3
with: with:
name: ${{ matrix.archive }} name: ${{ matrix.archive }}

View File

@@ -1,139 +1,143 @@
param([switch]$NoTests) [CmdletBinding(DefaultParameterSetName = "Build")]
Set-StrictMode -Version Latest param(
$ErrorActionPreference = 'Stop' [Parameter(ParameterSetName="Build")][switch]$Build,
$ProgressPreference = 'SilentlyContinue' [Parameter(ParameterSetName="BuildDeps")][switch]$BuildDeps,
[Parameter(ParameterSetName="EnsureTestDeps")][switch]$EnsureTestDeps,
$env:CONFIGURATION -match '^(?<compiler>\w+)_(?<bits>32|64)(?:-(?<option>\w+))?$' [Parameter(ParameterSetName="Package")][switch]$Package,
$compiler = $Matches.compiler [Parameter(ParameterSetName="Test")][switch]$Test,
$compileOption = if ($Matches -contains 'option') {$Matches.option} else {''} [Parameter(ParameterSetName="TestOld")][switch]$TestOld
$bits = $Matches.bits )
$cmakeBuildType = $(if ($env:CMAKE_BUILD_TYPE -ne $null) {$env:CMAKE_BUILD_TYPE} else {'RelWithDebInfo'});
$buildDir = [System.IO.Path]::GetFullPath("$(pwd)") Set-StrictMode -Version Latest
$depsCmakeVars = @{ $ErrorActionPreference = 'Stop'
CMAKE_BUILD_TYPE = $cmakeBuildType; $ProgressPreference = 'SilentlyContinue'
}
$nvimCmakeVars = @{ $projectDir = [System.IO.Path]::GetFullPath("$(Get-Location)")
CMAKE_BUILD_TYPE = $cmakeBuildType; $buildDir = Join-Path -Path $projectDir -ChildPath "build"
BUSTED_OUTPUT_TYPE = 'nvim';
DEPS_PREFIX=$(if ($env:DEPS_PREFIX -ne $null) {$env:DEPS_PREFIX} else {".deps/usr"}); # $env:CMAKE_BUILD_TYPE is ignored by cmake when not using ninja
} $cmakeBuildType = $(if ($null -ne $env:CMAKE_BUILD_TYPE) {$env:CMAKE_BUILD_TYPE} else {'RelWithDebInfo'});
if ($env:DEPS_BUILD_DIR -eq $null) { $depsCmakeVars = @{
$env:DEPS_BUILD_DIR = ".deps"; CMAKE_BUILD_TYPE=$cmakeBuildType;
} }
$uploadToCodeCov = $false $nvimCmakeVars = @{
CMAKE_BUILD_TYPE=$cmakeBuildType;
function exitIfFailed() { BUSTED_OUTPUT_TYPE = 'nvim';
if ($LastExitCode -ne 0) { DEPS_PREFIX=$(if ($null -ne $env:DEPS_PREFIX) {$env:DEPS_PREFIX} else {".deps/usr"});
exit $LastExitCode }
} if ($null -eq $env:DEPS_BUILD_DIR) {
} $env:DEPS_BUILD_DIR = Join-Path -Path $projectDir -ChildPath ".deps"
}
if (-not $NoTests) { $uploadToCodeCov = $false
node --version
npm.cmd --version function exitIfFailed() {
} if ($LastExitCode -ne 0) {
exit $LastExitCode
if (-Not (Test-Path -PathType container $env:DEPS_BUILD_DIR)) { }
write-host "cache dir not found: $($env:DEPS_BUILD_DIR)" }
mkdir $env:DEPS_BUILD_DIR
} else { function convertToCmakeArgs($vars) {
write-host "cache dir $($env:DEPS_BUILD_DIR) size: $(Get-ChildItem $env:DEPS_BUILD_DIR -recurse | Measure-Object -property length -sum | Select -expand sum)" return $vars.GetEnumerator() | ForEach-Object { "-D$($_.Key)=$($_.Value)" }
} }
$cmakeGeneratorArgs = '/verbosity:normal' $installationPath = vswhere.exe -latest -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath
$cmakeGenerator = 'Visual Studio 16 2019' if ($installationPath -and (Test-Path "$installationPath\Common7\Tools\vsdevcmd.bat")) {
& "${env:COMSPEC}" /s /c "`"$installationPath\Common7\Tools\vsdevcmd.bat`" -arch=x64 -no_logo && set" | ForEach-Object {
$installationPath = vswhere.exe -latest -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath $name, $value = $_ -split '=', 2
if ($installationPath -and (test-path "$installationPath\Common7\Tools\vsdevcmd.bat")) { Set-Content env:\"$name" $value
& "${env:COMSPEC}" /s /c "`"$installationPath\Common7\Tools\vsdevcmd.bat`" -arch=x${bits} -no_logo && set" | foreach-object { }
$name, $value = $_ -split '=', 2 }
set-content env:\"$name" $value
} function BuildDeps {
}
if (Test-Path -PathType container $env:DEPS_BUILD_DIR) {
if (-not $NoTests) { $cachedBuildTypeStr = $(Get-Content $env:DEPS_BUILD_DIR\CMakeCache.txt | Select-String -Pattern "CMAKE_BUILD_TYPE.*=($cmakeBuildType)")
python -m ensurepip if (-not $cachedBuildTypeStr) {
python -m pip install pynvim ; exitIfFailed Write-Warning " unable to validate build type from cache dir ${env:DEPS_BUILD_DIR}"
# Sanity check }
python -c "import pynvim; print(str(pynvim))" ; exitIfFailed }
gem.cmd install --pre neovim # we currently can't use ninja for cmake.deps, see #19405
Get-Command -CommandType Application neovim-ruby-host.bat $depsCmakeGenerator = "Visual Studio 16 2019"
$depsCmakeGeneratorPlf = "x64"
npm.cmd install -g neovim cmake -S "$projectDir\cmake.deps" -B $env:DEPS_BUILD_DIR -G $depsCmakeGenerator -A $depsCmakeGeneratorPlf $(convertToCmakeArgs($depsCmakeVars)); exitIfFailed
Get-Command -CommandType Application neovim-node-host.cmd
npm.cmd link neovim $depsCmakeNativeToolOptions= @('/verbosity:normal', '/m')
} cmake --build $env:DEPS_BUILD_DIR --config $cmakeBuildType -- $depsCmakeNativeToolOptions; exitIfFailed
}
function convertToCmakeArgs($vars) {
return $vars.GetEnumerator() | foreach { "-D$($_.Key)=$($_.Value)" } function Build {
} cmake -S $projectDir -B $buildDir $(convertToCmakeArgs($nvimCmakeVars)) -G Ninja; exitIfFailed
cmake --build $buildDir --config $cmakeBuildType; exitIfFailed
cd $env:DEPS_BUILD_DIR }
if ($bits -eq 32) {
cmake -G $cmakeGenerator -A Win32 $(convertToCmakeArgs($depsCmakeVars)) "$buildDir/cmake.deps/" ; exitIfFailed function EnsureTestDeps {
} else { & $buildDir\bin\nvim.exe "--version"; exitIfFailed
cmake -G $cmakeGenerator -A x64 $(convertToCmakeArgs($depsCmakeVars)) "$buildDir/cmake.deps/" ; exitIfFailed
} # Ensure that the "win32" feature is set.
cmake --build . --config $cmakeBuildType -- $cmakeGeneratorArgs ; exitIfFailed & $buildDir\bin\nvim -u NONE --headless -c 'exe !has(\"win32\").\"cq\"' ; exitIfFailed
cd $buildDir
python -m pip install pynvim
# Build Neovim # Sanity check
mkdir build python -c "import pynvim; print(str(pynvim))"; exitIfFailed
cd build
if ($bits -eq 32) { gem.cmd install --pre neovim
cmake -G $cmakeGenerator -A Win32 $(convertToCmakeArgs($nvimCmakeVars)) .. ; exitIfFailed Get-Command -CommandType Application neovim-ruby-host.bat; exitIfFailed
} else {
cmake -G $cmakeGenerator -A x64 $(convertToCmakeArgs($nvimCmakeVars)) .. ; exitIfFailed node --version
} npm.cmd --version
cmake --build . --config $cmakeBuildType -- $cmakeGeneratorArgs ; exitIfFailed
.\bin\nvim --version ; exitIfFailed npm.cmd install -g neovim; exitIfFailed
Get-Command -CommandType Application neovim-node-host.cmd; exitIfFailed
# Ensure that the "win32" feature is set. npm.cmd link neovim
.\bin\nvim -u NONE --headless -c 'exe !has(\"win32\").\"cq\"' ; exitIfFailed
if ($env:USE_LUACOV -eq 1) {
if ($env:USE_LUACOV -eq 1) { & $env:DEPS_PREFIX\luarocks\luarocks.bat install cluacov
& $env:DEPS_PREFIX\luarocks\luarocks.bat install cluacov }
} }
if (-not $NoTests) { function Test {
# Functional tests # Functional tests
# The $LastExitCode from MSBuild can't be trusted # The $LastExitCode from MSBuild can't be trusted
$failed = $false $failed = $false
# Run only this test file: cmake --build $buildDir --target functionaltest 2>&1 |
# $env:TEST_FILE = "test\functional\foo.lua" ForEach-Object { $failed = $failed -or
cmake --build . --config $cmakeBuildType --target functionaltest -- $cmakeGeneratorArgs 2>&1 | $_ -match 'functional tests failed with error'; $_ }
foreach { $failed = $failed -or
$_ -match 'functional tests failed with error'; $_ } if ($failed) {
exit $LastExitCode
if ($uploadToCodecov) { }
if ($env:USE_LUACOV -eq 1) {
& $env:DEPS_PREFIX\bin\luacov.bat if (-not $uploadToCodecov) {
} return
bash -l /c/projects/neovim/ci/common/submit_coverage.sh functionaltest }
} if ($env:USE_LUACOV -eq 1) {
if ($failed) { & $env:DEPS_PREFIX\bin\luacov.bat
exit $LastExitCode }
} bash -l /c/projects/neovim/ci/common/submit_coverage.sh functionaltest
}
# Old tests
# Add MSYS to path, required for e.g. `find` used in test scripts. function TestOld {
# But would break functionaltests, where its `more` would be used then. # Old tests
$OldPath = $env:PATH # Add MSYS to path, required for e.g. `find` used in test scripts.
$env:PATH = "C:\msys64\usr\bin;$env:PATH" # But would break functionaltests, where its `more` would be used then.
& "C:\msys64\mingw$bits\bin\mingw32-make.exe" -C $(Convert-Path ..\src\nvim\testdir) VERBOSE=1 ; exitIfFailed $OldPath = $env:PATH
$env:PATH = $OldPath $env:PATH = "C:\msys64\usr\bin;$env:PATH"
& "C:\msys64\mingw64\bin\mingw32-make.exe" -C $(Convert-Path $projectDir\src\nvim\testdir) VERBOSE=1; exitIfFailed
if ($uploadToCodecov) { $env:PATH = $OldPath
bash -l /c/projects/neovim/ci/common/submit_coverage.sh oldtest
} if ($uploadToCodecov) {
} bash -l /c/projects/neovim/ci/common/submit_coverage.sh oldtest
}
# Ensure choco's cpack is not in PATH otherwise, it conflicts with CMake's }
if (Test-Path -Path $env:ChocolateyInstall\bin\cpack.exe) {
Remove-Item -Path $env:ChocolateyInstall\bin\cpack.exe -Force
} function Package {
cmake --build $buildDir --target package
# Build artifacts }
cpack -C $cmakeBuildType
if ($PSCmdlet.ParameterSetName) {
& (Get-ChildItem "Function:$($PSCmdlet.ParameterSetName)")
exit
}