aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/build.c9
-rw-r--r--src/cla_parse.c50
-rw-r--r--src/copy_install.c124
-rw-r--r--src/create_pkg.c30
-rw-r--r--src/declare.c2
-rw-r--r--src/fetch_git.c2
-rw-r--r--src/fetch_src.c25
-rw-r--r--src/files.c83
-rw-r--r--src/install_pkg.c83
-rw-r--r--src/is_updated.c2
-rw-r--r--src/link_install.c76
-rw-r--r--src/list_pkgs.c11
-rw-r--r--src/lua_build.c29
-rw-r--r--src/lua_state.c460
-rw-r--r--src/remove.c32
-rw-r--r--src/remove_pkg.c47
-rw-r--r--src/update_all.c4
-rw-r--r--src/update_pkg.c4
-rw-r--r--src/vars.c13
19 files changed, 494 insertions, 592 deletions
diff --git a/src/build.c b/src/build.c
index 02bbef4..549fe64 100644
--- a/src/build.c
+++ b/src/build.c
@@ -11,13 +11,8 @@ void build(Pkg pkg) {
char original_dir[MAX_PATH_LEN];
getcwd(original_dir, MAX_PATH_LEN);
- if (strcmp(pkg.src, original_dir) != 0) {
- chdir(pkg.src);
- }
-
- if (lua_build(pkg.name, pkg.target, pkg.src)) {
- return;
- }
+ if (strcmp(pkg.src, original_dir) != 0) chdir(pkg.src);
+ if (lua_build(pkg.name, pkg.target, pkg.src)) return;
printf("%s no usable build system was found\n", print_error);
exit(EXIT_FAILURE);
diff --git a/src/cla_parse.c b/src/cla_parse.c
index 9c62e07..4eae6f6 100644
--- a/src/cla_parse.c
+++ b/src/cla_parse.c
@@ -24,7 +24,7 @@
code
#define NOT_ENOUGH_ARGS(arg, next) \
- printf("%sNot enough arguments! Try: `pkgit %s [%s]`\n", print_error, arg, \
+ printf("%s Not enough arguments! Try: `pkgit %s [%s]`\n", print_error, arg, \
next)
void cla_parse(int argc, char **argv) {
@@ -38,6 +38,7 @@ void cla_parse(int argc, char **argv) {
for (int i = 1; i < argc; i++) {
COMMAND("--link", "-l", { is_symlink_install = true; });
COMMAND("--quiet", "-q", { is_verbose = false; });
+ COMMAND("--force", "-f", { is_forced = true; });
}
for (int i = 1; i < argc; i++) {
@@ -50,32 +51,38 @@ void cla_parse(int argc, char **argv) {
});
COMMAND("build", "b", {
if (argv[i + 1]) {
- if (argv[i + 2]) {
- pkg = create_pkg(argv[i + 1], argv[i + 2]);
- build(pkg);
- } else if (!is_verbose) {
- pkg = create_pkg(argv[i + 1], "quiet");
- build(pkg);
+ if (!is_verbose) {
+ for (int j = i + 1; j < argc; j++) {
+ if (argv[j][0] == '-') continue;
+ pkg = create_pkg(argv[j]);
+ build(pkg);
+ }
} else {
- pkg = create_pkg(argv[i + 1], "default");
- build(pkg);
+ for (int j = i + 1; j < argc; j++) {
+ if (argv[j][0] == '-') continue;
+ pkg = create_pkg(argv[j]);
+ build(pkg);
+ }
}
} else {
- pkg = create_pkg(".", "default");
+ pkg = create_pkg(".");
build(pkg);
}
});
COMMAND("install", "i", {
if (argv[i + 1]) {
- if (argv[i + 2]) {
- pkg = create_pkg(argv[i + 1], argv[i + 2]);
- install_pkg(pkg);
- } else if (!is_verbose) {
- pkg = create_pkg(argv[i + 1], "quiet");
- install_pkg(pkg);
+ if (!is_verbose) {
+ for (int j = i + 1; j < argc; j++) {
+ if (argv[j][0] == '-') continue;
+ pkg = create_pkg(argv[j]);
+ install_pkg(pkg);
+ }
} else {
- pkg = create_pkg(argv[i + 1], "default");
- install_pkg(pkg);
+ for (int j = i + 1; j < argc; j++) {
+ if (argv[j][0] == '-') continue;
+ pkg = create_pkg(argv[j]);
+ install_pkg(pkg);
+ }
}
} else {
NOT_ENOUGH_ARGS(argv[i], "url/pkg");
@@ -83,8 +90,11 @@ void cla_parse(int argc, char **argv) {
});
COMMAND("remove", "r", {
if (argv[i + 1]) {
- pkg = create_pkg(argv[i + 1], "default");
- remove_pkg(pkg);
+ for (int j = i + 1; j < argc; j++) {
+ if (argv[j][0] == '-') continue;
+ pkg = create_pkg(argv[j]);
+ remove_pkg(pkg);
+ }
} else {
NOT_ENOUGH_ARGS(argv[i], "url/pkg");
}
diff --git a/src/copy_install.c b/src/copy_install.c
deleted file mode 100644
index b1b56ff..0000000
--- a/src/copy_install.c
+++ /dev/null
@@ -1,124 +0,0 @@
-#include <dirent.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <unistd.h>
-
-#include "copy_install.h"
-#include "vars.h"
-
-static int is_executable(const char *path) { return (access(path, X_OK) == 0); }
-
-static int is_dir(const char *path) {
- struct stat st;
- if (stat(path, &st) == 0) {
- return S_ISDIR(st.st_mode);
- }
- return 0;
-}
-
-static const char *get_extension(const char *path) {
- const char *dot = strrchr(path, '.');
- return dot ? dot : "";
-}
-
-static int copy_file(const char *src, const char *dst) {
- struct stat st;
- if (stat(src, &st) != 0)
- return -1;
-
- int src_fd = open(src, O_RDONLY);
- if (src_fd < 0)
- return -1;
-
- int dst_fd = open(dst, O_WRONLY | O_CREAT | O_TRUNC, st.st_mode & 07777);
- if (dst_fd < 0) {
- close(src_fd);
- return -1;
- }
-
- char buf[8192];
- ssize_t n;
- while ((n = read(src_fd, buf, sizeof(buf))) > 0) {
- ssize_t written = 0;
- while (written < n) {
- ssize_t ret = write(dst_fd, buf + written, n - written);
- if (ret < 0) {
- close(src_fd);
- close(dst_fd);
- return -1;
- }
- written += ret;
- }
- }
-
- close(src_fd);
- close(dst_fd);
- return n == 0 ? 0 : -1;
-}
-
-static void copy_install_recursive(const char *dir_path) {
- DIR *dir = opendir(dir_path);
- if (!dir)
- return;
-
- struct dirent *entry;
- while ((entry = readdir(dir)) != NULL) {
- if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
- continue;
- }
-
- char src_path[MAX_PATH_LEN];
- snprintf(src_path, sizeof(src_path), "%s/%s", dir_path, entry->d_name);
-
- if (is_dir(src_path)) {
- if (strcmp(entry->d_name, ".git") != 0) {
- copy_install_recursive(src_path);
- }
- continue;
- }
-
- const char *ext = get_extension(entry->d_name);
-
- if (strncmp(ext, ".so", 3) == 0) {
- char dest_path[MAX_PATH_LEN];
- snprintf(dest_path, sizeof(dest_path), "%s/%s", lib, entry->d_name);
- if (!file_exists(dest_path)) {
- copy_file(src_path, dest_path);
- if (is_verbose) {
- printf("%scopied library: %s\n", print_pkgit, src_path);
- }
- }
- } else if (is_executable(src_path)) {
- if (strcmp(ext, ".sample") != 0 && strcmp(entry->d_name, "bldit") != 0 &&
- strcmp(entry->d_name, "build.sh") != 0 &&
- strcmp(entry->d_name, "compile.sh") != 0) {
- char dest_path[MAX_PATH_LEN];
- snprintf(dest_path, sizeof(dest_path), "%s/%s", bin, entry->d_name);
- if (!file_exists(dest_path)) {
- copy_file(src_path, dest_path);
- if (is_verbose) {
- printf("%scopied executable: %s\n", print_pkgit, src_path);
- }
- }
- }
- } else if (strcmp(ext, ".h") == 0) {
- char dest_path[MAX_PATH_LEN];
- snprintf(dest_path, sizeof(dest_path), "%s/%s", inc, entry->d_name);
- if (!file_exists(dest_path)) {
- copy_file(src_path, dest_path);
- if (is_verbose) {
- printf("%scopied include: %s\n", print_pkgit, src_path);
- }
- }
- }
- }
-
- closedir(dir);
-}
-
-void copy_install(const char *build_dir) {
- copy_install_recursive(build_dir);
-}
diff --git a/src/create_pkg.c b/src/create_pkg.c
index 36e9d10..cf92f75 100644
--- a/src/create_pkg.c
+++ b/src/create_pkg.c
@@ -4,13 +4,13 @@
#include <unistd.h>
#include "create_pkg.h"
+#include "files.h"
#include "lua_state.h"
#include "name_from_url.h"
#include "vars.h"
-Pkg create_pkg(const char *arg, const char *target) {
+Pkg create_pkg(const char *arg) {
Pkg pkg = {0};
- pkg.target = target;
pkg.ver = "HEAD";
pkg.is_local = false;
@@ -23,10 +23,17 @@ Pkg create_pkg(const char *arg, const char *target) {
char *new_arg = strdup(arg);
if (!new_arg) exit(EXIT_FAILURE);
char *argver = strchr(new_arg, '@');
+ char *argtrg = strchr(new_arg, ',');
if (argver) {
pkg.ver = argver + 1;
*argver = '\0';
}
+ if (argtrg) {
+ pkg.target = argtrg + 1;
+ *argtrg = '\0';
+ } else {
+ pkg.target = "default";
+ }
bool is_in_repos = false;
for (size_t i = 0; i < cached_repos_count; i++) {
@@ -42,7 +49,7 @@ Pkg create_pkg(const char *arg, const char *target) {
} else if (strcmp(new_arg, ".") == 0) {
pkg.url = "";
getcwd(pkg.src, MAX_PATH_LEN);
- pkg.name = name_from_url(pkg.url);
+ pkg.name = name_from_url(pkg.src);
pkg.is_local = true;
} else if (is_in_repos) {
for (size_t i = 0; i < cached_repos_count; i++) {
@@ -53,20 +60,27 @@ Pkg create_pkg(const char *arg, const char *target) {
}
pkg.name = strdup(new_arg);
} else {
- printf("%s'%s' is not a valid package\n", print_error, new_arg);
+ printf("%s '%s' is not a valid package\n", print_error, new_arg);
exit(EXIT_FAILURE);
}
- if (strlen(pkg.name) > 4 && strncmp(pkg.name + strlen(pkg.name) - 4, ".git", 4) == 0) {
+ if (strlen(pkg.name) > 4 &&
+ strncmp(pkg.name + strlen(pkg.name) - 4, ".git", 4) == 0)
pkg.name[strlen(pkg.name) - 4] = '\0';
- }
cache_install_directories();
if (!pkg.is_local) {
char src_dir[MAX_PATH_LEN];
- snprintf(src_dir, sizeof(src_dir), "%s/%s/%s", get_install_dir("src"),
- pkg.name, pkg.ver);
+ snprintf(src_dir, sizeof(src_dir), "%s/%s/%s",
+ get_install_dir("src"), pkg.name, pkg.ver);
snprintf(pkg.src, MAX_PATH_LEN, "%s", src_dir);
+ } else {
+ const char *destination = strcat(
+ strdup(get_install_dir("src")),
+ strcat(strdup("/"), pkg.name)
+ );
+ printf("%s\n", destination);
+ cpdir(pkg.src, destination);
}
return pkg;
diff --git a/src/declare.c b/src/declare.c
index 2ba42fb..d01468a 100644
--- a/src/declare.c
+++ b/src/declare.c
@@ -11,7 +11,7 @@ void declare() {
init_lua_state();
cache_repos();
for (size_t i = 0; i < cached_repos_count; i++) {
- Pkg pkg = create_pkg(cached_repos[i].source_value, "default");
+ Pkg pkg = create_pkg(cached_repos[i].source_value);
update_pkg(pkg);
}
}
diff --git a/src/fetch_git.c b/src/fetch_git.c
index 6353678..2d9e9a2 100644
--- a/src/fetch_git.c
+++ b/src/fetch_git.c
@@ -41,7 +41,7 @@ int fetch_git(Pkg pkg) {
waitpid(pid, &status, 0);
int result = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
if (result != 0) {
- printf("clone failed\n");
+ printf("%s git clone failed\n", print_warning);
}
return result;
diff --git a/src/fetch_src.c b/src/fetch_src.c
index f03ae5d..8ad1ff5 100644
--- a/src/fetch_src.c
+++ b/src/fetch_src.c
@@ -9,7 +9,10 @@
#include "fetch_git.h"
#include "vars.h"
-static int remove_tree(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf) {
+static int remove_tree(
+ const char *fpath, const struct stat *sb,
+ int typeflag, struct FTW *ftwbuf
+) {
(void)sb;
(void)ftwbuf;
if (typeflag == FTW_F || typeflag == FTW_SL) {
@@ -21,18 +24,30 @@ static int remove_tree(const char *fpath, const struct stat *sb, int typeflag, s
}
void fetch_src(Pkg pkg) {
- if (is_verbose) printf("%starget source directory: %s\n", print_pkgit, pkg.src);
+ if (is_verbose) printf(
+ "%s target source directory: %s\n",
+ print_pkgit, pkg.src
+ );
if (file_exists(pkg.src)) {
- if (is_verbose) printf("%s%s already exists. deleting...\n", print_pkgit, pkg.src);
+ if (is_verbose) printf(
+ "%s %s already exists. deleting...\n",
+ print_pkgit, pkg.src
+ );
nftw(pkg.src, remove_tree, 64, FTW_DEPTH | FTW_PHYS);
}
if (strcmp(pkg.url, "") == 0) {
- if (is_verbose) printf("%screating directory %s...\n", print_pkgit, pkg.src);
+ if (is_verbose) printf(
+ "%s creating directory %s...\n",
+ print_pkgit, pkg.src
+ );
mkdir_p(pkg.src);
return;
}
if (fetch_git(pkg) == 0) {
- if (is_verbose) printf("%scloned into %s...\n", print_pkgit, pkg.src);
+ if (is_verbose) printf(
+ "%s cloned into %s\n",
+ print_pkgit, pkg.src
+ );
return;
}
printf("%s no fetch methods worked.\n", print_error);
diff --git a/src/files.c b/src/files.c
index 86d9be4..5805d22 100644
--- a/src/files.c
+++ b/src/files.c
@@ -1,7 +1,90 @@
+#include <dirent.h>
+#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
+#include <sys/stat.h>
const char *get_filename_ext(const char *filename) {
const char *dot = strrchr(filename, '.');
if(!dot || dot == filename) return "";
return dot + 1;
}
+
+void cpdir(const char *path, const char *dest) {
+ DIR *dirp = opendir(path);
+ struct dirent *dirp_ent;
+
+ struct stat dest_st;
+ stat(dest, &dest_st);
+ if (dest_st.st_mode && dest_st.st_mode == S_IFDIR) {
+ mkdir(dest, dest_st.st_mode);
+ }
+
+ while ((dirp_ent = readdir(dirp))) {
+ if (dirp_ent->d_name[0] == '.' &&
+ (strlen(dirp_ent->d_name) == 1 ||
+ (strlen(dirp_ent->d_name) == 2 &&
+ dirp_ent->d_name[1] == '.'))
+ ) continue;
+ char rfile_line[1024];
+ struct stat st;
+ char *filename = malloc(sizeof(path)+sizeof(dirp_ent->d_name)+2);
+ snprintf(
+ filename,
+ sizeof(path)+sizeof(dirp_ent->d_name)+2,
+ "%s/%s",
+ path, dirp_ent->d_name
+ );
+ printf("FILENAME: %s\n", filename);
+ stat(filename, &st);
+ if (st.st_mode) {
+ char *newfile = malloc(sizeof(dest)+sizeof(dirp_ent->d_name)+2);
+ snprintf(
+ newfile,
+ sizeof(dest)+sizeof(dirp_ent->d_name)+2,
+ "%s/%s",
+ dest, dirp_ent->d_name
+ );
+ if (st.st_mode == S_IFDIR) {
+ printf("DIRECTORY\n");
+ printf("NEWDIR: %s\n", newfile);
+ mkdir(newfile, st.st_mode);
+ cpdir(filename, newfile);
+ continue;
+ }
+ FILE *rfile = fopen(dirp_ent->d_name, "r");
+ FILE *wfile = fopen(newfile, "w+");
+ if (!rfile || !wfile) { continue; }
+ size_t ret = fread(
+ rfile_line,
+ //sizeof(*rfile_line),
+ //sizeof(rfile_line)/sizeof(rfile_line[0]),
+ 1,
+ 1024,
+ rfile
+ );
+ if (ret != sizeof(rfile_line)/sizeof(rfile_line[0]) && ferror(rfile)) {
+ fprintf(stderr, "file read failed: %zu\n", ret);
+ continue;
+ }
+ size_t write = fwrite(
+ rfile_line,
+ //sizeof(rfile_line[0]),
+ 1,
+ ret,
+ wfile
+ );
+ if (write != sizeof(rfile_line)/sizeof(rfile_line[0])) {
+ fprintf(stderr, "file write failed: %zu\n", ret);
+ continue;
+ }
+ if (feof(rfile)) {
+ fclose(rfile);
+ fclose(wfile);
+ continue;
+ }
+ free(newfile);
+ }
+ free(filename);
+ }
+}
diff --git a/src/install_pkg.c b/src/install_pkg.c
index 8831499..c0809e8 100644
--- a/src/install_pkg.c
+++ b/src/install_pkg.c
@@ -7,65 +7,94 @@
#include "build.h"
#include "fetch_src.h"
#include "install_pkg.h"
-// #include "copy_install.h"
-// #include "link_install.h"
#include "lua_state.h"
#include "name_from_url.h"
#include "vars.h"
void install_pkg(Pkg pkg) {
+ if (is_directory(pkg.src)) {
+ if (!is_forced) {
+ if (is_verbose) printf(
+ "%s %s is already installed.\n",
+ print_skipped, pkg.name
+ );
+ return;
+ } else {
+ if (is_verbose) printf(
+ "%s %s is already installed.\n",
+ print_warning, pkg.name
+ );
+ }
+ }
+
if (!pkg.is_local) {
- printf("%sfetching %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ printf(
+ "%s fetching %s%s%s\n",
+ print_pkgit, green, pkg.name, color_reset
+ );
fetch_src(pkg);
if (is_verbose)
- printf("%sfetched %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ printf(
+ "%s fetched %s%s%s\n",
+ print_pkgit, green, pkg.name, color_reset
+ );
}
- printf("%sbuilding %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ printf(
+ "%s building %s%s%s\n",
+ print_pkgit, green, pkg.name, color_reset
+ );
build(pkg);
if (is_verbose)
- printf("%sbuilt %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ printf(
+ "%s built %s%s%s\n",
+ print_pkgit, green, pkg.name, color_reset
+ );
- printf("%sinstalling %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ printf(
+ "%s installing %s%s%s\n",
+ print_pkgit, green, pkg.name, color_reset
+ );
bool install_success = false;
- if (!install_success && repo_install(pkg.name))
+ if (!install_success && repo_install(pkg.name, pkg.target))
install_success = true;
if (!install_success && bldit_install(pkg.target))
install_success = true;
- if (!install_success && config_install(pkg.src))
+ if (!install_success && config_install(pkg.src, pkg.target))
install_success = true;
if (!install_success) {
- printf("%sno install function availible for package: %s\n", print_error,
- pkg.name);
+ printf(
+ "%s no install function availible for package: %s\n",
+ print_error, pkg.name
+ );
return;
}
- // is_auto_installed = true;
- // if (is_auto_installed) {
- // if (is_symlink_install) {
- // link_install(pkg.src);
- // } else {
- // copy_install(pkg.src);
- // }
- // }
- printf("%sinstalled %s%s%s\n", print_success, green, pkg.name, color_reset);
+ printf(
+ "%s installed %s%s%s\n",
+ print_success, green, pkg.name, color_reset
+ );
bool repo_exists = false;
for (size_t i = 0; i < cached_repos_count; i++) {
- char *repo_name = name_from_url(cached_repos[i].source_value);
- if (strcmp(repo_name, pkg.name) == 0) {
- repo_exists = true;
- }
+ char *repo_name = name_from_url(cached_repos[i].source_key);
+ if (strcmp(repo_name, pkg.name) == 0) { repo_exists = true; }
free(repo_name);
}
if (!repo_exists) {
- printf("%sadding %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ printf(
+ "%s adding %s%s%s\n",
+ print_pkgit, green, pkg.name, color_reset
+ );
if (pkg.url && strlen(pkg.url) > 0) {
add_repo(pkg.url, pkg.name);
}
- printf("%sadded %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ printf(
+ "%s added %s%s%s\n",
+ print_pkgit, green, pkg.name, color_reset
+ );
} else {
if (is_verbose)
- printf("%srepo already exists, done\n", print_pkgit);
+ printf("%s repo already exists, done\n", print_pkgit);
}
} \ No newline at end of file
diff --git a/src/is_updated.c b/src/is_updated.c
index 29b482d..5fce96b 100644
--- a/src/is_updated.c
+++ b/src/is_updated.c
@@ -10,7 +10,7 @@
bool is_updated(const char *src) {
if (src && strlen(src) > 0 && chdir(src) != 0) {
- return false;
+ return false;
}
char *output = cmd_out("git pull");
diff --git a/src/link_install.c b/src/link_install.c
deleted file mode 100644
index 9f658d4..0000000
--- a/src/link_install.c
+++ /dev/null
@@ -1,76 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <dirent.h>
-
-#include "link_install.h"
-#include "vars.h"
-
-static int is_executable(const char *path) {
- return (access(path, X_OK) == 0);
-}
-
-static int is_dir(const char *path) {
- struct stat st;
- if (stat(path, &st) == 0) {
- return S_ISDIR(st.st_mode);
- }
- return 0;
-}
-
-static const char* get_extension(const char *path) {
- const char *dot = strrchr(path, '.');
- return dot ? dot : "";
-}
-
-void link_install(const char *build_dir) {
- DIR *dir = opendir(build_dir);
- if (!dir) return;
-
- struct dirent *entry;
- while ((entry = readdir(dir)) != NULL) {
- if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
- continue;
- }
-
- char src_path[MAX_PATH_LEN];
- char link_path[MAX_PATH_LEN];
- snprintf(src_path, sizeof(src_path), "%s/%s", build_dir, entry->d_name);
-
- const char *ext = get_extension(entry->d_name);
-
- if (strncmp(ext, ".so", 3) == 0) {
- snprintf(link_path, sizeof(link_path), "%s/%s", lib, entry->d_name);
- if (!file_exists(link_path)) {
- symlink(src_path, link_path);
- if (is_verbose) {
- printf("%slinked library: %s\n", print_pkgit, src_path);
- }
- }
- } else if (is_executable(src_path) && !is_dir(src_path)) {
- if (strcmp(entry->d_name, "bldit") != 0 &&
- strcmp(entry->d_name, "build.sh") != 0 &&
- strcmp(entry->d_name, "compile.sh") != 0) {
- snprintf(link_path, sizeof(link_path), "%s/%s", bin, entry->d_name);
- if (!file_exists(link_path)) {
- symlink(src_path, link_path);
- if (is_verbose) {
- printf("%slinked executable: %s\n", print_pkgit, src_path);
- }
- }
- }
- } else if (strcmp(ext, ".h") == 0) {
- snprintf(link_path, sizeof(link_path), "%s/%s", inc, entry->d_name);
- if (!file_exists(link_path)) {
- symlink(src_path, link_path);
- if (is_verbose) {
- printf("%slinked include: %s\n", print_pkgit, src_path);
- }
- }
- }
- }
-
- closedir(dir);
-} \ No newline at end of file
diff --git a/src/list_pkgs.c b/src/list_pkgs.c
index 5d6fcce..6d4ba3f 100644
--- a/src/list_pkgs.c
+++ b/src/list_pkgs.c
@@ -12,12 +12,19 @@ void list_pkgs() {
DIR* dir_ptr = opendir(src_code);
if (dir_ptr == NULL) {
- fprintf(stderr, "%scould not open %s\n", print_pkgit, src_code);
+ fprintf(
+ stderr,
+ "%s could not open %s\n",
+ print_pkgit, src_code
+ );
return;
}
while ((dirent_ptr = readdir(dir_ptr)) != NULL) {
- if (strcmp(dirent_ptr->d_name, "..") == 0 || strcmp(dirent_ptr->d_name, ".") == 0) { continue; }
+ if (
+ strcmp(dirent_ptr->d_name, "..") == 0 ||
+ strcmp(dirent_ptr->d_name, ".") == 0
+ ) continue;
printf("%s\n", dirent_ptr->d_name);
}
} \ No newline at end of file
diff --git a/src/lua_build.c b/src/lua_build.c
index de82f83..1e90d3a 100644
--- a/src/lua_build.c
+++ b/src/lua_build.c
@@ -7,17 +7,34 @@
bool lua_build(const char *repository, const char *target, const char *path) {
if (is_verbose) printf(
- "%sattempting to use build function specified in 'repositories.%s'...\n",
+ "%s attempting init.lua: 'repositories.%s.build'\n",
print_pkgit, repository
);
+ if (repo_build(repository, target)) { return true; }
+ if (is_verbose) printf(
+ "%s failed init.lua: 'repositories.%s.build'\n",
+ print_warning, repository
+ );
- if (repo_build(repository)) { return true; }
-
- if (is_verbose) printf("%sattempting to use build function specified in 'bldit.lua'...\n", print_pkgit);
+ if (is_verbose) printf(
+ "%s attempting bldit.lua\n",
+ print_pkgit
+ );
if (bldit(target)) { return true; }
+ if (is_verbose) printf(
+ "%s failed bldit.lua\n",
+ print_warning
+ );
- if (is_verbose) printf("%sattempting to use build functions specified in 'build_systems'...\n", print_pkgit);
- if (config_build(path)) { return true; }
+ if (is_verbose) printf(
+ "%s attempting init.lua: 'build_systems'\n",
+ print_pkgit
+ );
+ if (config_build(path, target)) { return true; }
+ if (is_verbose) printf(
+ "%s failed init.lua: 'build_systems'\n",
+ print_warning
+ );
return false;
} \ No newline at end of file
diff --git a/src/lua_state.c b/src/lua_state.c
index 25e9a7b..c23eb92 100644
--- a/src/lua_state.c
+++ b/src/lua_state.c
@@ -37,11 +37,11 @@ void init_lua_state() {
push_lua_path(L, lua_path);
if (luaL_loadfile(L, config_file) || lua_pcall(L, 0, 0, 0)) {
printf(
- "%scannot run configuration script: %s\n",
+ "%s cannot run configuration script: %s\n",
print_error, lua_tostring(L, -1)
);
printf(
- "%sto generate a configration file, head into the root directory of the pkgit source and run `make defconfig`\n",
+ "%s to generate a configration file, head into the root directory of the pkgit source and run `make defconfig`\n",
print_pkgit
);
exit(EXIT_FAILURE);
@@ -49,7 +49,7 @@ void init_lua_state() {
if (file_exists(repo_file)) {
if (luaL_loadfile(L, repo_file) || lua_pcall(L, 0, 0, 0)) {
printf(
- "%scannot load repository file: %s\n",
+ "%s cannot load repository file: %s\n",
print_error, lua_tostring(L, -1)
);
lua_pop(L, 1);
@@ -65,7 +65,7 @@ void init_bldit() {
luaL_openlibs(B);
if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) {
if (is_verbose) printf(
- "%scannot run bldit script: %s\n",
+ "%s cannot run bldit script: %s\n",
print_warning, lua_tostring(B, -1)
);
return;
@@ -89,7 +89,7 @@ void cache_install_directories() {
}
if (!lua_istable(L, -1)) {
printf(
- "%slua variable 'install_directories' is not a table.\n",
+ "%s init.lua: 'install_directories' is not a table.\n",
print_error
);
return;
@@ -116,7 +116,7 @@ void install_dependencies(lua_State *L) {
lua_getfield(L, -1, "version");
const char *dep_version = lua_tostring(L, -1);
lua_pop(L, 1);
- Pkg pkg = create_pkg(dep_url, "default");
+ Pkg pkg = create_pkg(dep_url);
pkg.ver = strdup(dep_version);
const int top = lua_gettop(L);
char cwd[PATH_MAX];
@@ -130,126 +130,136 @@ void install_dependencies(lua_State *L) {
}
}
-bool repo_build(const char *repository) {
- lua_getglobal(L, "repositories");
- if (!config_loaded || !lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%slua variable 'repositories' is not a table.\n",
- print_warning
- );
- lua_pop(L, 1);
- return false;
- }
- lua_getfield(L, -1, repository);
+bool target_loop_build(lua_State *L, const char* lua_file, const char *target) {
+ lua_getfield(L, -1, target);
if (!lua_istable(L, -1)) {
if (is_verbose) printf(
- "%s'repositories.%s' is not a table.\n",
- print_warning, repository
+ "%s %s: 'targets.%s' is not a table.\n",
+ print_warning, lua_file, target
);
- lua_pop(L, 2);
+ lua_pop(L, 1);
return false;
}
-
lua_getfield(L, -1, "dependencies");
- if (!lua_istable(L, -1)) {
- if (is_verbose) printf(
- "%s'repositories.%s.dependencies' is not a table.\n",
- print_warning, repository
- );
- } else {
+ if (lua_istable(L, -1)) {
lua_pushnil(L);
install_dependencies(L);
}
lua_pop(L, 1);
-
lua_getfield(L, -1, "build");
if (!lua_isfunction(L, -1)) {
if (is_verbose) printf(
- "%s'repositories.%s.build' is not a function: %s\n",
- print_warning, repository, lua_tostring(L, -1)
+ "%s %s: 'targets.%s.build' is not a function.\n",
+ print_warning, lua_file, target
);
lua_pop(L, 3);
return false;
}
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
printf(
- "%s'repositories.%s.build' failed: %s\n",
- print_warning, repository, lua_tostring(L, -1)
+ "%s %s: 'targets.%s.build' failed: %s\n",
+ print_error, lua_file, target, lua_tostring(L, -1)
);
lua_pop(L, 3);
return false;
}
-
lua_pop(L, 2);
return true;
}
-bool repo_install(const char *repository) {
- lua_getglobal(L, "repositories");
- if (!config_loaded || !lua_istable(L, -1)) {
- if (is_verbose) printf("%slua variable 'repositories' is not a table.\n", print_warning);
- lua_pop(L, 1);
- return false;
- }
- lua_getfield(L, -1, repository);
+bool target_loop_install(lua_State *L, const char* lua_file, const char *target) {
+ lua_getfield(L, -1, target);
if (!lua_istable(L, -1)) {
- if (is_verbose) printf("%s'repositories.%s' is not a table.\n", print_warning, repository);
- lua_pop(L, 2);
+ if (is_verbose) printf(
+ "%s %s: 'targets.%s' is not a table.\n",
+ print_warning, lua_file, target
+ );
+ lua_pop(L, 1);
return false;
}
-
lua_getfield(L, -1, "pre_install");
if (!lua_isfunction(L, -1)) {
if (is_verbose) printf(
- "%s'repositories.%s.pre_install' is not a function.\n",
- print_warning, repository
+ "%s %s: 'targets.%s.pre_install' is not a function.\n",
+ print_warning, lua_file, target
);
} else if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
if (is_verbose) printf(
- "%s'repositories.%s.pre_install' failed: %s\n",
- print_warning, repository, lua_tostring(L, -1)
+ "%s %s: 'targets.%s.pre_install' failed: %s\n",
+ print_warning, lua_file, target, lua_tostring(L, -1)
);
}
lua_pop(L, 1);
-
lua_getfield(L, -1, "install");
if (!lua_isfunction(L, -1)) {
if (is_verbose) printf(
- "%s'repositories.%s.install' is not a function.\n",
- print_warning, repository
+ "%s %s: 'targets.%s.install' is not a function.\n",
+ print_warning, lua_file, target
);
+ lua_pop(L, 1);
return false;
}
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
if (is_verbose) printf(
- "%s'repositories.%s.install' failed: %s\n",
- print_warning, repository, lua_tostring(L, -1)
+ "%s %s: 'targets.%s.install' failed: %s\n",
+ print_warning, lua_file, target, lua_tostring(L, -1)
);
+ lua_pop(L, 1);
+ return false;
}
lua_pop(L, 1);
-
lua_getfield(L, -1, "post_install");
if (!lua_isfunction(L, -1)) {
if (is_verbose) printf(
- "%s'repositories.%s.post_install' is not a function.\n",
- print_warning, repository
+ "%s %s: 'targets.%s.post_install' is not a function.\n",
+ print_warning, lua_file, target
);
} else if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
if (is_verbose) printf(
- "%s'repositories.%s.post_install' failed: %s\n",
- print_warning, repository, lua_tostring(L, -1)
+ "%s %s: 'targets.%s.post_install' failed: %s\n",
+ print_warning, lua_file, target, lua_tostring(L, -1)
);
}
+ lua_pop(L, 1);
+ return true;
+}
- lua_pop(L, 2);
+bool target_loop_uninstall(lua_State *L, const char *lua_file, const char *target) {
+ lua_getfield(L, -1, target);
+ if (!lua_istable(L, -1)) {
+ if (is_verbose) printf(
+ "%s %s: 'targets.%s' is not a table.\n",
+ print_warning, lua_file, target
+ );
+ lua_pop(L, 1);
+ return false;
+ }
+ lua_getfield(L, -1, "uninstall");
+ if (!lua_isfunction(L, -1)) {
+ if (is_verbose) printf(
+ "%s %s: 'targets.%s.uninstall' is not a function.\n",
+ print_warning, lua_file, target
+ );
+ lua_pop(L, 1);
+ return false;
+ }
+ if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
+ if (is_verbose) printf(
+ "%s %s: 'targets.%s.uninstall' failed: %s\n",
+ print_warning, lua_file, target, lua_tostring(L, -1)
+ );
+ lua_pop(L, 1);
+ return false;
+ }
+ lua_pop(L, 1);
return true;
}
-bool repo_uninstall(const char *repository) {
+bool repo_build(const char *repository, const char *target) {
lua_getglobal(L, "repositories");
if (!config_loaded || !lua_istable(L, -1)) {
if (is_verbose) printf(
- "%slua variable 'repositories' is not a table.\n",
+ "%s init.lua: 'repositories' is not a table.\n",
print_warning
);
lua_pop(L, 1);
@@ -258,32 +268,102 @@ bool repo_uninstall(const char *repository) {
lua_getfield(L, -1, repository);
if (!lua_istable(L, -1)) {
if (is_verbose) printf(
- "%s'repositories.%s' is not a table.\n",
+ "%s init.lua: 'repositories.%s' is not a table.\n",
print_warning, repository
);
lua_pop(L, 2);
return false;
}
- lua_getfield(L, -1, "uninstall");
- if (!lua_isfunction(L, -1)) {
+ lua_getfield(L, -1, "dependencies");
+ if (!lua_istable(L, -1)) {
if (is_verbose) printf(
- "%s'repositories.%s.uninstall' is not a function.\n",
+ "%s init.lua: 'repositories.%s.dependencies' is not a table.\n",
+ print_warning, repository
+ );
+ } else {
+ lua_pushnil(L);
+ install_dependencies(L);
+ }
+ lua_pop(L, 1);
+
+ lua_getfield(L, -1, "targets");
+ if (!lua_istable(L, -1)) {
+ if (is_verbose) printf(
+ "%s init.lua: 'repositories.%s.targets' is not a table.\n",
print_warning, repository
);
return false;
}
- if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
+ bool target_loop_success = target_loop_build(L, "init.lua", target);
+ lua_pop(L, 3);
+ return target_loop_success;
+}
+
+bool repo_install(const char *repository, const char* target) {
+ lua_getglobal(L, "repositories");
+ if (!config_loaded || !lua_istable(L, -1)) {
if (is_verbose) printf(
- "%s'repositories.%s.uninstall' failed: %s\n",
- print_warning, repository, lua_tostring(L, -1)
+ "%s init.lua: 'repositories' is not a table.\n",
+ print_warning
);
+ lua_pop(L, 1);
return false;
}
- lua_pop(L, 1);
+ lua_getfield(L, -1, repository);
+ if (!lua_istable(L, -1)) {
+ if (is_verbose) printf(
+ "%s init.lua: 'repositories.%s' is not a table.\n",
+ print_warning, repository
+ );
+ lua_pop(L, 2);
+ return false;
+ }
+
+ lua_getfield(L, -1, "targets");
+ if (!lua_istable(L, -1)) {
+ if (is_verbose) printf(
+ "%s init.lua: 'repositories.%s.targets' is not a table.\n",
+ print_warning, repository
+ );
+ return false;
+ }
+ bool target_loop_success = target_loop_install(L, "init.lua", target);
+ lua_pop(L, 3);
+ return target_loop_success;
+}
+bool repo_uninstall(const char *repository, const char *target) {
+ lua_getglobal(L, "repositories");
+ if (!config_loaded || !lua_istable(L, -1)) {
+ if (is_verbose) printf(
+ "%s init.lua: 'repositories' is not a table.\n",
+ print_warning
+ );
+ lua_pop(L, 1);
+ return false;
+ }
+ lua_getfield(L, -1, repository);
+ if (!lua_istable(L, -1)) {
+ if (is_verbose) printf(
+ "%s init.lua: 'repositories.%s' is not a table.\n",
+ print_warning, repository
+ );
+ lua_pop(L, 2);
+ return false;
+ }
+
+ lua_getfield(L, -1, "targets");
+ if (!lua_istable(L, -1)) {
+ if (is_verbose) printf(
+ "%s init.lua: 'repositories.%s.targets' is not a table.\n",
+ print_warning, repository
+ );
+ return false;
+ }
+ bool target_loop_success = target_loop_uninstall(L, "init.lua", target);
lua_pop(L, 2);
- return true;
+ return target_loop_success;
}
bool bldit(const char *target) {
@@ -291,24 +371,24 @@ bool bldit(const char *target) {
luaL_openlibs(B);
if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) {
- if (is_verbose) printf("%scannot 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("%sbldit variable 'bldit_version' is not a string.\n", print_warning);
+ if (is_verbose) printf("%s bldit.lua: 'bldit_version' is not a string.\n", print_warning);
}
lua_getglobal(B, "package_version");
if (!lua_isstring(B, -1)) {
- if (is_verbose) printf("%sbldit variable 'package_version' is not a string.\n", print_warning);
+ if (is_verbose) printf("%s bldit.lua: 'package_version' is not a string.\n", print_warning);
}
- lua_getglobal(B, "global_dependencies");
+ lua_getglobal(B, "dependencies");
if (!lua_istable(B, -1)) {
- if (is_verbose) printf("%sbldit variable 'global_dependencies' is not a table.\n", print_warning);
+ if (is_verbose) printf("%s bldit.lua: 'dependencies' is not a table.\n", print_warning);
} else {
lua_pushnil(B);
install_dependencies(B);
@@ -317,52 +397,15 @@ bool bldit(const char *target) {
lua_getglobal(B, "targets");
if (!lua_istable(B, -1)) {
- if (is_verbose) printf("%sbldit variable 'targets' is not a table.\n", print_warning);
- lua_close(B);
- return false;
- }
-
- lua_getfield(B, -1, target);
- if (!lua_istable(B, -1)) {
- if (is_verbose) printf("%sbldit variable 'targets.%s' is not a table.\n", print_warning, target);
- lua_pop(B, 2);
- lua_close(B);
- return false;
- }
-
- lua_getfield(B, -1, "dependencies");
- if (!lua_istable(B, -1)) {
- if (is_verbose) printf("%sbldit variable 'targets.%s.dependencies' is not a table.\n", target, print_warning);
- } else {
- lua_pushnil(B);
- install_dependencies(B);
- }
- lua_pop(B, 1);
-
- lua_getfield(B, -1, "build");
- if (!lua_isfunction(B, -1)) {
- if (is_verbose) printf(
- "%sbldit variable 'targets.%s.build' is not a function.\n",
- print_warning, target
- );
- lua_pop(B, 3);
- lua_close(B);
- return false;
- }
- if (lua_pcall(B, 0, 0, 0) != LUA_OK) {
- printf(
- "%s'targets.%s.build' failed: %s\n",
- print_error, target, lua_tostring(B, -1)
- );
- lua_pop(B, 1);
- lua_pop(B, 2);
+ if (is_verbose) printf("%s bldit.lua: 'targets' is not a table.\n", print_warning);
lua_close(B);
return false;
}
+ bool target_loop_success = target_loop_build(B, "bldit.lua", target);
lua_pop(B, 2);
lua_close(B);
- return true;
+ return target_loop_success;
}
bool bldit_install(const char *target) {
@@ -371,7 +414,7 @@ bool bldit_install(const char *target) {
if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) {
if (is_verbose) printf(
- "%scannot run bldit script: %s\n",
+ "%s cannot run bldit script: %s\n",
print_warning, lua_tostring(B, -1)
);
lua_close(B);
@@ -381,7 +424,7 @@ bool bldit_install(const char *target) {
lua_getglobal(B, "targets");
if (!lua_istable(B, -1)) {
if (is_verbose) printf(
- "%sbldit variable 'targets' is not a table.\n",
+ "%s bldit.lua: 'targets' is not a table.\n",
print_warning
);
lua_pop(B, 1);
@@ -389,64 +432,10 @@ bool bldit_install(const char *target) {
return false;
}
- lua_getfield(B, -1, target);
- if (!lua_istable(B, -1)) {
- if (is_verbose) printf(
- "%sbldit variable 'targets.%s' is not a table.\n",
- print_warning, target
- );
- lua_pop(B, 2);
- lua_close(B);
- return false;
- }
-
- lua_getfield(B, -1, "pre_install");
- if (!lua_isfunction(B, -1)) {
- if (is_verbose) printf(
- "%s'targets.%s.pre_install' is not a function.\n",
- print_warning, target
- );
- }
- if (lua_pcall(B, 0, 0, 0) != LUA_OK) {
- if (is_verbose) printf(
- "%s'targets.%s.pre_install' failed: %s\n",
- print_warning, target, lua_tostring(B, -1)
- );
- }
-
- lua_getfield(B, -1, "install");
- if (!lua_isfunction(B, -1)) {
- if (is_verbose) printf(
- "%sbldit variable 'targets.%s.install' is not a function.\n",
- print_warning, target
- );
- } else {
- return false;
- }
- if (lua_pcall(B, 0, 0, 0) != LUA_OK) {
- if (is_verbose) printf(
- "%s'targets.%s.install' failed: %s\n",
- print_warning, target, lua_tostring(B, -1)
- );
- }
-
- lua_getfield(B, -1, "post_install");
- if (!lua_isfunction(B, -1)) {
- if (is_verbose) printf(
- "%sbldit variable 'targets.%s.post_install' is not a function.\n",
- print_warning, target
- );
- }
- if (lua_pcall(B, 0, 0, 0) != LUA_OK) {
- if (is_verbose) printf(
- "%s'targets.%s.post_install' failed: %s\n",
- print_warning, target, lua_tostring(B, -1)
- );
- }
-
- lua_pop(B, 2);
+ bool target_loop_success = target_loop_install(B, "bldit.lua", target);
+ lua_pop(B, 1);
lua_close(B);
- return true;
+ return target_loop_success;
}
bool bldit_uninstall(const char *target) {
@@ -455,7 +444,7 @@ bool bldit_uninstall(const char *target) {
if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) {
if (is_verbose) printf(
- "%scannot run bldit script: %s\n",
+ "%s cannot run bldit script: %s\n",
print_warning, lua_tostring(B, -1)
);
lua_close(B);
@@ -465,7 +454,7 @@ bool bldit_uninstall(const char *target) {
lua_getglobal(B, "targets");
if (!lua_istable(B, -1)) {
if (is_verbose) printf(
- "%sbldit variable 'targets' is not a table.\n",
+ "%s bldit.lua: 'targets' is not a table.\n",
print_warning
);
lua_close(B);
@@ -475,7 +464,7 @@ bool bldit_uninstall(const char *target) {
lua_getfield(B, -1, target);
if (!lua_istable(B, -1)) {
if (is_verbose) printf(
- "%sbldit variable 'targets.%s' is not a table.\n",
+ "%s bldit.lua: 'targets.%s' is not a table.\n",
print_warning, target
);
lua_pop(B, 2);
@@ -483,23 +472,14 @@ bool bldit_uninstall(const char *target) {
return false;
}
- lua_getfield(B, -1, "uninstall");
- if (!lua_isfunction(B, -1)) {
- if (is_verbose) printf(
- "%sbldit variable 'targets.%s.uninstall' is not a function.\n",
- print_warning, target
- );
- return false;
- }
- if (lua_pcall(B, 0, 0, 0) != LUA_OK) {
- if (is_verbose) printf(
- "%s'targets.%s.uninstall' failed: %s\n",
- print_warning, target, lua_tostring(B, -1)
- );
+ lua_getglobal(B, "targets");
+ if (!lua_istable(B, -1)) {
+ if (is_verbose) printf("%s bldit.lua: 'targets' is not a table.\n", print_warning);
+ lua_close(B);
return false;
}
-
- lua_pop(B, 2);
+ bool target_loop_success = target_loop_uninstall(B, "bldit.lua", target);
+ lua_pop(B, 1);
lua_close(B);
return true;
}
@@ -509,7 +489,7 @@ void cache_repos() {
lua_getglobal(L, "repositories");
if (!config_loaded || !lua_istable(L, -1)) {
printf(
- "%slua variable 'repositories' is not a table.\n",
+ "%s init.lua: 'repositories' is not a table.\n",
print_error
);
lua_pop(L, 1);
@@ -519,7 +499,7 @@ void cache_repos() {
while (lua_next(L, -2) != 0) {
const char *repo_name = lua_tostring(L, -2);
if (!repo_name || !lua_istable(L, -1)) {
- printf("%slua variable 'repositories.%s' is not a table\n", print_error, repo_name);
+ printf("%s init.lua: 'repositories.%s' is not a table\n", print_error, repo_name);
lua_pop(L, 1);
continue;
}
@@ -547,7 +527,7 @@ void cache_build_systems() {
}
if (!lua_istable(L, -1)) {
- printf("%slua variable 'build_systems' is not a table.\n", print_error);
+ printf("%s init.lua: 'build_systems' is not a table.\n", print_error);
return;
}
@@ -555,7 +535,7 @@ void cache_build_systems() {
while (lua_next(L, -2) != 0) {
const char *key = lua_tostring(L, -2);
if (lua_isfunction(L, -1) == 0) {
- printf("%slua variable 'build_systems.%s' is not a function\n", print_error, key);
+ printf("%s init.lua: 'build_systems.%s' is not a function\n", print_error, key);
lua_pop(L, 1);
continue;
}
@@ -566,12 +546,13 @@ void cache_build_systems() {
lua_pop(L, 1);
}
-bool config_build(const char *path) {
+bool config_build(const char *path, const char *target) {
lua_getglobal(L, "build_systems");
if (!config_loaded || !lua_istable(L, -1)) {
lua_pop(L, 1);
return false;
}
+ bool target_loop_success = false;
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
const char *key = lua_tostring(L, -2);
@@ -585,30 +566,27 @@ bool config_build(const char *path) {
lua_pop(L, 1);
continue;
}
- lua_getfield(L, -1, "build");
- if (!lua_isfunction(L, -1)) {
- lua_pop(L, 1);
- continue;
- }
- if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
+ lua_getfield(L, -1, "targets");
+ if (!lua_istable(L, -1)) {
+ if (is_verbose) printf("%s init.lua: 'targets' is not a table.\n", print_warning);
lua_pop(L, 1);
continue;
}
+ target_loop_success = target_loop_build(L, "init.lua", target);
lua_pop(L, 1);
- lua_pop(L, 1);
- return true;
}
lua_pop(L, 1);
- return false;
+ return target_loop_success;
}
-bool config_install(const char *path) {
+bool config_install(const char *path, const char *target) {
lua_getglobal(L, "build_systems");
if (!config_loaded || !lua_istable(L, -1)) {
lua_pop(L, 1);
return false;
}
lua_pushnil(L);
+ bool target_loop_success = false;
while (lua_next(L, -2) != 0) {
const char *key = lua_tostring(L, -2);
if (!lua_istable(L, -1)) {
@@ -621,50 +599,30 @@ bool config_install(const char *path) {
lua_pop(L, 1);
continue;
}
- lua_getfield(L, -1, "pre_install");
- if (lua_isfunction(L, -1)) {
- if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
- if (is_verbose) printf(
- "%s'build_systems.%s.pre_install' is not available\n",
- print_warning, key
- );
- }
- } else { lua_pop(L, 1); }
-
- lua_getfield(L, -1, "install");
- if (lua_isfunction(L, -1)) {
- if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
- if (is_verbose) printf(
- "%s'build_systems.%s.install' is not available\n",
- print_warning, key
- );
- }
- } else { lua_pop(L, 1); }
-
- lua_getfield(L, -1, "post_install");
- if (!lua_isfunction(L, -1)) {
- if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
- if (is_verbose) printf(
- "%s'build_systems.%s.post_install' is not available\n",
- print_warning, key
- );
- }
- } else { lua_pop(L, 1); }
+ lua_getfield(L, -1, "targets");
+ if (!lua_istable(L, -1)) {
+ if (is_verbose) printf(
+ "%s init.lua: 'build_systems.%s.targets' is not a table.\n",
+ print_warning, key
+ );
+ lua_close(L);
+ return false;
+ }
+ target_loop_success = target_loop_install(L, "init.lua", target);
lua_pop(L, 1);
- lua_pop(L, 1);
- return true;
}
lua_pop(L, 1);
- return false;
+ return target_loop_success;
}
-bool config_uninstall(const char *path) {
+bool config_uninstall(const char *path, const char *target) {
lua_getglobal(L, "build_systems");
if (!config_loaded || !lua_istable(L, -1)) {
lua_pop(L, 1);
return false;
}
+ bool target_loop_success = false;
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
const char *key = lua_tostring(L, -2);
@@ -679,20 +637,18 @@ bool config_uninstall(const char *path) {
continue;
}
- lua_getfield(L, -1, "uninstall");
- if (!lua_isfunction(L, -1)) {
- lua_pop(L, 1);
- continue;
- }
- if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
- lua_pop(L, 1);
- continue;
+ lua_getfield(L, -1, "targets");
+ if (!lua_istable(L, -1)) {
+ if (is_verbose) printf(
+ "%s init.lua: 'build_systems.%s.targets' is not a table.\n",
+ print_warning, key
+ );
+ lua_close(L);
+ return false;
}
-
- lua_pop(L, 1);
+ target_loop_success = target_loop_uninstall(L, "init.lua", target);
lua_pop(L, 1);
- return true;
}
lua_pop(L, 1);
- return false;
+ return target_loop_success;
}
diff --git a/src/remove.c b/src/remove.c
deleted file mode 100644
index 1282d44..0000000
--- a/src/remove.c
+++ /dev/null
@@ -1,32 +0,0 @@
-#include <stdio.h>
-#include <dirent.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include "files.h"
-#include "vars.h"
-
-//void remove_pkg(Pkg pkg) {
-// char* src_code = pkg.src;
-// struct dirent* dirent_ptr;
-// DIR* dir_ptr;
-//
-// if ((dir_ptr = opendir(src_code)) == NULL) {
-// fprintf(stderr, "%scould not open %s\n", print_pkgit, src_code);
-// }
-//
-// while ((dirent_ptr = readdir(dir_ptr)) != NULL) {
-// struct stat stat_buf;
-// FILE* file_ptr = fopen(dirent_ptr->d_name, "r");
-// if (!file_ptr) { continue; }
-// if (strcmp(get_filename_ext(dirent_ptr->d_name), ".so") == 0) {
-// remove(strcat(map_get(&cached_install_directories, "lib"), strcat("/", dirent_ptr->d_name)));
-// } else if (!access(dirent_ptr->d_name, X_OK) && stat_buf.st_mode != S_IFDIR) {
-// remove(strcat(map_get(&cached_install_directories, "bin"), strcat("/", dirent_ptr->d_name)));
-// } else if (strcmp(get_filename_ext(dirent_ptr->d_name), ".h") == 0) {
-// remove(strcat(map_get(&cached_install_directories, "include"), strcat("/", dirent_ptr->d_name)));
-// }
-// }
-// }
-//}
diff --git a/src/remove_pkg.c b/src/remove_pkg.c
index 1dc39db..14e1f4a 100644
--- a/src/remove_pkg.c
+++ b/src/remove_pkg.c
@@ -9,8 +9,10 @@
#include "remove_pkg.h"
#include "vars.h"
-static int remove_installed(const char *src_path, const struct stat *sb,
- int typeflag, struct FTW *ftwbuf) {
+static int remove_installed(
+ const char *src_path, const struct stat *sb,
+ int typeflag, struct FTW *ftwbuf
+) {
(void)sb;
(void)ftwbuf;
@@ -60,28 +62,33 @@ static int remove_tree(const char *fpath, const struct stat *sb, int typeflag,
void remove_pkg(Pkg pkg) {
if (!file_exists(pkg.src)) {
- printf("%s%s is not installed!\n", print_pkgit, pkg.name);
+ printf("%s %s is not installed!\n", print_pkgit, pkg.name);
return;
}
chdir(pkg.src);
- if (repo_uninstall(pkg.name)) return;
- if (bldit_uninstall(pkg.target)) return;
- if (config_uninstall(pkg.src)) return;
+ bool uninstall_available = false;
+ if (!uninstall_available) if (repo_uninstall(pkg.name, pkg.target))
+ uninstall_available = true;
+ if (!uninstall_available) if (bldit_uninstall(pkg.target))
+ uninstall_available = true;
+ if (!uninstall_available) if (config_uninstall(pkg.src, pkg.target))
+ uninstall_available = true;
- printf("%sno uninstall function availible for package: %s\n",
- print_error, pkg.name);
- return;
+ if (!uninstall_available) printf(
+ "%s no uninstall function availible for package: %s\n",
+ print_error, pkg.name
+ );
- //nftw(pkg.src, remove_installed, 64, FTW_PHYS);
- //const char *last_slash = strrchr(pkg.src, '/');
- //char target[MAX_PATH_LEN];
- //if (last_slash && last_slash != pkg.src) {
- // size_t parent_len = last_slash - pkg.src;
- // snprintf(target, sizeof(target), "%.*s", (int)parent_len, pkg.src);
- //} else {
- // snprintf(target, sizeof(target), "%s", pkg.src);
- //}
- //nftw(target, remove_tree, 64, FTW_DEPTH | FTW_PHYS);
- //printf("%sremoved %s\n", print_pkgit, pkg.name);
+ nftw(pkg.src, remove_installed, 64, FTW_PHYS);
+ const char *last_slash = strrchr(pkg.src, '/');
+ char target[MAX_PATH_LEN];
+ if (last_slash && last_slash != pkg.src) {
+ size_t parent_len = last_slash - pkg.src;
+ snprintf(target, sizeof(target), "%.*s", (int)parent_len, pkg.src);
+ } else {
+ snprintf(target, sizeof(target), "%s", pkg.src);
+ }
+ nftw(pkg.src, remove_tree, 64, FTW_DEPTH | FTW_PHYS);
+ printf("%s removed %s\n", print_success, pkg.name);
} \ No newline at end of file
diff --git a/src/update_all.c b/src/update_all.c
index 2d941eb..521b1d1 100644
--- a/src/update_all.c
+++ b/src/update_all.c
@@ -20,13 +20,13 @@ void update_all() {
struct dirent* dirent_ptr;
DIR* dir_ptr;
if ((dir_ptr = opendir(get_install_dir("src"))) == NULL) {
- fprintf(stderr, "%scould not open %s\n", print_pkgit, get_install_dir("src"));
+ fprintf(stderr, "%s could not open %s\n", print_pkgit, get_install_dir("src"));
}
while ((dirent_ptr = readdir(dir_ptr)) != NULL) {
if (strcmp(dirent_ptr->d_name, "..") == 0 || strcmp(dirent_ptr->d_name, ".") == 0) continue;
for (size_t i = 0; i < cached_repos_count; i++) {
if (!strcmp(dirent_ptr->d_name, cached_repos[i].source_key) == 0) continue;
- Pkg pkg = create_pkg(cached_repos[i].source_value, "default");
+ Pkg pkg = create_pkg(cached_repos[i].source_value);
update_pkg(pkg);
}
}
diff --git a/src/update_pkg.c b/src/update_pkg.c
index 093f25c..7511b54 100644
--- a/src/update_pkg.c
+++ b/src/update_pkg.c
@@ -7,9 +7,9 @@
void update_pkg(Pkg pkg) {
if (is_updated(pkg.src)) {
- printf("%s%s%s%s is already up to date.\n", print_skipped, green, pkg.name, color_reset);
+ printf("%s %s%s%s is already up to date.\n", print_skipped, green, pkg.name, color_reset);
return;
}
- printf("%sUpdating package: %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
+ printf("%s Updating package: %s%s%s\n", print_pkgit, green, pkg.name, color_reset);
install_pkg(pkg);
} \ No newline at end of file
diff --git a/src/vars.c b/src/vars.c
index 0aa7f78..a8199af 100644
--- a/src/vars.c
+++ b/src/vars.c
@@ -11,6 +11,7 @@
bool is_symlink_install = false;
bool is_verbose = true;
bool is_auto_installed = true;
+bool is_forced = false;
bool config_exists = false;
char home_dir[MAX_PATH_LEN] = {0};
@@ -48,7 +49,7 @@ const char* get_install_dir(const char *key) {
return "";
}
-const char *version = "0.1.3";
+const char *version = "1.0.0";
const char *red = "\e[0;31m";
const char *green = "\e[0;32m";
@@ -162,27 +163,27 @@ void init_vars() {
install_directories[4] = strdup(get_install_dir("src"));
static char print_pkgit_buf[256];
- snprintf(print_pkgit_buf, sizeof(print_pkgit_buf), "%s[%s%s%s] %s",
+ snprintf(print_pkgit_buf, sizeof(print_pkgit_buf), "%s[%s%s%s]%s",
bold_yellow, bold_magenta, "pkgit", bold_yellow, color_reset);
print_pkgit = print_pkgit_buf;
static char print_success_buf[256];
- snprintf(print_success_buf, sizeof(print_success_buf), "%s%s[SUCCESS] %s",
+ snprintf(print_success_buf, sizeof(print_success_buf), "%s%s [SUCCESS]%s",
print_pkgit, green, color_reset);
print_success = print_success_buf;
static char print_skipped_buf[256];
- snprintf(print_skipped_buf, sizeof(print_skipped_buf), "%s%s[SKIP] %s",
+ snprintf(print_skipped_buf, sizeof(print_skipped_buf), "%s%s [SKIP]%s",
print_pkgit, blue, color_reset);
print_skipped = print_skipped_buf;
static char print_warning_buf[256];
- snprintf(print_warning_buf, sizeof(print_warning_buf), "%s%s[WARN] %s",
+ snprintf(print_warning_buf, sizeof(print_warning_buf), "%s%s [WARN]%s",
print_pkgit, yellow, color_reset);
print_warning = print_warning_buf;
static char print_error_buf[256];
- snprintf(print_error_buf, sizeof(print_error_buf), "%s%s[ERROR] %s",
+ snprintf(print_error_buf, sizeof(print_error_buf), "%s%s [ERROR]%s",
print_pkgit, red, color_reset);
print_error = print_error_buf;
}