diff --git a/src/lib66/graph/deps-lib/deps b/src/lib66/graph/deps-lib/deps index a4ea9b288ad5fd720787c3d91c3439f9628b6372..85d7026bfc597db299208a09739f7e4229a63ef6 100644 --- a/src/lib66/graph/deps-lib/deps +++ b/src/lib66/graph/deps-lib/deps @@ -1,7 +1,12 @@ -graph.o +graph_add_deps.o +graph_build_g.o +graph_build_service_bytree.o +graph_build_tree.o +graph_remove_deps.o ss_resolve_graph.o -ls6rc -ls6 -loblibs -lexecline -lskarnet + diff --git a/src/lib66/graph/graph.c b/src/lib66/graph/graph.c deleted file mode 100644 index 1612b184a865af7680c67368ca01b45b447d3325..0000000000000000000000000000000000000000 --- a/src/lib66/graph/graph.c +++ /dev/null @@ -1,289 +0,0 @@ -/* - * graph.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 <string.h> -#include <stdint.h> - -#include <oblibs/string.h> -#include <oblibs/log.h> -#include <oblibs/sastr.h> - -#include <skalibs/genalloc.h> - -#include <66/graph.h> -#include <66/service.h> -#include <66/resolve.h> -#include <66/constants.h> -#include <66/enum.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 ; -} - -/* -int graph_remove_deps(graph_t *g, char const *vertex, char const *edge, uint8_t requiredby) -{ - int e = 0 ; - - if (!requiredby) { - - if (!graph_edge_remove_g(g, vertex, edge)) - log_warnu_return(LOG_EXIT_ZERO, "remove edge at vertex: ", vertex) ; - - } else { - - if (!graph_edge_remove_g(g, edge, vertex)) - } - - e = 1 ; - - freed: - return e ; -} -*/ - -/** - * - * - * - * - * a revoir auto_strings(solve, base, SS_SYSTEM, SS_RESOLVE) ; c'est faux pour les services - * - * - * - * - * */ - -int graph_build_g(graph_t *g, char const *base, char const *treename, uint8_t data_type) -{ - log_flow() ; - - if (data_type == DATA_SERVICE) { - - //if (!graph_build_service(g, base, treename)) - return 0 ; - - } else if (data_type == DATA_TREE) { - - //if (!graph_build_tree(g, base)) - return 0 ; - } - - if (!graph_matrix_build(g)) - log_warnu_return(LOG_EXIT_ZERO, "build the graph") ; - - if (!graph_matrix_analyze_cycle(g)) - log_warnu_return(LOG_EXIT_ZERO, "found cycle") ; - - if (!graph_matrix_sort(g)) - log_warnu_return(LOG_EXIT_ZERO, "sort the graph") ; - - return 1 ; -} - -int graph_build(graph_t *g, char const *base, char const *treename, uint8_t what) -{ - log_flow() ; - - int e = 0 ; - size_t baselen = strlen(base), treelen = strlen(treename), pos = 0 ; - char const *exclude[2] = { SS_MASTER + 1, 0 } ; - char solve[baselen + SS_SYSTEM_LEN + SS_RESOLVE_LEN + 1 + treelen + 1] ; - - stralloc sa = STRALLOC_ZERO ; - resolve_tree_t tres = RESOLVE_TREE_ZERO ; - resolve_wrapper_t_ref wres = resolve_set_struct(DATA_TREE, &tres) ; - - RESOLVE_SET_SAWRES(wres) ; - - auto_strings(solve, base, SS_SYSTEM, SS_RESOLVE) ; - - if (!sastr_dir_get(&sa, solve, exclude, S_IFREG)) - goto err ; - - solve[baselen + SS_SYSTEM_LEN] = 0 ; - - FOREACH_SASTR(&sa, pos) { - - char *name = sa.s + pos ; - - if (!resolve_read(wres, solve, name)) - goto err ; - - if (what == DATA_SERVICE) { - - auto_strings(solve + baselen + SS_SYSTEM_LEN, "/", treename) ; - - if (!graph_build_service_bytree(g, solve, 2)) - goto err ; - - } else if (what == DATA_TREE) { - - if (!graph_vertex_add(g, name)) - goto err ; - - if (tres.ndepends) - if (!graph_add_deps(g, name, sawres->s + tres.depends, 0)) - goto err ; - - if (tres.nrequiredby) - if (!graph_add_deps(g, name, sawres->s + tres.requiredby, 1)) - goto err ; - } - } - - if (!graph_matrix_build(g)) { - log_warnu("build the graph") ; - goto err ; - } - - if (!graph_matrix_analyze_cycle(g)) { - log_warn("found cycle") ; - goto err ; - } - - if (!graph_matrix_sort(g)) { - log_warnu("sort the graph") ; - goto err ; - } - - e = 1 ; - - err: - resolve_free(wres) ; - stralloc_free(&sa) ; - return e ; -} - -/** @tree: absolute path of the tree - * 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) -{ - log_flow() ; - - int e = 0 ; - stralloc sa = STRALLOC_ZERO ; - resolve_service_t res = RESOLVE_SERVICE_ZERO ; - resolve_wrapper_t_ref wres = resolve_set_struct(DATA_SERVICE, &res) ; - - size_t treelen = strlen(tree), pos = 0 ; - char solve[treelen + SS_SVDIRS_LEN + SS_RESOLVE_LEN + 1] ; - - auto_strings(solve, tree, SS_SVDIRS, SS_RESOLVE) ; - - char const *exclude[2] = { SS_MASTER + 1, 0 } ; - - if (!sastr_dir_get(&sa,solve,exclude,S_IFREG)) - goto err ; - - solve[treelen + SS_SVDIRS_LEN] = 0 ; - - if (!service_resolve_sort_bytype(&sa, solve)) - goto err ; - - FOREACH_SASTR(&sa, pos) { - - char *service = sa.s + pos ; - - if (!resolve_read(wres, solve, service)) - goto err ; - - char *str = res.sa.s ; - - if (!graph_vertex_add(g, service)) { - log_warnu("add vertex: ", service) ; - goto err ; - } - - if (res.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 (res.nrequiredby) { - - if (!graph_add_deps(g, service, str + res.requiredby, 1)) { - log_warnu("add requiredby of service: ", service) ; - goto err ; - } - } - } - - if (!graph_matrix_build(g)) { - log_warnu("build the graph") ; - goto err ; - } - - if (!graph_matrix_analyze_cycle(g)) { - log_warn("found cycle") ; - goto err ; - } - - if (!graph_matrix_sort(g)) { - log_warnu("sort the graph") ; - goto err ; - } - - e = 1 ; - - err: - resolve_free(wres) ; - stralloc_free(&sa) ; - return e ; -} diff --git a/src/lib66/graph/graph_add_deps.c b/src/lib66/graph/graph_add_deps.c new file mode 100644 index 0000000000000000000000000000000000000000..ea34bb0fe74895fbfdad2717d5f4043a12d9f992 --- /dev/null +++ b/src/lib66/graph/graph_add_deps.c @@ -0,0 +1,53 @@ +/* + * 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 new file mode 100644 index 0000000000000000000000000000000000000000..92ee9d8e5cb0ee15e9dc4fe4fbf84e84671f7a6d --- /dev/null +++ b/src/lib66/graph/graph_build_g.c @@ -0,0 +1,47 @@ +/* + * graph_build_g.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 <stdint.h> + +#include <oblibs/graph.h> +#include <oblibs/log.h> + +#include <66/graph.h> + +int graph_build_g(graph_t *g, char const *base, char const *treename, uint8_t data_type) +{ + log_flow() ; + + if (data_type == DATA_SERVICE) { + + //if (!graph_build_service(g, base, treename)) + return 0 ; + + } else if (data_type == DATA_TREE) { + + if (!graph_build_tree(g, base)) + return 0 ; + } + + if (!graph_matrix_build(g)) + log_warnu_return(LOG_EXIT_ZERO, "build the graph") ; + + if (!graph_matrix_analyze_cycle(g)) + log_warnu_return(LOG_EXIT_ZERO, "found cycle") ; + + if (!graph_matrix_sort(g)) + log_warnu_return(LOG_EXIT_ZERO, "sort the graph") ; + + return 1 ; +} diff --git a/src/lib66/graph/graph_build_service_bytree.c b/src/lib66/graph/graph_build_service_bytree.c new file mode 100644 index 0000000000000000000000000000000000000000..6cf42ea4a73253148d7f6d28b3a15a695ca08b12 --- /dev/null +++ b/src/lib66/graph/graph_build_service_bytree.c @@ -0,0 +1,123 @@ +/* + * graph_build_service_bytree.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 <stdint.h> +#include <string.h> + +#include <oblibs/log.h> +#include <oblibs/graph.h> +#include <oblibs/string.h> +#include <oblibs/sastr.h> + +#include <skalibs/stralloc.h> + +#include <66/resolve.h> +#include <66/constants.h> +#include <66/service.h> +#include <66/enum.h> +#include <66/graph.h> + +/** @tree: absolute path of the tree + * 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) +{ + log_flow() ; + + int e = 0 ; + stralloc sa = STRALLOC_ZERO ; + resolve_service_t res = RESOLVE_SERVICE_ZERO ; + resolve_wrapper_t_ref wres = resolve_set_struct(DATA_SERVICE, &res) ; + + size_t treelen = strlen(tree), pos = 0 ; + char solve[treelen + SS_SVDIRS_LEN + SS_RESOLVE_LEN + 1] ; + + auto_strings(solve, tree, SS_SVDIRS, SS_RESOLVE) ; + + char const *exclude[2] = { SS_MASTER + 1, 0 } ; + + if (!sastr_dir_get(&sa,solve,exclude,S_IFREG)) + goto err ; + + solve[treelen + SS_SVDIRS_LEN] = 0 ; + + if (!service_resolve_sort_bytype(&sa, solve)) + goto err ; + + FOREACH_SASTR(&sa, pos) { + + char *service = sa.s + pos ; + + if (!resolve_read(wres, solve, service)) + goto err ; + + char *str = res.sa.s ; + + if (!graph_vertex_add(g, service)) { + log_warnu("add vertex: ", service) ; + goto err ; + } + + if (res.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 (res.nrequiredby) { + + if (!graph_add_deps(g, service, str + res.requiredby, 1)) { + log_warnu("add requiredby of service: ", service) ; + goto err ; + } + } + } + + if (!graph_matrix_build(g)) { + log_warnu("build the graph") ; + goto err ; + } + + if (!graph_matrix_analyze_cycle(g)) { + log_warn("found cycle") ; + goto err ; + } + + if (!graph_matrix_sort(g)) { + log_warnu("sort the graph") ; + goto err ; + } + + e = 1 ; + + err: + resolve_free(wres) ; + stralloc_free(&sa) ; + return e ; +} diff --git a/src/lib66/graph/graph_build_tree.c b/src/lib66/graph/graph_build_tree.c new file mode 100644 index 0000000000000000000000000000000000000000..60312b0d5261262b49eb38457cb29557311865f2 --- /dev/null +++ b/src/lib66/graph/graph_build_tree.c @@ -0,0 +1,75 @@ +/* + * graph_build_tree.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 <string.h> +#include <sys/stat.h> + +#include <oblibs/graph.h> +#include <oblibs/log.h> +#include <oblibs/string.h> +#include <oblibs/sastr.h> + +#include <skalibs/stralloc.h> + +#include <66/constants.h> +#include <66/resolve.h> +#include <66/tree.h> + + +int graph_build_tree(graph_t *g, char const *base) +{ + log_flow() ; + + int e = 0 ; + size_t baselen = strlen(base), pos = 0 ; + char const *exclude[2] = { SS_MASTER + 1, 0 } ; + char solve[baselen + SS_SYSTEM_LEN + SS_RESOLVE_LEN + 1] ; + + stralloc sa = STRALLOC_ZERO ; + resolve_tree_t tres = RESOLVE_TREE_ZERO ; + resolve_wrapper_t_ref wres = resolve_set_struct(DATA_TREE, &tres) ; + + auto_strings(solve, base, SS_SYSTEM, SS_RESOLVE) ; + + if (!sastr_dir_get(&sa, solve, exclude, S_IFREG)) + goto err ; + + solve[baselen + SS_SYSTEM_LEN] = 0 ; + + FOREACH_SASTR(&sa, pos) { + + char *name = sa.s + pos ; + + if (!resolve_read(wres, solve, name)) + goto err ; + + if (!graph_vertex_add(g, name)) + goto err ; + + if (tres.ndepends) + if (!graph_add_deps(g, name, tres.sa.s + tres.depends, 0)) + goto err ; + + if (tres.nrequiredby) + if (!graph_add_deps(g, name, tres.sa.s + tres.requiredby, 1)) + goto err ; + } + + e = 1 ; + + err: + resolve_free(wres) ; + stralloc_free(&sa) ; + return e ; +} diff --git a/src/lib66/graph/graph_remove_deps.c b/src/lib66/graph/graph_remove_deps.c new file mode 100644 index 0000000000000000000000000000000000000000..cf03734321a30d50176c64d08060ccd3a76dd6d8 --- /dev/null +++ b/src/lib66/graph/graph_remove_deps.c @@ -0,0 +1,40 @@ +/* + * graph_remove_deps.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 <stdint.h> + +#include <oblibs/graph.h> +#include <oblibs/log.h> + +/* +int graph_remove_deps(graph_t *g, char const *vertex, char const *edge, uint8_t requiredby) +{ + int e = 0 ; + + if (!requiredby) { + + if (!graph_edge_remove_g(g, vertex, edge)) + log_warnu_return(LOG_EXIT_ZERO, "remove edge at vertex: ", vertex) ; + + } else { + + if (!graph_edge_remove_g(g, edge, vertex)) + } + + e = 1 ; + + freed: + return e ; +} +*/