[OpenWrt-Devel] [PATCH 1/6] build: Add auto file tracking / uninstall for Host/Install

Jeffery To jeffery.to at gmail.com
Fri Jun 14 14:35:29 EDT 2019


This adds automatic file tracking and uninstallation (similar to that
for Build/InstallDev) for files installed by Host/Install.

A path to a staging directory will be passed to Host/Install. If files
are placed in that staging directory, they will be tracked and installed
into $(HOST_BUILD_PREFIX) (either $(STAGING_DIR_HOST) or
$(STAGING_DIR_HOSTPKG), depend on the package/tool).

If Host/Install doesn't use the staging directory and install to
$(STAGING_DIR_HOST) / $(STAGING_DIR_HOSTPKG) directly, no error is
raised.

This also updates Host/Install/Default to handle the staging directory,
combined with setting DESTDIR in a new HOST_MAKE_INSTALL_FLAGS variable.

Host/Install/Default now also handles a second parameter, allowing a
different install target to be specified (similar to
Build/Install/Default).

Signed-off-by: Jeffery To <jeffery.to at gmail.com>
---
 include/host-build.mk | 52 ++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 47 insertions(+), 5 deletions(-)

diff --git a/include/host-build.mk b/include/host-build.mk
index 827ea6bbfb..ce2fcc26eb 100644
--- a/include/host-build.mk
+++ b/include/host-build.mk
@@ -30,6 +30,20 @@ HOST_STAMP_BUILT:=$(HOST_BUILD_DIR)/.built
 HOST_BUILD_PREFIX?=$(if $(IS_PACKAGE_BUILD),$(STAGING_DIR_HOSTPKG),$(STAGING_DIR_HOST))
 HOST_STAMP_INSTALLED:=$(HOST_BUILD_PREFIX)/stamp/.$(PKG_NAME)_installed
 
+HOST_STAGING_FILES_LIST:=$(PKG_NAME).list
+HOST_STAGING_DIR:=$(TMP_DIR)/$(if $(IS_PACKAGE_BUILD),hostpkg,host)-stage-$(PKG_NAME)
+
+define HostCleanStaging
+	rm -f $(HOST_STAMP_INSTALLED)
+	@-(\
+		if [ -f $(HOST_BUILD_PREFIX)/packages/$(HOST_STAGING_FILES_LIST) ]; then \
+			$(SCRIPT_DIR)/clean-package.sh \
+				"$(HOST_BUILD_PREFIX)/packages/$(HOST_STAGING_FILES_LIST)" \
+				"$(HOST_BUILD_PREFIX)"; \
+		fi; \
+	)
+endef
+
 override MAKEFLAGS=
 
 include $(INCLUDE_DIR)/autotools.mk
@@ -77,6 +91,10 @@ HOST_MAKE_VARS = \
 
 HOST_MAKE_FLAGS =
 
+HOST_MAKE_INSTALL_FLAGS = \
+	$(HOST_MAKE_FLAGS) \
+	DESTDIR="$(HOST_INSTALL_DIR)"
+
 HOST_CONFIGURE_CMD = $(BASH) ./configure
 
 ifeq ($(HOST_OS),Darwin)
@@ -112,11 +130,17 @@ define Host/Compile
 endef
 
 define Host/Install/Default
-	$(call Host/Compile/Default,install)
+	+$(HOST_MAKE_VARS) \
+	$(MAKE) $(HOST_JOBS) -C $(HOST_BUILD_DIR) \
+		$(HOST_MAKE_INSTALL_FLAGS) \
+		$(if $(2),$(2),install)
+	$(if $(1),
+		$(CP) $(HOST_INSTALL_DIR)/$(HOST_BUILD_PREFIX)/* $(1)/
+	)
 endef
 
 define Host/Install
-  $(call Host/Install/Default,$(HOST_BUILD_PREFIX))
+  $(call Host/Install/Default,$(1),)
 endef
 
 
@@ -169,8 +193,25 @@ ifndef DUMP
 
   $(call Host/Exports,$(HOST_STAMP_INSTALLED))
   $(HOST_STAMP_INSTALLED): $(HOST_STAMP_BUILT) $(if $(FORCE_HOST_INSTALL),FORCE)
-		$(call Host/Install,$(HOST_BUILD_PREFIX))
-		$(foreach hook,$(Hooks/HostInstall/Post),$(call $(hook))$(sep))
+		rm -rf $(HOST_STAGING_DIR)
+		mkdir -p $(HOST_STAGING_DIR) $(HOST_BUILD_PREFIX)/packages
+		$(call Host/Install,$(HOST_STAGING_DIR))
+		$(foreach hook,$(Hooks/HostInstall/Post),\
+			$(call $(hook),$(HOST_STAGING_DIR))$(sep)\
+		)
+		if [ -f $(HOST_BUILD_PREFIX)/packages/$(HOST_STAGING_FILES_LIST) ]; then \
+			$(SCRIPT_DIR)/clean-package.sh \
+				"$(HOST_BUILD_PREFIX)/packages/$(HOST_STAGING_FILES_LIST)" \
+				"$(HOST_BUILD_PREFIX)"; \
+		fi
+		if [ -z "$$$$(find $(HOST_STAGING_DIR) -maxdepth 0 -type d -empty)" ]; then \
+			(cd $(HOST_STAGING_DIR); find ./ > $(HOST_STAGING_DIR).files); \
+			$(call locked, \
+				mv $(HOST_STAGING_DIR).files $(HOST_BUILD_PREFIX)/packages/$(HOST_STAGING_FILES_LIST) && \
+				$(CP) $(HOST_STAGING_DIR)/* $(HOST_BUILD_PREFIX)/ \
+			,host-staging-dir); \
+		fi
+		rm -rf $(HOST_STAGING_DIR)
 		mkdir -p $$(shell dirname $$@)
 		touch $(HOST_STAMP_BUILT)
 		touch $$@
@@ -193,9 +234,10 @@ ifndef DUMP
 	rm -rf $(HOST_BUILD_DIR) $(HOST_STAMP_BUILT)
 
   host-clean: host-clean-build
+	$(HostCleanStaging)
 	$(call Host/Clean)
 	$(call Host/Uninstall)
-	rm -rf $(HOST_STAMP_INSTALLED)
+	rm -f $(HOST_BUILD_PREFIX)/packages/$(HOST_STAGING_FILES_LIST)
 
     ifneq ($(CONFIG_AUTOREMOVE),)
       host-compile:
-- 
2.20.1


_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel



More information about the openwrt-devel mailing list