Merge "strings.mk: Allow empty RHS values for inputs of collapse-pairs" am: 62d5978710

Change-Id: Ib42301a1e2074ebfb317dec9b85563672d141962
This commit is contained in:
Treehugger Robot 2020-04-15 16:57:20 +00:00 committed by Automerger Merge Worker
commit 4acb0e2577

View file

@ -88,7 +88,7 @@ $(word $(1),$(subst :,$(space),$(2)))
endef
###########################################################
## Convert "a=b c= d e = f" into "a=b c=d e=f"
## Convert "a=b c= d e = f = g h=" into "a=b c=d e= f=g h="
##
## $(1): list to collapse
## $(2): if set, separator word; usually "=", ":", or ":="
@ -96,11 +96,29 @@ endef
###########################################################
define collapse-pairs
$(strip \
$(eval _cpSEP := $(strip $(if $(2),$(2),=)))\
$(strip $(subst $(space)$(_cpSEP)$(space),$(_cpSEP),$(strip \
$(subst $(_cpSEP), $(_cpSEP) ,$(1)))$(space)))
$(eval _cpLHS :=)\
$(eval _cpRET :=)\
$(foreach w,$(subst $(space)$(_cpSEP),$(_cpSEP),$(strip \
$(subst $(_cpSEP),$(space)$(_cpSEP)$(space),$(1)))),\
$(if $(findstring $(_cpSEP),$(w)),\
$(eval _cpRET += $(_cpLHS))$(eval _cpLHS := $(w)),\
$(eval _cpRET += $(_cpLHS)$(w))$(eval _cpLHS :=)))\
$(if $(_cpLHS),$(_cpRET)$(space)$(_cpLHS),$(_cpRET))\
$(eval _cpSEP :=)\
$(eval _cpLHS :=)\
$(eval _cpRET :=))
endef
# Sanity check for collapse-pairs.
ifneq (a=b c=d e= f=g h=,$(call collapse-pairs,a=b c= d e = f = g h=))
$(error collapse-pairs sanity check failure)
endif
ifneq (a:=b c:=d e:=f g:=h,$(call collapse-pairs,a:=b c:= d e :=f g := h,:=))
$(error collapse-pairs sanity check failure)
endif
###########################################################
## Given a list of pairs, if multiple pairs have the same
## first components, keep only the first pair.