From f368ac4fc719e0eb28bb7c3f5d2384eddf65fca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 23 May 2023 14:46:00 +0200 Subject: Add a test for ESCRIPT_ZIP_FILE and abspath the value This way we can just configure it to a local folder without having to use $(CURDIR). --- plugins/escript.mk | 12 ++++++------ test/plugin_escript.mk | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/plugins/escript.mk b/plugins/escript.mk index 2719a03..1790dcb 100644 --- a/plugins/escript.mk +++ b/plugins/escript.mk @@ -29,11 +29,11 @@ help:: escript-zip:: FULL=1 escript-zip:: deps app - $(verbose) mkdir -p $(dir $(ESCRIPT_ZIP_FILE)) - $(verbose) rm -f $(ESCRIPT_ZIP_FILE) - $(gen_verbose) cd .. && $(ESCRIPT_ZIP) $(ESCRIPT_ZIP_FILE) $(PROJECT)/ebin/* + $(verbose) mkdir -p $(dir $(abspath $(ESCRIPT_ZIP_FILE))) + $(verbose) rm -f $(abspath $(ESCRIPT_ZIP_FILE)) + $(gen_verbose) cd .. && $(ESCRIPT_ZIP) $(abspath $(ESCRIPT_ZIP_FILE)) $(PROJECT)/ebin/* ifneq ($(DEPS),) - $(verbose) cd $(DEPS_DIR) && $(ESCRIPT_ZIP) $(ESCRIPT_ZIP_FILE) \ + $(verbose) cd $(DEPS_DIR) && $(ESCRIPT_ZIP) $(abspath $(ESCRIPT_ZIP_FILE)) \ $(subst $(DEPS_DIR)/,,$(addsuffix /*,$(wildcard \ $(addsuffix /ebin,$(shell cat $(ERLANG_MK_TMP)/deps.log))))) endif @@ -43,8 +43,8 @@ escript:: escript-zip "#!$(ESCRIPT_SHEBANG)" \ "%% $(ESCRIPT_COMMENT)" \ "%%! $(ESCRIPT_EMU_ARGS)" > $(ESCRIPT_FILE) - $(verbose) cat $(ESCRIPT_ZIP_FILE) >> $(ESCRIPT_FILE) + $(verbose) cat $(abspath $(ESCRIPT_ZIP_FILE)) >> $(ESCRIPT_FILE) $(verbose) chmod +x $(ESCRIPT_FILE) distclean-escript: - $(gen_verbose) rm -f $(ESCRIPT_FILE) + $(gen_verbose) rm -f $(ESCRIPT_FILE) $(abspath $(ESCRIPT_ZIP_FILE)) diff --git a/test/plugin_escript.mk b/test/plugin_escript.mk index 3949547..6479e3f 100644 --- a/test/plugin_escript.mk +++ b/test/plugin_escript.mk @@ -175,3 +175,40 @@ escript-extra: init $i "Check that the escript contains the extra files" $t unzip -l $(APP)/$(APP) 2> /dev/null | grep -q Makefile $t unzip -l $(APP)/$(APP) 2> /dev/null | grep -q erlang.mk + +escript-zip-file: init + + $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 "Set ESCRIPT_ZIP_FILE to a custom location" + $t perl -ni.bak -e 'print;if ($$.==1) {print "ESCRIPT_ZIP_FILE = tmp/my_escript.zip\n"}' $(APP)/Makefile + + $i "Generate a module containing a function main/1" + $t printf "%s\n" \ + "-module($(APP))." \ + "-export([main/1])." \ + 'main(_) -> io:format("good~n").' > $(APP)/src/$(APP).erl + + $i "Build the escript" + $t $(MAKE) -C $(APP) escript $v + + $i "Check that the file at ESCRIPT_ZIP_FILE exists" + $t test -f $(APP)/tmp/my_escript.zip + + $i "Check that the escript exists" + $t test -f $(APP)/$(APP) + + $i "Check that the escript runs" + $t $(APP)/$(APP) | grep -q good + + $i "Distclean the application" + $t $(MAKE) -C $(APP) distclean $v + + $i "Check that the file at ESCRIPT_ZIP_FILE was removed" + $t test ! -e $(APP)/tmp/my_escript.zip + + $i "Check that the escript was removed" + $t test ! -e $(APP)/$(APP) -- cgit v1.2.3