From 905d99ae32d66795c7025e3ddc68256f8161b6d7 Mon Sep 17 00:00:00 2001 From: obarun <eric@obarun.org> Date: Sat, 15 Oct 2022 20:58:46 +1100 Subject: [PATCH] adapt to new functions, some function need improvement --- src/lib66/graph/deps-lib/deps | 5 +- src/lib66/graph/graph_add_deps.c | 53 ----------- src/lib66/graph/graph_build_g.c | 20 ++-- src/lib66/graph/graph_build_service.c | 47 +++------ src/lib66/graph/graph_build_service_bytree.c | 90 ++++++++++-------- .../graph_build_service_bytree_from_src.c | 24 ++--- .../graph/graph_build_service_from_list.c | 95 +++++++++++++++++++ src/lib66/graph/graph_build_tree.c | 42 ++++---- 8 files changed, 196 insertions(+), 180 deletions(-) delete mode 100644 src/lib66/graph/graph_add_deps.c create mode 100644 src/lib66/graph/graph_build_service_from_list.c diff --git a/src/lib66/graph/deps-lib/deps b/src/lib66/graph/deps-lib/deps index 2c2b2334..56b8909b 100644 --- a/src/lib66/graph/deps-lib/deps +++ b/src/lib66/graph/deps-lib/deps @@ -1,11 +1,10 @@ -graph_add_deps.o -graph_build_g.o graph_build_service.o graph_build_service_bytree.o graph_build_service_bytree_from_src.o +graph_build_service_from_list.o graph_build_tree.o +graph_compute_dependencies.o graph_remove_deps.o -ss_resolve_graph.o -loblibs -lskarnet diff --git a/src/lib66/graph/graph_add_deps.c b/src/lib66/graph/graph_add_deps.c deleted file mode 100644 index ea34bb0f..00000000 --- a/src/lib66/graph/graph_add_deps.c +++ /dev/null @@ -1,53 +0,0 @@ -/* - * graph_add_deps.c - * - * Copyright (c) 2018-2021 Eric Vidal <eric@obarun.org> - * - * All rights reserved. - * - * This file is part of Obarun. It is subject to the license terms in - * the LICENSE file found in the top-level directory of this - * distribution. - * This file may not be copied, modified, propagated, or distributed - * except according to the terms contained in the LICENSE file./ - */ - -#include <stdint.h> - -#include <oblibs/graph.h> -#include <oblibs/log.h> -#include <oblibs/sastr.h> - -#include <skalibs/stralloc.h> - -int graph_add_deps(graph_t *g, char const *vertex, char const *edge, uint8_t requiredby) -{ - log_flow() ; - - stralloc sa = STRALLOC_ZERO ; - int e = 0 ; - if (!sastr_clean_string(&sa, edge)) { - log_warnu("rebuild dependencies list") ; - goto freed ; - } - - if (!requiredby) { - - if (!graph_vertex_add_with_nedge(g, vertex, &sa)) { - log_warnu("add edges at vertex: ", vertex) ; - goto freed ; - } - - } else { - - if (!graph_vertex_add_with_nrequiredby(g, vertex, &sa)) { - log_warnu("add requiredby at vertex: ", vertex) ; - goto freed ; - } - } - e = 1 ; - - freed: - stralloc_free(&sa) ; - return e ; -} diff --git a/src/lib66/graph/graph_build_g.c b/src/lib66/graph/graph_build_g.c index 1a8a45e0..0cb48611 100644 --- a/src/lib66/graph/graph_build_g.c +++ b/src/lib66/graph/graph_build_g.c @@ -12,29 +12,23 @@ * except according to the terms contained in the LICENSE file./ */ -#include <stdint.h> -#include <oblibs/graph.h> #include <oblibs/log.h> #include <66/service.h> -#include <66/tree.h> +#include <66/resolve.h> #include <66/graph.h> +#include <66/ssexec.h> -int graph_build_g(graph_t *g, char const *base, char const *treename, uint8_t data_type, uint8_t general) +void graph_build_g(graph_t *graph, resolve_service_t *ares, unsigned int *areslen, ssexec_t *info) { log_flow() ; - if (data_type == DATA_SERVICE) { + if (data_type == DATA_SERVICE) - if (!graph_build_service(g, base, treename, general)) - return 0 ; + graph_build_service(graph, ares, areslen, info) ; - } else if (data_type == DATA_TREE) { + else if (data_type == DATA_TREE) - if (!graph_build_tree(g, base)) - return 0 ; - } - - return 1 ; + graph_build_tree(g, info->base.s) ; } diff --git a/src/lib66/graph/graph_build_service.c b/src/lib66/graph/graph_build_service.c index 92e67dca..35547897 100644 --- a/src/lib66/graph/graph_build_service.c +++ b/src/lib66/graph/graph_build_service.c @@ -12,8 +12,8 @@ * except according to the terms contained in the LICENSE file./ */ -#include <stdint.h> #include <string.h> +#include <stdint.h> #include <oblibs/log.h> #include <oblibs/string.h> @@ -22,49 +22,24 @@ #include <skalibs/stralloc.h> #include <66/constants.h> -#include <66/tree.h> -#include <66/resolve.h> +#include <66/service.h> #include <66/graph.h> +#include <66/state.h> -/** - * @general has only effect for DATA_SERVICE type - * !general -> all services from @treename - * general -> all services from all trees of the system - * - * */ -int graph_build_service(graph_t *g, char const *base, char const *treename, uint8_t general) +void graph_build_service(graph_t *graph, resolve_service_t *ares, unsigned int *areslen, ssexec_t *info, uint32_t flag) { log_flow() ; - int e = 0 ; - size_t pos = 0, baselen = strlen(base) ; stralloc sa = STRALLOC_ZERO ; + char const *exclude[1] = { 0 } ; + char solve[info->base.len + SS_SYSTEM_LEN + SS_RESOLVE_LEN + 1 + SS_SERVICE_LEN + 1] ; - char solve[baselen + SS_SYSTEM_LEN + 1 + SS_MAX_TREENAME + SS_SVDIRS_LEN + 1] ; - - if (general) { - - if (!resolve_get_field_tosa_g(&sa, base, treename, SS_MASTER + 1, DATA_TREE_MASTER, E_RESOLVE_TREE_MASTER_CONTENTS)) - goto err ; - - FOREACH_SASTR(&sa, pos) { - - auto_strings(solve + baselen + SS_SYSTEM_LEN + 1, sa.s + pos, SS_SVDIRS) ; - - if (!graph_build_service_bytree(g, solve, 2)) - goto err ; - } - - } else { + auto_strings(solve, info->base.s, SS_SYSTEM, SS_RESOLVE, "/", SS_SERVICE) ; - auto_strings(solve, base, SS_SYSTEM, "/", treename, SS_SVDIRS) ; + if (!sastr_dir_get_recursive(&sa, solve, exclude, S_IFREG, 0)) + log_dieu(LOG_EXIT_SYS, "get resolve files") ; - if (!graph_build_service_bytree(g, solve, 2)) - goto err ; - } + service_graph_g(sa.s, sa.len, graph, ares, areslen, info, flag) ; - e = 1 ; - err: - stralloc_free(&sa) ; - return e ; + stralloc_free(&sa) ; } diff --git a/src/lib66/graph/graph_build_service_bytree.c b/src/lib66/graph/graph_build_service_bytree.c index 27416390..35bbb4e3 100644 --- a/src/lib66/graph/graph_build_service_bytree.c +++ b/src/lib66/graph/graph_build_service_bytree.c @@ -27,12 +27,18 @@ #include <66/service.h> #include <66/enum.h> #include <66/graph.h> +#include <66/state.h> +/* + * + * Need to be review entirely + * + * */ /** @tree: absolute path of the tree including SS_SVDIRS * what = 0 -> classic * what = 1 -> atomic and bundle * what > 1 -> module */ -int graph_build_service_bytree(graph_t *g, char const *tree, uint8_t what) +int graph_build_service_bytree(graph_t *g, char const *tree, uint8_t what, uint8_t is_supervised) { log_flow() ; @@ -44,32 +50,46 @@ int graph_build_service_bytree(graph_t *g, char const *tree, uint8_t what) resolve_service_master_t mres = RESOLVE_SERVICE_MASTER_ZERO ; resolve_wrapper_t_ref mwres = resolve_set_struct(DATA_SERVICE_MASTER, &mres) ; - if (!resolve_read_g(mwres, tree, SS_MASTER + 1)) { - log_warnu("read resolve Master file of trees") ; + if (!resolve_read(mwres, tree, SS_MASTER + 1)) { + log_warnu("read resolve Master service file of tree: ", tree) ; goto err ; } + /** + * + * + * a revoir ici les checks en fonction des appels qui sont fait + * notamment par 66-inservice, 66-intree + * + * + * + * */ + if (what == 2) + if (mres.ncontents) + if (!auto_stra(&sa, mres.sa.s + mres.contents)) + goto err ; - if (mres.nclassic) - if (!auto_stra(&sa, mres.sa.s + mres.classic)) - goto err ; + if (!what) + if (mres.nclassic) + if (!auto_stra(&sa, mres.sa.s + mres.classic)) + goto err ; - if (mres.nmodule) - if (!auto_stra(&sa, mres.sa.s + mres.module)) - goto err ; + if (what > 1) + if (mres.nmodule) + if (!auto_stra(&sa, mres.sa.s + mres.module)) + goto err ; - if (mres.nbundle) - if (!auto_stra(&sa, mres.sa.s + mres.bundle)) - goto err ; + if (what == 1) { - if (mres.nlongrun) - if (!auto_stra(&sa, mres.sa.s + mres.longrun)) - goto err ; + if (mres.nbundle) + if (!auto_stra(&sa, mres.sa.s + mres.bundle)) + goto err ; - if (mres.noneshot) - if (!auto_stra(&sa, mres.sa.s + mres.oneshot)) - goto err ; + if (mres.noneshot) + if (!auto_stra(&sa, mres.sa.s + mres.oneshot)) + goto err ; + } - if (!sastr_clean_string_g(&sa, sa.s)) + if (!sastr_clean_string_flush_sa(&sa, sa.s)) goto err ; FOREACH_SASTR(&sa, pos) { @@ -79,6 +99,14 @@ int graph_build_service_bytree(graph_t *g, char const *tree, uint8_t what) if (!resolve_read(wres, tree, service)) goto err ; + if (is_supervised) { + + char atree[strlen(res.sa.s + res.treename) + 1] ; + + if (!service_is_g(atree, service, STATE_FLAGS_ISSUPERVISED)) + continue ; + } + char *str = res.sa.s ; if (!graph_vertex_add(g, service)) { @@ -86,29 +114,17 @@ int graph_build_service_bytree(graph_t *g, char const *tree, uint8_t what) goto err ; } - if (res.ndepends) { + if (res.dependencies.ndepends) { - if (res.type == TYPE_MODULE || res.type == TYPE_BUNDLE) { - - uint32_t depends = res.type == TYPE_MODULE ? what > 1 ? res.contents : res.depends : res.depends ; - - if (!graph_add_deps(g, service, str + depends, 0)) { - log_warnu("add dependencies of service: ",service) ; - goto err ; - } - - } else { - - if (!graph_add_deps(g, service,str + res.depends, 0)) { - log_warnu("add dependencies of service: ",service) ; - goto err ; - } + if (!graph_compute_dependencies(g, service,str + res.dependencies.depends, 0)) { + log_warnu("add dependencies of service: ",service) ; + goto err ; } } - if (res.nrequiredby) { + if (res.dependencies.nrequiredby) { - if (!graph_add_deps(g, service, str + res.requiredby, 1)) { + if (!graph_compute_dependencies(g, service, str + res.dependencies.requiredby, 1)) { log_warnu("add requiredby of service: ", service) ; goto err ; } diff --git a/src/lib66/graph/graph_build_service_bytree_from_src.c b/src/lib66/graph/graph_build_service_bytree_from_src.c index 1b86df23..2a9972f8 100644 --- a/src/lib66/graph/graph_build_service_bytree_from_src.c +++ b/src/lib66/graph/graph_build_service_bytree_from_src.c @@ -70,29 +70,17 @@ int graph_build_service_bytree_from_src(graph_t *g, char const *src, uint8_t wha goto err ; } - if (res.ndepends) { + if (res.dependencies.ndepends) { - if (res.type == TYPE_MODULE || res.type == TYPE_BUNDLE) { - - uint32_t depends = res.type == TYPE_MODULE ? what > 1 ? res.contents : res.depends : res.depends ; - - if (!graph_add_deps(g, service, str + depends, 0)) { - log_warnu("add dependencies of service: ",service) ; - goto err ; - } - - } else { - - if (!graph_add_deps(g, service,str + res.depends, 0)) { - log_warnu("add dependencies of service: ",service) ; - goto err ; - } + if (!graph_compute_dependencies(g, service,str + res.dependencies.depends, 0)) { + log_warnu("add dependencies of service: ",service) ; + goto err ; } } - if (res.nrequiredby) { + if (res.dependencies.nrequiredby) { - if (!graph_add_deps(g, service, str + res.requiredby, 1)) { + if (!graph_compute_dependencies(g, service, str + res.dependencies.requiredby, 1)) { log_warnu("add requiredby of service: ", service) ; goto err ; } diff --git a/src/lib66/graph/graph_build_service_from_list.c b/src/lib66/graph/graph_build_service_from_list.c new file mode 100644 index 00000000..c9f65bee --- /dev/null +++ b/src/lib66/graph/graph_build_service_from_list.c @@ -0,0 +1,95 @@ +/* + * graph_build_service_from_list.c + * + * Copyright (c) 2018-2022 Eric Vidal <eric@obarun.org> + * + * All rights reserved. + * + * This file is part of Obarun. It is subject to the license terms in + * the LICENSE file found in the top-level directory of this + * distribution. + * This file may not be copied, modified, propagated, or distributed + * except according to the terms contained in the LICENSE file./ + */ + +#include <string.h> +#include <stdlib.h> + +#include <oblibs/log.h> +#include <oblibs/string.h> +#include <oblibs/graph.h> + +#include <skalibs/genalloc.h> + +#include <66/config.h> +#include <66/graph.h> +#include <66/service.h> +#include <66/resolve.h> +#include <66/constants.h> +#include <66/state.h> + +int graph_build_service_from_list(char const *const *list, char const *base, graph_t *graph, resolve_service_t *ares, uint8_t requiredby) +{ + log_flow() ; + + + unsigned int areslen = 0, e = 0 ; + char atree[SS_MAX_TREENAME + 1] ; + + for (; *list ; list++) { + + int found = 0 ; + unsigned int pos = 0, ndeps = 0 ; + unsigned int alist[graph->mlen] ; + char const *name = *list ; + + resolve_service_t res = RESOLVE_SERVICE_ZERO ; + resolve_wrapper_t_ref wres = resolve_set_struct(DATA_SERVICE, &res) ; + + graph_array_init_single(alist, graph->mlen) ; + + resolve_service_t cp = RESOLVE_SERVICE_ZERO ; + + if (!resolve_read_g(wres, base, name)) + goto err ; + + if (!service_resolve_copy(&cp, &res)) + goto err ; + + if (service_resolve_array_search(ares, areslen, name) < 0) + ares[areslen++] = cp ; + + ndeps = graph_matrix_get_edge_g_list(alist, graph, name, requiredby, 1) ; + if (ndeps < 0) + goto err ; + + for (; pos < ndeps ; pos++) { + + char *name = graph->data.s + genalloc_s(graph_hash_t, &graph->hash)[alist[pos]].vertex ; + + if (service_resolve_array_search(ares, areslen, name) < 0) { + + resolve_service_t cp = RESOLVE_SERVICE_ZERO ; + + found = service_is_g(atree, name, STATE_FLAGS_ISPARSED) ; + if (found <= 0) + goto err ; + + if (!resolve_read_g(wres, base, name)) + goto err ; + + if (!service_resolve_copy(&cp, &res)) + goto err ; + + ares[areslen++] = cp ; + } + } + resolve_free(wres) ; + } + + e = areslen ; + + err: + + return e ; +} diff --git a/src/lib66/graph/graph_build_tree.c b/src/lib66/graph/graph_build_tree.c index 43e2c86f..155069f5 100644 --- a/src/lib66/graph/graph_build_tree.c +++ b/src/lib66/graph/graph_build_tree.c @@ -25,47 +25,49 @@ #include <66/constants.h> #include <66/resolve.h> #include <66/tree.h> +#include <66/graph.h> -int graph_build_tree(graph_t *g, char const *base) +void graph_build_tree(graph_t *g, char const *base) { log_flow() ; - int e = 0 ; - size_t baselen = strlen(base), pos = 0 ; - char solve[baselen + SS_SYSTEM_LEN + 1] ; + size_t pos = 0 ; stralloc sa = STRALLOC_ZERO ; resolve_tree_t tres = RESOLVE_TREE_ZERO ; resolve_wrapper_t_ref wres = resolve_set_struct(DATA_TREE, &tres) ; - if (!resolve_get_field_tosa_g(&sa, base, 0, SS_MASTER + 1, DATA_TREE_MASTER, TREE_ENUM_MASTER_CONTENTS)) - goto err ; - - auto_strings(solve, base, SS_SYSTEM) ; + if (!resolve_get_field_tosa_g(&sa, base, SS_MASTER + 1, DATA_TREE_MASTER, E_RESOLVE_TREE_MASTER_CONTENTS)) + log_dieu(LOG_EXIT_SYS, "get resolve Master file of trees") ; FOREACH_SASTR(&sa, pos) { char *name = sa.s + pos ; - if (!resolve_read(wres, solve, name)) - goto err ; + if (!resolve_read_g(wres, base, name)) + log_dieu(LOG_EXIT_SYS, "read resolve file of: ", name) ; if (!graph_vertex_add(g, name)) - goto err ; + log_dieu(LOG_EXIT_SYS, "add vertex of: ", name) ; if (tres.ndepends) - if (!graph_add_deps(g, name, tres.sa.s + tres.depends, 0)) - goto err ; + if (!graph_compute_dependencies(g, name, tres.sa.s + tres.depends, 0)) + log_dieu(LOG_EXIT_SYS, "compute dependencies of: ", name) ; if (tres.nrequiredby) - if (!graph_add_deps(g, name, tres.sa.s + tres.requiredby, 1)) - goto err ; + if (!graph_compute_dependencies(g, name, tres.sa.s + tres.requiredby, 1)) + log_dieu(LOG_EXIT_SYS, "compute requiredby of: ", name) ; } - e = 1 ; + if (!graph_matrix_build(g)) + log_dieu(LOG_EXIT_SYS, "build the graph") ; + + if (!graph_matrix_analyze_cycle(g)) + log_dieu(LOG_EXIT_SYS, "found cycle") ; + + if (!graph_matrix_sort(g)) + log_dieu(LOG_EXIT_SYS, "sort the graph") ; - err: - resolve_free(wres) ; - stralloc_free(&sa) ; - return e ; + resolve_free(wres) ; + stralloc_free(&sa) ; } -- GitLab