Skip to content

Commit

Permalink
Merge pull request #16 from andrei-mihaila/master
Browse files Browse the repository at this point in the history
Download rebar3 (if not installed) and use it to build Elvis
  • Loading branch information
elbrujohalcon authored Aug 29, 2022
2 parents bb60fdb + e5bda04 commit 696404c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
22 changes: 15 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,24 @@ following in your Makefile:
```make
BUILD_DEPS = elvis_mk

# defaults to 1.1.0
# the version must be a tag in the repo
# that Elvis version must compile with the installed Erlang / OTP
# don't forget to do `make distclean` after changing the version
# ELVIS_VERSION = 1.0.1 # downgrade

dep_elvis_mk = git https://github.com/inaka/elvis.mk.git 1.1.0
dep_elvis_mk = git https://github.com/inaka/elvis.mk.git 1.1.1

DEP_PLUGINS = elvis_mk
```
## Extra config

- `ELVIS_VERSION` - the Elvis version to build and use
- defaults to `1.1.0`
- the version must be a tag in the [Elvis repo](https://github.com/inaka/elvis)
- that Elvis version must compile with the installed Erlang / OTP
- don't forget to do `make distclean-elvis` after changing the version
- `ELVIS_REBAR3` - path to the Rebar3 executable to build Elvis with
- defaults to `rebar3`
- if this command is not found Rebar 3 will be downloaded from `ELVIS_REBAR3_URL`
- `ELVIS_REBAR3_URL`
- defaults to `https://s3.amazonaws.com/rebar3/rebar3`

For even more extras use the force, [read the source](plugins.mk).

## Help

Expand Down
25 changes: 20 additions & 5 deletions plugins.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ ELVIS_OPTS ?=
ELVIS_BUILD_DIR ?= $(CURDIR)/_build
ELVIS_CODE_ARCHIVE = $(ELVIS_VERSION).tar.gz

ELVIS_REBAR3_URL ?= https://s3.amazonaws.com/rebar3/rebar3
ELVIS_REBAR3 ?= rebar3

# Core targets.

help::
Expand All @@ -27,16 +30,28 @@ distclean:: distclean-elvis
# Plugin-specific targets.

$(ELVIS):
$(gen_verbose) mkdir -p $(ELVIS_BUILD_DIR)
$(gen_verbose) $(call core_http_get,$(ELVIS_BUILD_DIR)/$(ELVIS_CODE_ARCHIVE),$(ELVIS_URL))
$(gen_verbose) cd $(ELVIS_BUILD_DIR) && \
$(verbose) mkdir -p $(ELVIS_BUILD_DIR)
ifeq ($(shell command -v $(ELVIS_REBAR3)),)
$(verbose) echo "Downloading Rebar3 from: "$(ELVIS_REBAR3_URL)
$(verbose) $(call core_http_get,$(ELVIS_BUILD_DIR)/rebar3,$(ELVIS_REBAR3_URL))
$(verbose) chmod +x $(ELVIS_BUILD_DIR)/rebar3
$(eval ELVIS_REBAR3 := $(ELVIS_BUILD_DIR)/rebar3)
else
$(verbose) echo "Using Rebar3: "$(ELVIS_REBAR3)
endif
$(verbose) echo "Downloading Elvis from: "$(ELVIS_URL)
$(verbose) $(call core_http_get,$(ELVIS_BUILD_DIR)/$(ELVIS_CODE_ARCHIVE),$(ELVIS_URL))
$(verbose) cd $(ELVIS_BUILD_DIR) && \
tar -xzf $(ELVIS_CODE_ARCHIVE) && \
cd elvis-$(ELVIS_VERSION) && \
rebar3 escriptize
$(ELVIS_REBAR3) escriptize
$(gen_verbose) cp $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)/_build/default/bin/elvis $(ELVIS)
$(gen_verbose) cp --no-clobber $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)/elvis.config $(ELVIS_CONFIG)
$(verbose) chmod +x $(ELVIS)
$(gen_verbose) rm -rf $(ELVIS_BUILD_DIR)
$(verbose) rm -rf $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)
$(verbose) rm $(ELVIS_BUILD_DIR)/$(ELVIS_CODE_ARCHIVE)
$(verbose) rm --force $(ELVIS_BUILD_DIR)/rebar3
$(verbose) rmdir --ignore-fail-on-non-empty $(ELVIS_BUILD_DIR)

elvis: $(ELVIS)
$(verbose) $(ELVIS) rock -c $(ELVIS_CONFIG) $(ELVIS_OPTS)
Expand Down

0 comments on commit 696404c

Please sign in to comment.