2 # aur-graph - print package/dependency pairs
4 # shellcheck disable=all
7 # = 0 : if ver1 == ver2
9 function get_vercmp
(ver1
, ver2
, op
) {
10 command =
("vercmp " ver1
" " ver2
)
12 if (op ==
"-" || ver2 ==
"-") {
13 return "true" # dependency is unversioned
14 } else if (op ==
"=") {
15 return (ver1 == ver2
) # common case
16 } else if (op ==
"<") {
20 } else if (op ==
">") {
24 } else if (op ==
"<=") {
28 } else if (op ==
">=") {
33 printf("invalid operation\n") > "/dev/stderr"
38 function setopt
(opt
, default
) {
45 function has_valid_arch
(attr
) {
47 return !i
|| (substr(attr
, i
+1) in arch
)
51 DEPENDS = setopt
(DEPENDS
, 1)
52 MAKEDEPENDS = setopt
(MAKEDEPENDS
, 1)
53 CHECKDEPENDS = setopt
(CHECKDEPENDS
, 1)
54 OPTDEPENDS = setopt
(OPTDEPENDS
, 0)
55 PRINTALL = setopt
(PRINTALL
, 0)
65 # track both the pkgbases themselves and their number of deps
66 dep_counts
[pkgbase
] =
0
69 $
1 ==
"pkgver" && !in_split_pkg
{
77 index($
1, "depends") ==
1 && !in_split_pkg
{
78 if (DEPENDS
&& has_valid_arch
($
1))
79 pkg_deps
[pkgbase
, ++dep_counts
[pkgbase
]] = $
3
82 index($
1, "makedepends") ==
1 && !in_split_pkg
{
83 if (MAKEDEPENDS
&& has_valid_arch
($
1))
84 pkg_deps
[pkgbase
, ++dep_counts
[pkgbase
]] = $
3
87 index($
1, "checkdepends") ==
1 && !in_split_pkg
{
88 if (CHECKDEPENDS
&& has_valid_arch
($
1))
89 pkg_deps
[pkgbase
, ++dep_counts
[pkgbase
]] = $
3
92 index($
1, "optdepends") ==
1 && !in_split_pkg
{
93 if (OPTDEPENDS
&& has_valid_arch
($
1))
94 pkg_deps
[pkgbase
, ++dep_counts
[pkgbase
]] = $
3
102 pkg_map
[$
3] = pkgbase
# node
103 ver_map
[$
3] = pkgver
# weight
106 index($
1, "provides") ==
1 && has_valid_arch
($
1) {
109 # if provider is unversioned, use pkgver
111 ver_map
[prov
[1]] = prov
[2]
113 ver_map
[prov
[1]] = pkgver
116 pkg_map
[prov
[1]] = pkgbase
122 for (pkgbase in dep_counts
) {
123 # add a loop to isolated nodes (#402)
124 printf("%s\t%s\n", pkgbase
, pkgbase
)
126 for (dep =
1; dep
<= dep_counts
[pkgbase
]; dep
++) {
128 printf("%s\t%s\n", pkgbase
, pkg_deps
[pkgbase
, dep
])
131 dep_op =
"-" # unversioned / no comparison
133 # valid operators (important: <= before <)
134 split("<=|>=|<|=|>", cmp
, "|")
136 # split: fourth argument is gawk extension
138 split(pkg_deps
[pkgbase
, dep
], dep_split
, cmp
[i
])
140 if ("2" in dep_split
) {
146 if ("1" in dep_split
)
147 dep_pkgname = dep_split
[1]
151 if ("2" in dep_split
)
152 dep_pkgver = dep_split
[2]
156 # only print dependency if it was encountered before
157 if (dep_pkgname in pkg_map ==
0)
160 # run vercmp with provider and versioned dependency
161 if (get_vercmp
(ver_map
[dep_pkgname
], dep_pkgver
, dep_op
)) {
162 printf("%s\t%s\n", pkgbase
, pkg_map
[dep_pkgname
])
164 printf("invalid node: %s %s (required: %s%s)\n",
165 dep_pkgname
, ver_map
[dep_pkgname
], dep_op
, dep_pkgver
) > "/dev/stderr"
168 # delay mismatches to loop end