Skip to content

Commit 3947edd

Browse files
committed
update distribute.sh to add usage, options, and change how to compile modules.
1 parent ea20613 commit 3947edd

File tree

3 files changed

+160
-53
lines changed

3 files changed

+160
-53
lines changed

README.rst

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,32 +54,58 @@ documentation for recommended components at::
5454
well, so that you can test your application on the full range of
5555
Android platform versions that your application supports.
5656

57-
After installing them, export both installation path::
57+
After installing them, export both installation path, ndk version and api to use::
5858

5959
export ANDROIDSDK=/path/to/android-sdk
6060
export ANDROIDNDK=/path/to/android-ndk
61+
export ANDROIDNDKVER=rX
62+
export ANDROIDAPI=X
6163

62-
# examples
64+
# example
6365
export ANDROIDSDK="/home/tito/code/android/android-sdk-linux_86"
64-
export ANDROIDNDK="/home/tito/code/android/android-ndk-r5b"
66+
export ANDROIDNDK="/home/tito/code/android/android-ndk-r7"
67+
export ANDROIDNDKVER=r7
68+
export ANDROIDAPI=14
6569

6670

6771
Usage
6872
-----
6973

7074
Step 1, compile the toolchain::
7175

72-
MODULES="openssl pygame" ./configure.sh
76+
./distribute.sh -m "kivy"
77+
78+
After a long time, you'll get a "dist/default" directory containing all the compiled
79+
libraries and build.py script to package your application using thoses
80+
libraries.
7381

7482
Step 2, package your application::
7583

76-
...
84+
cd dist/default
85+
./build.py --package org.test.touchtracer --name touchtracer \
86+
--version 1.0 --dir ~/code/kivy/examples/demo/touchtracer installd
87+
88+
Example of other toolchain::
89+
90+
./distribute.sh -m "pil kivy"
91+
./distribute.sh -m "openssl python"
92+
93+
# create another distribution in a directory bleh
94+
./distribute.sh -m "openssl kivy" -d bleh
95+
cd dist/bleh
96+
./build.py ...
97+
98+
Available options::
7799

100+
-d directory Name of the distribution directory
101+
-h Show this help
102+
-l Show a list of available modules
103+
-m 'mod1 mod2' Modules to include
78104

79105
Available modules
80106
-----------------
81107

82-
List of available modules: jpeg pil png sdl sqlite3
108+
List of available modules: jpeg pil png sdl sqlite3 pygame kivy android
83109

84110
The up-to-date list is available at:
85111
https://github.com/tito/python-for-android/tree/master/recipes
@@ -124,8 +150,8 @@ Related project
124150
TODO
125151
----
126152

127-
- Make Android API configurable (defined in src/default.properties => shoudl be generated)
128153
- jni/Android.mk must not include ttf/image/mixer if not asked by the user
129154
- application should be automatically generated (Android.mk etc...)
130155
- Python try always to import name.so, namemodule.so, name.py, name.pyo ?
131156
- restore libpymodules.so loading to reduce the number of dlopen.
157+
- if MODULES= change, the old build need to be cleaned

distribute.sh

Lines changed: 126 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ LIBS_PATH="$ROOT_PATH/build/libs"
1717
PACKAGES_PATH="$ROOT_PATH/.packages"
1818
SRC_PATH="$ROOT_PATH/src"
1919
JNI_PATH="$SRC_PATH/jni"
20-
DIST_PATH="$ROOT_PATH/dist"
20+
DIST_PATH="$ROOT_PATH/dist/default"
2121

2222
# Internals
2323
CRED="\x1b[31;01m"
@@ -131,6 +131,23 @@ function pop_arm() {
131131
export MAKE=$OLD_MAKE
132132
}
133133

134+
function usage() {
135+
echo "Python for android - distribute.sh"
136+
echo "This script create a directory will all the libraries wanted"
137+
echo
138+
echo "Usage: ./distribute.sh [options] directory"
139+
echo "Example: ./distribute.sh -m 'pil kivy' dist"
140+
echo
141+
echo "Options:"
142+
echo
143+
echo " -d directory Name of the distribution directory"
144+
echo " -h Show this help"
145+
echo " -l Show a list of available modules"
146+
echo " -m 'mod1 mod2' Modules to include"
147+
echo
148+
exit 0
149+
}
150+
134151
function run_prepare() {
135152
info "Check enviromnent"
136153
if [ "X$ANDROIDSDK" == "X" ]; then
@@ -153,6 +170,11 @@ function run_prepare() {
153170
exit -1
154171
fi
155172

173+
if [ "X$MODULES" == "X" ]; then
174+
usage
175+
exit 0
176+
fi
177+
156178
debug "SDK located at $ANDROIDSDK"
157179
debug "NDK located at $ANDROIDNDK"
158180
debug "NDK version is $ANDROIDNDKVER"
@@ -179,14 +201,37 @@ function run_prepare() {
179201
mkdir -p $LIBS_PATH
180202
fi
181203

204+
info "Distribution will be located at $DIST_PATH"
205+
if [ -e "$DIST_PATH" ]; then
206+
error "The distribution $DIST_PATH already exist"
207+
error "Press a key to remove it, or Control + C to abort."
208+
read
209+
try rm -rf "$DIST_PATH"
210+
fi
211+
try mkdir -p "$DIST_PATH"
212+
182213
# create initial files
183214
echo "target=android-$ANDROIDAPI" > $SRC_PATH/default.properties
184215
echo "sdk.dir=$ANDROIDSDK" > $SRC_PATH/local.properties
185216
}
186217

218+
function in_array() {
219+
term="$1"
220+
shift
221+
i=0
222+
for key in $@; do
223+
if [ $term == $key ]; then
224+
return $i
225+
fi
226+
i=$(($i + 1))
227+
done
228+
return 255
229+
}
230+
187231
function run_source_modules() {
188-
needed=(hostpython python android $MODULES)
232+
needed=($MODULES)
189233
declare -A processed
234+
order=()
190235

191236
while [ ${#needed[*]} -ne 0 ]; do
192237

@@ -204,6 +249,12 @@ function run_source_modules() {
204249
# add this module as done
205250
processed[$module]=1
206251

252+
# append our module at the end only if we are not exist yet
253+
in_array $module "${order[@]}"
254+
if [ $? -eq 255 ]; then
255+
order=( ${order[@]} $module )
256+
fi
257+
207258
# read recipe
208259
debug "Read $module recipe"
209260
recipe=$RECIPES_PATH/$module/recipe.sh
@@ -219,40 +270,38 @@ function run_source_modules() {
219270
if [ ${#deps[*]} -gt 0 ]; then
220271
debug "Module $module depend on" ${deps[@]}
221272
needed=( ${needed[@]} ${deps[@]} )
222-
fi
223-
done
224-
}
225273

226-
# order modules by their priority
227-
function run_order_modules() {
228-
cd $BUILD_PATH
229-
filename=$RANDOM.order
230-
if [ -f $filename ]; then
231-
rm $filename
232-
fi
233-
234-
for module in hostpython python android $MODULES; do
235-
# get priority
236-
priority="PRIORITY_$module"
237-
priority=${!priority}
238-
# write on the file
239-
echo "$priority $module" >> $filename
274+
# for every deps, check if it's already added to order
275+
# if not, add the deps before ourself
276+
debug "Dependency order is ${order[@]} (current)"
277+
for dep in "${deps[@]}"; do
278+
#debug "Check if $dep is in order"
279+
in_array $dep "${order[@]}"
280+
if [ $? -eq 255 ]; then
281+
#debug "missing $dep in order"
282+
# deps not found in order
283+
# add it before ourself
284+
in_array $module "${order[@]}"
285+
index=$?
286+
#debug "our $module index is $index"
287+
order=(${order[@]:0:$index} $dep ${order[@]:$index})
288+
#debug "new order is ${order[@]}"
289+
fi
290+
done
291+
debug "Dependency order is ${order[@]} (computed)"
292+
fi
240293
done
241294

242-
# update modules by priority
243-
MODULES=$(sort -n $filename|cut -d\ -f2)
244-
info "Module order is '$MODULES'"
245-
246-
# remove temporary filename
247-
rm $filename
295+
MODULES="${order[@]}"
296+
info="Modules changed to $MODULES"
248297
}
249298

250-
function run_get_deps() {
251-
info "Run get dependencies"
299+
function run_get_packages() {
300+
info "Run get packages"
252301

253302
for module in $MODULES; do
254303
# download dependencies for this module
255-
debug "Download dependencies for $module"
304+
debug "Download package for $module"
256305

257306
url="URL_$module"
258307
url=${!url}
@@ -264,7 +313,7 @@ function run_get_deps() {
264313
fi
265314

266315
if [ "X$url" == "X" ]; then
267-
debug "No dependencies for $module"
316+
debug "No package for $module"
268317
continue
269318
fi
270319

@@ -372,14 +421,7 @@ function run_postbuild() {
372421
function run_distribute() {
373422
info "Run distribute"
374423

375-
if [ -e $DIST_PATH ]; then
376-
debug "Remove old distribution"
377-
try rm -rf $DIST_PATH
378-
fi
379-
380-
debug "Create new distribution at $DIST_PATH"
381-
try mkdir -p $DIST_PATH
382-
cd $DIST_PATH
424+
cd "$DIST_PATH"
383425

384426
debug "Create initial layout"
385427
try mkdir assets bin gen obj private res templates
@@ -406,17 +448,18 @@ function run_distribute() {
406448
try cp python-install/include/python2.7/pyconfig.h private/include/python2.7/
407449

408450
debug "Reduce private directory from unwanted files"
409-
try rm -f $DIST_PATH/private/lib/libpython2.7.so
410-
try rm -rf $DIST_PATH/private/lib/pkgconfig
411-
try cd $DIST_PATH/private/lib/python2.7
451+
try rm -f "$DIST_PATH"/private/lib/libpython2.7.so
452+
try rm -rf "$DIST_PATH"/private/lib/pkgconfig
453+
try cd "$DIST_PATH"/private/lib/python2.7
412454
try find . | grep -E '*\.(py|pyc|so\.o|so\.a|so\.libs)$' | xargs rm
455+
456+
# we are sure that all of theses will be never used on android (well...)
413457
try rm -rf test
414458
try rm -rf ctypes
415459
try rm -rf lib2to3
416460
try rm -rf lib-tk
417461
try rm -rf idlelib
418462
try rm -rf unittest/test
419-
#try rm -rf lib-dynload
420463
try rm -rf json/tests
421464
try rm -rf distutils/tests
422465
try rm -rf email/test
@@ -431,11 +474,10 @@ function run_distribute() {
431474
function run() {
432475
run_prepare
433476
run_source_modules
434-
run_order_modules
435-
run_get_deps
477+
run_get_packages
436478

437479
push_arm
438-
debug $PATH
480+
debug "PATH is $PATH"
439481
pop_arm
440482

441483
run_prebuild
@@ -445,6 +487,45 @@ function run() {
445487
info "All done !"
446488
}
447489

490+
function list_modules() {
491+
modules=$(find recipes -iname 'recipe.sh' | cut -d/ -f2 | sort -u | xargs echo)
492+
echo "Available modules: $modules"
493+
exit 0
494+
}
495+
448496
# Do the build
449-
run
497+
while getopts ":hvlm:d:" opt; do
498+
case $opt in
499+
h)
500+
usage
501+
;;
502+
l)
503+
list_modules
504+
;;
505+
m)
506+
MODULES="$OPTARG"
507+
;;
508+
d)
509+
DIST_PATH="$ROOT_PATH/dist/$OPTARG"
510+
;;
511+
\?)
512+
echo "Invalid option: -$OPTARG" >&2
513+
exit 1
514+
;;
515+
:)
516+
echo "Option -$OPTARG requires an argument." >&2
517+
exit 1
518+
;;
519+
520+
*)
521+
echo "=> $OPTARG"
522+
;;
523+
esac
524+
done
450525

526+
package=${*:$OPTIND:1}
527+
if [ "X$package" == "X" ]; then
528+
usage
529+
fi
530+
531+
run

recipes/kivy/recipe.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
PRIORITY_kivy=30
44
VERSION_kivy=
55
URL_kivy=
6-
DEPS_kivy=(pygame)
6+
DEPS_kivy=(pygame android)
77
MD5_kivy=
88
BUILD_kivy=$BUILD_PATH/kivy/kivy
99
RECIPE_kivy=$RECIPES_PATH/kivy

0 commit comments

Comments
 (0)