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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
|
#!/bin/bash -e
# Copyright 2012, The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Creates and builds projects from a RenderScript testcase and a set of Java templates
HELP=no
VERBOSE=no
MINSDK=1
TARGET=1
NAME=""
OUT_DIR=
ACTIVITY=""
PACKAGE=""
SDK=""
TESTCASE_PATH=""
DRIVER=""
check_param ()
{
if [ -z "$2" ]; then
echo "ERROR: Missing parameter after option '$1'"
exit 1
fi
}
check_required_param()
{
if [ -z "$1" ]; then
echo "ERROR: Missing required parameter $2"
exit 1
fi
}
run ()
{
if [ "$VERBOSE" = "yes" ] ; then
echo "## COMMAND: $@"
fi
$@ 2>&1
}
process_template()
{
src=$1
dest=$2
sed -e "s/%ACTIVITY%/$3/g" -e "s/%PACKAGE%/$4/g" -e "s/%TESTCASE%/$5/g" -e "s/%MINSDK%/$6/g" < $src > $dest;
echo "processed $src ==> $dest"
}
while [ -n "$1" ]; do
opt="$1"
case "$opt" in
--help|-h|-\?)
HELP=yes
;;
--verbose|-v)
VERBOSE=yes
;;
--sdk)
check_param $1 $2
SDK="$2"
;;
--name)
check_param $1 $2
NAME="$2"
;;
--out)
check_param $1 $2
OUT_DIR="$2"
;;
--activity)
check_param $1 $2
ACTIVITY="$2"
;;
--package)
check_param $1 $2
PACKAGE="$2"
;;
--minsdk)
check_param $1 $2
MINSDK="$2"
;;
--target)
check_param $1 $2
TARGET="$2"
;;
--testcase)
check_param $1 $2
TESTCASE_PATH="$2"
;;
--driver)
check_param $1 $2
DRIVER="${2%/}"
;;
-*) # unknown options
echo "ERROR: Unknown option '$opt', use --help for list of valid ones."
exit 1
;;
*) # Simply record parameter
if [ -z "$PARAMETERS" ] ; then
PARAMETERS="$opt"
else
PARAMETERS="$PARAMETERS $opt"
fi
;;
esac
shift
done
if [ "$HELP" = "yes" ] ; then
echo "Usage: $PROGNAME [options]"
echo ""
echo "Build a test project from a RS testcase and a java driver template."
echo ""
echo "Required Parameters:"
echo " --sdk Location of Android SDK installation"
echo " --out <path> Location of your project directory"
echo " --testcase <name> The .rs testcase file with which to build the project"
echo " --driver <name> The java template directory with which to build the project"
echo ""
echo "Optional Parameters (reasonable defaults are used if not specified)"
echo " --activity <name> Name for your default Activity class"
echo " --package <name> Package namespace for your project"
echo " --target <name> Android build target. Execute 'android list targets' to list available targets and their ID's."
echo " --minsdk <name> minSdkVersion attribute to embed in AndroidManifest.xml of test project."
echo " --help|-h|-? Print this help"
echo " --verbose|-v Enable verbose mode"
echo ""
exit 0
fi
# Verify required parameters are non-empty
check_required_param "$SDK" "--sdk"
check_required_param "$OUT_DIR" "--out"
check_required_param "$TESTCASE_PATH" "--testcase"
check_required_param "$DRIVER" "--driver"
# Compute name of testcase
TESTCASE=`basename $TESTCASE_PATH .rs`
# Compute activity, appname, and java package, if not specified via parameters
if [ -z "$ACTIVITY" ]; then
ACTIVITY="$TESTCASE";
fi
if [ -z "$NAME" ]; then
NAME="$ACTIVITY"
fi
if [ -z "$PACKAGE" ]; then
PACKAGE=com.android.test.rsdebug.$TESTCASE
fi
# Create the project
run $SDK/tools/android create project --target $TARGET --name $NAME --path $OUT_DIR --activity $ACTIVITY --package $PACKAGE
if [ $? != 0 ] ; then
echo "ERROR: Could not create Android project."
echo " Check parameters and try again."
exit 1
fi
# Compute name of destination source directory
DEST_SRC_DIR=$OUT_DIR/src/`echo $PACKAGE | sed 's/\./\//g'`
if [ ! -d "$DRIVER" ]; then
# If driver directory does not exist, try to fix it up by searching the
# testcase directory as well
DRIVER=`dirname $TESTCASE_PATH`/"$DRIVER"
if [ ! -d $DRIVER ]; then
echo "unable to find driver in $DRIVER, please check --driver"
exit 1;
fi
fi
echo "Copying driver template from $DRIVER -> $DEST_SRC_DIR"
if [ ! -d "$DEST_SRC_DIR" ]; then
echo "Error, destination directory does not exist: $DEST_SRC_DIR";
exit 1;
fi
echo "Performing template substitutions:"
echo " %ACTIVITY% ==> $ACTIVITY"
echo " %PACKAGE% ==> $PACKAGE"
echo " %TESTCASE% ==> $TESTCASE"
echo " %MINSDK% ==> $MINSDK"
SUBST_PARAMS="$ACTIVITY $PACKAGE $TESTCASE $MINSDK"
# If it exists, use contents of driver-common directory to seed
# the testcase project
DRIVER_COMMON="`dirname $TESTCASE_PATH`/driver-common"
if [ -d $DRIVER_COMMON ]; then
echo "Found common driver directory: $DRIVER_COMMON"
ls $DRIVER_COMMON/SRC/*.java.template | while read src; do
SRC_BASENAME=`basename $src .java.template`;
dest=$DEST_SRC_DIR/`echo $SRC_BASENAME | sed "s/ACTIVITY/$ACTIVITY/g"`.java
process_template $src $dest $SUBST_PARAMS
done;
# Copy AndroidManifest.xml
COMMON_MANIFEST="$DRIVER_COMMON/AndroidManifest.xml"
if [ -e $COMMON_MANIFEST ]; then
process_template $COMMON_MANIFEST $OUT_DIR/AndroidManifest.xml $SUBST_PARAMS
fi
fi
# Copy Java source to project directory.
ls $DRIVER/*.java.template | while read src; do
SRC_BASENAME=`basename $src .java.template`
dest=$DEST_SRC_DIR/`echo $SRC_BASENAME | sed "s/ACTIVITY/$ACTIVITY/g"`.java
process_template $src $dest $SUBST_PARAMS
done;
# Copy AndroidManifest.xml override, if it exists
OVERRIDE_MANIFEST="$DRIVER/AndroidManifest.xml"
if [ -e $OVERRIDE_MANIFEST ]; then
process_template $OVERRIDE_MANIFEST $OUT_DIR/AndroidManifest.xml $SUBST_PARAMS
fi
# Copy RS testcase to project directory.
TESTCASE_DEST=$DEST_SRC_DIR/`basename $TESTCASE_PATH`
process_template $TESTCASE_PATH $TESTCASE_DEST $SUBST_PARAMS
# Buid signed and aligned apk
cd $OUT_DIR
run ant clean debug install
if [ $? != 0 ] ; then
echo "ERROR: Apk build and install failed"
exit 1
fi
exit 0
|