aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordacctal <donotcontactmevia@email.invalid>2026-10-22 15:00:26 +0000
committerdacctal <donotcontactmevia@email.invalid>2026-10-22 15:00:26 +0000
commit5bea8b95e3857b250e98327140a580ef68a59d9c (patch)
tree710026fb87bfd94d87cb16fa650b06e85ac401d6
parent865342c3fabb50672e2188ccd4d7c3eb7bfb045a (diff)
added some bldit stuff, it's still broken though
-rw-r--r--bldit.lua6
-rw-r--r--config/init.lua4
-rw-r--r--include/bldit.h27
-rw-r--r--include/pkg.h9
-rw-r--r--src/cli.c2
-rw-r--r--src/hooks.c107
-rw-r--r--src/lua_state.c19
-rw-r--r--src/pkg.c3
-rw-r--r--src/recipes.c44
9 files changed, 168 insertions, 53 deletions
diff --git a/bldit.lua b/bldit.lua
index e266b7d..cb7914f 100644
--- a/bldit.lua
+++ b/bldit.lua
@@ -19,10 +19,9 @@
]]
local bldit = {}
-bldit.version = "1.2.0"
+bldit.version = "2.0.0"
bldit.package_version = bldit.version
-
-- fetchers, entirely made by the developer --
local fetchers = {}
fetchers.git = {
@@ -39,7 +38,7 @@ fetchers.git = {
}
-- fetchers, entirely made by the developer --
-
+-- dependencies, completely optional --
bldit.dependencies = {
luajit = {
url = "https://luajit.org/git/luajit.git",
@@ -48,6 +47,7 @@ bldit.dependencies = {
recipe = recpies.make
}
}
+-- dependencies, completely optional --
bldit.recipe = {
build = function()
diff --git a/config/init.lua b/config/init.lua
index dfaa68d..4ce15ee 100644
--- a/config/init.lua
+++ b/config/init.lua
@@ -20,7 +20,9 @@ cfg.fetchers.git = {
-- returns a string
get_version = function(url) return io.popen(
- "git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags "..url.." '*.*.*' | tail --lines=1 | cut --delimiter='/' --fields=3"
+ "git -c 'versionsort.suffix=-' ls-remote --exit-code --refs "
+ .."--sort='version:refname' --tags "..url
+ .." '*.*.*' | tail --lines=1 | cut --delimiter='/' --fields=3"
):read("*a") end,
}
-- the default fetch method (used when you don't provide one in pkgs)
diff --git a/include/bldit.h b/include/bldit.h
new file mode 100644
index 0000000..4dc0745
--- /dev/null
+++ b/include/bldit.h
@@ -0,0 +1,27 @@
+/*
+
+ pkgit - package it!
+
+ Copyright (C) 2026 dacctal
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+*/
+
+#ifndef PKGIT_CLI_H
+#define PKGIT_CLI_H
+
+#include "str.h"
+str bldit_file = {0};
+
+#endif
diff --git a/include/pkg.h b/include/pkg.h
index 6b13e71..8aa5ac5 100644
--- a/include/pkg.h
+++ b/include/pkg.h
@@ -4,7 +4,7 @@
#include "str.h"
typedef struct package_t {
- str name, version, url, src, root;
+ str name, version, url, src, root, bldit;
unsigned int dep_count;
bool is_local;
} package_t;
@@ -19,6 +19,12 @@ bool pkg_hook_remove(package_t *pkg);
bool pkg_hook_on_update(package_t *pkg);
bool pkg_hook_fetch_sources(package_t *pkg);
bool pkg_hook_fetch_latest_version(package_t *pkg);
+
+void bldit_file_set(package_t *pkg);
+bool bldit_file_exists(package_t *pkg);
+bool bldit_hook_set(package_t *pkg);
+bool bldit_hook_recipe(package_t *pkg, const char *recipe);
+
str pkg_get_latest_version(package_t *pkg);
bool pkg_hook_url(package_t *pkg);
str pkg_get_url(package_t *pkg);
@@ -26,6 +32,7 @@ str pkg_get_url(package_t *pkg);
bool pkg_setup(package_t *pkg);
bool pkg_build(package_t *pkg);
bool pkg_install(package_t *pkg);
+bool pkg_full_install(package_t *pkg);
bool pkg_remove(package_t *pkg);
bool pkg_update(package_t *pkg);
diff --git a/src/cli.c b/src/cli.c
index 3017a80..fc3edfd 100644
--- a/src/cli.c
+++ b/src/cli.c
@@ -73,7 +73,7 @@ void cmd_install(int argc, char **argv, int i) {
continue;
str arg = mstr(argv[j]);
package_t pkg = pkg_create(&arg);
- if (!pkg_install(&pkg)) log_error(
+ if (!pkg_full_install(&pkg)) log_error(
"failed to install '%.*s'", str_fmt(&pkg.name));
pkg_free(&pkg);
if (str_is_valid(&arg))
diff --git a/src/hooks.c b/src/hooks.c
index 20923b7..6053575 100644
--- a/src/hooks.c
+++ b/src/hooks.c
@@ -21,7 +21,8 @@
#include <stdio.h>
#include <string.h>
-#include "common.h"
+#include "bldit.h"
+#include "files.h"
#include "log.h"
#include "lua_state.h"
#include "pkg.h"
@@ -29,16 +30,18 @@
#include "state.h"
bool pkg_exists(str *name) {
- lua_get_field_type("pkgs", table, &config.init_path, 1);
- lua_get_field_type(name->data, table, &config.init_path, 2);
- lua_pop(L, 2);
+ lua_getglobal(L, "__pkgit_user_config");
+ lua_get_field_type("pkgs", table, &config.init_path, 2);
+ lua_get_field_type(name->data, table, &config.init_path, 3);
+ lua_pop(L, 3);
return true;
}
bool pkg_hook_url(package_t *pkg) {
- lua_get_field_type("pkgs", table, &config.init_path, 1);
- lua_get_field_type(pkg->name.data, table, &config.init_path, 2);
- lua_get_field_type("url", string, &config.init_path, 3);
+ lua_getglobal(L, "__pkgit_user_config");
+ lua_get_field_type("pkgs", table, &config.init_path, 2);
+ lua_get_field_type(pkg->name.data, table, &config.init_path, 3);
+ lua_get_field_type("url", string, &config.init_path, 4);
if (!lua_isstring(L, -1)) return false;
return true;
}
@@ -56,33 +59,36 @@ str pkg_get_url(package_t *pkg) {
}
bool pkg_hook_fetch_sources(package_t *pkg) {
- lua_get_field_type("pkgs", table, &config.init_path, 1);
- lua_get_field_type(pkg->name.data, table, &config.init_path, 2);
- lua_get_field_type("fetcher", table, &config.init_path, 3);
- lua_get_field_type("get_source", function, &config.init_path, 4);
+ lua_getglobal(L, "__pkgit_user_config");
+ lua_get_field_type("pkgs", table, &config.init_path, 2);
+ lua_get_field_type(pkg->name.data, table, &config.init_path, 3);
+ lua_get_field_type("fetcher", table, &config.init_path, 4);
+ lua_get_field_type("get_source", function, &config.init_path, 5);
lua_pushstring(L, pkg->url.data);
lua_pushstring(L, pkg->version.data);
lua_pushstring(L, pkg->name.data);
- lua_run_function("get_source", &config.init_path, 3, 1, 4);
+ lua_run_function("get_source", &config.init_path, 3, 1, 5);
if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) {
- lua_pop(L, 4);
+ lua_pop(L, 5);
return false;
}
- lua_pop(L, 4);
+ lua_pop(L, 5);
return true;
}
bool pkg_hook_fetch_latest_version(package_t *pkg) {
- lua_get_field_type("pkgs", table, &config.init_path, 1);
- lua_get_field_type(pkg->name.data, table, &config.init_path, 2);
- lua_get_field_type("fetcher", table, &config.init_path, 3);
- lua_get_field_type("get_version", function, &config.init_path, 4);
+ lua_getglobal(L, "__pkgit_user_config");
+ lua_get_field_type("pkgs", table, &config.init_path, 2);
+ lua_get_field_type(pkg->name.data, table, &config.init_path, 3);
+ lua_get_field_type("fetcher", table, &config.init_path, 4);
+ lua_get_field_type("get_version", function, &config.init_path, 5);
lua_pushstring(L, pkg->url.data);
- lua_run_function("get_version", &config.init_path, 1, 1, 4);
+ lua_run_function("get_version", &config.init_path, 1, 1, 5);
if (!lua_isstring(L, -1)) {
- lua_pop(L, 4);
+ lua_pop(L, 5);
return false;
}
+ lua_pop(L, 5);
return true;
}
@@ -95,21 +101,22 @@ str pkg_get_latest_version(package_t *pkg) {
str_copy_into(&version, &tmp_version);
str_free(&tmp_version);
}
- lua_pop(L, 4);
+ lua_pop(L, 5);
return version;
}
bool pkg_hook_recipe(char *recipe, package_t *pkg) {
- lua_get_field_type("pkgs", table, &config.init_path, 1);
- lua_get_field_type(pkg->name.data, table, &config.init_path, 2);
- lua_get_field_type("recipe", table, &config.init_path, 3);
- lua_get_field_type(recipe, function, &config.init_path, 4);
- lua_run_function(recipe, &config.init_path, 0, 1, 4);
+ lua_getglobal(L, "__pkgit_user_config");
+ lua_get_field_type("pkgs", table, &config.init_path, 2);
+ lua_get_field_type(pkg->name.data, table, &config.init_path, 3);
+ lua_get_field_type("recipe", table, &config.init_path, 4);
+ lua_get_field_type(recipe, function, &config.init_path, 5);
+ lua_run_function(recipe, &config.init_path, 0, 1, 5);
if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) {
- lua_pop(L, 4);
+ lua_pop(L, 5);
return false;
}
- lua_pop(L, 4);
+ lua_pop(L, 5);
return true;
}
@@ -134,12 +141,52 @@ bool pkg_hook_on_update(package_t *pkg) {
}
bool config_hook_on_update(void) {
- lua_get_field_type("on_update", function, &config.init_path, 1);
- lua_run_function("on_update", &config.init_path, 0, 1, 1);
+ lua_getglobal(L, "__pkgit_user_config");
+ lua_get_field_type("on_update", function, &config.init_path, 2);
+ lua_run_function("on_update", &config.init_path, 0, 1, 2);
if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) {
+ lua_pop(L, 2);
+ return false;
+ }
+ lua_pop(L, 2);
+ return true;
+}
+
+void bldit_file_set(package_t *pkg) {
+ pkg->bldit = str_format("%.*s/bldit.lua", str_fmt(&pkg->src));
+}
+
+bool bldit_file_exists(package_t *pkg) {
+ if (file_exists(pkg->bldit.data)) return true;
+ return false;
+}
+
+bool bldit_hook_set(package_t *pkg) {
+ if (luaL_loadfile(L, pkg->bldit.data) || lua_pcall(L, 0, 1, 0)) {
+ log_warn("bldit brokie");
lua_pop(L, 1);
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");
+ 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_run_function(recipe, &pkg->bldit, 0, 1, 3);
+ if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) {
+ lua_pop(L, 3);
+ return false;
+ }
+ lua_pop(L, 3);
+ return true;
+}
diff --git a/src/lua_state.c b/src/lua_state.c
index 297a218..cf46760 100644
--- a/src/lua_state.c
+++ b/src/lua_state.c
@@ -62,6 +62,8 @@ bool init_lua_state(void) {
}
str_free(&lua_path);
+ lua_setglobal(L, "__pkgit_user_config");
+ lua_pop(L, 1);
L_is_loaded = true;
return true;
}
@@ -94,10 +96,8 @@ static void setup_base_dirs(void) {
}
static bool load_init_lua(void) {
- lua_setglobal(L, "__PkgitUserConfig");
- lua_getglobal(L, "__PkgitUserConfig");
-
- lua_get_field_type("dirs", table, &config.init_path, 1);
+ lua_getglobal(L, "__pkgit_user_config");
+ lua_get_field_type("dirs", table, &config.init_path, 2);
#define X(field) \
do { \
@@ -114,20 +114,15 @@ static bool load_init_lua(void) {
#undef X
- lua_pop(L, 1);
+ lua_pop(L, 2);
return true;
}
bool init_lua_config(void) {
setup_base_dirs();
-
- if (!init_lua_state())
- return false;
-
- if (!load_init_lua())
- return false;
-
+ if (!init_lua_state()) return false;
+ if (!load_init_lua()) return false;
return true;
}
diff --git a/src/pkg.c b/src/pkg.c
index 852f555..04cc95c 100644
--- a/src/pkg.c
+++ b/src/pkg.c
@@ -102,6 +102,8 @@ package_t pkg_create(str *arg) {
str_free(&cwd);
str_free(&destdir);
+ bldit_file_set(&pkg);
+ bldit_hook_set(&pkg);
return pkg;
}
@@ -111,4 +113,5 @@ void pkg_free(package_t *pkg) {
str_free(&pkg->url);
str_free(&pkg->src);
str_free(&pkg->root);
+ str_free(&pkg->bldit);
}
diff --git a/src/recipes.c b/src/recipes.c
index 246224e..a4a08e8 100644
--- a/src/recipes.c
+++ b/src/recipes.c
@@ -44,6 +44,21 @@
log_info("'%.*s' %s done", str_fmt(&(pkg)->name), operation); \
} while (0)
+#define try_bldit_fn(fn, pkg, operation, smol) \
+ do { \
+ 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)))) { \
+ log_error("%s failed", operation); \
+ return false; \
+ } \
+ 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); \
+ } while (0)
+
static bool pkg_write_status(const char *status, package_t *pkg) {
bool success = false;
str status_str = mstr(status);
@@ -105,7 +120,13 @@ static bool pkg_enter(package_t *pkg) {
bool pkg_setup(package_t *pkg) {
if (pkg_read_status('s', pkg)) return true;
if (!pkg_enter(pkg)) return false;
- try_pkg_fn(pkg_hook_setup, pkg, "setup", 's');
+ if (bldit_file_exists(pkg)) {
+ log_info("using bldit.lua");
+ try_bldit_fn(bldit_hook_recipe, pkg, "setup", 's');
+ } else {
+ log_info("using your config");
+ try_pkg_fn(pkg_hook_setup, pkg, "setup", 's');
+ }
log_success("'%.*s' set up", str_fmt(&pkg->name));
return true;
}
@@ -113,22 +134,35 @@ bool pkg_setup(package_t *pkg) {
bool pkg_build(package_t *pkg) {
if (pkg_read_status('b', pkg)) return true;
if (!pkg_enter(pkg)) return false;
- try_pkg_fn(pkg_hook_build, pkg, "build", 'b');
+ if (bldit_file_exists(pkg)) {
+ log_info("using bldit.lua");
+ try_bldit_fn(bldit_hook_recipe, pkg, "build", 'b');
+ } else {
+ 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_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;
- try_pkg_fn(pkg_hook_setup, pkg, "setup", 's');
- try_pkg_fn(pkg_hook_build, pkg, "build", 'b');
try_pkg_fn(pkg_hook_install, pkg, "install", 'i');
log_success("'%.*s' installed", str_fmt(&pkg->name));
return true;
}
+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);
+ return true;
+}
+
bool pkg_remove(package_t *pkg) {
if (!pkg_enter(pkg)) return false;
if (!pkg_hook_remove(pkg)) return false;