aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/.clangd4
-rw-r--r--src/add_repo.cc2
-rw-r--r--src/build.cc21
-rw-r--r--src/cla_parse.cc116
-rw-r--r--src/create_pkg.cc29
-rw-r--r--src/fetch_git.cc15
-rw-r--r--src/fetch_src.cc23
-rw-r--r--src/install_pkg.cc8
-rw-r--r--src/list_pkgs.cc3
-rw-r--r--src/lua_build.cc60
-rw-r--r--src/lua_state.cc239
-rw-r--r--src/main.cc14
-rw-r--r--src/setup_dirs.cc11
-rw-r--r--src/setup_pkgit.cc2
-rw-r--r--src/setup_repo.cc29
-rw-r--r--src/update_all.cc5
-rw-r--r--src/vars.cc5
17 files changed, 367 insertions, 219 deletions
diff --git a/src/.clangd b/src/.clangd
new file mode 100644
index 0000000..5022e8f
--- /dev/null
+++ b/src/.clangd
@@ -0,0 +1,4 @@
+CompileFlags:
+ Add: [-I/usr/include/luajit-2.1, -I../include]
+---
+UseTab: Always
diff --git a/src/add_repo.cc b/src/add_repo.cc
index c302b94..a0ab07d 100644
--- a/src/add_repo.cc
+++ b/src/add_repo.cc
@@ -22,7 +22,7 @@ void add_repo(std::string repo, std::string repo_name) {
std::ofstream wfile;
wfile.open(repo_file);
- wfile << previous_repos << "repos[\"" << repo_name << "\"] = \"" << repo << "\"" << std::endl;
+ wfile << previous_repos << "repos." << repo_name << ".url = \"" << repo << "\"" << std::endl;
wfile.close();
std::cout << print_pkgit << green << "Added " << repo_name << color_reset << std::endl;
diff --git a/src/build.cc b/src/build.cc
index 88b40c7..a78faf9 100644
--- a/src/build.cc
+++ b/src/build.cc
@@ -5,24 +5,11 @@
#include "lua_build.hh"
#include "vars.hh"
-void build(std::filesystem::path build_dir) {
- if (build_dir != std::filesystem::current_path().string()) {
- std::filesystem::current_path(build_dir);
+void build(Pkg pkg) {
+ if (pkg.src != std::filesystem::current_path().string()) {
+ std::filesystem::current_path(pkg.src);
}
-
- bool bldit_found = false;
- bool build_found = false;
-
- for (auto const &dir_entry : std::filesystem::directory_iterator(std::filesystem::current_path().string())) {
- if (dir_entry.path().filename() == "bldit") {
- bldit_found = true;
- break;
- }
- }
-
- if (bldit_found) {
- system("./bldit");
- } else if (lua_build(build_dir.c_str())) {
+ if (lua_build(pkg.name.c_str(), pkg.target, pkg.src.c_str())) {
return;
} else {
std::cout << print_error << "no usable build system was found\n";
diff --git a/src/cla_parse.cc b/src/cla_parse.cc
index 42d2f65..24b572f 100644
--- a/src/cla_parse.cc
+++ b/src/cla_parse.cc
@@ -1,7 +1,7 @@
-#include <string>
#include <cstring>
#include <filesystem>
#include <iostream>
+#include <string>
#include "cla_parse.hh"
@@ -13,85 +13,71 @@
#include "list_pkgs.hh"
#include "name_from_url.hh"
#include "remove_pkg.hh"
-#include "setup_pkgit.hh"
#include "update_all.hh"
#include "vars.hh"
-void cla_parse(int argc, char** argv) {
+#define COMMAND(large, small, code) \
+ if (strcmp(argv[i], large) == 0 || strcmp(argv[i], small) == 0) \
+ code
+#define NOT_ENOUGH_ARGS(arg, next) \
+ std::cout << print_error << "Not enough arguments! Try: `pkgit " << arg \
+ << " [" << next << "]`"
+
+void cla_parse(int argc, char **argv) {
Pkg pkg;
- if (!argv[1]) { help(); return; }
+ if (!argv[1]) {
+ help();
+ return;
+ }
for (int i = 1; i < argc; i++) {
- if (strcmp(argv[i], "--link") == 0 || strcmp(argv[i], "-l") == 0) {
- is_symlink_install = true;
- }
-
- if (strcmp(argv[i], "add") == 0 || strcmp(argv[i], "a") == 0) {
- for (int j = i+1; j < argc; j++) {
- if (argv[j]) {
- add_repo(argv[j], name_from_url(argv[j]));
- return;
- } else {
- std::cout << print_error << "Not enough arguments! Try: `pkgit add [url]`";
- return;
- }
+ COMMAND("--large", "-l", { is_symlink_install = true; });
+ COMMAND("add", "a", {
+ if (argv[i + 1]) {
+ add_repo(argv[i + 1], name_from_url(argv[i + 1]));
+ } else {
+ NOT_ENOUGH_ARGS(argv[i], "url");
}
-
- } else if (strcmp(argv[i], "build") == 0 || strcmp(argv[i], "b") == 0) {
- for (int j = i+1; j < argc; j++) {
- if (argv[j]) {
- build(argv[j]);
- return;
+ });
+ COMMAND("build", "b", {
+ if (argv[i + 1]) {
+ if (argv[i + 2]) {
+ pkg = create_pkg(argv[i + 1], argv[i + 2]);
+ build(pkg);
} else {
- build(std::filesystem::current_path().string().c_str());
- return;
+ pkg = create_pkg(argv[i + 1], "default");
+ build(pkg);
}
+ } else {
+ pkg = create_pkg(".", "default");
+ build(pkg);
}
-
- } else if (strcmp(argv[i], "install") == 0 || strcmp(argv[i], "i") == 0) {
- for (int j = i+1; j < argc; j++) {
- pkg = create_pkg(argv[j]);
- if (argv[j]) {
+ });
+ COMMAND("install", "i", {
+ if (argv[i + 1]) {
+ if (argv[i + 2]) {
+ pkg = create_pkg(argv[i + 1], argv[i + 2]);
install_pkg(pkg);
- return;
} else {
- std::cout << print_error << "Not enough arguments! Try: `pkgit install [url/pkg]`";
- return;
+ pkg = create_pkg(argv[i + 1], "default");
+ install_pkg(pkg);
}
+ } else {
+ NOT_ENOUGH_ARGS(argv[i], "url/pkg");
}
-
- } else if (strcmp(argv[i], "remove") == 0 || strcmp(argv[i], "r") == 0) {
- for (int j = i+1; j < argc; j++) {
- pkg = create_pkg(argv[j]);
- if (argv[j]) {
- remove_pkg(pkg);
- return;
- } else {
- std::cout << print_error << "Not enough arguments! Try: `pkgit remove [url/pkg]`";
- return;
- }
+ });
+ COMMAND("remove", "r", {
+ pkg = create_pkg(argv[i + 1]);
+ if (argv[i + 1]) {
+ remove_pkg(pkg);
+ } else {
+ NOT_ENOUGH_ARGS(argv[i], "url/pkg");
}
-
- } else if (strcmp(argv[i], "update") == 0 || strcmp(argv[i], "u") == 0) {
- update_all();
- return;
-
- } else if (strcmp(argv[i], "list") == 0 || strcmp(argv[i], "l") == 0) {
- list_pkgs();
- return;
-
- } else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-v") == 0) {
- std::cout << version << std::endl;
- return;
-
- } else if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
- help();
- return;
-
- } else {
- help();
- return;
- }
+ });
+ COMMAND("update", "u", { update_all(); });
+ COMMAND("list", "l", { list_pkgs(); });
+ COMMAND("--version", "-v", { std::cout << version << std::endl; });
+ COMMAND("--help", "-h", { help(); });
}
}
diff --git a/src/create_pkg.cc b/src/create_pkg.cc
index a6b78e9..1792d24 100644
--- a/src/create_pkg.cc
+++ b/src/create_pkg.cc
@@ -3,34 +3,47 @@
#include <filesystem>
#include "create_pkg.hh"
+#include "lua_state.hh"
#include "name_from_url.hh"
#include "vars.hh"
-Pkg create_pkg(std::string arg) {
+Pkg create_pkg(std::string arg, const char* target) {
Pkg pkg;
+ pkg.target = target;
+ pkg.ver = "HEAD";
bool is_in_repos = false;
+ bool is_local = false;
- for (auto repo : repos) {
+ init_lua_state();
+ cache_repos();
+ for (auto repo : cached_repos) {
if (arg == repo.first) { is_in_repos = true; }
}
if (arg.rfind("http", 0) == 0) {
pkg.url = arg;
pkg.name = name_from_url(arg);
- } else if (arg == ".") {
+ } else if (std::filesystem::exists(arg) || arg == ".") {
pkg.url = "";
- pkg.name = name_from_url(std::filesystem::current_path().string());
+ if (std::filesystem::exists(arg)) {
+ pkg.src = arg;
+ } else {
+ pkg.src = std::filesystem::current_path().string();
+ }
+ pkg.name = name_from_url(arg);
+ is_local = true;
} else if (is_in_repos) {
- pkg.url = repos[arg];
+ pkg.url = cached_repos[arg].source.value;
pkg.name = arg;
} else {
std::cout << print_error << "'" << arg << "'" << " is not a valid package" << std::endl;
exit(1);
}
- pkg.ver = "HEAD";
-
- pkg.src = install_directories["pkgblds"] + "/" + pkg.name + "/" + pkg.ver;
+ cache_install_directories();
+ if (!is_local) {
+ pkg.src = install_directories["src"] + "/" + pkg.name + "/" + pkg.ver;
+ }
return pkg;
}
diff --git a/src/fetch_git.cc b/src/fetch_git.cc
index c4fd3b2..dc5015b 100644
--- a/src/fetch_git.cc
+++ b/src/fetch_git.cc
@@ -1,19 +1,22 @@
#include <cstring>
+#include <iostream>
#include "fetch_git.hh"
#include "vars.hh"
int fetch_git(Pkg pkg) {
std::string clone_cmds[] = {
- "git -c advice.detachedHead=false clone " + pkg.url +
- " " + pkg.src.c_str(),
- "git -c advice.detachedHead=false clone --branch " + pkg.ver +
- " " + pkg.url + " " + pkg.src.c_str()
+ "git -c advice.detachedHead=false clone " + pkg.url + " " + pkg.src.c_str(),
+ "git -c advice.detachedHead=false clone --branch " + pkg.ver + " " + pkg.url + " " + pkg.src.c_str()
};
if (strcmp(pkg.ver.c_str(), "HEAD") == 0) {
- if (system(clone_cmds[0].c_str()) != 0) { system(clone_cmds[0].c_str()); }
+ if (system(clone_cmds[0].c_str()) != 0) {
+ std::cout << "clone failed" << std::endl;
+ }
} else {
- if (system(clone_cmds[2].c_str()) != 0) { system(clone_cmds[1].c_str()); }
+ if (system(clone_cmds[1].c_str()) != 0) {
+ std::cout << "clone failed" << std::endl;
+ }
}
return 0;
}
diff --git a/src/fetch_src.cc b/src/fetch_src.cc
index 0b79a94..626e798 100644
--- a/src/fetch_src.cc
+++ b/src/fetch_src.cc
@@ -1,10 +1,25 @@
#include <stdlib.h>
+#include <iostream>
#include "fetch_src.hh"
#include "fetch_git.hh"
void fetch_src(Pkg pkg) {
- if (std::filesystem::exists(pkg.src)) { std::filesystem::remove_all(pkg.src); }
-
- if (pkg.url == "") { std::filesystem::create_directories(pkg.src); return; }
- else if (fetch_git(pkg) == 0) { return; } else { exit(EXIT_FAILURE); }
+ std::cout << print_pkgit << "target source directory: " << pkg.src << std::endl;
+ if (std::filesystem::exists(pkg.src)) {
+ std::cout << print_pkgit << pkg.src << " already exists. deleting..." << std::endl;
+ std::filesystem::remove_all(pkg.src);
+ }
+ if (pkg.url == "") {
+ std::cout << print_pkgit << "creating directory " << pkg.src << "..." << std::endl;
+ std::filesystem::create_directories(pkg.src);
+ return;
+ }
+ else if (fetch_git(pkg) == 0) {
+ std::cout << print_pkgit << "cloned into " << pkg.src << "..." << std::endl;
+ return;
+ }
+ else {
+ std::cout << print_error << "no fetch methods worked." << std::endl;
+ exit(EXIT_FAILURE);
+ }
}
diff --git a/src/install_pkg.cc b/src/install_pkg.cc
index 3f0bd75..2cf7193 100644
--- a/src/install_pkg.cc
+++ b/src/install_pkg.cc
@@ -6,6 +6,8 @@
#include "copy_install.hh"
#include "install_pkg.hh"
#include "link_install.hh"
+#include "lua_state.hh"
+#include "name_from_url.hh"
#include "vars.hh"
void install_pkg(Pkg pkg) {
@@ -13,15 +15,15 @@ void install_pkg(Pkg pkg) {
fetch_src(pkg);
std::cout << print_pkgit << "building..." << std::endl;
- build(pkg.src.c_str());
+ build(pkg);
std::cout << print_pkgit << "installing..." << std::endl;
if (is_symlink_install) { link_install(pkg.src); }
else { copy_install(pkg.src); }
bool repo_exists = false;
- for (auto repo : repos) {
- if (repo.first == pkg.name) {
+ for (auto repo : cached_repos) {
+ if (name_from_url(repo.second.source.value) == pkg.name) {
repo_exists = true;
}
}
diff --git a/src/list_pkgs.cc b/src/list_pkgs.cc
index 487a75c..a64c753 100644
--- a/src/list_pkgs.cc
+++ b/src/list_pkgs.cc
@@ -1,10 +1,11 @@
#include <iostream>
#include "list_pkgs.hh"
+#include "lua_state.hh"
#include "vars.hh"
void list_pkgs() {
- for (auto repo : repos) {
+ for (auto repo : cached_repos) {
std::cout << repo.first << std::endl;
}
}
diff --git a/src/lua_build.cc b/src/lua_build.cc
index 75a626a..fd07184 100644
--- a/src/lua_build.cc
+++ b/src/lua_build.cc
@@ -1,51 +1,25 @@
-#include <iostream>
-#include <filesystem>
-#include <unordered_map>
-#include "lua_state.hh"
#include "lua_build.hh"
+#include "lua_state.hh"
#include "vars.hh"
+#include <filesystem>
+#include <iostream>
+#include <unordered_map>
-std::unordered_map<std::string, int> build_files;
-
-bool lua_build(const char *path) {
- init_lua_state();
- lua_State *L = get_lua_state();
-
- lua_getglobal(L, "build_systems");
-
- if (!lua_istable(L, -1)) {
- std::cout << print_error << "lua variable 'build_systems' is not a table.\n";
+bool lua_build(const char *repository, const char *target, const char *path) {
+ std::cout << print_pkgit << "attempting to use build function specified in 'repositories." << repository << "'..." << std::endl;
+ if (repo_build(repository)) {
+ return true;
}
- lua_pushnil(L);
-
- bool build_found = false;
- while (lua_next(L, -2) != 0) {
- const char *key = lua_tostring(L, -2);
- int value = lua_type(L, -1);
-
- if (lua_isfunction(L, -1) == 0) {
- std::cout << print_error << "build value is not a function\n";
- lua_pop(L, 1);
- continue;
- }
-
- build_files[key] = value;
+ std::cout << print_pkgit << "attempting to use build function specified in 'bldit.lua'..." << std::endl;
+ if (bldit(target)) {
+ return true;
+ }
- for (auto const& dir_entry : std::filesystem::directory_iterator(std::filesystem::current_path().string())) {
- std::string string_key = key;
- if (dir_entry.path().filename() != string_key) { continue; }
- build_found = true;
- lua_pushvalue(L, -1);
- lua_pushstring(L, std::filesystem::current_path().string().c_str());
- std::cout << "calling lua build function according to key filename '"<< key << "'...\n";
- if (lua_pcall(L, 1, 0, 0) != 0) {
- std::cout << print_error << "lua build function failed to run\n";
- break;
- }
- if (build_found) { break; }
- }
- lua_pop(L, 1);
+ std::cout << print_pkgit << "attempting to use build functions specified in 'build_systems'..." << std::endl;
+ if (config_build(path)) {
+ return true;
}
- return build_found;
+
+ return false;
} \ No newline at end of file
diff --git a/src/lua_state.cc b/src/lua_state.cc
index cbcf08f..fd2b080 100644
--- a/src/lua_state.cc
+++ b/src/lua_state.cc
@@ -1,31 +1,44 @@
-#include <iostream>
-#include <unordered_map>
#include "lua_state.hh"
#include "vars.hh"
+#include <iostream>
+#include <unordered_map>
static lua_State *L = nullptr;
static bool config_loaded = false;
+static lua_State *B = nullptr;
+static bool bldit_loaded = false;
+
std::unordered_map<std::string, std::string> cached_install_directories;
-std::unordered_map<std::string, std::string> cached_repos;
+std::unordered_map<std::string, repo> cached_repos;
std::unordered_map<std::string, int> cached_build_systems;
void init_lua_state() {
- if (L != nullptr) return;
+ if (L != nullptr)
+ return;
L = luaL_newstate();
luaL_openlibs(L);
-
if (luaL_loadfile(L, config_file.c_str()) || lua_pcall(L, 0, 0, 0)) {
std::cout << print_error << "cannot run configuration script: " << lua_tostring(L, -1) << "\n";
return;
}
+ //if (luaL_loadfile(L, repo_file.c_str()) || lua_pcall(L, 0, 0, 0)) {
+ // std::cout << print_error << "cannot run repository script: " << lua_tostring(L, -1) << "\n";
+ // return;
+ //}
+ config_loaded = true;
+}
- if (luaL_loadfile(L, repo_file.c_str()) || lua_pcall(L, 0, 0, 0)) {
- std::cout << print_error << "cannot run repository script: " << lua_tostring(L, -1) << "\n";
+void init_bldit() {
+ if (B != nullptr)
+ return;
+ B = luaL_newstate();
+ luaL_openlibs(B);
+ if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) {
+ std::cout << print_warning << "cannot run bldit script: " << lua_tostring(B, -1) << "\n";
return;
}
-
- config_loaded = true;
+ bldit_loaded = true;
}
void free_lua_state() {
@@ -36,20 +49,17 @@ void free_lua_state() {
config_loaded = false;
}
-lua_State* get_lua_state() {
- return L;
-}
+lua_State *get_lua_state() { return L; }
void cache_install_directories() {
if (!config_loaded || !lua_istable(L, -1)) {
lua_getglobal(L, "install_directories");
}
-
if (!lua_istable(L, -1)) {
- std::cout << print_error << "lua variable 'install_directories' is not a table.\n";
+ std::cout << print_error
+ << "lua variable 'install_directories' is not a table.\n";
return;
}
-
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
const char *key = lua_tostring(L, -2);
@@ -60,23 +70,163 @@ void cache_install_directories() {
lua_pop(L, 1);
}
-void cache_repos() {
- if (!config_loaded) {
- lua_getglobal(L, "repositories");
- } else if (!lua_istable(L, -1)) {
- lua_getglobal(L, "repositories");
+bool repo_build(const char *repository) {
+ lua_getglobal(L, "repositories");
+ if (!config_loaded || !lua_istable(L, -1)) {
+ std::cout << print_warning
+ << "lua variable 'repositories' is not a table.\n";
+ lua_pop(L, 1);
+ return false;
+ }
+ std::cout << print_pkgit
+ << "lua variable 'repositories' used successfully.\n";
+ lua_getfield(L, -1, repository);
+ if (!lua_istable(L, -1)) {
+ std::cout << print_warning << "'repositories' lua variable '" << repository << "' is not a table.\n";
+ lua_pop(L, 2);
+ return false;
+ }
+ std::cout << print_pkgit << "'repositories' lua variable '" << repository << "' used successfully.\n";
+ lua_getfield(L, -1, "build");
+ if (!lua_isfunction(L, -1)) {
+ std::cout << print_warning << "'repositories' lua variable 'build' is not a function." << std::endl;
+ lua_pop(L, 3);
+ return false;
+ }
+ if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
+ std::cout << "'repositories' build failed: " << lua_tostring(L, -1) << std::endl;
+ lua_pop(L, 1);
+ lua_pop(L, 2);
+ return false;
}
+ lua_pop(L, 2);
+ std::cout << print_pkgit
+ << "'repositories' lua function 'build' ran successfully.\n";
+ return true;
+}
+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)) {
+ std::cout << print_warning << "cannot run bldit script: " << lua_tostring(B, -1) << "\n";
+ return false;
+ }
+ lua_getglobal(B, "targets");
+ if (!lua_istable(B, -1)) {
+ std::cout << print_warning << "bldit variable 'targets' is not a table.\n";
+ return false;
+ }
+ std::cout << print_pkgit << "bldit variable 'targets' used successfully.\n";
+ lua_getfield(B, -1, target);
if (!lua_istable(L, -1)) {
+ std::cout << print_warning << "bldit variable '" << target
+ << "' is not a table.\n";
+ lua_pop(B, 2);
+ return false;
+ }
+ std::cout << print_pkgit << "bldit variable '" << target
+ << "' used successfully.\n";
+ lua_getfield(B, -1, "build");
+ if (!lua_isfunction(B, -1)) {
+ std::cout << "'repositories' lua variable 'build' is not a function."
+ << std::endl;
+ lua_pop(B, 3);
+ return false;
+ }
+ if (lua_pcall(B, 0, 0, 0) != LUA_OK) {
+ std::cout << "build failed: " << lua_tostring(B, -1) << std::endl;
+ lua_pop(B, 1);
+ lua_pop(B, 2);
+ return false;
+ }
+ lua_pop(B, 2);
+ std::cout << print_pkgit << "bldit function 'build' ran successfully.\n";
+ return true;
+}
+
+//bool config_build(const char* path) {
+// free_lua_state();
+// init_lua_state();
+// lua_State* L = get_lua_state();
+// std::unordered_map<std::string, int> build_files;
+// lua_getglobal(L, "build_systems");
+// if (!config_loaded || !lua_istable(L, -1)) {
+// lua_pop(L, 1);
+// std::cout << print_warning << "config lua variable 'build_systems' is not
+// a table.\n"; return false;
+// }
+// lua_pushnil(L);
+// bool build_found = false;
+// while (lua_next(L, -2) != 0) {
+// const char *key = lua_tostring(L, -2);
+// int value = lua_type(L, -1);
+// if (lua_isfunction(L, -1) == 0) {
+// std::cout << print_warning << "config build value " << key << " is not
+// a function\n"; lua_pop(L, 1); continue;
+// }
+// build_files[key] = value;
+// for (auto const& dir_entry : std::filesystem::directory_iterator(std::filesystem::current_path().string())) {
+// std::string string_key = key;
+// if (dir_entry.path().filename() != string_key) { continue; }
+// build_found = true;
+// lua_pushvalue(L, -1);
+// lua_pushstring(L, std::filesystem::current_path().string().c_str());
+// std::cout << "calling config lua build function according to key filename '"
+// << key << "'...\n";
+// if (lua_pcall(L, 1, 0, 0) != 0) {
+// std::cout << print_warning << "config lua build function failed to run\n";
+// break;
+// }
+// if (build_found) { break; }
+// }
+// lua_pop(L, 1);
+// }
+// return build_found;
+//}
+
+void cache_repos() {
+ lua_getglobal(L, "repositories");
+ if (!config_loaded || !lua_istable(L, -1)) {
std::cout << print_error << "lua variable 'repositories' is not a table.\n";
+ lua_pop(L, 1);
return;
- }
-
+ }
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
- const char *key = lua_tostring(L, -2);
- const char *value = lua_tostring(L, -1);
- cached_repos[key] = value;
+ const char *repo_name = lua_tostring(L, -2);
+ if (!repo_name || !lua_istable(L, -1)) {
+ std::cout << print_error << "repository key is not a table\n";
+ lua_pop(L, 1);
+ continue;
+ }
+ lua_getfield(L, -1, "url");
+ const char* url = lua_tostring(L, -1);
+ lua_pop(L, 1);
+ cached_repos[repo_name].source.key = "url";
+ cached_repos[repo_name].source.value = url ? url : "";
+ lua_getfield(L, -1, "dependencies");
+ if (!lua_istable(L, -1)) {
+ std::cout << print_warning << repo_name << ": \tlua variable 'dependencies' is not a table.\n";
+ lua_pop(L, 2);
+ continue;
+ }
+ lua_pushnil(L);
+ while (lua_next(L, -2) != 0) {
+ const char* depname = lua_tostring(L, -2);
+ if (depname && lua_istable(L, -1)) {
+ lua_getfield(L, -1, "url");
+ const char* dep_url = lua_tostring(L, -1);
+ lua_pop(L, 1);
+ lua_getfield(L, -1, "version");
+ const char* dep_version = lua_tostring(L, -1);
+ lua_pop(L, 1);
+ cached_repos[repo_name].dependencies[depname].url = dep_url ? dep_url : "";
+ cached_repos[repo_name].dependencies[depname].version = dep_version ? dep_version : "";
+ }
+ lua_pop(L, 1);
+ }
+ lua_pop(L, 1);
lua_pop(L, 1);
}
lua_pop(L, 1);
@@ -88,12 +238,10 @@ void cache_build_systems() {
} else if (!lua_istable(L, -1)) {
lua_getglobal(L, "build_systems");
}
-
if (!lua_istable(L, -1)) {
std::cout << print_error << "lua variable 'build_systems' is not a table.\n";
return;
}
-
lua_pushnil(L);
while (lua_next(L, -2) != 0) {
const char *key = lua_tostring(L, -2);
@@ -107,3 +255,40 @@ void cache_build_systems() {
}
lua_pop(L, 1);
}
+
+bool config_build(const char *path) {
+ lua_getglobal(L, "build_systems");
+ if (!config_loaded || !lua_istable(L, -1)) {
+ std::cout << print_warning << "lua variable 'build_systems' is not a table.\n";
+ lua_pop(L, 1);
+ return false;
+ }
+ std::cout << print_pkgit << "lua variable 'build_systems' used successfully.\n";
+ lua_pushnil(L);
+ while (lua_next(L, -2) != 0) {
+ const char *key = lua_tostring(L, -2);
+ if (!lua_istable(L, -1)) {
+ std::cout << print_error << "build value " << key << " is not a table\n";
+ lua_pop(L, 1);
+ continue;
+ }
+ for (auto const& dir_entry : std::filesystem::directory_iterator(std::filesystem::current_path().string())) {
+ std::string string_key = key;
+ if (dir_entry.path().filename() != string_key) { continue; }
+ lua_getfield(L, -1, "build");
+ if (lua_isfunction(L, -1) == 0) {
+ std::cout << print_error << "no build function for " << key << "\n";
+ lua_pop(L, 1);
+ continue;
+ }
+ if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
+ std::cout << "'" << key << "' build failed: " << lua_tostring(L, -1) << std::endl;
+ lua_pop(L, 1);
+ continue;
+ }
+ }
+ lua_pop(L, 1);
+ }
+ lua_pop(L, 1);
+ return true;
+} \ No newline at end of file
diff --git a/src/main.cc b/src/main.cc
index dd00010..4ec16c9 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -1,9 +1,15 @@
+#include <iostream>
+#include <unordered_map>
+
#include "cla_parse.hh"
#include "setup_pkgit.hh"
-#include "vars.hh"
+#include "lua_state.hh"
int main(int argc, char *argv[]) {
- setup_pkgit();
- cla_parse(argc, argv);
- return 0;
+ setup_pkgit();
+ //init_lua_state();
+ //repo_build("omnisearch");
+ cla_parse(argc, argv);
+ free_lua_state();
+ return 0;
}
diff --git a/src/setup_dirs.cc b/src/setup_dirs.cc
index 3a349e6..54b9eb0 100644
--- a/src/setup_dirs.cc
+++ b/src/setup_dirs.cc
@@ -6,11 +6,12 @@
void setup_dirs() {
std::filesystem::create_directories(config_dir);
- std::filesystem::create_directories(install_directories["bin"]);
- std::filesystem::create_directories(install_directories["lib"]);
- std::filesystem::create_directories(install_directories["include"]);
- std::filesystem::create_directories(install_directories["pkgblds"]);
+ for (auto i: install_directories) {
+ if (std::filesystem::exists(i.second)) continue;
+ if (i.second == "") continue;
+ std::filesystem::create_directories(i.second);
+ }
//for(unsigned int i = 0; i < sizeof(all_dirs)/sizeof(all_dirs[0]); i++) {
- //std::filesystem::create_directories(all_dirs[i]);
+ // std::filesystem::create_directories(all_dirs[i]);
//}
}
diff --git a/src/setup_pkgit.cc b/src/setup_pkgit.cc
index 15dc60c..df7e87f 100644
--- a/src/setup_pkgit.cc
+++ b/src/setup_pkgit.cc
@@ -3,11 +3,9 @@
#include "set_install_directories.hh"
#include "setup_pkgit.hh"
#include "setup_dirs.hh"
-#include "setup_repo.hh"
#include "vars.hh"
void setup_pkgit() {
set_install_directories();
setup_dirs();
- setup_repo();
}
diff --git a/src/setup_repo.cc b/src/setup_repo.cc
deleted file mode 100644
index bc15d1f..0000000
--- a/src/setup_repo.cc
+++ /dev/null
@@ -1,29 +0,0 @@
-#include <iostream>
-#include "lua_state.hh"
-#include "setup_repo.hh"
-#include "ensure_repo.hh"
-#include "vars.hh"
-
-void setup_repo() {
- ensure_repo();
-
- init_lua_state();
- lua_State *L = get_lua_state();
-
- lua_getglobal(L, "repos");
-
- if (!lua_istable(L, -1)) {
- std::cout << print_error << "lua variable 'repos' is not a table.\n";
- }
-
- lua_pushnil(L);
-
- while (lua_next(L, -2) != 0) {
- const char *key = lua_tostring(L, -2);
- const char *value = lua_tostring(L, -1);
-
- repos[key] = value;
-
- lua_pop(L, 1);
- }
-} \ No newline at end of file
diff --git a/src/update_all.cc b/src/update_all.cc
index 5af2e67..6f55543 100644
--- a/src/update_all.cc
+++ b/src/update_all.cc
@@ -1,11 +1,12 @@
#include "update_all.hh"
#include "create_pkg.hh"
+#include "lua_state.hh"
#include "update_pkg.hh"
#include "vars.hh"
void update_all() {
- for (auto repo : repos) {
- Pkg pkg = create_pkg(repo.second);
+ for (auto repo : cached_repos) {
+ Pkg pkg = create_pkg(repo.second.source.value);
update_pkg(pkg);
}
}
diff --git a/src/vars.cc b/src/vars.cc
index 12c7e7e..b619e15 100644
--- a/src/vars.cc
+++ b/src/vars.cc
@@ -4,7 +4,7 @@
#include "vars.hh"
-std::unordered_map<std::string, std::string> repos;
+//std::unordered_map<std::string, std::string> repos;
std::unordered_map<std::string, std::string> install_directories;
bool is_symlink_install = false;
@@ -76,5 +76,6 @@ const std::string italic = "\e[3m";
const std::string color_reset = "\e[0m";
const std::string print_pkgit = bold_yellow + "[" + bold_magenta + "pkgit" + bold_yellow + "]\t" + color_reset;
-const std::string print_skipped = print_pkgit + blue + "[SKIPPED]\t" + color_reset;
+const std::string print_skipped = print_pkgit + blue + "[SKIP]\t" + color_reset;
+const std::string print_warning = print_pkgit + yellow + "[WARN]\t" + color_reset;
const std::string print_error = print_pkgit + red + "[ERROR]\t" + color_reset;