From b54a292ba265e65b6a4499f8d6f49010db932f47 Mon Sep 17 00:00:00 2001 From: Klein Hu Date: Fri, 24 May 2019 17:30:40 -0700 Subject: [PATCH] Add version and latest commit id to ONNX Runtime Server (#1078) * Add version and latest commit id to ORT Server * Update cmake * Change build id to build number * Use target_compile_definitions instead of add_definitions --- cmake/onnxruntime_server.cmake | 8 +++++ onnxruntime/server/main.cc | 32 +++++++++++++++++++ .../linux-ort-srv-nightly-pipeline.yml | 2 +- 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/cmake/onnxruntime_server.cmake b/cmake/onnxruntime_server.cmake index 7e85aae615..64889d3d84 100644 --- a/cmake/onnxruntime_server.cmake +++ b/cmake/onnxruntime_server.cmake @@ -108,6 +108,14 @@ if(NOT WIN32) endif() endif() +set(onnxruntime_SERVER_VERSION "local-build" CACHE STRING "Sever version") +target_compile_definitions(${SERVER_APP_NAME} PUBLIC SRV_VERSION="${onnxruntime_SERVER_VERSION}") +message(STATUS "ONNX Runtime Server version set to: ${onnxruntime_SERVER_VERSION}") + +set(onnxruntime_LATEST_COMMIT_ID "default" CACHE STRING "The latest commit id") +target_compile_definitions(${SERVER_APP_NAME} PUBLIC LATEST_COMMIT_ID="${onnxruntime_LATEST_COMMIT_ID}") +message(STATUS "ONNX Runtime Server latest commit id is: ${onnxruntime_LATEST_COMMIT_ID}") + onnxruntime_add_include_to_target(${SERVER_APP_NAME} onnxruntime_session onnxruntime_server_lib gsl onnx onnx_proto server_proto) target_include_directories(${SERVER_APP_NAME} PRIVATE diff --git a/onnxruntime/server/main.cc b/onnxruntime/server/main.cc index f938a98c11..2a3a105f7a 100644 --- a/onnxruntime/server/main.cc +++ b/onnxruntime/server/main.cc @@ -6,11 +6,43 @@ #include "predict_request_handler.h" #include "server_configuration.h" +#define VALUE_TO_STRING(x) #x +#define VALUE(x) VALUE_TO_STRING(x) +#define VAR_NAME_VALUE(var) #var "=" VALUE(var) + +#define LOCAL_BUILD_VERSION "local_build" +#if !defined(SRV_VERSION) +#define SRV_VERSION LOCAL_BUILD_VERSION +#endif +#pragma message(VAR_NAME_VALUE(SRV_VERSION)) + +#define DEFAULT_COMMIT_ID "default" +#if !defined(LATEST_COMMIT_ID) +#define LATEST_COMMIT_ID DEFAULT_COMMIT_ID +#endif +#pragma message(VAR_NAME_VALUE(LATEST_COMMIT_ID)) + namespace beast = boost::beast; namespace http = beast::http; namespace server = onnxruntime::server; int main(int argc, char* argv[]) { + // Here we use std::cout print out the version and latest commit id, + // to make sure in case even logger has problem, we still have the version information and commit id. + std::string version = SRV_VERSION; + if (version.empty()){ + version = LOCAL_BUILD_VERSION; + } + + std::string commit_id = LATEST_COMMIT_ID; + if (commit_id.empty()){ + commit_id = DEFAULT_COMMIT_ID; + } + + std::cout << "Version: " << version << std::endl; + std::cout << "Commit ID: " << commit_id << std::endl; + std::cout << std::endl; + server::ServerConfiguration config{}; auto res = config.ParseInput(argc, argv); diff --git a/tools/ci_build/github/azure-pipelines/linux-ort-srv-nightly-pipeline.yml b/tools/ci_build/github/azure-pipelines/linux-ort-srv-nightly-pipeline.yml index 66871a3aa3..9ae7351ac7 100644 --- a/tools/ci_build/github/azure-pipelines/linux-ort-srv-nightly-pipeline.yml +++ b/tools/ci_build/github/azure-pipelines/linux-ort-srv-nightly-pipeline.yml @@ -30,7 +30,7 @@ jobs: pythonInterpreter: '/usr/bin/python3' workingDirectory: $(Build.BinariesDirectory) - - script: 'tools/ci_build/github/linux/run_dockerbuild.sh -o ubuntu16.04 -d cpu -r $(Build.BinariesDirectory) -x "--config Debug --build_server --use_openmp --use_full_protobuf --enable_server_model_tests"' + - script: 'tools/ci_build/github/linux/run_dockerbuild.sh -o ubuntu16.04 -d cpu -r $(Build.BinariesDirectory) -x "--config RelWithDebInfo --build_server --use_openmp --use_full_protobuf --enable_server_model_tests --cmake_extra_defines onnxruntime_SERVER_VERSION=$(cat ./VERSION_NUMBER)-$(Build.BuildNumber) onnxruntime_LATEST_COMMIT_ID=$(Build.SourceVersion)"' displayName: 'Run build script with model tests' - task: ms.vss-governance-buildtask.governance-build-task-component-detection.ComponentGovernanceComponentDetection@0