8136383: Improve make utilities containing and not-containing
Reviewed-by: ihse
This commit is contained in:
parent
9969836a33
commit
8feb75af0b
@ -567,16 +567,22 @@ else
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Convenience functions for working around make's limitations with $(filter ).
|
|
||||||
containing = \
|
|
||||||
$(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),$v)))
|
|
||||||
not-containing = \
|
|
||||||
$(strip $(foreach v,$(strip $2),$(if $(findstring $(strip $1),$v),,$v)))
|
|
||||||
|
|
||||||
# Filter out duplicate sub strings while preserving order. Keeps the first occurance.
|
# Filter out duplicate sub strings while preserving order. Keeps the first occurance.
|
||||||
uniq = \
|
uniq = \
|
||||||
$(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
|
$(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
|
||||||
|
|
||||||
|
# Returns all whitespace-separated words in $2 where at least one of the
|
||||||
|
# whitespace-separated words in $1 is a substring.
|
||||||
|
containing = \
|
||||||
|
$(strip \
|
||||||
|
$(foreach v,$(strip $2),\
|
||||||
|
$(call uniq,$(foreach p,$(strip $1),$(if $(findstring $p,$v),$v)))))
|
||||||
|
|
||||||
|
# Returns all whitespace-separated words in $2 where none of the
|
||||||
|
# whitespace-separated words in $1 is a substring.
|
||||||
|
not-containing = \
|
||||||
|
$(strip $(filter-out $(call containing,$1,$2),$2))
|
||||||
|
|
||||||
# Return a list of all string elements that are duplicated in $1.
|
# Return a list of all string elements that are duplicated in $1.
|
||||||
dups = \
|
dups = \
|
||||||
$(strip $(foreach v, $(sort $1), $(if $(filter-out 1, \
|
$(strip $(foreach v, $(sort $1), $(if $(filter-out 1, \
|
||||||
|
@ -72,6 +72,37 @@ $(ESCAPE_DOLLAR_DIR)/_escape_dollar: $(DEPS)
|
|||||||
|
|
||||||
TEST_TARGETS += $(ESCAPE_DOLLAR_DIR)/_escape_dollar
|
TEST_TARGETS += $(ESCAPE_DOLLAR_DIR)/_escape_dollar
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# Test containing and not-containing
|
||||||
|
|
||||||
|
CONT_LIST := foo bar baz foobar foobaz
|
||||||
|
|
||||||
|
# Param 1 - string to look for
|
||||||
|
# Param 2 - expected result
|
||||||
|
define TestContaining
|
||||||
|
value := $$(call containing, $1, $(CONT_LIST))
|
||||||
|
ifneq ($$(value), $2)
|
||||||
|
$$(info (call containing, $1, $(CONT_LIST)))
|
||||||
|
$$(error result >$$(value)<, expected >$2<)
|
||||||
|
endif
|
||||||
|
endef
|
||||||
|
|
||||||
|
$(eval $(call TestContaining,bar,bar foobar))
|
||||||
|
$(eval $(call TestContaining,foo bar,foo bar foobar foobaz))
|
||||||
|
|
||||||
|
# Param 1 - string to look for
|
||||||
|
# Param 2 - expected result
|
||||||
|
define TestNotContaining
|
||||||
|
value := $$(call not-containing, $1, $(CONT_LIST))
|
||||||
|
ifneq ($$(value), $2)
|
||||||
|
$$(info (call not-containing, $1, $(CONT_LIST)))
|
||||||
|
$$(error result >$$(value)<, expected >$2<)
|
||||||
|
endif
|
||||||
|
endef
|
||||||
|
|
||||||
|
$(eval $(call TestNotContaining,bar,foo baz foobaz))
|
||||||
|
$(eval $(call TestNotContaining,foo bar,baz))
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Test Equals
|
# Test Equals
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user