-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrebar3.mk
More file actions
110 lines (97 loc) · 3.93 KB
/
Copy pathrebar3.mk
File metadata and controls
110 lines (97 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
## rebar3.mk
## Version 0.1.1
## Copyright 2023 Jesse Gumm
## MIT License
##
## This is a tool to help you either use the existing rebar3 in the system or
## build a new one just for a specific project.
##
## How to use:
## 1) include it in your Makefile with:
##
## include rebar3.mk
##
## 2) Update any rules in your makefile so that rebar3 is required, and then
## change the rebar3 calls to use "$(REBAR)" instead of "rebar3" or "./rebar3"
##
## For example, change this:
##
## compile:
## rebar3 compile
##
## To This:
##
## compile: rebar3
## $(REBAR) compile
## TODO Notes:
## I'd like to update this to take a $MINIMUM_REBAR_VERSION variable
## to check the current version of rebar3, and if the version is less than
## the $MINIMUM_REBAR_VERSION, then download/compile the latest version
## Similarly, I'd like to add a $(FORCE_REBAR_VERSION) variable which *forces*
## the project to use that specific verion. This would work similarly by
## comparing versions, and if the version is different, download/compile that
## specific version locally.
## Finally, the logic here should be changed slightly to check for a local (in
## this project) version of rebar3 and use that first. If that doesn't exist,
## then fall back to checking the path, and finally, if that still doesn't
## exist, then (and only then) downloading and compiling rebar3.
## A more advanced version of this checker would also verify that rebar3
## actually runs and doesn't just throw an error.
PREFIX="rebar3.mk: "
REBAR3_MK_VERSION = 0.3.1
## master here means pull the latest version
NEW_REBAR3_MK_VERSION ?= master
REBAR3_MK_REPO = choptastic/rebar3.mk
REBAR3_MK_RAW_URL = https://raw.githubusercontent.com/$(REBAR3_MK_REPO)/$(NEW_REBAR3_MK_VERSION)/rebar3.mk
REPO ?= erlang/rebar3
REPO_SVC_NAME ?= Github
REPO_URL ?= https://github.com/$(REPO).git
REBAR_LATEST_VERSION ?= $(shell curl -s "https://api.github.com/repos/$(REPO)/releases/latest" | grep '"tag_name"' | cut -d '"' -f 4)
REBAR_VERSION ?= $(REBAR_LATEST_VERSION)
REBAR_PATH = $(shell which rebar3)
ifeq ($(REBAR_PATH),)
REBAR = $(shell pwd)/rebar3
RANDOM_STRING := rebar3_$(shell openssl rand -hex 16)
rebar3:
@while true; do\
echo "$(PREFIX)rebar3 not found! (in either the local directory, or in the PATH)"; \
echo "$(PREFIX)Would you like to clone the rebar3 repo and and build it this local project?"; \
echo "$(PREFIX) * Latest release: $(REBAR_LATEST_VERSION) (REBAR_LATEST_VERSION)"; \
echo "$(PREFIX) * Release to download: $(REBAR_VERSION) (REBAR_VERSION)"; \
echo "$(PREFIX) * From $(REPO_SVC_NAME) (REPO_SVC_NAME): $(REPO) (REPO)"; \
echo "$(PREFIX) URL: $(REPO_URL) (REPO_URL)"; \
read -r -p " ===> Proceed to clone and build rebar3 based on the above? [Y/N] " yn; \
case $$yn in \
[Yy]*) \
REPO="$(REPO)" REPO_URL="$(REPO_URL)" REBAR_VERSION="$(REBAR_VERSION)" make update_rebar3; \
break;; \
[Nn]*) \
echo "$(PREFIX)Aborting! You will need to install rebar3 locally or allow rebar3.mk"; \
echo "$(PREFIX)to build a project-local version. See rebar3.org for more information."; \
exit 1;; \
*) \
echo "$(PREFIX)Please answer Y or N";; \
esac; \
done
else
REBAR = rebar3
rebar3:
endif
rebar3_mk:
@echo "$(PREFIX)Getting rebar3.mk $(NEW_REBAR3_MK_VERSION) (NEW_REBAR3_MK_VERSION) from $(REBAR3_MK_REPO) (REBAR3_MK_REPO)"
@echo "$(PREFIX)Downloading URL: $(REBAR3_MK_RAW_URL) (REBAR3_MK_RAW_URL)"
@curl -O $(REBAR3_MK_RAW_URL)
update_rebar3:
@echo "$(PREFIX)Fetching and compiling rebar3 ($(REBAR_VERSION)) for this local project..."
@(cd /tmp && \
git clone $(REPO_URL) $(RANDOM_STRING) -q && \
cd $(RANDOM_STRING) && \
git fetch --tags -q && \
git checkout $(REBAR_VERSION) -q && \
./bootstrap)
@echo "$(PREFIX)Installing rebar3 into your project's directory..."
@(mv /tmp/$(RANDOM_STRING)/rebar3 .)
@echo "$(PREFIX)Cleaning up..."
@(rm -fr /tmp/$(RANDOM_STRING))
install_rebar3: rebar3
@(./rebar3 local install)