From 0305622f259c11258cc9d56fa46af28d2206bd43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 15 May 2017 20:55:06 +0200 Subject: Add tweaks and tests for the WITHOUT feature --- Makefile | 13 ++--- core/core.mk | 10 ++-- doc/src/guide/getting_started.asciidoc | 11 ---- doc/src/guide/updating.asciidoc | 33 ++++++++---- test/Makefile | 48 ------------------ test/core_misc.mk | 92 ++++++++++++++++++++++++++++++++++ 6 files changed, 124 insertions(+), 83 deletions(-) create mode 100644 test/core_misc.mk diff --git a/Makefile b/Makefile index 6d6ff23..1580445 100644 --- a/Makefile +++ b/Makefile @@ -15,15 +15,16 @@ WITHOUT ?= BUILD_CONFIG_FILE ?= $(CURDIR)/build.config -ifeq ($(WITHOUT),) + +ifeq ($(strip $(WITHOUT)),) BUILD_CONFIG = $(shell sed "s/\#.*//" $(BUILD_CONFIG_FILE)) else empty := $(subst ,, ) -BUILD_EXCLUDE = "^$(subst $(empty),\|^,$(WITHOUT))" -BUILD_CONFIG = $(shell sed "s/\#.*//" $(BUILD_CONFIG_FILE)|grep -v $(BUILD_EXCLUDE)) +BUILD_CONFIG = $(shell sed "s/\#.*//" $(BUILD_CONFIG_FILE) \ + | grep -v "^$(subst $(empty),\|^,$(WITHOUT))") endif -ERLANG_MK = erlang.mk +ERLANG_MK ?= erlang.mk ERLANG_MK_VERSION = $(shell git describe --tags --dirty) .PHONY: all check @@ -31,8 +32,8 @@ ERLANG_MK_VERSION = $(shell git describe --tags --dirty) all: export LC_COLLATE=C; \ awk 'FNR==1 && NR!=1{print ""}1' $(patsubst %,%.mk,$(BUILD_CONFIG)) \ - | sed 's/^ERLANG_MK_VERSION = .*/ERLANG_MK_VERSION = $(ERLANG_MK_VERSION)/' \ - | sed 's:^ERLANG_MK_WITHOUT = .*:ERLANG_MK_WITHOUT = $(WITHOUT):' > $(ERLANG_MK) + | sed 's/^ERLANG_MK_VERSION =.*/ERLANG_MK_VERSION = $(ERLANG_MK_VERSION)/' \ + | sed 's:^ERLANG_MK_WITHOUT =.*:ERLANG_MK_WITHOUT = $(WITHOUT):' > $(ERLANG_MK) ifdef p # Remove p from the list of variables since that conflicts with bootstrapping. diff --git a/core/core.mk b/core/core.mk index 89cfa25..63265d3 100644 --- a/core/core.mk +++ b/core/core.mk @@ -18,6 +18,7 @@ ERLANG_MK_FILENAME := $(realpath $(lastword $(MAKEFILE_LIST))) export ERLANG_MK_FILENAME ERLANG_MK_VERSION = rolling +ERLANG_MK_WITHOUT = # Make 3.81 and 3.82 are deprecated. @@ -29,9 +30,6 @@ ifeq ($(MAKE_VERSION),3.82) $(warning Please upgrade to GNU Make 4 or later: https://erlang.mk/guide/installation.html) endif -# Ignored plugins -ERLANG_MK_WITHOUT = "" - # Core configuration. PROJECT ?= $(notdir $(CURDIR)) @@ -187,16 +185,14 @@ ERLANG_MK_COMMIT ?= ERLANG_MK_BUILD_CONFIG ?= build.config ERLANG_MK_BUILD_DIR ?= .erlang.mk.build -WITHOUT ?= $(ERLANG_MK_WITHOUT) -WITHOUT := $(strip $(WITHOUT)) - +erlang-mk: WITHOUT ?= $(ERLANG_MK_WITHOUT) erlang-mk: git clone $(ERLANG_MK_REPO) $(ERLANG_MK_BUILD_DIR) ifdef ERLANG_MK_COMMIT cd $(ERLANG_MK_BUILD_DIR) && git checkout $(ERLANG_MK_COMMIT) endif if [ -f $(ERLANG_MK_BUILD_CONFIG) ]; then cp $(ERLANG_MK_BUILD_CONFIG) $(ERLANG_MK_BUILD_DIR)/build.config; fi - $(MAKE) -C $(ERLANG_MK_BUILD_DIR) WITHOUT='$(WITHOUT)' + $(MAKE) -C $(ERLANG_MK_BUILD_DIR) WITHOUT='$(strip $(WITHOUT))' cp $(ERLANG_MK_BUILD_DIR)/erlang.mk ./erlang.mk rm -rf $(ERLANG_MK_BUILD_DIR) diff --git a/doc/src/guide/getting_started.asciidoc b/doc/src/guide/getting_started.asciidoc index 5d7d804..ca1391d 100644 --- a/doc/src/guide/getting_started.asciidoc +++ b/doc/src/guide/getting_started.asciidoc @@ -78,17 +78,6 @@ to bootstrap. This operation is done only once. Consult the xref:updating[Updating Erlang.mk] chapter for more information. -[NOTE] ----- -By default the file contains a package index. To filter it, run the command -above with the `WITHOUT=index` argument. - -[source,bash] -$ make -f erlang.mk bootstrap WITHOUT=index - -This command will generate the file without the index. ----- - Of course, the generated project can now be compiled: [source,bash] diff --git a/doc/src/guide/updating.asciidoc b/doc/src/guide/updating.asciidoc index 3c72749..8eeb0bf 100644 --- a/doc/src/guide/updating.asciidoc +++ b/doc/src/guide/updating.asciidoc @@ -47,10 +47,28 @@ Yep, it's that easy. === Customizing the build -Erlang.mk allows you to customize which plugins are to be included -in the 'erlang.mk' file. You can do so by maintaining your own -'build.config' file in your repository. Erlang.mk will automatically -use it the next time you run `make erlang-mk`. +Erlang.mk allows you to customize which components are to be included +in the 'erlang.mk' file. The `WITHOUT` variable allows you to +remove components from the default Erlang.mk build. The 'build.config' +file lets you define exactly what goes in (including your own code!), +and in what order. + +The `WITHOUT` file contains the list of components to exclude from +the build. For example, to exclude the package index and the EDoc +plugin when bootstrapping your application: + +[source,bash] +$ make -f erlang.mk bootstrap WITHOUT="index plugins/edoc" + +The generated Erlang.mk will never include those components when +you update it, until you change your mind and use the `WITHOUT` +variable again when you upgrade: + +[source,bash] +$ make erlang-mk WITHOUT=index + +The 'build.config' file is automatically used when you bootstrap +Erlang.mk or when you update it with `make erlang-mk`. The 'build.config' file contains the list of all files that will be built into the resulting 'erlang.mk' file. You can start from @@ -61,10 +79,3 @@ You can also name the file differently or put it in a separate folder by modifying the value for `ERLANG_MK_BUILD_CONFIG`. You can also tell Erlang.mk to use a different temporary directory by changing the `ERLANG_MK_BUILD_DIR` variable. - -Alternatively you can filter out a plugin in the build config by using the -`WITHOUT` variable the first time you generate the file. For example this -commande will filter the index plugin: - -[source,bash] -$ make -f erlang.mk WITHOUT=index diff --git a/test/Makefile b/test/Makefile index b5e1747..a7060ab 100644 --- a/test/Makefile +++ b/test/Makefile @@ -123,54 +123,6 @@ endef $(eval $(foreach t,$(patsubst %.mk,%,$(patsubst plugin_%,%,$(wildcard plugin_*.mk))),$(call include_plugin,$t))) -# Tests that don't easily fit into other categories. - -core:: core-clean-crash-dump core-distclean-tmp core-help - -.PHONY: core-clean-crash-dump core-distclean-tmp core-help - -core-clean-crash-dump: 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 a fake erl_crash.dump file" - $t touch $(APP)/erl_crash.dump - - $i "Clean the application" - $t $(MAKE) -C $(APP) clean $v - - $i "Check that the crash dump is removed" - $t test ! -e $(APP)/erl_crash.dump - -core-distclean-tmp: build clean - - $i "Bootstrap a new OTP application named $(APP)" - $t mkdir $(APP)/ - $t cp ../erlang.mk $(APP)/ - $t $(MAKE) -C $(APP) -f erlang.mk bootstrap all $v - - $i "Check that a .erlang.mk directory exists" - $t test -d $(APP)/.erlang.mk - - $i "Distclean the application" - $t $(MAKE) -C $(APP) distclean $v - - $i "Check that .erlang.mk directory got removed" - $t test ! -e $(APP)/.erlang.mk - -core-help: 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 "Run 'make help' and check that it prints help" - $t test -n "`$(MAKE) -C $(APP) help` | grep Usage" - # Packages. PACKAGES = $(foreach pkg,$(sort $(wildcard ../index/*.mk)),$(notdir $(basename $(pkg)))) diff --git a/test/core_misc.mk b/test/core_misc.mk new file mode 100644 index 0000000..9397378 --- /dev/null +++ b/test/core_misc.mk @@ -0,0 +1,92 @@ +# Core: Miscellaneous. +# +# The miscellaneous tests use the prefix "core-", not "core-misc-". + +CORE_MISC_CASES = clean-crash-dump distclean-tmp help without-edoc without-index without-many +CORE_MISC_TARGETS = $(addprefix core-,$(CORE_MISC_CASES)) + +.PHONY: $(CORE_MISC_TARGETS) + +core:: $(CORE_MISC_TARGETS) + +core-clean-crash-dump: 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 a fake erl_crash.dump file" + $t touch $(APP)/erl_crash.dump + + $i "Clean the application" + $t $(MAKE) -C $(APP) clean $v + + $i "Check that the crash dump is removed" + $t test ! -e $(APP)/erl_crash.dump + +core-distclean-tmp: build clean + + $i "Bootstrap a new OTP application named $(APP)" + $t mkdir $(APP)/ + $t cp ../erlang.mk $(APP)/ + $t $(MAKE) -C $(APP) -f erlang.mk bootstrap all $v + + $i "Check that a .erlang.mk directory exists" + $t test -d $(APP)/.erlang.mk + + $i "Distclean the application" + $t $(MAKE) -C $(APP) distclean $v + + $i "Check that .erlang.mk directory got removed" + $t test ! -e $(APP)/.erlang.mk + +core-help: 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 "Run 'make help' and check that it prints help" + $t test -n "`$(MAKE) -C $(APP) help` | grep Usage" + +core-without-edoc: clean + + $i "Create a working directory for this test" + $t mkdir -p $(APP)/ + + $i "Generate a bleeding edge Erlang.mk without the EDoc plugin" + $t cd .. && $(MAKE) WITHOUT=plugins/edoc ERLANG_MK=$(CURDIR)/$(APP)/erlang.mk $v + + $i "Confirm that the EDoc plugin was not included." + $t ! grep -q distclean-edoc $(APP)/erlang.mk + +# @todo Update Erlang.mk and confirm this sticks. + +core-without-index: clean + + $i "Create a working directory for this test" + $t mkdir -p $(APP)/ + + $i "Generate a bleeding edge Erlang.mk without the package index" + $t cd .. && $(MAKE) WITHOUT=index ERLANG_MK=$(CURDIR)/$(APP)/erlang.mk $v + + $i "Confirm that the index was not included." + $t ! grep -q pkg_cowboy $(APP)/erlang.mk + +# @todo Update Erlang.mk and confirm this sticks. + +core-without-many: clean + + $i "Create a working directory for this test" + $t mkdir -p $(APP)/ + + $i "Generate a bleeding edge Erlang.mk without the index and the EDoc plugin" + $t cd .. && $(MAKE) WITHOUT="index plugins/edoc" ERLANG_MK=$(CURDIR)/$(APP)/erlang.mk $v + + $i "Confirm that the EDoc plugin was not included." + $t ! grep -q distclean-edoc $(APP)/erlang.mk + + $i "Confirm that the index was not included." + $t ! grep -q pkg_cowboy $(APP)/erlang.mk -- cgit v1.2.3