build.ps1 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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 -Su" ; 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. # Setup python (use AppVeyor system python)
  80. # Disambiguate python3, if needed
  81. if (-not (Test-Path -Path C:\hostedtoolcache\windows\Python\3.5.4\x64\python3.exe) ) {
  82. move C:\hostedtoolcache\windows\Python\3.5.4\x64\python.exe C:\hostedtoolcache\windows\Python\3.5.4\x64\python3.exe
  83. }
  84. $env:PATH = "C:\hostedtoolcache\windows\Python\2.7.18\x64;C:\hostedtoolcache\windows\Python\3.5.4\x64;$env:PATH"
  85. python -m pip install pynvim ; exitIfFailed
  86. python3 -m pip install pynvim ; exitIfFailed
  87. # Sanity check
  88. python -c "import pynvim; print(str(pynvim))" ; exitIfFailed
  89. python3 -c "import pynvim; print(str(pynvim))" ; exitIfFailed
  90. gem.cmd install --pre neovim
  91. Get-Command -CommandType Application neovim-ruby-host.bat
  92. npm.cmd install -g neovim
  93. Get-Command -CommandType Application neovim-node-host.cmd
  94. npm.cmd link neovim
  95. }
  96. if ($compiler -eq 'MSVC') {
  97. # Required for LuaRocks (https://github.com/luarocks/luarocks/issues/1039#issuecomment-507296940).
  98. $env:VCINSTALLDIR = "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.16.27023/"
  99. }
  100. function convertToCmakeArgs($vars) {
  101. return $vars.GetEnumerator() | foreach { "-D$($_.Key)=$($_.Value)" }
  102. }
  103. cd $env:DEPS_BUILD_DIR
  104. cmake -G $cmakeGenerator $(convertToCmakeArgs($depsCmakeVars)) "$buildDir/third-party/" ; exitIfFailed
  105. cmake --build . --config $cmakeBuildType -- $cmakeGeneratorArgs ; exitIfFailed
  106. cd $buildDir
  107. # Build Neovim
  108. mkdir build
  109. cd build
  110. cmake -G $cmakeGenerator $(convertToCmakeArgs($nvimCmakeVars)) .. ; exitIfFailed
  111. cmake --build . --config $cmakeBuildType -- $cmakeGeneratorArgs ; exitIfFailed
  112. .\bin\nvim --version ; exitIfFailed
  113. # Ensure that the "win32" feature is set.
  114. .\bin\nvim -u NONE --headless -c 'exe !has(\"win32\").\"cq\"' ; exitIfFailed
  115. if ($env:USE_LUACOV -eq 1) {
  116. & $env:DEPS_PREFIX\luarocks\luarocks.bat install cluacov
  117. }
  118. if (-not $NoTests) {
  119. # Functional tests
  120. # The $LastExitCode from MSBuild can't be trusted
  121. $failed = $false
  122. # Run only this test file:
  123. # $env:TEST_FILE = "test\functional\foo.lua"
  124. cmake --build . --config $cmakeBuildType --target functionaltest -- $cmakeGeneratorArgs 2>&1 |
  125. foreach { $failed = $failed -or
  126. $_ -match 'functional tests failed with error'; $_ }
  127. if ($uploadToCodecov) {
  128. if ($env:USE_LUACOV -eq 1) {
  129. & $env:DEPS_PREFIX\bin\luacov.bat
  130. }
  131. bash -l /c/projects/neovim/ci/common/submit_coverage.sh functionaltest
  132. }
  133. if ($failed) {
  134. exit $LastExitCode
  135. }
  136. # Old tests
  137. # Add MSYS to path, required for e.g. `find` used in test scripts.
  138. # But would break functionaltests, where its `more` would be used then.
  139. $OldPath = $env:PATH
  140. $env:PATH = "C:\msys64\usr\bin;$env:PATH"
  141. & "C:\msys64\mingw$bits\bin\mingw32-make.exe" -C $(Convert-Path ..\src\nvim\testdir) VERBOSE=1 ; exitIfFailed
  142. $env:PATH = $OldPath
  143. if ($uploadToCodecov) {
  144. bash -l /c/projects/neovim/ci/common/submit_coverage.sh oldtest
  145. }
  146. }
  147. # Ensure choco's cpack is not in PATH otherwise, it conflicts with CMake's
  148. if (Test-Path -Path $env:ChocolateyInstall\bin\cpack.exe) {
  149. Remove-Item -Path $env:ChocolateyInstall\bin\cpack.exe -Force
  150. }
  151. # Build artifacts
  152. cpack -G ZIP -C RelWithDebInfo
  153. if ($env:APPVEYOR_REPO_TAG_NAME -ne $null) {
  154. cpack -G NSIS -C RelWithDebInfo
  155. }