1 |
> # @ECLASS_VARIABLE: DB_VERSIONS |
2 |
> # @REQUIRED |
3 |
> # @DESCRIPTION: |
4 |
> # This variable contains a list of sys-libs/db SLOT versions the package |
5 |
> # works with. Please always sort the list so that higher slot versions come |
6 |
> # first or else the package might not depend on the latest possible version of |
7 |
> # sys-libs/db |
8 |
> # |
9 |
> # Example: |
10 |
> # @CODE |
11 |
> # DB_VERSIONS=( 5.0 4.8 ) |
12 |
> # inherit db-use-r1 |
13 |
> # @CODE |
14 |
> # |
15 |
> # Please note that you can also use bash brace expansion if you like: |
16 |
> # @CODE |
17 |
> # DB_VERSIONS=( 5.{3,2,1,0} 4.8 ) |
18 |
> # inherit db-use-r1 |
19 |
> # @CODE |
20 |
> if ! declare -p DB_VERSIONS &>/dev/null; then |
21 |
> die "DB_VERSIONS not declared." |
22 |
> fi |
23 |
|
24 |
You may want to add here an additional check if it is an array. Otherwise, |
25 |
you may end up with some random behavior when someone sets it to single |
26 |
string. |
27 |
|
28 |
> # @ECLASS-VARIABLE: DB_DEPS |
29 |
> # @DESCRIPTION: |
30 |
> # This eclass sets and exports DB_DEPS which should be uses as follows: |
31 |
> # |
32 |
> # @CODE |
33 |
> # RDEPEND="${DB_DEPEND}" |
34 |
> # @CODE |
35 |
|
36 |
DB_DEPS or DB_DEPEND? |
37 |
|
38 |
> # |
39 |
> # or |
40 |
> # |
41 |
> # @CODE |
42 |
> # RDEPEND="berkdb? ( ${DB_DEPEND} )" |
43 |
> # @CODE |
44 |
> DB_DEPEND="" |
45 |
> if [ "${#DB_VERSIONS[@]}" -gt 1 ] ; then |
46 |
> DB_DEPEND="|| (" |
47 |
> fi |
48 |
|
49 |
I think it's perfectly valid to have '|| ( single-atom )'. IMO it's not |
50 |
worth the effort to add it conditionally. |
51 |
|
52 |
> for db_slotver in ${DB_VERSIONS[@]} ; do |
53 |
> DB_DEPEND+=" sys-libs/db:${db_slotver}" |
54 |
> done |
55 |
|
56 |
You can do it without the loop: |
57 |
|
58 |
DB_DEPEND+=${DB_VERSIONS[@]/#/ sys-libs/db:} |
59 |
|
60 |
> if [ "${#DB_VERSIONS[@]}" -gt 1 ] ; then |
61 |
> DB_DEPEND+=" )" |
62 |
> fi |
63 |
> export DB_DEPEND |
64 |
> [[ ! -n ${DB_DEPEND} ]] && die "Cannot assing sys-libs/db dependency" |
65 |
|
66 |
Looks like impossible to me. Well, unless DB_VERSIONS are empty but then |
67 |
it looks like erring on the result rather than reason. |
68 |
|
69 |
> inherit versionator multilib |
70 |
> |
71 |
> # @FUNCTION: db_ver_to_slot |
72 |
> # @USAGE: <db-version> |
73 |
> # @DESCRIPTION: |
74 |
> # Convert a version to a db slot. You need to submit at least the first two |
75 |
> # Version components |
76 |
> # This is meant for ebuilds using the real version number of a sys-libs/db |
77 |
> # package. This eclass doesn't use it internally. |
78 |
> db_ver_to_slot() { |
79 |
> if [ $# -ne 1 ]; then |
80 |
> eerror "Function db_ver_to_slot needs one argument" >&2 |
81 |
|
82 |
Shouldn't eerror use stderr on itself? |
83 |
|
84 |
> eerror "args given:" >&2 |
85 |
> for f in $@ |
86 |
|
87 |
Missing quoting. |
88 |
|
89 |
> do |
90 |
> eerror " - \"$@\"" >&2 |
91 |
> done |
92 |
> return 1 |
93 |
> fi |
94 |
> if [ "$(get_version_component_count $1)" -lt 2 ] ; then |
95 |
> eerror "db_ver_to_slot function needs at least a version component" |
96 |
> eerror "count of two." |
97 |
> return 1 |
98 |
|
99 |
'die', please. |
100 |
|
101 |
> fi |
102 |
> echo -n "$(get_version_component_range 1-2 $1)" |
103 |
|
104 |
Just FYI, '-n' is not really necessary here since shell automatically |
105 |
strips trailing newline in $(). |
106 |
|
107 |
> } |
108 |
> |
109 |
> # @FUNCTION: db_findver |
110 |
> # @USAGE: |
111 |
> # @DESCRIPTION: |
112 |
> # Find the highest installed db version that fits DB_VERSIONS |
113 |
> db_findver() { |
114 |
> local db_slotver |
115 |
> for db_slotver in ${DB_VERSIONS[@]} ; do |
116 |
> if has_version sys-libs/db:${db_slotver} \ |
117 |
> && [ -d "/usr/include/db${db_slotver}" ] ; then |
118 |
|
119 |
Why do you need both checks? |
120 |
|
121 |
> echo -n "${db_slotver}" |
122 |
> return 0 |
123 |
> fi |
124 |
> done |
125 |
> return 1 |
126 |
> } |
127 |
> |
128 |
> # @FUNCTION: db_includedir |
129 |
> # @USAGE: |
130 |
> # @DESCRIPTION: |
131 |
> # Get the include dir for berkeley db. This function returns the best version |
132 |
> # found by db_findver() |
133 |
> db_includedir() { |
134 |
> VER="$(db_findver)" || return 1 |
135 |
|
136 |
Shouldn't this be 'local'? |
137 |
|
138 |
> einfo "include version ${VER}" >&2 |
139 |
|
140 |
Looks more like debug-print candidate. Or, at least mention 'berkdb' |
141 |
somewhere since user will have no idea 'version of what'. |
142 |
|
143 |
> if [ -d "/usr/include/db${VER}" ]; then |
144 |
> echo -n "/usr/include/db${VER}" |
145 |
> return 0 |
146 |
> else |
147 |
> eerror "sys-libs/db package requested, but headers not found" >&2 |
148 |
> return 1 |
149 |
> fi |
150 |
> } |
151 |
> |
152 |
> # @FUNCTION: db_libname |
153 |
> # @USAGE: |
154 |
> # @DESCRIPTION: |
155 |
> # Get the library name for berkeley db. Something like "db-4.2" will be the |
156 |
> # outcome. This function returns the best version found by db_findver() |
157 |
> db_libname() { |
158 |
> VER="$(db_findver)" || return 1 |
159 |
> if [ -e "/usr/$(get_libdir)/libdb-${VER}.so" ]; then |
160 |
> echo -n "db-${VER}" |
161 |
> return 0 |
162 |
> else |
163 |
> eerror "sys-libs/db package requested, but library not found" >&2 |
164 |
> return 1 |
165 |
> fi |
166 |
> } |
167 |
|
168 |
-- |
169 |
Best regards, |
170 |
Michał Górny |