aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.clangd2
-rw-r--r--Makefile5
-rwxr-xr-xbldit1
-rwxr-xr-xpkgitbin534504 -> 164376 bytes
-rw-r--r--src/build.cc13
-rw-r--r--src/build_pkg.cc27
-rw-r--r--src/create_pkg.cc3
-rw-r--r--src/fetch_git.cc23
-rw-r--r--src/fetch_pwd.cc5
-rw-r--r--src/fetch_src.cc4
-rw-r--r--src/install_pkg.cc5
-rw-r--r--src/lua_build.cc58
-rw-r--r--src/main.cc4
-rw-r--r--src/vars.cc2
14 files changed, 109 insertions, 43 deletions
diff --git a/.clangd b/.clangd
new file mode 100644
index 0000000..ffabaa3
--- /dev/null
+++ b/.clangd
@@ -0,0 +1,2 @@
+CompileFlags:
+ Add: [-I/usr/include/luajit-2.1]
diff --git a/Makefile b/Makefile
index e02bad1..63d8a1a 100644
--- a/Makefile
+++ b/Makefile
@@ -12,3 +12,8 @@ pkgit: src/main.cc
install: pkgit
install -d $(DESTDIR)$(PREFIX)/bin
install -m 755 pkgit $(DESTDIR)$(PREFIX)/bin/pkgit
+
+
+luatest: src/lua_build.cc
+ $(CC) -o luatest src/lua_build.cc -I"./include" $(CXXFLAGS)
+ chmod +x luatest
diff --git a/bldit b/bldit
index 9e89e95..bec03bc 100755
--- a/bldit
+++ b/bldit
@@ -1,3 +1,2 @@
#!/usr/bin/env sh
-
make
diff --git a/pkgit b/pkgit
index 8d7ce6b..20c2e9f 100755
--- a/pkgit
+++ b/pkgit
Binary files differ
diff --git a/src/build.cc b/src/build.cc
new file mode 100644
index 0000000..0195412
--- /dev/null
+++ b/src/build.cc
@@ -0,0 +1,13 @@
+#include <filesystem>
+
+#include "lua_build.cc"
+
+void build(std::filesystem::path build_dir) {
+ if (build_dir != std::filesystem::current_path().string()) {
+ std::filesystem::current_path(build_dir);
+ }
+ for (auto const &dir_entry : std::filesystem::directory_iterator(fs::current_path().string())) {
+ if (dir_entry.path().filename() == "bldit") { system("./bldit"); }
+ else { lua_build(build_dir.c_str()); }
+ }
+}
diff --git a/src/build_pkg.cc b/src/build_pkg.cc
index 67c67b8..7627e16 100644
--- a/src/build_pkg.cc
+++ b/src/build_pkg.cc
@@ -1,36 +1,17 @@
#include <functional>
-#include "build_systems.cc"
-
-const std::map<std::string, std::function<void()>> builds = {
- {"bldit", bldit_build},
- {"compile.sh", compilesh_build},
- {"build.sh", buildsh_build},
- {"autogen.sh", autogen_build},
- {"configure", autotools_build},
- {"configure.ac", autotools_build},
- {"Makefile", make_build},
- {"Makefile.am", make_build},
- {"CMakeLists.txt", cmake_build},
- {"meson.build", meson_build},
- {"build.ninja", ninja_build},
- {"Cargo.toml", cargo_build},
- {"go.mod", go_build},
- {"gradle.build", gradle_build},
- {"pnpm-lock.yaml", pnpm_build},
- {"pyproject.toml", python_build},
- {"build.zig", zig_build}
-};
+#include "build_map.cc"
void build_pkg(std::filesystem::path build_dir) {
if (build_dir != fs::current_path().string()) {
fs::current_path(build_dir);
}
- for (auto const& dir_entry : fs::directory_iterator(fs::current_path().string())) {
+ for (auto const &dir_entry :
+ fs::directory_iterator(fs::current_path().string())) {
for (auto build : builds) {
if (dir_entry.path().filename() == build.first) {
build.second();
}
- }
+ }
}
}
diff --git a/src/create_pkg.cc b/src/create_pkg.cc
index b243afd..5cea49e 100644
--- a/src/create_pkg.cc
+++ b/src/create_pkg.cc
@@ -10,6 +10,9 @@ Pkg create_pkg(std::string arg) {
if (arg.rfind("http", 0) == 0) {
pkg.url = arg;
pkg.name = name_from_url(arg);
+ } else if (arg == ".") {
+ pkg.url = "";
+ pkg.name = name_from_url(fs::current_path().string());
}
pkg.ver = "HEAD";
diff --git a/src/fetch_git.cc b/src/fetch_git.cc
index 3306e42..b8df6bb 100644
--- a/src/fetch_git.cc
+++ b/src/fetch_git.cc
@@ -4,21 +4,16 @@
int fetch_git(Pkg pkg) {
std::string clone_cmds[] = {
- "git -c advice.detachedHead=false clone --depth 1 " + pkg.url + " " +
- pkg.src.c_str(),
- "git -c advice.detachedHead=false clone --branch " + pkg.ver +
- " --depth 1 " + pkg.url + " " + pkg.src.c_str()};
+ "git -c advice.detachedHead=false clone --depth 1 " + pkg.url +
+ " " + pkg.src.c_str(),
+ "git -c advice.detachedHead=false clone --branch " + pkg.ver +
+ " --depth 1 " + pkg.url + " " + pkg.src.c_str()
+ };
if (strcmp(pkg.ver.c_str(), "HEAD") == 0) {
- if (WEXITSTATUS(system(clone_cmds[0].c_str())) == 0x10) {
- return 0;
- } else {
- return 1;
- }
+ if (WEXITSTATUS(system(clone_cmds[0].c_str())) == 0x10) { return 0; }
+ else { return 1; }
} else {
- if (WEXITSTATUS(system(clone_cmds[1].c_str())) == 0x10) {
- return 0;
- } else {
- return 1;
- }
+ if (WEXITSTATUS(system(clone_cmds[1].c_str())) == 0x10) { return 0; }
+ else { return 1; }
}
}
diff --git a/src/fetch_pwd.cc b/src/fetch_pwd.cc
new file mode 100644
index 0000000..dbd5fcf
--- /dev/null
+++ b/src/fetch_pwd.cc
@@ -0,0 +1,5 @@
+#include "vars.cc"
+
+void fetch_pwd(Pkg pkg) {
+ std::filesystem::copy(std::filesystem::current_path(), pkg.src);
+}
diff --git a/src/fetch_src.cc b/src/fetch_src.cc
index 27a4b23..3e5cca3 100644
--- a/src/fetch_src.cc
+++ b/src/fetch_src.cc
@@ -3,5 +3,7 @@
void fetch_src(Pkg pkg) {
if (fs::exists(pkg.src)) { fs::remove_all(pkg.src); }
- if (fetch_git(pkg) == 0) { return; } else { exit(EXIT_FAILURE); }
+
+ if (pkg.url == "") { std::filesystem::create_directories(pkg.src); return; }
+ else if (fetch_git(pkg) == 0) { return; } else { exit(EXIT_FAILURE); }
}
diff --git a/src/install_pkg.cc b/src/install_pkg.cc
index a710831..13cef81 100644
--- a/src/install_pkg.cc
+++ b/src/install_pkg.cc
@@ -1,9 +1,10 @@
#include "fetch_src.cc"
-#include "build_pkg.cc"
+#include "build.cc"
#include "link_install.cc"
void install_pkg(Pkg pkg) {
fetch_src(pkg);
- build_pkg(pkg.src);
+ //build_pkg(pkg.src);
+ build(pkg.src.c_str());
link_install(pkg.src);
}
diff --git a/src/lua_build.cc b/src/lua_build.cc
new file mode 100644
index 0000000..b75e2f3
--- /dev/null
+++ b/src/lua_build.cc
@@ -0,0 +1,58 @@
+#include <iostream>
+#include <filesystem>
+#include <map>
+#include <lua5.1/lua.h>
+#include <lua5.1/lauxlib.h>
+#include <lua5.1/lualib.h>
+
+#include "vars.cc"
+
+std::map<std::string, int> build_files;
+
+void lua_build (const char *path) {
+ lua_State *L = lua_open();
+ 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";
+ }
+
+ lua_getglobal(L, "build_systems");
+
+ if (!lua_istable(L, -1)) {
+ std::cout << print_error << "lua variable 'build_systems' is not a table.\n";
+ }
+
+ 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;
+
+ 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";
+ }
+ if (build_found) { break; }
+ }
+ lua_pop(L, 1);
+ }
+ if (!build_found) {
+ std::cout << print_error << "no usable build system was found\n";
+ }
+}
diff --git a/src/main.cc b/src/main.cc
index c020c87..bcc45df 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -14,9 +14,9 @@ int main(int argc, char *argv[]) {
if (argv[1]) {
if (strcmp(argv[1], "build") == 0 || strcmp(argv[1], "b") == 0) {
if (argv[2]) {
- build_pkg(argv[2]);
+ build(argv[2]);
} else {
- build_pkg(fs::current_path().string());
+ build(fs::current_path().string().c_str());
}
} else if (strcmp(argv[1], "install") == 0 || strcmp(argv[1], "i") == 0) {
pkg = create_pkg(argv[2]);
diff --git a/src/vars.cc b/src/vars.cc
index 4957be4..b4c2abe 100644
--- a/src/vars.cc
+++ b/src/vars.cc
@@ -15,6 +15,8 @@ struct Pkg {
const std::string home_dir = std::getenv("HOME");
+const std::string config_file = home_dir + "/.config/pkgit/init.lua";
+
const std::string bin = home_dir + "/.local/bin";
const std::string lib = home_dir + "/.local/lib";
const std::string include = home_dir + "/.local/include";