8212587: equals in MakeBase does not handle empty strings correctly
Reviewed-by: erikj
--- a/make/common/MakeBase.gmk Wed Oct 17 21:51:00 2018 -0700
+++ b/make/common/MakeBase.gmk Thu Oct 18 09:19:29 2018 +0200
@@ -656,8 +656,11 @@
# String equals
equals = \
- $(and $(findstring $(strip $1),$(strip $2)),\
- $(findstring $(strip $2),$(strip $1)))
+ $(if $(strip $1)$(strip $2),$(strip \
+ $(and $(findstring $(strip $1),$(strip $2)),\
+ $(findstring $(strip $2),$(strip $1)))), \
+ true \
+ )
# Remove a whole list of prefixes
# $1 - List of prefixes
--- a/test/make/TestMakeBase.gmk Wed Oct 17 21:51:00 2018 -0700
+++ b/test/make/TestMakeBase.gmk Thu Oct 18 09:19:29 2018 +0200
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# This code is free software; you can redistribute it and/or modify it
@@ -93,6 +93,7 @@
EQUALS_VALUE1 := value1$(SPACE)
EQUALS_VALUE2 := value2
+EQUALS_EMPTY :=
ifneq ($(call equals, $(EQUALS_VALUE1), $(EQUALS_VALUE2)), )
$(error The strings >$(EQUALS_VALUE1)< and >$(EQUALS_VALUE2)< are equal)
@@ -102,6 +103,18 @@
$(error The strings >$(EQUALS_VALUE1)< and >$(EQUALS_VALUE1)< are not equal)
endif
+ifeq ($(call equals, $(EQUALS_EMPTY), $(EQUALS_EMPTY)), )
+ $(error The strings >$(EQUALS_EMPTY)< and >$(EQUALS_EMPTY)< are not equal)
+endif
+
+ifneq ($(call equals, $(EQUALS_EMPTY), $(EQUALS_VALUE2)), )
+ $(error The strings >$(EQUALS_EMPTY)< and >$(EQUALS_VALUE2)< are equal)
+endif
+
+ifneq ($(call equals, $(EQUALS_VALUE2), $(EQUALS_EMPTY)), )
+ $(error The strings >$(EQUALS_VALUE2)< and >$(EQUALS_EMPTY)< are equal)
+endif
+
################################################################################
# Test remove-prefixes