| 141 | |
| 142 | |
| 143 | def android_env(host): |
| 144 | if host: |
| 145 | prefix = subdir(host) / "prefix" |
| 146 | else: |
| 147 | prefix = ANDROID_DIR / "prefix" |
| 148 | sysconfig_files = prefix.glob("lib/python*/_sysconfigdata__android_*.py") |
| 149 | sysconfig_filename = next(sysconfig_files).name |
| 150 | host = re.fullmatch(r"_sysconfigdata__android_(.+).py", sysconfig_filename)[1] |
| 151 | |
| 152 | env_output = subprocess.run( |
| 153 | f"set -eu; " |
| 154 | f"HOST={host}; " |
| 155 | f"PREFIX={prefix}; " |
| 156 | f". {ENV_SCRIPT}; " |
| 157 | f"export", |
| 158 | check=True, shell=True, capture_output=True, encoding='utf-8', |
| 159 | ).stdout |
| 160 | |
| 161 | env = {} |
| 162 | for line in env_output.splitlines(): |
| 163 | # We don't require every line to match, as there may be some other |
| 164 | # output from installing the NDK. |
| 165 | if match := re.search( |
| 166 | "^(declare -x |export )?(\\w+)=['\"]?(.*?)['\"]?$", line |
| 167 | ): |
| 168 | key, value = match[2], match[3] |
| 169 | if os.environ.get(key) != value: |
| 170 | env[key] = value |
| 171 | |
| 172 | if not env: |
| 173 | raise ValueError(f"Found no variables in {ENV_SCRIPT.name} output:\n" |
| 174 | + env_output) |
| 175 | return env |
| 176 | |
| 177 | |
| 178 | def build_python_path(): |