Просмотр исходного кода

Support plugins local to the application

If the application's Makefile specify either:
    DEP_PLUGINS = $(PROJECT)
or e.g.:
    DEP_PLUGINS = $(PROJECT)/mk/dist.mk
then load the plugin from the application instead of a dependency.

This helps when you have an application with common Erlang modules and
Erlang.mk plugins: your common application can load Erlang.mk plugins
exactly like other applications depending on the common application.
Jean-Sébastien Pédron 8 лет назад
Родитель
Сommit
724521b68c
3 измененных файлов с 75 добавлено и 1 удалено
  1. 4 0
      core/deps.mk
  2. 28 0
      doc/src/guide/external_plugins.asciidoc
  3. 43 1
      test/core_plugins.mk

+ 4 - 0
core/deps.mk

@@ -25,9 +25,13 @@ export REBAR_DEPS_DIR
 # They both use the core_dep_plugin macro.
 
 define core_dep_plugin
+ifeq ($(2),$(PROJECT))
+-include $$(patsubst $(PROJECT)/%,%,$(1))
+else
 -include $(DEPS_DIR)/$(1)
 
 $(DEPS_DIR)/$(1): $(DEPS_DIR)/$(2) ;
+endif
 endef
 
 DEP_EARLY_PLUGINS ?=

+ 28 - 0
doc/src/guide/external_plugins.asciidoc

@@ -101,3 +101,31 @@ DEP_EARLY_PLUGINS = common_deps
 DEPS += cowboy
 TEST_DEPS = ct_helper
 dep_ct_helper = git https://github.com/ninenines/ct_helper master
+
+=== Loading  plugins local to the application
+
+If the Erlang.mk plugin lives in the same directory or repository as your
+application or library, then you can load it exactly like an external
+plugin: the dependency name is simply the name of your application or
+library.
+
+For example, the following Makefile loads a plugin in the 'mk'
+subdirectory:
+
+[source,make]
+DEP_PLUGINS = $(PROJECT)/mk/dist.mk
+
+This also works with early-stage plugins:
+
+[source,make]
+DEP_EARLY_PLUGINS = $(PROJECT)/mk/variables.mk
+
+Like external plugins, if you do not specify the path to the plugin, it
+defaults to 'plugins.mk' or 'early-plugins.mk', located at the root of
+your application:
+
+[source,make]
+# Loads ./early-plugins.mk
+DEP_EARLY_PLUGINS = $(PROJECT)
+# Loads ./plugins.mk
+DEP_PLUGINS = $(PROJECT)

+ 43 - 1
test/core_plugins.mk

@@ -1,6 +1,6 @@
 # Core: External plugins.
 
-CORE_PLUGINS_CASES = all early one templates test
+CORE_PLUGINS_CASES = all early early-local local one templates test
 CORE_PLUGINS_TARGETS = $(addprefix core-plugins-,$(CORE_PLUGINS_CASES))
 
 .PHONY: core-plugins $(CORE_PLUGINS_TARGETS)
@@ -65,6 +65,48 @@ core-plugins-early: build clean
 	$t test -e $(APP)/deps/cowlib
 	$t test -e $(APP)/deps/ranch
 
+core-plugins-early-local: 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 "Create two internal plugin makefiles"
+	$t mkdir -p $(APP)/mk
+	$t echo "plugin1: ; @echo \$$@" > $(APP)/mk/plugin1.mk
+	$t echo "plugin2: ; @echo \$$@" > $(APP)/early-plugins.mk
+
+	$i "Add dependency and plugins to the Makefile"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "DEP_EARLY_PLUGINS = \$$(PROJECT) \$$(PROJECT)/mk/plugin1.mk\n"}' $(APP)/Makefile
+
+	$i "Run 'make plugin1' and check that it prints plugin1"
+	$t $(MAKE) --no-print-directory -C $(APP) plugin1 | grep -qw plugin1
+
+	$i "Run 'make plugin2' and check that it prints plugin2"
+	$t $(MAKE) --no-print-directory -C $(APP) plugin2 | grep -qw plugin2
+
+core-plugins-local: 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 "Create two internal plugin makefiles"
+	$t mkdir -p $(APP)/mk
+	$t echo "plugin1: ; @echo \$$@" > $(APP)/mk/plugin1.mk
+	$t echo "plugin2: ; @echo \$$@" > $(APP)/plugins.mk
+
+	$i "Add dependency and plugins to the Makefile"
+	$t perl -ni.bak -e 'print;if ($$.==1) {print "DEP_PLUGINS = \$$(PROJECT) \$$(PROJECT)/mk/plugin1.mk\n"}' $(APP)/Makefile
+
+	$i "Run 'make plugin1' and check that it prints plugin1"
+	$t $(MAKE) --no-print-directory -C $(APP) plugin1 | grep -qw plugin1
+
+	$i "Run 'make plugin2' and check that it prints plugin2"
+	$t $(MAKE) --no-print-directory -C $(APP) plugin2 | grep -qw plugin2
+
 core-plugins-one: build clean
 
 	$i "Bootstrap a new OTP library named $(APP)"