build.ps1 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. param([switch]$NoTests)
  2. Set-StrictMode -Version Latest
  3. $ErrorActionPreference = 'Stop'
  4. $ProgressPreference = 'SilentlyContinue'
  5. $env:CONFIGURATION -match '^(?<compiler>\w+)_(?<bits>32|64)(?:-(?<option>\w+))?$'
  6. $compiler = $Matches.compiler
  7. $compileOption = if ($Matches -contains 'option') {$Matches.option} else {''}
  8. $bits = $Matches.bits
  9. $cmakeBuildType = $(if ($env:CMAKE_BUILD_TYPE -ne $null) {$env:CMAKE_BUILD_TYPE} else {'RelWithDebInfo'});
  10. $buildDir = [System.IO.Path]::GetFullPath("$(pwd)")
  11. $depsCmakeVars = @{
  12. CMAKE_BUILD_TYPE = $cmakeBuildType;
  13. }
  14. $nvimCmakeVars = @{
  15. CMAKE_BUILD_TYPE = $cmakeBuildType;
  16. BUSTED_OUTPUT_TYPE = 'nvim';
  17. DEPS_PREFIX=$(if ($env:DEPS_PREFIX -ne $null) {$env:DEPS_PREFIX} else {".deps/usr"});
  18. }
  19. if ($env:DEPS_BUILD_DIR -eq $null) {
  20. $env:DEPS_BUILD_DIR = ".deps";
  21. }
  22. $uploadToCodeCov = $false
  23. function exitIfFailed() {
  24. if ($LastExitCode -ne 0) {
  25. exit $LastExitCode
  26. }
  27. }
  28. if (-not $NoTests) {
  29. node --version
  30. npm.cmd --version
  31. }
  32. if (-Not (Test-Path -PathType container $env:DEPS_BUILD_DIR)) {
  33. write-host "cache dir not found: $($env:DEPS_BUILD_DIR)"
  34. mkdir $env:DEPS_BUILD_DIR
  35. } else {
  36. write-host "cache dir $($env:DEPS_BUILD_DIR) size: $(Get-ChildItem $env:DEPS_BUILD_DIR -recurse | Measure-Object -property length -sum | Select -expand sum)"
  37. }
  38. if ($compiler -eq 'MINGW') {
  39. if ($bits -eq 32) {
  40. $arch = 'i686'
  41. }
  42. elseif ($bits -eq 64) {
  43. $arch = 'x86_64'
  44. }
  45. if ($compileOption -eq 'gcov') {
  46. $nvimCmakeVars['USE_GCOV'] = 'ON'
  47. $uploadToCodecov = $true
  48. $env:GCOV = "C:\msys64\mingw$bits\bin\gcov"
  49. # Setup/build Lua coverage.
  50. $env:USE_LUACOV = 1
  51. $env:BUSTED_ARGS = "--coverage"
  52. }
  53. # These are native MinGW builds, but they use the toolchain inside
  54. # MSYS2, this allows using all the dependencies and tools available
  55. # in MSYS2, but we cannot build inside the MSYS2 shell.
  56. $cmakeGenerator = 'Ninja'
  57. $cmakeGeneratorArgs = '-v'
  58. $mingwPackages = @('ninja', 'cmake', 'diffutils').ForEach({
  59. "mingw-w64-$arch-$_"
  60. })
  61. # Add MinGW to the PATH
  62. $env:PATH = "C:\msys64\mingw$bits\bin;$env:PATH"
  63. # Avoid pacman "warning" which causes non-zero return code. https://github.com/open62541/open62541/issues/2068
  64. & C:\msys64\usr\bin\mkdir -p /var/cache/pacman/pkg
  65. # Build third-party dependencies
  66. C:\msys64\usr\bin\bash -lc "pacman --verbose --noconfirm -Syu" ; exitIfFailed
  67. C:\msys64\usr\bin\bash -lc "pacman --verbose --noconfirm --needed -S $mingwPackages" ; exitIfFailed
  68. }
  69. elseif ($compiler -eq 'MSVC') {
  70. $cmakeGeneratorArgs = '/verbosity:normal'
  71. if ($bits -eq 32) {
  72. $cmakeGenerator = 'Visual Studio 15 2017'
  73. }
  74. elseif ($bits -eq 64) {
  75. $cmakeGenerator = 'Visual Studio 15 2017 Win64'
  76. }
  77. }
  78. if (-not $NoTests) {
  79. python -m ensurepip
  80. python -m pip install pynvim ; exitIfFailed
  81. # Sanity check
  82. python -c "import pynvim; print(str(pynvim))" ; exitIfFailed
  83. gem.cmd install --pre neovim
  84. Get-Command -CommandType Application neovim-ruby-host.bat
  85. npm.cmd install -g neovim
  86. Get-Command -CommandType Application neovim-node-host.cmd
  87. npm.cmd link neovim
  88. }
  89. if ($compiler -eq 'MSVC') {
  90. # Required for LuaRocks (https://github.com/luarocks/luarocks/issues/1039#issuecomment-507296940).
  91. $env:VCINSTALLDIR = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/"
  92. }
  93. function convertToCmakeArgs($vars) {
  94. return $vars.GetEnumerator() | foreach { "-D$($_.Key)=$($_.Value)" }
  95. }
  96. cd $env:DEPS_BUILD_DIR
  97. cmake -G $cmakeGenerator $(convertToCmakeArgs($depsCmakeVars)) "$buildDir/third-party/" ; exitIfFailed
  98. cmake --build . --config $cmakeBuildType -- $cmakeGeneratorArgs ; exitIfFailed
  99. cd $buildDir
  100. # Build Neovim
  101. mkdir build
  102. cd build
  103. cmake -G $cmakeGenerator $(convertToCmakeArgs($nvimCmakeVars)) .. ; exitIfFailed
  104. cmake --build . --config $cmakeBuildType -- $cmakeGeneratorArgs ; exitIfFailed
  105. .\bin\nvim --version ; exitIfFailed
  106. # Ensure that the "win32" feature is set.
  107. .\bin\nvim -u NONE --headless -c 'exe !has(\"win32\").\"cq\"' ; exitIfFailed
  108. if ($env:USE_LUACOV -eq 1) {
  109. & $env:DEPS_PREFIX\luarocks\luarocks.bat install cluacov
  110. }
  111. if (-not $NoTests) {
  112. # Functional tests
  113. # The $LastExitCode from MSBuild can't be trusted
  114. $failed = $false
  115. # Run only this test file:
  116. # $env:TEST_FILE = "test\functional\foo.lua"
  117. cmake --build . --config $cmakeBuildType --target functionaltest -- $cmakeGeneratorArgs 2>&1 |
  118. foreach { $failed = $failed -or
  119. $_ -match 'functional tests failed with error'; $_ }
  120. if ($uploadToCodecov) {
  121. if ($env:USE_LUACOV -eq 1) {
  122. & $env:DEPS_PREFIX\bin\luacov.bat
  123. }
  124. bash -l /c/projects/neovim/ci/common/submit_coverage.sh functionaltest
  125. }
  126. if ($failed) {
  127. exit $LastExitCode
  128. }
  129. # Old tests
  130. # Add MSYS to path, required for e.g. `find` used in test scripts.
  131. # But would break functionaltests, where its `more` would be used then.
  132. $OldPath = $env:PATH
  133. $env:PATH = "C:\msys64\usr\bin;$env:PATH"
  134. & "C:\msys64\mingw$bits\bin\mingw32-make.exe" -C $(Convert-Path ..\src\nvim\testdir) VERBOSE=1 ; exitIfFailed
  135. $env:PATH = $OldPath
  136. if ($uploadToCodecov) {
  137. bash -l /c/projects/neovim/ci/common/submit_coverage.sh oldtest
  138. }
  139. }
  140. # Ensure choco's cpack is not in PATH otherwise, it conflicts with CMake's
  141. if (Test-Path -Path $env:ChocolateyInstall\bin\cpack.exe) {
  142. Remove-Item -Path $env:ChocolateyInstall\bin\cpack.exe -Force
  143. }
  144. # Build artifacts
  145. cpack -G ZIP -C RelWithDebInfo
  146. if ($env:APPVEYOR_REPO_TAG_NAME -ne $null) {
  147. cpack -G NSIS -C RelWithDebInfo
  148. }