-
Notifications
You must be signed in to change notification settings - Fork 10
/
build.sh
executable file
·165 lines (143 loc) · 5.82 KB
/
build.sh
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env bash
function usage() {
printf "Usage: $0 OPTION...
-c DIR Directory where CMAKE install is located
\\n" "$0" 1>&2
exit 1
}
CLEAN=${CLEAN:-false}
DEBUG=${DEBUG:-false}
VERBOSE=${VERBOSE:-false}
TIME_BEGIN=$(date -u +%s)
if [ $# -ne 0 ]; then
while getopts "a:cdhv" opt; do
case "${opt}" in
a)
APTS_DIR=$OPTARG
;;
c)
CLEAN=true
;;
d)
DEBUG=true
set -x
;;
v)
VERBOSE=true
;;
h)
usage
;;
?)
echo "Invalid Option!" 1>&2
usage
;;
:)
echo "Invalid Option: -${OPTARG} requires an argument." 1>&2
usage
;;
*)
usage
;;
esac
done
fi
SCRIPT_VERSION=2.10
export CURRENT_WORKING_DIR=$(pwd) # relative path support
export CLEAN
export DEBUG
export VERBOSE
# Obtain dependency versions; Must come first in the script
. ./.environment
# Load general helpers
. ./utils.sh
echo
echo "FIO Contracts Build Script Version: ${SCRIPT_VERSION}"
echo "FIO Contracts Version: ${FIO_CNTRX_VERSION_FULL}"
echo "$(date -u)"
echo "User: ${CURRENT_USER}"
# echo "git head id: %s" "$( cat .git/refs/heads/master )"
echo "Current branch: $(execute git rev-parse --abbrev-ref HEAD 2>/dev/null)"
# Checks for Arch and OS + Support for tests setting them manually
## Necessary for linux exclusion while running bats tests/bash-bats/*.sh
[[ -z "${ARCH}" ]] && export ARCH=$(uname)
if [[ -z "${NAME}" ]]; then
if [[ $ARCH == "Linux" ]]; then
[[ ! -e /etc/os-release ]] && echo "${COLOR_RED} - /etc/os-release not found! It seems you're attempting to use an unsupported Linux distribution.${COLOR_NC}" && exit 1
# Obtain OS NAME, and VERSION
. /etc/os-release
elif [[ $ARCH == "Darwin" ]]; then
export NAME=$(sw_vers -productName)
else
echo " ${COLOR_RED}- FIO is not supported for your Architecture!${COLOR_NC}" && exit 1
fi
set-system-vars
fi
echo
echo "Performing OS/System Validation..."
([[ $NAME == "Ubuntu" ]] && ([[ "$(echo ${VERSION_ID})" == "18.04" ]] || [[ "$(echo ${VERSION_ID})" == "20.04" ]] || [[ "$(echo ${VERSION_ID})" == "22.04" ]])) || (echo " - You must be running 18.04.x, 20.04.x, or 22.04 to build the FIO Contracts." && exit 1)
# Set up the working directories for build, etc
setup
# CMAKE Installation
# cmake may have been passed as arg to build or previously installed in local apts dir, check these and set if appropriate
export CMAKE=
([[ -z "${CMAKE}" ]] && [[ -d ${APTS_DIR} ]] && [[ -x ${APTS_DIR}/bin/cmake ]]) && export CMAKE=${APTS_DIR}/bin/cmake
([[ -z "${CMAKE}" ]] && [[ -d ${FIO_CNTRX_APTS_DIR} ]] && [[ -x ${FIO_CNTRX_APTS_DIR}/bin/cmake ]]) && export CMAKE=${FIO_CNTRX_APTS_DIR}/bin/cmake && export APTS_DIR=${FIO_CNTRX_APTS_DIR}
if [[ $ARCH == "Darwin" ]]; then
([[ -z "${CMAKE}" ]] && [[ ! -z $(command -v cmake 2>/dev/null) ]]) && export CMAKE=$(command -v cmake 2>/dev/null) && export CMAKE_CURRENT_VERSION=$($CMAKE --version | grep -E "cmake version[[:blank:]]*" | sed 's/.*cmake version //g')
# If it exists, check that it's > required version +
if [[ ! -z $CMAKE_CURRENT_VERSION ]] && [[ $((10#$(echo $CMAKE_CURRENT_VERSION | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }'))) -lt $((10#$(echo $CMAKE_REQUIRED_VERSION | awk -F. '{ printf("%03d%03d%03d\n", $1,$2,$3); }'))) ]]; then
echo "${COLOR_RED}The currently installed cmake version ($CMAKE_CURRENT_VERSION) is less than the required version ($CMAKE_REQUIRED_VERSION). Cannot proceed."
exit 1
fi
fi
ensure-cmake
[[ ! -x "${CMAKE}" ]] && echo "CMake not found! Exiting..." && exit 1
ensure-cdt
if ! hash eosio-cpp 2>/dev/null; then
echo "The FIO Contract Development Toolkit is not installed (not found in PATH)! Either update PATH or"
echo "perform the following steps to clone, build and install the fio.cdt suite;"
echo " git clone https://www.github.com/fioprotocol/fio.cdt.git"
echo " cd fio.cdt"
echo " git submodule update --init --recursive"
echo " ./build.sh"
echo " sudo ./install.sh"
echo
exit 1
fi
echo
printf "\t=========== Building FIO Contracts ===========\n\n"
RED='\033[0;31m'
NC='\033[0m'
mkdir -p build
pushd build
${CMAKE} ../
make -j${JOBS}
popd
printf "\t=========== Copying FIO Contracts ABIs ===========\n\n"
execute cp contracts/fio.address/fio.address.abi build/contracts/fio.address/
execute cp contracts/fio.fee/fio.fee.abi build/contracts/fio.fee/
execute cp contracts/fio.request.obt/fio.request.obt.abi build/contracts/fio.request.obt/
execute cp contracts/fio.tpid/fio.tpid.abi build/contracts/fio.tpid/
execute cp contracts/fio.treasury/fio.treasury.abi build/contracts/fio.treasury/
execute cp contracts/fio.escrow/fio.escrow.abi build/contracts/fio.escrow/
execute cp contracts/fio.staking/fio.staking.abi build/contracts/fio.staking/
execute cp contracts/fio.oracle/fio.oracle.abi build/contracts/fio.oracle/
execute cp contracts/fio.perms/fio.perms.abi build/contracts/fio.perms/
echo
printf "\t=========== FIO Contracts Build Complete ===========\n\n"
echo
printf "${bldred}\n"
printf " ___ ___ \n"
printf " /\\__\\ /\\ \\ \n"
printf " /:/ _/_ ___ /::\\ \\ \n"
printf " /:/ /\\__\\ /\\__\\ /:/\\:\\ \\ \n"
printf " /:/ /:/ / /:/__/ /:/ \\:\\ \\ \n"
printf " /:/_/:/ / /::\\ \\ /:/__/ \\:\\__\\ \n"
printf " \\:\\/:/ / \\/\\:\\ \\__ \\:\\ \\ /:/ / \n"
printf " \\::/__/ \\:\\/\\__\\ \\:\\ /:/ / \n"
printf " \\:\\ \\ \\::/ / \\:\\/:/ / \n"
printf " \\:\\__\\ /:/ / \\::/ / \n"
printf " \\/__/ \\/__/ \\/__/ \n\n${txtrst}"
printf "\\tFor more information:\\n"
printf "\\tFIO website: https://fio.net\\n"