summaryrefslogtreecommitdiffstats
path: root/meta/classes-recipe/rootfs-postcommands.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes-recipe/rootfs-postcommands.bbclass')
-rw-r--r--meta/classes-recipe/rootfs-postcommands.bbclass24
1 files changed, 24 insertions, 0 deletions
diff --git a/meta/classes-recipe/rootfs-postcommands.bbclass b/meta/classes-recipe/rootfs-postcommands.bbclass
index 690fa976aae..3b4d219417f 100644
--- a/meta/classes-recipe/rootfs-postcommands.bbclass
+++ b/meta/classes-recipe/rootfs-postcommands.bbclass
@@ -25,6 +25,9 @@ ROOTFS_POSTPROCESS_COMMAND += "rootfs_update_timestamp; "
# Tweak files in /etc if read-only-rootfs is enabled
ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "read-only-rootfs", "read_only_rootfs_hook; ", "",d)}'
+# Leave only pyc if pyc-only is enabled
+ROOTFS_POSTPROCESS_COMMAND += '${@bb.utils.contains("IMAGE_FEATURES", "pyc-only", "pyc_only_hook; ", "",d)}'
+
# We also need to do the same for the kernel boot parameters,
# otherwise kernel or initramfs end up mounting the rootfs read/write
# (the default) if supported by the underlying storage.
@@ -151,6 +154,27 @@ read_only_rootfs_hook () {
fi
}
+
+inherit python3native
+pyc_only_hook () {
+ # Create pyc files
+ nativepython3 \
+ ${COREBASE}/scripts/contrib/pycompile.py \
+ --verbose \
+ --strip-root ${IMAGE_ROOTFS} \
+ ${IMAGE_ROOTFS}${libdir}/${PYTHON_DIR}
+
+ # Remove py files
+ find ${IMAGE_ROOTFS}${libdir}/${PYTHON_DIR} -name '*.py' \
+ -print0 | \
+ xargs -0 --no-run-if-empty rm -f
+
+ # Remove pycache files
+ find ${IMAGE_ROOTFS}${libdir}/${PYTHON_DIR} -name '__pycache__' \
+ -print0 | \
+ xargs -0 --no-run-if-empty rm -rf
+}
+
#
# This function disallows empty root passwords
#