1 |
george 08/04/14 14:50:49 |
2 |
|
3 |
Added: gnat.eselect-1.4 |
4 |
Log: |
5 |
split profile validity check off the get_active_gnat and made the update action clean unmerged profile |
6 |
(Portage version: 2.1.5_rc3) |
7 |
|
8 |
Revision Changes Path |
9 |
1.1 app-admin/eselect-gnat/files/gnat.eselect-1.4 |
10 |
|
11 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/eselect-gnat/files/gnat.eselect-1.4?rev=1.1&view=markup |
12 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/eselect-gnat/files/gnat.eselect-1.4?rev=1.1&content-type=text/plain |
13 |
|
14 |
Index: gnat.eselect-1.4 |
15 |
=================================================================== |
16 |
# Copyright 1999-2005 Gentoo Foundation |
17 |
# Distributed under the terms of the GNU General Public License v2 |
18 |
# $Id: gnat.eselect-1.4,v 1.1 2008/04/14 14:50:48 george Exp $ |
19 |
|
20 |
DESCRIPTION="Manage the installed gnat compilers" |
21 |
MAINTAINER="ada@g.o" |
22 |
SVN_DATE='$Date: 2008/04/14 14:50:48 $' |
23 |
VERSION=$(svn_date_to_version "${SVN_DATE}" ) |
24 |
|
25 |
# "inheriting" common stuff |
26 |
# this crude sourcing has to stay the way it is, as common code |
27 |
# cannot be part of some eclass (bug #192505) |
28 |
. /usr/share/gnat/lib/gnat-common.bash |
29 |
|
30 |
|
31 |
### Phylosophy |
32 |
# Each gnat installs a "specs" file named ${ARCH}-${PN}-${SLOT} under ${SPECSDIR} |
33 |
# Each lib creates a dir with its name under ${SPECSDIR} and populates it with |
34 |
# similar specs files (same name scheme) |
35 |
# Recognizing gnat specs from lib specs is then eazy - test entry for being a |
36 |
# dir, then just check what gnat profiles are installed for each lib.. |
37 |
# doset then creates env file that combines settings for gnat and for the |
38 |
# corresponding profile of each installed lib.. |
39 |
|
40 |
|
41 |
### Helpers |
42 |
|
43 |
# return *the* name of the active profile, checking that we do not have multiple |
44 |
# env files. |
45 |
# There can be only one! |
46 |
get_current_gnat() { |
47 |
local profiles=( $(get_env_list) ) |
48 |
|
49 |
if [ ${profiles[@]} == "${MARKER}*" ]; then exit; fi |
50 |
|
51 |
if (( 1 == ${#profiles[@]} )); then |
52 |
local active=${profiles[0]#${MARKER}} |
53 |
else |
54 |
die -q "${ENVDIR} contains multiple gnat profiles, please cleanup!" |
55 |
fi |
56 |
|
57 |
echo ${active} |
58 |
# disabling this check, as we want to use get_current_gnat with empty profile |
59 |
# as an indication that last gnat in SLOT was removed |
60 |
# if [ -f ${SPECSDIR}/${active} ]; then |
61 |
# echo ${active} |
62 |
# else |
63 |
# die -q "the active env.d profile does not correspond to any installed gnat!" |
64 |
# fi |
65 |
} |
66 |
|
67 |
# validity check that was removed from get_current_gnat, in case we need it |
68 |
# somewhere.. |
69 |
# Arguments: |
70 |
# $1 - name of the gnat profiel to check |
71 |
profile_is_valid() { |
72 |
if [[ -n $1 ]] ; then |
73 |
[[ -f ${SPECSDIR}/$1 ]] || return 1 |
74 |
fi |
75 |
} |
76 |
|
77 |
# check if the passed arg represents the installed gnat and return it or |
78 |
# not_found |
79 |
# takes args: |
80 |
# $1 - list ID to check |
81 |
get_name_from_list() { |
82 |
compiler=$1 |
83 |
|
84 |
compilers=( $(find_all_compilers) ) |
85 |
for (( i = 0 ; i < ${#compilers[@]} ; i = i + 1 )) ; do |
86 |
if [[ ${compilers[$i]} == ${compiler} ]] ; then |
87 |
echo ${compiler} |
88 |
return |
89 |
fi |
90 |
done |
91 |
|
92 |
echo "(not-found)" |
93 |
} |
94 |
|
95 |
|
96 |
# removes env files (for compiler and libs) |
97 |
# params: |
98 |
# $1: the name of profile for which to remove env file |
99 |
unset_env() { |
100 |
rm -f ${ENVDIR}/${MARKER}$1 &> /dev/null |
101 |
} |
102 |
|
103 |
|
104 |
### show action ### |
105 |
|
106 |
describe_show() { |
107 |
echo "Show the active gnat compiler/profile and installed libs" |
108 |
} |
109 |
|
110 |
do_show() { |
111 |
active=$(get_current_gnat) |
112 |
if $(profile_is_valid ${active}); then |
113 |
write_list_start "Current gnat version:" |
114 |
if [[ -n ${active} ]] ; then |
115 |
write_kv_list_entry "$active" "" |
116 |
libs=( $(find_libs4profile ${active}) ) |
117 |
write_list_start "Active libs:" |
118 |
write_numbered_list "${libs[@]}" |
119 |
else |
120 |
write_kv_list_entry "(none set)" "" |
121 |
fi |
122 |
else |
123 |
write_error_msg "The active profile in ${ENVDIR} is not valid! Please set a valid profile!" |
124 |
fi |
125 |
} |
126 |
|
127 |
### list action ### |
128 |
|
129 |
describe_list() { |
130 |
echo "List installed gnat compilers and libs" |
131 |
} |
132 |
|
133 |
do_list() { |
134 |
compilers=( $(find_all_compilers ) ) |
135 |
active=$(get_current_gnat) |
136 |
|
137 |
write_list_start "Available gnat compilers:" |
138 |
|
139 |
if [[ -n ${compilers[@]} ]] ; then |
140 |
local i |
141 |
for (( i = 0 ; i < ${#compilers[@]} ; i = i + 1 )) ; do |
142 |
linkversion=${compilers[${i}]} |
143 |
|
144 |
[[ $linkversion == $active ]] && \ |
145 |
compilers[${i}]="${compilers[${i}]} $(highlight '*' )" |
146 |
done |
147 |
write_numbered_list "${compilers[@]}" |
148 |
|
149 |
# now the libs |
150 |
libs=( $(find_all_libs) ) |
151 |
write_list_start "Installed libs:" |
152 |
for (( i = 0 ; i < ${#libs[@]} ; i = i + 1 )) ; do |
153 |
[ -f ${SPECSDIR}/${libs[$i]}/${active} ] && \ |
154 |
libs[${i}]="${libs[${i}]} $(highlight '*' )" |
155 |
done |
156 |
write_numbered_list "${libs[@]}" |
157 |
else |
158 |
write_kv_list_entry "(none found)" "" |
159 |
fi |
160 |
} |
161 |
|
162 |
|
163 |
### set action ### |
164 |
|
165 |
describe_set() { |
166 |
echo "Set active gnat compiler" |
167 |
} |
168 |
|
169 |
# The set action. Parameters: |
170 |
# $1 - name of profile to set, obligatory, passed by eselect |
171 |
# $2 - optional, name of env file to generate. Used from gnat.eclass. |
172 |
do_set() { |
173 |
if [[ -z ${1} ]] ; then |
174 |
# no parameter |
175 |
die -q "You didn't tell me which gnat to use" |
176 |
fi |
177 |
|
178 |
local toset=$(get_name_from_list $1) |
179 |
if [[ ${toset} == "(not-found)" ]] ; then |
180 |
die -q "I don't recognise the selection" |
181 |
fi |
182 |
|
183 |
# the action! |
184 |
# in this implementation simply create an appropriate env file |
185 |
local active=$(get_current_gnat) |
186 |
if [[ -z ${2} ]] ; then |
187 |
local envfile="${ENVDIR}/${MARKER}${toset}" |
188 |
|
189 |
# now we need to remove an old env file, which is guaranteed to |
190 |
# be unique by get_current_gnat above |
191 |
if [[ -n ${active} ]] ; then |
192 |
unset_env ${active} |
193 |
fi |
194 |
# just for a good measure remove the one we are going to write |
195 |
unset_env ${toset} |
196 |
else |
197 |
local envfile="$2" |
198 |
fi |
199 |
|
200 |
generate_envFile ${toset} ${envfile} |
201 |
|
202 |
# force update environment |
203 |
# should be replaced with "do_action env update" when #172472 gets resolved |
204 |
env-update &> /dev/null |
205 |
} |
206 |
|
207 |
|
208 |
|
209 |
### update action ### |
210 |
# |
211 |
# This action regenerates the /etc/env.d file for the current profile. Basically |
212 |
# the same as set, only it does not take any parameters. It should be called from ebuilds |
213 |
# installing Ada libs or in the pkg_postrm in gnatbuild.eclass, to clean up the |
214 |
# profile if last gnat in SLOT was removed. |
215 |
|
216 |
describe_update() { |
217 |
echo "Update active gnat profile picking up new libs." |
218 |
} |
219 |
|
220 |
do_update() { |
221 |
local toset=$(get_current_gnat) |
222 |
local envfile="${ENVDIR}/${MARKER}${toset}" |
223 |
# now check whether to update or unset the profile |
224 |
if $(profile_is_valid ${toset}); then |
225 |
generate_envFile ${toset} ${envfile} |
226 |
else |
227 |
unset_env ${toset} |
228 |
fi |
229 |
do_action env update &> /dev/null |
230 |
} |
231 |
|
232 |
### unset action ### |
233 |
|
234 |
describe_unset() { |
235 |
echo "Remove settings for currently active gnat" |
236 |
} |
237 |
|
238 |
do_unset() { |
239 |
local active=$(get_current_gnat) |
240 |
# check whether we have any profile set before removing anything.. |
241 |
if [[ -n ${active} ]] ; then |
242 |
unset_env ${active} |
243 |
do_action env update &> /dev/null |
244 |
fi |
245 |
} |
246 |
|
247 |
|
248 |
|
249 |
-- |
250 |
gentoo-commits@l.g.o mailing list |