Browse Source

Validate the .app file after generating it

Loïc Hoguin 6 years ago
parent
commit
f1ebd11d44
2 changed files with 25 additions and 1 deletions
  1. 12 1
      core/erlc.mk
  2. 13 0
      test/core_app.mk

+ 12 - 1
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 \

+ 13 - 0
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