aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-11-30 21:19:20 +0100
committerLoïc Hoguin <[email protected]>2018-11-30 21:19:20 +0100
commitf1ebd11d44f1ea131b536df661b6a17caa405cbc (patch)
treefb436270e547deb3f02cc24fe0da742e82dc037a
parentfe225610451e5a56c1bcee220e55c45fd95bc9aa (diff)
downloaderlang.mk-f1ebd11d44f1ea131b536df661b6a17caa405cbc.tar.gz
erlang.mk-f1ebd11d44f1ea131b536df661b6a17caa405cbc.tar.bz2
erlang.mk-f1ebd11d44f1ea131b536df661b6a17caa405cbc.zip
Validate the .app file after generating it
-rw-r--r--core/erlc.mk13
-rw-r--r--test/core_app.mk13
2 files changed, 25 insertions, 1 deletions
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