package

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

commit 778bc8ce8ad9f7f7cbf540b63369be180a722fe4
parent 09e9642f2040cd5fc9fae68d147625d1fd7be456
Author: Josuah Demangeon <mail@josuah.net>
Date:   Mon,  7 Jan 2019 23:32:06 +0100

fix dependency order

Diffstat:
Mpack-dep.c | 45+++++++++++++++++----------------------------
1 file changed, 17 insertions(+), 28 deletions(-)

diff --git a/pack-dep.c b/pack-dep.c @@ -25,7 +25,7 @@ pack_hasdep(pack const *p, genalloc *packs) } static int -pack_dep_recurse(pack const *p, genalloc *packs, char const *def) +pack_dep(pack const *p, genalloc *packs, char const *def) { stralloc path = STRALLOC_ZERO; stralloc line = STRALLOC_ZERO; @@ -51,8 +51,8 @@ pack_dep_recurse(pack const *p, genalloc *packs, char const *def) if (!pack_version(&new, def)) goto err; if (pack_hasdep(&new, packs)) continue; + if (!pack_dep(&new, packs, def)) goto err; if (!genalloc_append(packs, new)) goto err; - if (!pack_dep_recurse(&new, packs, def)) goto err; } ret = (r == 0); @@ -63,21 +63,6 @@ err: stralloc_free(&line); return ret; } -static int -pack_dep(genalloc *packs, char const *def) -{ - size_t n = genalloc_len(packs, pack); - size_t i; - - for (i = 0; i < n; ++i) { - pack *p = genalloc_get(packs, pack, i); - if (!pack_version(p, def)) return 0; - if (!pack_dep_recurse(p, packs, def)) return 0; - } - - return 1; -} - int main(int argc, char **argv) { @@ -87,8 +72,11 @@ main(int argc, char **argv) struct stat st; genalloc packs; size_t i; + size_t n; + pack p; - if (argc < 2) log_usage(*argv, "package[/version] ..."); + if (argc != 2) log_usage(*argv, "package[/version]"); + ++argv; def = env_get("PACK_DEF"); if (!def) def = PACK_DEF; @@ -97,26 +85,27 @@ main(int argc, char **argv) genalloc_init(&packs); - while (*++argv) { - pack p; - size_t n = pack_scan(&p, *argv); + n = pack_scan(&p, *argv); + if (n == 0 || (*argv)[n] != '\0') + log_die2(1, "invalid package name: ", *argv); - if (n == 0 || (*argv)[n] != '\0') log_die2(1, "invalid package name: ", *argv); - genalloc_append(&packs, p); - } + if (!pack_version(&p, def)) + log_diesys3(103, "could not get ", *argv," version"); - if (!pack_dep(&packs, def)) + if (!pack_dep(&p, &packs, def)) log_diesys1(103, "could not resolve package dependencies"); - i = genalloc_len(&packs, pack) - 1; - do { + if (!genalloc_append(&packs, p)) + log_diesys1(103, "malloc"); + + for (i = 0; i < genalloc_len(&packs, pack); ++i) { char fmt[PACK_FMT]; pack *p = genalloc_get(&packs, pack, i); pack_fmt(p, fmt); buffer_puts(buffer_1, fmt); buffer_putc(buffer_1, '\n'); - } while (i-- > 0); + } buffer_flush(buffer_1); return 0;