313 lines
11 KiB
Diff
313 lines
11 KiB
Diff
diff -ru Python-3.3.5/Lib/platform.py Python-3.3.5-android/Lib/platform.py
|
|
--- Python-3.3.5/Lib/platform.py 2014-03-09 09:40:13.000000000 +0100
|
|
+++ Python-3.3.5-android/Lib/platform.py 2014-08-04 22:19:36.000000000 +0200
|
|
@@ -368,6 +368,63 @@
|
|
supported_dists=supported_dists,
|
|
full_distribution_name=0)
|
|
|
|
+_android_environment_vars = (
|
|
+ 'ANDROID_PRIVATE', 'ANDROID_ARGUMENT', 'ANDROID_APP_PATH', 'ANDROID_DATA',
|
|
+ 'ANDROID_PROPERTY_WORKSPACE', 'ANDROID_BOOTLOGO')
|
|
+_android_version_property = 'ro.build.version.release'
|
|
+_android_buildstr_property = 'ro.build.version.full'
|
|
+
|
|
+def android_version(version='', buildstr=''):
|
|
+ """ Attempt to get the Android version number and build string.
|
|
+
|
|
+ The function checks for the getprop binary to retrieve build info,
|
|
+ and falls back to manually reading /system/build.prop if available.
|
|
+
|
|
+ Returns a (version, buildstr) tuple which defaults to the args given
|
|
+ as parameters.
|
|
+ """
|
|
+ if not any(os.getenv(e) for e in _android_environment_vars):
|
|
+ # Probably not on Android...
|
|
+ return version, buildstr
|
|
+
|
|
+ version_obtained = False
|
|
+ buildstr_obtained = False
|
|
+
|
|
+ # Try the 'official' API tool first, since /system/build.prop might
|
|
+ # not be the only source for properties.
|
|
+ if os.access('/system/bin/getprop', os.X_OK):
|
|
+ try:
|
|
+ output = subprocess.check_output(['/system/bin/getprop',
|
|
+ _android_version_property])
|
|
+ version = output.decode('ascii').strip()
|
|
+ version_obtained = True
|
|
+ except (subprocess.CalledProcessError, UnicodeDecodeError):
|
|
+ pass
|
|
+
|
|
+ try:
|
|
+ output = subprocess.check_output(['/system/bin/getprop',
|
|
+ _android_buildstr_property])
|
|
+ buildstr = output.decode('ascii').strip()
|
|
+ buildstr_obtained = True
|
|
+ except (subprocess.CalledProcessError, UnicodeDecodeError):
|
|
+ pass
|
|
+ done = version_obtained and buildstr_obtained
|
|
+
|
|
+ # Fall back to parsing /system/build.prop manually.
|
|
+ if not done and os.path.isfile('/system/build.prop'):
|
|
+ for line in open('/system/build.prop'):
|
|
+ if '=' not in line:
|
|
+ continue
|
|
+ key, val = line.split('=')
|
|
+ key = key.strip()
|
|
+
|
|
+ if not version_obtained and key == _android_version_property:
|
|
+ version = val.strip()
|
|
+ elif not buildstr_obtained and key == _android_buildstr_property:
|
|
+ buildstr = val.strip()
|
|
+
|
|
+ return version, buildstr
|
|
+
|
|
def popen(cmd, mode='r', bufsize=-1):
|
|
|
|
""" Portable popen() interface.
|
|
diff -ru Python-3.3.5/Lib/subprocess.py Python-3.3.5-android/Lib/subprocess.py
|
|
--- Python-3.3.5/Lib/subprocess.py 2014-03-09 09:40:13.000000000 +0100
|
|
+++ Python-3.3.5-android/Lib/subprocess.py 2014-08-04 22:19:36.000000000 +0200
|
|
@@ -1343,9 +1343,18 @@
|
|
args = list(args)
|
|
|
|
if shell:
|
|
- args = ["/bin/sh", "-c"] + args
|
|
if executable:
|
|
- args[0] = executable
|
|
+ main = executable
|
|
+ elif os.path.isfile('/bin/sh'):
|
|
+ main = '/bin/sh'
|
|
+ else:
|
|
+ import platform
|
|
+ if platform.android_version()[0]:
|
|
+ main = '/system/bin/sh'
|
|
+ else:
|
|
+ raise RuntimeError('Could not find system shell')
|
|
+
|
|
+ args = [main, "-c"] + args
|
|
|
|
if executable is None:
|
|
executable = args[0]
|
|
diff -ru Python-3.3.5/Lib/test/test_subprocess.py Python-3.3.5-android/Lib/test/test_subprocess.py
|
|
--- Python-3.3.5/Lib/test/test_subprocess.py 2014-03-09 09:40:19.000000000 +0100
|
|
+++ Python-3.3.5-android/Lib/test/test_subprocess.py 2014-08-04 22:19:36.000000000 +0200
|
|
@@ -17,6 +17,7 @@
|
|
import shutil
|
|
import gc
|
|
import textwrap
|
|
+import platform
|
|
|
|
try:
|
|
import resource
|
|
@@ -1356,7 +1357,10 @@
|
|
fd, fname = mkstemp()
|
|
# reopen in text mode
|
|
with open(fd, "w", errors="surrogateescape") as fobj:
|
|
- fobj.write("#!/bin/sh\n")
|
|
+ if platform.android_version()[0]:
|
|
+ fobj.write('#!/system/bin/sh\n')
|
|
+ else:
|
|
+ fobj.write("#!/bin/sh\n")
|
|
fobj.write("exec '%s' -c 'import sys; sys.exit(47)'\n" %
|
|
sys.executable)
|
|
os.chmod(fname, 0o700)
|
|
@@ -1401,7 +1405,10 @@
|
|
fd, fname = mkstemp()
|
|
# reopen in text mode
|
|
with open(fd, "w", errors="surrogateescape") as fobj:
|
|
- fobj.write("#!/bin/sh\n")
|
|
+ if platform.android_version()[0]:
|
|
+ fobj.write('#!/system/bin/sh\n')
|
|
+ else:
|
|
+ fobj.write("#!/bin/sh\n")
|
|
fobj.write("exec '%s' -c 'import sys; sys.exit(47)'\n" %
|
|
sys.executable)
|
|
os.chmod(fname, 0o700)
|
|
diff -ru Python-3.4.2/Modules/pwdmodule.c Python-3.4.2-android/Modules/pwdmodule.c
|
|
--- Python-3.4.2/Modules/pwdmodule.c 2015-02-24 23:06:31.000000000 +0100
|
|
+++ Python-3.4.2-android/Modules/pwdmodule.c 2015-02-24 23:09:14.000000000 +0100
|
|
@@ -72,7 +72,11 @@
|
|
SETS(setIndex++, p->pw_passwd);
|
|
PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromUid(p->pw_uid));
|
|
PyStructSequence_SET_ITEM(v, setIndex++, _PyLong_FromGid(p->pw_gid));
|
|
+#if !defined(__ANDROID__)
|
|
SETS(setIndex++, p->pw_gecos);
|
|
+#else
|
|
+ SETS(setIndex++, "");
|
|
+#endif
|
|
SETS(setIndex++, p->pw_dir);
|
|
SETS(setIndex++, p->pw_shell);
|
|
|
|
diff -ru Python-3.3.5/Modules/socketmodule.c Python-3.3.5-android/Modules/socketmodule.c
|
|
--- Python-3.3.5/Modules/socketmodule.c 2014-03-09 09:40:28.000000000 +0100
|
|
+++ Python-3.3.5-android/Modules/socketmodule.c 2014-08-04 22:19:36.000000000 +0200
|
|
@@ -150,7 +150,7 @@
|
|
On the other hand, not all Linux versions agree, so there the settings
|
|
computed by the configure script are needed! */
|
|
|
|
-#ifndef linux
|
|
+#if !defined(linux) || __ANDROID__
|
|
# undef HAVE_GETHOSTBYNAME_R_3_ARG
|
|
# undef HAVE_GETHOSTBYNAME_R_5_ARG
|
|
# undef HAVE_GETHOSTBYNAME_R_6_ARG
|
|
@@ -169,7 +169,7 @@
|
|
# define HAVE_GETHOSTBYNAME_R_3_ARG
|
|
# elif defined(__sun) || defined(__sgi)
|
|
# define HAVE_GETHOSTBYNAME_R_5_ARG
|
|
-# elif defined(linux)
|
|
+# elif defined(linux) && !__ANDROID__
|
|
/* Rely on the configure script */
|
|
# else
|
|
# undef HAVE_GETHOSTBYNAME_R
|
|
diff -ru Python-3.3.5/Modules/posixmodule.c Python-3.3.5-android/Modules/posixmodule.c
|
|
--- Python-3.3.5/Modules/posixmodule.c 2014-03-09 08:40:28.000000000 +0000
|
|
+++ Python-3.3.5-android/Modules/posixmodule.c 2015-02-24 19:57:05.368843433 +0000
|
|
@@ -403,6 +403,11 @@
|
|
#endif
|
|
#endif
|
|
|
|
+/* Android doesn't expose AT_EACCESS - manually define it. */
|
|
+#if !defined(AT_EACCESS) && defined(__ANDROID__)
|
|
+#define AT_EACCESS 0x200
|
|
+#endif
|
|
+
|
|
|
|
#ifdef MS_WINDOWS
|
|
static int
|
|
diff -ru Python-3.3.5/Python/pytime.c Python-3.3.5-android/Python/pytime.c
|
|
--- Python-3.3.5/Python/pytime.c 2015-02-23 11:54:25.000000000 -0500
|
|
+++ Python-3.3.5-android/Python/pytime.c 2015-02-23 11:55:19.000000000 -0500
|
|
@@ -3,7 +3,7 @@
|
|
#include <windows.h>
|
|
#endif
|
|
|
|
-#if defined(__APPLE__) && defined(HAVE_GETTIMEOFDAY) && defined(HAVE_FTIME)
|
|
+#if (defined(__APPLE__) || defined(__ANDROID__)) && defined(HAVE_GETTIMEOFDAY) && defined(HAVE_FTIME)
|
|
/*
|
|
* _PyTime_gettimeofday falls back to ftime when getttimeofday fails because the latter
|
|
* might fail on some platforms. This fallback is unwanted on MacOSX because
|
|
diff -ru Python-3.4.2/configure Python-3.4.2-android/configure
|
|
--- Python-3.4.2/configure 2015-02-24 23:18:31.000000000 +0100
|
|
+++ Python-3.4.2-android/configure 2015-03-01 20:15:02.000000000 +0100
|
|
@@ -5406,6 +5406,34 @@
|
|
MULTIARCH=$($CC --print-multiarch 2>/dev/null)
|
|
|
|
|
|
+# Test if we're running on Android.
|
|
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if target is Android-based" >&5
|
|
+$as_echo_n "checking if target is Android-based... " >&6; }
|
|
+cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
|
+/* end confdefs.h. */
|
|
+
|
|
+#if __ANDROID__
|
|
+yes
|
|
+#endif
|
|
+
|
|
+_ACEOF
|
|
+if (eval "$ac_cpp conftest.$ac_ext") 2>&5 |
|
|
+ $EGREP "yes" >/dev/null 2>&1; then :
|
|
+
|
|
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
|
|
+$as_echo "yes" >&6; }
|
|
+ with_android=yes
|
|
+
|
|
+else
|
|
+
|
|
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
|
|
+$as_echo "no" >&6; }
|
|
+ with_android=no
|
|
+
|
|
+
|
|
+fi
|
|
+rm -f conftest*
|
|
+
|
|
|
|
|
|
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking LIBRARY" >&5
|
|
@@ -5650,7 +5678,14 @@
|
|
SOVERSION=`echo $SOVERSION|cut -d "." -f 1`
|
|
;;
|
|
esac
|
|
- INSTSONAME="$LDLIBRARY".$SOVERSION
|
|
+
|
|
+ if test "$with_android" != yes
|
|
+ then
|
|
+ INSTSONAME="$LDLIBRARY".$SOVERSION
|
|
+ else
|
|
+ INSTSONAME="$LDLIBRARY"
|
|
+ fi
|
|
+
|
|
if test "$with_pydebug" != yes
|
|
then
|
|
PY3LIBRARY=libpython3.so
|
|
diff -ru Python-3.4.2/configure.ac Python-3.4.2-android/configure.ac
|
|
--- Python-3.4.2/configure.ac 2015-02-24 23:18:31.000000000 +0100
|
|
+++ Python-3.4.2-android/configure.ac 2015-03-01 20:14:54.000000000 +0100
|
|
@@ -796,6 +796,21 @@
|
|
MULTIARCH=$($CC --print-multiarch 2>/dev/null)
|
|
AC_SUBST(MULTIARCH)
|
|
|
|
+# Test if we're running on Android.
|
|
+AC_MSG_CHECKING(if target is Android-based)
|
|
+AC_EGREP_CPP(yes,
|
|
+[
|
|
+#if __ANDROID__
|
|
+yes
|
|
+#endif
|
|
+], [
|
|
+ AC_MSG_RESULT(yes)
|
|
+ with_android=yes
|
|
+ ], [
|
|
+ AC_MSG_RESULT(no)
|
|
+ with_android=no
|
|
+ ]
|
|
+)
|
|
|
|
AC_SUBST(LIBRARY)
|
|
AC_MSG_CHECKING(LIBRARY)
|
|
@@ -970,7 +985,14 @@
|
|
SOVERSION=`echo $SOVERSION|cut -d "." -f 1`
|
|
;;
|
|
esac
|
|
- INSTSONAME="$LDLIBRARY".$SOVERSION
|
|
+
|
|
+ if test "$with_android" != yes
|
|
+ then
|
|
+ INSTSONAME="$LDLIBRARY".$SOVERSION
|
|
+ else
|
|
+ INSTSONAME="$LDLIBRARY"
|
|
+ fi
|
|
+
|
|
if test "$with_pydebug" != yes
|
|
then
|
|
PY3LIBRARY=libpython3.so
|
|
|
|
diff -ru Python-3.4.2/Makefile.pre.in Python-3.4.2-android/Makefile.pre.in
|
|
--- Python-3.4.2/Makefile.pre.in 2015-03-04 16:25:36.000000000 +0100
|
|
+++ Python-3.4.2-android/Makefile.pre.in 2015-03-04 16:27:27.000000000 +0100
|
|
@@ -568,7 +568,7 @@
|
|
*\ -s*|s*) quiet="-q";; \
|
|
*) quiet="";; \
|
|
esac; \
|
|
- $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED)' OPT='$(OPT)' \
|
|
+ $(RUNSHARED) CC='$(CC)' LDSHARED='$(BLDSHARED) -lpython$(LDVERSION)' OPT='$(OPT)' \
|
|
_TCLTK_INCLUDES='$(TCLTK_INCLUDES)' _TCLTK_LIBS='$(TCLTK_LIBS)' \
|
|
$(PYTHON_FOR_BUILD) $(srcdir)/setup.py $$quiet build
|
|
|
|
diff -Nru Python-3.4.2/Makefile.pre.in Python-3.4.2-android/Makefile.pre.in
|
|
--- Python-3.4.2/Makefile.pre.in 2015-06-27 17:04:23.885777456 +0000
|
|
+++ Python-3.4.2-android/Makefile.pre.in 2015-06-27 17:05:27.709777315 +0000
|
|
@@ -585,11 +585,9 @@
|
|
$(RANLIB) $@
|
|
|
|
libpython$(LDVERSION).so: $(LIBRARY_OBJS)
|
|
+ $(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
|
|
if test $(INSTSONAME) != $(LDLIBRARY); then \
|
|
- $(BLDSHARED) -Wl,-h$(INSTSONAME) -o $(INSTSONAME) $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
|
|
$(LN) -f $(INSTSONAME) $@; \
|
|
- else \
|
|
- $(BLDSHARED) -o $@ $(LIBRARY_OBJS) $(MODLIBS) $(SHLIBS) $(LIBC) $(LIBM) $(LDLAST); \
|
|
fi
|
|
|
|
libpython3.so: libpython$(LDVERSION).so
|