From 22a19e87aa7687c7f7cde5fbca20b001c40f6ec8 Mon Sep 17 00:00:00 2001 From: lguohan Date: Mon, 27 Jul 2020 10:46:20 -0700 Subject: [PATCH] [build]: wait for conflicts package to be uninstalled (#5039) when parallel build is enabled, both docker-fpm-frr and docker-syncd-brcm is built at the same time, docker-fpm-frr requires swss which requires to install libsaivs-dev. docker-syncd-brcm requires syncd package which requires to install libsaibcm-dev. since libsaivs-dev and libsaibcm-dev install the sai header in the same location, these two packages cannot be installed at the same time. Therefore, we need to serialize the build between these two packages. Simply uninstall the conflict package is not enough to solve this issue. The correct solution is to have one package wait for another package to be uninstalled. For example, if syncd is built first, then it will install libsaibcm-dev. Meanwhile, if the swss build job starts and tries to install libsaivs-dev, it will first try to query if libsaibcm-dev is installed or not. if it is installed, then it will wait until libsaibcm-dev is uninstalled. After syncd job is finished, it will uninstall libsaibcm-dev and swss build job will be unblocked. To solve this issue, _UNINSTALLS is introduced to uninstall a package that is no longer needed and to allow blocked job to continue. Signed-off-by: Guohan Lu --- platform/barefoot/bfn-sai.mk | 3 ++- platform/barefoot/rules.mk | 1 + platform/broadcom/rules.mk | 2 ++ platform/broadcom/sai.mk | 2 +- platform/cavium/rules.mk | 2 ++ platform/centec/rules.mk | 2 ++ platform/centec/sdk.mk | 2 +- platform/innovium/invm-sai.mk | 2 +- platform/innovium/rules.mk | 1 + platform/marvell/rules.mk | 2 ++ platform/marvell/sai.mk | 2 +- platform/mellanox/mlnx-sai.mk | 2 +- platform/mellanox/rules.mk | 2 ++ platform/nephos/rules.mk | 2 ++ platform/nephos/sai.mk | 2 +- rules/functions | 24 ++++++++++++++++++ rules/swss.mk | 1 + slave.mk | 47 ++++++++++++++++------------------- 18 files changed, 68 insertions(+), 33 deletions(-) diff --git a/platform/barefoot/bfn-sai.mk b/platform/barefoot/bfn-sai.mk index 9d77755449..eab421e6eb 100644 --- a/platform/barefoot/bfn-sai.mk +++ b/platform/barefoot/bfn-sai.mk @@ -5,5 +5,6 @@ $(BFN_SAI)_DEPENDS += $(LIBNL_GENL3_DEV) $(BFN_SAI)_RDEPENDS += $(LIBNL_GENL3) SONIC_ONLINE_DEBS += $(BFN_SAI) +$(eval $(call add_conflict_package,$(BFN_SAI),$(LIBSAIVS_DEV))) + $(BFN_SAI_DEV)_DEPENDS += $(BFN_SAI) -$(BFN_SAI_DEV)_CONFLICTS += $(LIBSAIVS_DEV) diff --git a/platform/barefoot/rules.mk b/platform/barefoot/rules.mk index 1e4a293af3..03130ac4d0 100644 --- a/platform/barefoot/rules.mk +++ b/platform/barefoot/rules.mk @@ -22,6 +22,7 @@ SONIC_ALL += $(SONIC_ONE_IMAGE) $(SONIC_ONE_ABOOT) \ # Inject sai into syncd #$(SYNCD)_DEPENDS += $(BFN_SAI) $(WNC_OSW1800_PLATFORM) $(BFN_INGRASYS_PLATFORM) $(BFN_PLATFORM) $(SYNCD)_DEPENDS += $(BFN_SAI) $(BFN_INGRASYS_PLATFORM) $(BFN_PLATFORM) +$(SYNCD)_UNINSTALLS += $(BFN_SAI) ifeq ($(ENABLE_SYNCD_RPC),y) $(SYNCD)_DEPENDS += $(LIBSAITHRIFT_DEV) diff --git a/platform/broadcom/rules.mk b/platform/broadcom/rules.mk index afcec34a73..34edfa0d37 100644 --- a/platform/broadcom/rules.mk +++ b/platform/broadcom/rules.mk @@ -34,6 +34,8 @@ SONIC_ALL += $(SONIC_ONE_IMAGE) $(SONIC_ONE_ABOOT_IMAGE) \ # Inject brcm sai into syncd $(SYNCD)_DEPENDS += $(BRCM_SAI) $(BRCM_SAI_DEV) +$(SYNCD)_UNINSTALLS += $(BRCM_SAI_DEV) + ifeq ($(ENABLE_SYNCD_RPC),y) $(SYNCD)_DEPENDS += $(LIBSAITHRIFT_DEV) endif diff --git a/platform/broadcom/sai.mk b/platform/broadcom/sai.mk index 1cb3bf80c0..8624464fdc 100644 --- a/platform/broadcom/sai.mk +++ b/platform/broadcom/sai.mk @@ -6,4 +6,4 @@ $(BRCM_SAI_DEV)_URL = "https://sonicstorage.blob.core.windows.net/packages/bcmsa SONIC_ONLINE_DEBS += $(BRCM_SAI) $(BRCM_SAI_DEV)_DEPENDS += $(BRCM_SAI) -$(BRCM_SAI_DEV)_CONFLICTS += $(LIBSAIVS_DEV) +$(eval $(call add_conflict_package,$(BRCM_SAI_DEV),$(LIBSAIVS_DEV))) diff --git a/platform/cavium/rules.mk b/platform/cavium/rules.mk index acdd7477fd..bbc2e4d2d2 100644 --- a/platform/cavium/rules.mk +++ b/platform/cavium/rules.mk @@ -14,6 +14,8 @@ SONIC_ALL += $(SONIC_ONE_IMAGE) \ # Inject cavium sai into syncd $(SYNCD)_DEPENDS += $(CAVM_SAI) $(CAVM_LIBSAI) +$(SYNCD)_UNINSTALLS += $(CAVM_LIBSAI) + ifeq ($(ENABLE_SYNCD_RPC),y) $(SYNCD)_DEPENDS += $(LIBSAITHRIFT_DEV_CAVM) endif diff --git a/platform/centec/rules.mk b/platform/centec/rules.mk index d1f1d9acee..4f5173d82e 100644 --- a/platform/centec/rules.mk +++ b/platform/centec/rules.mk @@ -12,6 +12,8 @@ SONIC_ALL += $(SONIC_ONE_IMAGE) \ # Inject centec sai into syncd $(SYNCD)_DEPENDS += $(CENTEC_SAI) +$(SYNCD)_UNINSTALLS += $(CENTEC_SAI) + ifeq ($(ENABLE_SYNCD_RPC),y) $(SYNCD)_DEPENDS += $(LIBSAITHRIFT_DEV) endif diff --git a/platform/centec/sdk.mk b/platform/centec/sdk.mk index 308f0b3bf4..7b6571bdca 100644 --- a/platform/centec/sdk.mk +++ b/platform/centec/sdk.mk @@ -1,6 +1,6 @@ # Centec SAI CENTEC_SAI = libsai_1.3.3_amd64.deb $(CENTEC_SAI)_URL = https://github.com/CentecNetworks/goldengate-sai/raw/master/lib/SONiC_1.3.3/libsai_1.3.3-1.0_amd64.deb -$(CENTEC_SAI)_CONFLICTS += $(LIBSAIVS_DEV) +$(eval $(call add_conflict_package,$(CENTEC_SAI),$(LIBSAIVS_DEV))) SONIC_ONLINE_DEBS += $(CENTEC_SAI) diff --git a/platform/innovium/invm-sai.mk b/platform/innovium/invm-sai.mk index a631f29562..e9d694d3f3 100755 --- a/platform/innovium/invm-sai.mk +++ b/platform/innovium/invm-sai.mk @@ -10,7 +10,7 @@ $(INVM_LIBSAI)_URL = $(INVM_SAI_ONLINE)/$(INVM_LIBSAI) $(INVM_HSAI)_URL = $(INVM_SAI_ONLINE)/$(INVM_HSAI) $(INVM_DRV)_URL = $(INVM_SAI_ONLINE)/$(INVM_DRV) -$(INVM_HSAI)_CONFLICTS += $(LIBSAIVS_DEV) +$(eval $(call add_conflict_package,$(INVM_HSAI),$(LIBSAIVS_DEV))) SONIC_ONLINE_DEBS += $(INVM_LIBSAI) $(INVM_HSAI) $(INVM_DRV) SONIC_STRETCH_DEBS += $(INVM_DRV) diff --git a/platform/innovium/rules.mk b/platform/innovium/rules.mk index 7c9d6826a6..6317cb23b6 100755 --- a/platform/innovium/rules.mk +++ b/platform/innovium/rules.mk @@ -14,6 +14,7 @@ SONIC_ALL += $(SONIC_INVM_ONE_IMAGE) \ # Inject invm sai into syncd $(SYNCD)_DEPENDS += $(INVM_HSAI) $(INVM_LIBSAI) $(LIBSAITHRIFT_DEV_INVM) +$(SYNCD)_UNINSTALLS += $(INVM_HSAI) # Runtime dependency on invm sai is set only for syncd $(SYNCD)_RDEPENDS += $(INVM_HSAI) diff --git a/platform/marvell/rules.mk b/platform/marvell/rules.mk index 442af4cbe9..da23e53f26 100644 --- a/platform/marvell/rules.mk +++ b/platform/marvell/rules.mk @@ -10,6 +10,8 @@ SONIC_ALL += $(SONIC_ONE_IMAGE) \ # Inject mrvl sai into syncd $(SYNCD)_DEPENDS += $(MRVL_FPA) $(MRVL_SAI) +$(SYNCD)_UNINSTALLS += $(MRVL_SAI) + ifeq ($(ENABLE_SYNCD_RPC),y) $(SYNCD)_DEPENDS += $(LIBSAITHRIFT_DEV) endif diff --git a/platform/marvell/sai.mk b/platform/marvell/sai.mk index 586efc3433..ae117c6c34 100644 --- a/platform/marvell/sai.mk +++ b/platform/marvell/sai.mk @@ -3,6 +3,6 @@ export MRVL_SAI = mrvllibsai_amd64_1.4.1.deb $(MRVL_SAI)_SRC_PATH = $(PLATFORM_PATH)/sai -$(MRVL_SAI)_CONFLICTS = $(LIBSAIVS_DEV) +$(eval $(call add_conflict_package,$(MRVL_SAI),$(LIBSAIVS_DEV))) SONIC_MAKE_DEBS += $(MRVL_SAI) diff --git a/platform/mellanox/mlnx-sai.mk b/platform/mellanox/mlnx-sai.mk index 41672cd573..f94f7f38bf 100644 --- a/platform/mellanox/mlnx-sai.mk +++ b/platform/mellanox/mlnx-sai.mk @@ -10,5 +10,5 @@ $(MLNX_SAI)_DEPENDS += $(MLNX_SDK_DEBS) $(MLNX_SAI)_RDEPENDS += $(MLNX_SDK_RDEBS) $(MLNX_SDK_DEBS) MLNX_SAI_DBGSYM = mlnx-sai-dbgsym_1.mlnx.$(MLNX_SAI_VERSION)_amd64.deb $(eval $(call add_derived_package,$(MLNX_SAI),$(MLNX_SAI_DBGSYM))) -$(MLNX_SAI)_CONFLICTS += $(LIBSAIVS_DEV) +$(eval $(call add_conflict_package,$(MLNX_SAI),$(LIBSAIVS_DEV))) SONIC_MAKE_DEBS += $(MLNX_SAI) diff --git a/platform/mellanox/rules.mk b/platform/mellanox/rules.mk index 19e8538b72..1bb8a60ba4 100644 --- a/platform/mellanox/rules.mk +++ b/platform/mellanox/rules.mk @@ -20,6 +20,8 @@ SONIC_ALL += $(SONIC_ONE_IMAGE) \ # Inject mlnx sai into syncd $(SYNCD)_DEPENDS += $(MLNX_SAI) +$(SYNCD)_UNINSTALLS += $(MLNX_SAI) + ifeq ($(ENABLE_SYNCD_RPC),y) $(SYNCD)_DEPENDS += $(LIBSAITHRIFT_DEV) endif diff --git a/platform/nephos/rules.mk b/platform/nephos/rules.mk index 727f6ab461..8950c665de 100644 --- a/platform/nephos/rules.mk +++ b/platform/nephos/rules.mk @@ -24,6 +24,8 @@ SONIC_ALL += $(SONIC_ONE_IMAGE) $(DOCKER_FPM) # Inject nephos sai into syncd $(SYNCD)_DEPENDS += $(NEPHOS_SAI) $(NEPHOS_SAI_DEV) +$(SYNCD)_UNINSTALLS += $(NEPHOS_SAI_DEV) + ifeq ($(ENABLE_SYNCD_RPC),y) $(SYNCD)_DEPENDS += $(LIBSAITHRIFT_DEV) endif diff --git a/platform/nephos/sai.mk b/platform/nephos/sai.mk index f330065de5..48539e498e 100644 --- a/platform/nephos/sai.mk +++ b/platform/nephos/sai.mk @@ -26,4 +26,4 @@ else SONIC_ONLINE_DEBS += $(NEPHOS_SAI) endif $(NEPHOS_SAI_DEV)_DEPENDS += $(NEPHOS_SAI) -$(NEPHOS_SAI_DEV)_CONFLICTS += $(LIBSAIVS_DEV) +$(eval $(call add_conflict_package,$(NEPHOS_SAI_DEV),$(LIBSAIVS_DEV))) diff --git a/rules/functions b/rules/functions index 38f2028e01..4d00edd127 100644 --- a/rules/functions +++ b/rules/functions @@ -91,6 +91,17 @@ $(1)_EXTRA_DEBS += $(2) SONIC_EXTRA_DEBS += $(2) endef +############################################################################### +## Definition of conflict packages +############################################################################### + +# call: +# add_conflict_package some_deb.deb, conflict_deb +define add_conflict_package +$(1)_CONFLICT_DEBS += $(2) +$(2)_CONFLICT_DEBS += $(1) +endef + ############################################################################### ## Utility functions ############################################################################### @@ -108,3 +119,16 @@ sudo mount -t overlay overlay -olowerdir=/var/lib/dpkg,upperdir=$$upperdir,workd export SONIC_DPKG_ADMINDIR=$$mergedir trap "sudo umount $$mergedir && rm -rf $$mergedir $$upperdir $$workdir" EXIT endef + +############################################################################### +## Uninstall debs +############################################################################### +define UNINSTALL_DEBS +$(info $(1)) +$(foreach deb,$(1), \ + { while true; do \ + if mkdir $(DEBS_PATH)/dpkg_lock &> /dev/null; then \ + { sudo DEBIAN_FRONTEND=noninteractive dpkg -P $(firstword $(subst _, ,$(basename $(deb)))) $(LOG) && rm -d $(DEBS_PATH)/dpkg_lock && break; } || { rm -d $(DEBS_PATH)/dpkg_lock && exit 1 ; } \ + fi; \ + done; } ) +endef diff --git a/rules/swss.mk b/rules/swss.mk index 11794afc37..3d496828db 100644 --- a/rules/swss.mk +++ b/rules/swss.mk @@ -6,6 +6,7 @@ $(SWSS)_DEPENDS += $(LIBSAIREDIS_DEV) $(LIBSAIMETADATA_DEV) $(LIBTEAM_DEV) \ $(LIBTEAMDCT) $(LIBTEAM_UTILS) $(LIBSWSSCOMMON_DEV) \ $(LIBSAIVS) $(LIBSAIVS_DEV) $(SWSS)_RDEPENDS += $(LIBSAIREDIS) $(LIBSAIMETADATA) $(LIBTEAM) $(LIBSWSSCOMMON) $(PYTHON_SWSSCOMMON) +$(SWSS)_UNINSTALLS = $(LIBSAIVS_DEV) SONIC_DPKG_DEBS += $(SWSS) diff --git a/slave.mk b/slave.mk index 7d3b64fd80..eda99e8806 100644 --- a/slave.mk +++ b/slave.mk @@ -311,6 +311,10 @@ $(addprefix $(FILES_PATH)/, $(SONIC_MAKE_FILES)) : $(FILES_PATH)/% : .platform $ make DEST=$(shell pwd)/$(FILES_PATH) -C $($*_SRC_PATH) $(shell pwd)/$(FILES_PATH)/$* $(LOG) # Clean up if [ -f $($*_SRC_PATH).patch/series ]; then pushd $($*_SRC_PATH) && quilt pop -a -f; popd; fi + + # Uninstall unneeded build dependency + $(call UNINSTALL_DEBS,$($*_UNINSTALLS)) + $(FOOTER) SONIC_TARGET_LIST += $(addprefix $(FILES_PATH)/, $(SONIC_MAKE_FILES)) @@ -338,6 +342,10 @@ $(addprefix $(DEBS_PATH)/, $(SONIC_MAKE_DEBS)) : $(DEBS_PATH)/% : .platform $$(a DEB_BUILD_OPTIONS="${DEB_BUILD_OPTIONS_GENERIC}" make DEST=$(shell pwd)/$(DEBS_PATH) -C $($*_SRC_PATH) $(shell pwd)/$(DEBS_PATH)/$* $(LOG) # Clean up if [ -f $($*_SRC_PATH).patch/series ]; then pushd $($*_SRC_PATH) && quilt pop -a -f; popd; fi + + # Uninstall unneeded build dependency + $(call UNINSTALL_DEBS,$($*_UNINSTALLS)) + $(FOOTER) SONIC_TARGET_LIST += $(addprefix $(DEBS_PATH)/, $(SONIC_MAKE_DEBS)) @@ -367,6 +375,10 @@ $(addprefix $(DEBS_PATH)/, $(SONIC_DPKG_DEBS)) : $(DEBS_PATH)/% : .platform $$(a if [ -f $($*_SRC_PATH).patch/series ]; then pushd $($*_SRC_PATH) && quilt pop -a -f; popd; fi # Take built package(s) mv $(addprefix $($*_SRC_PATH)/../, $* $($*_DERIVED_DEBS) $($*_EXTRA_DEBS)) $(DEBS_PATH) $(LOG) + + # Uninstall unneeded build dependency + $(call UNINSTALL_DEBS,$($*_UNINSTALLS)) + $(FOOTER) SONIC_TARGET_LIST += $(addprefix $(DEBS_PATH)/, $(SONIC_DPKG_DEBS)) @@ -410,35 +422,18 @@ SONIC_INSTALL_TARGETS = $(addsuffix -install,$(addprefix $(DEBS_PATH)/, \ $(SONIC_PYTHON_STDEB_DEBS) \ $(SONIC_DERIVED_DEBS) \ $(SONIC_EXTRA_DEBS))) -$(SONIC_INSTALL_TARGETS) : $(DEBS_PATH)/%-install : .platform $$(addsuffix -install,$$(addprefix $(DEBS_PATH)/,$$($$*_DEPENDS))) $(DEBS_PATH)/$$* $$(addsuffix -uninstall,$$(addprefix $(DEBS_PATH)/,$$($$*_CONFLICTS))) + +$(SONIC_INSTALL_TARGETS) : $(DEBS_PATH)/%-install : .platform $$(addsuffix -install,$$(addprefix $(DEBS_PATH)/,$$($$*_DEPENDS))) $(DEBS_PATH)/$$* $(HEADER) [ -f $(DEBS_PATH)/$* ] || { echo $(DEBS_PATH)/$* does not exist $(LOG) && false $(LOG) } - # put a lock here because dpkg does not allow installing packages in parallel while true; do - if mkdir $(DEBS_PATH)/dpkg_lock &> /dev/null; then - { sudo dpkg -i $(DEBS_PATH)/$* $(LOG) && rm -d $(DEBS_PATH)/dpkg_lock && break; } || { rm -d $(DEBS_PATH)/dpkg_lock && exit 1 ; } - fi - done - $(FOOTER) - -# Targets for installing debian packages prior to build one that depends on them -SONIC_UNINSTALL_TARGETS = $(addsuffix -uninstall,$(addprefix $(DEBS_PATH)/, \ - $(SONIC_ONLINE_DEBS) \ - $(SONIC_COPY_DEBS) \ - $(SONIC_MAKE_DEBS) \ - $(SONIC_DPKG_DEBS) \ - $(SONIC_PYTHON_STDEB_DEBS) \ - $(SONIC_DERIVED_DEBS) \ - $(SONIC_EXTRA_DEBS))) - -$(SONIC_UNINSTALL_TARGETS) : $(DEBS_PATH)/%-uninstall : .platform - $(HEADER) - [ -f $(DEBS_PATH)/$* ] || { echo $(DEBS_PATH)/$* does not exist $(LOG) && false $(LOG) } - # put a lock here because dpkg does not allow installing packages in parallel - while true; do - if mkdir $(DEBS_PATH)/dpkg_lock &> /dev/null; then - { sudo DEBIAN_FRONTEND=noninteractive dpkg -P $(firstword $(subst _, ,$(basename $*))) $(LOG) && rm -d $(DEBS_PATH)/dpkg_lock && break; } || { rm -d $(DEBS_PATH)/dpkg_lock && exit 1 ; } - fi + # wait for conflicted packages to be uninstalled + $(foreach deb, $($*_CONFLICT_DEBS), \ + { while dpkg -s $(firstword $(subst _, ,$(basename $(deb)))) &> /dev/null; do echo "waiting for $(deb) to be uninstalled" $(LOG); sleep 1; done } ) + # put a lock here because dpkg does not allow installing packages in parallel + if mkdir $(DEBS_PATH)/dpkg_lock &> /dev/null; then + { sudo DEBIAN_FRONTEND=noninteractive dpkg -i $(DEBS_PATH)/$* $(LOG) && rm -d $(DEBS_PATH)/dpkg_lock && break; } || { rm -d $(DEBS_PATH)/dpkg_lock && exit 1 ; } + fi done $(FOOTER)