aboutsummaryrefslogtreecommitdiff
path: root/src/recipes.c
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 /src/recipes.c
parent5bea8b95e3857b250e98327140a580ef68a59d9c (diff)
bldit fundamentals are working
Diffstat (limited to 'src/recipes.c')
-rw-r--r--src/recipes.c52
1 files changed, 37 insertions, 15 deletions
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;
}