[3.13] gh-116622: Fix testPyObjectPrintOSError on Android (GH-122487)… · python/cpython@5212624

GitHub

GitHub CopilotWrite better code with AI | MCP RegistryIntegrate external tools | ActionsAutomate any workflow | CodespacesInstant dev environments | IssuesPlan and track work | Code ReviewManage code changes | Code QualityEnforce quality at merge | Why GitHub | Marketplace | View all features | Enterprises | Small and medium teams | Startups | View all use cases | View all industries | View all solutions | AI | Software Development | DevOps | Security | View all topics | Customer stories | Events & webinars | Ebooks & reports | Business insights | Trust center | Partners | View all resources

@@ -1,6 +1,7 @@

11#!/usr/bin/env python3

2233importargparse

4+fromglobimportglob

45importos

56importre

67importshutil

@@ -16,16 +17,21 @@

1617CROSS_BUILD_DIR=CHECKOUT/"cross-build"

1718181919-defdelete_if_exists(path):

20-ifpath.exists():

20+defdelete_glob(pattern):

21+# Path.glob doesn't accept non-relative patterns.

22+forpathinglob(str(pattern)):

23+path=Path(path)

2124print(f"Deleting {path} ...")

22-shutil.rmtree(path)

25+ifpath.is_dir() andnotpath.is_symlink():

26+shutil.rmtree(path)

27+else:

28+path.unlink()

232924302531defsubdir(name, *, clean=None):

2632path=CROSS_BUILD_DIR/name

2733ifclean:

28-delete_if_exists(path)

34+delete_glob(path)

2935ifnotpath.exists():

3036ifcleanisNone:

3137sys.exit(

@@ -150,10 +156,17 @@ def configure_host_python(context):

150156151157152158defmake_host_python(context):

159+# The CFLAGS and LDFLAGS set in android-env include the prefix dir, so

160+# delete any previously-installed Python libs and include files to prevent

161+# them being used during the build.

153162host_dir=subdir(context.host)

163+prefix_dir=host_dir/"prefix"

164+delete_glob(f"{prefix_dir}/include/python*")

165+delete_glob(f"{prefix_dir}/lib/libpython*")

166+154167os.chdir(host_dir/"build")

155168run(["make", "-j", str(os.cpu_count())], host=context.host)

156-run(["make", "install", f"prefix={host_dir}/prefix"], host=context.host)

169+run(["make", "install", f"prefix={prefix_dir}"], host=context.host)

157170158171159172defbuild_all(context):

@@ -164,7 +177,7 @@ def build_all(context):

164177165178166179defclean_all(context):

167-delete_if_exists(CROSS_BUILD_DIR)

180+delete_glob(CROSS_BUILD_DIR)

168181169182170183# To avoid distributing compiled artifacts without corresponding source code,