[olympic/studio] Fix Project::writeObj to ensure parent directory of file exists
All checks were successful
Build / build (push) Successful in 2m7s
All checks were successful
Build / build (push) Successful in 2m7s
This commit is contained in:
parent
67543af806
commit
ae066a914c
@ -36,6 +36,15 @@ constexpr ox::Result<ox::StringView> fileExt(ox::CRStringView path) noexcept {
|
|||||||
return substr(path, extStart + 1);
|
return substr(path, extStart + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]]
|
||||||
|
constexpr ox::StringView parentDir(ox::StringView path) noexcept {
|
||||||
|
if (path.len() && path[path.len() - 1] == '/') {
|
||||||
|
path = substr(path, 0, path.len() - 1);
|
||||||
|
}
|
||||||
|
auto const extStart = ox::find(path.crbegin(), path.crend(), '/').offset();
|
||||||
|
return substr(path, 0, extStart);
|
||||||
|
}
|
||||||
|
|
||||||
class Project {
|
class Project {
|
||||||
private:
|
private:
|
||||||
keel::Context &m_ctx;
|
keel::Context &m_ctx;
|
||||||
@ -108,6 +117,7 @@ template<typename T>
|
|||||||
ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat fmt) noexcept {
|
ox::Error Project::writeObj(ox::CRStringView path, T const&obj, ox::ClawFormat fmt) noexcept {
|
||||||
oxRequireM(buff, ox::writeClaw(obj, fmt));
|
oxRequireM(buff, ox::writeClaw(obj, fmt));
|
||||||
// write to FS
|
// write to FS
|
||||||
|
oxReturnError(mkdir(parentDir(path)));
|
||||||
oxReturnError(writeBuff(path, buff));
|
oxReturnError(writeBuff(path, buff));
|
||||||
// write type descriptor
|
// write type descriptor
|
||||||
if (m_typeStore.get<T>().error) {
|
if (m_typeStore.get<T>().error) {
|
||||||
|
@ -13,6 +13,11 @@
|
|||||||
|
|
||||||
namespace studio {
|
namespace studio {
|
||||||
|
|
||||||
|
static_assert(fileExt("main.c").value == "c");
|
||||||
|
static_assert(fileExt("a.b.c").value == "c");
|
||||||
|
static_assert(parentDir("/a/b/c") == "/a/b");
|
||||||
|
static_assert(parentDir("/a/b/c/") == "/a/b");
|
||||||
|
|
||||||
static void generateTypes(ox::TypeStore &ts) noexcept {
|
static void generateTypes(ox::TypeStore &ts) noexcept {
|
||||||
for (auto const mod : keel::modules()) {
|
for (auto const mod : keel::modules()) {
|
||||||
for (auto gen : mod->types()) {
|
for (auto gen : mod->types()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user