Package: dpkg
Version: 1.21.7
Severity: minor
Tags: patch

/usr/share/dpkg/architecture.mk sets up variables in a way so that
every single variable out of 33 DEB_{HOST,..}_{ARCH,..} total is
set separately by its own call to dpkg-architecture if it is not
already defined.

On my (not slow at all) system, just including architecture.mk and
doing a trivial echo command for a target, takes really significant
time.

============== For this makefile: ==============
ifeq ($A,1)
# slow version
include /usr/share/dpkg/architecture.mk
else
$(foreach d, $(shell dpkg-architecture | sed 's/=/?=/'), $(eval export $d))
endif
tst:
        echo ${DEB_HOST_MULTIARCH}
=================================================

$ time make A=0
echo x86_64-linux-gnu
x86_64-linux-gnu

real    0m0,078s
user    0m0,059s
sys     0m0,021s

$ time make A=1
echo x86_64-linux-gnu
x86_64-linux-gnu

real    0m2,222s
user    0m2,005s
sys     0m0,228s


So the time required to run simple echo command is
reduced from 2.2s to almost non-existent 0.078s when
replacing architecture.mk with its one-shot equivalent.

This is huge.

And this is where actual time is important: you run
./d/rules manually to debug build issues, when none
of the DEB_*_* variables are set, and each 2s delay
before any first command is run is really annoying.

Please consider applying the attached patch which first
checks if any of the DEB_*_* variables are not set
(the big if()), and if any is not set, it executes
dpkg-architecture *once*, and sets all missing variables
(which are not already set) in one go.

/mjt

--- scripts/mk/architecture.mk.orig     2022-03-26 20:17:59.000000000 +0300
+++ scripts/mk/architecture.mk  2022-04-12 19:00:23.588642919 +0300
@@ -2,10 +2,21 @@
 # DEB_BUILD_* variables that dpkg-architecture can return. Existing values
 # of those variables are preserved as per policy.
 
+# preserve the following define for compatibiluty?
 dpkg_lazy_eval ?= $$(or $$(value DPKG_CACHE_$(1)),$$(eval DPKG_CACHE_$(1) := 
$$(shell $(2)))$$(value DPKG_CACHE_$(1)))
 
-dpkg_architecture_setvar = export $(1) ?= $(call 
dpkg_lazy_eval,$(1),dpkg-architecture -q$(1))
+# if at least one of $DEB_{HOST,..}_{ARCH,..} is not set, ...
+ifneq \
+(,$(strip \
+    $(foreach p, HOST BUILD TARGET, \
+        $(foreach s, ARCH ARCH_ABI ARCH_LIBC ARCH_OS ARCH_CPU ARCH_BITS \
+                     ARCH_ENDIAN GNU_CPU GNU_SYSTEM GNU_TYPE MULTIARCH, \
+            $(if ${DEB_$p_$s},,$p_$s) \
+         )\
+     )\
+))
 
-$(foreach machine,BUILD HOST TARGET,\
-  $(foreach var,ARCH ARCH_ABI ARCH_LIBC ARCH_OS ARCH_CPU ARCH_BITS ARCH_ENDIAN 
GNU_CPU GNU_SYSTEM GNU_TYPE MULTIARCH,\
-    $(eval $(call dpkg_architecture_setvar,DEB_$(machine)_$(var)))))
+# ... set the missing ones from dpkg-architecture
+  $(foreach d, $(shell dpkg-architecture | sed 's/=/?=/'), $(eval export $d))
+
+endif

Reply via email to