Browse Source

Ensure that modules generated from erlydtl are listed in .app file

bullno1 9 years ago
parent
commit
9de82c2195
2 changed files with 47 additions and 1 deletions
  1. 6 1
      plugins/erlydtl.mk
  2. 41 0
      test/plugin_erlydtl.mk

+ 6 - 1
plugins/erlydtl.mk

@@ -33,7 +33,12 @@ define erlydtl_compile.erl
 endef
 
 ifneq ($(wildcard src/),)
-ebin/$(PROJECT).app:: $(sort $(call core_find,$(DTL_PATH),*.dtl))
+
+DTL_FILES = $(sort $(call core_find,$(DTL_PATH),*.dtl))
+DTL_ERL_FILES = $(addprefix src/,$(patsubst %.dtl,%_dtl.erl,$(notdir $(DTL_FILES))))
+ERL_FILES += $(DTL_ERL_FILES)
+
+ebin/$(PROJECT).app:: $(DTL_FILES)
 	$(if $(strip $?),\
 		$(dtl_verbose) $(call erlang,$(call erlydtl_compile.erl,$?,-pa ebin/ $(DEPS_DIR)/erlydtl/ebin/)))
 endif

+ 41 - 0
test/plugin_erlydtl.mk

@@ -0,0 +1,41 @@
+# ErlyDTL plugin
+
+ERLYDTL_CASES = test
+ERLYDTL_TARGETS = $(addprefix erlydtl-,$(ERLYDTL_CASES))
+ERLYDTL_CLEAN_TARGETS = $(addprefix clean-,$(ERLYDTL_TARGETS))
+
+.PHONY: erlydtl clean-erlydtl
+
+clean-erlydtl: $(ERLYDTL_CLEAN_TARGETS)
+
+$(ERLYDTL_CLEAN_TARGETS):
+	$t rm -rf $(APP_TO_CLEAN)/
+
+erlydtl: $(ERLYDTL_TARGETS)
+
+erlydtl-test: build clean-erlydtl-test
+	$i "Bootstrap a new OTP application named $(APP)"
+	$t mkdir $(APP)/
+	$t cp ../erlang.mk $(APP)/
+	$t $(MAKE) -C $(APP) -f erlang.mk bootstrap $v
+	$t mkdir $(APP)/templates
+	$t touch $(APP)/templates/$(APP)_template.dtl
+	$t touch $(APP)/templates/$(APP)_template2.dtl
+	$t echo "PROJECT = $(APP)" > $(APP)/Makefile
+	$t echo "DEPS = erlydtl" >> $(APP)/Makefile
+	$t echo "include erlang.mk" >> $(APP)/Makefile
+
+	$i "Build the application"
+	$t $(MAKE) -C $(APP) $v
+
+	$i "Check that ErlyDTL templates are compiled"
+	$t test -f $(APP)/ebin/$(APP)_template_dtl.beam
+	$t test -f $(APP)/ebin/$(APP)_template2_dtl.beam
+
+	$i "Check that ErlyDTL generated modules are included in .app file"
+	$t $(ERL) -pa $(APP)/ebin/ -eval " \
+		ok = application:load($(APP)), \
+		{ok, Modules} = application:get_key($(APP), modules), \
+		true = lists:member($(APP)_template_dtl, Modules), \
+		true = lists:member($(APP)_template2_dtl, Modules), \
+		halt()"