aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordacctal <donotcontactmevia@email.invalid>2026-10-23 09:11:29 +0000
committerdacctal <donotcontactmevia@email.invalid>2026-10-23 09:11:29 +0000
commitc37341416b47bec24f32a49219b6f6259f641370 (patch)
treeb7da894a3e54714ca1a07744dcb5fabcddcb0b7a
parent5bea8b95e3857b250e98327140a580ef68a59d9c (diff)
bldit fundamentals are working
-rw-r--r--include/pkg.h1
-rw-r--r--src/cli.c2
-rw-r--r--src/hooks.c21
-rw-r--r--src/recipes.c52
4 files changed, 52 insertions, 24 deletions
diff --git a/include/pkg.h b/include/pkg.h
index 8aa5ac5..8828286 100644
--- a/include/pkg.h
+++ b/include/pkg.h
@@ -31,6 +31,7 @@ str pkg_get_url(package_t *pkg);
bool pkg_setup(package_t *pkg);
bool pkg_build(package_t *pkg);
+bool pkg_full_build(package_t *pkg);
bool pkg_install(package_t *pkg);
bool pkg_full_install(package_t *pkg);
bool pkg_remove(package_t *pkg);
diff --git a/src/cli.c b/src/cli.c
index fc3edfd..d5e86fd 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -53,7 +53,7 @@ void cmd_build(int argc, char **argv, int i) {
continue;
str arg = mstr(argv[j]);
package_t pkg = pkg_create(&arg);
- if (!pkg_build(&pkg)) log_error(
+ if (!pkg_full_build(&pkg)) log_error(
"failed to build '%.*s'", str_fmt(&pkg.name));
pkg_free(&pkg);
if (str_is_valid(&arg))
diff --git a/src/hooks.c b/src/hooks.c
index 6053575..81c3fc5 100644
--- a/src/hooks.c
+++ b/src/hooks.c
@@ -163,25 +163,30 @@ bool bldit_file_exists(package_t *pkg) {
bool bldit_hook_set(package_t *pkg) {
if (luaL_loadfile(L, pkg->bldit.data) || lua_pcall(L, 0, 1, 0)) {
- log_warn("bldit brokie");
+ log_warn(
+ "%.*s is broken: %s",
+ str_fmt(&pkg->bldit),
+ lua_tostring(L, -1)
+ );
lua_pop(L, 1);
return false;
}
+ if (!lua_istable(L, -1)) {
+ log_error("%.*s does not return a table", str_fmt(&pkg->bldit));
+ lua_pop(L, 1);
+ lua_close(L);
+ return false;
+ }
lua_setglobal(L, "__pkgit_bldit_config");
lua_pop(L, 1);
return true;
}
bool bldit_hook_recipe(package_t *pkg, const char *recipe) {
-// luaL_dofile(L, pkg->bldit.data);
-// lua_setglobal(L, "__pkgit_bldit_config");
lua_getglobal(L, "__pkgit_bldit_config");
- printf("\n%s\n\n", lua_tostring(L, -1));
- log_info("entered bldit config");
+ //printf("\n%s\n\n", lua_tostring(L, -1));
lua_get_field_type("recipe", table, &pkg->bldit, 2);
- log_info("entered bldit recipe");
- lua_get_field_type(recipe, table, &pkg->bldit, 3);
- log_info("entered bldit recipe function: %s", recipe);
+ lua_get_field_type(recipe, function, &pkg->bldit, 3);
lua_run_function(recipe, &pkg->bldit, 0, 1, 3);
if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) {
lua_pop(L, 3);
diff --git a/src/recipes.c b/src/recipes.c
index a4a08e8..ae3adda 100644
--- a/src/recipes.c
+++ b/src/recipes.c
@@ -41,7 +41,7 @@
char big[2] = "\0"; \
big[0] = smol; \
if (!pkg_write_status(big, pkg)) return false; \
- log_info("'%.*s' %s done", str_fmt(&(pkg)->name), operation); \
+ log_success("'%.*s' %s done", str_fmt(&(pkg)->name), operation); \
} while (0)
#define try_bldit_fn(fn, pkg, operation, smol) \
@@ -49,7 +49,7 @@
if (pkg_read_status(smol, pkg)) return true; \
if (!flags.quiet) log_info("'%.*s' %s in progress...", \
str_fmt(&(pkg)->name), operation); \
- if (!(fn((pkg),(operation)))) { \
+ if (!(fn((pkg),(operation)))) { \
log_error("%s failed", operation); \
return false; \
} \
@@ -59,6 +59,16 @@
log_info("'%.*s' %s done", str_fmt(&(pkg)->name), operation); \
} while (0)
+static bool pkg_status_exists(package_t *pkg) {
+ bool success = false;
+ str pkgit_status = str_format("%.*s/.pkgit_status",
+ str_fmt(&pkg->src));
+ if (file_exists(pkgit_status.data)) success = true;
+ else log_info("%.*s doesn't exist", str_fmt(&pkgit_status));
+ str_free(&pkgit_status);
+ return success;
+}
+
static bool pkg_write_status(const char *status, package_t *pkg) {
bool success = false;
str status_str = mstr(status);
@@ -71,13 +81,9 @@ static bool pkg_write_status(const char *status, package_t *pkg) {
static bool pkg_read_status(const char desired, package_t *pkg) {
bool success = false;
+ if (!pkg_status_exists(pkg)) return false;
str pkgit_status = str_format("%.*s/.pkgit_status",
str_fmt(&pkg->src));
- if (!file_exists(pkgit_status.data)) {
- log_info("%.*s doesn't exist", str_fmt(&pkgit_status));
- str_free(&pkgit_status);
- return false;
- }
str status = file_read(&pkgit_status);
success = (str_find_char(&status, desired) != 0);
str_free(&pkgit_status);
@@ -85,6 +91,16 @@ static bool pkg_read_status(const char desired, package_t *pkg) {
return success;
}
+static bool pkg_remove_status(package_t *pkg) {
+ bool success = false;
+ str pkgit_status = str_format("%.*s/.pkgit_status",
+ str_fmt(&pkg->src));
+ if (!pkg_status_exists(pkg)) return true;
+ success = rmrf(&pkgit_status);
+ str_free(&pkgit_status);
+ return success;
+}
+
static bool is_pkg_installed(package_t *pkg) {
if (pkg_read_status('i', pkg)) {
if (flags.force) log_warn(
@@ -121,13 +137,12 @@ bool pkg_setup(package_t *pkg) {
if (pkg_read_status('s', pkg)) return true;
if (!pkg_enter(pkg)) return false;
if (bldit_file_exists(pkg)) {
- log_info("using bldit.lua");
+ log_info("using %.*s", str_fmt(&pkg->bldit));
try_bldit_fn(bldit_hook_recipe, pkg, "setup", 's');
} else {
- log_info("using your config");
+ log_info("using %.*s", str_fmt(&config.init_path));
try_pkg_fn(pkg_hook_setup, pkg, "setup", 's');
}
- log_success("'%.*s' set up", str_fmt(&pkg->name));
return true;
}
@@ -141,15 +156,22 @@ bool pkg_build(package_t *pkg) {
log_info("using your config");
try_pkg_fn(pkg_hook_build, pkg, "build", 'b');
}
- log_success("'%.*s' built", str_fmt(&pkg->name));
+ return true;
+}
+
+bool pkg_full_build(package_t *pkg) {
+ if (flags.force) pkg_remove_status(pkg);
+ if (!pkg_enter(pkg)) return false;
+ if (!pkg_setup(pkg)) return false;
+ if (!pkg_build(pkg)) return false;
return true;
}
bool pkg_install(package_t *pkg) {
if (is_pkg_installed(pkg) && !flags.force) return true;
+ if (flags.force) pkg_remove_status(pkg);
if (!pkg_enter(pkg)) return false;
try_pkg_fn(pkg_hook_install, pkg, "install", 'i');
- log_success("'%.*s' installed", str_fmt(&pkg->name));
return true;
}
@@ -157,9 +179,9 @@ bool pkg_full_install(package_t *pkg) {
if (is_pkg_installed(pkg) && !flags.force) return true;
try_pkg_fn(pkg_fetch_sources, pkg, "fetch", 'f');
if (!pkg_enter(pkg)) return false;
- pkg_setup(pkg);
- pkg_build(pkg);
- pkg_install(pkg);
+ if (!pkg_setup(pkg)) return false;
+ if (!pkg_build(pkg)) return false;
+ if (!pkg_install(pkg)) return false;
return true;
}