This commit is contained in:
Fancy code 2024-05-17 20:50:59 +08:00
parent 9567a6cd66
commit 467e998479
6 changed files with 49 additions and 1 deletions

View File

@ -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})

View File

@ -0,0 +1,2 @@
add_definitions(-DHUNTING_CAMERA_VERSION="1.0.0.0")

View File

@ -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)

View File

@ -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)

View File

@ -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 <thread>
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
#include <regex>
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