build: handle --root feeds script feature

Rework the package SOURCE entry handling to account for the --root feeds
script feature.

Move the SOURCE entry string manipulation logic outside package-defaults.mk
in package.mk and limit only to non DUMP scenario to not pollute the .mk
too much.

Restructure the previous logic and add a new additional condition.
If we detect the package comes from a feed, replace any feed path that
have the _root prefix to the feed name with the non-root variant (the
feeds script create a symbolic link to it) and point the package SOURCE
entry to what the symbolic link points to.

Example:
Feed link: feeds/base_root/package -> feeds/base
Package: feeds/base_root/package/system/uci -> feeds/base/system/uci

Link: https://github.com/openwrt/openwrt/pull/20459
Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
This commit is contained in:
Christian Marangi
2025-10-19 20:43:09 +02:00
parent b91b99ec18
commit 330d17f52d
2 changed files with 30 additions and 1 deletions

View File

@ -20,7 +20,7 @@ define Package/Default
PROVIDES:=
EXTRA_DEPENDS:=
MAINTAINER:=$(PKG_MAINTAINER)
SOURCE:=$(patsubst $(TOPDIR)/%,%,$(patsubst $(TOPDIR)/package/%,feeds/base/%,$(CURDIR)))
SOURCE:=$(patsubst $(TOPDIR)/%,%,$(if $(__pkg_source_makefile),$(__pkg_source_makefile),$(CURDIR)))
ifneq ($(PKG_VERSION),)
ifneq ($(PKG_RELEASE),)
VERSION:=$(PKG_VERSION)-r$(PKG_RELEASE)

View File

@ -134,6 +134,35 @@ endef
PKG_INSTALL_STAMP:=$(PKG_INFO_DIR)/$(PKG_DIR_NAME).$(if $(BUILD_VARIANT),$(BUILD_VARIANT),default).install
# Normalize package SOURCE entry to pack reproducible package
# If we are packing a package with OpenWrt buildroot:
# - Replace package/... with feeds/base/...
# If we are packing a package with SDK:
# - Replace feeds/.*_root/... with feeds/.*/... and remove
# the intermediate directory to reflect what the symbolic link
# points to.
# Example:
# Feed link: feeds/base_root/package -> feeds/base
# Package: feeds/base_root/package/system/uci -> feeds/base/system/uci
ifeq ($(DUMP),)
__pkg_base_path:=$(patsubst $(TOPDIR)/%,%,$(CURDIR))
__pkg_provider_path:=$(word 1,$(subst /, ,$(__pkg_base_path)))
ifeq ($(__pkg_provider_path), feeds)
__pkg_feed_path:=$(word 2,$(subst /, ,$(__pkg_base_path)))
__pkg_feed_name:=$(patsubst %_root,%,$(__pkg_feed_path))
ifneq (__pkg_feed_path, __pkg_feed_name)
__pkg_feed_realpath:=$(realpath $(TOPDIR)/feeds/$(__pkg_feed_name))
__pkg_feed_dir:=$(patsubst $(TOPDIR)/feeds/$(__pkg_feed_path)/%,%,$(__pkg_feed_realpath))
__pkg_path:=$(patsubst feeds/$(__pkg_feed_path)/$(__pkg_feed_dir)/%,%,$(__pkg_base_path))
else
__pkg_path:=$(patsubst feeds/$(__pkg_feed_path)/%,%,$(__pkg_base_path))
endif
__pkg_source_makefile:=$(TOPDIR)/feeds/$(__pkg_feed_name)/$(__pkg_path)
else ifeq ($(__pkg_provider_path), package)
__pkg_source_makefile:=$(TOPDIR)/feeds/base/$(patsubst package/%,%,$(__pkg_base_path))
endif
endif
include $(INCLUDE_DIR)/package-defaults.mk
include $(INCLUDE_DIR)/package-dumpinfo.mk
include $(INCLUDE_DIR)/package-pack.mk