diff --git a/tests/Makefile.am.inc b/tests/Makefile.am.inc index 814986d0..15a68ebe 100644 --- a/tests/Makefile.am.inc +++ b/tests/Makefile.am.inc @@ -85,6 +85,12 @@ installed_test_data = \ tests/test.json \ tests/session.conf.in \ tests/0001-Add-test-logo.patch \ + tests/org.test.Python.json \ + tests/empty-configure \ + tests/testpython.py \ + tests/testpython.py \ + tests/importme.py \ + tests/importme2.py \ $(NULL) installed_test_keyringdir = $(installed_testdir)/test-keyring @@ -111,6 +117,7 @@ dist_test_scripts = \ tests/test-bundle.sh \ tests/test-bundle-system.sh \ tests/test-builder.sh \ + tests/test-builder-python.sh \ $(NULL) test_programs = testdb test-doc-portal testlibrary diff --git a/tests/empty-configure b/tests/empty-configure new file mode 100755 index 00000000..b967536e --- /dev/null +++ b/tests/empty-configure @@ -0,0 +1,9 @@ +#!/bin/sh + +cat < Makefile +all: + echo Building + +install: + echo Installing +EOF diff --git a/tests/importme.py b/tests/importme.py new file mode 100644 index 00000000..a6f4d896 --- /dev/null +++ b/tests/importme.py @@ -0,0 +1,2 @@ +import sys +foo = "first" diff --git a/tests/importme2.py b/tests/importme2.py new file mode 100644 index 00000000..f257cf08 --- /dev/null +++ b/tests/importme2.py @@ -0,0 +1,2 @@ +import sys +foo = "modified" diff --git a/tests/libtest.sh b/tests/libtest.sh index 9dbcc115..923732c9 100644 --- a/tests/libtest.sh +++ b/tests/libtest.sh @@ -193,6 +193,12 @@ setup_sdk_repo () { update_repo } +setup_python2_repo () { + GPGARGS="$FL_GPGARGS" . $(dirname $0)/make-test-runtime.sh org.test.PythonPlatform bash python2 ls cat echo readlink > /dev/null + GPGARGS="$FL_GPGARGS" . $(dirname $0)/make-test-runtime.sh org.test.PythonSdk python2 bash ls cat echo readlink make mkdir cp touch > /dev/null + update_repo +} + install_repo () { ${FLATPAK} ${U} install test-repo org.test.Platform master ${FLATPAK} ${U} install test-repo org.test.Hello master @@ -202,6 +208,11 @@ install_sdk_repo () { ${FLATPAK} ${U} install test-repo org.test.Sdk master } +install_python2_repo () { + ${FLATPAK} ${U} install test-repo org.test.PythonPlatform master + ${FLATPAK} ${U} install test-repo org.test.PythonSdk master +} + run () { ${CMD_PREFIX} flatpak run "$@" @@ -230,6 +241,14 @@ skip_without_bwrap () { fi } +skip_without_python2 () { + if ! test -f /usr/bin/python2 || ! test -f /usr/lib*/python2.7/os.py ; then + echo "1..0 # SKIP this test requires /usr/bin/python2 (2.7) support" + exit 0 + fi +} + + sed s#@testdir@#${test_builddir}# ${test_srcdir}/session.conf.in > session.conf dbus-daemon --fork --config-file=session.conf --print-address=3 --print-pid=4 \ 3> dbus-session-bus-address 4> dbus-session-bus-pid diff --git a/tests/make-test-runtime.sh b/tests/make-test-runtime.sh index 8a3c4550..9295fd3c 100755 --- a/tests/make-test-runtime.sh +++ b/tests/make-test-runtime.sh @@ -20,6 +20,21 @@ for i in $@; do I=`which $i` cp $I ${DIR}/usr/bin ldd $I | sed "s/.* => //" | awk '{ print $1}' | grep ^/ | grep ^/ >> $T + if test $i == python2; then + mkdir -p ${DIR}/usr/lib/python2.7/lib-dynload + # This is a hardcoded minimal set of modules we need in the current tests. + # Pretty hacky stuff. Add modules as needed. + for py in site os stat posixpath genericpath warnings \ + linecache types UserDict abc _abcoll \ + _weakrefset copy_reg traceback sysconfig \ + re sre_compile sre_parse sre_constants \ + _sysconfigdata ; do + cp /usr/lib*/python2.7/$py.py ${DIR}/usr/lib/python2.7 + done + for so in _locale strop ; do + cp /usr/lib*/python2.7/lib-dynload/${so}module.so ${DIR}/usr/lib/python2.7/lib-dynload + done + fi done ln -s bash ${DIR}/usr/bin/sh for i in `sort -u $T`; do diff --git a/tests/org.test.Python.json b/tests/org.test.Python.json new file mode 100644 index 00000000..64a97cac --- /dev/null +++ b/tests/org.test.Python.json @@ -0,0 +1,63 @@ +{ + "app-id": "org.test.Python", + "runtime": "org.test.PythonPlatform", + "sdk": "org.test.PythonSdk", + "command": "testpython.py", + "modules": [ + { + "name": "compiled-python", + "post-install": [ + "mkdir /app/bin", + "cp testpython.py /app/bin", + "cp importme.py /app/bin", + /* Compile importme.py */ + "/app/bin/testpython.py" + ], + "sources": [ + { + "type": "file", + "path": "empty-configure", + "dest-filename": "configure" + }, + { + "type": "file", + "path": "testpython.py" + }, + { + "type": "file", + "path": "importme.py" + } + ] + }, + { + "name": "modify-python", + "post-install": [ + "cp importme2.py /app/bin/importme.py" + ], + "sources": [ + { + "type": "file", + "path": "empty-configure", + "dest-filename": "configure" + }, + { + "type": "file", + "path": "importme2.py" + } + ] + }, + { + "name": "recompile-modified-python", + "post-install": [ + "/app/bin/testpython.py" + ], + "sources": [ + { + "type": "file", + "path": "empty-configure", + "dest-filename": "configure" + } + ] + } + ] +} diff --git a/tests/test-builder-python.sh b/tests/test-builder-python.sh new file mode 100755 index 00000000..21d296d4 --- /dev/null +++ b/tests/test-builder-python.sh @@ -0,0 +1,52 @@ +#!/bin/bash +# +# Copyright (C) 2011 Colin Walters +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +set -euo pipefail + +. $(dirname $0)/libtest.sh + +skip_without_bwrap +skip_without_user_xattrs +skip_without_python2 + +echo "1..1" + +setup_repo +install_repo +setup_python2_repo +install_python2_repo + +# Need /var/tmp cwd for xattrs +REPO=`pwd`/repo +cd $TEST_DATA_DIR/ + +cp $(dirname $0)/org.test.Python.json . +cp -a $(dirname $0)/empty-configure . +cp -a $(dirname $0)/testpython.py . +cp $(dirname $0)/importme.py . +cp $(dirname $0)/importme2.py . +flatpak-builder --force-clean appdir org.test.Python.json + +assert_has_file appdir/files/bin/importme.pyc + +flatpak-builder --run appdir org.test.Python.json testpython.py > testpython.out + +assert_file_has_content testpython.out ^modified$ + +echo "ok handled pyc rewriting multiple times" diff --git a/tests/testpython.py b/tests/testpython.py new file mode 100755 index 00000000..b40d848d --- /dev/null +++ b/tests/testpython.py @@ -0,0 +1,4 @@ +#!/usr/bin/python2 + +import importme +print importme.foo