build.ps1 5.0 KB

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