Bug 743243 - Add isTargetStem makefile function. r=ted
authorJoey Armstrong <joey@mozilla.com>
Sat, 28 Apr 2012 11:16:12 -0400
changeset 92667 4f0b589036e4a6bdd79f1165a128031c151845ea
parent 92666 e4f72e3b1081daecf64de21a4e42cdf729bb4d3d
child 92668 d913b3d444e44dfa1d604aef22fbb29fc4c87284
push id8805
push userryanvm@gmail.com
push dateSat, 28 Apr 2012 15:20:16 +0000
treeherdermozilla-inbound@4f0b589036e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs743243
milestone15.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 743243 - Add isTargetStem makefile function. r=ted
config/makefiles/autotargets.mk
config/makefiles/makeutils.mk
config/makefiles/test/Makefile.in
config/makefiles/test/check_XinY.mk
js/src/config/makefiles/autotargets.mk
js/src/config/makefiles/makeutils.mk
--- a/config/makefiles/autotargets.mk
+++ b/config/makefiles/autotargets.mk
@@ -45,13 +45,10 @@ endif
 #################################################################
 # One ring/dep to rule them all:
 #   config/rules.mk::all target is available by default
 #   Add $(AUTO_DEPS) as an explicit target dependency when needed.
 #################################################################
 
 AUTO_DEPS +=$(GENERATED_DIRS_DEPS)
 
-
 # Complain loudly if deps have not loaded so getargv != $(NULL)
-ifndef getargv
-  $(error config/makefiles/makeutil.mk has not been included)
-endif
+$(call requiredfunction,getargv)
--- a/config/makefiles/makeutils.mk
+++ b/config/makefiles/makeutils.mk
@@ -1,22 +1,15 @@
 # -*- makefile -*-
 # vim:set ts=8 sw=8 sts=8 noet:
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
-# Usage: $(call banner,foo bar tans)
-banner =\
-$(info )\
-$(info ***************************************************************************)\
-$(info ** BANNER: $(1) $(2) $(3) $(4) $(5) $(6) $(7) $(8) $(9))\
-$(info ***************************************************************************)\
-
 ## Identify function argument types
 istype =$(if $(value ${1}),list,scalar)
 isval  =$(if $(filter-out list,$(call istype,${1})),true)
 isvar  =$(if $(filter-out scalar,$(call istype,${1})),true)
 
 # Access up to 9 arguments passed, option needed to emulate $*
 # Inline for function expansion, do not use $(call )
 argv  =$(strip
@@ -30,16 +23,72 @@ argv +=)
 ## Access function args as a simple list, inline within user functions.
 ## Usage: $(info ** $(call banner,$(getargv)))
 ##    $(call banner,scalar)
 ##    $(call banner,list0 list1 list2)
 ##    $(call banner,ref) ; ref=foo bar tans
 ## getarglist() would be a more accurate name but is longer to type
 getargv = $(if $(call isvar,$(1)),$($(1)),$(argv))
 
+###########################################################################
+# Strip [n] leading options from an argument list.  This will allow passing
+# extra args to user functions that will not propogate to sub-$(call )'s
+# Usage: $(call subargv,2)
+subargv =$(wordlist $(1),$(words $(getargv)),$(getargv))
+
+###########################################################################
+# Intent: Display a distinct banner heading in the output stream
+# Usage: $(call banner,BUILDING: foo bar tans)
+# Debug:
+#   target-preqs = \
+#     $(call banner,target-preqs-BEGIN) \
+#     foo bar tans \
+#     $(call banner,target-preqs-END) \
+#     $(NULL)
+#   target: $(target-preqs)
+
+banner =\
+$(info )\
+$(info ***************************************************************************)\
+$(info ** $(getargv))\
+$(info ***************************************************************************)\
+$(NULL)
+
+#####################################################################
+# Intent: Determine if a string or pattern is contained in a list
+# Usage: strcmp  - $(call if_XinY,clean,$(MAKECMDGOALS))
+#      : pattern - $(call if_XinY,clean%,$(MAKECMDGOALS))
+is_XinY =$(filter $(1),$(call subargv,3,$(getargv)))
+
+#####################################################################
+# Provide an alternate var to support testing
+ifdef MAKEUTILS_UNIT_TEST
+  mcg_goals=TEST_MAKECMDGOALS
+else
+  mcg_goals=MAKECMDGOALS
+endif
+
+# Intent: Conditionals for detecting common/tier target use
+#   Todo: are check, install, test needed ?
+isTargetStem       = $(sort $(foreach pat, $(1)% %$(1), $(call is_XinY,$(pat),${$(mcg_goals)})))
+isTargetStemClean  = $(call isTargetStem,clean)
+isTargetStemExport = $(call isTargetStem,export)
+isTargetStemLibs   = $(call isTargetStem,libs)
+isTargetStemTools  = $(call isTargetStem,tools)
+
+##################################################
+# Intent: Validation functions / unit test helpers
+
+errorifneq =$(if $(subst $(strip $(1)),$(NULL),$(strip $(2))),$(error expected [$(1)] but found [$(2)]))
+
+# Intent: verify function declaration exists
+requiredfunction =$(foreach func,$(1) $(2) $(3) $(4) $(5) $(6) $(7) $(8) $(9),$(if $(value $(func)),$(NULL),$(error required function [$(func)] is unavailable)))
+
+
+
 ## http://www.gnu.org/software/make/manual/make.html#Call-Function
 ## Usage: o = $(call map,origin,o map $(MAKE))
 map = $(foreach val,$(2),$(call $(1),$(val)))
 
 
 ## Disable checking for clean targets
 ifeq (,$(filter %clean clean%,$(MAKECMDGOALS)))
 
--- a/config/makefiles/test/Makefile.in
+++ b/config/makefiles/test/Makefile.in
@@ -5,16 +5,18 @@
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 DEPTH     = ../../..
 topsrcdir = @top_srcdir@
 srcdir    = @srcdir@
 VPATH     = @srcdir@
 
 include $(DEPTH)/config/autoconf.mk
+
+MAKEUTILS_UNIT_TEST = 1
 include $(topsrcdir)/config/makefiles/makeutils.mk
 
 ##------------------_##
 ##---]  TARGETS  [---##
 ##------------------_##
 all::
 
 ###########################################################################
@@ -24,37 +26,41 @@ all::
 ## very handy for testing when pwd==$src/ but for now avoid the overhead.
 ##
 ## Test logic will be interpreted at compile time, 'fast' and 'required' so
 ## the test will always be run when testing is enabled.
 ###########################################################################
 check::
 	@true
 
+###########################################################################
 ## Logic processed at compile time so be selective about when to test
-ifneq ($(NULL),$(findstring check,$(MAKECMDGOALS))) #{
-
+## Verify istype, isval, isvar, getargv, subargv
+ifneq ($(NULL),$(findstring check,$(MAKECMDGOALS))) #
 
 ifdef VERBOSE
 
 $(info ===========================================================================)
 $(info Running test: $(MAKECMDGOALS): pwd=$(CURDIR))
 $(info ===========================================================================)
 
 $(info )
 $(info ===========================================================================)
 $(info Running test: istype, getargv)
 $(info ===========================================================================)
 endif
 
-## Silent errors are oh so much fun
-ifndef istype
-  $(error makeutils.mk was not included)
+ifndef requiredfunction
+  $(error requiredfunction is not defined)
 endif
 
+include $(topsrcdir)/config/makefiles/test/check_XinY.mk
+
+$(call requiredfunc,istype isvar isval)
+
 # arg_scalar = [scalar|literal]
 arg_list = foo bar
 arg_ref  = arg_list
 
 ## Identify type of function argument(s)
 ########################################
 ifneq (scalar,$(call istype,arg_scalar))
   $(error istype(arg_scalar)=scalar, found [$(call istype,arg_scalar)])
@@ -119,9 +125,18 @@ ifdef MANUAL_TEST #{
   xyz=abc
   $(info STATUS: warnIfEmpty - two vars)
   $(call warnIfEmpty,foo xyz bar)
   $(info STATUS: errorIfEmpty - on first var)
   $(call errorIfEmpty,foo xyz bar)
   $(error TEST FAILED: processing should not reach this point)
 endif #}
 
-endif #} check in MAKECMDGOALS
+# Verify subargv expansion
+##########################
+subargs=foo bar tans fans
+subargs_exp=tans fans
+subargs_found=$(call subargv,4,$(subargs))
+ifneq ($(subargs_exp),$(subargs_found))
+  $(error subargv(4,$(subargs)): expected [$(subargs_exp)] found [$(subargs_found)])
+endif
+ 
+endif #} unit_test: istype, isvar, isval, getargv, subargv
new file mode 100644
--- /dev/null
+++ b/config/makefiles/test/check_XinY.mk
@@ -0,0 +1,47 @@
+# -*- makefile -*-
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this file,
+# You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# Verify dependencies are available
+$(call requiredfunction,getargv subargv is_XinY errorifneq)
+
+#############################
+ifdef VERBOSE
+  $(warning )
+  $(call banner,Unit test: is_XinY)
+endif
+
+zero := 0
+one  := 1
+
+# Verify 'invalid' is not matched
+val  := invalid
+$(call errorifneq,$(zero),$(words $(call is_XinY,foo,$(val))))
+$(call errorifneq,$(zero),$(words $(call is_XinY,clean,$(val))))
+$(call errorifneq,$(zero),$(words $(call is_XinY,clean%,$(val))))
+
+# verify strcmp('clean')
+val  := clean
+$(call errorifneq,$(zero),$(words $(call is_XinY,foo,$(val))))
+$(call errorifneq,$(one),$(words $(call is_XinY,clean,$(val))))
+$(call errorifneq,$(one,$(words $(call is_XinY,clean%,$(val)))))
+$(call errorifneq,$(one),$(words $(call is_XinY,%clean,$(val))))
+
+# List match for 'clean'
+val     := blah clean distclean FcleanG clean-level-1
+wanted  := clean distclean clean-level-1
+$(call errorifneq,$(zero),$(words $(call is_XinY_debug,foo,$(val))))
+$(call errorifneq,$(one),$(words $(call is_XinY,clean,$(val))))
+$(call errorifneq,$(one),$(words $(call is_XinY,distclean,$(val))))
+
+# pattern match 'clean'
+#     match: clean, distclean, clean-level-1
+#   exclude: FcleanG
+TEST_MAKECMDGOALS := $(val)
+$(call errorifneq,3,$(words $(call isTargetStemClean)))
+
+TEST_MAKECMDGOALS := invalid
+$(call errorifneq,$(zero),$(words $(call isTargetStemClean)))
+
--- a/js/src/config/makefiles/autotargets.mk
+++ b/js/src/config/makefiles/autotargets.mk
@@ -45,13 +45,10 @@ endif
 #################################################################
 # One ring/dep to rule them all:
 #   config/rules.mk::all target is available by default
 #   Add $(AUTO_DEPS) as an explicit target dependency when needed.
 #################################################################
 
 AUTO_DEPS +=$(GENERATED_DIRS_DEPS)
 
-
 # Complain loudly if deps have not loaded so getargv != $(NULL)
-ifndef getargv
-  $(error config/makefiles/makeutil.mk has not been included)
-endif
+$(call requiredfunction,getargv)
--- a/js/src/config/makefiles/makeutils.mk
+++ b/js/src/config/makefiles/makeutils.mk
@@ -1,22 +1,15 @@
 # -*- makefile -*-
 # vim:set ts=8 sw=8 sts=8 noet:
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
-# Usage: $(call banner,foo bar tans)
-banner =\
-$(info )\
-$(info ***************************************************************************)\
-$(info ** BANNER: $(1) $(2) $(3) $(4) $(5) $(6) $(7) $(8) $(9))\
-$(info ***************************************************************************)\
-
 ## Identify function argument types
 istype =$(if $(value ${1}),list,scalar)
 isval  =$(if $(filter-out list,$(call istype,${1})),true)
 isvar  =$(if $(filter-out scalar,$(call istype,${1})),true)
 
 # Access up to 9 arguments passed, option needed to emulate $*
 # Inline for function expansion, do not use $(call )
 argv  =$(strip
@@ -30,16 +23,72 @@ argv +=)
 ## Access function args as a simple list, inline within user functions.
 ## Usage: $(info ** $(call banner,$(getargv)))
 ##    $(call banner,scalar)
 ##    $(call banner,list0 list1 list2)
 ##    $(call banner,ref) ; ref=foo bar tans
 ## getarglist() would be a more accurate name but is longer to type
 getargv = $(if $(call isvar,$(1)),$($(1)),$(argv))
 
+###########################################################################
+# Strip [n] leading options from an argument list.  This will allow passing
+# extra args to user functions that will not propogate to sub-$(call )'s
+# Usage: $(call subargv,2)
+subargv =$(wordlist $(1),$(words $(getargv)),$(getargv))
+
+###########################################################################
+# Intent: Display a distinct banner heading in the output stream
+# Usage: $(call banner,BUILDING: foo bar tans)
+# Debug:
+#   target-preqs = \
+#     $(call banner,target-preqs-BEGIN) \
+#     foo bar tans \
+#     $(call banner,target-preqs-END) \
+#     $(NULL)
+#   target: $(target-preqs)
+
+banner =\
+$(info )\
+$(info ***************************************************************************)\
+$(info ** $(getargv))\
+$(info ***************************************************************************)\
+$(NULL)
+
+#####################################################################
+# Intent: Determine if a string or pattern is contained in a list
+# Usage: strcmp  - $(call if_XinY,clean,$(MAKECMDGOALS))
+#      : pattern - $(call if_XinY,clean%,$(MAKECMDGOALS))
+is_XinY =$(filter $(1),$(call subargv,3,$(getargv)))
+
+#####################################################################
+# Provide an alternate var to support testing
+ifdef MAKEUTILS_UNIT_TEST
+  mcg_goals=TEST_MAKECMDGOALS
+else
+  mcg_goals=MAKECMDGOALS
+endif
+
+# Intent: Conditionals for detecting common/tier target use
+#   Todo: are check, install, test needed ?
+isTargetStem       = $(sort $(foreach pat, $(1)% %$(1), $(call is_XinY,$(pat),${$(mcg_goals)})))
+isTargetStemClean  = $(call isTargetStem,clean)
+isTargetStemExport = $(call isTargetStem,export)
+isTargetStemLibs   = $(call isTargetStem,libs)
+isTargetStemTools  = $(call isTargetStem,tools)
+
+##################################################
+# Intent: Validation functions / unit test helpers
+
+errorifneq =$(if $(subst $(strip $(1)),$(NULL),$(strip $(2))),$(error expected [$(1)] but found [$(2)]))
+
+# Intent: verify function declaration exists
+requiredfunction =$(foreach func,$(1) $(2) $(3) $(4) $(5) $(6) $(7) $(8) $(9),$(if $(value $(func)),$(NULL),$(error required function [$(func)] is unavailable)))
+
+
+
 ## http://www.gnu.org/software/make/manual/make.html#Call-Function
 ## Usage: o = $(call map,origin,o map $(MAKE))
 map = $(foreach val,$(2),$(call $(1),$(val)))
 
 
 ## Disable checking for clean targets
 ifeq (,$(filter %clean clean%,$(MAKECMDGOALS)))