From 40feced78700434ca08d061b428fda5efaff9a22 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 14 May 2017 14:00:07 +0200 Subject: [PATCH] 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 ef4fab1..fc883ea 100644 --- a/example/Dockerfile +++ b/example/Dockerfile @@ -1,6 +1,6 @@ FROM testbed/vim -RUN install_vim -tag v7.1 -name vim71 -build \ +RUN install_vim -tag v7.1 -name vim71 -py2 -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 ef98ebd..c2035a4 100644 --- a/example/Makefile +++ b/example/Makefile @@ -37,6 +37,13 @@ test: test-setup 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 dbbd22c..5519de5 100644 --- a/scripts/install_vim.sh +++ b/scripts/install_vim.sh @@ -71,10 +71,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 -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 @@ -85,7 +116,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 @@ -113,31 +152,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 -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.