Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #7553 from EOSIO/cmake-required-version-check
Browse files Browse the repository at this point in the history
[develop] CMAKE version check before dependencies are installed
  • Loading branch information
NorseGaud authored Jul 2, 2019
2 parents 8abddec + cee9752 commit c760c42
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 2 additions & 0 deletions scripts/.environment
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ else
export EOSIO_VERSION_FULL="${EOSIO_VERSION_MAJOR}.${EOSIO_VERSION_MINOR}.${EOSIO_VERSION_PATCH}-${EOSIO_VERSION_SUFFIX}"
fi

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 EOSIO_INSTALL_DIR="${EOSIO_INSTALL_DIR:-${HOME}/eosio/${EOSIO_VERSION}}"
export TEMP_DIR="${TEMP_DIR:-${HOME}/tmp}"

Expand Down
12 changes: 11 additions & 1 deletion scripts/eosio_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,17 @@ execute cd $REPO_ROOT
ensure-submodules-up-to-date

# Check if cmake already exists
( [[ -z "${CMAKE}" ]] && [[ ! -z $(command -v cmake 2>/dev/null) ]] ) && export CMAKE=$(command -v cmake 2>/dev/null)
( [[ -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
export CMAKE=
if [[ $ARCH == 'Darwin' ]]; 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
else
echo "${COLOR_YELLOW}The currently installed cmake version ($CMAKE_CURRENT_VERSION) is less than the required version ($CMAKE_REQUIRED_VERSION). We will be installing $CMAKE_VERSION.${COLOR_NC}"
fi
fi

# Use existing cmake on system (either global or specific to eosio)
# Setup based on architecture
Expand Down
2 changes: 1 addition & 1 deletion tests/bash-bats/eosio_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ TEST_LABEL="[eosio_build]"
run bash -c "printf \"y\ny\ny\nn\nn\n\" | ./${SCRIPT_LOCATION}"
[[ ! -z $(echo "${output}" | grep "Unable to find .* compiler") ]] || exit
fi
fi
fi

cd ./scripts # Also test that we can run the script from a directory other than the root
run bash -c "./eosio_build.sh -y -P"
Expand Down
24 changes: 24 additions & 0 deletions tests/bash-bats/modules/cmake.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,37 @@
load ../helpers/functions

@test "${TEST_LABEL} > Testing CMAKE" {

# Testing for if CMAKE already exists
export CMAKE=${HOME}/cmake
touch $CMAKE
export CMAKE_CURRENT_VERSION=3.7.1
run bash -c " ./$SCRIPT_LOCATION -y -P"
if [[ $ARCH == "Darwin" ]]; then
[[ "${output##*$'\n'}" =~ "($CMAKE_REQUIRED_VERSION). Cannot proceed" ]] || exit # Test the required version
else
[[ ! -z $(echo "${output}" | grep "We will be installing $CMAKE_VERSION") ]] || exit # Test the required version
[[ ! -z $(echo "${output}" | grep "Executing: bash -c ${BIN_DIR}/cmake") ]] || exit
fi
export CMAKE_CURRENT_VERSION=
run bash -c " ./$SCRIPT_LOCATION -y -P"
[[ ! -z $(echo "${output}" | grep "Executing: bash -c ${HOME}/cmake") ]] || exit
if [[ $ARCH != "Darwin" ]]; then
[[ -z $(echo "${output}" | grep "CMAKE successfully installed") ]] || exit
fi

# Testing for if cmake doesn't exist to be sure it's set properly
export CMAKE=
export CMAKE_CURRENT_VERSION=3.6
run bash -c "./$SCRIPT_LOCATION -y -P"
if [[ $ARCH == "Darwin" ]]; then
[[ "${output##*$'\n'}" =~ "($CMAKE_REQUIRED_VERSION). Cannot proceed" ]] || exit # Test the required version
else
[[ ! -z $(echo "${output}" | grep "We will be installing $CMAKE_VERSION") ]] || exit # Test the required version
[[ ! -z $(echo "${output}" | grep "Executing: bash -c ${BIN_DIR}/cmake") ]] || exit
[[ ! -z $(echo "${output}" | grep "CMAKE successfully installed") ]] || exit
fi
export CMAKE_CURRENT_VERSION=
run bash -c "./$SCRIPT_LOCATION -y -P"
if [[ $ARCH == "Darwin" ]]; then
[[ ! -z $(echo "${output}" | grep "Executing: bash -c /usr/local/bin/cmake -DCMAKE_BUILD") ]] || exit
Expand Down

0 comments on commit c760c42

Please sign in to comment.