Skip to content

Commit

Permalink
Modernize Makefile and rebar.config.script while fixing CI on OTP 22
Browse files Browse the repository at this point in the history
  • Loading branch information
g-andrade committed May 4, 2024
1 parent 4bfe510 commit 0a6ba9a
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 28 deletions.
69 changes: 49 additions & 20 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,62 +1,91 @@
CLI_ARTIFACT_PATH = _build/escriptize/bin/locus

export ERL_FLAGS = -enable-feature maybe_expr # needed for katana-code under OTP 25
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -euc
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules

.PHONY: all build clean check
.PHONY: xref hank-dead-code-cleaner elvis-linter dialyzer
.PHONY: test cover
.PHONY: shell console doc-dry publish cli
export ERL_FLAGS = -enable-feature maybe_expr # needed for katana-code under OTP 25

.NOTPARALLEL: check cover test
## General Rules

all: build
all: compile
.PHONY: all
.NOTPARALLEL: all

build:
compile:
@rebar3 compile
.PHONY: compile

clean:
@rebar3 clean
@rebar3 clean -a
.PHONY: clean

check: xref hank-dead-code-cleaner elvis-linter dialyzer
.NOTPARALLEL: check
.PHONY: check

test: eunit ct cli
./locus check --log-level debug test/priv/GeoLite2-Country.tar.gz
.NOTPARALLEL: test
.PHONY: test

## Tests

ct:
@rebar3 do ct, cover
.PHONY: ct

eunit:
@rebar3 eunit
.PHONY: eunit

## Checks

xref:
@rebar3 xref
.PHONY: xref

hank-dead-code-cleaner:
@if rebar3 plugins list | grep '^rebar3_hank\>' >/dev/null; then \
rebar3 hank; \
else \
echo >&2 "WARN: skipping rebar3_hank check"; \
fi
.PHONY: hank-dead-code-cleaner

elvis-linter:
@rebar3 lint
@if rebar3 plugins list | grep '^rebar3_lint\>' >/dev/null; then \
rebar3 lint; \
else \
echo >&2 "WARN: skipping rebar3_lint check"; \
fi
.PHONY: elvis-linter

dialyzer:
@rebar3 dialyzer
.PHONY: dialyzer

eqwalizer:
@rebar3 as eqwalizer,test compile
elp eqwalize-all

test: cli
@rebar3 do eunit, ct, cover
./locus check --log-level debug test/priv/GeoLite2-Country.tar.gz

cover: test
## Shell, docs and publication

shell: export ERL_FLAGS = +pc unicode
shell:
@rebar3 as shell shell

console: shell
cli:
@rebar3 as escriptize escriptize
cp -p "$(CLI_ARTIFACT_PATH)" ./

doc-dry:
@rebar3 hex build
.PHONY: doc-dry

publish:
publish: doc
@rebar3 hex publish

cli:
@rebar3 as escriptize escriptize
cp -p "$(CLI_ARTIFACT_PATH)" ./
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
{rebar3_ex_doc, "0.2.22"},
{rebar3_hank, "1.4.0"}, % excluded on OTP 22 (see rebar.config.script)
{rebar3_hex, "7.0.7"},
{rebar3_lint, "3.2.3"}
{rebar3_lint, "3.2.3"} % excluded on OTP 22 (see rebar.config.script)
]}.

%% == Dialyzer ==
Expand Down
25 changes: 18 additions & 7 deletions rebar.config.script
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
% vim: set ft=erlang:
begin
TakeOutHank
= fun (Config) ->
TakeOutProjPlugin
= fun (Name, Config) ->
{project_plugins, ProjPlugins}
= lists:keyfind(project_plugins, 1, Config),
{value, {rebar3_hank, HankVersion}, RemainingProjPlugins}
= lists:keytake(rebar3_hank, 1, ProjPlugins),
{value, {_, Version}, RemainingProjPlugins}
= lists:keytake(Name, 1, ProjPlugins),
logger:info("Dropping proj plugin '~ts' ~ts", [Name, Version]),
_UpdatedConfig
= lists:keystore(project_plugins, 1, Config,
{project_plugins, RemainingProjPlugins})
end,

TakeOutElvis
= fun (Config) ->
TakeOutProjPlugin(rebar3_lint, Config)
end,

TakeOutHank
= fun (Config) ->
TakeOutProjPlugin(rebar3_hank, Config)
end,

TakeOutHankIfMaybeExprNotEnabledOnEnv
= fun (Config) ->
Env = os:getenv(),
Expand All @@ -32,9 +43,9 @@ begin

OtpRelease = erlang:system_info(otp_release),
try list_to_integer(OtpRelease) of
22 ->
% Take rebar3_hank away as it's no longer compatible with OTP 22
TakeOutHank(CONFIG) ;
TooOld when TooOld =< 22 ->
% Take dev helpers away as they're no longer compatible with OTP 22
TakeOutHank(TakeOutElvis(CONFIG));
25 ->
TakeOutHankIfMaybeExprNotEnabledOnEnv(CONFIG);
_ ->
Expand Down

0 comments on commit 0a6ba9a

Please sign in to comment.