diff options
| author | mosimchah <mosimchah@gmail.com> | 2025-12-02 09:27:38 -0500 |
|---|---|---|
| committer | mosimchah <mosimchah@gmail.com> | 2025-12-02 09:27:38 -0500 |
| commit | c7bade461dc55726f62997d13a48582f7c4b4655 (patch) | |
| tree | ea0588da76060a2038f54f67efd046ca77634b10 /python/scripts/main.py | |
| parent | 0f5414d19317805e8bbbe7c4db5f0fd78769bad5 (diff) | |
| parent | 89d78cff8b00d3b20a90074635c3fe5a2ee49474 (diff) | |
Merge branch 'lineage-23.1' of https://github.com/LineageOS/android_build_soong into HEADw16.1
* 'lineage-23.1' of https://github.com/LineageOS/android_build_soong: (528 commits)
Revert "install_symlink: Make symlink target configurable"
Reapply "Clear as much of cc.Module as possible after GenerateBuildActions"
Revert "rust: config: Fix missing CPU variant LD flags in Rust"
Rename build-flag in outdir
Revert^4 "cipd: Default CIPD proxy server to on, add opt-out"
Convert check-vintf-all to phony with actions
Create a partial implementation of check-vintf-all for soong-only
Configure RBE rust pool based on build variant
Revert^3 "Add sdk version check to arr"
Add jdk.internal.invoke to the allowlist
Make droid always depend on symbols zip
Import Device and Odm skus
Don't install gob_gen in Soong
Remove bazel reference from run_integration_tests.sh
Fix bootstrap_test.sh
Don't panic in aconfig libraries when AllowMissingDependencies is set
Avoid returning nil paths from PathForModuleSrc
Revert "Flag controled clang version"
Rework module target dependencies on required deps
Revert^2 "Add sdk version check to arr"
...
Change-Id: I6e9a63fa14fda917a42e426e5dcebbad7f67e1de
Diffstat (limited to 'python/scripts/main.py')
| -rw-r--r-- | python/scripts/main.py | 90 |
1 files changed, 47 insertions, 43 deletions
diff --git a/python/scripts/main.py b/python/scripts/main.py index 35cdfc47e..a3d8f65a2 100644 --- a/python/scripts/main.py +++ b/python/scripts/main.py @@ -1,48 +1,52 @@ +# It's important that we use a function here, as any global variables we make in this script will +# also be available in the real entrypoint run by runpy._run_module_as_main. +def _soong_main(): + import os + import runpy + import shutil + import sys + import tempfile + import zipfile -import os -import runpy -import shutil -import sys -import tempfile -import zipfile + from pathlib import PurePath -from pathlib import PurePath + sys.argv[0] = __loader__.archive + # Set sys.executable to None. The real executable is available as + # sys.argv[0], and too many things assume sys.executable is a regular Python + # binary, which isn't available. By setting it to None we get clear errors + # when people try to use it. + sys.executable = None -sys.argv[0] = __loader__.archive - -# Set sys.executable to None. The real executable is available as -# sys.argv[0], and too many things assume sys.executable is a regular Python -# binary, which isn't available. By setting it to None we get clear errors -# when people try to use it. -sys.executable = None - -# Extract the shared libraries from the zip file into a temporary directory. -# This works around the limitations of dynamic linker. Some Python libraries -# reference the .so files relatively and so extracting only the .so files -# does not work, so we extract the entire parent directory of the .so files to a -# tempdir and then add that to sys.path. -tempdir = None -with zipfile.ZipFile(__loader__.archive) as z: - # any root so files or root directories that contain so files will be - # extracted to the tempdir so the linker load them, this minimizes the - # number of files that need to be extracted to a tempdir - extract_paths = {} - for member in z.infolist(): - if member.filename.endswith('.so'): - extract_paths[PurePath(member.filename).parts[0]] = member.filename - if extract_paths: - tempdir = tempfile.mkdtemp() + # Extract the shared libraries from the zip file into a temporary directory. + # This works around the limitations of dynamic linker. Some Python libraries + # reference the .so files relatively and so extracting only the .so files + # does not work, so we extract the entire parent directory of the .so files to a + # tempdir and then add that to sys.path. + tempdir = None + with zipfile.ZipFile(__loader__.archive) as z: + # any root so files or root directories that contain so files will be + # extracted to the tempdir so the linker load them, this minimizes the + # number of files that need to be extracted to a tempdir + extract_paths = {} for member in z.infolist(): - if not PurePath(member.filename).parts[0] in extract_paths.keys(): - continue - if member.is_dir(): - os.makedirs(os.path.join(tempdir, member.filename)) - else: - z.extract(member, tempdir) - sys.path.insert(0, tempdir) -try: - runpy._run_module_as_main("ENTRY_POINT", alter_argv=False) -finally: - if tempdir is not None: - shutil.rmtree(tempdir) + if member.filename.endswith('.so'): + extract_paths[PurePath(member.filename).parts[0]] = member.filename + if extract_paths: + tempdir = tempfile.mkdtemp() + for member in z.infolist(): + if not PurePath(member.filename).parts[0] in extract_paths.keys(): + continue + if member.is_dir(): + os.makedirs(os.path.join(tempdir, member.filename)) + else: + z.extract(member, tempdir) + sys.path.insert(0, tempdir) + try: + runpy._run_module_as_main("ENTRY_POINT", alter_argv=False) + finally: + if tempdir is not None: + shutil.rmtree(tempdir) + +if __name__ == "__main__": + _soong_main() |
