Skip to content

Commit

Permalink
Merge pull request #20 from andrei-mihaila/master
Browse files Browse the repository at this point in the history
Small performance improvements, docs updates
  • Loading branch information
elbrujohalcon authored Oct 19, 2022
2 parents 81ccb60 + 8fe2e13 commit 59938d9
Show file tree
Hide file tree
Showing 9 changed files with 150 additions and 11 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Test on a few operating systems
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test-on-ubuntu:
name: Test on Ubuntu
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: test/run.sh

test-on-mac:
name: Test on MacOS
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- run: brew install erlang make
- run: PATH="$(brew --prefix)/opt/make/libexec/gnubin:$PATH" test/run.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ ebin
rel/example_project
.concrete/DEV_MODE
.rebar
test/test.d
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
# Change Log

## [1.1.2](https://github.com/inaka/elvis.mk/tree/1.1.2) (2022-10-13)
**Implemented enhancements:**

- fix: some compatibily issues with non-GNU environments [\#17](https://github.com/inaka/elvis.mk/issues/17)
- perf: don't run `command -v rebar3` on each Elvis invocation

## [1.1.1](https://github.com/inaka/elvis.mk/tree/1.1.1) (2022-08-23)
**Implemented enhancements:**

- download Rebar3 (if not found locally) and use it to build Elvis [\#16](https://github.com/inaka/elvis.mk/issues/16)

## [1.1.0](https://github.com/inaka/elvis.mk/tree/1.1.0) (2022-08-05)
**Implemented enhancements:**

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ following in your Makefile:
```make
BUILD_DEPS = elvis_mk

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

DEP_PLUGINS = elvis_mk
```
Expand Down
17 changes: 7 additions & 10 deletions plugins.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,29 @@ help::

distclean:: distclean-elvis

MAKEFILE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

# Plugin-specific targets.

$(ELVIS):
$(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) && \
$(ELVIS_REBAR3) escriptize
export ELVIS_BUILD_DIR=$(ELVIS_BUILD_DIR) && \
export ELVIS_REBAR3_URL=$(ELVIS_REBAR3_URL) && \
export ELVIS_REBAR3=$(ELVIS_REBAR3) && \
$(MAKEFILE_DIR)/rebar3.sh escriptize
$(gen_verbose) cp $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)/_build/default/bin/elvis $(ELVIS)
$(gen_verbose) [ -e $(ELVIS_CONFIG) ] || \
cp -n $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)/elvis.config $(ELVIS_CONFIG)
$(verbose) chmod +x $(ELVIS)
$(verbose) rm -rf $(ELVIS_BUILD_DIR)/elvis-$(ELVIS_VERSION)
$(verbose) rm $(ELVIS_BUILD_DIR)/$(ELVIS_CODE_ARCHIVE)
$(verbose) rm -f $(ELVIS_BUILD_DIR)/rebar3
$(if $(shell ls -A $(ELVIS_BUILD_DIR)/),,$(verbose) rmdir $(ELVIS_BUILD_DIR))
$(verbose) find $(ELVIS_BUILD_DIR) -maxdepth 0 -empty -exec rmdir "{}" ";"

elvis: $(ELVIS)
$(verbose) $(ELVIS) rock -c $(ELVIS_CONFIG) $(ELVIS_OPTS)
Expand Down
12 changes: 12 additions & 0 deletions rebar3.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env sh

if [ ! -x $ELVIS_REBAR3 ] && [ -z "$(command -v $ELVIS_REBAR3)" ]; then
mkdir -p "$ELVIS_BUILD_DIR"
echo "Downloading Rebar3 from: "$ELVIS_REBAR3_URL
curl -sLfo "$ELVIS_BUILD_DIR/rebar3" "$ELVIS_REBAR3_URL"
chmod +x "$ELVIS_BUILD_DIR/rebar3"
"$ELVIS_BUILD_DIR/rebar3" $@
else
echo "Using Rebar3: "$ELVIS_REBAR3
"$ELVIS_REBAR3" $@
fi
6 changes: 6 additions & 0 deletions test/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
PROJECT = test
PROJECT_DESCRIPTION = Test project
PROJECT_VERSION = 0.1.0

include erlang.mk
include ../plugins.mk
75 changes: 75 additions & 0 deletions test/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash

set -e

fail() {
echo -e "\033[31mError: $1\033[0m"
exit 1
}

prepare_test() {
rm -rf _build elvis elvis.config out.log
echo -e "--- \033[32mTest: $1 \033[0m ---"
}

cleanup() {
rm -f rebar3 erlang.mk elvis elvis.config out.log
rm -rf _build .erlang.mk
}

finished_test() {
echo -e "--- \033[32mTest passed\033[0m ---"
}

cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null

cleanup

echo "Preparing ..."
echo -n "Downloading Erlang.mk ..."
curl -sLfo erlang.mk https://erlang.mk/erlang.mk
echo " OK"

echo -n "Downloading Rebar3 ..."
curl -sLfo rebar3 https://s3.amazonaws.com/rebar3/rebar3
chmod a+x rebar3
echo " OK"

echo "Doing the initial make ..."
make > /dev/null

prepare_test "Local rebar3, no build dir, no elvis.config"
ELVIS_REBAR3=$(pwd)/rebar3 make elvis || fail "make failed, exit code $?"

[ -x elvis ] || fail "Elvis executable not found"
[ -f elvis.config ] || fail "elvis.config not found"
[ -e _build ] && fail "build dir ('_build') not removed"

cp test-elvis.config elvis.config
make elvis > out.log 2>&1 || fail "Elvis rock failed, exit code $?"
[ ! -s out.log ] || (echo "--- out.log ---" && \
cat out.log && \
echo "---" && \
fail "Elvis rock output (out.log) not empty")
finished_test

prepare_test "Remote rebar3, existing build dir, existing elvis.config"
mkdir -p _build/existing
export ELVIS_REBAR3=not-to-be-found
rm rebar3
cp test-elvis.config elvis.config

make elvis || fail "make failed, exit code $?"

[ -x elvis ] || fail "Elvis executable not found"
cmp --silent test-elvis.config elvis.config || fail "elvis.config was overwritten"
[ -e _build ] || fail "build dir ('_build') removed"

make elvis > out.log 2>&1 || fail "Elvis rock failed, exit code $?"
[ ! -s out.log ] || (echo "--- out.log ---" && \
cat out.log && \
echo "---" && \
fail "Elvis rock output (out.log) not empty")
finished_test

cleanup
14 changes: 14 additions & 0 deletions test/test-elvis.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
elvis,
[
{config, [
#{
dirs => ["."],
filter => "elvis.config",
ruleset => elvis_config
}
]}
]
}
].

0 comments on commit 59938d9

Please sign in to comment.