[keel] Cleanup pack logging

This commit is contained in:
Gary Talent 2024-05-28 20:56:40 -05:00
parent 0b8051b6cc
commit 78eb8fca28
3 changed files with 18 additions and 17 deletions

View File

@ -86,19 +86,21 @@ ox::Error preloadObj(
ox::TypeStore &ts,
ox::FileSystem &romFs,
ox::Preloader<PlatSpec> &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<GbaPlatSpec>(&obj), ox::alignOf<GbaPlatSpec>(obj)));
auto const size = ox::sizeOf<GbaPlatSpec>(&obj);
auto const alignment = ox::alignOf<GbaPlatSpec>(obj);
oxRequire(a, pl.startAlloc(size, alignment));
auto const err = ox::preload<GbaPlatSpec, ox::ModelObject>(&pl, &obj);
oxReturnError(pl.endAlloc());
oxReturnError(err);
keel::PreloadPtr const p{.preloadAddr = static_cast<uint32_t>(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));

View File

@ -11,7 +11,7 @@
#include <keel/keel.hpp>
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<intptr_t>(buff.size()));
@ -32,17 +32,17 @@ static ox::Result<ox::Buffer> readFileBuff(ox::StringView path) noexcept {
ox::Buffer buff(size);
file.seekg(0, std::ios::beg);
file.read(buff.data(), static_cast<std::streamsize>(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<ox::PassThroughFS>(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 {};
}

View File

@ -34,7 +34,7 @@ static ox::Error pathToInode(
}
oxRequire(s, dest.stat(path));
oxReturnError(o.at("type").unwrap()->set(static_cast<int8_t>(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));
}
}