aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2015-07-02 18:35:44 +0200
committerLoïc Hoguin <[email protected]>2015-07-02 18:35:44 +0200
commit6a3bf18655384cbd534308104d82b1ae0f66c228 (patch)
tree65a4d3a9c0910774eb664ac5895af18bb623cbf1
parent061d4491da416ad23a8d470a4198a0cd608b7e0f (diff)
downloaderlang.mk-6a3bf18655384cbd534308104d82b1ae0f66c228.tar.gz
erlang.mk-6a3bf18655384cbd534308104d82b1ae0f66c228.tar.bz2
erlang.mk-6a3bf18655384cbd534308104d82b1ae0f66c228.zip
Reduce dependency on external programs
This commit implements a core_find and core_ls function that can be used to list files recursively or not. A few other minute changes are included and a couple hacks removed.
-rw-r--r--core/core.mk11
-rw-r--r--core/erlc.mk25
-rw-r--r--core/test.mk4
-rw-r--r--plugins/c_src.mk2
-rw-r--r--plugins/ct.mk2
-rw-r--r--plugins/erlydtl.mk2
-rw-r--r--plugins/eunit.mk58
-rw-r--r--plugins/protobuffs.mk2
-rw-r--r--plugins/triq.mk7
-rw-r--r--test/Makefile3
10 files changed, 59 insertions, 57 deletions
diff --git a/core/core.mk b/core/core.mk
index c9c8256..ad70ee6 100644
--- a/core/core.mk
+++ b/core/core.mk
@@ -126,13 +126,13 @@ define newline
endef
-define erlang_list
-[$(subst $(space),$(comma),$(strip $(1)))]
+define comma_list
+$(subst $(space),$(comma),$(strip $(1)))
endef
# Adding erlang.mk to make Erlang scripts who call init:get_plain_arguments() happy.
define erlang
-$(ERL) -pa $(ERLANG_MK_TMP)/rebar/ebin -eval "$(subst $(newline),,$(subst ",\",$(1)))" -- erlang.mk
+$(ERL) -pz $(ERLANG_MK_TMP)/rebar/ebin -eval "$(subst $(newline),,$(subst ",\",$(1)))" -- erlang.mk
endef
ifeq ($(shell which wget 2>/dev/null | wc -l), 1)
@@ -162,8 +162,13 @@ endif
core_eq = $(and $(findstring $(1),$(2)),$(findstring $(2),$(1)))
+core_find = $(foreach d,$(call core_ls,$1*),$(call core_find,$d/,$2) $(filter $(subst *,%,$2),$d))
+
core_lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$(1)))))))))))))))))))))))))))
+# @todo On Windows: $(shell dir /B $(1)); make sure to handle when no file exists.
+core_ls = $(filter-out $(1),$(shell echo $(1)))
+
# Automated update.
ERLANG_MK_BUILD_CONFIG ?= build.config
diff --git a/core/erlc.mk b/core/erlc.mk
index b1f7c40..20b8fbb 100644
--- a/core/erlc.mk
+++ b/core/erlc.mk
@@ -51,9 +51,9 @@ define app_file
{description, "$(PROJECT_DESCRIPTION)"},
{vsn, "$(PROJECT_VERSION)"},
{id, "$(1)"},
- {modules, [$(2)]},
+ {modules, [$(call comma_list,$(2))]},
{registered, []},
- {applications, $(call erlang_list,kernel stdlib $(OTP_DEPS) $(DEPS))}
+ {applications, [$(call comma_list,kernel stdlib $(OTP_DEPS) $(DEPS))]}
]}.
endef
else
@@ -62,9 +62,9 @@ define app_file
{description, "$(PROJECT_DESCRIPTION)"},
{vsn, "$(PROJECT_VERSION)"},
{id, "$(1)"},
- {modules, [$(2)]},
- {registered, $(call erlang_list,$(PROJECT)_sup $(PROJECT_REGISTERED))},
- {applications, $(call erlang_list,kernel stdlib $(OTP_DEPS) $(DEPS))},
+ {modules, [$(call comma_list,$(2))]},
+ {registered, [$(call comma_list,$(PROJECT)_sup $(PROJECT_REGISTERED))]},
+ {applications, [$(call comma_list,kernel stdlib $(OTP_DEPS) $(DEPS))]},
{mod, {$(PROJECT)_app, []}}
]}.
endef
@@ -72,8 +72,7 @@ endif
app-build: erlc-include ebin/$(PROJECT).app
$(eval GITDESCRIBE := $(shell git describe --dirty --abbrev=7 --tags --always --first-parent 2>/dev/null || true))
- $(eval MODULES := $(shell find ebin -type f -name \*.beam \
- | sed "s/ebin\//'/;s/\.beam/',/" | sed '$$s/.$$//'))
+ $(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename $(wildcard ebin/*.beam))))))
ifeq ($(wildcard src/$(PROJECT).app.src),)
$(app_verbose) echo $(subst $(newline),,$(subst ",\",$(call app_file,$(GITDESCRIBE),$(MODULES)))) \
> ebin/$(PROJECT).app
@@ -83,7 +82,7 @@ else
exit 1; \
fi
$(appsrc_verbose) cat src/$(PROJECT).app.src \
- | sed "s/{[[:space:]]*modules[[:space:]]*,[[:space:]]*\[\]}/{modules, \[$(MODULES)\]}/" \
+ | sed "s/{[[:space:]]*modules[[:space:]]*,[[:space:]]*\[\]}/{modules, \[$(call comma_list,$(MODULES))\]}/" \
| sed "s/{id,[[:space:]]*\"git\"}/{id, \"$(GITDESCRIBE)\"}/" \
> ebin/$(PROJECT).app
endif
@@ -123,21 +122,21 @@ ebin/$(PROJECT).app::
@mkdir -p ebin/
ifneq ($(wildcard asn1/),)
-ebin/$(PROJECT).app:: $(shell find asn1 -type f -name \*.asn1)
+ebin/$(PROJECT).app:: $(sort $(call core_find,asn1/,*.asn1))
@mkdir -p include
$(if $(strip $?),$(call compile_asn1,$?))
endif
ifneq ($(wildcard mibs/),)
-ebin/$(PROJECT).app:: $(shell find mibs -type f -name \*.mib)
+ebin/$(PROJECT).app:: $(sort $(call core_find,mibs/,*.mib))
@mkdir -p priv/mibs/ include
$(if $(strip $?),$(call compile_mib,$?))
endif
-ebin/$(PROJECT).app:: $(shell find src -type f -name \*.erl -o -name \*.core)
+ebin/$(PROJECT).app:: $(sort $(call core_find,src/,*.erl *.core))
$(if $(strip $?),$(call compile_erl,$?))
-ebin/$(PROJECT).app:: $(shell find src -type f -name \*.xrl -o -name \*.yrl)
+ebin/$(PROJECT).app:: $(sort $(call core_find,src/,*.xrl *.yrl))
$(if $(strip $?),$(call compile_xyrl,$?))
endif
@@ -145,4 +144,4 @@ clean:: clean-app
clean-app:
$(gen_verbose) rm -rf ebin/ priv/mibs/ \
- $(addprefix include/,$(addsuffix .hrl,$(notdir $(basename $(wildcard mibs/*.mib)))))
+ $(addprefix include/,$(addsuffix .hrl,$(notdir $(basename $(call core_find,mibs/,*.mib)))))
diff --git a/core/test.mk b/core/test.mk
index 7dd5d61..3832996 100644
--- a/core/test.mk
+++ b/core/test.mk
@@ -23,10 +23,10 @@ test-deps: $(ALL_TEST_DEPS_DIRS)
@for dep in $(ALL_TEST_DEPS_DIRS) ; do $(MAKE) -C $$dep; done
endif
-ifneq ($(strip $(TEST_DIR)),)
+ifneq ($(wildcard $(TEST_DIR)),)
test-dir:
$(gen_verbose) erlc -v $(TEST_ERLC_OPTS) -I include/ -o $(TEST_DIR) \
- $(wildcard $(TEST_DIR)/*.erl $(TEST_DIR)/*/*.erl) -pa ebin/
+ $(call core_find,$(TEST_DIR)/,*.erl) -pa ebin/
endif
ifeq ($(wildcard ebin/test),)
diff --git a/plugins/c_src.mk b/plugins/c_src.mk
index 34e4952..98417ed 100644
--- a/plugins/c_src.mk
+++ b/plugins/c_src.mk
@@ -64,7 +64,7 @@ clean::
else
ifeq ($(SOURCES),)
-SOURCES := $(shell find $(C_SRC_DIR) -type f \( -name "*.c" -o -name "*.C" -o -name "*.cc" -o -name "*.cpp" \))
+SOURCES := $(sort $(call core_find,$(C_SRC_DIR)/,*.c *.C *.cc *.cpp))
endif
OBJECTS = $(addsuffix .o, $(basename $(SOURCES)))
diff --git a/plugins/ct.mk b/plugins/ct.mk
index eba0e52..7e0f683 100644
--- a/plugins/ct.mk
+++ b/plugins/ct.mk
@@ -7,7 +7,7 @@
CT_OPTS ?=
ifneq ($(wildcard $(TEST_DIR)),)
- CT_SUITES ?= $(sort $(subst _SUITE.erl,,$(shell find $(TEST_DIR) -type f -name \*_SUITE.erl -exec basename {} \;)))
+ CT_SUITES ?= $(sort $(subst _SUITE.erl,,$(notdir $(call core_find,$(TEST_DIR)/,*_SUITE.erl))))
else
CT_SUITES ?=
endif
diff --git a/plugins/erlydtl.mk b/plugins/erlydtl.mk
index d65231d..46a3080 100644
--- a/plugins/erlydtl.mk
+++ b/plugins/erlydtl.mk
@@ -26,6 +26,6 @@ define compile_erlydtl
endef
ifneq ($(wildcard src/),)
-ebin/$(PROJECT).app:: $(shell find templates -type f -name \*.dtl 2>/dev/null)
+ebin/$(PROJECT).app:: $(sort $(call core_find,templates/,*.dtl))
$(if $(strip $?),$(call compile_erlydtl,$?))
endif
diff --git a/plugins/eunit.mk b/plugins/eunit.mk
index b9f2856..79add79 100644
--- a/plugins/eunit.mk
+++ b/plugins/eunit.mk
@@ -6,28 +6,8 @@
# Configuration
-# All modules in TEST_DIR
-ifeq ($(strip $(TEST_DIR)),)
-TEST_DIR_MODS =
-else
-TEST_DIR_MODS = $(notdir $(basename $(shell find $(TEST_DIR) -type f -name *.beam)))
-endif
-
-# All modules in 'ebin'
-EUNIT_EBIN_MODS = $(notdir $(basename $(shell find ebin -type f -name *.beam)))
-# Only those modules in TEST_DIR with no matching module in 'ebin'.
-# This is done to avoid some tests being executed twice.
-EUNIT_MODS = $(filter-out $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(TEST_DIR_MODS))
-TAGGED_EUNIT_TESTS = $(foreach mod,$(EUNIT_EBIN_MODS) $(EUNIT_MODS),{module,$(mod)})
-
EUNIT_OPTS ?=
-# Utility functions
-
-define str-join
- $(shell echo '$(strip $(1))' | sed -e "s/ /,/g")
-endef
-
# Core targets.
tests:: eunit
@@ -39,16 +19,32 @@ help::
# Plugin-specific targets.
-EUNIT_RUN_BEFORE ?=
-EUNIT_RUN_AFTER ?=
-EUNIT_RUN = $(ERL) \
- -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin \
- -pz ebin \
- $(EUNIT_RUN_BEFORE) \
- -eval 'case eunit:test([$(call str-join,$(TAGGED_EUNIT_TESTS))],\
- [$(EUNIT_OPTS)]) of ok -> ok; error -> halt(1) end.' \
- $(EUNIT_RUN_AFTER) \
- -eval 'halt(0).'
+define eunit.erl
+ case "$(COVER)" of
+ "" -> ok;
+ _ ->
+ case cover:compile_beam_directory("ebin") of
+ {error, _} -> halt(1);
+ _ -> ok
+ end
+ end,
+ case eunit:test([$(call comma_list,$(1))], [$(EUNIT_OPTS)]) of
+ ok -> ok;
+ error -> halt(2)
+ end,
+ case "$(COVER)" of
+ "" -> ok;
+ _ ->
+ cover:export("eunit.coverdata")
+ end,
+ halt()
+endef
+
+EUNIT_EBIN_MODS = $(notdir $(basename $(call core_find,ebin/,*.beam)))
+EUNIT_TEST_MODS = $(notdir $(basename $(call core_find,$(TEST_DIR)/,*.beam)))
+EUNIT_MODS = $(foreach mod,$(EUNIT_EBIN_MODS) $(filter-out \
+ $(patsubst %,%_tests,$(EUNIT_EBIN_MODS)),$(EUNIT_TEST_MODS)),{module,'$(mod)'})
eunit: test-build
- $(gen_verbose) $(EUNIT_RUN)
+ $(gen_verbose) $(ERL) -pa $(TEST_DIR) $(DEPS_DIR)/*/ebin ebin \
+ -eval "$(subst $(newline),,$(subst ",\",$(call eunit.erl,$(EUNIT_MODS))))"
diff --git a/plugins/protobuffs.mk b/plugins/protobuffs.mk
index d180b1f..b0400bf 100644
--- a/plugins/protobuffs.mk
+++ b/plugins/protobuffs.mk
@@ -26,6 +26,6 @@ define compile_proto.erl
endef
ifneq ($(wildcard src/),)
-ebin/$(PROJECT).app:: $(shell find src -type f -name \*.proto 2>/dev/null)
+ebin/$(PROJECT).app:: $(sort $(call core_find,src/,*.proto))
$(if $(strip $?),$(call compile_proto,$?))
endif
diff --git a/plugins/triq.mk b/plugins/triq.mk
index f487f8c..702491d 100644
--- a/plugins/triq.mk
+++ b/plugins/triq.mk
@@ -12,7 +12,7 @@ define triq_check.erl
code:add_pathsa(["$(CURDIR)/ebin", "$(DEPS_DIR)/*/ebin"]),
try
case $(1) of
- all -> [true] =:= lists:usort([triq:check(M) || M <- [$(MODULES)]]);
+ all -> [true] =:= lists:usort([triq:check(M) || M <- [$(call comma_list,$(3))]]);
module -> triq:check($(2));
function -> triq:check($(2))
end
@@ -36,8 +36,7 @@ triq: test-build
endif
else
triq: test-build
- $(eval MODULES := $(shell find ebin -type f -name \*.beam \
- | sed "s/ebin\//'/;s/\.beam/',/" | sed '$$s/.$$//'))
- $(gen_verbose) $(call erlang,$(call triq_check.erl,all,undefined))
+ $(eval MODULES := $(patsubst %,'%',$(sort $(notdir $(basename $(wildcard ebin/*.beam))))))
+ $(gen_verbose) $(call erlang,$(call triq_check.erl,all,undefined,$(MODULES)))
endif
endif
diff --git a/test/Makefile b/test/Makefile
index 0de1b17..4c6f25e 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -108,6 +108,7 @@ eunit: app1
$i "eunit: Testing the 'eunit' target."
$i "Running eunit test case inside module src/t.erl"
$t $(call create-module-t)
+ $t $(MAKE) -C app1 distclean $v
$t $(MAKE) -C app1 eunit $v
$i "Checking that the eunit test in module t."
$t echo t | cmp app1/test-eunit.log -
@@ -128,6 +129,7 @@ eunit: app1
' ?assertEqual(2, t:succ(1)),' \
' os:cmd("echo x_tests >> test-eunit.log").' \
> app1/eunit/x_tests.erl
+ $t $(MAKE) -C app1 distclean TEST_DIR=eunit $v
$t $(MAKE) -C app1 eunit TEST_DIR=eunit $v
$i "Checking that '$(MAKE) eunit' didn't run the tests in t_tests twice, etc."
$t printf "%s\n" t t_tests x_tests | cmp app1/test-eunit.log -
@@ -140,6 +142,7 @@ eunit: app1
"succ_test() ->" \
" ?assertEqual(42, t:succ(1))." \
> app1/eunit/t_tests.erl
+ $t $(MAKE) -C app1 distclean TEST_DIR=eunit $v
$t if $(MAKE) -C app1 eunit TEST_DIR=eunit $v ; then false ; fi
$t rm -rf app1/eunit app1/src/t.erl app1/test-eunit.log
$i "Test 'eunit' passed."