-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdroidenv.zsh
166 lines (119 loc) · 3.68 KB
/
droidenv.zsh
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# Droidenv Initialization
function _get_target(){
echo "Pick a target:"
local i=1
local e
for e in "${(@k)DIR_TARGETS}"
do
echo " $i. $e"
i=$((i + 1))
done
echo ""
read "target?Which target would you like? "
}
function _validate_target(){
[ -z $target ] && return 1
if [[ $target =~ '^[0-9]+$' ]]; then
target=${${(@k)DIR_TARGETS}[$target]}
[ ! -z $target ] && return 0;
else
local e
for e in "${(@k)DIR_TARGETS}"; do [[ "$e" == "$target" ]] && return 0; done
fi
echo "Error: Invalid target"
return 1
}
function _select_env(){
target=$1
[ -z $target ] && _get_target
_validate_target $target || return 1
echo "\nLoading environment : $target"
TARGETDIR=$DIR_TARGETS[$target]
TARGETLUNCH=$LUNCH_TARGETS[$target]
[ -z $TARGETDIR ] && echo "Error: No directory provided for '$target'" && return 1
[ ! -d $TARGETDIR ] && echo "Error: Directory '$TARGETDIR' does not exist" && return 1
echo "Base directory : $TARGETDIR"
echo "Launch target : $TARGETLUNCH\n"
return 0
}
# Post-initialization Utility functions
function _compile_usage(){
echo "Usage: $0 targets"
echo "Valid targets:"
for key in ${(k)COMPILE_TARGETS}; do printf " %-15s - %s\n" $key $COMPILE_TARGETS[$key]; done
}
function _validate_compile_target() {
[ ! "$#" -eq 1 ] && return 1
for e in ${(@k)COMPILE_TARGETS}; do [[ "$e" == "$1" ]] && return 0; done
return 1
}
function _build(){
[ ! "$#" -eq 1 ] && return 1
echo -e "\e[92m[+]\033[0m Building: $1"
mmm -j4 $1
if [ $? -ne 0 ]; then
echo -e "\e[31m[-]\033[0m FAILED: $1"
cd -
kill -INT $$
fi
}
function _gen_image(){
echo -e "\e[92m[+]\033[0m Generating Image"
make snod
if [ $? -ne 0 ]; then
echo -e "\e[31m[-]\033[0m Unable to generate image"
cd -
kill -INT $$
fi
echo -e "\e[92m[+]\033[0m Done!"
}
function compile(){
[ "$#" -lt 1 ] && _compile_usage && return 1
[ -z $ANDROID_BUILD_TOP ] && echo "Run 'droidenv' to initialize the environment" && return 1
if [[ "$1" == "all" ]]; then
cd $ANDROID_BUILD_TOP
make -j4
cd -
return 0
fi
for arg in "$@"; do _validate_compile_target $arg || (echo "Error: invalid argument - $arg" && return 1); done
cd $ANDROID_BUILD_TOP
for arg in $@; do _build $COMPILE_TARGETS[$arg]; done
_gen_image
cd -
}
#Emulator Utilities
function _initsd(){
[ -z $DROIDENV ] && echo "Error: \$DROIDENV not set" && return 1
echo "Initializing emulator sdcard"
mksdcard -l droidenv 1024M $DROIDENV/droidenv.img
echo "done"
}
function emu(){
[ -z $DROIDENV ] && echo "Error: \$DROIDENV not set" && return 1
[ "$#" -ne 1 ] && echo "Usage: emu [on/off]" && return 1
[ ! -f $DROIDENV/droidenv.img ] && _initsd
if [ "$1" != "off" ]; then
emulator -verbose -skin WXGA800 -sdcard $DROIDENV/droidenv.img -gpu on
else
emulator -verbose -skin WXGA800 -sdcard $DROIDENV/droidenv.img
fi
}
# Load droidenv
[ -z "$DROIDENV" ] && echo "Error: \$DROIDENV not set" && return 1
[ ! -f $DROIDENV/targets.cfg ] && echo "Error: Missing config file: $DROIDENV/targets.cfg" && return 1
declare -A DIR_TARGETS
declare -A LUNCH_TARGETS
declare -A COMPILE_TARGETS
source $DROIDENV/targets.cfg
autoload bashcompinit; bashcompinit
alias droidenv='_select_env && cd $TARGETDIR && source ./build/envsetup.sh && lunch $TARGETLUNCH && cd -'
#Autocomplete
_compile_complete(){
reply=( ${(k)COMPILE_TARGETS} )
}
compctl -K _compile_complete compile
_emu_complete(){
reply=( on off )
}
compctl -K _emu_complete emu