summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
author Youkichi Hosoi <youkichihosoi@google.com> 2020-04-01 05:07:24 +0900
committer Youkichi Hosoi <youkichihosoi@google.com> 2020-04-02 03:34:49 +0900
commitf6652f4f186d11df7b09965e16fc850516962d8e (patch)
tree78dd21a80c856b0c0f2b02e3aceb49284d41aeb7 /common
parent63a16b56ee23744762e7d88c39d3fe191f2d2a91 (diff)
strings.mk: Allow empty RHS values for inputs of collapse-pairs
This CL is to make the function collapse-pairs(), which is applied to lists of "property=value" pairs, allow empty properties (i.e. lines of the form "empty.prop="). Currently, the function only allows empty properties at the end (see https://android-review.googlesource.com/c/platform/build/+/722908). So empty properties in the middle result in broken property files (e.g. "a=b c= d=e" is transformed to "a=b c=d=e", in which the property "c", which originally has no value, is interpreted as having the value "d=e", whereas the property "d", which originally has the value "e", is missing from the resulting property file). This CL revises the function so as to keep empty properties in the middle as is (e.g. it returns "a=b c= d=e" for the above example), while preserving the behavior for well-formed lists like "a=b c= d e = f". Bug: 152379493 Test: make Change-Id: I35faeaedc3bc42e56e01201baf7ea6805a610439
Diffstat (limited to 'common')
-rw-r--r--common/strings.mk24
1 files changed, 21 insertions, 3 deletions
diff --git a/common/strings.mk b/common/strings.mk
index ce6d6fbe9f..ba20e272c0 100644
--- a/common/strings.mk
+++ b/common/strings.mk
@@ -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.