diff --git a/framework/tools/hc-gen/src/macro_gen.cpp b/framework/tools/hc-gen/src/macro_gen.cpp index 4ce4eeb4e94fa90c84f54be4da09d8d0ff5dabf0..57d3f1a993308f547b9b97796142c9c4c6bc7925 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 bcb5d2f18e7893ba9981b06ca9c842ac304f2bd7..ab959c0f034f6b9d84ae72a6dd283f2f4e169930 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" @@ -86,10 +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(); + 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; + } + } - ofs_.open(outFileName, std::ofstream::out | std::ofstream::binary); + 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; }