forked from chen3feng/blade-build
-
Notifications
You must be signed in to change notification settings - Fork 0
/
blade
executable file
·116 lines (99 loc) · 2.79 KB
/
blade
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
#
# SCRIPT: blade
# AUTHOR: Michaelpeng <michaelpeng@tencent.com>
# Phongchen <phongchen@tencent.com>
# DATE: Dec 17 2011
# REV: 1.0.P (Valid are A, B, D, T and P)
# (For Alpha, Beta, Dev, Test and Production)
#
# PLATFORM: Linux
# PURPOSE : A bash wrapper for blade, always run blade of
# corresponding version in for given source dir
# tree.
# REV LIST:
# DATE: Dec 17 2011
# BY : Michaelpeng
# MODIFICATION: Created
function _info()
{
if [ -t 1 ]; then
echo -e "\033[1;36mBlade(info): $@\033[m" >&2
else
echo -e "Blade(info): $@" >&2
fi
}
function _warning()
{
if [ -t 2 ]; then
echo -e "\033[1;33mBlade(warning): $@\033[m" >&2
else
echo -e "Blade(warning): $@" >&2
fi
}
function _error_exit()
{
if [ -t 2 ]; then
echo -e "\033[1;31mBlade(error): $@\nBlade (error): Blade will exit...\033[m" >&2
else
echo -e "Blade(error): $@\nBlade (error): Blade will exit..." >&2
fi
exit 1
}
function _full_real_path()
{
local o
local f
f="$1"
if [ ! -L "$0" ]; then
echo $f
return 0
fi
if o=`readlink -f $f 2>/dev/null`; then
echo "$o";
return 0
fi
# BSD readlink doesn't support -f
if o=`readlink $f`; then
f="$o"
fi
echo $(cd $(dirname $f) && pwd)/$(basename $f)
return 0
}
blade_path=`_full_real_path $0`
blade_dir=$(cd $(dirname $blade_path) && pwd)
blade_file="$blade_dir/bootstrap.py"
if [ -e $blade_dir/blade_init ]; then
source $blade_dir/blade_init
fi
if [[ "$BLADE_AUTO_UPGRADE" != "no" ]]; then
# Auto update blade main program to latest version and run it
if svn_up_info=`svn up --trust-server-cert --non-interactive ${blade_dir} 2>&1`; then
_info "Auto upgrade success: $svn_up_info"
else
_warning "Auto upgrade failure: $svn_up_info"
_warning "Please svn up $blade_dir"
_warning "You can setenv BLADE_AUTO_UPGRADE=no to disable auto upgrade"
fi
fi
# Check the python version at first, exit blade when python
# version is under 2.4
no_python=$(which python 2>&1 | grep 'which: no')
if [[ -n "$no_python" ]]; then
_error_exit "Please install python 2.4 or above in your system"
fi
python_ver=$(python -V 2>&1 | sed 's/Python //g')
if [[ "$python_ver" < "2.4" ]]; then
_info "Python version in your machine: $python_ver"
_error_exit "Please upgrade your python version to 2.4 or above"
fi
# Check scons environment
no_scons=$(which scons 2>&1 | grep 'which: no scons in')
if [[ -n "$no_scons" ]]; then
_error_exit "Please install scons v2.0 or above on your machine"
fi
# Check blade file
if [[ ! -f "$blade_file" ]]; then
_error_exit "Cannot find the core file $blade_file"
fi
python $blade_file "$@"