install-vim 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. #!/bin/sh
  2. #
  3. # Install and setup a Vim or Neovim for running tests.
  4. # This should work on both Travis and people's desktop computers, and be 100%
  5. # independent from any system installed Vim.
  6. #
  7. # It will echo the full path to a Vim binary, e.g.:
  8. # /some/path/src/vim
  9. set -euC
  10. vimgodir=$(cd -P "$(dirname "$0")/.." > /dev/null && pwd)
  11. cd "$vimgodir"
  12. vim=${1:-}
  13. case "$vim" in
  14. "vim-7.4")
  15. # This is what the most recent Ubuntu LTS (16.04) ships with.
  16. tag="v7.4.1689"
  17. giturl="https://github.com/vim/vim"
  18. ;;
  19. "vim-8.0")
  20. # This follows the version in Arch Linux. Vim's master branch isn't always
  21. # stable, and we don't want to have the build fail because Vim introduced a
  22. # bug.
  23. tag="v8.0.1176"
  24. giturl="https://github.com/vim/vim"
  25. ;;
  26. "nvim")
  27. # Use latest stable version.
  28. tag="v0.2.0"
  29. giturl="https://github.com/neovim/neovim"
  30. ;;
  31. *)
  32. echo "unknown version: '${1:-}'"
  33. echo "First argument must be 'vim-7.4', 'vim-8.0', or 'nvim'."
  34. exit 1
  35. ;;
  36. esac
  37. srcdir="/tmp/vim-go-test/$1-src"
  38. installdir="/tmp/vim-go-test/$1-install"
  39. # Use cached installdir.
  40. if [ -d "$installdir" ]; then
  41. echo "$installdir exists; skipping build."
  42. # The ./scripts/test script relies on this.
  43. echo "installed to: $installdir"
  44. exit 0
  45. fi
  46. mkdir -p "$srcdir"
  47. cd "$srcdir"
  48. # Neovim build requires more deps than Vim and is annoying, so we use the
  49. # binary.
  50. # 0.2.0 doesn't have a binary build for Linux, so we use 0.2.1-dev for now.
  51. if [ "$1" = "nvim" ]; then
  52. # TODO: Use macOS binaries on macOS
  53. curl -Ls https://github.com/neovim/neovim/releases/download/nightly/nvim-linux64.tar.gz |
  54. tar xzf - -C /tmp/vim-go-test/
  55. mv /tmp/vim-go-test/nvim-linux64 /tmp/vim-go-test/nvim-install
  56. mkdir -p "$installdir/share/nvim/runtime/pack/vim-go/start"
  57. ln -s "$vimgodir" "$installdir/share/nvim/runtime/pack/vim-go/start/vim-go"
  58. # Consistent paths makes calling things easier.
  59. mv "$installdir/bin/nvim" "$installdir/bin/vim"
  60. mkdir -p "$installdir/share/vim/vimgo/pack"
  61. ln -s "$installdir/share/nvim/runtime/pack/vim-go" "$installdir/share/vim/vimgo/pack/vim-go"
  62. # Build Vim from source.
  63. else
  64. if [ -d "$srcdir/.git" ]; then
  65. echo "Skipping clone as $srcdir/.git exists"
  66. else
  67. echo "Cloning $tag from $giturl"
  68. git clone --branch "$tag" --depth 1 "$giturl" "$srcdir"
  69. fi
  70. ./configure --prefix="$installdir" --with-features=huge --disable-gui
  71. make install
  72. mkdir -p "$installdir/share/vim/vimgo/pack/vim-go/start"
  73. ln -s "$vimgodir" "$installdir/share/vim/vimgo/pack/vim-go/start/vim-go"
  74. fi
  75. # Make sure all Go tools and other dependencies are installed.
  76. echo "Installing Go binaries"
  77. export GOPATH=$installdir
  78. export PATH=${GOPATH}/bin:$PATH
  79. "$vimgodir/scripts/run-vim" $vim +':silent :GoUpdateBinaries' +':qa'
  80. echo "Installing lint tools"
  81. (
  82. mkdir -p "$installdir/share/vim/vimgo/pack/vim-go/start/"
  83. cd "$installdir/share/vim/vimgo/pack/vim-go/start/"
  84. [ -d "vim-vimhelplint" ] || git clone --depth 1 --quiet https://github.com/machakann/vim-vimhelplint
  85. [ -d "vim-vimlparser" ] || git clone --depth 1 --quiet https://github.com/ynkdir/vim-vimlparser
  86. [ -d "vim-vimlint" ] || git clone --depth 1 --quiet https://github.com/syngan/vim-vimlint
  87. )
  88. # Don't really need source after successful install.
  89. rm -rf "$srcdir"
  90. echo "installed to: $installdir"
  91. # vim:ts=2:sts=2:sw=2:et