diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/build.c | 2 | ||||
| -rw-r--r-- | src/cla_parse.c | 22 | ||||
| -rw-r--r-- | src/create_pkg.c | 2 | ||||
| -rw-r--r-- | src/help.c | 26 | ||||
| -rw-r--r-- | src/is_updated.c | 32 | ||||
| -rw-r--r-- | src/lua_build.c | 2 | ||||
| -rw-r--r-- | src/lua_state.c | 107 | ||||
| -rw-r--r-- | src/set_install_directories.c | 1 | ||||
| -rw-r--r-- | src/update_pkg.c | 3 | ||||
| -rw-r--r-- | src/vars.c | 1 |
10 files changed, 156 insertions, 42 deletions
diff --git a/src/build.c b/src/build.c index e5be9b2..5e96f52 100644 --- a/src/build.c +++ b/src/build.c @@ -4,6 +4,8 @@ #include <unistd.h> #include "build.h" + +#include "is_updated.h" #include "lua_build.h" #include "vars.h" diff --git a/src/cla_parse.c b/src/cla_parse.c index 964a38b..20f7c44 100644 --- a/src/cla_parse.c +++ b/src/cla_parse.c @@ -104,9 +104,6 @@ void parse_flags(int argc, char **argv, Pkg pkg) { if (argv[i][1] == '-') { COMMAND("--quiet", "-q", { is_verbose = false; }); COMMAND("--force", "-f", { is_forced = true; }); - COMMAND("--version", "-v", { printf("%s\n", version); }); - COMMAND("--help", "-h", { help(); }); - COMMAND("--check", "-c", { resolve_deps(); }); } else { mod_flags(argv, i); cmd_flags(argc, argv, i, pkg); @@ -116,14 +113,17 @@ void parse_flags(int argc, char **argv, Pkg pkg) { void parse_cmds(int argc, char **argv, Pkg pkg) { for (int i = 1; i < argc; i++) { - COMMAND("add", "a", { cmd_add(argv, i); }); - COMMAND("build", "b", { cmd_build(argc, argv, i, pkg); }); - COMMAND("install", "i", { cmd_install(argc, argv, i, pkg); }); - COMMAND("remove", "r", { cmd_remove(argc, argv, i, pkg); }); - COMMAND("update", "u", { update_all(); }); - COMMAND("declare", "d", { declare(); }); - COMMAND("list", "l", { list_pkgs(); }); - COMMAND("search", "s", { search(argv[i + 1]); }); + COMMAND("--add", "a", { cmd_add(argv, i); }); + COMMAND("--build", "b", { cmd_build(argc, argv, i, pkg); }); + COMMAND("--install", "i", { cmd_install(argc, argv, i, pkg); }); + COMMAND("--remove", "r", { cmd_remove(argc, argv, i, pkg); }); + COMMAND("--update", "u", { update_all(); }); + COMMAND("--declare", "d", { declare(); }); + COMMAND("--list", "l", { list_pkgs(); }); + COMMAND("--search", "s", { search(argv[i + 1]); }); + COMMAND("--version", "v", { printf("%s\n", version); }); + COMMAND("--help", "h", { help(); }); + COMMAND("--check", "c", { resolve_deps(); }); } } diff --git a/src/create_pkg.c b/src/create_pkg.c index 2ce3588..b65b49c 100644 --- a/src/create_pkg.c +++ b/src/create_pkg.c @@ -82,7 +82,7 @@ Pkg create_pkg(const char *arg) { pkg.target = trgptr + 1; *trgptr = '\0'; } else { - pkg.target = "default"; + pkg.target = is_verbose ? "default" : "quiet"; } bool is_in_repos = false; @@ -17,20 +17,20 @@ void help() { printf("%s%s%s\n", magenta, version, color_reset); } printf("\n"); - printf("%ssubcommands%s:\n", red, color_reset); - printf("%s %sa%s, %sadd %s[url] %s# add a repo\n", color_reset, green, color_reset, yellow, blue, gray); - printf("%s %sb%s, %sbuild %s[path] %s# build a package\n", color_reset, green, color_reset, yellow, blue, gray); - printf("%s %sd%s, %sdeclare %s# install all packages\n", color_reset, green, color_reset, yellow, gray); - printf("%s %ss%s, %ssearch %s[pkgs] %s# find a package from your repos\n", color_reset, green, color_reset, yellow, blue, gray); - printf("%s %si%s, %sinstall %s[pkgs, urls] %s# install a package/repo\n", color_reset, green, color_reset, yellow, blue, gray); - printf("%s %sr%s, %sremove %s[pkgs] %s# remove an installed package\n", color_reset, green, color_reset, yellow, blue, gray); - printf("%s %sl%s, %slist %s# list all installed packages\n", color_reset, green, color_reset, yellow, gray); - printf("%s %su%s, %supdate %s# update all installed packages\n", color_reset, green, color_reset, yellow, gray); - printf("\n"); - printf("%sflags%s:\n", red, color_reset); + printf("%ssubcommand flags%s:\n", red, color_reset); + printf("%s %s-a%s, %s--add %s[url] %s# add a repo\n", color_reset, green, color_reset, yellow, blue, gray); + printf("%s %s-b%s, %s--build %s[path] %s# build a package\n", color_reset, green, color_reset, yellow, blue, gray); + printf("%s %s-d%s, %s--declare %s# install all packages\n", color_reset, green, color_reset, yellow, gray); + printf("%s %s-s%s, %s--search %s[pkgs] %s# find a package from your repos\n", color_reset, green, color_reset, yellow, blue, gray); + printf("%s %s-i%s, %s--install %s[pkgs, urls] %s# install a package/repo\n", color_reset, green, color_reset, yellow, blue, gray); + printf("%s %s-r%s, %s--remove %s[pkgs] %s# remove an installed package\n", color_reset, green, color_reset, yellow, blue, gray); + printf("%s %s-l%s, %s--list %s# list all installed packages\n", color_reset, green, color_reset, yellow, gray); + printf("%s %s-u%s, %s--update %s# update all installed packages\n", color_reset, green, color_reset, yellow, gray); printf("%s %s-h%s, %s--help %s# display this help message\n", color_reset, green, color_reset, yellow, gray); - printf("%s %s-q%s, %s--quiet %s# run without logging to terminal\n", color_reset, green, color_reset, yellow, gray); - printf("%s %s-f%s, %s--force %s# force an operation like 'install'\n", color_reset, green, color_reset, yellow, gray); printf("%s %s-v%s, %s--version %s# display version number\n", color_reset, green, color_reset, yellow, gray); printf("%s %s-c%s, %s--check %s# run package checks\n", color_reset, green, color_reset, yellow, gray); + printf("\n"); + printf("%smodifier flags%s:\n", red, color_reset); + printf("%s %s-q%s, %s--quiet %s# run without logging to terminal\n", color_reset, green, color_reset, yellow, gray); + printf("%s %s-f%s, %s--force %s# force an operation like 'install'\n", color_reset, green, color_reset, yellow, gray); } diff --git a/src/is_updated.c b/src/is_updated.c index 68e6d2e..6ed53d3 100644 --- a/src/is_updated.c +++ b/src/is_updated.c @@ -5,15 +5,33 @@ #include <unistd.h> #include "is_updated.h" + #include "cmd_out.h" +#include "lua_state.h" bool is_updated(const char *src) { - if (src && strlen(src) > 0 && chdir(src) != 0) { - return false; - } - - char *output = cmd_out("git pull"); - bool result = (strstr(output, "Already up to date.") != NULL); - free(output); + bool result = false; + if (src && strlen(src) > 0 && chdir(src) != 0) return result; + char *bldit_pkgver = bldit_pkg_getver(); + char *git_tag = cmd_out("git tag | tail -n 1"); + result = (strstr(git_tag, bldit_pkgver) != NULL); + char *git_pull = cmd_out("git pull"); + result = (strstr(git_pull, "Already up to date.") != NULL); + free(git_tag); + free(git_pull); return result; +} + +bool is_bldit_usable() { + char* bldit_version = bldit_getver(); + if (strcmp(bldit_version, version) == 0) return true; + bool prev_pass = false; + for (int i = 0; i < strlen(bldit_version); i++) { + if (bldit_version[i] == '.') continue; + if ((bldit_version[i] - '0') <= (version[i] - '0')) { + prev_pass = ((bldit_version[i] - '0') != (version[i] - '0')); + continue; + } else return prev_pass; + } + return true; }
\ No newline at end of file diff --git a/src/lua_build.c b/src/lua_build.c index 269482d..7a289fd 100644 --- a/src/lua_build.c +++ b/src/lua_build.c @@ -2,6 +2,8 @@ #include <stdbool.h> #include "lua_build.h" + +#include "is_updated.h" #include "lua_state.h" #include "vars.h" diff --git a/src/lua_state.c b/src/lua_state.c index 4d3c4b5..fcaf90c 100644 --- a/src/lua_state.c +++ b/src/lua_state.c @@ -6,6 +6,7 @@ #include "create_pkg.h" #include "install_pkg.h" +#include "is_updated.h" #include "lua_state.h" #include "vars.h" @@ -81,6 +82,19 @@ void free_lua_state() { lua_State *get_lua_state() { return L; } +void cache_prefix_directory() { + lua_getglobal(L, "prefix"); + if (!lua_isstring(L, -1)) { + printf( + "%s init.lua: 'prefix' is not a string.\n", + print_error + ); + return; + } + snprintf(prefix_dir, MAX_PATH_LEN, "%s", lua_tostring(L, -1)); + lua_pop(L, 1); +} + void cache_install_directories() { if (!config_loaded || !lua_istable(L, -1)) { lua_getglobal(L, "install_directories"); @@ -155,7 +169,15 @@ bool target_loop_build( lua_pop(L, 3); return false; } - if (lua_pcall(L, 0, 0, 0) != LUA_OK) { + if (lua_pcall(L, 0, 1, 0) != LUA_OK) { + printf( + "%s %s: 'targets.%s.build' function borked: %s\n", + print_error, lua_file, target, lua_tostring(L, -1) + ); + lua_pop(L, 3); + return false; + } + if (!lua_isnumber(L, -1) || lua_tonumber(L, -1) != 0) if (is_verbose) { printf( "%s %s: 'targets.%s.build' failed: %s\n", print_error, lua_file, target, lua_tostring(L, -1) @@ -163,7 +185,7 @@ bool target_loop_build( lua_pop(L, 3); return false; } - lua_pop(L, 2); + lua_pop(L, 3); return true; } @@ -366,25 +388,58 @@ bool repo_uninstall(const char *repository, const char *target) { return target_loop_success; } +char* bldit_getver() { + init_bldit(); + lua_getglobal(B, "bldit_version"); + if (!lua_isstring(B, -1)) { + if (is_verbose) + printf("%s bldit.lua: 'bldit_version' is not a string.\n", print_warning); + return NULL; + } + const char* bldit_version = lua_tostring(B, -1); + return strdup(bldit_version); +} + +char* bldit_pkg_getver() { + init_bldit(); + lua_getglobal(B, "package_version"); + if (!lua_isstring(B, -1)) { + if (is_verbose) + printf("%s bldit.lua: 'package_version' is not a string.\n", print_warning); + return NULL; + } + const char* package_version = lua_tostring(B, -1); + return strdup(package_version); +} + bool bldit(const char *target) { lua_State *B = luaL_newstate(); luaL_openlibs(B); if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) { - if (is_verbose) printf("%s cannot run bldit script: %s\n", print_warning, lua_tostring(B, -1)); + if (is_verbose) printf( + "%s cannot run bldit script: %s\n", + print_warning, lua_tostring(B, -1) + ); lua_close(B); return false; } - lua_getglobal(B, "bldit_version"); - if (!lua_isstring(B, -1)) { - if (is_verbose) printf("%s bldit.lua: 'bldit_version' is not a string.\n", print_warning); + if (!is_bldit_usable()) { + printf( + "%s bldit version is newer than the installed pkgit version\n", + print_error + ); + printf( + "%s consider updating pkgit\n", + print_pkgit + ); + if (!is_forced) return false; } - lua_getglobal(B, "package_version"); - if (!lua_isstring(B, -1)) { - if (is_verbose) printf("%s bldit.lua: 'package_version' is not a string.\n", print_warning); - } + lua_pushfstring(B, "%s", prefix_dir); + lua_setglobal(B, "prefix"); + lua_pop(B, 1); lua_getglobal(B, "dependencies"); if (!lua_istable(B, -1)) { @@ -421,6 +476,22 @@ bool bldit_install(const char *target) { return false; } + if (!is_bldit_usable()) { + printf( + "%s bldit version is newer than the installed pkgit version\n", + print_error + ); + printf( + "%s consider updating pkgit\n", + print_pkgit + ); + if (!is_forced) return false; + } + + lua_pushfstring(B, "%s", prefix_dir); + lua_setglobal(B, "prefix"); + lua_pop(B, 1); + lua_getglobal(B, "targets"); if (!lua_istable(B, -1)) { if (is_verbose) printf( @@ -451,6 +522,22 @@ bool bldit_uninstall(const char *target) { return false; } + if (!is_bldit_usable()) { + printf( + "%s bldit version is newer than the installed pkgit version\n", + print_error + ); + printf( + "%s consider updating pkgit\n", + print_pkgit + ); + if (!is_forced) return false; + } + + lua_pushfstring(B, "%s", prefix_dir); + lua_setglobal(B, "prefix"); + lua_pop(B, 1); + lua_getglobal(B, "targets"); if (!lua_istable(B, -1)) { if (is_verbose) printf( diff --git a/src/set_install_directories.c b/src/set_install_directories.c index 95bd505..b99e227 100644 --- a/src/set_install_directories.c +++ b/src/set_install_directories.c @@ -8,6 +8,7 @@ void set_install_directories() { lua_State *L = get_lua_state(); + cache_prefix_directory(); lua_getglobal(L, "install_directories"); if (!lua_istable(L, -1)) { printf( diff --git a/src/update_pkg.c b/src/update_pkg.c index c926d4b..52c4c9e 100644 --- a/src/update_pkg.c +++ b/src/update_pkg.c @@ -1,8 +1,11 @@ #include <stdio.h> +#include <string.h> #include "update_pkg.h" + #include "is_updated.h" #include "install_pkg.h" +#include "lua_state.h" void update_pkg(Pkg pkg) { if (is_updated(pkg.src)) { @@ -15,6 +15,7 @@ bool is_forced = false; bool config_exists = false; char home_dir[MAX_PATH_LEN] = {0}; +char prefix_dir[MAX_PATH_LEN] = {0}; char root_config[MAX_PATH_LEN] = "/etc/pkgit/init.lua"; bool is_root_config = false; |
