diff options
| author | forever2k38 <forever2k38@noreply.codeberg.org> | 2026-09-06 22:35:45 +0200 |
|---|---|---|
| committer | forever2k38 <forever2k38@noreply.codeberg.org> | 2026-09-06 22:35:45 +0200 |
| commit | 1371aac8280c8281d7b79926fc7b8d8e38cda3ab (patch) | |
| tree | 3695aa664f3f7270263fb27d1895266b4b6934f1 | |
| parent | 7bf3c5b692f34bd6d9467ac3c651692c885a1d90 (diff) | |
feat: initial builds!
| -rw-r--r-- | src/args.c | 4 | ||||
| -rw-r--r-- | src/build.c | 11 | ||||
| -rw-r--r-- | src/download.c | 27 | ||||
| -rw-r--r-- | src/download.h | 3 | ||||
| -rw-r--r-- | src/package.c | 118 | ||||
| -rw-r--r-- | src/package.h | 9 | ||||
| -rw-r--r-- | src/paths.c | 2 | ||||
| -rw-r--r-- | src/pow_lua.c | 2 | ||||
| -rw-r--r-- | testing/samurai/1.3.lua | 10 |
9 files changed, 178 insertions, 8 deletions
@@ -22,8 +22,8 @@ char *help = "▄▄▄▄▄▄▄▄▄▄▄ ▄\n" int pow_args_parse(int argc, char **argv, pow_args *args) { int flags = 0; - bool next_flag_config; - bool next_flag_package; + bool next_flag_config = false; + bool next_flag_package = false; for (int i = 0; i < argc; i++) { char *arg = argv[i]; diff --git a/src/build.c b/src/build.c index 855b38b..243f3bc 100644 --- a/src/build.c +++ b/src/build.c @@ -2,10 +2,12 @@ #include "package.h" #include "paths.h" +#include "download.h" #include "lauxlib.h" #include "lua.h" #include "lualib.h" #include "stdio.h" +#include "stdlib.h" #include "unistd.h" int pow_package_build(pow_package *pkg) { @@ -31,16 +33,25 @@ int pow_package_build(pow_package *pkg) { if ((err = chdir(tmp_path))) { printf("uh oh oops %d\n", err); + + return 1; } + printf("building package %s\n", pkg->name); + + pow_download_source(pkg->sources[0], tmp_path); + lua_getfield(pkg->L, -1, "build"); if (lua_pcall(pkg->L, 0, 0, 0) != LUA_OK) { + free(tmp_path); + printf("error running script: %s\n", lua_tostring(pkg->L, -1)); return 1; } + free(tmp_path); fflush(stdout); return 0; diff --git a/src/download.c b/src/download.c index bb8365c..351a36b 100644 --- a/src/download.c +++ b/src/download.c @@ -1,5 +1,9 @@ +#include "package.h" + #include "curl/curl.h" #include "stdio.h" +#include "stdlib.h" +#include "string.h" static size_t write_cb(char *ptr, size_t size, size_t nmemb, void *stream) { size_t written = fwrite(ptr, size, nmemb, (FILE *)stream); @@ -11,6 +15,9 @@ int pow_download_file(char *path, char *url) { FILE *pagefile; CURL *curl = curl_easy_init(); + printf("%s", path); + printf("%s", url); + if (!curl) { printf("failed to init curl\n"); @@ -18,13 +25,16 @@ int pow_download_file(char *path, char *url) { } curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_cb); + curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); pagefile = fopen(path, "wb"); if (!pagefile) { + printf("failed to open file to download\n"); + curl_easy_cleanup(curl); return 1; @@ -32,9 +42,22 @@ int pow_download_file(char *path, char *url) { curl_easy_setopt(curl, CURLOPT_WRITEDATA, pagefile); - int result = curl_easy_perform(curl); + CURLcode result = curl_easy_perform(curl); + + curl_easy_cleanup(curl); fclose(pagefile); return result; } + +int pow_download_source(pow_package_source *src, const char *prefix) { + size_t len = strlen(prefix) + strlen(src->out) + 2; + char *full_path = malloc(len); + + snprintf(full_path, len, "%s/%s", prefix, src->out); + + pow_download_file(full_path, src->in); + + return 0; +} diff --git a/src/download.h b/src/download.h index c2db32b..53b991e 100644 --- a/src/download.h +++ b/src/download.h @@ -1 +1,4 @@ +#include "package.h" + int pow_download_file(char *path, char *url); +int pow_download_source(pow_package_source *src, const char *prefix); diff --git a/src/package.c b/src/package.c index 98d6f00..ad7e4d0 100644 --- a/src/package.c +++ b/src/package.c @@ -6,6 +6,7 @@ #include "pow_lua.h" #include "stdio.h" #include "string.h" +#include <lua.h> int extract_package_info(lua_State *L, pow_package *pkg) { lua_getfield(L, -1, "name"); @@ -29,6 +30,8 @@ int extract_package_info(lua_State *L, pow_package *pkg) { lua_getfield(L, -1, "version"); if (!lua_isstring(L, -1)) { + free(pkg->name); + printf("invalid package, version is not string (or doesn't exist)\n"); return 1; @@ -39,11 +42,120 @@ int extract_package_info(lua_State *L, pow_package *pkg) { lua_pop(L, 1); if (!pkg->version) { + free(pkg->name); + printf("strdup failed trying to get package name\n"); return 1; } + lua_getfield(L, -1, "sources"); + + if (!lua_istable(L, -1)) { + free(pkg->name); + free(pkg->version); + + printf("sources is not table or doesn't exist\n"); + + return 1; + } + + size_t sources_len = lua_rawlen(L, -1); + + for (size_t i = 0; i < sources_len; i++) { + lua_pushinteger(L, i + 1); + + lua_gettable(L, -2); + + if (lua_type(L, -1) == LUA_TNIL) + break; + + lua_getfield(L, -1, "path"); + + pow_package_source *src = malloc(sizeof(pow_package_source)); + + if (!src) { + printf("failed to malloc pow_package_source\n"); + + return 1; + } + + if (!lua_isstring(L, -1)) { + lua_pop(L, 1); + + printf("path is not string\n"); + + return 1; + } + + const char *in = strdup(lua_tostring(L, -1)); + + if (!in) { + printf("failed to strdup path?"); + + return 1; + } + + src->in = in; + + lua_pop(L, 1); + + lua_getfield(L, -1, "out"); + + if (!lua_isstring(L, -1)) { + lua_pop(L, 1); + + printf("out is not string\n"); + + return 1; + } + + const char *out = strdup(lua_tostring(L, -1)); + + if (!out) { + free(in); + + lua_pop(L, 1); + + printf("out strdup failed?\n"); + + return 1; + } + + src->out = out; + + lua_pop(L, 1); + + lua_getfield(L, -1, "hash"); + + if (!lua_isstring(L, -1)) { + free(in); + free(out); + + printf("hash is not string?\n"); + + return 1; + } + + const char *hash = strdup(lua_tostring(L, -1)); + + src->hash = hash; + + pkg->source_count++; + + printf("attempting to malloc\n"); + + pkg->sources = + realloc(pkg->sources, pkg->source_count * sizeof(pow_package_source *)); + + pkg->sources[pkg->source_count - 1] = src; + + lua_pop(L, 1); + lua_pop(L, 1); + } + + lua_pop(L, 1); + return 0; } @@ -73,6 +185,7 @@ int pow_package_open(pow_package *pkg, const char *path) { if (!tmp) { fclose(fp); + free(package_buffer); printf("failed to realloc package buffer\n"); @@ -87,6 +200,8 @@ int pow_package_open(pow_package *pkg, const char *path) { package_buffer[total++] = c; } + fclose(fp); + package_buffer[total] = '\0'; lua_State *L = luaL_newstate(); @@ -114,6 +229,9 @@ int pow_package_open(pow_package *pkg, const char *path) { return 1; } + pkg->source_count = 0; + pkg->sources = NULL; + extract_package_info(L, pkg); pkg->path = path; diff --git a/src/package.h b/src/package.h index 12804bc..5d84800 100644 --- a/src/package.h +++ b/src/package.h @@ -5,12 +5,21 @@ #include "stddef.h" typedef struct { + const char *in; + const char *out; + const char *hash; +} pow_package_source; + +typedef struct { const char *name; const char *version; const char *description; const char *path; + pow_package_source **sources; + size_t source_count; + size_t *arch; lua_State *L; diff --git a/src/paths.c b/src/paths.c index 20af56d..5c8121a 100644 --- a/src/paths.c +++ b/src/paths.c @@ -16,7 +16,9 @@ int pow_create_dir_for_package(char **path) { strcpy(new_path, template); if (!mkdtemp(new_path)) { + printf("failed to make dir\n"); free(new_path); + return 1; } diff --git a/src/pow_lua.c b/src/pow_lua.c index 70b32ad..cd71c87 100644 --- a/src/pow_lua.c +++ b/src/pow_lua.c @@ -7,6 +7,8 @@ #include "string.h" int pow_lua_extract(lua_State *L) { + printf("extract called\n"); + int r; ssize_t size; diff --git a/testing/samurai/1.3.lua b/testing/samurai/1.3.lua index 1da722f..c84e4a1 100644 --- a/testing/samurai/1.3.lua +++ b/testing/samurai/1.3.lua @@ -17,16 +17,18 @@ package.deps = { package.sources = { { - url = "https://github.com/michaelforney/samurai/releases/download/1.3/samurai-1.3.tar.gz", - sha256 = "1bc020a9e133432df51911ac71cc34322f828934d9a2282ba2916d88c15976af", - name = "source.tar.gz", + path = "https://github.com/michaelforney/samurai/releases/download/1.3/samurai-1.3.tar.gz", + hash = "1bc020a9e133432df51911ac71cc34322f828934d9a2282ba2916d88c15976af", + out = "source.tar.gz", }, } package.build = function() + print(lfs.currentdir()) + pow.extract("source.tar.gz", "source") - lfs.chdir("source") + lfs.chdir("source/samurai-1.3") os.execute("make") end |
