aboutsummaryrefslogtreecommitdiffstats
path: root/test/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'test/Makefile')
-rw-r--r--test/Makefile178
1 files changed, 165 insertions, 13 deletions
diff --git a/test/Makefile b/test/Makefile
index 0517684..9bd9168 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -13,10 +13,12 @@ endif
# Temporary application name, taken from rule name.
APP = test_$(subst -,_,$@)
+CACHE_DIR = $(CURDIR)/$(APP)/.cache
+export CACHE_DIR
# Erlang, quickly!
-ERL = erl +A0 -noinput -boot no_dot_erlang
+ERL = erl -noinput -boot no_dot_erlang -kernel start_distribution false +P 1024 +Q 1024
# Platform detection, condensed version.
@@ -123,32 +125,44 @@ endef
.PHONY: all clean init
-all:: core
+all::
+ $t :
clean::
- $t rm -rf erl_crash.dump packages/ $(filter-out test_rebar_git/,$(wildcard test_*/))
+ $t rm -rf erl_crash.dump packages/ $(filter-out test_hex_core_git/ test_rebar_git/,$(wildcard test_*/))
init: clean
- $i "Prefetch Rebar if necessary"
+ $i "Prefetch hex_core if necessary"
+ $t if [ ! -d test_hex_core_git ]; then \
+ git clone -q -n -- https://github.com/hexpm/hex_core test_hex_core_git; \
+ fi
+
+ $i "Prefetch rebar if necessary"
$t if [ ! -d test_rebar_git ]; then \
- git clone -q -n -- https://github.com/rebar/rebar test_rebar_git; \
+ git clone -q -n -- https://github.com/erlang/rebar3 test_rebar_git; \
fi
$i "Generate a bleeding edge Erlang.mk"
$t cd .. && $(MAKE) $v
-REBAR_GIT = file://$(CURDIR)/test_rebar_git
-export REBAR_GIT
+HEX_CORE_GIT = file://$(CURDIR)/test_hex_core_git
+export HEX_CORE_GIT
+
+REBAR3_GIT = file://$(CURDIR)/test_rebar_git
+export REBAR3_GIT
# Core.
.PHONY: core
-define include_core
-core:: core-$1
+CORE_TARGETS :=
+PLUGINS_TARGETS :=
+define include_core
include core_$1.mk
+CORE_TARGETS += $$(core_$1_TARGETS)
+
endef
$(eval $(foreach t,$(patsubst %.mk,%,$(patsubst core_%,%,$(wildcard core_*.mk))),$(call include_core,$t)))
@@ -156,18 +170,24 @@ $(eval $(foreach t,$(patsubst %.mk,%,$(patsubst core_%,%,$(wildcard core_*.mk)))
# Plugins.
define include_plugin
-all:: $1
-
include plugin_$1.mk
+PLUGINS_TARGETS += $$($1_TARGETS)
+
endef
$(eval $(foreach t,$(patsubst %.mk,%,$(patsubst plugin_%,%,$(wildcard plugin_*.mk))),$(call include_plugin,$t)))
+core:: $(CORE_TARGETS)
+
+all:: $(CORE_TARGETS) $(PLUGINS_TARGETS)
+
# Packages.
PACKAGES = $(foreach pkg,$(sort $(wildcard ../index/*.mk)),$(notdir $(basename $(pkg))))
-EXCLUDE_FROM_CHECK = ['ci.erlang.mk', esh_mk, hexer_mk, inaka_mk, 'lfe.mk', rabbitmq_codegen]
+PATCHES = ELIXIR_PATCH=1 HUT_PATCH=1
+EXCLUDE_FROM_CHECK = ['ci.erlang.mk', elvis_mk, esh_mk, hexer_mk, inaka_mk, 'lfe.mk', pmod_transform, rust_mk]
+EXCLUDE_FROM_APP_CHECK = esh_mk pmod_transform rust_mk
packages: $(addprefix pkg-,$(PACKAGES))
@@ -196,11 +216,122 @@ pkg-$1: init
false; \
fi
+ $(if $(filter $1,$(EXCLUDE_FROM_APP_CHECK)),,
+ $i "Check that $1 has a .app file"
+ $t if ! test -f packages/$1_pkg/deps/$(APP_NAME)/ebin/$(APP_NAME).app; then \
+ echo "$1: no .app file" >> packages/errors.log; \
+ false; \
+ fi)
+
+ $i "Check that all applications and their modules can be loaded"
+ $t if ! ( cd packages/$1_pkg/ && $(ERL) -pa deps/*/ebin/ -eval " \
+ Apps0 = [list_to_atom(App) || \"deps/\" ++ App \
+ <- filelib:wildcard(\"deps/*\")], \
+ Apps = [App || App <- Apps0, not lists:member(App, $(EXCLUDE_FROM_CHECK))], \
+ [begin \
+ io:format(\"Loading application ~p~n\", [App]), \
+ case application:load(App) of \
+ ok -> ok; \
+ {error, {already_loaded, App}} -> ok \
+ end, \
+ {ok, Mods} = application:get_key(App, modules), \
+ [try io:format(\" Loading module ~p~n\", [Mod]), \
+ {module, Mod} = code:load_file(Mod) \
+ catch C:R -> timer:sleep(500), erlang:C(R) \
+ end || Mod <- Mods] \
+ end || App <- Apps], \
+ halt()." ); then \
+ echo "$1: load error" >> packages/errors.log; \
+ false; \
+ fi
+
+ $i "Recompile package $1"
+ $t if ! ( cd packages/$1_pkg/ && $(MAKE) $(PATCHES) FULL=1 $v ); then \
+ echo "$(1): recompile error" >> packages/errors.log; \
+ false; \
+ fi
+
+ $(if $(filter $1,$(EXCLUDE_FROM_APP_CHECK)),,
+ $i "Check that $1 has a .app file"
+ $t if ! test -f packages/$1_pkg/deps/$(APP_NAME)/ebin/$(APP_NAME).app; then \
+ echo "$1: no .app file" >> packages/errors.log; \
+ false; \
+ fi)
+
+ $i "Check that all applications and their modules can still be loaded"
+ $t if ! ( cd packages/$1_pkg/ && $(ERL) -pa deps/*/ebin/ -eval " \
+ Apps0 = [list_to_atom(App) || \"deps/\" ++ App \
+ <- filelib:wildcard(\"deps/*\")], \
+ Apps = [App || App <- Apps0, not lists:member(App, $(EXCLUDE_FROM_CHECK))], \
+ [begin \
+ io:format(\"Loading application ~p~n\", [App]), \
+ case application:load(App) of \
+ ok -> ok; \
+ {error, {already_loaded, App}} -> ok \
+ end, \
+ {ok, Mods} = application:get_key(App, modules), \
+ [try io:format(\" Loading module ~p~n\", [Mod]), \
+ {module, Mod} = code:load_file(Mod) \
+ catch C:R -> timer:sleep(500), erlang:C(R) \
+ end || Mod <- Mods] \
+ end || App <- Apps], \
+ halt()." ); then \
+ echo "$1: recompile+load error" >> packages/errors.log; \
+ false; \
+ fi
+
+ $i "Check that no erl_crash.dump file exists"
+ $t if ( ! find packages/$1_pkg/ -type f -name erl_crash.dump ); then \
+ echo "$(1): erl_crash.dump found" >> packages/errors.log; \
+ fi
+
+ $(if $(KEEP_BUILDS),,
+ $i "OK; delete the build directory"
+ $t rm -rf packages/$1_pkg/)
+endef
+
+$(foreach pkg,$(PACKAGES),$(eval $(call pkg_target,$(pkg))))
+
+# Hex.pm packages.
+
+ifdef HEXPM
+
+HEXPM_PACKAGES =
+
+define hexpm_pkg_target
+HEXPM_PACKAGES += $1
+
+.PHONY: hexpm-pkg-$1
+
+hexpm-pkg-$1: init
+
+# Make sure $@ is defined inside the define.
+ $(eval @ = hexpm-pkg-$1)
+
+# @todo Get the real application's name. How?
+ $(eval APP_NAME := $1)
+
+ $i "Bootstrap a new OTP library in packages/$1_pkg"
+ $t mkdir -p packages/$1_pkg/
+ $t cp ../erlang.mk packages/$1_pkg/
+ $t cd packages/$1_pkg/ && $(MAKE) -f erlang.mk bootstrap-lib $v
+
+ $i "Add package $1 to the Makefile"
+ $t perl -ni.bak -e 'print;if ($$$$.==1) {print "DEPS = $1\ndep_$1 = hex $2\n"}' packages/$1_pkg/Makefile
+
+ $i "Compile package $1"
+ $t if ! ( cd packages/$1_pkg/ && $(MAKE) $(PATCHES) $v ); then \
+ echo "$1: compile error" >> packages/errors.log; \
+ false; \
+ fi
+
+# $(if $(filter $1,$(EXCLUDE_FROM_APP_CHECK)),,
$i "Check that $1 has a .app file"
$t if ! test -f packages/$1_pkg/deps/$(APP_NAME)/ebin/$(APP_NAME).app; then \
echo "$1: no .app file" >> packages/errors.log; \
false; \
fi
+# )
$i "Check that all applications and their modules can be loaded"
$t if ! ( cd packages/$1_pkg/ && $(ERL) -pa deps/*/ebin/ -eval " \
@@ -230,11 +361,13 @@ pkg-$1: init
false; \
fi
+# $(if $(filter $1,$(EXCLUDE_FROM_APP_CHECK)),,
$i "Check that $1 has a .app file"
$t if ! test -f packages/$1_pkg/deps/$(APP_NAME)/ebin/$(APP_NAME).app; then \
echo "$1: no .app file" >> packages/errors.log; \
false; \
fi
+# )
$i "Check that all applications and their modules can still be loaded"
$t if ! ( cd packages/$1_pkg/ && $(ERL) -pa deps/*/ebin/ -eval " \
@@ -268,4 +401,23 @@ pkg-$1: init
$t rm -rf packages/$1_pkg/)
endef
-$(foreach pkg,$(PACKAGES),$(eval $(call pkg_target,$(pkg))))
+$(foreach pkg,$(shell grep -v '^#' hexpm_packages.txt | sed 's/ /@/'),$(eval $(call hexpm_pkg_target,$(firstword $(subst @, ,$(pkg))),$(lastword $(subst @, ,$(pkg))))))
+
+hexpm-packages: $(addprefix hexpm-pkg-,$(HEXPM_PACKAGES))
+
+endif
+
+# Templates.
+#
+# apps_Makefile, top_Makefile and vm.args are not currently tested here.
+
+templates: clean
+ $i "Compile Erlang modules"
+ $t mkdir test_templates/
+ $t cd test_templates/ && erlc +no_error_module_mismatch ../../templates/*.erl
+
+ $i "Load Erlang term files"
+ $t $(ERL) -eval '{ok, _} = file:consult("../templates/application.app.src"), halt()'
+ $t $(ERL) -eval '{ok, _} = file:consult("../templates/library.app.src"), halt()'
+ $t $(ERL) -eval '{ok, _} = file:consult("../templates/relx.config"), halt()'
+ $t $(ERL) -eval '{ok, _} = file:consult("../templates/sys.config"), halt()'