[openwrt/openwrt] build: refactor dependency formatting

LEDE Commits lede-commits at lists.infradead.org
Fri Jan 16 08:13:09 PST 2026


robimarko pushed a commit to openwrt/openwrt.git, branch openwrt-25.12:
https://git.openwrt.org/b4e537e9cd87f3b0ea605a35727d74cb14040811

commit b4e537e9cd87f3b0ea605a35727d74cb14040811
Author: George Sapkin <george at sapk.in>
AuthorDate: Sun Jan 4 03:46:38 2026 +0200

    build: refactor dependency formatting
    
    Refactor dependencies and extra dependencies logic into a helper define
    and document it.
    
    Signed-off-by: George Sapkin <george at sapk.in>
    Link: https://github.com/openwrt/openwrt/pull/21369
    (cherry picked from commit 779fa7ff6caa509d5df3827342162fdb07093cee)
    Link: https://github.com/openwrt/openwrt/pull/21547
    Signed-off-by: Robert Marko <robimarko at gmail.com>
---
 include/package-pack.mk | 80 ++++++++++++++++++++++++++++++-------------------
 1 file changed, 50 insertions(+), 30 deletions(-)

diff --git a/include/package-pack.mk b/include/package-pack.mk
index 84c21a95ba..94ad16dd6d 100644
--- a/include/package-pack.mk
+++ b/include/package-pack.mk
@@ -78,6 +78,55 @@ define FixupDependencies
   $(call AddDependency,$(1),$$(DEPS))
 endef
 
+# Format dependencies and extra dependencies
+#
+# ABI-version EXTRA_DEPENDS so dependencies can be correctly looked up using the
+# existing semantics without the ABI specified. This is needed since ABI-
+# versioned libraries don't provide `${package_name}=${package_version}`, so
+# that same library but with different ABI versions can be installed side by
+# side.
+#
+# Remove duplicate dependencies when EXTRA_DEPENDS specifies a versioned one
+# that is already in DEPENDS.
+#
+# 1: list of dependencies
+# 2: list of extra dependencies
+define FormatDepends
+$(strip
+  $(eval _COMMA_SEP := __COMMA_SEP__)
+  $(eval _SPACE_SEP := __SPACE_SEP__)
+  $(eval _DEPENDS := $(1))
+  $(eval _EXTRA_DEPENDS_ABI := )
+  $(eval _DEP_ITEMS := $(subst $(_COMMA_SEP),$(space),$(subst $(space),$(_SPACE_SEP),$(subst $(comma),$(_COMMA_SEP),$(2)))))
+
+  $(foreach dep,$(_DEP_ITEMS),
+    $(eval _EXTRA_DEP := )
+    $(eval _CUR_DEP := $(subst $(_SPACE_SEP),$(space),$(strip $(dep))))
+    $(eval _PKG_NAME := $(word 1,$(_CUR_DEP)))
+    $(if $(findstring $(paren_left), $(_PKG_NAME)),
+      $(error "Unsupported extra dependency format: no space before '(': $(_CUR_DEP)"))
+    )
+    $(eval _ABI_SUFFIX := $(call GetABISuffix,$(_PKG_NAME)))
+    $(eval _PKG_NAME_ABI := $(_PKG_NAME)$(_ABI_SUFFIX))
+    $(eval _VERSION_CONSTRAINT := $(word 2,$(_CUR_DEP)))
+    $(if $(_VERSION_CONSTRAINT),
+      $(eval _EXTRA_DEP := $(_PKG_NAME_ABI) $(_VERSION_CONSTRAINT)),
+      $(error "Extra dependencies must have version constraints. $(_PKG_NAME) seems to be unversioned.")
+    )
+    $(if $(and $(_EXTRA_DEPENDS_ABI),$(_EXTRA_DEP)),
+      $(eval _EXTRA_DEPENDS_ABI := $(_EXTRA_DEPENDS_ABI)$(comma)$(_EXTRA_DEP)),
+      $(eval _EXTRA_DEPENDS_ABI := $(_EXTRA_DEP))
+    )
+    $(if $(_DEPENDS),
+      $(eval _DEPENDS := $(filter-out $(_PKG_NAME_ABI),$(_DEPENDS)))
+    )
+  )
+
+  $(eval _DEPENDS := $(call mergelist,$(_DEPENDS)))
+  $(_EXTRA_DEPENDS_ABI)$(if $(_DEPENDS),$(comma) $(_DEPENDS))
+)
+endef
+
 # Format provide and add ABI and version if it's not a virtual provide marked
 # with an @.
 #
@@ -308,36 +357,7 @@ endif
         Package/$(1)/DEPENDS := $$(call mergelist,$$(Package/$(1)/DEPENDS))
         Package/$(1)/DEPENDS := $$(EXTRA_DEPENDS)$$(if $$(Package/$(1)/DEPENDS),$$(comma) $$(Package/$(1)/DEPENDS))
       else
-        _SEP := __COMMA_SEP__
-        _SPACE := __SPACE_SEP__
-        _DEPENDS := $$(Package/$(1)/DEPENDS)
-        _EXTRA_DEPENDS_ABI :=
-        _DEP_ITEMS := $$(subst $$(_SEP),$$(space),$$(subst $$(space),$$(_SPACE),$$(subst $$(comma),$$(_SEP),$$(EXTRA_DEPENDS))))
-
-        $$(foreach dep,$$(_DEP_ITEMS), \
-          $$(eval _CUR_DEP := $$(subst $$(_SPACE),$$(space),$$(strip $$(dep)))) \
-          $$(eval _PKG_NAME := $$(word 1,$$(_CUR_DEP))) \
-          $$(if $$(findstring $$(paren_left), $$(_PKG_NAME)), \
-            $$(error "Unsupported extra dependency format: no space before '(': $$(_CUR_DEP)")) \
-          ) \
-          $$(eval _ABI_SUFFIX := $$(call GetABISuffix,$$(_PKG_NAME))) \
-          $$(eval _PKG_NAME_ABI := $$(_PKG_NAME)$$(_ABI_SUFFIX)) \
-          $$(eval _VERSION_CONSTRAINT := $$(word 2,$$(_CUR_DEP))) \
-          $$(if $$(_VERSION_CONSTRAINT), \
-            $$(eval _EXTRA_DEP := $$(_PKG_NAME_ABI) $$(_VERSION_CONSTRAINT)), \
-            $$(error "Extra dependencies must have version constraints. $$(_PKG_NAME) seems to be unversioned.") \
-          ) \
-          $$(if $$(_EXTRA_DEPENDS_ABI), \
-            $$(eval _EXTRA_DEPENDS_ABI := $$(_EXTRA_DEPENDS_ABI)$$(comma)$$(_EXTRA_DEP)), \
-            $$(eval _EXTRA_DEPENDS_ABI := $$(_EXTRA_DEP)) \
-          ) \
-          $$(if $$(_DEPENDS), \
-            $$(eval _DEPENDS := $$(filter-out $$(_PKG_NAME_ABI),$$(_DEPENDS))) \
-          ) \
-        )
-
-        _DEPENDS := $$(call mergelist,$$(_DEPENDS))
-        Package/$(1)/DEPENDS := $$(_EXTRA_DEPENDS_ABI)$$(if $$(_DEPENDS),$$(comma) $$(_DEPENDS))
+        Package/$(1)/DEPENDS := $$(call FormatDepends,$$(Package/$(1)/DEPENDS),$$(EXTRA_DEPENDS))
       endif
     else
       Package/$(1)/DEPENDS := $$(call mergelist,$$(Package/$(1)/DEPENDS))




More information about the lede-commits mailing list