aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/build.c10
-rw-r--r--src/lua_globs.c10
-rw-r--r--src/lua_install.c28
3 files changed, 32 insertions, 16 deletions
diff --git a/src/build.c b/src/build.c
index 1aafb36..0b97af7 100644
--- a/src/build.c
+++ b/src/build.c
@@ -19,8 +19,6 @@
*/
#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
#include <unistd.h>
#include "build.h"
@@ -53,10 +51,8 @@ bool repo_build(package_t *pkg) {
install_dependencies(L);
}
lua_pop(L, 1);
- printf("test\n");
if (!lua_try_table(L, "init.lua", "targets")) {
lua_pop(L, 3);
- printf("testtable\n");
return false;
}
bool target_success = target_build(L, "init.lua", &pkg->target);
@@ -99,13 +95,16 @@ bool config_build(package_t *pkg) {
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
str key = mstr(lua_tostring(L, -2));
- if (!lua_try_table(L, "init.lua", key.data)) {
+ if (!lua_istable(L, -1)) {
lua_pop(L, 1);
+ str_free(&key);
continue;
}
str file_path = str_format("%.*s/%s", str_fmt(&pkg->src), key.data);
if (access(file_path.data, F_OK) != 0) {
lua_pop(L, 1);
+ str_free(&file_path);
+ str_free(&key);
continue;
}
str_free(&file_path);
@@ -123,7 +122,6 @@ bool build_loop(package_t *pkg) {
log_info("attempting init.lua: 'repositories.%.*s.build'", str_fmt(&pkg->name));
if (repo_build(pkg)) { return true; }
log_warn("failed init.lua: 'repositories.%.*s.build'", str_fmt(&pkg->name));
- printf("testmeta\n");
log_info("attempting bldit.lua");
if (bldit(pkg)) { return true; }
diff --git a/src/lua_globs.c b/src/lua_globs.c
index ce5a59b..b14eb3a 100644
--- a/src/lua_globs.c
+++ b/src/lua_globs.c
@@ -138,11 +138,13 @@ bool lua_try_function(lua_State *L, char *lua_file, char *fname) {
bldit_isnt_type(fname, "function");
else
lua_isnt_type(fname, "function");
+ lua_pop(L, 1);
} else if (lua_pcall(L, 0, 1, 0) != LUA_OK) {
log_warn(
"%s: '%s' function borked: %s",
lua_file, fname, lua_tostring(L, -1)
);
+ lua_pop(L, 1);
return false;
}
if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) {
@@ -150,6 +152,7 @@ bool lua_try_function(lua_State *L, char *lua_file, char *fname) {
"%s: '%s' failed: %s",
lua_file, fname, lua_tostring(L, -1)
);
+ lua_pop(L, 1);
return false;
}
lua_pop(L, 1);
@@ -158,14 +161,13 @@ bool lua_try_function(lua_State *L, char *lua_file, char *fname) {
bool lua_try_table(lua_State *L, char *lua_file, char *tname) {
lua_getfield(L, -1, tname);
- bool val = true;
if (!lua_istable(L, -1)) {
- val = false;
- lua_pop(L, 1);
if (!strcmp(lua_file, "bldit.lua"))
bldit_isnt_type(tname, "table");
else
lua_isnt_type(tname, "table");
+ lua_pop(L, 1);
+ return false;
}
- return val;
+ return true;
}
diff --git a/src/lua_install.c b/src/lua_install.c
index e9fc2b4..5bf5270 100644
--- a/src/lua_install.c
+++ b/src/lua_install.c
@@ -57,9 +57,18 @@ void install_dependencies(lua_State *L) {
}
bool target_install(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, target->data)) {
+ lua_pop(L, 1);
+ return false;
+ }
+ lua_pop(L, 1);
lua_try_function(L, lua_file, "pre_install");
- if (!lua_try_function(L, lua_file, "install")) return false;
+ lua_pop(L, 1);
+ if (!lua_try_function(L, lua_file, "install")) {
+ lua_pop(L, 1);
+ return false;
+ }
+ lua_pop(L, 1);
lua_try_function(L, lua_file, "post_install");
lua_pop(L, 1);
return true;
@@ -73,7 +82,8 @@ bool repo_install(package_t *pkg) {
return false;
}
if (!lua_try_table(L, "init.lua", pkg->name.data)) {
- lua_pop(L, 1);
+ lua_isnt_type(pkg->name.data, "table");
+ lua_pop(L, 2);
return false;
}
if (!lua_try_table(L, "init.lua", "targets")) return false;
@@ -92,9 +102,9 @@ bool bldit_install(package_t *pkg) {
lua_pushfstring(B, "%s", inst_dirs.prefix.data);
lua_setglobal(B, "prefix");
lua_pop(B, 1);
- lua_try_table(L, "bldit.lua", "targets");
+ if (!lua_try_table(B, "bldit.lua", "targets")) return false;
bool target_success = target_install(B, "bldit.lua", &pkg->target);
- lua_pop(B, 1);
+ lua_pop(B, 2);
lua_close(B);
return target_success;
}
@@ -115,7 +125,10 @@ bool config_install(package_t *pkg) {
continue;
}
str_free(&file_path);
- lua_try_table(L, "init.lua", "targets");
+ if (!lua_try_table(L, "init.lua", "targets")) {
+ lua_pop(L, 2);
+ continue;
+ }
target_success = target_install(L, "init.lua", &pkg->target);
lua_pop(L, 2);
}
@@ -149,10 +162,13 @@ void pkg_install(package_t *pkg) {
log_pkgit("built " GREEN "%.*s" COLOR_RESET , str_fmt(&pkg->name));
bool install_success = false;
+ log_info("attempting init.lua: 'repositories.%.*s.install'", str_fmt(&pkg->name));
if (!install_success && repo_install(pkg))
install_success = true;
+ log_info("attempting bldit.lua: 'repositories.%.*s.install'", str_fmt(&pkg->name));
if (!install_success && bldit_install(pkg))
install_success = true;
+ log_info("attempting init.lua: 'build_systems'", str_fmt(&pkg->name));
if (!install_success && config_install(pkg))
install_success = true;
if (!install_success) {