[PATCH 4/4] image.in, pkg.in/groups: inter-group dependencies

Michael Shigorin mike at altlinux.org
Wed Jul 17 21:15:06 MSK 2019


The whole affair with automatic extraction hasn't
ended with profiles2groups and groups2lists functions
as we've also got dependencies between package groups
-- both up and down; these can be recursive, and so far
nothing stops them from being circular as well.

The typical problems that should be solved by this
commit are:

- missing parent groups (with presumed installer
  list items turning into toplevel ones);
- missing dependency groups (leaving warnings during
  image build and silent errors during installation IIRC).

groups2deps script's core logic was written by
Dmitry Levin <ldv at altlinux.org>, I was too sleepy
to write down the invariant handling.

NB: someone might prefer to disable this kind of service
    some day; drop me a note (or a knob patch)
    if you're that someone.
---
 bin/groups2deps        | 32 ++++++++++++++++++++++++++++++++
 image.in/functions.mk  | 19 ++++++++++++-------
 pkg.in/groups/Makefile |  9 ++++++++-
 3 files changed, 52 insertions(+), 8 deletions(-)
 create mode 100755 bin/groups2deps

diff --git a/bin/groups2deps b/bin/groups2deps
new file mode 100755
index 0000000..1e42639
--- /dev/null
+++ b/bin/groups2deps
@@ -0,0 +1,32 @@
+#!/bin/sh
+# extract dependencies from directory files
+# corresponding to specified group names
+# as a sorted group name list
+
+exit_handler()
+{
+	local rc=$1
+	rm -f -- "$list" "$next"
+	exit $rc
+}
+
+list="$(mktemp)"
+next="$(mktemp)"
+
+trap 'exit_handler $?' EXIT HUP PIPE INT QUIT TERM
+
+# convert to group file names
+g2f() { sed -r 's,\<[^ ]+\>,groups/&.directory,g'; }
+
+# extract dependencies
+g2d() { sed -rn 's,^X-Alterator-(Depends|Parent)=(.*)$,\2,p' "$@" /dev/null; }
+
+if [ -n "$*" ]; then echo "$@"; else cat; fi | tr ' ' '\n' | sort -u > "$list"
+
+while :; do
+	g2d $(g2f < "$list") | sort -u | comm -23 - "$list" > "$next"
+	[ -s "$next" ] || break
+	sort -u -o "$list"{,} "$next"
+done
+
+cat "$list"
diff --git a/image.in/functions.mk b/image.in/functions.mk
index 548a6a6..c9975a7 100644
--- a/image.in/functions.mk
+++ b/image.in/functions.mk
@@ -31,16 +31,21 @@ define profiles2groups_body
 fi; }
 endef
 
+# collect groups recursively
+# NB: no cyclic graph protection
+allgroups = $(shell $(allgroups_body))
+define allgroups_body
+{ if [ -n "$(THE_GROUPS)$(MAIN_GROUPS)$(THE_PROFILES)" ]; then \
+	cd $(PKGDIR) && \
+	groups2deps $(THE_GROUPS) $(MAIN_GROUPS) $(profiles2groups); \
+fi; }
+endef
+
 # happens at least thrice, and variables are the same by design
 groups2lists = $(shell $(groups2lists_body))
 define groups2lists_body
-{ if [ -n "$(THE_GROUPS)$(MAIN_GROUPS)$(THE_PROFILES)" ]; then \
-	sed -rn 's,^X-Alterator-PackageList=(.*)$$,\1,p' \
-		$(call map,group, \
-			$(THE_GROUPS) $(MAIN_GROUPS) \
-			$(call profiles2groups)) \
-		/dev/null; \
-fi; }
+{ sed -rn 's,^X-Alterator-PackageList=(.*)$$,\1,p' \
+	$(call map,group,$(allgroups)) /dev/null; }
 endef
 
 # kernel package list generation; see also #24669
diff --git a/pkg.in/groups/Makefile b/pkg.in/groups/Makefile
index 5d79727..802d54f 100644
--- a/pkg.in/groups/Makefile
+++ b/pkg.in/groups/Makefile
@@ -33,19 +33,26 @@ check-pkglists:
 else
 
 include $(BUILDDIR)/distcfg.mk
+include $(BUILDDIR)/functions.mk
+
 SUFFIX := pkg/groups
 TARGET := $(BUILDDIR)/$(SUFFIX)
 
+all: PKGDIR = ..
 all: $(GLOBAL_DEBUG)
 	@if [ -n "$(THE_GROUPS)$(MAIN_GROUPS)" ]; then \
 		mkdir -p $(TARGET) && \
 		cp --parents -at $(TARGET) -- \
-			$(addsuffix .directory,$(THE_GROUPS) $(MAIN_GROUPS)); \
+			$(addsuffix .directory, \
+				$(THE_GROUPS) $(MAIN_GROUPS) $(allgroups)); \
 		mp-commit "$(TARGET)" "requested $(SUFFIX) copied over"; \
 	fi
 
 debug:
 	@echo "** THE_GROUPS: $(THE_GROUPS)"
 	@echo "** MAIN_GROUPS: $(MAIN_GROUPS)"
+ifeq (2,$(DEBUG))
+	@echo "** allgroups: $(call allgroups)"
+endif
 
 endif
-- 
2.10.4


--k1lZvvs/B4yU6o8G--


More information about the devel-distro mailing list