Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
6
66
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eric Vidal
66
Commits
5071faca
Commit
5071faca
authored
3 years ago
by
Eric Vidal
Browse files
Options
Downloads
Patches
Plain Diff
[WIP] add graph_build function, change format of graph_add_deps function
parent
857b1ec2
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/include/66/graph.h
+3
-3
3 additions, 3 deletions
src/include/66/graph.h
src/lib66/graph.c
+169
-12
169 additions, 12 deletions
src/lib66/graph.c
with
172 additions
and
15 deletions
src/include/66/graph.h
+
3
−
3
View file @
5071faca
...
...
@@ -19,8 +19,8 @@
#include
<oblibs/graph.h>
extern
int
graph_
service_
add_deps
(
graph_t
*
g
,
char
const
*
s
er
vice
,
char
const
*
deps
)
;
extern
int
graph_
service_build_bytree
(
graph_t
*
g
,
char
const
*
tree
,
uint8_t
what
)
;
extern
int
graph_add_deps
(
graph_t
*
g
,
char
const
*
v
er
tex
,
char
const
*
edge
,
uint8_t
requiredby
)
;
extern
int
graph_
build
(
graph_t
*
g
,
char
const
*
base
,
char
const
*
tree
name
,
uint8_t
what
)
;
extern
int
graph_build_service_bytree
(
graph_t
*
g
,
char
const
*
tree
,
uint8_t
what
)
;
#endif
This diff is collapsed.
Click to expand it.
src/lib66/graph.c
+
169
−
12
View file @
5071faca
...
...
@@ -27,23 +27,169 @@
#include
<66/constants.h>
#include
<66/enum.h>
int
graph_
service_
add_deps
(
graph_t
*
g
,
char
const
*
s
er
vice
,
char
const
*
deps
)
int
graph_add_deps
(
graph_t
*
g
,
char
const
*
v
er
tex
,
char
const
*
edge
,
uint8_t
requiredby
)
{
log_flow
()
;
stralloc
sa
=
STRALLOC_ZERO
;
u
int
8_t
e
=
0
;
if
(
!
sastr_clean_string
(
&
sa
,
deps
))
{
int
e
=
0
;
if
(
!
sastr_clean_string
(
&
sa
,
edge
))
{
log_warnu
(
"rebuild dependencies list"
)
;
goto
freed
;
}
if
(
!
graph_vertex_add_with_nedge
(
g
,
service
,
&
sa
))
{
log_warnu
(
"add edges at vertex: "
,
service
)
;
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
;
}
...
...
@@ -52,14 +198,14 @@ int graph_service_add_deps(graph_t *g, char const *service, char const *deps)
* what = 0 -> classic
* what = 1 -> atomic and bundle
* what > 1 -> module */
int
graph_service_
build_
bytree
(
graph_t
*
g
,
char
const
*
tree
,
uint8_t
what
)
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
(
SERVICE
_STRUCT
,
&
res
)
;
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
]
;
...
...
@@ -73,6 +219,9 @@ int graph_service_build_bytree(graph_t *g, char const *tree, uint8_t what)
solve
[
treelen
+
SS_SVDIRS_LEN
]
=
0
;
if
(
!
service_resolve_sort_bytype
(
&
sa
,
solve
))
goto
err
;
FOREACH_SASTR
(
&
sa
,
pos
)
{
char
*
service
=
sa
.
s
+
pos
;
...
...
@@ -87,25 +236,33 @@ int graph_service_build_bytree(graph_t *g, char const *tree, uint8_t what)
goto
err
;
}
if
(
res
.
ndep
s
>
0
)
{
if
(
res
.
ndep
ends
)
{
if
(
res
.
type
==
TYPE_MODULE
||
res
.
type
==
TYPE_BUNDLE
)
{
uint32_t
deps
=
res
.
type
==
TYPE_MODULE
?
what
>
1
?
res
.
contents
:
res
.
deps
:
res
.
deps
;
uint32_t
dep
end
s
=
res
.
type
==
TYPE_MODULE
?
what
>
1
?
res
.
contents
:
res
.
dep
end
s
:
res
.
dep
end
s
;
if
(
!
graph_
service_
add_deps
(
g
,
service
,
str
+
dep
s
))
{
if
(
!
graph_add_deps
(
g
,
service
,
str
+
dep
ends
,
0
))
{
log_warnu
(
"add dependencies of service: "
,
service
)
;
goto
err
;
}
}
else
{
if
(
!
graph_
service_
add_deps
(
g
,
service
,
str
+
res
.
dep
s
))
{
if
(
!
graph_add_deps
(
g
,
service
,
str
+
res
.
dep
ends
,
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
))
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment