From c327376f6c2aac8cc5d4d070dff3adb7f5018741 Mon Sep 17 00:00:00 2001 From: lwz9103 Date: Fri, 14 Jun 2024 16:42:31 +0800 Subject: [PATCH] [GLUTEN-6094][CH] Add gluten commit info in local engine --- cpp-ch/local-engine/CMakeLists.txt | 25 ++++++++++++++++++++++ cpp-ch/local-engine/gluten_version.h.in | 27 ++++++++++++++++++++++++ cpp-ch/local-engine/local_engine_jni.cpp | 7 +++++- 3 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 cpp-ch/local-engine/gluten_version.h.in diff --git a/cpp-ch/local-engine/CMakeLists.txt b/cpp-ch/local-engine/CMakeLists.txt index 93ee4b8218af..50971a7ec27c 100644 --- a/cpp-ch/local-engine/CMakeLists.txt +++ b/cpp-ch/local-engine/CMakeLists.txt @@ -19,6 +19,31 @@ else() add_definitions(-DENABLE_MULTITARGET_CODE=0) endif() +get_filename_component(CURRENT_DIR ${CMAKE_CURRENT_SOURCE_DIR} ABSOLUTE) +if(IS_SYMLINK "${CURRENT_DIR}") + get_filename_component(REAL_DIR "${CURRENT_DIR}" REALPATH) + get_filename_component(PARENT_DIR "${REAL_DIR}" DIRECTORY) +else() + get_filename_component(PARENT_DIR "${CURRENT_DIR}" DIRECTORY) +endif() +execute_process( + COMMAND git log -n 1 --pretty=format:%h,%an,%ad -- "${PARENT_DIR}" + WORKING_DIRECTORY ${PARENT_DIR} + OUTPUT_VARIABLE LAST_CHANGE + OUTPUT_STRIP_TRAILING_WHITESPACE) +string(REPLACE "," ";" CHANGE_PARTS ${LAST_CHANGE}) +list(GET CHANGE_PARTS 0 COMMIT_HASH) +list(GET CHANGE_PARTS 1 COMMIT_AUTHOR) +list(GET CHANGE_PARTS 2 COMMIT_DATE) + +message("Last change in gluten/cpp-ch directory:") +message("Commit: ${COMMIT_HASH}") +message("Author: ${COMMIT_AUTHOR}") +message("Date: ${COMMIT_DATE}") + +configure_file(${CMAKE_CURRENT_SOURCE_DIR}/gluten_version.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/gluten_version.h) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -w -ffunction-sections -fdata-sections") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -w -ffunction-sections -fdata-sections") set(CMAKE_SHARED_LINKER_FLAGS diff --git a/cpp-ch/local-engine/gluten_version.h.in b/cpp-ch/local-engine/gluten_version.h.in new file mode 100644 index 000000000000..9c7f77d48c73 --- /dev/null +++ b/cpp-ch/local-engine/gluten_version.h.in @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef VERSION_H +#define VERSION_H + +namespace local_engine { + constexpr const char* COMMIT_HASH = "@COMMIT_HASH@"; + constexpr const char* COMMIT_AUTHOR = "@COMMIT_AUTHOR@"; + constexpr const char* COMMIT_DATE = "@COMMIT_DATE@"; +} + +#endif // VERSION_H \ No newline at end of file diff --git a/cpp-ch/local-engine/local_engine_jni.cpp b/cpp-ch/local-engine/local_engine_jni.cpp index 38f188293726..dd8c9486ff0d 100644 --- a/cpp-ch/local-engine/local_engine_jni.cpp +++ b/cpp-ch/local-engine/local_engine_jni.cpp @@ -17,7 +17,7 @@ #include #include #include - +#include #include #include #include @@ -130,6 +130,11 @@ JNIEXPORT jint JNI_OnLoad(JavaVM * vm, void * /*reserved*/) if (vm->GetEnv(reinterpret_cast(&env), JNI_VERSION_1_8) != JNI_OK) return JNI_ERR; + LOG_INFO(&Poco::Logger::get("jni"), "gluten version info:"); + LOG_INFO(&Poco::Logger::get("jni"), "gluten commit hash: {}", local_engine::COMMIT_HASH); + LOG_INFO(&Poco::Logger::get("jni"), "gluten commit author: {}", local_engine::COMMIT_AUTHOR); + LOG_INFO(&Poco::Logger::get("jni"), "gluten commit date: {}", local_engine::COMMIT_DATE); + local_engine::JniErrorsGlobalState::instance().initialize(env); spark_row_info_class = local_engine::CreateGlobalClassReference(env, "Lorg/apache/gluten/row/SparkRowInfo;");