Skip to content

Commit

Permalink
feat: support new command-line syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Dec 16, 2024
1 parent b40703f commit c943644
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ string(CONCAT RUBY_API_VER ${RUBY_VER_BASE} ".0")
# list(GET LIBDWARFS_WR_VER_COMPONENTS 2 LIBDWARFS_WR_VER_PATCH)
# set (LIBDWARFS_WR_VER_M ${LIBDWARFS_WR_VER_MAJOR}.${LIBDWARFS_WR_VER_MINOR}.${LIBDWARFS_WR_VER_PATCH})
#else(DWARFS_PRELOAD)
def_ext_prj_g(DWARFS_WR "v0.8.3")
def_ext_prj_g(DWARFS_WR "v0.9.1")
#endif(DWARFS_PRELOAD)

def_ext_prj_g(PATCHELF "65e14792061c298f1d2bc44becd48a10cbf0bc81")
Expand Down
2 changes: 1 addition & 1 deletion common.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BUILD_TYPE=Release
DEPS=deps
INCBIN_TAG=348e36b
DWARFS_WR_TAG=v0.8.3
DWARFS_WR_TAG=v0.9.1
RUBY_VER=3.2.5
47 changes: 21 additions & 26 deletions src/tebako-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,19 @@
#include <tebako/tebako-version.h>
#include <tebako/tebako-main.h>
#include <tebako/tebako-fs.h>
#include <tebako/tebako-cmdline-helpers.h>
#include <tebako/tebako-cmdline.h>

static int running_miniruby = 0;
static tebako::cmdline_args* args = nullptr;

static void tebako_clean(void)
{
unmount_root_memfs();
if (args) {
delete args;
args = nullptr;
}
}

extern "C" int tebako_main(int* argc, char*** argv)
{
Expand All @@ -71,25 +81,20 @@ extern "C" int tebako_main(int* argc, char*** argv)
}
else {
try {
args = new tebako::cmdline_args(*argc, (const char**) *argv);
args->parse_arguments();

fsret = mount_root_memfs(&gfsData[0], gfsSize, tebako::fs_log_level, nullptr, nullptr, nullptr, nullptr, nullptr);

if (fsret == 0) {
if ((*argc > 1) && strcmp((*argv)[1], "--tebako-extract") == 0) {
ret = tebako::build_arguments_for_extract(argc, argv, tebako::fs_mount_point);
}
else {
auto [mountpoints, parsed_argv] = tebako::parse_arguments(*argc, *argv);
// for (auto& mp : mountpoints) {
// printf("Mountpoint: %s\n", mp.c_str());
// }
tebako::process_mountpoints(mountpoints);
std::tie(*argc, *argv) = tebako::build_arguments(parsed_argv, tebako::fs_mount_point, tebako::fs_entry_point);
ret = 0;
}
args->process_mountpoints();
args->build_arguments(tebako::fs_mount_point, tebako::fs_entry_point);
*argc = args->get_argc();
*argv = args->get_argv();
ret = 0;
atexit(tebako_clean);
}
atexit(unmount_root_memfs);
}

catch (std::exception e) {
printf("Failed to process command line: %s\n", e.what());
}
Expand All @@ -110,17 +115,7 @@ extern "C" int tebako_main(int* argc, char*** argv)
if (ret != 0) {
try {
printf("Tebako initialization failed\n");
if (new_argv) {
delete new_argv;
new_argv = nullptr;
}
if (argv_memory) {
delete argv_memory;
argv_memory = nullptr;
}
if (fsret == 0) {
unmount_root_memfs();
}
tebako_clean();
}
catch (...) {
// Nested error, no recovery :(
Expand Down

0 comments on commit c943644

Please sign in to comment.