aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2015-09-17 00:55:51 +0200
committerLoïc Hoguin <[email protected]>2015-09-17 00:55:51 +0200
commit127426e78657e8faa1194f8fa0fd5084be7fed1d (patch)
tree91ab622598297480e231be474ec94803d18b2c6a
parent85e787e36d676c9b11768fa1e9e6263459e49fe2 (diff)
downloaderlang.mk-127426e78657e8faa1194f8fa0fd5084be7fed1d.tar.gz
erlang.mk-127426e78657e8faa1194f8fa0fd5084be7fed1d.tar.bz2
erlang.mk-127426e78657e8faa1194f8fa0fd5084be7fed1d.zip
Add initial 'make rebar.config'
This is a preliminary work, good enough to be used in some, but not all, projects. Tests cover the current functionality. Documentation has been written but will be committed at a later stage, as it covers more than just this target (the target is documented as part of a "Compatibility with other build tools" chapter).
-rw-r--r--build.config1
-rw-r--r--core/compat.mk25
-rw-r--r--test/core_compat.mk169
3 files changed, 195 insertions, 0 deletions
diff --git a/build.config b/build.config
index 31090df..2c2fba6 100644
--- a/build.config
+++ b/build.config
@@ -16,6 +16,7 @@ plugins/protobuffs
core/erlc
core/docs
core/test
+core/compat
# Plugins.
plugins/asciidoc
diff --git a/core/compat.mk b/core/compat.mk
new file mode 100644
index 0000000..bdf9a90
--- /dev/null
+++ b/core/compat.mk
@@ -0,0 +1,25 @@
+# Copyright (c) 2015, Loïc Hoguin <[email protected]>
+# This file is part of erlang.mk and subject to the terms of the ISC License.
+
+.PHONY: rebar.config
+
+# We strip out -Werror because we don't want to fail due to
+# warnings when used as a dependency.
+
+define compat_convert_erlc_opt
+$(if $(filter-out -Werror,$1),\
+ $(if $(findstring +,$1),\
+ $(shell echo $1 | cut -b 2-)))
+endef
+
+define compat_rebar_config
+{deps, [$(call comma_list,$(foreach d,$(DEPS),\
+ {$(call dep_name,$d),".*",{git,"$(call dep_repo,$d)","$(call dep_commit,$d)"}}))]}.
+{erl_opts, [$(call comma_list,$(foreach o,$(ERLC_OPTS),$(call compat_convert_erlc_opt,$o)))]}.
+endef
+
+$(eval _compat_rebar_config = $$(compat_rebar_config))
+$(eval export _compat_rebar_config)
+
+rebar.config:
+ $(gen_verbose) echo "$${_compat_rebar_config}" > rebar.config
diff --git a/test/core_compat.mk b/test/core_compat.mk
new file mode 100644
index 0000000..04921b2
--- /dev/null
+++ b/test/core_compat.mk
@@ -0,0 +1,169 @@
+# Core: Compatibility with other build tools.
+#
+# Note: autopatch functionality is covered separately.
+
+CORE_COMPAT_CASES = auto-rebar rebar rebar-deps rebar-deps-pkg rebar-erlc-opts
+CORE_COMPAT_TARGETS = $(addprefix core-compat-,$(CORE_COMPAT_CASES))
+CORE_COMPAT_CLEAN_TARGETS = $(addprefix clean-,$(CORE_COMPAT_TARGETS))
+
+.PHONY: core-compat $(CORE_COMPAT_TARGETS) clean-core-compat $(CORE_COMPAT_CLEAN_TARGETS)
+
+clean-core-compat: $(CORE_COMPAT_CLEAN_TARGETS)
+
+$(CORE_COMPAT_CLEAN_TARGETS):
+ $t rm -rf $(APP_TO_CLEAN)/
+
+core-compat: $(CORE_COMPAT_TARGETS)
+
+core-compat-auto-rebar: build clean-core-compat-auto-rebar
+
+ $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 "Add rebar.config as a dependency of 'app' target"
+ $t echo "app:: rebar.config" >> $(APP)/Makefile
+
+ $i "Build the application"
+ $t $(MAKE) -C $(APP) $v
+
+ $i "Check that rebar.config was created"
+ $t test -f $(APP)/rebar.config
+
+ $i "Check that rebar.config can be loaded"
+ $t $(ERL) -eval "{ok, _} = file:consult(\"$(APP)/rebar.config\"), halt()"
+
+ $i "Create a temporary file"
+ $t touch $(APP)/older_file
+
+ $i "Wait a second"
+ $t sleep 1
+
+ $i "Build the application again"
+ $t $(MAKE) -C $(APP) $v
+
+ $i "Check that rebar.config is newer than the temporary file"
+ $t test $(APP)/rebar.config -nt $(APP)/older_file
+
+ $i "Check that rebar.config can be loaded"
+ $t $(ERL) -eval "{ok, _} = file:consult(\"$(APP)/rebar.config\"), halt()"
+
+core-compat-rebar: build clean-core-compat-rebar
+
+ $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 "Run 'make rebar.config'"
+ $t $(MAKE) -C $(APP) rebar.config $v
+
+ $i "Check that rebar.config was created"
+ $t test -f $(APP)/rebar.config
+
+ $i "Check that rebar.config can be loaded"
+ $t $(ERL) -eval "{ok, _} = file:consult(\"$(APP)/rebar.config\"), halt()"
+
+ $i "Create a temporary file"
+ $t touch $(APP)/older_file
+
+ $i "Wait a second"
+ $t sleep 1
+
+ $i "Run 'make rebar.config' again"
+ $t $(MAKE) -C $(APP) rebar.config $v
+
+ $i "Check that rebar.config is newer than the temporary file"
+ $t test $(APP)/rebar.config -nt $(APP)/older_file
+
+ $i "Check that rebar.config can be loaded"
+ $t $(ERL) -eval "{ok, _} = file:consult(\"$(APP)/rebar.config\"), halt()"
+
+core-compat-rebar-deps: build clean-core-compat-rebar-deps
+
+ $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 "Add Cowboy as a dependency"
+ $t sed -i.bak '2i\
+DEPS = cowboy\
+dep_cowboy = git repo commit\
+' $(APP)/Makefile
+
+ $i "Run 'make rebar.config'"
+ $t $(MAKE) -C $(APP) rebar.config $v
+
+ $i "Check that rebar.config was created"
+ $t test -f $(APP)/rebar.config
+
+ $i "Check that Cowboy is listed in rebar.config"
+ $t $(ERL) -eval " \
+ {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
+ {_, [{cowboy, _, {git, \"repo\", \"commit\"}}]} = lists:keyfind(deps, 1, C), \
+ halt()"
+
+core-compat-rebar-deps-pkg: build clean-core-compat-rebar-deps-pkg
+
+ $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 "Add Cowboy package as a dependency"
+ $t sed -i.bak '2i\
+DEPS = cowboy\
+' $(APP)/Makefile
+
+ $i "Run 'make rebar.config'"
+ $t $(MAKE) -C $(APP) rebar.config $v
+
+ $i "Check that rebar.config was created"
+ $t test -f $(APP)/rebar.config
+
+ $i "Check that Cowboy is listed in rebar.config"
+ $t $(ERL) -eval " \
+ {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
+ {_, [{cowboy, _, {git, \"https://github.com/\" ++ _, _}}]} = lists:keyfind(deps, 1, C), \
+ halt()"
+
+core-compat-rebar-erlc-opts: build clean-core-compat-rebar-erlc-opts
+
+ $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 "Add extra options to ERLC_OPTS"
+ $t echo "ERLC_OPTS += +warn_export_all +warn_missing_spec +warn_untyped_record" >> $(APP)/Makefile
+
+ $i "Run 'make rebar.config'"
+ $t $(MAKE) -C $(APP) rebar.config $v
+
+ $i "Check that rebar.config was created"
+ $t test -f $(APP)/rebar.config
+
+ $i "Check that -Werror is not listed in rebar.config"
+ $t $(ERL) -eval " \
+ {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
+ {_, Opts} = lists:keyfind(erl_opts, 1, C), \
+ false = lists:member(warning_as_errors, Opts), \
+ halt()"
+
+ $i "Check that debug_info is listed in rebar.config"
+ $t $(ERL) -eval " \
+ {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
+ {_, Opts} = lists:keyfind(erl_opts, 1, C), \
+ true = lists:member(debug_info, Opts), \
+ halt()"
+
+ $i "Check that extra options are listed in rebar.config"
+ $t $(ERL) -eval " \
+ {ok, C} = file:consult(\"$(APP)/rebar.config\"), \
+ {_, Opts} = lists:keyfind(erl_opts, 1, C), \
+ true = lists:member(warn_export_all, Opts), \
+ true = lists:member(warn_missing_spec, Opts), \
+ true = lists:member(warn_untyped_record, Opts), \
+ halt()"