aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLoïc Hoguin <[email protected]>2018-12-05 09:38:56 +0100
committerLoïc Hoguin <[email protected]>2018-12-05 11:38:02 +0100
commit672f9310b5a1fc9e6b7bb65f725f278666511db3 (patch)
tree3065f0542330189998b7a864339faf61e60877ec
parentf221d99c4188a64352a77f28441985572313ed0f (diff)
downloaderlang.mk-672f9310b5a1fc9e6b7bb65f725f278666511db3.tar.gz
erlang.mk-672f9310b5a1fc9e6b7bb65f725f278666511db3.tar.bz2
erlang.mk-672f9310b5a1fc9e6b7bb65f725f278666511db3.zip
Allow hooking before/after autopatch
-rw-r--r--core/deps.mk9
-rw-r--r--doc/src/guide/deps.asciidoc33
-rw-r--r--test/core_autopatch.mk39
3 files changed, 74 insertions, 7 deletions
diff --git a/core/deps.mk b/core/deps.mk
index 611106d..4ec9d13 100644
--- a/core/deps.mk
+++ b/core/deps.mk
@@ -659,6 +659,12 @@ $(DEPS_DIR)/$(call dep_name,$1):
cd $(DEPS_DIR)/$(DEP_NAME) && ./configure; \
fi
ifeq ($(filter $(1),$(NO_AUTOPATCH)),)
+ $(verbose) $$(MAKE) --no-print-directory autopatch-$(DEP_NAME)
+endif
+
+.PHONY: autopatch-$(call dep_name,$1)
+
+autopatch-$(call dep_name,$1)::
$(verbose) if [ "$(1)" = "amqp_client" -a "$(RABBITMQ_CLIENT_PATCH)" ]; then \
if [ ! -d $(DEPS_DIR)/rabbitmq-codegen ]; then \
echo " PATCH Downloading rabbitmq-codegen"; \
@@ -677,9 +683,8 @@ ifeq ($(filter $(1),$(NO_AUTOPATCH)),)
elif [ "$1" = "elixir" -a "$(ELIXIR_PATCH)" ]; then \
ln -s lib/elixir/ebin $(DEPS_DIR)/elixir/; \
else \
- $$(call dep_autopatch,$(DEP_NAME)) \
+ $$(call dep_autopatch,$(call dep_name,$1)) \
fi
-endif
endef
$(foreach dep,$(BUILD_DEPS) $(DEPS),$(eval $(call dep_target,$(dep))))
diff --git a/doc/src/guide/deps.asciidoc b/doc/src/guide/deps.asciidoc
index 9939e82..913fa24 100644
--- a/doc/src/guide/deps.asciidoc
+++ b/doc/src/guide/deps.asciidoc
@@ -502,11 +502,10 @@ performed:
* Run autopatch on the project
Autopatch first checks if there is any project-specific patch
-enabled. There are currently two: `RABBITMQ_CLIENT_PATCH` for
-the `amqp_client` dependency, and `RABBITMQ_SERVER_PATCH` for
-the `rabbit` dependency. These are needed only for RabbitMQ
-versions before 3.6.0 (assuming you are using upstream RabbitMQ,
-and not a fork).
+enabled. There are currently three: `RABBITMQ_CLIENT_PATCH` for
+the `amqp_client` dependency (before 3.6.0), `RABBITMQ_SERVER_PATCH`
+for the `rabbit` dependency (before 3.6.0) and `ELIXIR_PATCH`
+for the `elixir` dependency.
Otherwise, autopatch performs different operations depending
on the kind of project it finds the dependency to be.
@@ -529,6 +528,30 @@ empty Makefile generated, for compatibility purposes.
* Other projects with no Makefile are left untouched.
+You can add additional commands to be run immediately before
+or after autopatch is done by extending the target
+`autopatch-$(dep)::`, for example this would remove
+a module:
+
+[source,make]
+----
+autopatch-ranch::
+ rm -f $(DEPS_DIR)/ranch/src/ranch_proxy_header.erl
+----
+
+A common use case for this feature is to apply a PATCH
+file on the dependency immediately after fetching it.
+It can also be used to add compiler options, for example:
+
+[source,make]
+----
+autopatch-couchbeam::
+ printf "\nERLC_OPTS += -DWITH_JIFFY\n" >> $(DEPS_DIR)/couchbeam/Makefile
+----
+
+The commands will run before autopatch when the target is
+defined before including 'erlang.mk', and after otherwise.
+
You can disable the replacing of the 'erlang.mk' file by
defining the `NO_AUTOPATCH_ERLANG_MK` variable:
diff --git a/test/core_autopatch.mk b/test/core_autopatch.mk
index 11da189..21fad4b 100644
--- a/test/core_autopatch.mk
+++ b/test/core_autopatch.mk
@@ -6,6 +6,45 @@ CORE_AUTOPATCH_TARGETS = $(call list_targets,core-autopatch)
core-autopatch: $(CORE_AUTOPATCH_TARGETS)
+core-autopatch-extended: build clean
+
+ $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 Ranch to the list of dependencies"
+ $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = ranch\n"}' $(APP)/Makefile
+
+ $i "Extend autopatch-ranch to create an additional module"
+ $t echo "autopatch-ranch:: ; rm -f \$$(DEPS_DIR)/ranch/src/ranch_protocol.erl" >> $(APP)/Makefile
+
+ $i "Build the application"
+ $t $(MAKE) -C $(APP) $v
+
+ $i "Check that the module was removed"
+ $t ! test -e $(APP)/deps/ranch/src/ranch_protocol.erl
+ $t ! test -e $(APP)/deps/ranch/ebin/ranch_protocol.beam
+
+core-autopatch-extended-erlc-opts: build clean
+
+ $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 couchbeam to the list of dependencies"
+ $t perl -ni.bak -e 'print;if ($$.==1) {print "DEPS = couchbeam\n"}' $(APP)/Makefile
+
+ $i "Extend autopatch-couchbeam to add options to its ERLC_OPTS"
+ $t echo "autopatch-couchbeam:: ; printf '\nERLC_OPTS += -DWITH_JIFFY\n' >> \$$(DEPS_DIR)/couchbeam/Makefile" >> $(APP)/Makefile
+
+ $i "Build the application"
+ $t $(MAKE) -C $(APP) $v
+
+ $i "Check that couchbeam_ejson was compiled with the added option"
+ $t $(ERL) -pa $(APP)/deps/couchbeam/ebin -eval 'c:m(couchbeam_ejson), halt()' | grep -c "WITH_JIFFY" | grep -q 1
+
core-autopatch-no-autopatch: build clean
$i "Bootstrap a new OTP library named $(APP)"