From 78eb8fca2896b0f6462ced15f618dd74910366be Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Tue, 28 May 2024 20:56:40 -0500 Subject: [PATCH] [keel] Cleanup pack logging --- src/olympic/keel/include/keel/pack.hpp | 10 ++++++---- src/olympic/keel/src/pack-applib.cpp | 19 +++++++++---------- src/olympic/keel/src/pack.cpp | 6 +++--- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/olympic/keel/include/keel/pack.hpp b/src/olympic/keel/include/keel/pack.hpp index ed21ee25..635fc8ae 100644 --- a/src/olympic/keel/include/keel/pack.hpp +++ b/src/olympic/keel/include/keel/pack.hpp @@ -86,19 +86,21 @@ ox::Error preloadObj( ox::TypeStore &ts, ox::FileSystem &romFs, ox::Preloader &pl, - ox::CRStringView path) noexcept { + ox::StringView const path) noexcept { // load file oxRequireM(buff, romFs.read(path)); oxRequireM(obj, keel::readAsset(ts, buff)); if (obj.type()->preloadable) { - oxOutf("preloading {} as a {}\n", path, obj.type()->typeName); // preload - oxRequire(a, pl.startAlloc(ox::sizeOf(&obj), ox::alignOf(obj))); + auto const size = ox::sizeOf(&obj); + auto const alignment = ox::alignOf(obj); + oxRequire(a, pl.startAlloc(size, alignment)); auto const err = ox::preload(&pl, &obj); oxReturnError(pl.endAlloc()); oxReturnError(err); - keel::PreloadPtr const p{.preloadAddr = static_cast(a)}; + keel::PreloadPtr const p{.preloadAddr = a}; oxReturnError(ox::writeMC(p).moveTo(buff)); + oxOutf("preloaded {} as a {} @ {} to {}\n", path, obj.type()->typeName, a, a + size); } else { // strip the Claw header (it is not needed after preloading) and write back out to dest fs oxReturnError(ox::writeMC(obj).moveTo(buff)); diff --git a/src/olympic/keel/src/pack-applib.cpp b/src/olympic/keel/src/pack-applib.cpp index 1ea389ae..e10e8fa1 100644 --- a/src/olympic/keel/src/pack-applib.cpp +++ b/src/olympic/keel/src/pack-applib.cpp @@ -11,7 +11,7 @@ #include -static ox::Error writeFileBuff(ox::StringView path, ox::Buffer const&buff) noexcept { +static ox::Error writeFileBuff(ox::StringView path, ox::BufferView const buff) noexcept { try { std::ofstream f(std::string(toStdStringView(path)), std::ios::binary); f.write(buff.data(), static_cast(buff.size())); @@ -32,17 +32,17 @@ static ox::Result readFileBuff(ox::StringView path) noexcept { ox::Buffer buff(size); file.seekg(0, std::ios::beg); file.read(buff.data(), static_cast(buff.size())); - return buff; + return std::move(buff); } catch (std::ios_base::failure const&e) { oxErrorf("Could not read OxFS file: {}", e.what()); return OxError(2, "Could not read OxFS file"); } } -static ox::Error generateTypes(ox::TypeStore *ts) noexcept { +static ox::Error generateTypes(ox::TypeStore &ts) noexcept { for (auto const mod : keel::modules()) { for (auto gen : mod->types()) { - oxReturnError(gen(*ts)); + oxReturnError(gen(ts)); } } return {}; @@ -54,7 +54,7 @@ static ox::Error pack(ox::StringView argSrc, ox::StringView argRomBin, ox::Strin ox::FileSystem32 dst(dstBuff); oxRequire(ctx, keel::init(ox::make_unique(argSrc), "keel-pack")); keel::TypeStore ts(*ctx->rom, ox::sfmt("{}/type_descriptors", projectDataDir)); - oxReturnError(generateTypes(&ts)); + oxReturnError(generateTypes(ts)); oxReturnError(keel::pack(*ctx, ts, dst)); oxRequireM(pl, keel::GbaPreloader::make()); oxReturnError(preload(ts, dst, *pl)); @@ -62,14 +62,13 @@ static ox::Error pack(ox::StringView argSrc, ox::StringView argRomBin, ox::Strin // resize buffer oxRequire(dstSize, dst.size()); dstBuff.resize(dstSize); - + // concatenate ROM segments oxRequireM(romBuff, readFileBuff(argRomBin)); - oxReturnError(appendBinary(romBuff, dstBuff, *pl)); - + oxOutf("Input exe size: {} bytes\n", romBuff.size()); oxOutf("Dest FS size: {} bytes\n", dstSize); oxOutf("Preload buff size: {} bytes\n", pl->buff().size()); - oxOutf("ROM buff size: {} bytes\n", romBuff.size()); - + oxReturnError(appendBinary(romBuff, dstBuff, *pl)); + oxOutf("Final ROM buff size: {} bytes\n", romBuff.size()); oxReturnError(writeFileBuff(argRomBin, romBuff)); return {}; } diff --git a/src/olympic/keel/src/pack.cpp b/src/olympic/keel/src/pack.cpp index e79a9242..09bda0e8 100644 --- a/src/olympic/keel/src/pack.cpp +++ b/src/olympic/keel/src/pack.cpp @@ -34,7 +34,7 @@ static ox::Error pathToInode( } oxRequire(s, dest.stat(path)); oxReturnError(o.at("type").unwrap()->set(static_cast(ox::FileAddressType::Inode))); - oxOutf("path to inode: {} => {}\n", path, s.inode); + oxOutf("\tpath to inode: {} => {}\n", path, s.inode); return data.set(2, s.inode); } @@ -97,6 +97,7 @@ static ox::Error doTransformations( oxReturnError(keel::performPackTransforms(ctx, buff)); // transform FileAddresses oxRequireM(obj, keel::readAsset(ts, buff)); + oxOutf("transforming {}\n", filePath); oxReturnError(transformFileAddressesObj(ctx, dest, obj)); oxReturnError(ox::writeClaw(obj).moveTo(buff)); // write file to dest @@ -143,16 +144,15 @@ static ox::Error copy( if (beginsWith(name, ".")) { continue; } - oxOutf("reading {}\n", currentFile); oxRequire(stat, src.stat(currentFile)); if (stat.fileType == ox::FileType::Directory) { oxReturnError(dest.mkdir(currentFile, true)); oxReturnError(copy(src, dest, currentFile + '/')); } else { // load file + oxOutf("copying file: {}\n", currentFile); oxRequireM(buff, src.read(currentFile)); // write file to dest - oxOutf("writing {}\n", currentFile); oxReturnError(dest.write(currentFile, buff)); } }