diff --git a/middleware/HuntingUpgrade/CMakeLists.txt b/middleware/HuntingUpgrade/CMakeLists.txt index 8a80d50..f860217 100644 --- a/middleware/HuntingUpgrade/CMakeLists.txt +++ b/middleware/HuntingUpgrade/CMakeLists.txt @@ -1,6 +1,7 @@ include(${CMAKE_SOURCE_DIR_IPCSDK}/build/global_config.cmake) include(${HAL_SOURCE_PATH}/build/hal.cmake) +include(./build/hunting_upgrade.cmake) set(EXECUTABLE_OUTPUT_PATH ${EXEC_OUTPUT_PATH}) set(LIBRARY_OUTPUT_PATH ${LIBS_OUTPUT_PATH}) diff --git a/middleware/HuntingUpgrade/build/hunting_upgrade.cmake b/middleware/HuntingUpgrade/build/hunting_upgrade.cmake new file mode 100644 index 0000000..4be9712 --- /dev/null +++ b/middleware/HuntingUpgrade/build/hunting_upgrade.cmake @@ -0,0 +1,2 @@ + +add_definitions(-DHUNTING_CAMERA_VERSION="1.0.0.0") \ No newline at end of file diff --git a/middleware/HuntingUpgrade/src/HuntingUpgradeImpl.cpp b/middleware/HuntingUpgrade/src/HuntingUpgradeImpl.cpp index 495dbab..2ad2e0f 100644 --- a/middleware/HuntingUpgrade/src/HuntingUpgradeImpl.cpp +++ b/middleware/HuntingUpgrade/src/HuntingUpgradeImpl.cpp @@ -16,6 +16,7 @@ #include "ILog.h" StatusCode HuntingUpgradeImpl::CheckFileHeader(const UpgradeFileHeader &head) { + const char *version = HUNTING_CAMERA_VERSION; return CreateStatusCode(STATUS_CODE_OK); } StatusCode HuntingUpgradeImpl::CheckUpgradeFile(void) diff --git a/test/application/VersionReleaseTool/CMakeLists.txt b/test/application/VersionReleaseTool/CMakeLists.txt index 5014efe..c75b2c1 100644 --- a/test/application/VersionReleaseTool/CMakeLists.txt +++ b/test/application/VersionReleaseTool/CMakeLists.txt @@ -35,6 +35,8 @@ if(${TARGET_PLATFORM} MATCHES ${DEFINE_LINUX}) aux_source_directory(./src_mock SRC_FILES) endif() +add_definitions(-DHUNTING_UPGRADE_BUILD_FILE="../ipc-sdk/middleware/HuntingUpgrade/build/hunting_upgrade.cmake") + set(TARGET_NAME VersionReleaseTool) add_executable(${TARGET_NAME} ${SRC_FILES_MAIN} ${SRC_FILES}) target_link_libraries(${TARGET_NAME} UpgradeTool StatusCode Log gtest gmock pthread) diff --git a/test/application/VersionReleaseTool/src/VersionReleaseTool.cpp b/test/application/VersionReleaseTool/src/VersionReleaseTool.cpp index eb68e6f..9dd946e 100644 --- a/test/application/VersionReleaseTool/src/VersionReleaseTool.cpp +++ b/test/application/VersionReleaseTool/src/VersionReleaseTool.cpp @@ -13,21 +13,63 @@ * limitations under the License. */ #include "VersionReleaseTool.h" +#include "ArgvAnalysis.h" #include "GtestUsing.h" #include "ILog.h" #include "UpgradeTool.h" -#include "ArgvAnalysis.h" #include +#include +#include +#include +#include +#include namespace VersionReleaseTool { /** * @brief Construct a new TEST object * ../output_files/test/bin/VersionReleaseTool --v_source_file=./test.bin --v_output_file=./test_output.bin */ +static void GetVersion(std::string &versiond) +{ + + const std::string filename = HUNTING_UPGRADE_BUILD_FILE; + std::ifstream file(filename); + if (!file.is_open()) { + std::cerr << "无法打开文件: " << filename << std::endl; + return ; + } + + std::string line; + std::string version; + std::regex pattern(R"(add_definitions\(-DHUNTING_CAMERA_VERSION=\"([^"]+)\"\))"); + + while (std::getline(file, line)) { + std::smatch match; + if (std::regex_search(line, match, pattern)) { + // 如果找到匹配项,match[1]将包含捕获的版本号 + version = match[1].str(); + break; // 找到后退出循环 + } + } + + file.close(); + + if (version.empty()) { + std::cerr << "在文件中未找到指定的行或版本号!" << std::endl; + return ; + } + + std::cout << "提取的版本号: " << version << std::endl; + return ; + + +} TEST(VersionReleaseTool, Version) { std::string sourceFile = ArgvAnalysis::GetInstance()->GetSourceFile(); std::string outputFile = ArgvAnalysis::GetInstance()->GetOutputFile(); + std::string version; + GetVersion(version); UpgradeTool::GetInstance()->PackFile(sourceFile, outputFile, "1.0.0", "product", "project", "upgradeType"); } } // namespace VersionReleaseTool \ No newline at end of file diff --git a/tools/version_release/VersionReleaseTool b/tools/version_release/VersionReleaseTool index 3ce420b..853f654 100755 Binary files a/tools/version_release/VersionReleaseTool and b/tools/version_release/VersionReleaseTool differ