Skip to content

Commit

Permalink
Workflow improvements.
Browse files Browse the repository at this point in the history
- Build and run tests in `install.sh`.

- Implement Python version detection on Mac OS X.

- Set up Travis CI.
  • Loading branch information
nixprime committed Sep 16, 2016
1 parent 7f96ff3 commit c4779dc
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 23 deletions.
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Output directories
bin/
build/

# Binaries
*.bin

# Vim
*[._]s[a-w][a-z]

Expand Down
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Language must be "generic" to get minimal Trusty image.
language: generic

env:
- TEST_PY=py2
- TEST_PY=py3

os:
- linux
- osx

# Need Trusty for version of GCC that supports C++11.
dist: trusty
sudo: required
addons:
apt:
packages:
- cmake
- libboost-dev
- libboost-program-options-dev
- python-dev
- python3-dev

osx_image: xcode7

install: ./.travis/install.sh

script: ./.travis/script.sh
16 changes: 16 additions & 0 deletions .travis/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

if [[ "${TRAVIS_OS_NAME}" == 'osx' ]]; then
brew update
# Skip updating Boost, since doing so takes a long time and we'd like to
# know about compatibility breakage anyway.
brew install cmake
case "${TEST_PY}" in
py2) brew outdated python || brew upgrade python;;
py3) brew install python3;;
esac
fi
11 changes: 11 additions & 0 deletions .travis/script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

case "${TEST_PY}" in
py2) PY3=OFF ./install.sh;;
py3) PY3=ON ./install.sh;;
*) echo "Unknown TEST_PY: ${TEST_PY}"; false;;
esac
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ else()
set_target_properties(cpsm_py PROPERTIES PREFIX "")
endif()
install(TARGETS cpsm_py DESTINATION ${PROJECT_SOURCE_DIR}/autoload)
install(TARGETS cpsm_py DESTINATION ${PROJECT_SOURCE_DIR}/test)
install(TARGETS cpsm_py DESTINATION ${PROJECT_SOURCE_DIR}/bin)

add_executable(cpsm_cli EXCLUDE_FROM_ALL src/cpsm_cli_main.cc)
add_executable(cpsm_cli src/cpsm_cli_main.cc)
target_link_libraries(cpsm_cli cpsm_core ${Boost_PROGRAM_OPTIONS_LIBRARIES})
set_target_properties(cpsm_cli PROPERTIES PREFIX "" SUFFIX ".bin")
install(TARGETS cpsm_cli DESTINATION ${PROJECT_SOURCE_DIR}/test OPTIONAL)
install(TARGETS cpsm_cli DESTINATION ${PROJECT_SOURCE_DIR}/bin)

add_executable(matcher_test EXCLUDE_FROM_ALL src/matcher_test.cc)
enable_testing()

add_executable(matcher_test src/matcher_test.cc)
target_link_libraries(matcher_test cpsm_core)
set_target_properties(matcher_test PROPERTIES PREFIX "" SUFFIX ".bin")
install(TARGETS matcher_test DESTINATION ${PROJECT_SOURCE_DIR}/test OPTIONAL)
add_test(matcher_test matcher_test)
File renamed without changes.
File renamed without changes.
File renamed without changes.
50 changes: 37 additions & 13 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,48 @@
set -o errexit
set -o nounset
set -o pipefail
set +o histexpand

if [ -z ${PY3+x} ]; then
# neovim's --version doesn't indicate the presence or absence of python3
# support.
have_py3=$(script -q --return -c "vim -S <(echo -e \"redir! > /dev/stderr\\necho has('python3')\\nqa!\") 2>&3" /dev/null 3>&1 >/dev/null)
if [ "$have_py3" -eq "1" ]; then
function vim_has {
local vim="$1"
local feature="$2"

# We can't use `vim --version` because neovim is too unique to print
# +/-python{,3}, so instead we get to play stupid games with script(1).
local uname="$(uname)"
case "${uname}" in
Linux) echo $(script -eqc "${vim} -S <(echo -e \"echo 'x=' . has('${feature}')\\nqa!\")" /dev/null | grep -o 'x=.' | grep -o '[[:digit:]]' -m 1);;
Darwin | FreeBSD) echo $(script -q /dev/null ${vim} -S <(echo -e "echo 'x=' . has('${feature}')\nqa!") | grep -o 'x=.' | grep -o '[[:digit:]]' -m 1);;
*) >&2 echo "ERROR: Unknown uname: ${uname}; Vim feature detection not supported"; false;;
esac
}

if [ -z "${PY3+x}" ]; then
VIM="${VIM:-vim}"
echo "PY3 not specified; inferring Python version from ${VIM}"
have_py2=$(vim_has ${VIM} python)
have_py3=$(vim_has ${VIM} python3)
if [ "${have_py3}" -eq "1" ]; then
echo "Python 3 selected"
PY3="ON"
else
elif [ "${have_py2}" -eq "1" ]; then
echo "Python 2 selected"
PY3="OFF"
else
>&2 echo "ERROR: No Python support detected"
false
fi
else
case "${PY3}" in
ON) echo "Python 3 selected by PY3=${PY3}";;
OFF) echo "Python 2 selected by PY3=${PY3}";;
*) >&2 echo "ERROR: invalid PY3=${PY3}"; false;;
esac
fi
echo "PY3=$PY3"

rm -rf build
rm -rf bin build
mkdir -p build
{
(
cd build
cmake -DPY3:BOOL=$PY3 ..
make install
}
cmake -DPY3:BOOL=${PY3} ..
make install && make test
)

0 comments on commit c4779dc

Please sign in to comment.