1 // Copyright 2017 Google Inc. All rights reserved. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef ANDROID_CPYTHON2_PYTHON_LAUNCHER_INTERNAL_H 16 #define ANDROID_CPYTHON2_PYTHON_LAUNCHER_INTERNAL_H 17 18 #include <Python.h> 19 20 #include <string> 21 22 namespace android { 23 namespace cpython2 { 24 namespace python_launcher { 25 26 namespace internal{ 27 #define ENTRYPOINT_FILE "entry_point.txt" 28 #define RUNFILES "runfiles" 29 30 // Use "runpy" module to locate and run Python script using Python module 31 // namespace rather than the filesystem. 32 // The caller owns "module" pointer, which cannot be NULL. 33 int RunModule(const char *module, int set_argv0); 34 35 // Get valid entrypoint file path. 36 // The caller owns "launcher_path" pointer, which cannot be NULL. 37 // Return non-empty string as success. Otherwise, return empty string. 38 std::string GetEntryPointFilePath(const char *launcher_path); 39 40 // Run the Python script embedded in ENTRYPOINT_FILE. 41 // The caller owns "launcher_path" pointer, which cannot be NULL. 42 int RunModuleNameFromEntryPoint(const char *launcher_path, std::string entrypoint); 43 44 // Add path to Python sys.path list. 45 // The caller owns "path" pointer, which cannot be NULL. 46 int AddPathToPythonSysPath(const char *path); 47 48 // Run __main__ module within the hermetic .par file. 49 // The caller owns "launcher_path" pointer, which cannot be NULL. 50 // Return 0 as success. Otherwise, return -1. 51 int RunMainFromImporter(const char *launcher_path); 52 } // namespace internal 53 54 // Try to run the Python script embedded in ENTRYPOINT_FILE. Otherwise, 55 // run __main__ module as fallback. 56 // The caller owns "launcher_path" pointer, which cannot be NULL. 57 int RunEntryPointOrMainModule(const char *launcher_path); 58 } // namespace python_launcher 59 } // namespace cpython2 60 } // namespace android 61 62 #endif // ANDROID_CPYTHON2_PYTHON_LAUNCHER_INTERNAL_H 63