Skip to content

bpo-32637: Set sys.platform to "android" on Android#5288

Closed
vstinner wants to merge 2 commits intopython:masterfrom
vstinner:ifdef_android_platform
Closed

bpo-32637: Set sys.platform to "android" on Android#5288
vstinner wants to merge 2 commits intopython:masterfrom
vstinner:ifdef_android_platform

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Jan 23, 2018

@vstinner
Copy link
Member Author

I abandoned my previous attempt to modify MACHDEP in configure: PR #5287.

@pmp-p
Copy link
Contributor

pmp-p commented Jan 24, 2018

Great, it works on arm7. And anyway MACHDEP won't help for loading android abi flavor of modules.

@vstinner
Copy link
Member Author

And anyway MACHDEP won't help for load android abi flavor of modules.

Note: While checking how MACHDEP is used, I found deadcode. I proposed a PR to remove it: PR #5289.

I don't know well the "multiarch" thing and I'm not confortable with autotools, so I chose to write this minimalist and self-contained change which only impacts sys.platform.

@pmp-p
Copy link
Contributor

pmp-p commented Jan 24, 2018

good effects, now instead of tring to load _sysconfigdata_dm/m_linux_.py it seeks for _sysconfigdata_dm/m_android_.py, which allows the two flavors to coexist nicely. Maybe now need code to generate multiarch ( api / cpu / bitness ) infos and store them in that file so modules build tools can use those. ( i see that ANDROID_API_LEVEL is already there )

@yan12125
Copy link
Contributor

Most likely at least MACHDEP should be modified, too.

>>> sysconfig.get_config_var('CFLAGS')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/data/local/tmp/python3/usr/lib/python3.7/sysconfig.py", line 595, in get_config_var
    return get_config_vars().get(name)
  File "/data/local/tmp/python3/usr/lib/python3.7/sysconfig.py", line 544, in get_config_vars
    _init_posix(_CONFIG_VARS)
  File "/data/local/tmp/python3/usr/lib/python3.7/sysconfig.py", line 415, in _init_posix
    _temp = __import__(name, globals(), locals(), ['build_time_vars'], 0)
ModuleNotFoundError: No module named '_sysconfigdata_m_android_'

In my build tree, there's build/target/python/usr/lib/python3.7/_sysconfigdata_m_linux_.py but no build/target/python/usr/lib/python3.7/_sysconfigdata_m_android_.py. If I understand the build process correctly, _sysconfigdata file is generated via $(PYTHON_FOR_BUILD) -S -m sysconfig --generate-posix-vars call in Makefile.pre.in, and PYTHON_FOR_BUILD uses MACHDEP via _PYTHON_SYSCONFIGDATA_NAME:

PYTHON_FOR_BUILD='_PYTHON_PROJECT_BASE=$(abs_builddir) _PYTHON_HOST_PLATFORM=$(_PYTHON_HOST_PLATFORM) PYTHONPATH=$(shell test -f pybuilddir.txt && echo $(abs_builddir)/`cat pybuilddir.txt`:)$(srcdir)/Lib _PYTHON_SYSCONFIGDATA_NAME=_sysconfigdata_$(ABIFLAGS)_$(MACHDEP)_$(MULTIARCH) '$interp

Note that this is tested with my building scripts at https://github.com/yan12125/python3-android/ using NDK r16b, not xdegaye's scripts. I tested ARM64, android-21 API on my ASUS ZE500KL phone.

@pmp-p
Copy link
Contributor

pmp-p commented Jan 26, 2018

@yan12125 i suggest to build sysconfigdata_m_android.py from a template as most of collected data in that file is only efficient for pip and setuptools when referencing a native compiler. If you look at the generated_sysconfigdata_m_linux_.py when cross compiled : it is full of reference to $HOST not $TARGET.

@vstinner vstinner closed this Feb 1, 2018
@vstinner vstinner deleted the ifdef_android_platform branch May 29, 2018 22:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants