aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Willemsen <dwillemsen@google.com>2019-02-18 11:10:43 -0800
committerandroid-build-merger <android-build-merger@google.com>2019-02-18 11:10:43 -0800
commit89359db7bf5b498c794c7c4be45e4a68b08b8a26 (patch)
tree959806fc7f6479fcf18ad2d3730b23de873a288d
parente9611a6c97ad95ce07317fdaf4fc994c07657aa4 (diff)
parentcd28285fe2b5ded6c12a0688e2e694c3c4e2e7f4 (diff)
downloadplatform_external_python_cpython2-89359db7bf5b498c794c7c4be45e4a68b08b8a26.tar.gz
platform_external_python_cpython2-89359db7bf5b498c794c7c4be45e4a68b08b8a26.tar.bz2
platform_external_python_cpython2-89359db7bf5b498c794c7c4be45e4a68b08b8a26.zip
Create py2-cmd which behaves more like the normal `python`
am: cd28285fe2 Change-Id: I5804aae41349c6d98d96e5ef30e6a5d5080c6149
-rw-r--r--Android.bp73
-rw-r--r--Launcher/launcher_main.cpp17
-rw-r--r--Lib/Android.bp1
3 files changed, 67 insertions, 24 deletions
diff --git a/Android.bp b/Android.bp
index 5d72eda072..aba4538e69 100644
--- a/Android.bp
+++ b/Android.bp
@@ -211,8 +211,8 @@ cc_library_static {
],
}
-cc_binary {
- name: "py2-launcher",
+cc_defaults {
+ name: "py2-launcher-defaults",
defaults: ["py2-interp-defaults"],
cflags: [
"-DVERSION=\"2.7\"",
@@ -226,8 +226,32 @@ cc_binary {
"-DDATE=\"Dec 31 1969\"",
"-DTIME=\"23:59:59\"",
],
+ static_libs: [
+ "libbase",
+ "libcrypto",
+ "libexpat",
+ "libssl",
+ "libz",
+ ],
+ target: {
+ linux_glibc_x86_64: {
+ host_ldlibs: ["-lutil"],
+ },
+ host: {
+ static_libs: ["libsqlite"],
+ },
+ // Use shared libsqlite for device side, otherwise
+ // the executable size will be really huge.
+ android: {
+ shared_libs: ["libsqlite"],
+ },
+ },
+}
+
+cc_library_static {
+ name: "py2-launcher-lib",
+ defaults: ["py2-launcher-defaults"],
srcs: [
- "Launcher/launcher_main.cpp",
"Modules/gcmodule.c",
"Modules/getpath.c",
"Modules/config.c",
@@ -246,8 +270,7 @@ cc_binary {
"Modules/main.c",
],
// NOTE: Please update Modules/config.c if new lib get added in the static_libs.
- static_libs: [
- "libbase",
+ whole_static_libs: [
// Be careful the order of these three static libraries below due to
// missing symbols issues.
"py2-interp-object",
@@ -307,22 +330,34 @@ cc_binary {
"py2-c-module-_sqlite3",
"py2-c-module-_ctypes_test",
"py2-c-module-_ctypes",
- "libcrypto",
- "libexpat",
- "libssl",
- "libz",
],
- target: {
- linux_glibc_x86_64: {
- host_ldlibs: ["-lutil"],
- },
- host: {
- static_libs: ["libsqlite"],
+}
+
+cc_binary {
+ name: "py2-launcher",
+ defaults: ["py2-launcher-defaults"],
+ srcs: ["Launcher/launcher_main.cpp"],
+ static_libs: ["py2-launcher-lib"],
+}
+
+cc_binary {
+ name: "py2-launcher-autorun",
+ defaults: ["py2-launcher-defaults"],
+ srcs: ["Launcher/launcher_main.cpp"],
+ static_libs: ["py2-launcher-lib"],
+ cflags: ["-DANDROID_AUTORUN"],
+}
+
+python_binary_host {
+ name: "py2-cmd",
+ autorun: false,
+ version: {
+ py2: {
+ enabled: true,
+ embedded_launcher: true,
},
- // Use shared libsqlite for device side, otherwise
- // the executable size will be really huge.
- android: {
- shared_libs: ["libsqlite"],
+ py3: {
+ enabled: false,
},
},
}
diff --git a/Launcher/launcher_main.cpp b/Launcher/launcher_main.cpp
index c0b0c49755..0a34c1885a 100644
--- a/Launcher/launcher_main.cpp
+++ b/Launcher/launcher_main.cpp
@@ -32,8 +32,12 @@ int main(int argc, char *argv[]) {
// everything's supposed to be hermetic.
Py_NoUserSiteDirectory = 1;
- // Ignore PYTHONPATH and PYTHONHOME from the environment.
+ // Ignore PYTHONPATH and PYTHONHOME from the environment. Unless we're not
+ // running from inside the zip file, in which case the user may have
+ // specified a PYTHONPATH.
+#ifdef ANDROID_AUTORUN
Py_IgnoreEnvironmentFlag = 1;
+#endif
Py_DontWriteBytecodeFlag = 1;
@@ -45,17 +49,20 @@ int main(int argc, char *argv[]) {
// Set the equivalent of PYTHONHOME internally.
Py_SetPythonHome(strdup(executable_path.c_str()));
- int new_argc = argc + 1;
- char **new_argv = reinterpret_cast<char**>(calloc(new_argc, sizeof(*argv)));
+#ifdef ANDROID_AUTORUN
+ argc += 1;
+ char **new_argv = reinterpret_cast<char**>(calloc(argc, sizeof(*argv)));
// Inject the path to our binary into argv[1] so the Py_Main won't parse any
// other options, and will execute the __main__.py script inside the zip file
// attached to our executable.
new_argv[0] = argv[0];
new_argv[1] = strdup(executable_path.c_str());
- for (int i = 1; i < argc; i++) {
+ for (int i = 1; i < argc - 1; i++) {
new_argv[i+1] = argv[i];
}
+ argv = new_argv;
+#endif
- return Py_Main(new_argc, new_argv);
+ return Py_Main(argc, argv);
}
diff --git a/Lib/Android.bp b/Lib/Android.bp
index 4fb6372b39..48e5caa099 100644
--- a/Lib/Android.bp
+++ b/Lib/Android.bp
@@ -20,6 +20,7 @@ python_library {
"*.py",
"compiler/**/*.py",
"ctypes/**/*.py",
+ "distutils/**/*.py",
"email/**/*.py",
"encodings/**/*.py",
"hotshot/**/*.py",