Patchwork Add support for custom package patches

login
register
mail settings
Submitter Simon Dawson
Date Oct. 30, 2012, 9:23 p.m.
Message ID <1351632205-15815-1-git-send-email-spdawson@gmail.com>
Download mbox | patch
Permalink /patch/195629/
State Superseded
Headers show

Comments

Simon Dawson - Oct. 30, 2012, 9:23 p.m.
From: Simon Dawson <spdawson@gmail.com>

Add a configuration item to allow a space-separated list of directories
to be specified, from which custom package patches will be applied.

Signed-off-by: Simon Dawson <spdawson@gmail.com>
---
 Config.in              |    7 +++++++
 package/pkg-generic.mk |   28 ++++++++++++++++------------
 2 files changed, 23 insertions(+), 12 deletions(-)
Arnout Vandecappelle - Oct. 30, 2012, 9:43 p.m.
On 10/30/12 22:23, spdawson@gmail.com wrote:
> From: Simon Dawson<spdawson@gmail.com>
>
> Add a configuration item to allow a space-separated list of directories
> to be specified, from which custom package patches will be applied.

  Good idea!

>
> Signed-off-by: Simon Dawson<spdawson@gmail.com>

Acked-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
but some potential improvements below.

> ---
>   Config.in              |    7 +++++++
>   package/pkg-generic.mk |   28 ++++++++++++++++------------
>   2 files changed, 23 insertions(+), 12 deletions(-)
>
> diff --git a/Config.in b/Config.in
> index dab7787..13a7daf 100644
> --- a/Config.in
> +++ b/Config.in
> @@ -415,6 +415,13 @@ config BR2_PACKAGE_OVERRIDE_FILE
>   	  as the source directory for a particular package. See the
>   	  Buildroot documentation for more details on this feature.
>
> +config BR2_CUSTOM_PACKAGE_PATCH_DIRS
> +	string "custom package patch directories"

  I would call it extra patch dirs, otherwise it sounds like it's overriding
the BR patch set.

> +	help
> +	  You may specify a space-separated list of directories containing
> +	  custom package patches. Note that any custom patches for a package
> +	  will be applied AFTER the Buildroot patch set for the package.
> +
>   endmenu
>
>   source "toolchain/Config.in"
> diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
> index 270da60..d77662e 100644
> --- a/package/pkg-generic.mk
> +++ b/package/pkg-generic.mk
> @@ -69,6 +69,20 @@ else
>   	@true # Nothing to do to source a local package
>   endif
>
> +# Apply package patches from the specified directory
> +define pkg-apply-patch-directory
> +	if test -d $(1); then \
> +	  if test "$(wildcard $(1)/$(NAMEVER)*.patch*)"; then \
> +	    support/scripts/apply-patches.sh $(@D) $(1) $(NAMEVER)\*.patch $(NAMEVER)\*.patch.$(ARCH) || exit 1; \
> +	  else \
> +	    support/scripts/apply-patches.sh $(@D) $(1) $(RAWNAME)\*.patch $(RAWNAME)\*.patch.$(ARCH) || exit 1; \
> +	    if test -d $(1)/$(NAMEVER); then \
> +	      support/scripts/apply-patches.sh $(@D) $(1)/$(NAMEVER) \*.patch \*.patch.$(ARCH) || exit 1; \

  For the custom patch dirs, we may also want to support the
$(1)/$(RAWNAME)/*.patch pattern.  So that would give:

	    elif test -d $(1)/$(RAWNAME); then \
	      support/scripts/apply-patches.sh $(@D) $(1)/$(RAWNAME) \*.patch \*.patch.$(ARCH) || exit 1; \

  We should also get rid of the patch.$(ARCH) pattern, but that's
a separate issue.

> +	    fi; \
> +	  fi; \
> +	fi;
> +endef
> +
>   # Patch
>   #
>   # The RAWNAME variable is the lowercased package name, which allows to
> @@ -79,18 +93,8 @@ $(BUILD_DIR)/%/.stamp_patched:
>   	@$(call MESSAGE,"Patching $($(PKG)_DIR_PREFIX)/$(RAWNAME)")
>   	$(foreach hook,$($(PKG)_PRE_PATCH_HOOKS),$(call $(hook))$(sep))
>   	$(if $($(PKG)_PATCH),support/scripts/apply-patches.sh $(@D) $(DL_DIR) $($(PKG)_PATCH))
> -	$(Q)( \
> -	if test -d $($(PKG)_DIR_PREFIX)/$(RAWNAME); then \
> -	  if test "$(wildcard $($(PKG)_DIR_PREFIX)/$(RAWNAME)/$(NAMEVER)*.patch*)"; then \
> -	    support/scripts/apply-patches.sh $(@D) $($(PKG)_DIR_PREFIX)/$(RAWNAME) $(NAMEVER)\*.patch $(NAMEVER)\*.patch.$(ARCH) || exit 1; \
> -	  else \
> -	    support/scripts/apply-patches.sh $(@D) $($(PKG)_DIR_PREFIX)/$(RAWNAME) $(RAWNAME)\*.patch $(RAWNAME)\*.patch.$(ARCH) || exit 1; \
> -	    if test -d $($(PKG)_DIR_PREFIX)/$(RAWNAME)/$(NAMEVER); then \
> -	      support/scripts/apply-patches.sh $(@D) $($(PKG)_DIR_PREFIX)/$(RAWNAME)/$(NAMEVER) \*.patch \*.patch.$(ARCH) || exit 1; \
> -	    fi; \
> -	  fi; \
> -	fi; \
> -	)
> +	$(Q)($(call pkg-apply-patch-directory,$($(PKG)_DIR_PREFIX)/$(RAWNAME)))
> +	$(Q)($(foreach	patchdir,$(call qstrip,$(BR2_CUSTOM_PACKAGE_PATCH_DIRS)),$(call pkg-apply-patch-directory,$(patchdir))))

  This actually looks a lot nicer!

>   	$(foreach hook,$($(PKG)_POST_PATCH_HOOKS),$(call $(hook))$(sep))
>   	$(Q)touch $@
>

  Regards,
  Arnout
Simon Dawson - Oct. 31, 2012, 7:43 a.m.
On 30 October 2012 21:43, Arnout Vandecappelle <arnout@mind.be> wrote:
> Acked-by: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
> but some potential improvements below.

Hi Arnout. Thanks for the feedback.

>> +config BR2_CUSTOM_PACKAGE_PATCH_DIRS
>> +       string "custom package patch directories"
>
>
>  I would call it extra patch dirs, otherwise it sounds like it's overriding
> the BR patch set.

Yes, agreed.

>  For the custom patch dirs, we may also want to support the
> $(1)/$(RAWNAME)/*.patch pattern.  So that would give:
>
>             elif test -d $(1)/$(RAWNAME); then \
>               support/scripts/apply-patches.sh $(@D) $(1)/$(RAWNAME)
> \*.patch \*.patch.$(ARCH) || exit 1; \

Yes, good idea.

I'll fix my patch, and resubmit.

Simon.

Patch

diff --git a/Config.in b/Config.in
index dab7787..13a7daf 100644
--- a/Config.in
+++ b/Config.in
@@ -415,6 +415,13 @@  config BR2_PACKAGE_OVERRIDE_FILE
 	  as the source directory for a particular package. See the
 	  Buildroot documentation for more details on this feature.
 
+config BR2_CUSTOM_PACKAGE_PATCH_DIRS
+	string "custom package patch directories"
+	help
+	  You may specify a space-separated list of directories containing
+	  custom package patches. Note that any custom patches for a package
+	  will be applied AFTER the Buildroot patch set for the package.
+
 endmenu
 
 source "toolchain/Config.in"
diff --git a/package/pkg-generic.mk b/package/pkg-generic.mk
index 270da60..d77662e 100644
--- a/package/pkg-generic.mk
+++ b/package/pkg-generic.mk
@@ -69,6 +69,20 @@  else
 	@true # Nothing to do to source a local package
 endif
 
+# Apply package patches from the specified directory
+define pkg-apply-patch-directory
+	if test -d $(1); then \
+	  if test "$(wildcard $(1)/$(NAMEVER)*.patch*)"; then \
+	    support/scripts/apply-patches.sh $(@D) $(1) $(NAMEVER)\*.patch $(NAMEVER)\*.patch.$(ARCH) || exit 1; \
+	  else \
+	    support/scripts/apply-patches.sh $(@D) $(1) $(RAWNAME)\*.patch $(RAWNAME)\*.patch.$(ARCH) || exit 1; \
+	    if test -d $(1)/$(NAMEVER); then \
+	      support/scripts/apply-patches.sh $(@D) $(1)/$(NAMEVER) \*.patch \*.patch.$(ARCH) || exit 1; \
+	    fi; \
+	  fi; \
+	fi;
+endef
+
 # Patch
 #
 # The RAWNAME variable is the lowercased package name, which allows to
@@ -79,18 +93,8 @@  $(BUILD_DIR)/%/.stamp_patched:
 	@$(call MESSAGE,"Patching $($(PKG)_DIR_PREFIX)/$(RAWNAME)")
 	$(foreach hook,$($(PKG)_PRE_PATCH_HOOKS),$(call $(hook))$(sep))
 	$(if $($(PKG)_PATCH),support/scripts/apply-patches.sh $(@D) $(DL_DIR) $($(PKG)_PATCH))
-	$(Q)( \
-	if test -d $($(PKG)_DIR_PREFIX)/$(RAWNAME); then \
-	  if test "$(wildcard $($(PKG)_DIR_PREFIX)/$(RAWNAME)/$(NAMEVER)*.patch*)"; then \
-	    support/scripts/apply-patches.sh $(@D) $($(PKG)_DIR_PREFIX)/$(RAWNAME) $(NAMEVER)\*.patch $(NAMEVER)\*.patch.$(ARCH) || exit 1; \
-	  else \
-	    support/scripts/apply-patches.sh $(@D) $($(PKG)_DIR_PREFIX)/$(RAWNAME) $(RAWNAME)\*.patch $(RAWNAME)\*.patch.$(ARCH) || exit 1; \
-	    if test -d $($(PKG)_DIR_PREFIX)/$(RAWNAME)/$(NAMEVER); then \
-	      support/scripts/apply-patches.sh $(@D) $($(PKG)_DIR_PREFIX)/$(RAWNAME)/$(NAMEVER) \*.patch \*.patch.$(ARCH) || exit 1; \
-	    fi; \
-	  fi; \
-	fi; \
-	)
+	$(Q)($(call pkg-apply-patch-directory,$($(PKG)_DIR_PREFIX)/$(RAWNAME)))
+	$(Q)($(foreach	patchdir,$(call qstrip,$(BR2_CUSTOM_PACKAGE_PATCH_DIRS)),$(call pkg-apply-patch-directory,$(patchdir))))
 	$(foreach hook,$($(PKG)_POST_PATCH_HOOKS),$(call $(hook))$(sep))
 	$(Q)touch $@