Create py2-cmd which behaves more like the normal `python`
Instead of executing the __main__.py inside the par file, it'll use all
the normal python command line options, allowing you to replace python
in $PATH with this executable.
Also add distutils, which some script expect to be in the stdlib.
Bug: 117811537
Test: move py2-cmd to prebuilts/build-tools/path/linux-x86/python and build
Change-Id: Iddab6ab4db23f99953ecf4d42cd7d966851b1e1b
diff --git a/Launcher/launcher_main.cpp b/Launcher/launcher_main.cpp
index c0b0c49..0a34c18 100644
--- a/Launcher/launcher_main.cpp
+++ b/Launcher/launcher_main.cpp
@@ -32,8 +32,12 @@
// 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 @@
// 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);
}