Skip to content

Commit ca4fb62

Browse files
committed
enhance distribute.sh to mark recipe as built or not, and allow the recipe to also indicate if it should be rebuilt or not + add -u "mod1 mod2" to force update of recipes (can be used when developing on android module, or specific P4A_module_DIR + standardize HOSTPYTHON and SITEPACKAGES_PATH
1 parent 419a22d commit ca4fb62

File tree

39 files changed

+335
-196
lines changed

39 files changed

+335
-196
lines changed

distribute.sh

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ PACKAGES_PATH="$ROOT_PATH/.packages"
2828
SRC_PATH="$ROOT_PATH/src"
2929
JNI_PATH="$SRC_PATH/jni"
3030
DIST_PATH="$ROOT_PATH/dist/default"
31+
SITEPACKAGES_PATH="$BUILD_PATH/python-install/lib/python2.7/site-packages/"
32+
HOSTPYTHON="$BUILD_PATH/python-install/bin/python.host"
3133

3234
# Tools
3335
export LIBLINK_PATH="$BUILD_PATH/objects"
@@ -213,19 +215,18 @@ function pop_arm() {
213215

214216
function usage() {
215217
echo "Python for android - distribute.sh"
216-
echo "This script create a directory will all the libraries wanted"
217218
echo
218-
echo "Usage: ./distribute.sh [options] directory"
219-
echo "Example: ./distribute.sh -m 'pil kivy' dist"
220-
echo
221-
echo "Options:"
219+
echo "Usage: ./distribute.sh [options]"
222220
echo
223221
echo " -d directory Name of the distribution directory"
224222
echo " -h Show this help"
225223
echo " -l Show a list of available modules"
226224
echo " -m 'mod1 mod2' Modules to include"
227225
echo " -f Restart from scratch (remove the current build)"
228-
echo " -x display expanded values (execute 'set -x')"
226+
echo " -x display expanded values (execute 'set -x')"
227+
echo
228+
echo "For developers:"
229+
echo " -u 'mod1 mod2' Modules to update (if already compiled)"
229230
echo
230231
exit 0
231232
}
@@ -330,6 +331,11 @@ function run_prepare() {
330331
try rm -rf $BUILD_PATH
331332
try rm -rf $SRC_PATH/obj
332333
try rm -rf $SRC_PATH/libs
334+
pushd $JNI_PATH
335+
push_arm
336+
try ndk-build clean
337+
pop_arm
338+
popd
333339
fi
334340

335341
# create build directory if not found
@@ -585,11 +591,40 @@ function run_prebuild() {
585591

586592
function run_build() {
587593
info "Run build"
594+
595+
modules_update=($MODULES_UPDATE)
596+
588597
cd $BUILD_PATH
598+
589599
for module in $MODULES; do
590-
fn=$(echo build_$module)
591-
debug "Call $fn"
592-
$fn
600+
fn="build_$module"
601+
shouldbuildfn="shouldbuild_$module"
602+
MARKER_FN="$BUILD_PATH/.mark-$module"
603+
604+
# if the module should be updated, then remove the marker.
605+
in_array $module "${modules_update[@]}"
606+
if [ $? -ne 255 ]; then
607+
debug "$module detected to be updated"
608+
rm -f "$MARKER_FN"
609+
fi
610+
611+
# if shouldbuild_$module exist, call it to see if the module want to be
612+
# built again
613+
DO_BUILD=1
614+
if [ "$(type -t $shouldbuildfn)" == "function" ]; then
615+
$shouldbuildfn
616+
fi
617+
618+
# if the module should be build, or if the marker is not present,
619+
# do the build
620+
if [ "X$DO_BUILD" == "X1" ] || [ ! -f "$MARKER_FN" ]; then
621+
debug "Call $fn"
622+
rm -f "$MARKER_FN"
623+
$fn
624+
touch "$MARKER_FN"
625+
else
626+
debug "Skipped $fn"
627+
fi
593628
done
594629
}
595630

@@ -633,7 +668,7 @@ function run_pymodules_install() {
633668
try echo "$PYMODULES" | try sed 's/\ /\n/g' > requirements.txt
634669

635670
debug "Install pure-python modules via pip in venv"
636-
try bash -c "source venv/bin/activate && env CC=/bin/false CXX=/bin/false $PIP install --target '$BUILD_PATH/python-install/lib/python2.7/site-packages' --download-cache '$PACKAGES_PATH' -r requirements.txt"
671+
try bash -c "source venv/bin/activate && env CC=/bin/false CXX=/bin/false $PIP install --target '$SITEPACKAGES_PATH' --download-cache '$PACKAGES_PATH' -r requirements.txt"
637672

638673
}
639674

@@ -656,7 +691,7 @@ function run_distribute() {
656691
try cp -a $BUILD_PATH/blacklist.txt .
657692

658693
debug "Copy python distribution"
659-
$BUILD_PATH/python-install/bin/python.host -OO -m compileall $BUILD_PATH/python-install
694+
$HOSTPYTHON -OO -m compileall $BUILD_PATH/python-install
660695
try cp -a $BUILD_PATH/python-install .
661696

662697
debug "Copy libs"
@@ -679,19 +714,11 @@ function run_distribute() {
679714
try find . | grep -E '*\.(py|pyc|so\.o|so\.a|so\.libs)$' | xargs rm
680715

681716
# we are sure that all of theses will be never used on android (well...)
682-
try rm -rf test
683717
try rm -rf ctypes
684718
try rm -rf lib2to3
685-
try rm -rf lib-tk
686719
try rm -rf idlelib
687-
try rm -rf unittest/test
688-
try rm -rf json/tests
689-
try rm -rf distutils/tests
690-
try rm -rf email/test
691-
try rm -rf bsddb/test
692720
try rm -rf config/libpython*.a
693721
try rm -rf config/python.o
694-
try rm -rf curses
695722
try rm -rf lib-dynload/_ctypes_test.so
696723
try rm -rf lib-dynload/_testcapi.so
697724

@@ -746,7 +773,7 @@ function arm_deduplicate() {
746773

747774

748775
# Do the build
749-
while getopts ":hvlfxm:d:s" opt; do
776+
while getopts ":hvlfxm:u:d:s" opt; do
750777
case $opt in
751778
h)
752779
usage
@@ -765,6 +792,9 @@ while getopts ":hvlfxm:d:s" opt; do
765792
m)
766793
MODULES="$OPTARG"
767794
;;
795+
u)
796+
MODULES_UPDATE="$OPTARG"
797+
;;
768798
d)
769799
DIST_PATH="$ROOT_PATH/dist/$OPTARG"
770800
;;

docs/source/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
# built documents.
4949
#
5050
# The short X.Y version.
51-
version = '1.1'
51+
version = '1.2'
5252
# The full version, including alpha/beta/rc tags.
53-
release = '1.1'
53+
release = '1.2'
5454

5555
# The language for content autogenerated by Sphinx. Refer to documentation
5656
# for a list of supported languages.

docs/source/usage.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Available options to `distribute.sh`::
4848
-l Show a list of available modules
4949
-m 'mod1 mod2' Modules to include
5050
-f Restart from scratch (remove the current build)
51+
-u 'mod1 mod2' Modules to update (if already compiled)
5152

5253
Step 2: package your application
5354
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

recipes/android/recipe.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ function prebuild_android() {
1616
fi
1717
}
1818

19+
function shouldbuild_android() {
20+
if [ -d "$SITEPACKAGES_PATH/android" ]; then
21+
DO_BUILD=0
22+
fi
23+
}
24+
1925
function build_android() {
2026
cd $BUILD_android
2127

@@ -31,8 +37,8 @@ function build_android() {
3137

3238
# cythonize
3339
try find . -iname '*.pyx' -exec cython {} \;
34-
try $BUILD_PATH/python-install/bin/python.host setup.py build_ext -v
35-
try $BUILD_PATH/python-install/bin/python.host setup.py install -O2
40+
try $HOSTPYTHON setup.py build_ext -v
41+
try $HOSTPYTHON setup.py install -O2
3642

3743
unset LDSHARED
3844

recipes/audiostream/recipe.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@ function prebuild_audiostream() {
1111
cd $BUILD_audiostream
1212
}
1313

14+
function shouldbuild_audiostream() {
15+
if [ -d "$SITEPACKAGES_PATH/audiostream" ]; then
16+
DO_BUILD=0
17+
fi
18+
}
19+
1420
function build_audiostream() {
1521
cd $BUILD_audiostream
1622

17-
if [ -d "$BUILD_PATH/python-install/lib/python2.7/site-packages/audiostream" ]; then
18-
#return
19-
true
20-
fi
21-
2223
push_arm
2324

2425
# build python extension
@@ -27,10 +28,10 @@ function build_audiostream() {
2728
export LDFLAGS="$LDFLAGS -lm -L$LIBS_PATH"
2829
export AUDIOSTREAM_ROOT="$BUILD_audiostream/build/audiostream/armeabi-v7a"
2930
try cd $BUILD_audiostream
30-
$BUILD_PATH/python-install/bin/python.host setup.py build_ext &>/dev/null
31+
$HOSTPYTHON setup.py build_ext &>/dev/null
3132
try find . -iname '*.pyx' -exec cython {} \;
32-
try $BUILD_PATH/python-install/bin/python.host setup.py build_ext -v
33-
try $BUILD_PATH/python-install/bin/python.host setup.py install -O2
33+
try $HOSTPYTHON setup.py build_ext -v
34+
try $HOSTPYTHON setup.py install -O2
3435
try cp -a audiostream/platform/android/org $JAVACLASS_PATH
3536

3637
pop_arm

recipes/cymunk/recipe.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ function prebuild_cymunk() {
1111
true
1212
}
1313

14+
function shouldbuild_cymunk() {
15+
if [ -d "$SITEPACKAGES_PATH/cymunk" ]; then
16+
DO_BUILD=0
17+
fi
18+
}
19+
1420
function build_cymunk() {
1521
cd $BUILD_cymunk
1622

@@ -19,7 +25,7 @@ function build_cymunk() {
1925
export LDSHARED="$LIBLINK"
2026

2127
try find . -iname '*.pyx' -exec cython {} \;
22-
try $BUILD_PATH/python-install/bin/python.host setup.py build_ext -v
28+
try $HOSTPYTHON setup.py build_ext -v
2329
try find build/lib.* -name "*.o" -exec $STRIP {} \;
2430

2531
export PYTHONPATH=$BUILD_hostpython/Lib/site-packages

recipes/docutils/recipe.sh

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ function prebuild_docutils() {
1111
true
1212
}
1313

14-
function build_docutils() {
15-
if [ -d "$BUILD_PATH/python-install/lib/python2.7/site-packages/docutils" ]; then
16-
#return
17-
true
18-
fi
14+
function shouldbuild_docutils() {
15+
if [ -d "$SITEPACKAGES_PATH/docutils" ]; then
16+
DO_BUILD=0
17+
fi
18+
}
1919

20+
function build_docutils() {
2021
cd $BUILD_docutils
2122

2223
push_arm
@@ -25,10 +26,10 @@ function build_docutils() {
2526
export LDSHARED="$LIBLINK"
2627

2728
# fake try to be able to cythonize generated files
28-
$BUILD_PATH/python-install/bin/python.host setup.py build_ext
29+
$HOSTPYTHON setup.py build_ext
2930
try find . -iname '*.pyx' -exec cython {} \;
30-
try $BUILD_PATH/python-install/bin/python.host setup.py build_ext -v
31-
try $BUILD_PATH/python-install/bin/python.host setup.py install -O2
31+
try $HOSTPYTHON setup.py build_ext -v
32+
try $HOSTPYTHON setup.py install -O2
3233

3334
unset LDSHARED
3435
pop_arm

recipes/ffmpeg/recipe.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ function prebuild_ffmpeg() {
1616
fi
1717
}
1818

19-
function build_ffmpeg() {
20-
cd $BUILD_ffmpeg
21-
22-
if [ -d "$BUILD_PATH/python-install/lib/python2.7/site-packages/ffmpeg" ]; then
23-
return
19+
function shouldbuild_ffmpeg() {
20+
if [ -d "$SITEPACKAGES_PATH/ffmpeg" ]; then
21+
DO_BUILD=0
2422
fi
23+
}
2524

25+
function build_ffmpeg() {
26+
cd $BUILD_ffmpeg
2627

2728
# build ffmpeg
2829
export NDK=$ANDROIDNDK
@@ -39,8 +40,8 @@ function build_ffmpeg() {
3940
export FFMPEG_ROOT="$BUILD_ffmpeg/build/ffmpeg/armeabi-v7a"
4041
try cd $BUILD_ffmpeg/python
4142
try find . -iname '*.pyx' -exec cython {} \;
42-
try $BUILD_PATH/python-install/bin/python.host setup.py build_ext -v
43-
try $BUILD_PATH/python-install/bin/python.host setup.py install -O2
43+
try $HOSTPYTHON setup.py build_ext -v
44+
try $HOSTPYTHON setup.py install -O2
4445

4546
pop_arm
4647
}

recipes/gevent/recipe.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,20 @@ function prebuild_gevent() {
1111
true
1212
}
1313

14+
function shouldbuild_gevent() {
15+
if [ -d "$SITEPACKAGES_PATH/gevent" ]; then
16+
DO_BUILD=0
17+
fi
18+
}
19+
1420
function build_gevent() {
1521
cd $BUILD_gevent
1622

17-
if [ -d "$BUILD_PATH/python-install/lib/python2.7/site-packages/gevent" ]; then
18-
return
19-
fi
20-
2123
push_arm
2224
export CFLAGS="$CFLAGS -I$BUILD_libevent/build/include"
2325
export LDFLAGS="$LDFLAGS -L$LIBS_PATH -L$BUILD_libevent/build/lib/"
2426

25-
try $BUILD_PATH/python-install/bin/python.host setup.py install -O2
27+
try $HOSTPYTHON setup.py install -O2
2628
pop_arm
2729
}
2830

recipes/greenlet/recipe.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@ function prebuild_greenlet() {
1212
true
1313
}
1414

15+
function shouldbuild_greenlet() {
16+
if [ -d "$SITEPACKAGES_PATH/greenlet" ]; then
17+
DO_BUILD=0
18+
fi
19+
}
20+
1521
function build_greenlet() {
1622
cd $BUILD_greenlet
1723

18-
if [ -d "$BUILD_PATH/python-install/lib/python2.7/site-packages/greenlet.so" ]; then
19-
return
20-
fi
21-
2224
push_arm
23-
24-
try $BUILD_PATH/python-install/bin/python.host setup.py install -O2
25+
try $HOSTPYTHON setup.py install -O2
2526
pop_arm
2627
}
2728

recipes/hostpython/recipe.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@ function prebuild_hostpython() {
1313
try cp $RECIPE_hostpython/Setup Modules/Setup
1414
}
1515

16-
function build_hostpython() {
17-
# placeholder for building
16+
function shouldbuild_hostpython() {
1817
cd $BUILD_hostpython
19-
20-
# don't do the build if we already got hostpython binary
2118
if [ -f hostpython ]; then
22-
return
19+
DO_BUILD=0
2320
fi
21+
}
22+
23+
function build_hostpython() {
24+
# placeholder for building
25+
cd $BUILD_hostpython
2426

2527
try ./configure
2628
try make -j5

0 commit comments

Comments
 (0)