Skip to content

Commit

Permalink
Merge pull request boscore#89 from EOSIO/81-better-dependency-version…
Browse files Browse the repository at this point in the history
…-check

Improved dependency version checker
  • Loading branch information
arhag authored Oct 2, 2018
2 parents a105558 + df48385 commit a0e9311
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 23 deletions.
37 changes: 22 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
cmake_minimum_required(VERSION 3.5)
project(eosio_contracts VERSION 1.3.1)

set(EOSIO_DEPENDENCY "1.2")
set(EOSIO_CDT_DEPENDENCY "1.2")
set(EOSIO_CDT_VERSION_MIN "1.2") # REMINDER: Change this to 1.3 before release
set(EOSIO_CDT_VERSION_SOFT_MAX "1.3")
#set(EOSIO_CDT_VERSION_HARD_MAX "")

include(CheckVersion.txt)

find_package(eosio.cdt)

### Check the version of eosio.cdt
set(VERSION_MATCH_ERROR_MSG "")
EOSIO_CHECK_VERSION(VERSION_OUTPUT "${EOSIO_CDT_VERSION}"
"${EOSIO_CDT_VERSION_MIN}"
"${EOSIO_CDT_VERSION_SOFT_MAX}"
"${EOSIO_CDT_VERSION_HARD_MAX}"
VERSION_MATCH_ERROR_MSG)
if(VERSION_OUTPUT STREQUAL "MATCH")
message(STATUS "Using eosio.cdt version ${EOSIO_CDT_VERSION}")
elseif(VERSION_OUTPUT STREQUAL "WARN")
message(WARNING "Using eosio.cdt version ${EOSIO_CDT_VERSION} even though it exceeds the maximum supported version of ${EOSIO_CDT_VERSION_SOFT_MAX}; continuing with configuration, however build may fail.\nIt is recommended to use eosio.cdt version ${EOSIO_CDT_VERSION_SOFT_MAX}.x")
else() # INVALID OR MISMATCH
message(FATAL_ERROR "Found eosio.cdt version ${EOSIO_CDT_VERSION} but it does not satisfy version requirements: ${VERSION_MATCH_ERROR_MSG}\nPlease use eosio.cdt version ${EOSIO_CDT_VERSION_SOFT_MAX}.x")
endif(VERSION_OUTPUT STREQUAL "MATCH")

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(TEST_BUILD_TYPE "Debug")
Expand All @@ -11,20 +31,7 @@ else()
set(TEST_BUILD_TYPE ${CMAKE_BUILD_TYPE})
endif()

if(EOSIO_ROOT STREQUAL "" OR NOT EOSIO_ROOT)
set(EOSIO_ROOT "/usr/local/eosio")
endif()

find_package(eosio.cdt)

### Check the version of eosio.cdt
string(FIND "${EOSIO_CDT_VERSION}" "${EOSIO_CDT_DEPENDENCY}" output)

if (NOT "${output}" EQUAL 0)
message(FATAL_ERROR "Incorrect EOSIO.CDT version, please use version ${EOSIO_CDT_DEPENDENCY}.x")
endif()

include_directories(AFTER ${BOOST_ROOT}/include)
add_subdirectory(eosio.bios)
add_subdirectory(eosio.msig)
add_subdirectory(eosio.sudo)
Expand Down
90 changes: 90 additions & 0 deletions CheckVersion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
function(EXTRACT_MAJOR_MINOR_FROM_VERSION version success major minor)
string(REGEX REPLACE "^([0-9]+)\\..+$" "\\1" _major "${version}")
if("${_major}" STREQUAL "${version}")
set(${success} FALSE PARENT_SCOPE)
return()
endif()

string(REGEX REPLACE "^[0-9]+\\.([0-9]+)(\\..*)?$" "\\1" _minor "${version}")
if("${_minor}" STREQUAL "${version}")
set(success FALSE PARENT_SCOPE)
return()
endif()

set(${major} ${_major} PARENT_SCOPE)
set(${minor} ${_minor} PARENT_SCOPE)
set(${success} TRUE PARENT_SCOPE)
endfunction(EXTRACT_MAJOR_MINOR_FROM_VERSION)

function(EOSIO_CHECK_VERSION output version hard_min soft_max hard_max) # optional 6th argument for error message
set(${output} "INVALID" PARENT_SCOPE)

EXTRACT_MAJOR_MINOR_FROM_VERSION("${version}" success major minor)
if(NOT success)
if(${ARGC} GREATER 5)
set(${ARGV5} "version '${version}' is invalid" PARENT_SCOPE)
endif()
return()
endif()

EXTRACT_MAJOR_MINOR_FROM_VERSION("${hard_min}" success hard_min_major hard_min_minor)
if(NOT success)
if(${ARGC} GREATER 5)
set(${ARGV5} "hard minimum version '${hard_min}' is invalid" PARENT_SCOPE)
endif()
return()
endif()

if( "${major}.${minor}" VERSION_LESS "${hard_min_major}.${hard_min_minor}" )
set(${output} "MISMATCH" PARENT_SCOPE)
if(${ARGC} GREATER 5)
set(${ARGV5} "version '${version}' does not meet hard minimum version requirement of ${hard_min_major}.${hard_min_minor}" PARENT_SCOPE)
endif()
return()
endif()

if(NOT hard_max STREQUAL "")
EXTRACT_MAJOR_MINOR_FROM_VERSION("${hard_max}" success hard_max_major hard_max_minor)
if(NOT success)
if(${ARGC} GREATER 5)
set(${ARGV5} "hard maximum version '${hard_max}' is invalid" PARENT_SCOPE)
endif()
return()
endif()

if( "${major}.${minor}" VERSION_GREATER "${hard_max_major}.${hard_max_minor}" )
set(${output} "MISMATCH" PARENT_SCOPE)
if(${ARGC} GREATER 5)
set(${ARGV5} "version '${version}' does not meet hard maximum version requirement of ${hard_max_major}.${hard_max_minor}" PARENT_SCOPE)
endif()
return()
endif()
endif()

EXTRACT_MAJOR_MINOR_FROM_VERSION("${soft_max}" success soft_max_major soft_max_minor)
if(NOT success)
set(${output} "MISMATCH" PARENT_SCOPE)
if(${ARGC} GREATER 5)
set(${ARGV5} "soft maximum version '${soft_max}' is invalid" PARENT_SCOPE)
endif()
return()
endif()

if( ${major} GREATER ${soft_max_major} )
set(${output} "MISMATCH" PARENT_SCOPE)
if(${ARGC} GREATER 5)
set(${ARGV5} "version '${version}' must have the same major version as the soft maximum version (${soft_max_major})" PARENT_SCOPE)
endif()
return()
endif()

if( "${major}.${minor}" VERSION_GREATER "${soft_max_major}.${soft_max_minor}" )
set(${output} "WARN" PARENT_SCOPE)
if(${ARGC} GREATER 5)
set(${ARGV5} "version '${version}' matches requirements but is greater than the soft maximum version of ${soft_max_major}.${soft_max_minor}" PARENT_SCOPE)
endif()
return()
endif()

set(${output} "MATCH" PARENT_SCOPE)
endfunction(EOSIO_CHECK_VERSION)
5 changes: 2 additions & 3 deletions UnitTestsExternalProject.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ find_package(Git REQUIRED)
include(GNUInstallDirs)

ExternalProject_Add(
contracts_unit_tests
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${TEST_BUILD_TYPE} -DEOSIO_ROOT=${EOSIO_ROOT} -DEOSIO_DEPENDENCY=${EOSIO_DEPENDENCY}

contracts_unit_tests
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${TEST_BUILD_TYPE} -DEOSIO_ROOT=${EOSIO_ROOT}
SOURCE_DIR ${CMAKE_SOURCE_DIR}/tests
BINARY_DIR ${CMAKE_BINARY_DIR}/tests
BUILD_ALWAYS 1
Expand Down
29 changes: 24 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
cmake_minimum_required( VERSION 3.5 )

set(EOSIO_VERSION_MIN "1.2")
set(EOSIO_VERSION_SOFT_MAX "1.2")
#set(EOSIO_VERSION_HARD_MAX "")

include(../CheckVersion.txt)

if(EOSIO_ROOT STREQUAL "" OR NOT EOSIO_ROOT)
set(EOSIO_ROOT "/usr/local/eosio")
endif()

list(APPEND CMAKE_MODULE_PATH ${EOSIO_ROOT}/lib/cmake)
include(EosioTester)

### check the version of EOSIO
string(FIND "${EOSIO_VERSION}" "${EOSIO_DEPENDENCY}" output)
if (NOT "${output}" EQUAL 0)
message(FATAL_ERROR "Incorrect EOSIO version, please use version ${EOSIO_DEPENDENCY}.x")
endif()
### Check the version of eosio
set(VERSION_MATCH_ERROR_MSG "")
EOSIO_CHECK_VERSION(VERSION_OUTPUT "${EOSIO_VERSION}"
"${EOSIO_VERSION_MIN}"
"${EOSIO_VERSION_SOFT_MAX}"
"${EOSIO_VERSION_HARD_MAX}"
VERSION_MATCH_ERROR_MSG)
if(VERSION_OUTPUT STREQUAL "MATCH")
message(STATUS "Using eosio version ${EOSIO_VERSION}")
elseif(VERSION_OUTPUT STREQUAL "WARN")
message(WARNING "Using eosio version ${EOSIO_VERSION} even though it exceeds the maximum supported version of ${EOSIO_VERSION_SOFT_MAX}; continuing with configuration, however build may fail.\nIt is recommended to use eosio version ${EOSIO_VERSION_SOFT_MAX}.x")
else() # INVALID OR MISMATCH
message(FATAL_ERROR "Found eosio version ${EOSIO_VERSION} but it does not satisfy version requirements: ${VERSION_MATCH_ERROR_MSG}\nPlease use eosio version ${EOSIO_VERSION_SOFT_MAX}.x")
endif(VERSION_OUTPUT STREQUAL "MATCH")


enable_testing()
Expand Down

0 comments on commit a0e9311

Please sign in to comment.