package

simple and robust package manager
Log | Files | Refs | README

commit 88773691eaf13d0a5d659c5250b06e49e3b4c563
parent 6842cd57815cba3a268b932bef4adbce83895983
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sat, 19 Jan 2019 19:44:30 +0100

package-add: run each package-* program sequentially

Diffstat:
Mmake-bin | 2+-
Mmake-o | 2+-
Mpackage-add.c | 79+++++++++++++++++++++++++++++++++++++++++++------------------------------------
Mpackage-install.c | 2+-
4 files changed, 46 insertions(+), 39 deletions(-)

diff --git a/make-bin b/make-bin @@ -1,2 +1,2 @@ #!/bin/sh -exec cc -static -s -o "$@" +exec cc -s -o "$@" diff --git a/make-o b/make-o @@ -1,2 +1,2 @@ #!/bin/sh -exec cc -D_POSIX_SOURCE -Wall -Wextra -Wno-misleading-indentation -std=c99 -pedantic -c "$@" +exec cc -D_POSIX_SOURCE -Wall -Wextra -std=c99 -pedantic -c "$@" diff --git a/package-add.c b/package-add.c @@ -25,17 +25,23 @@ main(int argc, char **argv) package p; char *pkg = PACKAGE_DIR; char *def = PACKAGE_DEF; + char *root = PACKAGE_ROOT; char **av = argv; + char fmt[PACKAGE_FMT + 80]; + int flag_i = 0; + int x; (void)argc; while (*++av) { if (str_equal(*av, "-d")) { if (!(def = *++av)) break; continue; } if (str_equal(*av, "-p")) { if (!(pkg = *++av)) break; continue; } + if (str_equal(*av, "-r")) { if (!(root = *++av)) break; continue; } + if (str_equal(*av, "-i")) { flag_i = 1; continue; } break; } - if (!*av) log_usage(*argv, "[-p pkgdir] [-d defdir] package[/version]"); + if (!*av) log_usage(*argv, "[-p pkgdir] [-p pkgdir] [-d defdir] package[/version]"); if (!stat_isdir(def)) log_fatal_sys_1(101, def); if (!stat_isdir(pkg)) log_fatal_sys_1(101, pkg); @@ -56,57 +62,58 @@ main(int argc, char **argv) { stralloc sa = STRALLOC_ZERO; package *p = genalloc_get(&ga, package, i); - char fmt[PACKAGE_FMT + 80]; - char const *argv[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; - int x; + char const *argv[] = { "package-get", "-d", def, "-p", pkg, fmt, NULL }; fmt[package_fmt(p, fmt)] = '\0'; - argv[1] = "-d"; - argv[2] = def; - argv[3] = "-p"; - argv[4] = pkg; - argv[5] = fmt; - stralloc_zero(&sa); if (!stralloc_cats(&sa, pkg)) die_nomem(); if (!stralloc_cats(&sa, "/")) die_nomem(); - if (!stralloc_cats(&sa, p->name)) die_nomem(); - if (!stralloc_cats(&sa, "/")) die_nomem(); - if (!stralloc_cats(&sa, p->ver)) die_nomem(); - if (!stralloc_cats(&sa, "/current")) die_nomem(); + if (!stralloc_cats(&sa, fmt)) die_nomem(); + if (!stralloc_cats(&sa, "/source.tar")) die_nomem(); if (!stralloc_cat0(&sa)) die_nomem(); - if (stat_islink(sa.x)) goto install; + if (stat_isfile(sa.x)) continue; + + log_info_2("package-get ", fmt); + if ((x = forkexec_wait(argv)) != 0) goto error; + } + + for (size_t i = 0; i < genalloc_len(&ga, package); ++i) + { + stralloc sa = STRALLOC_ZERO; + package *p = genalloc_get(&ga, package, i); + char const *argv[] = { "package-build", "-d", def, "-p", pkg, fmt, NULL }; + + fmt[package_fmt(p, fmt)] = '\0'; stralloc_zero(&sa); if (!stralloc_cats(&sa, pkg)) die_nomem(); if (!stralloc_cats(&sa, "/")) die_nomem(); - if (!stralloc_cats(&sa, p->name)) die_nomem(); - if (!stralloc_cats(&sa, "/")) die_nomem(); - if (!stralloc_cats(&sa, p->ver)) die_nomem(); - if (!stralloc_cats(&sa, "/source.tar")) die_nomem(); + if (!stralloc_cats(&sa, fmt)) die_nomem(); + if (!stralloc_cats(&sa, "/current")) die_nomem(); if (!stralloc_cat0(&sa)) die_nomem(); - if (stat_isfile(sa.x)) goto build; + if (stat_islink(sa.x)) continue; - log_info_4("package-get ", p->name, "/", p->ver); - argv[0] = "package-get"; - if ((x = forkexec_wait(argv)) != 0) goto error; -build: - log_info_4("package-build ", p->name, "/", p->ver); - argv[0] = "package-build"; - if ((x = forkexec_wait(argv)) != 0) goto error; -install: - log_info_4("package-install ", p->name, "/", p->ver); - argv[0] = "package-install"; + log_info_2("package-build ", fmt); if ((x = forkexec_wait(argv)) != 0) goto error; + } - continue; -error: - fmt[fmt_long(fmt, x)] = '\0'; - log_error_2("exited with status ", fmt); - return x; + if (!flag_i) return 0; + + for (size_t i = 0; i < genalloc_len(&ga, package); ++i) + { + package *p = genalloc_get(&ga, package, i); + char const *argv[] = { "package-install", "-r", root, "-d", def, "-p", pkg, fmt, NULL }; + + fmt[package_fmt(p, fmt)] = '\0'; + + log_info_2("package-install ", fmt); + if ((x = forkexec_wait(argv)) != 0) goto error; } - genalloc_free(&ga); return 0; +error: + fmt[fmt_long(fmt, x)] = '\0'; + log_error_2("exited with status ", fmt); + return x; } diff --git a/package-install.c b/package-install.c @@ -32,7 +32,7 @@ main(int argc, char **argv) break; } - if (!*av) log_usage(*argv, "[-r rootdir] package[/version]"); + if (!*av) log_usage(*argv, "[-p pkgdir] [-d defdir] [-r rootdir] package[/version]"); if (!stat_isdir(def)) log_fatal_sys_1(101, def); if (!stat_isdir(root)) log_fatal_sys_1(101, root);