From 15cd43ebbf9f6e1f930ad2c80912e58d848cafd8 Mon Sep 17 00:00:00 2001 From: wanghongen Date: Sun, 22 Jun 2025 12:11:56 +0800 Subject: [PATCH 1/2] hdf_core Signed-off-by: wanghongen --- framework/tools/hc-gen/src/macro_gen.cpp | 1 - .../tools/hc-gen/src/startup_cfg_gen.cpp | 20 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/framework/tools/hc-gen/src/macro_gen.cpp b/framework/tools/hc-gen/src/macro_gen.cpp index 4ce4eeb4e..57d3f1a99 100644 --- a/framework/tools/hc-gen/src/macro_gen.cpp +++ b/framework/tools/hc-gen/src/macro_gen.cpp @@ -197,7 +197,6 @@ bool MacroGen::GenNodeForeach(int32_t depth, const std::shared_ptr &n } ofs_ << std::endl; } - return true; } diff --git a/framework/tools/hc-gen/src/startup_cfg_gen.cpp b/framework/tools/hc-gen/src/startup_cfg_gen.cpp index bcb5d2f18..7a3db1b9e 100644 --- a/framework/tools/hc-gen/src/startup_cfg_gen.cpp +++ b/framework/tools/hc-gen/src/startup_cfg_gen.cpp @@ -9,6 +9,9 @@ #include "startup_cfg_gen.h" #include #include +#include +#include +#include #include "ast.h" #include "file.h" @@ -87,7 +90,22 @@ bool StartupCfgGen::Initialize() outFileName = Util::File::StripSuffix(outFileName).append(".cfg"); outFileName_ = Util::File::FileNameBase(outFileName); - ofs_.open(outFileName, std::ofstream::out | std::ofstream::binary); + std::filesystem::path + p(outFileName); + try { + p = std::filesystem::canonical(p); + } catch (const std::filesystem::filesystem_error& e) { + Logger().Error() << "failed to canonicalize path: " << e.what(); + return false; + } + if (!std::filesystem::exists(p.parent_path())) { + if(!std::filesystem::create_directories(p.parent_path())){ + Logger().Error() << "failed to canonicalize create parent directory for: " << p.string(); + return false; + } + } + + ofs_.open(p.string(), std::ofstream::out | std::ofstream::binary); if (!ofs_.is_open()) { Logger().Error() << "failed to open output file: " << outFileName; return false; -- Gitee From 7fa55a1c7973abf210fc97b343a1a6478fcc1bdb Mon Sep 17 00:00:00 2001 From: wanghongenaf Date: Sun, 22 Jun 2025 06:06:33 +0000 Subject: [PATCH 2/2] update framework/tools/hc-gen/src/startup_cfg_gen.cpp. Signed-off-by: wanghongenaf --- .../tools/hc-gen/src/startup_cfg_gen.cpp | 26 +++++++++---------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/framework/tools/hc-gen/src/startup_cfg_gen.cpp b/framework/tools/hc-gen/src/startup_cfg_gen.cpp index 7a3db1b9e..ab959c0f0 100644 --- a/framework/tools/hc-gen/src/startup_cfg_gen.cpp +++ b/framework/tools/hc-gen/src/startup_cfg_gen.cpp @@ -89,25 +89,23 @@ bool StartupCfgGen::Initialize() } outFileName = Util::File::StripSuffix(outFileName).append(".cfg"); outFileName_ = Util::File::FileNameBase(outFileName); - - std::filesystem::path - p(outFileName); - try { - p = std::filesystem::canonical(p); - } catch (const std::filesystem::filesystem_error& e) { - Logger().Error() << "failed to canonicalize path: " << e.what(); + std::filesystem::path p(outFileName); + try { + p = std::filesystem::canonical(p); + } catch (const std::filesystem::filesystem_error& e) { + Logger().Error() << "Failed to canonicalize path: " << e.what(); + return false; + } + if (!std::filesystem::exists(p.parent_path())) { + if (!std::filesystem::create_directories(p.parent_path())) { + Logger().Error() << "Failed to create parent directory for: " << p.string(); return false; } - if (!std::filesystem::exists(p.parent_path())) { - if(!std::filesystem::create_directories(p.parent_path())){ - Logger().Error() << "failed to canonicalize create parent directory for: " << p.string(); - return false; - } - } + } ofs_.open(p.string(), std::ofstream::out | std::ofstream::binary); if (!ofs_.is_open()) { - Logger().Error() << "failed to open output file: " << outFileName; + Logger().Error() << "failed to open output file: " << p.string(); return false; } -- Gitee