From e5c4fb5645754cee18af4551e7f89e39ada1eee0 Mon Sep 17 00:00:00 2001 From: Jim Huang Date: Tue, 20 Mar 2018 05:58:32 +0800 Subject: [PATCH] Perform sanity checks on python-based test cases --- Makefile | 10 ++++------ mk/python.mk | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 mk/python.mk diff --git a/Makefile b/Makefile index 2ff0201..aaab664 100644 --- a/Makefile +++ b/Makefile @@ -78,13 +78,10 @@ $(OUT)/libdcurl.so: $(OBJS) $(VECHO) " LD\t$@\n" $(Q)$(CC) -shared -o $@ $^ $(LDFLAGS) -# FIXME: script "tests/test-multi_pow.py" depends on PyIOTA package, and we -# have to check in advance, otherwise python3 would complain as following: -# ModuleNotFoundError: No module named 'iota' $(OUT)/test-multi_pow_%: tests/test-multi_pow_%.py $(OUT)/libdcurl.so - @echo "#!/usr/bin/env python3" > $@ - @cat $< >> $@ - @chmod +x $@ + $(Q)echo "#!$(PYTHON)" > $@ + $(call py_prepare_cmd) + $(Q)chmod +x $@ $(OUT)/test-%.done: $(OUT)/test-% $(Q)$(PRINTF) "*** Validating $< ***\n" @@ -95,4 +92,5 @@ clean: $(RM) -r $(OUT) include mk/common.mk +include mk/python.mk -include $(deps) diff --git a/mk/python.mk b/mk/python.mk new file mode 100644 index 0000000..b88a92e --- /dev/null +++ b/mk/python.mk @@ -0,0 +1,14 @@ +PYTHON = python3 +PYTHON := $(shell which $(PYTHON)) +ifndef PYTHON +$(error "python3 is required.") +endif + +# check "iota" module in Python installation +PY_CHECK_MOD_IOTA := $(shell $(PYTHON) -c "import iota" 2>/dev/null && \ + echo 1 || echo 0) +ifeq ("$(PY_CHECK_MOD_IOTA)","1") + py_prepare_cmd = $(Q)cat $< >> $@ +else + py_prepare_cmd = $(warning "skip $@ because PyIOTA is not installed.") +endif