diff --git a/.gitignore b/.gitignore index b5197fe..5c23683 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,7 @@ # Output directories +bin/ build/ -# Binaries -*.bin - # Vim *[._]s[a-w][a-z] diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9595fdc --- /dev/null +++ b/.travis.yml @@ -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 diff --git a/.travis/install.sh b/.travis/install.sh new file mode 100755 index 0000000..0cbbde1 --- /dev/null +++ b/.travis/install.sh @@ -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 diff --git a/.travis/script.sh b/.travis/script.sh new file mode 100755 index 0000000..51f7a89 --- /dev/null +++ b/.travis/script.sh @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index a38e018..8e49821 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/test/bench.py b/bench/bench.py similarity index 100% rename from test/bench.py rename to bench/bench.py diff --git a/test/bench_cpsm.py b/bench/bench_cpsm.py similarity index 100% rename from test/bench_cpsm.py rename to bench/bench_cpsm.py diff --git a/test/linuxclock.py b/bench/linuxclock.py similarity index 100% rename from test/linuxclock.py rename to bench/linuxclock.py diff --git a/install.sh b/install.sh index 5e67201..d09185f 100755 --- a/install.sh +++ b/install.sh @@ -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 +)