From 71b2cbcf9d1eb730fec8aa64436d7ea59d7cec08 Mon Sep 17 00:00:00 2001 From: dacctal Date: Sat, 18 Jul 2026 07:16:31 +0000 Subject: fix lua vm bugs, remove git repo when one already exists --- src/build.c | 65 +++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 21 deletions(-) (limited to 'src/build.c') diff --git a/src/build.c b/src/build.c index 769106a..72b1e40 100644 --- a/src/build.c +++ b/src/build.c @@ -24,17 +24,20 @@ #include "globs.h" #include "log.h" +#include "lua.h" #include "pkg.h" #include "pkgit_lua.h" -bool target_build(lua_State *L, char* lua_file, str *target) { - if (!lua_try_table(L, lua_file, target->data)) return false; +bool target_build(lua_State *L, char *lua_file, str *target) { + if (!lua_try_table(L, lua_file, target->data)) + return false; if (lua_try_table(L, lua_file, "dependencies")) { lua_pushnil(L); install_dependencies(L); } lua_pop(L, 1); - if (!lua_try_function(L, lua_file, "build")) return false; + if (!lua_try_function(L, lua_file, "build")) + return false; lua_pop(L, 1); return true; } @@ -61,15 +64,16 @@ bool repo_build(package_t *pkg) { bool bldit(package_t *pkg) { init_bldit_state(); - if (!bldit_loaded) return false; + if (!bldit_loaded) + return false; lua_getglobal(B, "dependencies"); if (!lua_istable(B, -1)) { bldit_isnt_type("dependencies", "table"); } else { lua_pushnil(B); install_dependencies(B); + lua_pop(B, 1); } - lua_pop(B, 1); lua_getglobal(B, "targets"); if (!lua_istable(B, -1)) { bldit_isnt_type("targets", "table"); @@ -78,8 +82,9 @@ bool bldit(package_t *pkg) { return false; } bool target_success = target_build(B, "bldit.lua", &pkg->target); - lua_pop(B, 2); - lua_close(B); + lua_pop(B, 1); + // lua_pop(B, 2); + // lua_close(B); return target_success; } @@ -108,9 +113,11 @@ bool config_build(package_t *pkg) { } str_free(&file_path); str_free(&key); - if (!lua_try_table(L, "init.lua", "targets")) continue; + if (!lua_try_table(L, "init.lua", "targets")) + continue; target_success = target_build(L, "init.lua", &pkg->target); - if (target_success) break; + if (target_success) + break; lua_pop(L, 1); } lua_pop(L, 1); @@ -118,26 +125,42 @@ bool config_build(package_t *pkg) { } bool build_loop(package_t *pkg) { - if (flags.verbose) log_info("attempting init.lua: 'repositories.%.*s.build'", str_fmt(&pkg->name)); - if (repo_build(pkg)) { return true; } - if (flags.verbose) log_warn("failed init.lua: 'repositories.%.*s.build'", str_fmt(&pkg->name)); - - if (flags.verbose) log_info("attempting bldit.lua"); - if (bldit(pkg)) { return true; } - if (flags.verbose) log_warn("failed bldit.lua"); + if (flags.verbose) + log_info("attempting init.lua: 'repositories.%.*s.build'", + str_fmt(&pkg->name)); + if (repo_build(pkg)) { + return true; + } + if (flags.verbose) + log_warn("failed init.lua: 'repositories.%.*s.build'", + str_fmt(&pkg->name)); + + if (flags.verbose) + log_info("attempting bldit.lua"); + if (bldit(pkg)) { + return true; + } + if (flags.verbose) + log_warn("failed bldit.lua"); - if (flags.verbose) log_info("attempting init.lua: 'build_systems'"); - if (config_build(pkg)) { return true; } - if (flags.verbose) log_warn("failed init.lua: 'build_systems'"); + if (flags.verbose) + log_info("attempting init.lua: 'build_systems'"); + if (config_build(pkg)) { + return true; + } + if (flags.verbose) + log_warn("failed init.lua: 'build_systems'"); return false; } bool build(package_t *pkg) { char cwd[MAX_PATH_LEN]; getcwd(cwd, MAX_PATH_LEN); - if (!str_equal_cstr(&pkg->src, cwd) && !pkg->is_local) chdir(pkg->src.data); + if (!str_equal_cstr(&pkg->src, cwd) && !pkg->is_local) + chdir(pkg->src.data); - if (build_loop(pkg)) return true; + if (build_loop(pkg)) + return true; log_error("no usable build system was found for %.*s", str_fmt(&pkg->name)); return false; } -- cgit v1.2.3