From 28264413ec8eab06ddf5b7545549bb0f23fb36da Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 13 May 2017 17:57:32 +0200 Subject: [PATCH 1/5] WIP: improve testplugin setup Fixes https://github.com/tweekmonster/vim-testbed/issues/8 --- Dockerfile | 12 +++++++----- example/Makefile | 7 +++---- example/{test/vimrc => testbed.vim} | 4 +++- scripts/init.vim | 2 ++ scripts/rtp.vim | 3 --- scripts/run_vim.sh | 7 +++---- 6 files changed, 18 insertions(+), 17 deletions(-) rename example/{test/vimrc => testbed.vim} (72%) create mode 100644 scripts/init.vim delete mode 100644 scripts/rtp.vim diff --git a/Dockerfile b/Dockerfile index 6883be0..62b29a8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,7 @@ RUN apk --no-cache upgrade RUN adduser -h /home/vimtest -s /bin/sh -D -u 8465 vimtest -RUN mkdir -p /vim /vim-build/bin /plugins -RUN chown vimtest:vimtest /home /plugins +RUN mkdir -p /vim /vim-build/bin # Useful during tests to have these packages in a deeper layer cached already. # RUN apk --no-cache add --virtual vim-build build-base @@ -14,14 +13,17 @@ ADD scripts/argecho.sh /vim-build/bin/argecho ADD scripts/install_vim.sh /sbin/install_vim ADD scripts/run_vim.sh /sbin/run_vim -RUN chmod +x /vim-build/bin/argecho /sbin/install_vim /sbin/run_vim +RUN mkdir /home/vimtest/.vim /home/vimtest/.config +ADD scripts/init.vim /home/vimtest/.vim/ +RUN ln -s ../.vim /home/vimtest/.config/nvim +RUN ln -s .vim/init.vim /home/vimtest/.vimrc -ADD scripts/rtp.vim /rtp.vim +RUN chmod +x /vim-build/bin/argecho /sbin/install_vim /sbin/run_vim # The user directory for setup VOLUME /home/vimtest # Your plugin -VOLUME /testplugin +VOLUME /testbed ENTRYPOINT ["/sbin/run_vim"] diff --git a/example/Makefile b/example/Makefile index 5f7d092..0722e47 100644 --- a/example/Makefile +++ b/example/Makefile @@ -7,10 +7,9 @@ WRITABLE_HOME:=$(shell tmpdir=$$(mktemp -d --dry-run); \ cd $(CURDIR)/test; \ cp -a vimrc *.vader $${tmpdir}/; \ echo $${tmpdir}) -DOCKER = docker run -a stderr --rm \ - -v $(CURDIR):/testplugin \ - -v $(WRITABLE_HOME):/home/vimtest \ - -v $(CURDIR)/$(PLUGINS):/home/vimtest/plugins "$(IMAGE)" +DOCKER = docker run -ti --rm \ + -v $(CURDIR):/testbed \ + -v $(CURDIR)/$(PLUGINS):/home/testbed/.vim/plugins "$(IMAGE)" test: build $(PLUGINS)/vader.vim test: test_vim71_with_profiling_enabled diff --git a/example/test/vimrc b/example/testbed.vim similarity index 72% rename from example/test/vimrc rename to example/testbed.vim index 0a96881..0c31a51 100644 --- a/example/test/vimrc +++ b/example/testbed.vim @@ -1,5 +1,7 @@ " vint: -ProhibitSetNoCompatible -source /rtp.vim + +let s:this_dir = expand(':h') +exe 'set runtimepath+='.s:this_dir.'/test/plugins/vader.vim' filetype plugin indent on syntax on diff --git a/scripts/init.vim b/scripts/init.vim new file mode 100644 index 0000000..44a5fb1 --- /dev/null +++ b/scripts/init.vim @@ -0,0 +1,2 @@ +set runtimepath+=/testbed +source /testbed/testbed.vim diff --git a/scripts/rtp.vim b/scripts/rtp.vim deleted file mode 100644 index b831ae1..0000000 --- a/scripts/rtp.vim +++ /dev/null @@ -1,3 +0,0 @@ -set rtp=/home/vimtest/vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,/home/vimtest/vim/after -execute 'set rtp+='.join(filter(split(expand('/home/vimtest/plugins/*')), 'isdirectory(v:val)'), ',') -set rtp+=/testplugin diff --git a/scripts/run_vim.sh b/scripts/run_vim.sh index aadcf5c..be33a9c 100644 --- a/scripts/run_vim.sh +++ b/scripts/run_vim.sh @@ -15,7 +15,7 @@ if ! [ -x "/vim-build/bin/$BIN" ]; then fi # Set default vimrc to a visible file -ARGS="-u /home/vimtest/vimrc -i NONE" +ARGS="-i NONE" # Run as the vimtest user (when no USER is specified in the Dockerfile, i.e. # when running as root). @@ -27,10 +27,9 @@ if [ "$(id -u)" = 0 ]; then ARGS="$ARGS \"$1\"" shift done - exec su -l vimtest -c "cd /testplugin && /vim-build/bin/$BIN $ARGS" + exec su -l vimtest -c "cd /testbed && /vim-build/bin/$BIN $ARGS" fi -cd /testplugin || exit - +cd /testbed || exit # shellcheck disable=SC2086 exec "/vim-build/bin/$BIN" "$@" From 2344d20cb5f8c9edb305d89f57a0bc740c313e23 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 13 May 2017 18:01:20 +0200 Subject: [PATCH 2/5] example/Makefile: remove writable home, use TEMPDIR --- example/Makefile | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/example/Makefile b/example/Makefile index 0722e47..7e7ee19 100644 --- a/example/Makefile +++ b/example/Makefile @@ -1,20 +1,18 @@ SHELL := $(shell which bash) IMAGE := vim-testbed-example PLUGINS := test/plugins -# A writable home directory, required for Neovim. -WRITABLE_HOME:=$(shell tmpdir=$$(mktemp -d --dry-run); \ - mkdir -m 777 $${tmpdir}; \ - cd $(CURDIR)/test; \ - cp -a vimrc *.vader $${tmpdir}/; \ - echo $${tmpdir}) + DOCKER = docker run -ti --rm \ -v $(CURDIR):/testbed \ + $(if $(TEMPDIR),-v $(TEMPDIR):$(TEMPDIR)) \ -v $(CURDIR)/$(PLUGINS):/home/testbed/.vim/plugins "$(IMAGE)" +test: TEMPDIR:=$(shell mktemp -d -u) test: build $(PLUGINS)/vader.vim test: test_vim71_with_profiling_enabled test: set -ex; \ + mkdir -m 0777 $(TEMPDIR); \ vims="$$(docker run --rm $(IMAGE) ls /vim-build/bin | grep vim)"; \ if [ -z "$$vims" ]; then echo "No Vims found!"; exit 1; fi; \ count_vims=0; \ @@ -29,31 +27,31 @@ test: fi; \ for vim in "neovim-master --headless" vim-master; do \ $(DOCKER) $${vim} -u NONE \ - "+py import sys; open('/home/vimtest/py2', 'w').write(str(sys.version_info[0]))" \ - "+py3 import sys; open('/home/vimtest/py3', 'w').write(str(sys.version_info[0]))" \ + "+py import sys; open('$(TEMPDIR)/py2', 'w').write(str(sys.version_info[0]))" \ + "+py3 import sys; open('$(TEMPDIR)/py3', 'w').write(str(sys.version_info[0]))" \ '+q'; \ - if [ "$$(<$(WRITABLE_HOME)/py2)" != "2" ]; then \ + if [ "$$(<$(TEMPDIR)/py2)" != "2" ]; then \ echo "Failed to get Python version from $${vim} (2)." >&2; exit 1; \ fi; \ - if [ "$$(<$(WRITABLE_HOME)/py3)" != "3" ]; then \ + if [ "$$(<$(TEMPDIR)/py3)" != "3" ]; then \ echo "Failed to get Python version from $${vim} (3)." >&2; exit 1; \ fi; \ - $(RM) $(WRITABLE_HOME)/py*; \ + $(RM) $(TEMPDIR)/py*; \ done; \ for vim in "neovim-master --headless" vim-master; do \ $(DOCKER) $${vim} -u NONE \ - "+ruby open('/home/vimtest/ruby', 'w') { |f| f << 'ruby was here' }" \ + "+ruby open('$(TEMPDIR)/ruby', 'w') { |f| f << 'ruby was here' }" \ '+q'; \ - if [ "$$(<$(WRITABLE_HOME)/ruby)" != "ruby was here" ]; then \ + if [ "$$(<$(TEMPDIR)/ruby)" != "ruby was here" ]; then \ echo "Failed to get output from Ruby for $${vim}." >&2; exit 1; \ fi; \ - $(RM) $(WRITABLE_HOME)/ruby; \ + $(RM) $(TEMPDIR)/ruby; \ done; \ for vim in "neovim-master --headless" vim-master; do \ $(DOCKER) $${vim} -u NONE \ - "+lua io.open('/home/vimtest/lua', 'w'):write('lua was here')" \ + "+lua io.open('$(TEMPDIR)/lua', 'w'):write('lua was here')" \ '+q'; \ - if [ "$$(<$(WRITABLE_HOME)/lua)" != "lua was here" ]; then \ + if [ "$$(<$(TEMPDIR)/lua)" != "lua was here" ]; then \ echo "Failed to get output from Lua for $${vim}." >&2; exit 1; \ fi; \ done; \ From 1b4bf190f8921efc142ff46280aa9a8772831436 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sat, 13 May 2017 23:38:54 +0200 Subject: [PATCH 3/5] install_vim.sh: shellcheck / bail if VIM_BIN was not created --- scripts/install_vim.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/install_vim.sh b/scripts/install_vim.sh index be1f468..3f22ac9 100644 --- a/scripts/install_vim.sh +++ b/scripts/install_vim.sh @@ -238,6 +238,9 @@ build() { else VIM_BIN="$INSTALL_PREFIX/bin/nvim" fi + if ! [ -e "$VIM_BIN" ]; then + bail "Binary $VIM_BIN was not created." + fi link_target="/vim-build/bin/$NAME" if [ -e "$link_target" ]; then echo "WARNING: link target for $NAME exists already. Overwriting." From f29bdf5baae1c9f1e82d40ba7b69cce6940f0dc2 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 14 May 2017 00:24:14 +0200 Subject: [PATCH 4/5] install_vim.sh: use VIM_CONFIG_ARGS, select ncurses --- scripts/install_vim.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/install_vim.sh b/scripts/install_vim.sh index 3f22ac9..f4957de 100644 --- a/scripts/install_vim.sh +++ b/scripts/install_vim.sh @@ -60,7 +60,7 @@ EOF INSTALL_PREFIX="/vim-build/$VIM_NAME" if [ "$FLAVOR" = vim ]; then - CONFIG_ARGS="--prefix=$INSTALL_PREFIX --enable-multibyte --without-x --enable-gui=no --with-compiledby=vim-testbed" + VIM_CONFIG_ARGS="--prefix=$INSTALL_PREFIX --enable-multibyte --without-x --enable-gui=no --with-compiledby=vim-testbed --with-tlib=ncurses" fi set +x echo "TAG:$TAG" @@ -75,7 +75,7 @@ EOF if [ -n "$PYTHON2" ]; then apk add --virtual vim-build python-dev if [ "$FLAVOR" = vim ]; then - CONFIG_ARGS="$CONFIG_ARGS --enable-pythoninterp=dynamic" + VIM_CONFIG_ARGS="$VIM_CONFIG_ARGS --enable-pythoninterp=dynamic" else apk add --virtual vim-build py2-pip apk add python @@ -86,7 +86,7 @@ EOF if [ -n "$PYTHON3" ]; then apk add --virtual vim-build python3-dev if [ "$FLAVOR" = vim ]; then - CONFIG_ARGS="$CONFIG_ARGS --enable-python3interp=dynamic" + VIM_CONFIG_ARGS="$VIM_CONFIG_ARGS --enable-python3interp=dynamic" else apk add python3 pip3 install neovim @@ -97,7 +97,7 @@ EOF apk add --virtual vim-build ruby-dev apk add ruby if [ "$FLAVOR" = vim ]; then - CONFIG_ARGS="$CONFIG_ARGS --enable-rubyinterp" + VIM_CONFIG_ARGS="$VIM_CONFIG_ARGS --enable-rubyinterp" else apk add --virtual vim-build ruby-rdoc ruby-irb gem install neovim @@ -106,7 +106,7 @@ EOF if [ $LUA -eq 1 ]; then if [ "$FLAVOR" = vim ]; then - CONFIG_ARGS="$CONFIG_ARGS --enable-luainterp" + VIM_CONFIG_ARGS="$VIM_CONFIG_ARGS --enable-luainterp" apk add --virtual vim-build lua5.3-dev apk add lua5.3-libs else @@ -115,7 +115,7 @@ EOF fi if [ "$FLAVOR" = vim ] && [ -n "$CONFIGURE_OPTIONS" ]; then - CONFIG_ARGS="$CONFIG_ARGS $CONFIGURE_OPTIONS" + VIM_CONFIG_ARGS="$VIM_CONFIG_ARGS $CONFIGURE_OPTIONS" fi cd /vim @@ -192,9 +192,9 @@ build() { fi fi - echo "Configuring with: $CONFIG_ARGS" + echo "Configuring with: $VIM_CONFIG_ARGS" # shellcheck disable=SC2086 - ./configure $CONFIG_ARGS || bail "Could not configure" + ./configure $VIM_CONFIG_ARGS || bail "Could not configure" make CFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" -j4 || bail "Make failed" make install || bail "Install failed" From 76f56f30fb43b56ce562d48608ac8767845eb6f4 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 14 May 2017 14:00:07 +0200 Subject: [PATCH 5/5] Fix Python with Vim before Vim 7.3g, test it with vim71 --- example/Dockerfile | 2 +- example/Makefile | 7 +++++ scripts/install_vim.sh | 68 +++++++++++++++++++++++++++--------------- 3 files changed, 52 insertions(+), 25 deletions(-) diff --git a/example/Dockerfile b/example/Dockerfile index 2160252..b39a9c3 100644 --- a/example/Dockerfile +++ b/example/Dockerfile @@ -1,6 +1,6 @@ FROM testbed/vim -RUN install_vim -tag v7.1 -name vim71 -prebuild_script 'echo "#define FEAT_PROFILE" >> src/feature.h' -build \ +RUN install_vim -tag v7.1 -name vim71 -py2 -prebuild_script 'echo "#define FEAT_PROFILE" >> src/feature.h' -build \ -tag v7.3.429 -name vim73 -py -build \ -tag v7.4.052 -name vim74-trusty -build \ -tag master -py2 -py3 -ruby -lua -build \ diff --git a/example/Makefile b/example/Makefile index 7e7ee19..f8c4d5f 100644 --- a/example/Makefile +++ b/example/Makefile @@ -38,6 +38,13 @@ test: fi; \ $(RM) $(TEMPDIR)/py*; \ done; \ + $(DOCKER) vim71 -u NONE \ + "+py import sys; open('$(TEMPDIR)/py2', 'w').write(str(sys.version_info[0]))" \ + '+q'; \ + if [ "$$(<$(TEMPDIR)/py2)" != "2" ]; then \ + echo "Failed to get Python version from vim71 (2)." >&2; exit 1; \ + fi; \ + $(RM) $(TEMPDIR)/py2; \ for vim in "neovim-master --headless" vim-master; do \ $(DOCKER) $${vim} -u NONE \ "+ruby open('$(TEMPDIR)/ruby', 'w') { |f| f << 'ruby was here' }" \ diff --git a/scripts/install_vim.sh b/scripts/install_vim.sh index f4957de..02870b3 100644 --- a/scripts/install_vim.sh +++ b/scripts/install_vim.sh @@ -72,10 +72,41 @@ EOF apk add --virtual vim-build curl gcc libc-dev make + cd /vim + + if [ -d "$INSTALL_PREFIX" ]; then + echo "WARNING: $INSTALL_PREFIX exists already. Overwriting." + fi + + BUILD_DIR="${FLAVOR}-${repo}-${tag}" + if [ ! -d "$BUILD_DIR" ]; then + mkdir -p "$BUILD_DIR" + cd "$BUILD_DIR" + # The git package adds about 200MB+ to the image. So, no cloning. + url="https://github.com/$repo/archive/${tag}.tar.gz" + echo "Downloading $repo:$tag from $url" + curl --retry 3 -SL "$url" | tar zx --strip-components=1 + else + cd "$BUILD_DIR" + fi + + vim_has_dynamic_python() { + # Added in b744b2f (released as Vim 7.3g). + if [ -e src/configure.ac ]; then + return 1 + fi + grep -q -e '--enable-pythoninterp.*OPTS=.*dynamic' src/configure.in + } + if [ -n "$PYTHON2" ]; then apk add --virtual vim-build python-dev if [ "$FLAVOR" = vim ]; then - VIM_CONFIG_ARGS="$VIM_CONFIG_ARGS --enable-pythoninterp=dynamic" + if vim_has_dynamic_python; then + VIM_CONFIG_ARGS="$VIM_CONFIG_ARGS --enable-pythoninterp=dynamic" + else + VIM_CONFIG_ARGS="$VIM_CONFIG_ARGS --enable-pythoninterp" + apk add python + fi else apk add --virtual vim-build py2-pip apk add python @@ -86,7 +117,15 @@ EOF if [ -n "$PYTHON3" ]; then apk add --virtual vim-build python3-dev if [ "$FLAVOR" = vim ]; then - VIM_CONFIG_ARGS="$VIM_CONFIG_ARGS --enable-python3interp=dynamic" + if ! [ -e src/if_python3.c ]; then + echo 'WARNING: Python 3 support seems to be missing in this version?!' + fi + if vim_has_dynamic_python; then + VIM_CONFIG_ARGS="$VIM_CONFIG_ARGS --enable-python3interp=dynamic" + else + VIM_CONFIG_ARGS="$VIM_CONFIG_ARGS --enable-python3interp" + apk add python3 + fi else apk add python3 pip3 install neovim @@ -114,31 +153,12 @@ EOF fi fi - if [ "$FLAVOR" = vim ] && [ -n "$CONFIGURE_OPTIONS" ]; then - VIM_CONFIG_ARGS="$VIM_CONFIG_ARGS $CONFIGURE_OPTIONS" - fi - - cd /vim - - if [ -d "$INSTALL_PREFIX" ]; then - echo "WARNING: $INSTALL_PREFIX exists already. Overwriting." - fi - - BUILD_DIR="${FLAVOR}-${repo}-${tag}" - if [ ! -d "$BUILD_DIR" ]; then - mkdir -p "$BUILD_DIR" - cd "$BUILD_DIR" - # The git package adds about 200MB+ to the image. So, no cloning. - url="https://github.com/$repo/archive/${tag}.tar.gz" - echo "Downloading $repo:$tag from $url" - curl --retry 3 -SL "$url" | tar zx --strip-components=1 - else - cd "$BUILD_DIR" - fi - if [ "$FLAVOR" = vim ]; then apk add --virtual vim-build ncurses-dev apk add ncurses + if [ -n "$CONFIGURE_OPTIONS" ]; then + VIM_CONFIG_ARGS="$VIM_CONFIG_ARGS $CONFIGURE_OPTIONS" + fi elif [ "$FLAVOR" = neovim ]; then # Some of them will be installed already, but it is a good reference for # what is required.