From 1b40d683be7fdc38bf04c2e889036314551f0035 Mon Sep 17 00:00:00 2001 From: micbou Date: Tue, 21 Apr 2015 01:10:12 +0200 Subject: [PATCH] Convert the install script to python Translate the install.sh script in python to make it platform independent. Keep install.sh as a wrapper of install.py to not break scripts that depend on it. --- install.py | 33 +++++++++++++++++++++++++++++++++ install.sh | 19 ++++--------------- 2 files changed, 37 insertions(+), 15 deletions(-) create mode 100644 install.py diff --git a/install.py b/install.py new file mode 100644 index 00000000..320e7640 --- /dev/null +++ b/install.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python + +import os +import subprocess +import sys +import os.path as p +import glob + +DIR_OF_THIS_SCRIPT = p.dirname( p.abspath( __file__ ) ) +DIR_OF_OLD_LIBS = p.join( DIR_OF_THIS_SCRIPT, 'python' ) + + +def Main(): + build_file = p.join( DIR_OF_THIS_SCRIPT, 'third_party', 'ycmd', 'build.py' ) + + if not p.isfile( build_file ): + sys.exit( 'File ' + build_file + ' does not exist; you probably forgot ' + 'to run:\n\tgit submodule update --init --recursive\n\n' ) + + python_binary = sys.executable + args = ' '.join( sys.argv[1:] ) + subprocess.call( ' '.join( [ python_binary, build_file, args ] ) ) + + # Remove old YCM libs if present so that YCM can start. + old_libs = ( + glob.glob( p.join( DIR_OF_OLD_LIBS, '*ycm_core.*' ) ) + + glob.glob( p.join( DIR_OF_OLD_LIBS, '*ycm_client_support.*' ) ) + + glob.glob( p.join( DIR_OF_OLD_LIBS, '*clang*.*') ) ) + for lib in old_libs: + os.remove( lib ) + +if __name__ == "__main__": + Main() diff --git a/install.sh b/install.sh index ca095896..8c9c2fd1 100755 --- a/install.sh +++ b/install.sh @@ -1,15 +1,9 @@ #!/bin/sh +echo "WARNING: this script is deprecated. Use the install.py script instead." 1>&2 + + SCRIPT_DIR=$(dirname $0 || exit $?) -cd $SCRIPT_DIR || exit $? - -build_file=$SCRIPT_DIR/third_party/ycmd/build.py - -if [ ! -f "$build_file" ]; then - echo "File $build_file doesn't exist; you probably forgot to run:" - printf "\n\tgit submodule update --init --recursive\n\n" - exit 1 -fi command_exists() { command -v "$1" >/dev/null 2>&1 ; @@ -20,9 +14,4 @@ if command_exists python2; then PYTHON_BINARY=python2 fi -$PYTHON_BINARY "$build_file" "$@" || exit $? - -# Remove old YCM libs if present so that YCM can start. -rm -f python/*ycm_core.* &> /dev/null -rm -f python/*ycm_client_support.* &> /dev/null -rm -f python/*clang*.* &> /dev/null +$PYTHON_BINARY "$SCRIPT_DIR/install.py" "$@" || exit $?