[Buildroot] [PATCH 1/2] target-finalize: generate all *.pyc

Samuel Martin s.martin49 at gmail.com
Mon Mar 9 21:30:02 UTC 2015

Hi Thomas, all,

On Mon, Mar 9, 2015 at 6:54 PM, Thomas Petazzoni
<thomas.petazzoni at free-electrons.com> wrote:
> Dear Samuel Martin,
> On Mon,  9 Mar 2015 17:24:23 +0100, Samuel Martin wrote:
>> This patch generates all *.pyc files from *.py located in
>> <target>/usr/python*/site-packages, before stripping the rootfs.
>> This prevents modules from packages that do not compile the *.py
>> files from disappearing.
>> Reported-by: Yegor Yefremov <yegorslists at googlemail.com>
>> Cc: Yegor Yefremov <yegorslists at googlemail.com>
>> Signed-off-by: Samuel Martin <s.martin49 at gmail.com>
>> ---
>>  Makefile | 5 +++++
>>  1 file changed, 5 insertions(+)
>> diff --git a/Makefile b/Makefile
>> index af043a3..ec0b923 100644
>> --- a/Makefile
>> +++ b/Makefile
>> @@ -564,6 +564,11 @@ $(TARGETS_ROOTFS): target-finalize
>>  target-finalize: $(TARGETS)
>>       @$(call MESSAGE,"Finalizing target directory")
>> +             $(HOST_DIR)/usr/bin/python -c "import compileall; \
>> +                     compileall.compile_dir('$(TARGET_DIR)/usr/lib/python$(PYTHON_VERSION_MAJOR)/site-packages')"
>> +endif
> Why not, but then don't we want to do something in the Python package
> infra, and in the Python 2/3 packages themselves to avoid spending time
> biulding the .pyc files?

Indeed, it'd be better to avoid  wasting time building *.pyc during
per-package build, though it does not seem really easy to do at first
Well, after hacking around, it is not that hard to do it! :-)
I cleanup my hacks and will submit them.

> Also, using TARGET_FINALIZE_HOOKS would be nicer. But there is the
> issue that the hook is the same between python and python3, so we
> wouldn't know where to put it.

The hook is simple enough to be moved in pkg-python.mk as a helper,
then just being added to the PYTHON{,3}_TARGET_FINALIZE_HOOKS.

However, if we decide to not go using a global TARGET_FINALIZE_HOOKS,
but per-package target-install hook, the helper can be easily added to
the packages that need it; the biggest remaining task being
identifying and updating all packages not using the pkg-python infra
but providing a python module.



More information about the buildroot mailing list