From c1d82ba7e9f9325062a265a892b1c7bad89fffa8 Mon Sep 17 00:00:00 2001 From: zvecr Date: Sat, 22 Jan 2022 06:06:58 +0000 Subject: [PATCH 1/3] Bodge for recursive rule matching --- Makefile | 54 ++++++++++++------------------------------------------ 1 file changed, 12 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 88f430619e39..95071672ea55 100644 --- a/Makefile +++ b/Makefile @@ -119,54 +119,24 @@ endef # a function that returns the value COMPARE_AND_REMOVE_FROM_RULE = $(eval $(call COMPARE_AND_REMOVE_FROM_RULE_HELPER,$1))$(RULE_FOUND) - -# Recursively try to find a match for the start of the rule to be checked -# $1 The list to be checked -# If a match is found, then RULE_FOUND is set to true -# and MATCHED_ITEM to the item that was matched -define TRY_TO_MATCH_RULE_FROM_LIST_HELPER3 - ifneq ($1,) - ifeq ($$(call COMPARE_AND_REMOVE_FROM_RULE,$$(firstword $1)),true) - MATCHED_ITEM := $$(firstword $1) - else - $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER3,$$(wordlist 2,9999,$1))) - endif - endif -endef - -# A recursive helper function for finding the longest match -# $1 The list to be checked -# It works by always removing the currently matched item from the list -define TRY_TO_MATCH_RULE_FROM_LIST_HELPER2 - # Stop the recursion when the list is empty - ifneq ($1,) - RULE_BEFORE := $$(RULE) - $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER3,$1)) - # If a match is found in the current list, otherwise just return what we had before - ifeq ($$(RULE_FOUND),true) - # Save the best match so far and call itself recursively - BEST_MATCH := $$(MATCHED_ITEM) - BEST_MATCH_RULE := $$(RULE) - RULE_FOUND := false - RULE := $$(RULE_BEFORE) - $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER2,$$(filter-out $$(MATCHED_ITEM),$1))) - endif - endif -endef - - -# Recursively try to find the longest match for the start of the rule to be checked +# Try to find the longest match for the start of the rule to be checked # $1 The list to be checked # If a match is found, then RULE_FOUND is set to true # and MATCHED_ITEM to the item that was matched define TRY_TO_MATCH_RULE_FROM_LIST_HELPER - BEST_MATCH := - $$(eval $$(call TRY_TO_MATCH_RULE_FROM_LIST_HELPER2,$1)) - ifneq ($$(BEST_MATCH),) + # $$(info R $$(RULE)) + TOKEN1:=$$(shell python -c "import sys; print((sys.argv[1].split(':',1)+[''])[0])" $$(RULE)) + TOKENr:=$$(shell python -c "import sys; print((sys.argv[1].split(':',1)+[''])[1])" $$(RULE)) + # $$(info TOKEN1 $$(TOKEN1) TOKENr $$(TOKENr)) + FOUNDx:=$$(shell echo $1 | tr " " "\n" | grep -Fx $$(TOKEN1)) + # $$(info $$(FOUNDx)) + ifneq ($$(FOUNDx),) + BEST_MATCH := $$(FOUNDx) + RULE := $$(TOKENr) RULE_FOUND := true - RULE := $$(BEST_MATCH_RULE) - MATCHED_ITEM := $$(BEST_MATCH) + MATCHED_ITEM := $$(FOUNDx) else + BEST_MATCH := RULE_FOUND := false MATCHED_ITEM := endif From a79432b033b83691e713c58846cbd809be9eda95 Mon Sep 17 00:00:00 2001 From: zvecr Date: Sat, 22 Jan 2022 06:08:00 +0000 Subject: [PATCH 2/3] Bodge for recursive rule matching - force python3 --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 95071672ea55..20a740ee7831 100644 --- a/Makefile +++ b/Makefile @@ -125,8 +125,8 @@ COMPARE_AND_REMOVE_FROM_RULE = $(eval $(call COMPARE_AND_REMOVE_FROM_RULE_HELPER # and MATCHED_ITEM to the item that was matched define TRY_TO_MATCH_RULE_FROM_LIST_HELPER # $$(info R $$(RULE)) - TOKEN1:=$$(shell python -c "import sys; print((sys.argv[1].split(':',1)+[''])[0])" $$(RULE)) - TOKENr:=$$(shell python -c "import sys; print((sys.argv[1].split(':',1)+[''])[1])" $$(RULE)) + TOKEN1:=$$(shell python3 -c "import sys; print((sys.argv[1].split(':',1)+[''])[0])" $$(RULE)) + TOKENr:=$$(shell python3 -c "import sys; print((sys.argv[1].split(':',1)+[''])[1])" $$(RULE)) # $$(info TOKEN1 $$(TOKEN1) TOKENr $$(TOKENr)) FOUNDx:=$$(shell echo $1 | tr " " "\n" | grep -Fx $$(TOKEN1)) # $$(info $$(FOUNDx)) From bacbb575f517d62360c6ff70e6dd8a1d7574f4d4 Mon Sep 17 00:00:00 2001 From: zvecr Date: Sun, 23 Jan 2022 02:18:14 +0000 Subject: [PATCH 3/3] Tidy up --- Makefile | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 20a740ee7831..5503d5a3ae0d 100644 --- a/Makefile +++ b/Makefile @@ -119,24 +119,21 @@ endef # a function that returns the value COMPARE_AND_REMOVE_FROM_RULE = $(eval $(call COMPARE_AND_REMOVE_FROM_RULE_HELPER,$1))$(RULE_FOUND) -# Try to find the longest match for the start of the rule to be checked +# Try to find a match for the start of the rule to be checked # $1 The list to be checked # If a match is found, then RULE_FOUND is set to true # and MATCHED_ITEM to the item that was matched define TRY_TO_MATCH_RULE_FROM_LIST_HELPER - # $$(info R $$(RULE)) + # Split on ":", padding with empty strings to avoid indexing issues TOKEN1:=$$(shell python3 -c "import sys; print((sys.argv[1].split(':',1)+[''])[0])" $$(RULE)) TOKENr:=$$(shell python3 -c "import sys; print((sys.argv[1].split(':',1)+[''])[1])" $$(RULE)) - # $$(info TOKEN1 $$(TOKEN1) TOKENr $$(TOKENr)) + FOUNDx:=$$(shell echo $1 | tr " " "\n" | grep -Fx $$(TOKEN1)) - # $$(info $$(FOUNDx)) ifneq ($$(FOUNDx),) - BEST_MATCH := $$(FOUNDx) RULE := $$(TOKENr) RULE_FOUND := true - MATCHED_ITEM := $$(FOUNDx) + MATCHED_ITEM := $$(TOKEN1) else - BEST_MATCH := RULE_FOUND := false MATCHED_ITEM := endif