From 03e6f41eb6647a9d55867709d9c4736a43657469 Mon Sep 17 00:00:00 2001 From: Julien Maffre <42961061+jumaffre@users.noreply.github.com> Date: Thu, 25 Jun 2020 11:45:58 +0100 Subject: [PATCH] cchost --version (#1323) --- .azure-pipelines-templates/matrix.yml | 4 -- .azure-pipelines-templates/release_checks.yml | 14 ----- CMakeLists.txt | 15 +++-- check-cmake-version-vs-tag.sh | 25 -------- cmake/common.cmake | 12 +--- cmake/version.cmake | 57 +++++++++++++++++++ src/host/main.cpp | 10 ++++ src/host/version.h.in | 10 ++++ 8 files changed, 89 insertions(+), 58 deletions(-) delete mode 100644 .azure-pipelines-templates/release_checks.yml delete mode 100755 check-cmake-version-vs-tag.sh create mode 100644 cmake/version.cmake create mode 100644 src/host/version.h.in diff --git a/.azure-pipelines-templates/matrix.yml b/.azure-pipelines-templates/matrix.yml index 3f8b0c2664..673fbf47ef 100644 --- a/.azure-pipelines-templates/matrix.yml +++ b/.azure-pipelines-templates/matrix.yml @@ -70,10 +70,6 @@ jobs: # Release - ${{ if eq(parameters.perf_or_release, 'release') }}: - - template: release_checks.yml - parameters: - env: ${{ parameters.env.Hosted }} - - template: common.yml parameters: target: SGX diff --git a/.azure-pipelines-templates/release_checks.yml b/.azure-pipelines-templates/release_checks.yml deleted file mode 100644 index a9602f1d50..0000000000 --- a/.azure-pipelines-templates/release_checks.yml +++ /dev/null @@ -1,14 +0,0 @@ -jobs: -- job: Release_Checks - displayName: 'Check code is ready for release' - - ${{ insert }}: ${{ parameters.env }} - - steps: - - checkout: self - clean: true - submodules: true - - - script: ./check-cmake-version-vs-tag.sh - displayName: 'Check project version in CMake matches git tag' - condition: succeededOrFailed() \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 8b6b193522..0a978e0721 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,19 +4,18 @@ cmake_minimum_required(VERSION 3.11) set(CCF_DIR ${CMAKE_CURRENT_SOURCE_DIR}) include(${CCF_DIR}/cmake/preproject.cmake) +include(${CCF_DIR}/cmake/version.cmake) project( ccf - VERSION 0.11.1 + VERSION ${CCF_RELEASE_VERSION} LANGUAGES C CXX ) set(ENV{BETTER_EXCEPTIONS} 1) -set(CCF_PROJECT_NAME_SUFFIX "") -set(CCF_PROJECT_NAME "${PROJECT_VERSION}${CCF_PROJECT_NAME_SUFFIX}") - -message(STATUS "CCF version=${CCF_PROJECT_NAME}") +message(STATUS "CCF version=${CCF_VERSION}") +message(STATUS "CCF release version=${CCF_RELEASE_VERSION}") # Set the default install prefix for CCF. Users may override this value with the # cmake command. For example: @@ -25,7 +24,7 @@ message(STATUS "CCF version=${CCF_PROJECT_NAME}") # if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX - "/opt/ccf/ccf-${CCF_PROJECT_NAME}" + "/opt/ccf/ccf-${CCF_VERSION}" CACHE PATH "Default install prefix" FORCE ) endif() @@ -39,6 +38,10 @@ install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/preproject.cmake include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/common.cmake) include(${CMAKE_CURRENT_SOURCE_DIR}/cmake/pbft.cmake) +configure_file( + ${CCF_DIR}/src/host/version.h.in ${CCF_GENERATED_DIR}/version.h @ONLY +) + set(CONSENSUSES raft pbft) option(BUILD_TESTS "Build tests" ON) diff --git a/check-cmake-version-vs-tag.sh b/check-cmake-version-vs-tag.sh deleted file mode 100755 index 3fb41e229a..0000000000 --- a/check-cmake-version-vs-tag.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the Apache 2.0 License. - -git_tag=$(git describe --tags --abbrev=0) -git_tag=${git_tag#v} - -# Check if git tag looks like a semver value - ignore if not -if [[ ${git_tag} =~ ^([[:digit:]])+(\.([[:digit:]])+)*(-.*)?$ ]]; then - mkdir -p build - pushd build - cmake_version=$(cmake .. -L | grep "CCF version=") - cmake_version=${cmake_version#*=} - echo "Comparing git tag ($git_tag) with CMake version ($cmake_version)" - if [[ "${git_tag}" == "${cmake_version}" ]]; then - echo "Git tag ($git_tag) matches CMake version ($cmake_version)" - exit 0 - else - echo "Git tag ($git_tag) does not match CMake version ($cmake_version) - please update CMake version" - exit 1 - fi -else - echo "Skipping check - ${git_tag} doesn't look like semver" - exit 0 -fi \ No newline at end of file diff --git a/cmake/common.cmake b/cmake/common.cmake index 2ec63c29dd..bba3e0aae7 100644 --- a/cmake/common.cmake +++ b/cmake/common.cmake @@ -109,14 +109,8 @@ install(PROGRAMS ${CCF_DIR}/tests/scurl.sh ${CCF_DIR}/tests/keygenerator.sh install(DIRECTORY ${CCF_DIR}/getting_started/ DESTINATION getting_started) if("sgx" IN_LIST COMPILE_TARGETS) - # If OE was built with LINK_SGX=1, then we also need to link SGX - if(OE_SGX) - message(STATUS "Linking SGX") - set(SGX_LIBS sgx_enclave_common sgx_dcap_ql sgx_urts) - - if(NOT DISABLE_QUOTE_VERIFICATION) - set(QUOTES_ENABLED ON) - endif() + if(NOT DISABLE_QUOTE_VERIFICATION) + set(QUOTES_ENABLED ON) endif() if(CMAKE_BUILD_TYPE STREQUAL "Debug") @@ -204,7 +198,6 @@ if("sgx" IN_LIST COMPILE_TARGETS) target_link_libraries( cchost PRIVATE uv - ${SGX_LIBS} ${CRYPTO_LIBRARY} ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT} @@ -239,6 +232,7 @@ if("virtual" IN_LIST COMPILE_TARGETS) target_compile_options(cchost.virtual PRIVATE -stdlib=libc++) target_include_directories( cchost.virtual PRIVATE ${CMAKE_CURRENT_BINARY_DIR} ${OE_INCLUDEDIR} + ${CCF_GENERATED_DIR} ) add_san(cchost.virtual) enable_coverage(cchost.virtual) diff --git a/cmake/version.cmake b/cmake/version.cmake new file mode 100644 index 0000000000..283341a7ae --- /dev/null +++ b/cmake/version.cmake @@ -0,0 +1,57 @@ +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the Apache 2.0 License. + +unset(CCF_VERSION) +unset(CCF_RELEASE_VERSION) + +# If possible, deduce project version from git environment +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.git) + find_package(Git) + + execute_process( + COMMAND ${GIT_EXECUTABLE} describe --tags + OUTPUT_VARIABLE "CCF_VERSION" + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + execute_process( + COMMAND "bash" "-c" "${GIT_EXECUTABLE} describe --tags --abbrev=0 | tr -d v" + OUTPUT_VARIABLE "CCF_RELEASE_VERSION" OUTPUT_STRIP_TRAILING_WHITESPACE + ) +endif() + +if(NOT CCF_RELEASE_VERSION) + # If not in a git environment (e.g. release tarball), deduce version from the + # source directory name + execute_process( + COMMAND "bash" "-c" + "[[ $(basename ${CMAKE_CURRENT_SOURCE_DIR}) =~ ^CCF-.* ]]" + RESULT_VARIABLE "IS_CCF_FOLDER" + ) + + if(NOT ${IS_CCF_FOLDER} STREQUAL "0") + message(FATAL_ERROR "Sources directory is not in \"CCF-...\" folder") + endif() + + execute_process( + COMMAND "bash" "-c" "basename ${CMAKE_CURRENT_SOURCE_DIR} | cut -d'-' -f2" + OUTPUT_VARIABLE "CCF_VERSION" OUTPUT_STRIP_TRAILING_WHITESPACE + ) + + set(CCF_RELEASE_VERSION ${CCF_VERSION}) + message(STATUS "CCF version deduced from sources directory: ${CCF_VERSION}") +endif() + +# Check that release version is semver +execute_process( + COMMAND "bash" "-c" + "[[ ${CCF_RELEASE_VERSION} =~ ^([[:digit:]])+(\.([[:digit:]])+)*$ ]]" + RESULT_VARIABLE "VERSION_IS_SEMVER" +) + +if(NOT ${VERSION_IS_SEMVER} STREQUAL "0") + message( + WARNING + "Release version \"${CCF_RELEASE_VERSION}\" does not follow semver. Defaulting to project version 0.0.0" + ) + set(CCF_RELEASE_VERSION "0.0.0") +endif() diff --git a/src/host/main.cpp b/src/host/main.cpp index ac8687e796..b4f669b231 100644 --- a/src/host/main.cpp +++ b/src/host/main.cpp @@ -15,6 +15,7 @@ #include "sig_term.h" #include "ticker.h" #include "time_updater.h" +#include "version.h" #include #include @@ -31,6 +32,12 @@ using namespace std::chrono_literals; ::timespec logger::config::start{0, 0}; +void print_version(size_t) +{ + std::cout << "CCF host: " << ccf::ccf_version << std::endl; + exit(0); +} + int main(int argc, char** argv) { // ignore SIGPIPE @@ -42,6 +49,9 @@ int main(int argc, char** argv) app.set_config("--config", "", "Read an INI or TOML file", false); app.allow_config_extras(false); + app.add_flag( + "-v, --version", print_version, "Display CCF host version and exit"); + app.require_subcommand(1, 1); std::string enclave_file; diff --git a/src/host/version.h.in b/src/host/version.h.in new file mode 100644 index 0000000000..7b2aa02edf --- /dev/null +++ b/src/host/version.h.in @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the Apache 2.0 License. +#pragma once + +#include + +namespace ccf +{ + static constexpr auto ccf_version = "@CCF_VERSION@"; +} \ No newline at end of file