Buildroot Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [RFC PATCH 1/1] package/pkg-generic.mk: introduce pre/post target finalize hooks
@ 2024-08-03 17:38 James Knight
  2024-08-03 20:57 ` Thomas Petazzoni via buildroot
  0 siblings, 1 reply; 3+ messages in thread
From: James Knight @ 2024-08-03 17:38 UTC (permalink / raw)
  To: buildroot; +Cc: James Knight, Thomas Petazzoni

Provides the ability for packages to register hooks in the finalization
process before and after Buildroot performs its own final target
changes. The pre-hook (`LIBFOO_TARGET_PRE_FINALIZE_HOOKS`) operates in
the same manner as `LIBFOO_TARGET_FINALIZE_HOOKS` did before. The newly
added post-hook (`LIBFOO_TARGET_POST_FINALIZE_HOOKS`) allows packages
to perform target modifications after Buildroot applies changes such as
rootfs overlay updates.

Signed-off-by: James Knight <james.d.knight@live.com>
---
The following is a proposal for adding support for post-finalize hooks
into the Buildroot framework. Been playing with using external package
definitions to perform some post-build tweaks to some board
configurations. While post-build scripts are a great way to perform any
late-stage target manipulation, it would be nice to be able to define
packages and register them into the menu system to make it easier to
re-use shared tweaks across multiple board configuration (versus trying
to add/stack post-build script paths into each configuration).

While `LIBFOO_TARGET_FINALIZE_HOOKS` worked for most cases, this occurs
before Buildroot performs additional finalization changes (e.g. merged
usr/). It would be nice to allow packages to perform their own
finalization changes after Buildroot does the bulk of it's own
finalization, but before post-build scripts are invoked.

If this change is considered, it appears the `luarocks.mk` package would
also need to be updated (in addition to manual changes).
---
 Makefile               | 7 +++++--
 package/pkg-generic.mk | 5 ++++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/Makefile b/Makefile
index f51e8f690fcb208c021b8169cd9db287d1e3e0ec..d97b5d7e492b8a4ba29103ba4ba6fbfeec1775d3 100644
--- a/Makefile
+++ b/Makefile
@@ -668,7 +668,7 @@ define GENERATE_GLIBC_LOCALES
 		LOCALES="$(GLIBC_GENERATE_LOCALES)" \
 		Q=$(Q)
 endef
-TARGET_FINALIZE_HOOKS += GENERATE_GLIBC_LOCALES
+TARGET_PRE_FINALIZE_HOOKS += GENERATE_GLIBC_LOCALES
 endif
 endif
 
@@ -706,7 +706,7 @@ define PURGE_LOCALES
 		done > $(TARGET_DIR)/usr/share/X11/locale/locale.dir; \
 	fi
 endef
-TARGET_FINALIZE_HOOKS += PURGE_LOCALES
+TARGET_PRE_FINALIZE_HOOKS += PURGE_LOCALES
 endif
 
 $(TARGETS_ROOTFS): target-finalize
@@ -731,6 +731,7 @@ target-finalize: $(PACKAGES) $(TARGET_DIR) host-finalize
 	@$(call MESSAGE,"Finalizing target directory")
 	$(call per-package-rsync,$(sort $(PACKAGES)),target,$(TARGET_DIR),copy)
 	$(foreach hook,$(TARGET_FINALIZE_HOOKS),$($(hook))$(sep))
+	$(foreach hook,$(TARGET_PRE_FINALIZE_HOOKS),$($(hook))$(sep))
 	rm -rf $(TARGET_DIR)/usr/include $(TARGET_DIR)/usr/share/aclocal \
 		$(TARGET_DIR)/usr/lib/pkgconfig $(TARGET_DIR)/usr/share/pkgconfig \
 		$(TARGET_DIR)/usr/lib/cmake $(TARGET_DIR)/usr/share/cmake \
@@ -798,6 +799,8 @@ endif # merged /usr
 		@$(call MESSAGE,"Copying overlay $(d)")$(sep) \
 		$(Q)$(call SYSTEM_RSYNC,$(d),$(TARGET_DIR))$(sep))
 
+	$(foreach hook,$(TARGET_POST_FINALIZE_HOOKS),$($(hook))$(sep))
+
 	$(Q)$(if $(TARGET_DIR_FILES_LISTS), \
 		cat $(TARGET_DIR_FILES_LISTS)) > $(BUILD_DIR)/packages-file-list.txt
 	$(Q)$(if $(HOST_DIR_FILES_LISTS), \
diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
index 171163dcb4401683bf2b8c7751fe261efa811081..17ddfcc4084ef522c693115623e20e14f5574fcb 100644
--- a/package/pkg-generic.mk
+++ b/package/pkg-generic.mk
@@ -1240,7 +1240,10 @@ endif
 ifneq ($$($(2)_LINUX_CONFIG_FIXUPS),)
 PACKAGES_LINUX_CONFIG_FIXUPS += $$($(2)_LINUX_CONFIG_FIXUPS)$$(sep)
 endif
-TARGET_FINALIZE_HOOKS += $$($(2)_TARGET_FINALIZE_HOOKS)
+# note: 'LIBFOO_TARGET_FINALIZE_HOOKS' deprecated
+TARGET_PRE_FINALIZE_HOOKS += $$($(2)_TARGET_FINALIZE_HOOKS)   
+TARGET_PRE_FINALIZE_HOOKS += $$($(2)_TARGET_PRE_FINALIZE_HOOKS)
+TARGET_POST_FINALIZE_HOOKS += $$($(2)_TARGET_POST_FINALIZE_HOOKS)
 ROOTFS_PRE_CMD_HOOKS += $$($(2)_ROOTFS_PRE_CMD_HOOKS)
 KEEP_PYTHON_PY_FILES += $$($(2)_KEEP_PY_FILES)
 
-- 
2.43.0.windows.1

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-08-04  2:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-03 17:38 [Buildroot] [RFC PATCH 1/1] package/pkg-generic.mk: introduce pre/post target finalize hooks James Knight
2024-08-03 20:57 ` Thomas Petazzoni via buildroot
2024-08-04  2:04   ` James Knight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox