forked from ArweaveTeam/arweave
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathar-rebar3
More file actions
executable file
·97 lines (84 loc) · 2.47 KB
/
Copy pathar-rebar3
File metadata and controls
executable file
·97 lines (84 loc) · 2.47 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
#!/bin/bash
set -e
set -x
if [ $# -ne 2 ]
then
echo "ar-rebar3 <profile> <command>"
exit 1
fi
SYSTEM=$(uname -s)
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
PROFILE=$1
COMMAND=$2
OVERLAY_TARGET="${SCRIPT_DIR}/_vars.config"
# helper function to create erlang like value from the shell
# and stored them into a specific file.
create_overlay_var() {
local target="${OVERLAY_TARGET}"
local name="${1}"
local value="$(eval ${2} 2>/dev/null || echo undefined)"
if ! echo "${name}" | grep -E '^[a-z]+[0-9A-Za-z_]+$' >/dev/null
then
echo "invalid variable ${name}" 1>&2
return 1
fi
if ! echo "${value}" | grep -E '^[[:print:]]+$' >/dev/null
then
echo "invalid value ${value}" 1>&2
return 1
fi
if test -e "${target}"
then
printf '{%s, "%s"}.\n' "${name}" "${value}" >> "${target}"
return 0
fi
printf '{%s, "%s"}.\n' "${name}" "${value}" > "${target}"
return 0
}
# create variables required for the overlay, it will contain
# various information regarding the build and will be
# hardcoded in the final release.
rebar3_overlay_variables() {
echo "Crafting overlay variables..."
if test "${SYSTEM}" = "Linux"
then
create_overlay_var git_rev "git rev-parse HEAD"
create_overlay_var datetime "date -u '+%Y-%m-%dT%H:%M:%SZ'"
create_overlay_var cc_version "cc --version | head -n1"
create_overlay_var gmake_version "gmake --version | head -n1"
create_overlay_var cmake_version "cmake --version | head -n1"
else
touch $OVERLAY_TARGET
fi
}
# remove old artifacts that must be recreated everytime.
rebar3_clean_artifacts() {
echo Removing build artifacts...
rm -vf "_vars.config"
rm -vf "${SCRIPT_DIR}/lib"
rm -vf "${SCRIPT_DIR}/releases"
}
# execute rebar3 using the profile and the command previously
# configured
rebar3_invocation() {
echo "Executing rebar3 as ${PROFILE} ${COMMAND}"
${SCRIPT_DIR}/rebar3 as ${PROFILE} ${COMMAND}
}
# create artifacts required to run the code locally, only useful
# in case of release.
rebar3_create_artifacts() {
echo Copying and linking build artifacts
ln -vsf ${RELEASE_PATH}/arweave/releases ${SCRIPT_DIR}/releases
ln -vsf ${RELEASE_PATH}/arweave/lib ${SCRIPT_DIR}/lib
}
######################################################################
# main script
######################################################################
rebar3_clean_artifacts
rebar3_overlay_variables
rebar3_invocation
if [ "${COMMAND}" = "release" ]
then
RELEASE_PATH=$(${SCRIPT_DIR}/rebar3 as ${ARWEAVE_BUILD_TARGET:-default} path --rel)
rebar3_create_artifacts
fi