msxbuild/lib/make/mb_assert.mk
2020-12-23 18:14:13 +01:00

34 lines
1,003 B
Makefile

define _mb_assert_success
@echo success: mb_assert_$(1)\; \'$(2)\'
endef
define _mb_assert_failure
@echo failure: mb_assert_$(1)\; \'$(2)\'
@exit 1
endef
define _mb_assert_if
$(if $(1),$(call _mb_assert_success,$(2),$(3)),$(call _mb_assert_failure,$(2),$(3)))
endef
define _mb_assert_if_not
$(if $(1),$(call _mb_assert_failure,$(2),$(3)),$(call _mb_assert_success,$(2),$(3)))
endef
# FIXME: Not stable
#define mb_assert_file_contains
# $(call _mb_assert_if,$(findstring $(2),$(file < $(1))),file_contains,$(2))
#endef
define mb_assert_file_equals
$(call _mb_assert_if_not,$(subst $(2),,$(file < $(1))),file_equals,$(2))
endef
# Assert that the variable(s) are set and doesn't have non-empty values.
# Params;
# 1. Variable name(s) to validate.
# 2. (optional) Error message to user.
define mb_assert_defined
$(strip $(foreach 1,$1,$(call _mb_assert_defined_error,$1,$(strip $(value 2)))))
endef
define _mb_assert_defined_error
$(if $(value $1),,$(error Undefined $1$(if $2, ($2))))
endef