Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Improve testplugin setup #33

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"]
2 changes: 1 addition & 1 deletion example/Dockerfile
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
44 changes: 24 additions & 20 deletions example/Makefile
Original file line number Diff line number Diff line change
@@ -1,21 +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 -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 \
$(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; \
Expand All @@ -30,31 +27,38 @@ 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; \
$(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('/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; \
Expand Down
4 changes: 3 additions & 1 deletion example/test/vimrc → example/testbed.vim
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
" vint: -ProhibitSetNoCompatible
source /rtp.vim

let s:this_dir = expand('<sfile>:h')
exe 'set runtimepath+='.s:this_dir.'/test/plugins/vader.vim'

filetype plugin indent on
syntax on
Expand Down
2 changes: 2 additions & 0 deletions scripts/init.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
set runtimepath+=/testbed
source /testbed/testbed.vim
81 changes: 52 additions & 29 deletions scripts/install_vim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
CONFIG_ARGS="$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
Expand All @@ -86,7 +117,15 @@ EOF
if [ -n "$PYTHON3" ]; then
apk add --virtual vim-build python3-dev
if [ "$FLAVOR" = vim ]; then
CONFIG_ARGS="$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
Expand All @@ -97,7 +136,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
Expand All @@ -106,39 +145,20 @@ 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
echo 'NOTE: -lua is automatically used with Neovim 0.2.1+, and not supported before.'
fi
fi

if [ "$FLAVOR" = vim ] && [ -n "$CONFIGURE_OPTIONS" ]; then
CONFIG_ARGS="$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.
Expand Down Expand Up @@ -192,9 +212,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"

Expand Down Expand Up @@ -238,6 +258,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."
Expand Down
3 changes: 0 additions & 3 deletions scripts/rtp.vim

This file was deleted.

7 changes: 3 additions & 4 deletions scripts/run_vim.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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" "$@"