From 3ee00fb8c5841ab1e9e88261a4b4e67a0e0204a0 Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Tue, 7 May 2024 13:49:35 -0600 Subject: [PATCH 01/19] BD-4617: Updated build framework to support using fio cmake builds --- .build_vars | 13 +++++ .environment | 23 ++++++++ build.sh | 148 ++++++++++++++++++++++++++++++++++++++++++++++----- utils.sh | 113 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 284 insertions(+), 13 deletions(-) create mode 100644 .build_vars create mode 100644 .environment create mode 100644 utils.sh diff --git a/.build_vars b/.build_vars new file mode 100644 index 00000000..4b0da162 --- /dev/null +++ b/.build_vars @@ -0,0 +1,13 @@ +# CMAKE +export CMAKE_BUILD_TYPE=Release +export CMAKE_VERSION_MAJOR=3 +export CMAKE_VERSION_MINOR=21 +export CMAKE_VERSION_PATCH=7 +export CMAKE_VERSION=${CMAKE_VERSION_MAJOR}.${CMAKE_VERSION_MINOR}.${CMAKE_VERSION_PATCH} + +export CMAKE_INSTALL_DIR=${CMAKE_INSTALL_DIR:-${FIO_CNTRX_APTS_DIR}} + +# GENERAL +export CURRENT_USER=${CURRENT_USER:-$(whoami)} +export DRYRUN=${DRYRUN:-false} +export VERBOSE=${VERBOSE:-false} diff --git a/.environment b/.environment new file mode 100644 index 00000000..5293153a --- /dev/null +++ b/.environment @@ -0,0 +1,23 @@ +export SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +export REPO_ROOT=$(realpath "${SCRIPT_DIR}") +export BUILD_DIR="${REPO_ROOT}/build" + +export CMAKE_REQUIRED_VERSION=$(cat $REPO_ROOT/CMakeLists.txt | grep -E "^[[:blank:]]*cmake_minimum_required[[:blank:]]*\([[:blank:]]*VERSION" | tail -1 | sed 's/.*VERSION //g' | sed 's/ //g' | sed 's/"//g' | cut -d\) -f1) + +export FIO_CNTRX_VERSION_MAJOR=$(cat $REPO_ROOT/CMakeLists.txt | grep -E "^[[:blank:]]*set[[:blank:]]*\([[:blank:]]*VERSION_MAJOR" | tail -1 | sed 's/.*VERSION_MAJOR //g' | sed 's/ //g' | sed 's/"//g' | cut -d\) -f1) +export FIO_CNTRX_VERSION_MINOR=$(cat $REPO_ROOT/CMakeLists.txt | grep -E "^[[:blank:]]*set[[:blank:]]*\([[:blank:]]*VERSION_MINOR" | tail -1 | sed 's/.*VERSION_MINOR //g' | sed 's/ //g' | sed 's/"//g' | cut -d\) -f1) +export FIO_CNTRX_VERSION_PATCH=$(cat $REPO_ROOT/CMakeLists.txt | grep -E "^[[:blank:]]*set[[:blank:]]*\([[:blank:]]*VERSION_PATCH" | tail -1 | sed 's/.*VERSION_PATCH //g' | sed 's/ //g' | sed 's/"//g' | cut -d\) -f1) +export FIO_CNTRX_VERSION_SUFFIX=$(cat $REPO_ROOT/CMakeLists.txt | grep -E "^[[:blank:]]*set[[:blank:]]*\([[:blank:]]*VERSION_SUFFIX" | tail -1 | sed 's/.*VERSION_SUFFIX //g' | sed 's/ //g' | sed 's/"//g' | cut -d\) -f1) +export FIO_CNTRX_VERSION="${FIO_CNTRX_VERSION_MAJOR}.${FIO_CNTRX_VERSION_MINOR}" +if [[ -z $FIO_CNTRX_VERSION_SUFFIX ]]; then + export FIO_CNTRX_VERSION_FULL="${FIO_CNTRX_VERSION_MAJOR}.${FIO_CNTRX_VERSION_MINOR}.${FIO_CNTRX_VERSION_PATCH}" +else + export FIO_CNTRX_CNTRX_VERSION_FULL="${FIO_CNTRX_VERSION_MAJOR}.${FIO_CNTRX_VERSION_MINOR}.${FIO_CNTRX_VERSION_PATCH}-${FIO_CNTRX_VERSION_SUFFIX}" +fi + +export TEMP_DIR="${TEMP_DIR:-${HOME}/tmp}" +export FIO_CNTRX_TMP_DIR="${FIO_CNTRX_TMP_DIR:-${TEMP_DIR}/fio.cntrx}" +#export FIO_CNTRX_INSTALL_DIR="${HOME}/fio.cntrx/${FIO_CNTRX_VERSION}" +export FIO_CNTRX_APTS_DIR="${FIO_CNTRX_APTS_DIR:-${FIO_CNTRX_TMP_DIR}/apts}" + +. ./.build_vars diff --git a/build.sh b/build.sh index 3d7b1469..e3209ffe 100755 --- a/build.sh +++ b/build.sh @@ -1,24 +1,146 @@ -#! /bin/bash +#!/usr/bin/env bash +#set -x -printf "\t=========== Building FIO system contracts ===========\n\n" +function usage() { + printf "Usage: $0 OPTION... + -f DIR FIO Install Directory (FIO binary, dependencies). Default: $HOME/fio + \\n" "$0" 1>&2 + exit 1 +} + +TIME_BEGIN=$(date -u +%s) +if [ $# -ne 0 ]; then + while getopts "f:hv" opt; do + case "${opt}" in + f) + FIO_INSTALL_DIR=$OPTARG + ;; + h) + usage + ;; + v) + VERBOSE=true + ;; + ?) + 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 + +# 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 or 20.04.x to install EOSIO." && exit 1) + +# Determine FIO install if any; if fio is built and installed, using pinned clang, cmake, etc then we want to use that +# 1) check -f optarg +# 2) check $HOME/.fio <- new. load fio env if exists to get fio install dir and cmake +# 3) others? maybe ask... +if [[ -z $FIO_INSTALL_DIR ]]; then + [[ -d $HOME/.fio ]] && [[ -s "$HOME/.fio/fio.sh" ]] && \. "$HOME/.fio/fio.sh" +fi + +# Set up the working directories for build, etc +setup + +# CMAKE Installation +export CMAKE= +([[ -z "${CMAKE}" ]] && [[ -d $FIO_INSTALL_DIR ]] && [[ -x $FIO_INSTALL_DIR/bin/cmake ]]) && export CMAKE=$FIO_INSTALL_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 +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 + +echo +printf "\t=========== Building FIO Contracts ===========\n\n" RED='\033[0;31m' NC='\033[0m' CORES=`getconf _NPROCESSORS_ONLN` + mkdir -p build pushd build &> /dev/null -cmake ../ + +${CMAKE} ../ make -j${CORES} popd &> /dev/null -printf "\t=========== Copying FIO source abi ===========\n\n" -cp contracts/fio.address/fio.address.abi build/contracts/fio.address/ -cp contracts/fio.fee/fio.fee.abi build/contracts/fio.fee/ -cp contracts/fio.request.obt/fio.request.obt.abi build/contracts/fio.request.obt/ -cp contracts/fio.tpid/fio.tpid.abi build/contracts/fio.tpid/ -cp contracts/fio.treasury/fio.treasury.abi build/contracts/fio.treasury/ -cp contracts/fio.escrow/fio.escrow.abi build/contracts/fio.escrow/ -cp contracts/fio.staking/fio.staking.abi build/contracts/fio.staking/ -cp contracts/fio.oracle/fio.oracle.abi build/contracts/fio.oracle/ -cp contracts/fio.perms/fio.perms.abi build/contracts/fio.perms/ +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" + diff --git a/utils.sh b/utils.sh new file mode 100644 index 00000000..63472e40 --- /dev/null +++ b/utils.sh @@ -0,0 +1,113 @@ +# Execution helpers; necessary for BATS testing and log output in buildkite +function execute() { + $VERBOSE && echo "--- Executing: $@" + $DRYRUN || "$@" +} + +function execute-quiet() { + $VERBOSE && echo "--- Executing: $@ &>/dev/null" + $DRYRUN || "$@" &>/dev/null +} + +function execute-always() { + ORIGINAL_DRYRUN=$DRYRUN + DRYRUN=false + execute "$@" + DRYRUN=$ORIGINAL_DRYRUN +} + +function execute-without-verbose() { + ORIGINAL_VERBOSE=$VERBOSE + VERBOSE=false + execute "$@" + VERBOSE=$ORIGINAL_VERBOSE +} + +function setup() { + if $VERBOSE; then + echo "VERBOSE: ${VERBOSE}" + echo "TEMP_DIR: ${TEMP_DIR}" + echo "FIO_CNTRX_TMP_DIR: $FIO_CNTRX_TMP_DIR" + echo "FIO_CNTRX_APTS_DIR: $FIO_CNTRX_APTS_DIR" + fi + ([[ -d $BUILD_DIR ]]) && execute rm -rf $BUILD_DIR # cleanup old build directory + execute mkdir -p $BUILD_DIR + execute-always mkdir -p $FIO_CNTRX_TMP_DIR + execute mkdir -p $FIO_CNTRX_APTS_DIR +} + +function set-system-vars() { + if [[ $ARCH == "Darwin" ]]; then + export OS_VER=$(sw_vers -productVersion) + export OS_MAJ=$(echo "${OS_VER}" | cut -d'.' -f1) + export OS_MIN=$(echo "${OS_VER}" | cut -d'.' -f2) + export OS_PATCH=$(echo "${OS_VER}" | cut -d'.' -f3) + export MEM_GIG=$(bc <<< "($(sysctl -in hw.memsize) / 1024000000)") + export DISK_INSTALL=$(df -h . | tail -1 | tr -s ' ' | cut -d\ -f1 || cut -d' ' -f1) + export blksize=$(df . | head -1 | awk '{print $2}' | cut -d- -f1) + export gbfactor=$(( 1073741824 / blksize )) + export total_blks=$(df . | tail -1 | awk '{print $2}') + export avail_blks=$(df . | tail -1 | awk '{print $4}') + export DISK_TOTAL=$((total_blks / gbfactor )) + export DISK_AVAIL=$((avail_blks / gbfactor )) + else + export DISK_INSTALL=$( df -h . | tail -1 | tr -s ' ' | cut -d\ -f1 ) + export DISK_TOTAL_KB=$( df . | tail -1 | awk '{print $2}' ) + export DISK_AVAIL_KB=$( df . | tail -1 | awk '{print $4}' ) + export MEM_GIG=$(( ( ( $(cat /proc/meminfo | grep MemTotal | awk '{print $2}') / 1000 ) / 1000 ) )) + export DISK_TOTAL=$(( DISK_TOTAL_KB / 1048576 )) + export DISK_AVAIL=$(( DISK_AVAIL_KB / 1048576 )) + fi + export JOBS=${JOBS:-$(( MEM_GIG > CPU_CORES ? CPU_CORES : MEM_GIG ))} +} + +function ensure-cmake() { + echo + echo "${COLOR_CYAN}[Ensuring CMAKE installation]${COLOR_NC}" + if [[ ! -e "${CMAKE}" ]]; then + if ! is-cmake-built; then + build-cmake + fi + install-cmake + [[ -z "${CMAKE}" ]] && export CMAKE="${CMAKE_INSTALL_DIR}/bin/cmake" + echo " - CMAKE successfully installed @ ${CMAKE}" + echo "" + else + echo " - CMAKE found @ ${CMAKE}." + echo "" + fi +} + +# CMake may be built but is it configured for the same install directory??? applies to other repos as well +function is-cmake-built() { + if [[ -x ${FIO_CNTRX_TMP_DIR}/cmake-${CMAKE_VERSION}/build/bin/cmake ]]; then + cmake_version=$(${FIO_CNTRX_TMP_DIR}/cmake-${CMAKE_VERSION}/build/bin/cmake --version | grep version | awk '{print $3}') + if [[ $cmake_version =~ 3.2 ]]; then + #cmake_install_location=$(cat ${FIO_CNTRX_TMP_DIR}/cmake-${CMAKE_VERSION}/build/CMakeCache.txt | grep CMAKE_INSTALL_PREFIX | awk -F= '{print $2}') + #[[ -x $cmake_install_location/bin/cmake ]] + #[[ $? -eq 0 ]] && return + return + fi + fi + false +} + +function build-cmake() { + echo "Building cmake..." + execute bash -c "cd $FIO_CNTRX_TMP_DIR \ + && rm -rf cmake-${CMAKE_VERSION} \ + && curl -LO https://cmake.org/files/v${CMAKE_VERSION_MAJOR}.${CMAKE_VERSION_MINOR}/cmake-${CMAKE_VERSION}.tar.gz \ + && tar -xzf cmake-${CMAKE_VERSION}.tar.gz \ + && rm -f cmake-${CMAKE_VERSION}.tar.gz \ + && cd cmake-${CMAKE_VERSION} \ + && mkdir build && cd build \ + && ../bootstrap --prefix=${CMAKE_INSTALL_DIR} \ + && make -j${JOBS}" +} + +function install-cmake() { + echo "Installing cmake..." + execute bash -c "cd $FIO_CNTRX_TMP_DIR/cmake-${CMAKE_VERSION} \ + && cd build \ + && make install" +} From 10a5581f830f8909fa8e9109edb56c7de4626215 Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Wed, 8 May 2024 07:42:25 -0600 Subject: [PATCH 02/19] BD-4617: added explicit mk of temp dir --- utils.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/utils.sh b/utils.sh index 63472e40..1391ae67 100644 --- a/utils.sh +++ b/utils.sh @@ -32,6 +32,7 @@ function setup() { fi ([[ -d $BUILD_DIR ]]) && execute rm -rf $BUILD_DIR # cleanup old build directory execute mkdir -p $BUILD_DIR + execute-always mkdir -p ${TEMP_DIR} execute-always mkdir -p $FIO_CNTRX_TMP_DIR execute mkdir -p $FIO_CNTRX_APTS_DIR } From c6492176f1cd7fdf1e3377b7e7b0ebdc4fdf1389 Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Sun, 12 May 2024 11:48:20 -0600 Subject: [PATCH 03/19] BD-4617: minor env cleanup --- build.sh | 16 +++------------- utils.sh | 16 +++++++++++++--- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/build.sh b/build.sh index e3209ffe..35c406b3 100755 --- a/build.sh +++ b/build.sh @@ -73,14 +73,6 @@ 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 or 20.04.x to install EOSIO." && exit 1) -# Determine FIO install if any; if fio is built and installed, using pinned clang, cmake, etc then we want to use that -# 1) check -f optarg -# 2) check $HOME/.fio <- new. load fio env if exists to get fio install dir and cmake -# 3) others? maybe ask... -if [[ -z $FIO_INSTALL_DIR ]]; then - [[ -d $HOME/.fio ]] && [[ -s "$HOME/.fio/fio.sh" ]] && \. "$HOME/.fio/fio.sh" -fi - # Set up the working directories for build, etc setup @@ -105,14 +97,12 @@ printf "\t=========== Building FIO Contracts ===========\n\n" RED='\033[0;31m' NC='\033[0m' -CORES=`getconf _NPROCESSORS_ONLN` - mkdir -p build -pushd build &> /dev/null +pushd build ${CMAKE} ../ -make -j${CORES} -popd &> /dev/null +make -j${JOBS} +popd printf "\t=========== Copying FIO Contracts ABIs ===========\n\n" diff --git a/utils.sh b/utils.sh index 1391ae67..ccc02d56 100644 --- a/utils.sh +++ b/utils.sh @@ -23,6 +23,14 @@ function execute-without-verbose() { VERBOSE=$ORIGINAL_VERBOSE } +function pushd () { + command pushd "$@" &> /dev/null +} + +function popd () { + command popd "$@" &> /dev/null +} + function setup() { if $VERBOSE; then echo "VERBOSE: ${VERBOSE}" @@ -59,6 +67,7 @@ function set-system-vars() { export DISK_TOTAL=$(( DISK_TOTAL_KB / 1048576 )) export DISK_AVAIL=$(( DISK_AVAIL_KB / 1048576 )) fi + export CPU_CORES=$(grep -c ^processor /proc/cpuinfo 2>/dev/null || sysctl -n hw.ncpu) export JOBS=${JOBS:-$(( MEM_GIG > CPU_CORES ? CPU_CORES : MEM_GIG ))} } @@ -84,9 +93,10 @@ function is-cmake-built() { if [[ -x ${FIO_CNTRX_TMP_DIR}/cmake-${CMAKE_VERSION}/build/bin/cmake ]]; then cmake_version=$(${FIO_CNTRX_TMP_DIR}/cmake-${CMAKE_VERSION}/build/bin/cmake --version | grep version | awk '{print $3}') if [[ $cmake_version =~ 3.2 ]]; then - #cmake_install_location=$(cat ${FIO_CNTRX_TMP_DIR}/cmake-${CMAKE_VERSION}/build/CMakeCache.txt | grep CMAKE_INSTALL_PREFIX | awk -F= '{print $2}') - #[[ -x $cmake_install_location/bin/cmake ]] - #[[ $? -eq 0 ]] && return + #cat ${FIO_CNTRX_TMP_DIR}/llvm4/build/CMakeCache.txt | grep CMAKE_INSTALL_PREFIX | grep ${EOSIO_INSTALL_DIR} >/dev/null + #if [[ $? -eq 0 ]]; then + # return + #fi return fi fi From b4afc65f36ad09427f17f6b9227d409fbc2277d6 Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Mon, 13 May 2024 09:08:32 -0600 Subject: [PATCH 04/19] BD-4617: minor cleanup --- utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.sh b/utils.sh index ccc02d56..5f0f68ef 100644 --- a/utils.sh +++ b/utils.sh @@ -93,7 +93,7 @@ function is-cmake-built() { if [[ -x ${FIO_CNTRX_TMP_DIR}/cmake-${CMAKE_VERSION}/build/bin/cmake ]]; then cmake_version=$(${FIO_CNTRX_TMP_DIR}/cmake-${CMAKE_VERSION}/build/bin/cmake --version | grep version | awk '{print $3}') if [[ $cmake_version =~ 3.2 ]]; then - #cat ${FIO_CNTRX_TMP_DIR}/llvm4/build/CMakeCache.txt | grep CMAKE_INSTALL_PREFIX | grep ${EOSIO_INSTALL_DIR} >/dev/null + #cat ${FIO_CNTRX_TMP_DIR}/cmake-${CMAKE_VERSION}/build/CMakeCache.txt | grep CMAKE_INSTALL_PREFIX | grep ${EOSIO_INSTALL_DIR} >/dev/null #if [[ $? -eq 0 ]]; then # return #fi From f52d8f5d84439fb7037d451a222c136a3204aaf1 Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Wed, 15 May 2024 08:47:08 -0600 Subject: [PATCH 05/19] BD-4617: Updates to support fio.cdt install, cmake use --- .build_vars | 10 +++++++- .environment | 1 - build.sh | 32 +++++++++++++++++------- utils.sh | 69 ++++++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 94 insertions(+), 18 deletions(-) diff --git a/.build_vars b/.build_vars index 4b0da162..164bcdc7 100644 --- a/.build_vars +++ b/.build_vars @@ -4,8 +4,16 @@ export CMAKE_VERSION_MAJOR=3 export CMAKE_VERSION_MINOR=21 export CMAKE_VERSION_PATCH=7 export CMAKE_VERSION=${CMAKE_VERSION_MAJOR}.${CMAKE_VERSION_MINOR}.${CMAKE_VERSION_PATCH} +export CMAKE_INSTALL_DIR=${FIO_CNTRX_APTS_DIR} -export CMAKE_INSTALL_DIR=${CMAKE_INSTALL_DIR:-${FIO_CNTRX_APTS_DIR}} +# FIO.CDT +export CDT_VERSION_MAJOR=1 +export CDT_VERSION_MINOR=5 +export CDT_VERSION_PATCH=0 +export CDT_VERSION=${CDT_VERSION_MAJOR}.${CDT_VERSION_MINOR}.${CDT_VERSION_PATCH} + +export FIO_CDT_TMP_DIR=${FIO_CDT_TMP_DIR:-${TEMP_DIR}/fio.cdt} +export FIO_CDT_APTS_DIR=${FIO_CDT_APTS_DIR:-${FIO_CDT_TMP_DIR}/apts} # GENERAL export CURRENT_USER=${CURRENT_USER:-$(whoami)} diff --git a/.environment b/.environment index 5293153a..41f7fdf8 100644 --- a/.environment +++ b/.environment @@ -17,7 +17,6 @@ fi export TEMP_DIR="${TEMP_DIR:-${HOME}/tmp}" export FIO_CNTRX_TMP_DIR="${FIO_CNTRX_TMP_DIR:-${TEMP_DIR}/fio.cntrx}" -#export FIO_CNTRX_INSTALL_DIR="${HOME}/fio.cntrx/${FIO_CNTRX_VERSION}" export FIO_CNTRX_APTS_DIR="${FIO_CNTRX_APTS_DIR:-${FIO_CNTRX_TMP_DIR}/apts}" . ./.build_vars diff --git a/build.sh b/build.sh index 35c406b3..225d028e 100755 --- a/build.sh +++ b/build.sh @@ -3,24 +3,24 @@ function usage() { printf "Usage: $0 OPTION... - -f DIR FIO Install Directory (FIO binary, dependencies). Default: $HOME/fio + -c DIR Directory where CMAKE install is located \\n" "$0" 1>&2 exit 1 } TIME_BEGIN=$(date -u +%s) if [ $# -ne 0 ]; then - while getopts "f:hv" opt; do + while getopts "c:hv" opt; do case "${opt}" in - f) - FIO_INSTALL_DIR=$OPTARG - ;; - h) - usage + c) + CMAKE_LOCATION=$OPTARG ;; v) VERBOSE=true ;; + h) + usage + ;; ?) echo "Invalid Option!" 1>&2 usage @@ -78,8 +78,8 @@ setup # CMAKE Installation export CMAKE= -([[ -z "${CMAKE}" ]] && [[ -d $FIO_INSTALL_DIR ]] && [[ -x $FIO_INSTALL_DIR/bin/cmake ]]) && export CMAKE=$FIO_INSTALL_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 +([[ -z "${CMAKE}" ]] && [[ -d ${CMAKE_LOCATION} ]] && [[ -x ${CMAKE_LOCATION}/bin/cmake ]]) && export CMAKE=${CMAKE_LOCATION}/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 CMAKE_LOCATION=${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') @@ -90,6 +90,20 @@ if [[ $ARCH == "Darwin" ]]; then fi fi ensure-cmake +[[ ! -x "${CMAKE}" ]] && echo "CMake not found! Exiting..." && exit 1 + +ensure-fio.cdt +if ! hash eosio-cpp 2>/dev/null; then + echo "The FIO Contract Development Toolkit is not installed. If contract development will be performed, either" + echo "re-execute this script with the '-t' option or perform the following steps to clone, build and install the" + echo "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 +fi echo printf "\t=========== Building FIO Contracts ===========\n\n" diff --git a/utils.sh b/utils.sh index 5f0f68ef..62165265 100644 --- a/utils.sh +++ b/utils.sh @@ -35,14 +35,16 @@ function setup() { if $VERBOSE; then echo "VERBOSE: ${VERBOSE}" echo "TEMP_DIR: ${TEMP_DIR}" - echo "FIO_CNTRX_TMP_DIR: $FIO_CNTRX_TMP_DIR" - echo "FIO_CNTRX_APTS_DIR: $FIO_CNTRX_APTS_DIR" + echo "FIO_CNTRX_TMP_DIR: ${FIO_CNTRX_TMP_DIR}" + echo "FIO_CNTRX_APTS_DIR: ${FIO_CNTRX_APTS_DIR}" fi - ([[ -d $BUILD_DIR ]]) && execute rm -rf $BUILD_DIR # cleanup old build directory - execute mkdir -p $BUILD_DIR + ([[ -d ${BUILD_DIR} ]]) && execute rm -rf ${BUILD_DIR} # cleanup old build directory + execute mkdir -p ${BUILD_DIR} execute-always mkdir -p ${TEMP_DIR} - execute-always mkdir -p $FIO_CNTRX_TMP_DIR - execute mkdir -p $FIO_CNTRX_APTS_DIR + execute-always mkdir -p ${FIO_CNTRX_TMP_DIR} + execute mkdir -p ${FIO_CNTRX_APTS_DIR} + execute-always mkdir -p ${FIO_CDT_TMP_DIR} + execute mkdir -p ${FIO_CDT_APTS_DIR} } function set-system-vars() { @@ -79,7 +81,8 @@ function ensure-cmake() { build-cmake fi install-cmake - [[ -z "${CMAKE}" ]] && export CMAKE="${CMAKE_INSTALL_DIR}/bin/cmake" + export CMAKE_LOCATION=${CMAKE_INSTALL_DIR} + export CMAKE="${CMAKE_INSTALL_DIR}/bin/cmake" echo " - CMAKE successfully installed @ ${CMAKE}" echo "" else @@ -122,3 +125,55 @@ function install-cmake() { && cd build \ && make install" } + +function ensure-fio.cdt() { + echo + echo "${COLOR_CYAN}[Ensuring fio.cdt installation]${COLOR_NC}" + # if ! hash eosio-cpp; then ... + if [[ ! (-d "${FIO_CDT_APTS_DIR}" && -x ${FIO_CDT_APTS_DIR}/bin/eosio-cpp) ]]; then + if ! is-cdt-built; then + build-cdt + fi + install-cdt + echo " - FIO.CDT successfully installed @ ${FIO_CDT_INSTALL_DIR}" + echo "" + else + echo " - FIO.CDT found @ ${FIO_CDT_INSTALL_DIR}." + echo "" + fi +} + +# CMake may be built but is it configured for the same install directory??? applies to other repos as well +function is-cdt-built() { + if [[ -x ${FIO_CDT_TMP_DIR}/fio.cdt-${CDT_VERSION}/build/bin/eosio-cpp ]]; then + #FIO eosio-cpp version 1.5.0 + cdt_version=$(${FIO_CDT_TMP_DIR}/fio.cdt-${CDT_VERSION}/build/bin/eosio-cpp --version | grep version | awk '{print $4}') + if [[ $cdt_version =~ 1.5 ]]; then + #cat ${FIO_CNTRX_TMP_DIR}/cmake-${CMAKE_VERSION}/build/CMakeCache.txt | grep CMAKE_INSTALL_PREFIX | grep ${EOSIO_INSTALL_DIR} >/dev/null + #if [[ $? -eq 0 ]]; then + # return + #fi + return + fi + fi + false +} + +function build-cdt() { + echo "Building fio.cdt..." + execute bash -c "cd ${FIO_CDT_TMP_DIR} \ + && rm -rf fio.cdt-${CDT_VERSION} \ + && git clone https://www.github.com/fioprotocol/fio.cdt.git fio.cdt-${CDT_VERSION} \ + && cd fio.cdt-${CDT_VERSION} \ + && git submodule update --init --recursive \ + && git checkout --recurse-submodules -- . \ + && rm -rf build \ + && git checkout feature/bd-4618-ubuntu-upgrade \ + && ./build.sh -c ${CMAKE_LOCATION}" +} + +function install-cdt() { + echo "Installing fio.cdt..." + execute bash -c "cd $FIO_CDT_TMP_DIR/fio.cdt-${CDT_VERSION} \ + && sudo ./install.sh" +} From 73836f583571199f6de51f75ece03996ece1e4ac Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Wed, 15 May 2024 10:48:53 -0600 Subject: [PATCH 06/19] BD-4617: fio.cdt build/install cleanup --- .build_vars | 1 - utils.sh | 12 ++++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.build_vars b/.build_vars index 164bcdc7..775f3035 100644 --- a/.build_vars +++ b/.build_vars @@ -13,7 +13,6 @@ export CDT_VERSION_PATCH=0 export CDT_VERSION=${CDT_VERSION_MAJOR}.${CDT_VERSION_MINOR}.${CDT_VERSION_PATCH} export FIO_CDT_TMP_DIR=${FIO_CDT_TMP_DIR:-${TEMP_DIR}/fio.cdt} -export FIO_CDT_APTS_DIR=${FIO_CDT_APTS_DIR:-${FIO_CDT_TMP_DIR}/apts} # GENERAL export CURRENT_USER=${CURRENT_USER:-$(whoami)} diff --git a/utils.sh b/utils.sh index 62165265..55eb27cc 100644 --- a/utils.sh +++ b/utils.sh @@ -44,7 +44,6 @@ function setup() { execute-always mkdir -p ${FIO_CNTRX_TMP_DIR} execute mkdir -p ${FIO_CNTRX_APTS_DIR} execute-always mkdir -p ${FIO_CDT_TMP_DIR} - execute mkdir -p ${FIO_CDT_APTS_DIR} } function set-system-vars() { @@ -129,8 +128,8 @@ function install-cmake() { function ensure-fio.cdt() { echo echo "${COLOR_CYAN}[Ensuring fio.cdt installation]${COLOR_NC}" - # if ! hash eosio-cpp; then ... - if [[ ! (-d "${FIO_CDT_APTS_DIR}" && -x ${FIO_CDT_APTS_DIR}/bin/eosio-cpp) ]]; then + #if [[ ! -d "${FIO_CDT_TMP_DIR}/fio.cdt-${CDT_VERSION}/build/bin/eosio-cpp" ]]; then + if ! hash eosio-cpp 2>/dev/null;; then if ! is-cdt-built; then build-cdt fi @@ -138,7 +137,12 @@ function ensure-fio.cdt() { echo " - FIO.CDT successfully installed @ ${FIO_CDT_INSTALL_DIR}" echo "" else - echo " - FIO.CDT found @ ${FIO_CDT_INSTALL_DIR}." + [[ ! -z $(command -v eosio-cpp 2>/dev/null) ]]) && cdt_bin=$(command -v cmake 2>/dev/null) && [[ ${cdt_bin} =~ ${FIO_CDT_INSTALL_DIR} ]] + if [[ $? -eq 0 ]] then + echo " - FIO.CDT found @ ${FIO_CDT_INSTALL_DIR}." + else + echo " - FIO.CDT found @ ${cdt_bin}." + fi echo "" fi } From 196d615a87c0e437a30a29d5641ed0a4f157cf65 Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Wed, 15 May 2024 11:14:07 -0600 Subject: [PATCH 07/19] BD-4617: script fixes --- build.sh | 2 +- utils.sh | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/build.sh b/build.sh index 225d028e..4be955a5 100755 --- a/build.sh +++ b/build.sh @@ -92,7 +92,7 @@ fi ensure-cmake [[ ! -x "${CMAKE}" ]] && echo "CMake not found! Exiting..." && exit 1 -ensure-fio.cdt +ensure-cdt if ! hash eosio-cpp 2>/dev/null; then echo "The FIO Contract Development Toolkit is not installed. If contract development will be performed, either" echo "re-execute this script with the '-t' option or perform the following steps to clone, build and install the" diff --git a/utils.sh b/utils.sh index 55eb27cc..23483aa8 100644 --- a/utils.sh +++ b/utils.sh @@ -125,11 +125,11 @@ function install-cmake() { && make install" } -function ensure-fio.cdt() { +function ensure-cdt() { echo echo "${COLOR_CYAN}[Ensuring fio.cdt installation]${COLOR_NC}" #if [[ ! -d "${FIO_CDT_TMP_DIR}/fio.cdt-${CDT_VERSION}/build/bin/eosio-cpp" ]]; then - if ! hash eosio-cpp 2>/dev/null;; then + if ! hash eosio-cpp 2>/dev/null; then if ! is-cdt-built; then build-cdt fi @@ -137,8 +137,8 @@ function ensure-fio.cdt() { echo " - FIO.CDT successfully installed @ ${FIO_CDT_INSTALL_DIR}" echo "" else - [[ ! -z $(command -v eosio-cpp 2>/dev/null) ]]) && cdt_bin=$(command -v cmake 2>/dev/null) && [[ ${cdt_bin} =~ ${FIO_CDT_INSTALL_DIR} ]] - if [[ $? -eq 0 ]] then + [[ ! -z $(command -v eosio-cpp 2>/dev/null) ]] && cdt_bin=$(command -v cmake 2>/dev/null) && [[ ${cdt_bin} =~ ${FIO_CDT_INSTALL_DIR} ]] + if [[ $? -eq 0 ]]; then echo " - FIO.CDT found @ ${FIO_CDT_INSTALL_DIR}." else echo " - FIO.CDT found @ ${cdt_bin}." From d79b3c8e90cc98de75dd318b0d82b29ddb0544ca Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Wed, 15 May 2024 21:03:59 -0600 Subject: [PATCH 08/19] BD-4617: script fixes --- utils.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils.sh b/utils.sh index 23483aa8..f535d1b2 100644 --- a/utils.sh +++ b/utils.sh @@ -137,7 +137,7 @@ function ensure-cdt() { echo " - FIO.CDT successfully installed @ ${FIO_CDT_INSTALL_DIR}" echo "" else - [[ ! -z $(command -v eosio-cpp 2>/dev/null) ]] && cdt_bin=$(command -v cmake 2>/dev/null) && [[ ${cdt_bin} =~ ${FIO_CDT_INSTALL_DIR} ]] + [[ ! -z $(command -v eosio-cpp 2>/dev/null) ]] && cdt_bin=$(command -v eosio-cpp 2>/dev/null) && [[ "${cdt_bin}" =~ "${FIO_CDT_INSTALL_DIR}" ]] if [[ $? -eq 0 ]]; then echo " - FIO.CDT found @ ${FIO_CDT_INSTALL_DIR}." else From 815699bb0c8edb9b01bed8d3c00c32268b1d8e4a Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Wed, 15 May 2024 21:08:55 -0600 Subject: [PATCH 09/19] BD-4617: added cdt install dir --- .build_vars | 1 + 1 file changed, 1 insertion(+) diff --git a/.build_vars b/.build_vars index 775f3035..b00b2820 100644 --- a/.build_vars +++ b/.build_vars @@ -13,6 +13,7 @@ export CDT_VERSION_PATCH=0 export CDT_VERSION=${CDT_VERSION_MAJOR}.${CDT_VERSION_MINOR}.${CDT_VERSION_PATCH} export FIO_CDT_TMP_DIR=${FIO_CDT_TMP_DIR:-${TEMP_DIR}/fio.cdt} +export FIO_CDT_INSTALL_DIR=${FIO_CDT_INSTALL_DIR:-/usr/local} # GENERAL export CURRENT_USER=${CURRENT_USER:-$(whoami)} From 9e433c6e0a557ce6924143678c845cba4a4bcc4c Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Thu, 16 May 2024 08:07:54 -0600 Subject: [PATCH 10/19] BD-4617: minor cleanup --- utils.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils.sh b/utils.sh index f535d1b2..d5e6820e 100644 --- a/utils.sh +++ b/utils.sh @@ -85,7 +85,7 @@ function ensure-cmake() { echo " - CMAKE successfully installed @ ${CMAKE}" echo "" else - echo " - CMAKE found @ ${CMAKE}." + echo " - CMAKE found @ ${CMAKE}" echo "" fi } @@ -139,9 +139,9 @@ function ensure-cdt() { else [[ ! -z $(command -v eosio-cpp 2>/dev/null) ]] && cdt_bin=$(command -v eosio-cpp 2>/dev/null) && [[ "${cdt_bin}" =~ "${FIO_CDT_INSTALL_DIR}" ]] if [[ $? -eq 0 ]]; then - echo " - FIO.CDT found @ ${FIO_CDT_INSTALL_DIR}." + echo " - FIO.CDT found @ ${FIO_CDT_INSTALL_DIR}" else - echo " - FIO.CDT found @ ${cdt_bin}." + echo " - FIO.CDT found @ ${cdt_bin}" fi echo "" fi From 36c110c931ff228896d62991c0036b9168ee1c3b Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Sat, 18 May 2024 08:37:37 -0600 Subject: [PATCH 11/19] BD-4617: added debug flag --- build.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/build.sh b/build.sh index 4be955a5..042c382e 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -#set -x function usage() { printf "Usage: $0 OPTION... @@ -9,12 +8,17 @@ function usage() { } TIME_BEGIN=$(date -u +%s) +DEBUG=${DEBUG:-false} if [ $# -ne 0 ]; then - while getopts "c:hv" opt; do + while getopts "c:dhv" opt; do case "${opt}" in c) CMAKE_LOCATION=$OPTARG ;; + d) + DEBUG=true + set -x + ;; v) VERBOSE=true ;; From c36f32064dadc08921ef4d5a33a01860c87bdde1 Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Tue, 21 May 2024 07:56:14 -0600 Subject: [PATCH 12/19] BD-4617: removed temp build customization --- .build_vars | 1 - .environment | 3 +-- build.sh | 1 - utils.sh | 30 +++++++++--------------------- 4 files changed, 10 insertions(+), 25 deletions(-) diff --git a/.build_vars b/.build_vars index b00b2820..5951b971 100644 --- a/.build_vars +++ b/.build_vars @@ -12,7 +12,6 @@ export CDT_VERSION_MINOR=5 export CDT_VERSION_PATCH=0 export CDT_VERSION=${CDT_VERSION_MAJOR}.${CDT_VERSION_MINOR}.${CDT_VERSION_PATCH} -export FIO_CDT_TMP_DIR=${FIO_CDT_TMP_DIR:-${TEMP_DIR}/fio.cdt} export FIO_CDT_INSTALL_DIR=${FIO_CDT_INSTALL_DIR:-/usr/local} # GENERAL diff --git a/.environment b/.environment index 41f7fdf8..3b1fed58 100644 --- a/.environment +++ b/.environment @@ -16,7 +16,6 @@ else fi export TEMP_DIR="${TEMP_DIR:-${HOME}/tmp}" -export FIO_CNTRX_TMP_DIR="${FIO_CNTRX_TMP_DIR:-${TEMP_DIR}/fio.cntrx}" -export FIO_CNTRX_APTS_DIR="${FIO_CNTRX_APTS_DIR:-${FIO_CNTRX_TMP_DIR}/apts}" +export FIO_CNTRX_APTS_DIR="${FIO_APTS_DIR:-${TEMP_DIR}/fio/apts}" . ./.build_vars diff --git a/build.sh b/build.sh index 042c382e..87e6297f 100755 --- a/build.sh +++ b/build.sh @@ -151,4 +151,3 @@ printf " \\/__/ \\/__/ \\/__/ \n\n${txtrst}" printf "\\tFor more information:\\n" printf "\\tFIO website: https://fio.net\\n" - diff --git a/utils.sh b/utils.sh index d5e6820e..3b1745da 100644 --- a/utils.sh +++ b/utils.sh @@ -35,15 +35,12 @@ function setup() { if $VERBOSE; then echo "VERBOSE: ${VERBOSE}" echo "TEMP_DIR: ${TEMP_DIR}" - echo "FIO_CNTRX_TMP_DIR: ${FIO_CNTRX_TMP_DIR}" echo "FIO_CNTRX_APTS_DIR: ${FIO_CNTRX_APTS_DIR}" fi ([[ -d ${BUILD_DIR} ]]) && execute rm -rf ${BUILD_DIR} # cleanup old build directory execute mkdir -p ${BUILD_DIR} execute-always mkdir -p ${TEMP_DIR} - execute-always mkdir -p ${FIO_CNTRX_TMP_DIR} - execute mkdir -p ${FIO_CNTRX_APTS_DIR} - execute-always mkdir -p ${FIO_CDT_TMP_DIR} + execute-always mkdir -p $FIO_CNTRX_APTS_DIR } function set-system-vars() { @@ -92,13 +89,9 @@ function ensure-cmake() { # CMake may be built but is it configured for the same install directory??? applies to other repos as well function is-cmake-built() { - if [[ -x ${FIO_CNTRX_TMP_DIR}/cmake-${CMAKE_VERSION}/build/bin/cmake ]]; then - cmake_version=$(${FIO_CNTRX_TMP_DIR}/cmake-${CMAKE_VERSION}/build/bin/cmake --version | grep version | awk '{print $3}') + if [[ -x ${TEMP_DIR}/cmake-${CMAKE_VERSION}/build/bin/cmake ]]; then + cmake_version=$(${TEMP_DIR}/cmake-${CMAKE_VERSION}/build/bin/cmake --version | grep version | awk '{print $3}') if [[ $cmake_version =~ 3.2 ]]; then - #cat ${FIO_CNTRX_TMP_DIR}/cmake-${CMAKE_VERSION}/build/CMakeCache.txt | grep CMAKE_INSTALL_PREFIX | grep ${EOSIO_INSTALL_DIR} >/dev/null - #if [[ $? -eq 0 ]]; then - # return - #fi return fi fi @@ -107,7 +100,7 @@ function is-cmake-built() { function build-cmake() { echo "Building cmake..." - execute bash -c "cd $FIO_CNTRX_TMP_DIR \ + execute bash -c "cd $TEMP_DIR \ && rm -rf cmake-${CMAKE_VERSION} \ && curl -LO https://cmake.org/files/v${CMAKE_VERSION_MAJOR}.${CMAKE_VERSION_MINOR}/cmake-${CMAKE_VERSION}.tar.gz \ && tar -xzf cmake-${CMAKE_VERSION}.tar.gz \ @@ -120,7 +113,7 @@ function build-cmake() { function install-cmake() { echo "Installing cmake..." - execute bash -c "cd $FIO_CNTRX_TMP_DIR/cmake-${CMAKE_VERSION} \ + execute bash -c "cd $TEMP_DIR/cmake-${CMAKE_VERSION} \ && cd build \ && make install" } @@ -128,7 +121,6 @@ function install-cmake() { function ensure-cdt() { echo echo "${COLOR_CYAN}[Ensuring fio.cdt installation]${COLOR_NC}" - #if [[ ! -d "${FIO_CDT_TMP_DIR}/fio.cdt-${CDT_VERSION}/build/bin/eosio-cpp" ]]; then if ! hash eosio-cpp 2>/dev/null; then if ! is-cdt-built; then build-cdt @@ -149,14 +141,10 @@ function ensure-cdt() { # CMake may be built but is it configured for the same install directory??? applies to other repos as well function is-cdt-built() { - if [[ -x ${FIO_CDT_TMP_DIR}/fio.cdt-${CDT_VERSION}/build/bin/eosio-cpp ]]; then + if [[ -x ${TEMP_DIR}/fio.cdt-${CDT_VERSION}/build/bin/eosio-cpp ]]; then #FIO eosio-cpp version 1.5.0 - cdt_version=$(${FIO_CDT_TMP_DIR}/fio.cdt-${CDT_VERSION}/build/bin/eosio-cpp --version | grep version | awk '{print $4}') + cdt_version=$(${TEMP_DIR}/fio.cdt-${CDT_VERSION}/build/bin/eosio-cpp --version | grep version | awk '{print $4}') if [[ $cdt_version =~ 1.5 ]]; then - #cat ${FIO_CNTRX_TMP_DIR}/cmake-${CMAKE_VERSION}/build/CMakeCache.txt | grep CMAKE_INSTALL_PREFIX | grep ${EOSIO_INSTALL_DIR} >/dev/null - #if [[ $? -eq 0 ]]; then - # return - #fi return fi fi @@ -165,7 +153,7 @@ function is-cdt-built() { function build-cdt() { echo "Building fio.cdt..." - execute bash -c "cd ${FIO_CDT_TMP_DIR} \ + execute bash -c "cd ${TEMP_DIR} \ && rm -rf fio.cdt-${CDT_VERSION} \ && git clone https://www.github.com/fioprotocol/fio.cdt.git fio.cdt-${CDT_VERSION} \ && cd fio.cdt-${CDT_VERSION} \ @@ -178,6 +166,6 @@ function build-cdt() { function install-cdt() { echo "Installing fio.cdt..." - execute bash -c "cd $FIO_CDT_TMP_DIR/fio.cdt-${CDT_VERSION} \ + execute bash -c "cd $TEMP_DIR/fio.cdt-${CDT_VERSION} \ && sudo ./install.sh" } From e4f002975cba44f7b01df61b2ed793ea3b857a8a Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Thu, 23 May 2024 07:32:45 -0600 Subject: [PATCH 13/19] BD-4617: added clarifying comments --- build.sh | 1 + utils.sh | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/build.sh b/build.sh index 87e6297f..c697a0a7 100755 --- a/build.sh +++ b/build.sh @@ -81,6 +81,7 @@ echo "Performing OS/System Validation..." 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 ${CMAKE_LOCATION} ]] && [[ -x ${CMAKE_LOCATION}/bin/cmake ]]) && export CMAKE=${CMAKE_LOCATION}/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 CMAKE_LOCATION=${FIO_CNTRX_APTS_DIR} diff --git a/utils.sh b/utils.sh index 3b1745da..40837735 100644 --- a/utils.sh +++ b/utils.sh @@ -69,6 +69,7 @@ function set-system-vars() { export JOBS=${JOBS:-$(( MEM_GIG > CPU_CORES ? CPU_CORES : MEM_GIG ))} } +# Check cmake env var definition, otherwise, build if necessary, install and set env function ensure-cmake() { echo echo "${COLOR_CYAN}[Ensuring CMAKE installation]${COLOR_NC}" @@ -87,7 +88,7 @@ function ensure-cmake() { fi } -# CMake may be built but is it configured for the same install directory??? applies to other repos as well +# Check previous build of cmake, incl version function is-cmake-built() { if [[ -x ${TEMP_DIR}/cmake-${CMAKE_VERSION}/build/bin/cmake ]]; then cmake_version=$(${TEMP_DIR}/cmake-${CMAKE_VERSION}/build/bin/cmake --version | grep version | awk '{print $3}') @@ -98,6 +99,7 @@ function is-cmake-built() { false } +# Download and build cmake function build-cmake() { echo "Building cmake..." execute bash -c "cd $TEMP_DIR \ @@ -118,6 +120,7 @@ function install-cmake() { && make install" } +# Check previous install of cdt, otherwise, download and build if necessary, and install function ensure-cdt() { echo echo "${COLOR_CYAN}[Ensuring fio.cdt installation]${COLOR_NC}" From cfb9eaf879a325b34b15df58562eb9761a91f678 Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Thu, 23 May 2024 08:58:10 -0600 Subject: [PATCH 14/19] BD-4617: revised fio.cdt check --- build.sh | 6 +++--- utils.sh | 8 ++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/build.sh b/build.sh index c697a0a7..d6252e89 100755 --- a/build.sh +++ b/build.sh @@ -99,15 +99,15 @@ ensure-cmake ensure-cdt if ! hash eosio-cpp 2>/dev/null; then - echo "The FIO Contract Development Toolkit is not installed. If contract development will be performed, either" - echo "re-execute this script with the '-t' option or perform the following steps to clone, build and install the" - echo "fio.cdt suite;" + echo "The FIO Contract Development Toolkit is not installed! To build and perform contract development" + 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 diff --git a/utils.sh b/utils.sh index 40837735..de5fd068 100644 --- a/utils.sh +++ b/utils.sh @@ -132,12 +132,8 @@ function ensure-cdt() { echo " - FIO.CDT successfully installed @ ${FIO_CDT_INSTALL_DIR}" echo "" else - [[ ! -z $(command -v eosio-cpp 2>/dev/null) ]] && cdt_bin=$(command -v eosio-cpp 2>/dev/null) && [[ "${cdt_bin}" =~ "${FIO_CDT_INSTALL_DIR}" ]] - if [[ $? -eq 0 ]]; then - echo " - FIO.CDT found @ ${FIO_CDT_INSTALL_DIR}" - else - echo " - FIO.CDT found @ ${cdt_bin}" - fi + [[ ! -z $(command -v eosio-cpp 2>/dev/null) ]] && cdt_bin=$(command -v eosio-cpp 2>/dev/null) + echo " - FIO.CDT found @ ${cdt_bin}" echo "" fi } From e195434348a1ad35a9f7c59f1c79cd825602704f Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Thu, 23 May 2024 09:05:21 -0600 Subject: [PATCH 15/19] BD-4617: revised fio.cdt check (2) --- build.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sh b/build.sh index d6252e89..49ee44a7 100755 --- a/build.sh +++ b/build.sh @@ -99,7 +99,7 @@ ensure-cmake ensure-cdt if ! hash eosio-cpp 2>/dev/null; then - echo "The FIO Contract Development Toolkit is not installed! To build and perform contract development" + 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" From c89d541d510bab210f022a54a700f866d65f6e5b Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Thu, 23 May 2024 09:18:10 -0600 Subject: [PATCH 16/19] BD-4617: revised fio.cdt clone and build --- utils.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/utils.sh b/utils.sh index de5fd068..cd71dba6 100644 --- a/utils.sh +++ b/utils.sh @@ -153,8 +153,7 @@ function is-cdt-built() { function build-cdt() { echo "Building fio.cdt..." execute bash -c "cd ${TEMP_DIR} \ - && rm -rf fio.cdt-${CDT_VERSION} \ - && git clone https://www.github.com/fioprotocol/fio.cdt.git fio.cdt-${CDT_VERSION} \ + && [[ -d fio.cdt-${CDT_VERSION} ]] || git clone https://www.github.com/fioprotocol/fio.cdt.git fio.cdt-${CDT_VERSION} \ && cd fio.cdt-${CDT_VERSION} \ && git submodule update --init --recursive \ && git checkout --recurse-submodules -- . \ From bbbeceecbffa7dc8b3c097de105c2b1f20e4a2dc Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Thu, 23 May 2024 11:43:56 -0600 Subject: [PATCH 17/19] BD-4617: removed branch checkout --- utils.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/utils.sh b/utils.sh index cd71dba6..8747960e 100644 --- a/utils.sh +++ b/utils.sh @@ -158,7 +158,6 @@ function build-cdt() { && git submodule update --init --recursive \ && git checkout --recurse-submodules -- . \ && rm -rf build \ - && git checkout feature/bd-4618-ubuntu-upgrade \ && ./build.sh -c ${CMAKE_LOCATION}" } From 3328e8f6a41068495f477090f2f8b12f53edaa23 Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Sat, 25 May 2024 10:03:51 -0600 Subject: [PATCH 18/19] BD-4617: Updated cdt section in readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index caf09157..611f7b1d 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ The included icons are provided under the same terms as the software and accompa ## Build Information The build script is located in main directory. Note that smart contracts are NOT installed per say; they are uploaded to the chain via clio, if a development chain, or via a multi-sig if a production chain. -### Build FIO smart contract +### Build The build script is straight-forward; it checks for any dependencies, then builds the contracts, putting the artifacts into the build directory. To build, first change to the `~/fioprotocol/fio.contracts` folder, then execute the script as follows: @@ -52,7 +52,7 @@ The build process writes all content to the `build` folder. ### Dependencies: [fio.cdt](https://github.com/fioprotocol/fio.cdt/tree/release/1.5.x) -fio.cdt, version 1.5.x, must be installed onto the build machine in order for the contracts to successfully build. This can be done by cloning the fio.cdt repo, then running build.sh and install.sh. Note that the fio.cdt artifacts are installed into `/usr/local` under the folder eosio.cdt and links are created to these artifacts in `/usr/local/bin`. Note: fio.cdt is a customized version of eosio.cdt but as such any installed artifacts retain the prefix of eosio. +fio.cdt, version 1.5.x, must be installed onto the build machine in order for the contracts to successfully build. As such, the fio.contracts build script will automatically install the cdt (contract development toolkit), however, a manual build may be done by cloning the fio.cdt repo, then running build.sh and install.sh. Note that the fio.cdt artifacts are installed into `/usr/local` under the folder eosio.cdt and links are created to these artifacts in `/usr/local/bin`. Note: fio.cdt is a customized version of eosio.cdt but as such any installed artifacts retain the prefix of eosio. [fio](https://github.com/fioprotocol/fio/) While the FIO core blockchain is not a direct dependency of fio.contracts, in order to successfully execute contract functionality, getters may be called that are part of the blockchain. FIO contracts are backward compatible* to multiple versions of the blockchain. The latest release of fio.contracts aligns to the latest release of the fio.blockchain. The latest release may be found [here](https://github.com/fioprotocol/fio/releases). From 46d481ef49f397fc589fe29dd7e0c230e33bd2db Mon Sep 17 00:00:00 2001 From: Michael Leet Date: Sun, 2 Jun 2024 07:42:39 -0600 Subject: [PATCH 19/19] BD-4617: revised cmake install dir handling, removed always clean on build, corrected os version check msg --- build.sh | 23 +++++++++++++++++------ utils.sh | 6 +++--- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/build.sh b/build.sh index 49ee44a7..524bab4e 100755 --- a/build.sh +++ b/build.sh @@ -7,13 +7,19 @@ function usage() { exit 1 } -TIME_BEGIN=$(date -u +%s) +CLEAN=${CLEAN:-false} DEBUG=${DEBUG:-false} +VERBOSE=${VERBOSE:-false} + +TIME_BEGIN=$(date -u +%s) if [ $# -ne 0 ]; then - while getopts "c:dhv" opt; do + while getopts "a:cdhv" opt; do case "${opt}" in + a) + APTS_DIR=$OPTARG + ;; c) - CMAKE_LOCATION=$OPTARG + CLEAN=true ;; d) DEBUG=true @@ -41,8 +47,13 @@ if [ $# -ne 0 ]; then 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 @@ -75,7 +86,7 @@ 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 or 20.04.x to install EOSIO." && exit 1) +([[ $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 @@ -83,8 +94,8 @@ 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 ${CMAKE_LOCATION} ]] && [[ -x ${CMAKE_LOCATION}/bin/cmake ]]) && export CMAKE=${CMAKE_LOCATION}/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 CMAKE_LOCATION=${FIO_CNTRX_APTS_DIR} +([[ -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') diff --git a/utils.sh b/utils.sh index 8747960e..6dc6b2b1 100644 --- a/utils.sh +++ b/utils.sh @@ -37,7 +37,7 @@ function setup() { echo "TEMP_DIR: ${TEMP_DIR}" echo "FIO_CNTRX_APTS_DIR: ${FIO_CNTRX_APTS_DIR}" fi - ([[ -d ${BUILD_DIR} ]]) && execute rm -rf ${BUILD_DIR} # cleanup old build directory + ([[ -d ${BUILD_DIR} ]]) && ${CLEAN} && execute rm -rf ${BUILD_DIR} # cleanup old build directory execute mkdir -p ${BUILD_DIR} execute-always mkdir -p ${TEMP_DIR} execute-always mkdir -p $FIO_CNTRX_APTS_DIR @@ -78,7 +78,7 @@ function ensure-cmake() { build-cmake fi install-cmake - export CMAKE_LOCATION=${CMAKE_INSTALL_DIR} + export APTS_DIR=${CMAKE_INSTALL_DIR} export CMAKE="${CMAKE_INSTALL_DIR}/bin/cmake" echo " - CMAKE successfully installed @ ${CMAKE}" echo "" @@ -158,7 +158,7 @@ function build-cdt() { && git submodule update --init --recursive \ && git checkout --recurse-submodules -- . \ && rm -rf build \ - && ./build.sh -c ${CMAKE_LOCATION}" + && ./build.sh -a ${APTS_DIR}" } function install-cdt() {