diff --git a/install.sh b/install.sh index 5ef0d13b..1c93036d 100755 --- a/install.sh +++ b/install.sh @@ -2,183 +2,6 @@ set -e -function command_exists { - hash "$1" 2>/dev/null ; -} +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -function cmake_install { - if [[ `uname -s` == "Darwin" ]]; then - homebrew_cmake_install - else - linux_cmake_install - fi -} - -function homebrew_cmake_install { - if command_exists brew; then - brew install cmake - else - echo "Homebrew was not found installed in your system." - echo "Go to http://mxcl.github.com/homebrew/ and follow the instructions." - echo "Or install CMake somehow and retry." - exit 1 - fi -} - -function python_finder { - python_library="-DPYTHON_LIBRARY=" - python_include="-DPYTHON_INCLUDE_DIR=" - - # The CMake 'FindPythonLibs' Module does not work properly. - # So we are forced to do its job for it. - python_prefix=$(python-config --prefix | sed 's/^[ \t]*//') - if [ -f "${python_prefix}/Python" ]; then - python_library+="${python_prefix}/Python" - python_include+="${python_prefix}/Headers" - else - which_python=$(python -c 'import sys;print(sys.version)' | sed 's/^[ \t]*//') - which_python="python${which_python:0:3}" - lib_python="${python_prefix}/lib/lib${which_python}" - if [ -f "${lib_python}.a" ]; then - python_library+="${lib_python}.a" - # This check is for for CYGWIN - elif [ -f "${lib_python}.dll.a" ]; then - python_library+="${lib_python}.dll.a" - else - python_library+="${lib_python}.dylib" - fi - python_include+="${python_prefix}/include/${which_python}" - fi - - echo "${python_library} ${python_include}" -} - -function num_cores { - if command_exists nproc; then - num_cpus=$(nproc) - else - num_cpus=1 - if [[ `uname -s` == "Linux" ]]; then - num_cpus=$(grep -c ^processor /proc/cpuinfo) - else - # Works on Mac and FreeBSD - num_cpus=$(sysctl -n hw.ncpu) - fi - fi - echo $num_cpus -} - - -function install { - ycmd_dir=`pwd`/third_party/ycmd - build_dir=`mktemp -d -t ycm_build.XXXXXX` - pushd $build_dir - - if [[ `uname -s` == "Darwin" ]]; then - cmake -G "Unix Makefiles" $(python_finder) "$@" . $ycmd_dir/cpp - else - cmake -G "Unix Makefiles" "$@" . $ycmd_dir/cpp - fi - - make -j $(num_cores) ycm_support_libs - popd - rm -rf $build_dir -} - -function testrun { - ycmd_dir=`pwd`/third_party/ycmd - build_dir=`mktemp -d -t ycm_build.XXXXXX` - pushd $build_dir - - cmake -G "Unix Makefiles" "$@" . $ycmd_dir/cpp - make -j $(num_cores) ycm_core_tests - cd ycm/tests - LD_LIBRARY_PATH=$ycmd_dir ./ycm_core_tests - - popd - rm -rf $build_dir -} - -function linux_cmake_install { - echo "Please install CMake using your package manager and retry." - exit 1 -} - -function usage { - echo "Usage: $0 [--clang-completer [--system-libclang]] [--omnisharp-completer]" - exit 0 -} - -function check_third_party_libs { - libs_present=true - for folder in third_party/*; do - num_files_in_folder=$(find $folder -maxdepth 1 -mindepth 1 | wc -l) - if [[ $num_files_in_folder -eq 0 ]]; then - libs_present=false - fi - done - - if ! $libs_present; then - echo "Some folders in ./third_party are empty; you probably forgot to run:" - printf "\n\tgit submodule update --init --recursive\n\n" - exit 1 - fi -} - -cmake_args="" -omnisharp_completer=false -for flag in $@; do - case "$flag" in - --clang-completer) - cmake_args="-DUSE_CLANG_COMPLETER=ON" - ;; - --system-libclang) - cmake_args="$cmake_args -DUSE_SYSTEM_LIBCLANG=ON" - ;; - --omnisharp-completer) - omnisharp_completer=true - ;; - *) - usage - ;; - esac -done - -if [[ $cmake_args == *-DUSE_SYSTEM_LIBCLANG=ON* ]] && \ - [[ $cmake_args != *-DUSE_CLANG_COMPLETER=ON* ]]; then - usage -fi - -check_third_party_libs - -if ! command_exists cmake; then - echo "CMake is required to build YouCompleteMe." - cmake_install -fi - -if [ -z "$YCM_TESTRUN" ]; then - install $cmake_args $EXTRA_CMAKE_ARGS -else - testrun $cmake_args $EXTRA_CMAKE_ARGS -fi - -if $omnisharp_completer; then - buildcommand="msbuild" - if ! command_exists msbuild; then - buildcommand="msbuild.exe" - if ! command_exists msbuild.exe; then - buildcommand="xbuild" - if ! command_exists xbuild; then - echo "msbuild or xbuild is required to build Omnisharp" - exit 1 - fi - fi - fi - - ycm_dir=`pwd` - build_dir=$ycm_dir"/third_party/OmniSharpServer" - - cd $build_dir - $buildcommand - cd $ycm_dir -fi +$SCRIPT_DIR/third_party/ycmd/build.sh "$@" diff --git a/run_tests.sh b/run_tests.sh index 36dca4cd..5607b87f 100755 --- a/run_tests.sh +++ b/run_tests.sh @@ -2,46 +2,16 @@ set -e -function usage { - echo "Usage: $0 [--no-clang-completer]" - exit 0 -} +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -flake8 --select=F,C9 --max-complexity=10 --exclude=.git,cpp \ - python third_party/ycmd/ycmd +$SCRIPT_DIR/third_party/ycmd/run_tests.sh "$@" -use_clang_completer=true -for flag in $@; do - case "$flag" in - --no-clang-completer) - use_clang_completer=false - ;; - *) - usage - ;; - esac -done +flake8 --select=F,C9 --max-complexity=10 $SCRIPT_DIR/python -if [ -n "$USE_CLANG_COMPLETER" ]; then - use_clang_completer=$USE_CLANG_COMPLETER -fi - -if $use_clang_completer; then - extra_cmake_args="-DUSE_CLANG_COMPLETER=ON -DUSE_DEV_FLAGS=ON" -else - extra_cmake_args="-DUSE_DEV_FLAGS=ON" -fi - -EXTRA_CMAKE_ARGS=$extra_cmake_args YCM_TESTRUN=1 ./install.sh --omnisharp-completer - -for directory in third_party/*; do +for directory in $SCRIPT_DIR/third_party/*; do if [ -d "${directory}" ]; then - export PYTHONPATH=$PWD/${directory}:$PYTHONPATH + export PYTHONPATH=${directory}:$PYTHONPATH fi done -if $use_clang_completer; then - nosetests -v python third_party/ycmd/ycmd -else - nosetests -v --exclude=".*Clang.*" python third_party/ycmd/ycmd -fi +nosetests -v $SCRIPT_DIR/python diff --git a/third_party/ycmd/build.sh b/third_party/ycmd/build.sh new file mode 100755 index 00000000..055c81dc --- /dev/null +++ b/third_party/ycmd/build.sh @@ -0,0 +1,185 @@ +#!/usr/bin/env bash + +set -e + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +function command_exists { + hash "$1" 2>/dev/null ; +} + +function cmake_install { + if [[ `uname -s` == "Darwin" ]]; then + homebrew_cmake_install + else + linux_cmake_install + fi +} + +function homebrew_cmake_install { + if command_exists brew; then + brew install cmake + else + echo "Homebrew was not found installed in your system." + echo "Go to http://mxcl.github.com/homebrew/ and follow the instructions." + echo "Or install CMake somehow and retry." + exit 1 + fi +} + +function python_finder { + python_library="-DPYTHON_LIBRARY=" + python_include="-DPYTHON_INCLUDE_DIR=" + + # The CMake 'FindPythonLibs' Module does not work properly. + # So we are forced to do its job for it. + python_prefix=$(python-config --prefix | sed 's/^[ \t]*//') + if [ -f "${python_prefix}/Python" ]; then + python_library+="${python_prefix}/Python" + python_include+="${python_prefix}/Headers" + else + which_python=$(python -c 'import sys;print(sys.version)' | sed 's/^[ \t]*//') + which_python="python${which_python:0:3}" + lib_python="${python_prefix}/lib/lib${which_python}" + if [ -f "${lib_python}.a" ]; then + python_library+="${lib_python}.a" + # This check is for for CYGWIN + elif [ -f "${lib_python}.dll.a" ]; then + python_library+="${lib_python}.dll.a" + else + python_library+="${lib_python}.dylib" + fi + python_include+="${python_prefix}/include/${which_python}" + fi + + echo "${python_library} ${python_include}" +} + +function num_cores { + if command_exists nproc; then + num_cpus=$(nproc) + else + num_cpus=1 + if [[ `uname -s` == "Linux" ]]; then + num_cpus=$(grep -c ^processor /proc/cpuinfo) + else + # Works on Mac and FreeBSD + num_cpus=$(sysctl -n hw.ncpu) + fi + fi + echo $num_cpus +} + + +function install { + build_dir=`mktemp -d -t ycm_build.XXXXXX` + pushd $build_dir + + if [[ `uname -s` == "Darwin" ]]; then + cmake -G "Unix Makefiles" $(python_finder) "$@" . $SCRIPT_DIR/cpp + else + cmake -G "Unix Makefiles" "$@" . $SCRIPT_DIR/cpp + fi + + make -j $(num_cores) ycm_support_libs + popd + rm -rf $build_dir +} + +function testrun { + build_dir=`mktemp -d -t ycm_build.XXXXXX` + pushd $build_dir + + cmake -G "Unix Makefiles" "$@" . $SCRIPT_DIR/cpp + make -j $(num_cores) ycm_core_tests + cd ycm/tests + LD_LIBRARY_PATH=$SCRIPT_DIR ./ycm_core_tests + + popd + rm -rf $build_dir +} + +function linux_cmake_install { + echo "Please install CMake using your package manager and retry." + exit 1 +} + +function usage { + echo "Usage: $0 [--clang-completer [--system-libclang]] [--omnisharp-completer]" + exit 0 +} + +function check_third_party_libs { + libs_present=true + for folder in third_party/*; do + num_files_in_folder=$(find $folder -maxdepth 1 -mindepth 1 | wc -l) + if [[ $num_files_in_folder -eq 0 ]]; then + libs_present=false + fi + done + + if ! $libs_present; then + echo "Some folders in ./third_party are empty; you probably forgot to run:" + printf "\n\tgit submodule update --init --recursive\n\n" + exit 1 + fi +} + +cmake_args="" +omnisharp_completer=false +for flag in $@; do + case "$flag" in + --clang-completer) + cmake_args="-DUSE_CLANG_COMPLETER=ON" + ;; + --system-libclang) + cmake_args="$cmake_args -DUSE_SYSTEM_LIBCLANG=ON" + ;; + --omnisharp-completer) + omnisharp_completer=true + ;; + *) + usage + ;; + esac +done + +if [[ $cmake_args == *-DUSE_SYSTEM_LIBCLANG=ON* ]] && \ + [[ $cmake_args != *-DUSE_CLANG_COMPLETER=ON* ]]; then + usage +fi + +check_third_party_libs + +if ! command_exists cmake; then + echo "CMake is required to build YouCompleteMe." + cmake_install +fi + +if [ -z "$YCM_TESTRUN" ]; then + install $cmake_args $EXTRA_CMAKE_ARGS +else + testrun $cmake_args $EXTRA_CMAKE_ARGS +fi + +if $omnisharp_completer; then + buildcommand="msbuild" + if ! command_exists msbuild; then + buildcommand="msbuild.exe" + if ! command_exists msbuild.exe; then + buildcommand="xbuild" + if ! command_exists xbuild; then + echo "msbuild or xbuild is required to build Omnisharp" + exit 1 + fi + fi + fi + + # TODO: change to the following when omnisharp in own third_party: + # $SCRIPT_DIR"/third_party/OmniSharpServer" + build_dir=$SCRIPT_DIR"/../OmniSharpServer" + + cd $build_dir + $buildcommand + cd $ycm_dir +fi diff --git a/third_party/ycmd/run_tests.sh b/third_party/ycmd/run_tests.sh new file mode 100755 index 00000000..9b877079 --- /dev/null +++ b/third_party/ycmd/run_tests.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +set -e + +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" + +function usage { + echo "Usage: $0 [--no-clang-completer]" + exit 0 +} + +flake8 --select=F,C9 --max-complexity=10 $SCRIPT_DIR/ycmd + +use_clang_completer=true +for flag in $@; do + case "$flag" in + --no-clang-completer) + use_clang_completer=false + ;; + *) + usage + ;; + esac +done + +if [ -n "$USE_CLANG_COMPLETER" ]; then + use_clang_completer=$USE_CLANG_COMPLETER +fi + +if $use_clang_completer; then + extra_cmake_args="-DUSE_CLANG_COMPLETER=ON -DUSE_DEV_FLAGS=ON" +else + extra_cmake_args="-DUSE_DEV_FLAGS=ON" +fi + +EXTRA_CMAKE_ARGS=$extra_cmake_args YCM_TESTRUN=1 \ + $SCRIPT_DIR/build.sh --omnisharp-completer + +# TODO: change to the following when we have own third_party: +# $SCRIPT_DIR/third_party/* +for directory in $SCRIPT_DIR/../*; do + if [ -d "${directory}" ]; then + export PYTHONPATH=${directory}:$PYTHONPATH + fi +done + +if $use_clang_completer; then + nosetests -v $SCRIPT_DIR/ycmd +else + nosetests -v --exclude=".*Clang.*" $SCRIPT_DIR/ycmd +fi