bug 753939: makeutils.mk .mk loading logic with unit tests r=ted

This commit is contained in:
Joey Armstrong 2012-05-11 11:47:29 -07:00
parent 7904cc3ec4
commit 3b6a3febef
8 changed files with 226 additions and 109 deletions

View File

@ -21,8 +21,9 @@ TOUCH ?= touch
###########################################################################
# Threadsafe directory creation
# GENERATED_DIRS - Automated creation of these directories.
# Squeeze '//' from the path, easily created by $(dir $(path))
###########################################################################
mkdir_deps =$(foreach dir,$(getargv),$(dir)/.mkdir.done)
mkdir_deps =$(subst //,/,$(foreach dir,$(getargv),$(dir)/.mkdir.done))
%/.mkdir.done: # mkdir -p -p => mkdir -p
$(subst $(SPACE)-p,$(null),$(MKDIR)) -p $(dir $@)
@ -42,7 +43,7 @@ endif #}
ifneq (,$(GENERATED_DIRS))
tmpauto :=$(call mkdir_deps,GENERATED_DIRS)
GENERATED_DIRS_DEPS +=$(tmpauto)
GARBAGE_DIRS +=$(tmpauto)
GARBAGE_DIRS +=$(GENERATED_DIRS)
endif
#################################################################

View File

@ -90,7 +90,7 @@ map = $(foreach val,$(2),$(call $(1),$(val)))
## Disable checking for clean targets
ifeq (,$(filter %clean clean%,$(MAKECMDGOALS)))
ifeq (,$(filter %clean clean%,$(MAKECMDGOALS))) #{
# Usage: $(call checkIfEmpty,[error|warning] foo NULL bar)
checkIfEmpty =$(foreach var,$(wordlist 2,100,$(argv)),$(if $(strip $($(var))),$(NOP),$(call $(1),Variable $(var) does not contain a value)))
@ -99,4 +99,13 @@ checkIfEmpty =$(foreach var,$(wordlist 2,100,$(argv)),$(if $(strip $($(var))),$(
errorIfEmpty =$(call checkIfEmpty,error $(argv))
warnIfEmpty =$(call checkIfEmpty,warning $(argv))
endif #}
###########################################################################
## Common makefile library loader
###########################################################################
topORerr =$(if $(topsrcdir),$(topsrcdir),$(error topsrcdir is not defined))
ifdef USE_AUTOTARGETS_MK # mkdir_deps
include $(topORerr)/config/makefiles/autotargets.mk
endif

View File

@ -14,129 +14,90 @@ include $(DEPTH)/config/autoconf.mk
MAKEUTILS_UNIT_TEST = 1
include $(topsrcdir)/config/makefiles/makeutils.mk
dir-ts = .deps/test
check-arglist = $(dir-ts)/arglist.ts
check-autotargets = $(dir-ts)/autotargets_mk.ts
check-XinY = $(dir-ts)/check_XinY_mk.ts
check-tests =\
$(check-arglist) \
$(check-autotargets) \
$(check-XinY) \
$(NULL)
##------------------_##
##---] TARGETS [---##
##------------------_##
all::
###########################################################################
## This test target should really depend on a timestamp to only perform
## work when makeutils.mk is modified. That answer would require using a
## 2nd makefile imposing more shell overhead. Separate makefiles would be
## 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
clean:
$(RM) $(check-tests)
###########################################################################
## Logic processed at compile time so be selective about when to test
## Verify istype, isval, isvar, getargv, subargv
## $(MAKE) check VERBOSE=1
ifneq ($(NULL),$(findstring check,$(MAKECMDGOALS))) #
ifdef VERBOSE
check-preqs =\
$(call mkdir_deps,$(dir-ts)) \
$(check-tests) \
$(NULL)
$(info ===========================================================================)
$(info Running test: $(MAKECMDGOALS): pwd=$(CURDIR))
$(info ===========================================================================)
check:: $(check-preqs)
@true
$(info )
$(info ===========================================================================)
$(info Running test: istype, getargv)
$(info ===========================================================================)
endif
ifdef VERBOSE #{ gmake check VERBOSE=1
$(info ===========================================================================)
$(info Running test: $(MAKECMDGOALS): pwd=$(CURDIR))
$(info ===========================================================================)
endif #}
ifndef requiredfunction
$(error requiredfunction is not defined)
endif
include $(topsrcdir)/config/makefiles/test/check_XinY.mk
$(call requiredfunc,istype isvar isval)
##################
check-XinY-preqs=\
$(call mkdir_deps,$(dir-ts)) \
$(topsrcdir)/config/makefiles/makeutils.mk \
$(srcdir)/check_XinY.mk \
$(eval include $(srcdir)/check_XinY.mk) \
$(NULL)
# arg_scalar = [scalar|literal]
arg_list = foo bar
arg_ref = arg_list
$(check-XinY): $(check-XinY-preqs)
@$(TOUCH) $@
# </check-XinY.mk>
## Identify type of function argument(s)
########################################
ifneq (scalar,$(call istype,arg_scalar))
$(error istype(arg_scalar)=scalar, found [$(call istype,arg_scalar)])
endif
ifneq (list,$(call istype,arg_list))
$(error istype(arg_list)=list, found [$(call istype,arg_list)])
endif
ifneq (list,$(call istype,arg_ref))
$(error istype(arg_ref)=list, found [$(call istype,arg_ref)])
endif
## Type == scalar or a list of values
#####################################
ifneq (true,$(call isval,scalar))
$(error isval(scalar)=true, found [$(call isval,scalar)])
endif
ifneq ($(NULL),$(call isval,arg_list))
$(error isval(arg_list)=null, found [$(call isval,arg_list)])
endif
###########################################################################
## check-arglist.mk always invoked as a compile time test
## maintain real file dependencies for use later on.
check-arglist-preqs=\
$(call mkdir_deps,$(dir-ts)) \
$(topsrcdir)/config/makefiles/makeutils.mk \
$(srcdir)/check-arglist.mk \
$(eval include $(srcdir)/check-arglist.mk) \
$(NULL)
## type == reference: macro=>macro => $($(1))
#############################################
ifneq ($(NULL),$(call isvar,scalar))
$(error isvar(scalar)=$(NULL), found [$(call isvar,scalar)])
endif
ifneq (true,$(call isvar,arg_list))
$(error isvar(arg_list)=true, found [$(call isvar,arg_list)])
endif
ifneq (true,$(call isvar,arg_ref))
$(error isvar(arg_ref)=true, found [$(call isvar,arg_ref)])
endif
$(check-arglist): $(check-arglist-preqs)
@$(TOUCH) $@
# </check-arglist.mk>
# Verify getargv expansion
##########################
ifneq (scalar,$(call getargv,scalar))
$(error getargv(scalar)=scalar, found [$(call getargv,scalar)])
endif
ifneq ($(arg_list),$(call getargv,arg_list))
$(error getargv(arg_list)=list, found [$(call getargv,arg_list)])
endif
ifneq (arg_list,$(call getargv,arg_ref))
$(error getargv(arg_ref)=list, found [$(call getargv,arg_ref)])
endif
ifdef MANUAL_TEST #{
# For automated testing a callback is needed that can set an external status
# variable that can be tested. Syntax is tricky to get correct functionality.
ifdef VERBOSE
$(info )
$(info ===========================================================================)
$(info Running test: checkIfEmpty)
$(info ===========================================================================)
endif
###########################################################################
# <CHECK: autotargets.mk>
check-autotargets-preqs=\
$(call mkdir_deps,$(dir-ts)) \
$(topsrcdir)/config/makefiles/makeutils.mk \
$(topsrcdir)/config/makefiles/autotargets.mk \
$(srcdir)/check-autotargets.mk \
$(eval include $(srcdir)/check-autotargets.mk) \
$(NULL)
#status =
#setTRUE =status=true
#setFALSE =status=$(NULL)
#$(call checkIfEmpty,setFALSE NULL)
#$(if $(status),$(error checkIfEmpty(xyz) failed))
#$(call checkIfEmpty,setTRUE xyz)
#$(if $(status),$(error checkIfEmpty(xyz) failed))
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 #}
$(check-autotargets): $(check-autotargets-preqs)
@$(TOUCH) $@
# </CHECK: autotargets.mk>
# 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
endif #} findstring check

View File

@ -0,0 +1,100 @@
# -*- 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/.
ifdef VERBOSE
$(warning loading test)
endif
$(call requiredfunction,getargv)
$(call requiredfunction,subargv)
$(call requiredfunction,istype isval isvar)
# 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)])
endif
ifneq (list,$(call istype,arg_list))
$(error istype(arg_list)=list, found [$(call istype,arg_list)])
endif
ifneq (list,$(call istype,arg_ref))
$(error istype(arg_ref)=list, found [$(call istype,arg_ref)])
endif
## Type == scalar or a list of values
#####################################
ifneq (true,$(call isval,scalar))
$(error isval(scalar)=true, found [$(call isval,scalar)])
endif
ifneq ($(NULL),$(call isval,arg_list))
$(error isval(arg_list)=null, found [$(call isval,arg_list)])
endif
## type == reference: macro=>macro => $($(1))
#############################################
ifneq ($(NULL),$(call isvar,scalar))
$(error isvar(scalar)=$(NULL), found [$(call isvar,scalar)])
endif
ifneq (true,$(call isvar,arg_list))
$(error isvar(arg_list)=true, found [$(call isvar,arg_list)])
endif
ifneq (true,$(call isvar,arg_ref))
$(error isvar(arg_ref)=true, found [$(call isvar,arg_ref)])
endif
# Verify getargv expansion
##########################
ifneq (scalar,$(call getargv,scalar))
$(error getargv(scalar)=scalar, found [$(call getargv,scalar)])
endif
ifneq ($(arg_list),$(call getargv,arg_list))
$(error getargv(arg_list)=list, found [$(call getargv,arg_list)])
endif
ifneq (arg_list,$(call getargv,arg_ref))
$(error getargv(arg_ref)=list, found [$(call getargv,arg_ref)])
endif
###########################################################################
##
###########################################################################
ifdef MANUAL_TEST #{
# For automated testing a callback is needed that can set an external status
# variable that can be tested. Syntax is tricky to get correct functionality.
ifdef VERBOSE
$(info )
$(info ===========================================================================)
$(info Running test: checkIfEmpty)
$(info ===========================================================================)
endif
#status =
#setTRUE =status=true
#setFALSE =status=$(NULL)
#$(call checkIfEmpty,setFALSE NULL)
#$(if $(status),$(error checkIfEmpty(xyz) failed))
#$(call checkIfEmpty,setTRUE xyz)
#$(if $(status),$(error checkIfEmpty(xyz) failed))
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 #}
# 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

View File

@ -0,0 +1,38 @@
# -*- 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/.
ifdef VERBOSE
$(warning loading test)
endif
GENERATED_DIRS = bogus # test data
undefine USE_AUTOTARGETS_MK
undefine INCLUDED_AUTOTARGETS_MK
include $(topsrcdir)/config/makefiles/autotargets.mk
ifndef INCLUDED_AUTOTARGETS_MK
$(error autotargets.mk was not included
endif
$(call requiredfunction,mkdir_deps)
# Verify test data populated makefile vars correctly
vars = AUTO_DEPS GARBAGE_DIRS GENERATED_DIRS_DEPS
$(foreach var,$(vars),$(call errorIfEmpty,$(var)))
# Data should also be valid
ifneq (bogus,$(findstring bogus,$(AUTO_DEPS)))
$(error AUTO_DEPS=[$(AUTO_DEPS)] is not set correctly)
endif
path = foo/bar.c
exp = foo/.mkdir.done
found = $(call mkdir_deps,$(dir $(path)))
ifneq ($(exp),$(found))
$(error mkdir_deps($(path))=$(exp) not set correctly [$(found)])
endif

View File

@ -7,10 +7,8 @@
# Verify dependencies are available
$(call requiredfunction,getargv subargv is_XinY errorifneq)
#############################
ifdef VERBOSE
$(warning )
$(call banner,Unit test: is_XinY)
$(warning loading test)
endif
zero := 0

View File

@ -21,8 +21,9 @@ TOUCH ?= touch
###########################################################################
# Threadsafe directory creation
# GENERATED_DIRS - Automated creation of these directories.
# Squeeze '//' from the path, easily created by $(dir $(path))
###########################################################################
mkdir_deps =$(foreach dir,$(getargv),$(dir)/.mkdir.done)
mkdir_deps =$(subst //,/,$(foreach dir,$(getargv),$(dir)/.mkdir.done))
%/.mkdir.done: # mkdir -p -p => mkdir -p
$(subst $(SPACE)-p,$(null),$(MKDIR)) -p $(dir $@)
@ -42,7 +43,7 @@ endif #}
ifneq (,$(GENERATED_DIRS))
tmpauto :=$(call mkdir_deps,GENERATED_DIRS)
GENERATED_DIRS_DEPS +=$(tmpauto)
GARBAGE_DIRS +=$(tmpauto)
GARBAGE_DIRS +=$(GENERATED_DIRS)
endif
#################################################################

View File

@ -90,7 +90,7 @@ map = $(foreach val,$(2),$(call $(1),$(val)))
## Disable checking for clean targets
ifeq (,$(filter %clean clean%,$(MAKECMDGOALS)))
ifeq (,$(filter %clean clean%,$(MAKECMDGOALS))) #{
# Usage: $(call checkIfEmpty,[error|warning] foo NULL bar)
checkIfEmpty =$(foreach var,$(wordlist 2,100,$(argv)),$(if $(strip $($(var))),$(NOP),$(call $(1),Variable $(var) does not contain a value)))
@ -99,4 +99,13 @@ checkIfEmpty =$(foreach var,$(wordlist 2,100,$(argv)),$(if $(strip $($(var))),$(
errorIfEmpty =$(call checkIfEmpty,error $(argv))
warnIfEmpty =$(call checkIfEmpty,warning $(argv))
endif #}
###########################################################################
## Common makefile library loader
###########################################################################
topORerr =$(if $(topsrcdir),$(topsrcdir),$(error topsrcdir is not defined))
ifdef USE_AUTOTARGETS_MK # mkdir_deps
include $(topORerr)/config/makefiles/autotargets.mk
endif