3 # $NetBSD: reduce-depends.awk,v 1.1 2011/10/15 00:23:09 reed Exp $
5 # Copyright (c) 2006 The NetBSD Foundation, Inc.
8 # This code is derived from software contributed to The NetBSD Foundation
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
19 # 3. All advertising materials mentioning features or use of this software
20 # must display the following acknowledgement:
21 # This product includes software developed by the NetBSD
22 # Foundation, Inc. and its contributors.
23 # 4. Neither the name of The NetBSD Foundation nor the names of its
24 # contributors may be used to endorse or promote products derived
25 # from this software without specific prior written permission.
27 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 # POSSIBILITY OF SUCH DAMAGE.
40 ######################################################################
43 # reduce-depends.awk -- reduce a list of dependencies
46 # reduce-depends.awk "depends_list"
49 # reduce-depends.awk removes some extraneous dependencies from the
50 # dependency list. The dependency list should be passed as a single
51 # argument, and the output will be a list of the reduced dependencies,
52 # echo one on a new line.
60 ######################################################################
63 CAT =
ENVIRON["CAT"] ?
ENVIRON["CAT"] : "cat"
64 PKG_ADMIN =
ENVIRON["PKG_ADMIN"] ?
ENVIRON["PKG_ADMIN"] : "pkg_admin"
65 PWD_CMD =
ENVIRON["PWD_CMD"] ?
ENVIRON["PWD_CMD"] : "pwd -P"
66 TEST =
ENVIRON["TEST"] ?
ENVIRON["TEST"] : "test"
68 PROGNAME =
"reduce-depends.awk"
71 # Gather all dependencies into the depends array. Index 0 of the
72 # depends[pkgpath] array is the number of patterns associated with
76 ARGC =
split(args
, ARGV); ARGC++
77 for (i =
1; i
< ARGC; i
++) {
78 pattern =
ARGV[i
]; sub(":.*", "", pattern
)
79 dir =
ARGV[i
]; sub(".*:", "", dir
)
80 if (pattern
":" dir
!= ARGV[i
]) {
81 print "ERROR: [" PROGNAME
"] invalid dependency pattern: " ARGV[i
] | ERRCAT
85 if (system(cmd
) ==
0) {
86 cmd =
"cd " dir
" && " PWD_CMD
87 while (cmd
| getline pkgpath
)
88 if (!
(pkgpath in pkgsrcdirs
)) {
89 pkgpaths
[P
++] = pkgpath
90 pkgsrcdirs
[pkgpath
] = dir
92 depends
[pkgpath
, 0]++;
93 depends
[pkgpath
, depends
[pkgpath
, 0]] = pattern
96 print "ERROR: [" PROGNAME
"] " dir
" does not exist." | ERRCAT
101 # Reduce dependencies to the strictest set of dependencies it
102 # can derive from all of depends[...]. It only understands
103 # dependencies of the form foo>=1.0, and leaves the other
104 # dependencies undisturbed.
106 # The algorithm takes dependencies of the form foo>=1.0 and
107 # converts them to foo-1.0. It then compares this pkg name against
108 # each dependency to see if it satisfies them all. The key fact
109 # is the the strictest dependency, when converted to a pkg name,
110 # will satisfy every dependency.
112 for (p =
0; p
< P
; p
++) {
113 pkgpath = pkgpaths
[p
]
114 D = depends
[pkgpath
, 0];
116 for (d =
1; d
<= D
; d
++) {
117 dep = depends
[pkgpath
, d
]
119 dep ~
/>=
[0-9][0-9\.
]*(nb
[0-9]+)?
<[0-9]+/ || \
122 reduced
[N
++] = dep
":" pkgsrcdirs
[pkgpath
]
125 ge_depends
[dep
] = dep
127 for (dep in ge_depends
) {
128 dep2pkg = dep
; sub(">=", "-", dep2pkg
)
130 for (pattern in ge_depends
) {
131 cmd = PKG_ADMIN
" pmatch \"" pattern
"\" " dep2pkg
132 if (system(cmd
) != 0) {
137 if (match_all ==
0) continue
138 reduced
[N
++] = dep
":" pkgsrcdirs
[pkgpath
]
142 # If there are conflicting dependencies, then just pass them
143 # through and let the rest of the pkgsrc machinery handle it.
145 if (match_all ==
0) {
146 for (d =
1; d
<= D
; d
++) {
147 dep = depends
[pkgpath
, d
]
148 reduced
[N
++] = dep
":" pkgsrcdirs
[pkgpath
]
151 for (dep in ge_depends
)
152 delete ge_depends
[dep
]
155 # Output reduced dependencies.
156 for (n =
0; n
< N
; n
++)