-
Notifications
You must be signed in to change notification settings - Fork 497
/
blade
executable file
·118 lines (100 loc) · 2.67 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
117
118
#!/bin/bash
#
# SCRIPT: blade
# AUTHOR: Michaelpeng <[email protected]>
# Phongchen <[email protected]>
# 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 _fatal() {
if [ -t 2 ]; then
echo -e "\033[1;31mBlade(fatal): $@\nBlade(fatal): Blade will exit...\033[m" >&2
else
echo -e "Blade(fatal): $@\nBlade(fatal): 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
}
# Check the python version at first, exit blade when python
# version is under 2.7
function _check_python() {
local python
if command -v python &> /dev/null; then
python="python"
elif command -v python3 &> /dev/null; then
echo "python3"
return
elif command -v python3 &> /dev/null; then
python="python"
echo "python3"
else
_fatal "Please install python 2.7+ or 3.6+ or above in your system"
fi
python_ver=$($python -V 2>&1 | sed 's/Python //g')
if [[ "$python_ver" < "2.7" ]]; then
_info "Python version in your machine: $python_ver"
_fatal "Please upgrade your python version to 2.7 or 3.6+"
fi
echo $python
}
blade_path=`_full_real_path $0`
blade_dir=$(cd $(dirname $blade_path) && pwd)
if [[ -d "$blade_dir/src/blade" ]]; then
blade_file="$blade_dir/src"
else
blade_file="$blade_dir/blade.zip"
fi
if [[ -e $blade_dir/blade_init ]]; then
source $blade_dir/blade_init
fi
python=$(_check_python)
# Check ninja
if ! command -v ninja &> /dev/null; then
_fatal "Please install ninja v1.8+ (https://ninja-build.org)"
fi
# Check blade file
if [[ ! -e "$blade_file" ]]; then
_fatal "Cannot find the core file $blade_file"
fi
${BLADE_PYTHON_INTERPRETER:-$python} $blade_file "$@"