diff --git a/CMakeLists.txt b/CMakeLists.txt index 8ae35de5..39a3cac0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,6 +41,28 @@ endif() # Set up project project("ProjectAirSimLibs") +# Capture build commit hash once during configure. Fallback to "unknown" +# when git is unavailable (or source is not a git checkout). +set(PROJECTAIRSIM_BUILD_COMMIT_HASH "unknown") +find_package(Git QUIET) +if(GIT_FOUND) + execute_process( + COMMAND ${GIT_EXECUTABLE} rev-parse HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE PROJECTAIRSIM_BUILD_COMMIT_HASH + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + RESULT_VARIABLE PROJECTAIRSIM_GIT_RESULT + ) + + if(NOT PROJECTAIRSIM_GIT_RESULT EQUAL 0 OR PROJECTAIRSIM_BUILD_COMMIT_HASH STREQUAL "") + set(PROJECTAIRSIM_BUILD_COMMIT_HASH "unknown") + endif() +endif() +message("PROJECTAIRSIM_BUILD_COMMIT_HASH set to ${PROJECTAIRSIM_BUILD_COMMIT_HASH}") + +file(WRITE ${CMAKE_BINARY_DIR}/commit_hash.txt "${PROJECTAIRSIM_BUILD_COMMIT_HASH}\n") + # Set up paths for packaging the sim libs build outputs as custom post-command steps set(SIMLIBS_PACKAGE_DIR ${CMAKE_SOURCE_DIR}/packages/projectairsim_simlibs) set(SIMLIBS_SHARED_LIB_DIR ${SIMLIBS_PACKAGE_DIR}/shared_libs) diff --git a/client/python/projectairsim/src/projectairsim/client.py b/client/python/projectairsim/src/projectairsim/client.py index adc7cb2a..89f537ff 100644 --- a/client/python/projectairsim/src/projectairsim/client.py +++ b/client/python/projectairsim/src/projectairsim/client.py @@ -163,6 +163,15 @@ def set_interactive_feature(self, feature_name, enabled): else: utils.projectairsim_log().info("Successfully set interactive feature.") + def get_build_commit_hash(self) -> str: + """Gets the commit hash used to build the current sim libs.""" + hash_req: Dict = { + "method": "/Sim/GetBuildCommitHash", + "params": {}, + "version": 1.0, + } + return self.request(hash_req) + def unsubscribe(self, topics): """Unsubscribes from one or more server topics diff --git a/core_sim/src/CMakeLists.txt b/core_sim/src/CMakeLists.txt index eef8fd38..fb65914d 100644 --- a/core_sim/src/CMakeLists.txt +++ b/core_sim/src/CMakeLists.txt @@ -116,6 +116,7 @@ endif() # Set up nng and openssl for linking target_link_directories(${TARGET_NAME} PRIVATE ${NNG_LIB_DIR}) target_compile_definitions(${TARGET_NAME} PRIVATE NNG_STATIC_LIB=ON) +target_compile_definitions(${TARGET_NAME} PRIVATE PROJECTAIRSIM_BUILD_COMMIT_HASH="${PROJECTAIRSIM_BUILD_COMMIT_HASH}") target_include_directories(${TARGET_NAME} PRIVATE "${ONNXRUNTIME_ROOTDIR}/include") target_link_directories(${TARGET_NAME} PRIVATE "${ONNXRUNTIME_ROOTDIR}/lib") @@ -163,6 +164,7 @@ add_custom_command(TARGET ${TARGET_NAME} COMMAND ${CMAKE_COMMAND} -E echo "Packaging [${TARGET_NAME}] build outputs to ${UE_PLUGIN_SIMLIBS_DIR}/${TARGET_NAME}/$,Release,Debug>" COMMAND ${CMAKE_COMMAND} -E copy_directory $ ${UE_PLUGIN_SIMLIBS_DIR}/${TARGET_NAME}/$,Release,Debug> COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/../include ${UE_PLUGIN_SIMLIBS_DIR}/${TARGET_NAME}/include + COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_BINARY_DIR}/commit_hash.txt ${UE_PLUGIN_SIMLIBS_DIR}/commit_hash.txt COMMAND ${CMAKE_COMMAND} -E remove_directory ${UE_PLUGIN_SIMLIBS_DIR}/${TARGET_NAME}/$,Release,Debug>/CMakeFiles COMMAND ${CMAKE_COMMAND} -E remove -f ${UE_PLUGIN_SIMLIBS_DIR}/${TARGET_NAME}/$,Release,Debug>/cmake_install.cmake COMMAND ${CMAKE_COMMAND} -E remove -f ${UE_PLUGIN_SIMLIBS_DIR}/${TARGET_NAME}/$,Release,Debug>/CTestTestfile.cmake diff --git a/core_sim/src/simulator.cpp b/core_sim/src/simulator.cpp index 57764067..2d47ab4e 100644 --- a/core_sim/src/simulator.cpp +++ b/core_sim/src/simulator.cpp @@ -1,4 +1,4 @@ -// Copyright (C) Microsoft Corporation. +// Copyright (C) Microsoft Corporation. // Copyright (C) 2025 IAMAI CONSULTING CORP // MIT License. All rights reserved. @@ -86,6 +86,7 @@ class Simulator::Impl : public ComponentWithTopicsAndServiceMethods { friend class Simulator::Loader; bool SetInteractiveFeature(const std::string& feature_id, bool enable); + std::string GetBuildCommitHash(); Simulator::Loader loader_; Scene sim_scene_; @@ -219,14 +220,23 @@ void Simulator::Impl::RegisterServiceMethod(const ServiceMethod& method, service_manager_.RegisterMethod(unique_method, method_handler); } -bool Simulator::Impl::SetInteractiveFeature(const std::string& feature_id, bool enable) { - if(feature_id == "viewport_camera"){ +bool Simulator::Impl::SetInteractiveFeature(const std::string& feature_id, + bool enable) { + if (feature_id == "viewport_camera") { sim_scene_.EnableViewportCamera(enable); return true; } return false; } +std::string Simulator::Impl::GetBuildCommitHash() { +#ifdef PROJECTAIRSIM_BUILD_COMMIT_HASH + return PROJECTAIRSIM_BUILD_COMMIT_HASH; +#else + return "unknown"; +#endif +} + void Simulator::Impl::RegisterServiceMethods() { auto unsubscribe_topic = ServiceMethod("Unsubscribe", {"topic_paths"}); auto unsubscribe_topic_handler = unsubscribe_topic.CreateMethodHandler( @@ -238,13 +248,22 @@ void Simulator::Impl::RegisterServiceMethods() { [this](const ServiceMethod& method, MethodHandler method_handler) { RegisterServiceMethod(method, method_handler); }); - - // Register service method SetInteractiveFeature( feature_id(str), enable(bool)) - auto set_interactive_feature = ServiceMethod("SetInteractiveFeature", {"feature_id", "enable"}); - auto set_interactive_feature_handler = set_interactive_feature.CreateMethodHandler( - &Simulator::Impl::SetInteractiveFeature, *this); - RegisterServiceMethod(set_interactive_feature, set_interactive_feature_handler); + // Register service method SetInteractiveFeature( feature_id(str), + // enable(bool)) + auto set_interactive_feature = + ServiceMethod("SetInteractiveFeature", {"feature_id", "enable"}); + auto set_interactive_feature_handler = + set_interactive_feature.CreateMethodHandler( + &Simulator::Impl::SetInteractiveFeature, *this); + RegisterServiceMethod(set_interactive_feature, + set_interactive_feature_handler); + + auto get_build_commit_hash = ServiceMethod("GetBuildCommitHash", {}); + auto get_build_commit_hash_handler = + get_build_commit_hash.CreateMethodHandler( + &Simulator::Impl::GetBuildCommitHash, *this); + RegisterServiceMethod(get_build_commit_hash, get_build_commit_hash_handler); } // -----------------------------------------------------------------------------