Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-131531: android.py enhancements to support cibuildwheel#132870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
Changes from1 commit
71cccb3
e3d27ac
6156255
24b082f
b7461d3
c7cdb98
f29e177
fc8c1e1
b273bc7
9c46ab0
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
android.py env
command- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -22,9 +22,13 @@ | ||||||
SCRIPT_NAME = Path(__file__).name | ||||||
ANDROID_DIR = Path(__file__).resolve().parent | ||||||
PYTHON_DIR = ANDROID_DIR.parent | ||||||
in_source_tree = ( | ||||||
ANDROID_DIR.name == "Android" and (PYTHON_DIR / "pyconfig.h.in").exists() | ||||||
) | ||||||
TESTBED_DIR = ANDROID_DIR / "testbed" | ||||||
CROSS_BUILD_DIR =PYTHON_DIR / "cross-build" | ||||||
HOSTS = ["aarch64-linux-android", "x86_64-linux-android"] | ||||||
APP_ID = "org.python.testbed" | ||||||
@@ -74,41 +78,62 @@ def subdir(*parts, create=False): | ||||||
def run(command, *, host=None, env=None, log=True, **kwargs): | ||||||
kwargs.setdefault("check", True) | ||||||
if env is None: | ||||||
env = os.environ.copy() | ||||||
if host: | ||||||
env.update(android_env(host)) | ||||||
if log: | ||||||
print(">", " ".join(map(str, command))) | ||||||
return subprocess.run(command, env=env, **kwargs) | ||||||
def print_env(context): | ||||||
android_env(getattr(context, "host", None)) | ||||||
def android_env(host): | ||||||
if host: | ||||||
prefix = subdir(host) / "prefix" | ||||||
else: | ||||||
prefix = ANDROID_DIR / "prefix" | ||||||
sysconfigdata_files = prefix.glob("lib/python*/_sysconfigdata__android_*.py") | ||||||
host = re.fullmatch( | ||||||
r"_sysconfigdata__android_(.+).py", next(sysconfigdata_files).name | ||||||
)[1] | ||||||
AA-Turner marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||||||
env_script = ANDROID_DIR / "android-env.sh" | ||||||
env_output = subprocess.run( | ||||||
f"set -eu; " | ||||||
f"export HOST={host}; " | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Is there a reason this has become a full export? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. I'm also using it in the cibuildwheel PR to set | ||||||
f"PREFIX={prefix}; " | ||||||
f". {env_script}; " | ||||||
f"export", | ||||||
check=True, shell=True, capture_output=True, text=True, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Is there a way to avoid Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. In this case the whole point of the code is to run a shell script and determine which environment variables it sets, so
Thanks, fixed. | ||||||
).stdout | ||||||
env = {} | ||||||
for line in env_output.splitlines(): | ||||||
# We don't require every line to match, as there may be some other | ||||||
# output from installing the NDK. | ||||||
if match := re.search( | ||||||
"^(declare -x |export )?(\\w+)=['\"]?(.*?)['\"]?$", line | ||||||
): | ||||||
key, value = match[2], match[3] | ||||||
if os.environ.get(key) != value: | ||||||
env[key] = value | ||||||
mhsmith marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||||||
if not env: | ||||||
raise ValueError(f"Found no variables in {env_script.name} output:\n" | ||||||
+ env_output) | ||||||
# Format the environment so it can be pasted into a shell. | ||||||
for key, value in sorted(env.items()): | ||||||
print(f"export {key}={shlex.quote(value)}") | ||||||
return env | ||||||
def build_python_path(): | ||||||
"""The path to the build Python binary.""" | ||||||
build_dir = subdir("build") | ||||||
@@ -127,7 +152,7 @@ def configure_build_python(context): | ||||||
clean("build") | ||||||
os.chdir(subdir("build", create=True)) | ||||||
command = [relpath(PYTHON_DIR / "configure")] | ||||||
if context.args: | ||||||
command.extend(context.args) | ||||||
run(command) | ||||||
@@ -168,7 +193,7 @@ def configure_host_python(context): | ||||||
os.chdir(host_dir) | ||||||
command = [ | ||||||
# Basic cross-compiling configuration | ||||||
relpath(PYTHON_DIR / "configure"), | ||||||
f"--host={context.host}", | ||||||
f"--build={sysconfig.get_config_var('BUILD_GNU_TYPE')}", | ||||||
f"--with-build-python={build_python_path()}", | ||||||
@@ -624,8 +649,7 @@ def parse_args(): | ||||||
configure_build = subcommands.add_parser("configure-build", | ||||||
help="Run `configure` for the " | ||||||
"build Python") | ||||||
subcommands.add_parser("make-build", help="Run `make` for the build Python") | ||||||
configure_host = subcommands.add_parser("configure-host", | ||||||
help="Run `configure` for Android") | ||||||
make_host = subcommands.add_parser("make-host", | ||||||
@@ -637,16 +661,22 @@ def parse_args(): | ||||||
test = subcommands.add_parser( | ||||||
"test", help="Run the test suite") | ||||||
package = subcommands.add_parser("package", help="Make a release package") | ||||||
env = subcommands.add_parser("env", help="Print environment variables") | ||||||
# Common arguments | ||||||
for subcommand in build, configure_build, configure_host: | ||||||
subcommand.add_argument( | ||||||
"--clean", action="store_true", default=False, dest="clean", | ||||||
help="Delete the relevant build and prefix directories first") | ||||||
host_commands = [build, configure_host, make_host, package] | ||||||
if in_source_tree: | ||||||
host_commands.append(env) | ||||||
for subcommand in host_commands: | ||||||
subcommand.add_argument( | ||||||
"host", metavar="HOST", choices=HOSTS, | ||||||
help="Host triplet: choices=[%(choices)s]") | ||||||
for subcommand in build, configure_build, configure_host: | ||||||
subcommand.add_argument("args", nargs="*", | ||||||
help="Extra arguments to pass to `configure`") | ||||||
@@ -690,6 +720,7 @@ def main(): | ||||||
"build-testbed": build_testbed, | ||||||
"test": run_testbed, | ||||||
"package": package, | ||||||
"env": print_env, | ||||||
} | ||||||
try: | ||||||
Uh oh!
There was an error while loading.Please reload this page.