mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 743243 - Add isTargetStem makefile function. r=ted
This commit is contained in:
parent
426bc7fa7f
commit
df698ab2be
@ -50,8 +50,5 @@ endif
|
||||
|
||||
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)
|
||||
|
@ -5,13 +5,6 @@
|
||||
# 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)
|
||||
@ -35,6 +28,62 @@ argv +=)
|
||||
## 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)))
|
||||
|
@ -10,6 +10,8 @@ srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MAKEUTILS_UNIT_TEST = 1
|
||||
include $(topsrcdir)/config/makefiles/makeutils.mk
|
||||
|
||||
##------------------_##
|
||||
@ -29,9 +31,10 @@ all::
|
||||
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
|
||||
|
||||
@ -45,11 +48,14 @@ $(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
|
||||
@ -124,4 +130,13 @@ ifdef MANUAL_TEST #{
|
||||
$(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
|
||||
|
47
config/makefiles/test/check_XinY.mk
Normal file
47
config/makefiles/test/check_XinY.mk
Normal file
@ -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)))
|
||||
|
@ -50,8 +50,5 @@ endif
|
||||
|
||||
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)
|
||||
|
@ -5,13 +5,6 @@
|
||||
# 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)
|
||||
@ -35,6 +28,62 @@ argv +=)
|
||||
## 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)))
|
||||
|
Loading…
Reference in New Issue
Block a user