Skip to content

Commit 5ed650a

Browse files
GeorgeSapkinrobimarko
authored andcommitted
build: add support for virtual provides
Allow defining virtual provides using the PROVIDES field by prefixing them with @, e.g.: PROVIDES:=@ca-certs Virtual provides don't own the provided name and multiple packages with the same virtual provides can be installed side-by-side. Packages must still take care not to override each other's files. Add an implicit self-provide to packages. apk can't handle self provides, be it versioned or virtual, so opt for a suffix instead. This allows several variants to provide the same virtual package without adding extra provides to the default one, e.g. wget implicitly provides wget-any and is marked as default, so wget-ssl can explicitly provide @wget-any as well. Filter out virtual provides when generating metadata. Filter out virtual provides prefix and self provide where appropriate. Signed-off-by: George Sapkin <[email protected]> Link: openwrt/openwrt#21288 Signed-off-by: Robert Marko <[email protected]>
1 parent cefbf11 commit 5ed650a

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

include/package-pack.mk

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,25 @@ define FixupDependencies
7878
$(call AddDependency,$(1),$$(DEPS))
7979
endef
8080

81+
# Format provide and add ABI and version if it's not a virtual provide marked
82+
# with an @.
83+
#
84+
# 1: provide name
85+
# 2: provide version
86+
# 3: (optional) ABI preformatted by FormatABISuffix
87+
define AddProvide
88+
$(if $(filter @%,$(1)),$(patsubst @%,%,$(1)),$(1)$(3)=$(2))
89+
endef
90+
91+
# Remove virtual provides prefix and self. apk doesn't like it when packages
92+
# specify a redundant provide pointing to self.
93+
#
94+
# 1: package name
95+
# 2: list of provides
96+
define SanitizeProvides
97+
$(filter-out $(1),$(patsubst @%,%,$(2)))
98+
endef
99+
81100
# Format provides both for apk and control
82101
#
83102
# - If ABI version is defined:
@@ -108,16 +127,33 @@ endef
108127
# this implies that only one version of a provide can be installed at the
109128
# same time
110129
#
130+
# - Both with and without an ABI, if a provide starts with an @, treat it as a
131+
# virtual provide, that doesn't own the name by not appending version.
132+
# Multiple packages with the same virtual provides can be installed
133+
# side-by-side.
134+
#
135+
# - apk doesn't like it when packages specify a redundant provide pointing to
136+
# self. Filter it out, but keep virtual self provides, in the form of
137+
# @${package_name}-any.
138+
#
139+
# - Packages implicitly add a virtual @${package_name}-any provide in Package.
140+
#
111141
# 1: package name
112142
# 2: package version
113143
# 3: list of provides
114144
# 4: list of alternatives
115145
define FormatProvides
116146
$(strip $(if $(ABIV_$(1)), \
117-
$(1) $(foreach provide,$(3), $(provide)$(ABIV_$(1))=$(2)), \
147+
$(1) $(foreach provide, \
148+
$(filter-out $(1),$(3)), \
149+
$(call AddProvide,$(provide),$(2),$(ABIV_$(1))) \
150+
), \
118151
$(if $(4), \
119-
$(3), \
120-
$(foreach provide,$(3), $(provide)=$(2)) \
152+
$(filter-out $(1),$(3)), \
153+
$(foreach provide, \
154+
$(filter-out $(1),$(3)), \
155+
$(call AddProvide,$(provide),$(2)) \
156+
) \
121157
) \
122158
))
123159
endef
@@ -237,7 +273,7 @@ endif
237273
$(if $(ABI_VERSION),echo '$(ABI_VERSION)' | cmp -s - $(PKG_INFO_DIR)/$(1).version || { \
238274
mkdir -p $(PKG_INFO_DIR); \
239275
echo '$(ABI_VERSION)' > $(PKG_INFO_DIR)/$(1).version; \
240-
$(foreach pkg,$(filter-out $(1),$(PROVIDES)), \
276+
$(foreach pkg,$(call SanitizeProvides,$(1),$(PROVIDES)), \
241277
cp $(PKG_INFO_DIR)/$(1).version $(PKG_INFO_DIR)/$(pkg).version; \
242278
) \
243279
} )
@@ -336,7 +372,7 @@ endif
336372
fi; \
337373
done; $(Package/$(1)/extra_provides) \
338374
) | sort -u > $(PKG_INFO_DIR)/$(1).provides
339-
$(if $(PROVIDES),@for pkg in $(filter-out $(1),$(PROVIDES)); do cp $(PKG_INFO_DIR)/$(1).provides $(PKG_INFO_DIR)/$$$$pkg.provides; done)
375+
$(if $(PROVIDES),@for pkg in $(call SanitizeProvides,$(1),$(PROVIDES)); do cp $(PKG_INFO_DIR)/$(1).provides $(PKG_INFO_DIR)/$$$$pkg.provides; done)
340376
$(CheckDependencies)
341377

342378
$(RSTRIP) $$(IDIR_$(1))

include/package.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,13 @@ define BuildPackage
332332
$(eval $(Package/Default))
333333
$(eval $(Package/$(1)))
334334

335+
# Add an implicit self-provide. apk can't handle self provides, be it
336+
# versioned or virtual, so opt for a suffix instead. This allows several
337+
# variants to provide the same virtual package without adding extra provides
338+
# to the default one, e.g. wget implicitly provides wget-any and is marked as
339+
# default, so wget-ssl can explicitly provide @wget-any as well.
340+
PROVIDES+=@$(1)-any
341+
335342
ifdef DESCRIPTION
336343
$$(error DESCRIPTION:= is obsolete, use Package/PKG_NAME/description)
337344
endif

scripts/metadata.pm

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ sub parse_package_metadata($) {
263263
/^Default: \s*(.+)\s*$/ and $pkg->{default} = $1;
264264
/^Provides: \s*(.+)\s*$/ and do {
265265
my @vpkg = split /\s+/, $1;
266+
foreach (@vpkg) {
267+
s/^@//;
268+
}
266269
@{$pkg->{provides}} = ($pkg->{name}, @vpkg);
267270
foreach my $vpkg (@vpkg) {
268271
next if ($vpkg eq $pkg->{name});

0 commit comments

Comments
 (0)