aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/build.c64
-rw-r--r--src/fetch.c79
-rw-r--r--src/lua_globs.c9
-rw-r--r--src/lua_install.c21
-rw-r--r--src/main.c18
-rw-r--r--src/parse_args.c10
6 files changed, 141 insertions, 60 deletions
diff --git a/src/build.c b/src/build.c
index 86a0b29..1aafb36 100644
--- a/src/build.c
+++ b/src/build.c
@@ -43,24 +43,30 @@ bool target_build(lua_State *L, char* lua_file, str *target) {
}
bool repo_build(package_t *pkg) {
- lua_getglobal(L, "repositories");
- if (!lua_try_table(L, "init.lua", pkg->name.data)) {
- lua_pop(L, 2);
- return false;
- }
- if (lua_try_table(L, "init.lua", "dependencies")) {
- lua_pushnil(L);
- install_dependencies(L);
- }
- lua_pop(L, 1);
- if (!lua_try_table(L, "init.lua", "targets")) return false;
- bool target_success = target_build(L, "init.lua", &pkg->target);
- lua_pop(L, 3);
- return target_success;
+ lua_getglobal(L, "repositories");
+ if (!lua_try_table(L, "init.lua", pkg->name.data)) {
+ lua_pop(L, 2);
+ return false;
+ }
+ if (lua_try_table(L, "init.lua", "dependencies")) {
+ lua_pushnil(L);
+ 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);
+ lua_pop(L, 3);
+ return target_success;
}
bool bldit(package_t *pkg) {
init_bldit_state();
+ if (!bldit_loaded) return false;
lua_getglobal(B, "dependencies");
if (!lua_istable(B, -1)) {
bldit_isnt_type("dependencies", "table");
@@ -72,6 +78,7 @@ bool bldit(package_t *pkg) {
lua_getglobal(B, "targets");
if (!lua_istable(B, -1)) {
bldit_isnt_type("targets", "table");
+ lua_pop(B, 3);
lua_close(B);
return false;
}
@@ -83,11 +90,19 @@ bool bldit(package_t *pkg) {
bool config_build(package_t *pkg) {
lua_getglobal(L, "build_systems");
+ if (!lua_istable(L, -1)) {
+ lua_isnt_type("build_systems", "table");
+ lua_pop(L, 1);
+ return false;
+ }
bool target_success = false;
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)) continue;
+ if (!lua_try_table(L, "init.lua", key.data)) {
+ lua_pop(L, 1);
+ 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);
@@ -97,7 +112,7 @@ bool config_build(package_t *pkg) {
str_free(&key);
if (!lua_try_table(L, "init.lua", "targets")) continue;
target_success = target_build(L, "init.lua", &pkg->target);
- if (target_success) return true;
+ if (target_success) break;
lua_pop(L, 1);
}
lua_pop(L, 1);
@@ -107,7 +122,8 @@ bool config_build(package_t *pkg) {
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));
+ 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; }
@@ -119,12 +135,12 @@ bool build_loop(package_t *pkg) {
return false;
}
-void build(package_t *pkg) {
- char cwd[MAX_PATH_LEN];
- getcwd(cwd, MAX_PATH_LEN);
- if (str_equal_cstr(&pkg->src, cwd) && !pkg->is_local) chdir(pkg->src.data);
+bool build(package_t *pkg) {
+ char cwd[MAX_PATH_LEN];
+ getcwd(cwd, MAX_PATH_LEN);
+ if (str_equal_cstr(&pkg->src, cwd) && !pkg->is_local) chdir(pkg->src.data);
- //if (lua_build(pkg->name, pkg->target, pkg->is_local ? cwd : pkg->src)) return;
- log_error("no usable build system was found for %.*s", str_fmt(&pkg->name));
- exit(EXIT_FAILURE);
+ if (build_loop(pkg)) return true;
+ log_error("no usable build system was found for %.*s", str_fmt(&pkg->name));
+ return false;
}
diff --git a/src/fetch.c b/src/fetch.c
index c6cefe5..87c632d 100644
--- a/src/fetch.c
+++ b/src/fetch.c
@@ -18,9 +18,86 @@
*/
-#include <git2.h>
+//#include <git2.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/wait.h>
+#include <unistd.h>
#include "fetch.h"
+#include "globs.h"
+#include "log.h"
+
+//bool fetch(package_t *pkg) {
+// git_libgit2_init();
+// git_clone_options clone_opts = GIT_CLONE_OPTIONS_INIT;
+// clone_opts.checkout_branch = pkg->version.data;
+// clone_opts.checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE;
+// git_repository *repo = NULL;
+// int error = git_clone(&repo, pkg->url.data, pkg->src.data, NULL);
+// if (error < 0) {
+// const git_error *e = git_error_last();
+// fprintf(stderr, "clone failed: %s\n",
+// e && e->message ? e->message : "unknown error");
+// git_libgit2_shutdown();
+// return false;
+// }
+// git_repository_free(repo);
+// git_libgit2_shutdown();
+// return true;
+//}
+
bool fetch(package_t *pkg) {
+ if (pkg->url.data == NULL || pkg->src.data == NULL) {
+ log_warn("invalid pkg: url or src is NULL");
+ return false;
+ }
+
+ pid_t pid = fork();
+ if (pid < 0) {
+ log_error("fork failed");
+ return false;
+ }
+
+ if (pid == 0) {
+ if (!flags.verbose) {
+ int nullfd = open("/dev/null", O_WRONLY);
+ if (nullfd >= 0) {
+ dup2(nullfd, STDOUT_FILENO);
+ dup2(nullfd, STDERR_FILENO);
+ close(nullfd);
+ }
+ }
+
+ const char *argv[12];
+ int i = 0;
+
+ argv[i++] = "git";
+ argv[i++] = "-c";
+ argv[i++] = "advice.detachedHead=false";
+ argv[i++] = "clone";
+
+ if (pkg->version.data != NULL && !str_equal_cstr(&pkg->version, "HEAD")) {
+ argv[i++] = "--branch";
+ argv[i++] = pkg->version.data;
+ }
+
+ argv[i++] = "--recursive";
+ argv[i++] = pkg->url.data;
+ argv[i++] = pkg->src.data;
+ argv[i] = NULL;
+
+ execvp("git", (char *const *)argv);
+ _exit(127);
+ }
+
+ int status;
+ waitpid(pid, &status, 0);
+
+ bool result = (WEXITSTATUS(status) == 0);
+ if (!result) { log_warn("git clone failed"); }
+
+ return result;
}
diff --git a/src/lua_globs.c b/src/lua_globs.c
index 815a75e..ce5a59b 100644
--- a/src/lua_globs.c
+++ b/src/lua_globs.c
@@ -158,13 +158,14 @@ 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)) {
- if (strcmp(lua_file, "bldit.lua"))
+ val = false;
+ lua_pop(L, 1);
+ if (!strcmp(lua_file, "bldit.lua"))
bldit_isnt_type(tname, "table");
else
lua_isnt_type(tname, "table");
- return false;
}
- lua_pop(L, 1);
- return true;
+ return val;
}
diff --git a/src/lua_install.c b/src/lua_install.c
index 1c240d4..e9fc2b4 100644
--- a/src/lua_install.c
+++ b/src/lua_install.c
@@ -25,6 +25,7 @@
#include "add_repo.h"
#include "build.h"
+#include "fetch.h"
#include "files.h"
#include "globs.h"
#include "log.h"
@@ -125,10 +126,10 @@ bool config_install(package_t *pkg) {
void pkg_install(package_t *pkg) {
if (is_directory(pkg->src.data)) {
if (!flags.force) {
- log_info("%.*s is already installed.", &pkg->name);
+ log_info("%.*s is already installed.", str_fmt(&pkg->name));
return;
} else {
- log_warn("%.*s is already installed.", &pkg->name);
+ log_warn("%.*s is already installed.", str_fmt(&pkg->name));
}
}
char cwd[MAX_PATH_LEN];
@@ -138,14 +139,14 @@ void pkg_install(package_t *pkg) {
//if (pkg->is_local) {
// cpdir(cwd, pkg->src);
//} else {
- log_info("fetching " GREEN "%.*s" COLOR_RESET , str_fmt(&pkg->name));
- fetch_src(pkg);
- log_info("fetched " GREEN "%.*s" COLOR_RESET , str_fmt(&pkg->name));
+ log_pkgit("fetching " GREEN "%.*s" COLOR_RESET , str_fmt(&pkg->name));
+ if (!fetch(pkg)) return;
+ log_pkgit("fetched " GREEN "%.*s" COLOR_RESET , str_fmt(&pkg->name));
//}
- log_info("building " GREEN "%.*s" COLOR_RESET , str_fmt(&pkg->name));
- build(pkg);
- log_info("built " GREEN "%.*s" COLOR_RESET , str_fmt(&pkg->name));
+ log_pkgit("building " GREEN "%.*s" COLOR_RESET , str_fmt(&pkg->name));
+ if (!build(pkg)) return;
+ log_pkgit("built " GREEN "%.*s" COLOR_RESET , str_fmt(&pkg->name));
bool install_success = false;
if (!install_success && repo_install(pkg))
@@ -168,10 +169,10 @@ void pkg_install(package_t *pkg) {
//}
if (!repo_exists) {
- log_info("adding " GREEN "%.*s" COLOR_RESET , &pkg->name);
+ log_pkgit("adding " GREEN "%.*s" COLOR_RESET , &pkg->name);
if (pkg->url.len > 0) {
add_repo(pkg);
- log_info("added " GREEN "%.*s" COLOR_RESET , &pkg->name);
+ log_pkgit("added " GREEN "%.*s" COLOR_RESET , &pkg->name);
}
} else {
log_info("repo already exists, done");
diff --git a/src/main.c b/src/main.c
index 441332f..341b7ad 100644
--- a/src/main.c
+++ b/src/main.c
@@ -20,28 +20,10 @@
#include "parse_args.h"
#include "globs.h"
-//#include "pkg.h"
-//#include "str.h"
-//#include "debug.h"
int main(int argc, char **argv) {
init_vars();
parse_args(argc, argv);
-
- //package_t pkg = pkg_create(mstrslc(argv[1]));
- //printf("NAME:\t");
- //str_println(&pkg.name);
- //printf("URL:\t");
- //str_println(&pkg.url);
- //printf("VER:\t");
- //str_println(&pkg.version);
- //printf("TRG:\t");
- //str_println(&pkg.target);
- //printf("SRC:\t");
- //str_println(&pkg.src);
- //pkg_free(&pkg);
-
- //debug_print_inst_dirs();
free_vars();
return 0;
}
diff --git a/src/parse_args.c b/src/parse_args.c
index 785673d..d4719c7 100644
--- a/src/parse_args.c
+++ b/src/parse_args.c
@@ -34,6 +34,7 @@
#include "pkg.h"
// #include "pkg_search.h"
// #include "pkg_install.h"
+#include "pkgit_lua.h"
// #include "pkg_list.h"
// #include "pkg_remove.h"
// #include "pkgit_globals.h"
@@ -79,9 +80,10 @@ void cmd_install(int argc, char **argv, int i) {
if (argv[j][0] == '-')
continue;
printf("install pkg %s\n", argv[j]);
- // str_slc arg = mstrslc(argv[j]);
- // package_t pkg = pkg_create(arg);
- // pkg_install(pkg);
+ str_slc arg = mstrslc(argv[j]);
+ package_t pkg = pkg_create(arg);
+ pkg_install(&pkg);
+ pkg_free(&pkg);
}
} else {
NOT_ENOUGH_ARGS(argv[i], "url/pkg");
@@ -148,6 +150,7 @@ void parse_flags(int argc, char **argv) {
flags_cmd(argc, argv, i);
}
}
+ return;
}
void parse_cmds(int argc, char **argv) {
@@ -176,4 +179,5 @@ void parse_args(int argc, char **argv) {
}
parse_flags(argc, argv);
parse_cmds(argc, argv);
+ return;
}