aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cla_parse.c1
-rw-r--r--src/fetch_git.c57
-rw-r--r--src/fetch_src.c8
-rw-r--r--src/help.c1
-rw-r--r--src/lua_build.c6
-rw-r--r--src/lua_state.c92
-rw-r--r--src/vars.c2
7 files changed, 89 insertions, 78 deletions
diff --git a/src/cla_parse.c b/src/cla_parse.c
index f9e759b..faa9341 100644
--- a/src/cla_parse.c
+++ b/src/cla_parse.c
@@ -36,6 +36,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("add", "a", {
if (argv[i + 1]) {
add_repo(argv[i + 1], name_from_url(argv[i + 1]));
diff --git a/src/fetch_git.c b/src/fetch_git.c
index 85275d3..deb94ac 100644
--- a/src/fetch_git.c
+++ b/src/fetch_git.c
@@ -1,3 +1,4 @@
+#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -8,31 +9,39 @@
#include "vars.h"
int fetch_git(Pkg pkg) {
- pid_t pid = fork();
- if (pid == 0) {
- const char *argv[8];
- int i = 0;
- argv[i++] = "git";
- argv[i++] = "-c";
- argv[i++] = "advice.detachedHead=false";
- argv[i++] = "clone";
- if (strcmp(pkg.ver, "HEAD") != 0) {
- argv[i++] = "--branch";
- argv[i++] = pkg.ver;
- }
- argv[i++] = pkg.url;
- argv[i++] = pkg.src;
- argv[i] = NULL;
- execvp("git", (char *const *)argv);
- _exit(127);
+ pid_t pid = fork();
+ if (pid == 0) {
+ if (!is_verbose) {
+ int nullfd = open("/dev/null", O_WRONLY);
+ if (nullfd >= 0) {
+ dup2(nullfd, STDOUT_FILENO);
+ dup2(nullfd, STDERR_FILENO);
+ close(nullfd);
+ }
}
-
- int status;
- waitpid(pid, &status, 0);
- int result = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
- if (result != 0) {
- printf("clone failed\n");
+ const char *argv[8];
+ int i = 0;
+ argv[i++] = "git";
+ argv[i++] = "-c";
+ argv[i++] = "advice.detachedHead=false";
+ argv[i++] = "clone";
+ if (strcmp(pkg.ver, "HEAD") != 0) {
+ argv[i++] = "--branch";
+ argv[i++] = pkg.ver;
}
+ argv[i++] = pkg.url;
+ argv[i++] = pkg.src;
+ argv[i] = NULL;
+ execvp("git", (char *const *)argv);
+ _exit(127);
+ }
+
+ int status;
+ waitpid(pid, &status, 0);
+ int result = WIFEXITED(status) ? WEXITSTATUS(status) : -1;
+ if (result != 0) {
+ printf("clone failed\n");
+ }
- return result;
+ return result;
} \ No newline at end of file
diff --git a/src/fetch_src.c b/src/fetch_src.c
index f05557a..3f90ea4 100644
--- a/src/fetch_src.c
+++ b/src/fetch_src.c
@@ -21,18 +21,18 @@ static int remove_tree(const char *fpath, const struct stat *sb, int typeflag, s
}
void fetch_src(Pkg pkg) {
- printf("%starget source directory: %s\n", print_pkgit, pkg.src);
+ if (is_verbose) printf("%starget source directory: %s\n", print_pkgit, pkg.src);
if (file_exists(pkg.src)) {
- 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) {
- printf("%screating directory %s...\n", print_pkgit, pkg.src);
+ if (is_verbose) printf("%screating directory %s...\n", print_pkgit, pkg.src);
mkdir_p(pkg.src);
return;
}
if (fetch_git(pkg) == 0) {
- printf("%scloned into %s...\n", print_pkgit, pkg.src);
+ if (is_verbose) printf("%scloned into %s...\n", print_pkgit, pkg.src);
return;
}
printf("%sno fetch methods worked.\n", print_error);
diff --git a/src/help.c b/src/help.c
index 47f892f..731b8f2 100644
--- a/src/help.c
+++ b/src/help.c
@@ -32,6 +32,7 @@ void help() {
printf("\n");
printf("%sflags%s:\n", red, color_reset);
printf("%s...... %s-h%s, %s--help %s# display this help message\n", color_reset, green, color_reset, yellow, gray);
+ printf("%s...... %s-q%s, %s--quiet %s# run without logging to terminal\n", color_reset, green, color_reset, yellow, gray);
printf("%s...... %s-v%s, %s--version %s# display version number\n", color_reset, green, color_reset, yellow, gray);
printf("%s...... %s-c%s, %s--check %s# run package checks\n", color_reset, green, color_reset, yellow, gray);
}
diff --git a/src/lua_build.c b/src/lua_build.c
index 6f7c571..f99a341 100644
--- a/src/lua_build.c
+++ b/src/lua_build.c
@@ -6,19 +6,19 @@
#include "vars.h"
bool lua_build(const char *repository, const char *target, const char *path) {
- printf("%sattempting to use build function specified in 'repositories.%s'...\n",
+ if (is_verbose) printf("%sattempting to use build function specified in 'repositories.%s'...\n",
print_pkgit, repository);
if (repo_build(repository)) {
return true;
}
- printf("%sattempting to use build function specified in 'bldit.lua'...\n", print_pkgit);
+ if (is_verbose) printf("%sattempting to use build function specified in 'bldit.lua'...\n", print_pkgit);
if (bldit(target)) {
return true;
}
- printf("%sattempting to use build functions specified in 'build_systems'...\n", print_pkgit);
+ if (is_verbose) printf("%sattempting to use build functions specified in 'build_systems'...\n", print_pkgit);
if (config_build(path)) {
return true;
}
diff --git a/src/lua_state.c b/src/lua_state.c
index 49672e8..42b0a39 100644
--- a/src/lua_state.c
+++ b/src/lua_state.c
@@ -54,7 +54,7 @@ void init_bldit() {
B = luaL_newstate();
luaL_openlibs(B);
if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) {
- printf("%scannot run bldit script: %s\n", print_warning,
+ if (is_verbose) printf("%scannot run bldit script: %s\n", print_warning,
lua_tostring(B, -1));
return;
}
@@ -95,24 +95,24 @@ void cache_install_directories() {
bool repo_build(const char *repository) {
lua_getglobal(L, "repositories");
if (!config_loaded || !lua_istable(L, -1)) {
- printf("%slua variable 'repositories' is not a table.\n", print_warning);
+ if (is_verbose) printf("%slua variable 'repositories' is not a table.\n", print_warning);
lua_pop(L, 1);
return false;
}
- printf("%slua variable 'repositories' used successfully.\n", print_pkgit);
+ if (is_verbose) printf("%slua variable 'repositories' used successfully.\n", print_pkgit);
lua_getfield(L, -1, repository);
if (!lua_istable(L, -1)) {
- printf("%s'repositories' lua variable '%s' is not a table.\n", print_warning, repository);
+ if (is_verbose) printf("%s'repositories' lua variable '%s' is not a table.\n", print_warning, repository);
lua_pop(L, 2);
return false;
}
- printf("%s'repositories' lua variable '%s' used successfully.\n", print_pkgit, repository);
+ if (is_verbose) printf("%s'repositories' lua variable '%s' used successfully.\n", print_pkgit, repository);
lua_getfield(L, -1, "dependencies");
if (!lua_istable(L, -1)) {
- printf("%sbldit variable 'dependencies' is not a table.\n", print_warning);
+ if (is_verbose) printf("%sbldit variable 'dependencies' is not a table.\n", print_warning);
} else {
- printf("%sbldit variable 'dependencies' used successfully.\n", print_pkgit);
+ if (is_verbose) printf("%sbldit variable 'dependencies' used successfully.\n", print_pkgit);
Repo *repo;
while (lua_next(L, -2) != 0) {
const char *depname = lua_tostring(L, -2);
@@ -133,55 +133,55 @@ bool repo_build(const char *repository) {
lua_getfield(L, -1, "build");
if (!lua_isfunction(L, -1)) {
- printf("%s'repositories' lua variable 'build' is not a function.\n",
+ if (is_verbose) printf("%s'repositories' lua variable 'build' is not a function.\n",
print_warning);
lua_pop(L, 3);
return false;
}
- printf("%s'repositories' lua variable 'build' used successfully.\n",
+ if (is_verbose) printf("%s'repositories' lua variable 'build' used successfully.\n",
print_pkgit);
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
- printf("'repositories' build failed: %s\n", lua_tostring(L, -1));
+ printf("%s'repositories' build failed: %s\n", print_warning, lua_tostring(L, -1));
lua_pop(L, 1);
lua_pop(L, 2);
return false;
}
- printf("%s'repositories' lua function 'build' ran successfully.\n", print_pkgit);
+ if (is_verbose) printf("%s'repositories' lua function 'build' ran successfully.\n", print_pkgit);
lua_getfield(L, -1, "pre_install");
if (!lua_isfunction(L, -1)) {
- printf("%s'repositories' lua variable 'pre_install' is not a function.\n", print_warning);
+ if (is_verbose) printf("%s'repositories' lua variable 'pre_install' is not a function.\n", print_warning);
}
- printf("%s'repositories' lua variable 'pre_install' used successfully.\n", print_pkgit);
+ if (is_verbose) printf("%s'repositories' lua variable 'pre_install' used successfully.\n", print_pkgit);
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
- printf("'repositories' pre_install failed: %s\n", lua_tostring(L, -1));
+ if (is_verbose) printf("%s'repositories' pre_install failed: %s\n", print_warning, lua_tostring(L, -1));
}
- printf("%s'repositories' lua function 'pre_install' ran successfully.\n", print_pkgit);
+ if (is_verbose) printf("%s'repositories' lua function 'pre_install' ran successfully.\n", print_pkgit);
lua_getfield(L, -1, "install");
if (!lua_isfunction(L, -1)) {
- printf("%s'repositories' lua variable 'install' is not a function.\n", print_warning);
+ if (is_verbose) printf("%s'repositories' lua variable 'install' is not a function.\n", print_warning);
} else {
is_auto_installed = false;
}
- printf("%s'repositories' lua variable 'install' used successfully.\n", print_pkgit);
+ if (is_verbose) printf("%s'repositories' lua variable 'install' used successfully.\n", print_pkgit);
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
- printf("'repositories' install failed: %s\n", lua_tostring(L, -1));
+ if (is_verbose) printf("%s'repositories' install failed: %s\n", print_warning, lua_tostring(L, -1));
}
- printf("%s'repositories' lua function 'install' ran successfully.\n", print_pkgit);
+ if (is_verbose) printf("%s'repositories' lua function 'install' ran successfully.\n", print_pkgit);
lua_pop(L, 1);
lua_getfield(L, -1, "post_install");
if (!lua_isfunction(L, -1)) {
- printf("%s'repositories' lua variable 'post_install' is not a function.\n", print_warning);
+ if (is_verbose) printf("%s'repositories' lua variable 'post_install' is not a function.\n", print_warning);
}
- printf("%s'repositories' lua variable 'post_install' used successfully.\n", print_pkgit);
+ if (is_verbose) printf("%s'repositories' lua variable 'post_install' used successfully.\n", print_pkgit);
if (lua_pcall(L, 0, 0, 0) != LUA_OK) {
- printf("'repositories' post_install failed: %s\n", lua_tostring(L, -1));
+ if (is_verbose) printf("%s'repositories' post_install failed: %s\n", print_warning, lua_tostring(L, -1));
}
lua_pop(L, 2);
- printf("%s'repositories' lua function 'post_install' ran successfully.\n", print_pkgit);
+ if (is_verbose) printf("%s'repositories' lua function 'post_install' ran successfully.\n", print_pkgit);
return true;
}
@@ -190,30 +190,30 @@ bool bldit(const char *target) {
luaL_openlibs(B);
if (luaL_loadfile(B, "bldit.lua") || lua_pcall(B, 0, 0, 0)) {
- printf("%scannot run bldit script: %s\n", print_warning, lua_tostring(B, -1));
+ if (is_verbose) printf("%scannot 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)) {
- printf("%sbldit variable 'bldit_version' is not a string.\n", print_warning);
+ if (is_verbose) printf("%sbldit variable 'bldit_version' is not a string.\n", print_warning);
} else {
- printf("%sbldit variable 'bldit_version' used successfully.\n", print_pkgit);
+ if (is_verbose) printf("%sbldit variable 'bldit_version' used successfully.\n", print_pkgit);
}
lua_getglobal(B, "package_version");
if (!lua_isstring(B, -1)) {
- printf("%sbldit variable 'package_version' is not a string.\n", print_warning);
+ if (is_verbose) printf("%sbldit variable 'package_version' is not a string.\n", print_warning);
} else {
- printf("%sbldit variable 'package_version' used successfully.\n", print_pkgit);
+ if (is_verbose) printf("%sbldit variable 'package_version' used successfully.\n", print_pkgit);
}
lua_getglobal(B, "global_dependencies");
if (!lua_istable(B, -1)) {
- printf("%sbldit variable 'global_dependencies' is not a table.\n", print_warning);
+ if (is_verbose) printf("%sbldit variable 'global_dependencies' is not a table.\n", print_warning);
} else {
- printf("%sbldit variable 'global_dependencies' used successfully.\n", print_pkgit);
+ if (is_verbose) printf("%sbldit variable 'global_dependencies' used successfully.\n", print_pkgit);
Repo *repo;
while (lua_next(B, -2) != 0) {
const char *depname = lua_tostring(B, -2);
@@ -233,71 +233,71 @@ bool bldit(const char *target) {
lua_getglobal(B, "targets");
if (!lua_istable(B, -1)) {
- printf("%sbldit variable 'targets' is not a table.\n", print_warning);
+ if (is_verbose) printf("%sbldit variable 'targets' is not a table.\n", print_warning);
lua_close(B);
return false;
}
- printf("%sbldit variable 'targets' used successfully.\n", print_pkgit);
+ if (is_verbose) printf("%sbldit variable 'targets' used successfully.\n", print_pkgit);
lua_getfield(B, -1, target);
if (!lua_istable(B, -1)) {
- printf("%sbldit variable '%s' is not a table.\n", print_warning, target);
+ if (is_verbose) printf("%sbldit variable '%s' is not a table.\n", print_warning, target);
lua_pop(B, 2);
lua_close(B);
return false;
}
- printf("%sbldit variable '%s' used successfully.\n", print_pkgit, target);
+ if (is_verbose) printf("%sbldit variable '%s' used successfully.\n", print_pkgit, target);
lua_getfield(B, -1, "build");
if (!lua_isfunction(B, -1)) {
- printf("%s'repositories' lua variable 'build' is not a function.\n",
+ if (is_verbose) printf("%s'repositories' lua variable 'build' is not a function.\n",
print_warning);
lua_pop(B, 3);
lua_close(B);
return false;
}
if (lua_pcall(B, 0, 0, 0) != LUA_OK) {
- printf("build failed: %s\n", lua_tostring(B, -1));
+ printf("%sbuild failed: %s\n", print_error, lua_tostring(B, -1));
lua_pop(B, 1);
lua_pop(B, 2);
lua_close(B);
return false;
}
- printf("%sbldit function 'build' ran successfully.\n", print_pkgit);
+ if (is_verbose) printf("%sbldit function 'build' ran successfully.\n", print_pkgit);
lua_getfield(B, -1, "pre_install");
if (!lua_isfunction(B, -1)) {
- printf("%s'repositories' lua variable 'pre_install' is not a function.\n",
+ if (is_verbose) printf("%s'repositories' lua variable 'pre_install' is not a function.\n",
print_warning);
}
if (lua_pcall(B, 0, 0, 0) != LUA_OK) {
- printf("build failed: %s\n", lua_tostring(B, -1));
+ printf("%sbuild failed: %s\n", print_error, lua_tostring(B, -1));
}
- printf("%sbldit function 'pre_install' ran successfully.\n", print_pkgit);
+ if (is_verbose) printf("%sbldit function 'pre_install' ran successfully.\n", print_pkgit);
lua_getfield(B, -1, "install");
if (!lua_isfunction(B, -1)) {
- printf("%s'repositories' lua variable 'install' is not a function.\n",
+ if (is_verbose) printf("%s'repositories' lua variable 'install' is not a function.\n",
print_warning);
} else {
is_auto_installed = false;
}
if (lua_pcall(B, 0, 0, 0) != LUA_OK) {
- printf("build failed: %s\n", lua_tostring(B, -1));
+ printf("%sbuild failed: %s\n", print_error, lua_tostring(B, -1));
}
- printf("%sbldit function 'install' ran successfully.\n", print_pkgit);
+ if (is_verbose) printf("%sbldit function 'install' ran successfully.\n", print_pkgit);
lua_getfield(B, -1, "post_install");
if (!lua_isfunction(B, -1)) {
- printf("%s'repositories' lua variable 'post_install' is not a function.\n",
+ if (is_verbose) printf("%s'repositories' lua variable 'post_install' is not a function.\n",
print_warning);
}
if (lua_pcall(B, 0, 0, 0) != LUA_OK) {
- printf("build failed: %s\n", lua_tostring(B, -1));
+ printf("%sbuild failed: %s\n", print_error, lua_tostring(B, -1));
}
- printf("%sbldit function 'post_install' ran successfully.\n", print_pkgit);
+ if (is_verbose) printf("%sbldit function 'post_install' ran successfully.\n", print_pkgit);
lua_pop(B, 2);
lua_close(B);
diff --git a/src/vars.c b/src/vars.c
index 967a052..64d053c 100644
--- a/src/vars.c
+++ b/src/vars.c
@@ -9,7 +9,7 @@
#include "vars.h"
bool is_symlink_install = false;
-bool is_verbose = false;
+bool is_verbose = true;
bool is_auto_installed = true;
bool config_exists = false;