From f1ebd11d44f1ea131b536df661b6a17caa405cbc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Fri, 30 Nov 2018 21:19:20 +0100 Subject: Validate the .app file after generating it --- core/erlc.mk | 13 ++++++++++++- test/core_app.mk | 13 +++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/core/erlc.mk b/core/erlc.mk index 56e6b79..872d3f5 100644 --- a/core/erlc.mk +++ b/core/erlc.mk @@ -301,6 +301,13 @@ define compile_erl -pa ebin/ -I include/ $(filter-out $(ERLC_EXCLUDE_PATHS),$(COMPILE_FIRST_PATHS) $(1)) endef +define validate_app_file + case file:consult("ebin/$(PROJECT).app") of + {ok, _} -> halt(); + _ -> halt(1) + end +endef + ebin/$(PROJECT).app:: $(ERL_FILES) $(CORE_FILES) $(wildcard src/$(PROJECT).app.src) $(eval FILES_TO_COMPILE := $(filter-out src/$(PROJECT).app.src,$?)) $(if $(strip $(FILES_TO_COMPILE)),$(call compile_erl,$(FILES_TO_COMPILE))) @@ -310,9 +317,13 @@ ebin/$(PROJECT).app:: $(ERL_FILES) $(CORE_FILES) $(wildcard src/$(PROJECT).app.s ifeq ($(wildcard src/$(PROJECT).app.src),) $(app_verbose) printf '$(subst %,%%,$(subst $(newline),\n,$(subst ','\'',$(call app_file,$(GITDESCRIBE),$(MODULES)))))' \ > ebin/$(PROJECT).app + $(verbose) if ! $(call erlang,$(call validate_app_file)); then \ + echo "The .app file produced is invalid. Please verify the value of PROJECT_ENV." >&2; \ + exit 1; \ + fi else $(verbose) if [ -z "$$(grep -e '^[^%]*{\s*modules\s*,' src/$(PROJECT).app.src)" ]; then \ - echo "Empty modules entry not found in $(PROJECT).app.src. Please consult the erlang.mk README for instructions." >&2; \ + echo "Empty modules entry not found in $(PROJECT).app.src. Please consult the erlang.mk documentation for instructions." >&2; \ exit 1; \ fi $(appsrc_verbose) cat src/$(PROJECT).app.src \ diff --git a/test/core_app.mk b/test/core_app.mk index 4c32178..eaa059d 100644 --- a/test/core_app.mk +++ b/test/core_app.mk @@ -281,6 +281,19 @@ core-app-env: build clean {ok, \"\\\"test_\\tvalue\\\"\"} = application:get_env($(APP), test_key), \ {ok, '\\\$$test'} = application:get_env($(APP), test_atom), \ halt()" + +core-app-env-invalid: build clean + + $i "Bootstrap a new OTP library named $(APP)" + $t mkdir $(APP)/ + $t cp ../erlang.mk $(APP)/ + $t $(MAKE) -C $(APP) -f erlang.mk bootstrap-lib $v + + $i "Define an invalid PROJECT_ENV" + $t echo "PROJECT_ENV = [{test_key, test_value" >> $(APP)/Makefile + + $i "Build the application" + $t ! $(MAKE) -C $(APP) $v endif core-app-erlc-exclude: build clean -- cgit v1.2.3