1 |
george 07/09/19 20:24:05 |
2 |
|
3 |
Added: gnat.eselect-1.1 gnat-common.bash |
4 |
digest-eselect-gnat-1.1 |
5 |
Log: |
6 |
split off code common with gnat.eclass (##192505 and 167000) |
7 |
(Portage version: 2.1.3.9) |
8 |
|
9 |
Revision Changes Path |
10 |
1.1 app-admin/eselect-gnat/files/gnat.eselect-1.1 |
11 |
|
12 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/eselect-gnat/files/gnat.eselect-1.1?rev=1.1&view=markup |
13 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/eselect-gnat/files/gnat.eselect-1.1?rev=1.1&content-type=text/plain |
14 |
|
15 |
Index: gnat.eselect-1.1 |
16 |
=================================================================== |
17 |
# Copyright 1999-2005 Gentoo Foundation |
18 |
# Distributed under the terms of the GNU General Public License v2 |
19 |
# $Id: gnat.eselect-1.1,v 1.1 2007/09/19 20:24:05 george Exp $ |
20 |
|
21 |
DESCRIPTION="Manage the talled gnat compilers" |
22 |
MAINTAINER="ada@g.o" |
23 |
SVN_DATE='$Date: 2007/09/19 20:24:05 $' |
24 |
VERSION=$(svn_date_to_version "${SVN_DATE}" ) |
25 |
|
26 |
# "inheriting" common stuff |
27 |
# this crude sourcing should be replaced by a call to function in |
28 |
# libs/package-manager.bash eventually |
29 |
. /usr/share/gnat/lib/gnat-common.bash |
30 |
|
31 |
|
32 |
### Phylosophy |
33 |
# Each gnat installs a "specs" file named ${ARCH}-${PN}-${SLOT} under ${SPECSDIR} |
34 |
# Each lib creates a dir with its name under ${SPECSDIR} and populates it with |
35 |
# similar specs files (same name scheme) |
36 |
# Recognizing gnat specs from lib specs is then eazy - test entry for being a |
37 |
# dir, then just check what gnat profiles are installed for each lib.. |
38 |
# doset then creates env file that combines settings for gnat and for the |
39 |
# corresponding profile of each installed lib.. |
40 |
|
41 |
|
42 |
### Helpers |
43 |
|
44 |
# return *the* name of the active profile, checking that we do not have multiple |
45 |
# env files. |
46 |
# There can be only one! |
47 |
get_current_gnat() { |
48 |
local profiles=( $(get_env_list) ) |
49 |
|
50 |
if [ ${profiles[@]} == "${MARKER}*" ]; then exit; fi |
51 |
|
52 |
if (( 1 == ${#profiles[@]} )); then |
53 |
local active=${profiles[0]#${MARKER}} |
54 |
else |
55 |
die -q "${ENVDIR} contains multiple gnat profiles, please cleanup!" |
56 |
fi |
57 |
|
58 |
if [ -f ${SPECSDIR}/${active} ]; then |
59 |
echo ${active} |
60 |
else |
61 |
die -q "the active env.d profile does not correspond to any installed gnat!" |
62 |
fi |
63 |
} |
64 |
|
65 |
# check if the passed arg represents the installed gnat and return it or |
66 |
# not_found |
67 |
# takes args: |
68 |
# $1 - list ID to check |
69 |
get_name_from_list() { |
70 |
compiler=$1 |
71 |
|
72 |
compilers=( $(find_compilers) ) |
73 |
for (( i = 0 ; i < ${#compilers[@]} ; i = i + 1 )) ; do |
74 |
if [[ ${compilers[$i]} == ${compiler} ]] ; then |
75 |
echo ${compiler} |
76 |
return |
77 |
fi |
78 |
done |
79 |
|
80 |
echo "(not-found)" |
81 |
} |
82 |
|
83 |
|
84 |
# removes env files (for compiler and libs) |
85 |
# params: |
86 |
# $1: the name of profile for which to remove env file |
87 |
unset_env() { |
88 |
rm -f ${ENVDIR}/${MARKER}$1 &> /dev/null |
89 |
} |
90 |
|
91 |
|
92 |
### show action ### |
93 |
|
94 |
describe_show() { |
95 |
echo "Show the active gnat compiler/profile and installed libs" |
96 |
} |
97 |
|
98 |
do_show() { |
99 |
write_list_start "Current gnat version:" |
100 |
active=$(get_current_gnat) |
101 |
if [ ! -z ${active} ] ; then # not sure why [ -n ] does not do the same |
102 |
write_kv_list_entry "$active" "" |
103 |
libs=( $(find_libs4profile ${active}) ) |
104 |
write_list_start "Active libs:" |
105 |
write_numbered_list "${libs[@]}" |
106 |
else |
107 |
write_kv_list_entry "(none set)" "" |
108 |
fi |
109 |
} |
110 |
|
111 |
### list action ### |
112 |
|
113 |
describe_list() { |
114 |
echo "List installed gnat compilers and libs" |
115 |
} |
116 |
|
117 |
do_list() { |
118 |
compilers=( $(find_compilers ) ) |
119 |
active=$(get_current_gnat) |
120 |
|
121 |
write_list_start "Available gnat compilers:" |
122 |
|
123 |
if [[ -n ${compilers[@]} ]] ; then |
124 |
local i |
125 |
for (( i = 0 ; i < ${#compilers[@]} ; i = i + 1 )) ; do |
126 |
linkversion=${compilers[${i}]} |
127 |
|
128 |
[[ $linkversion == $active ]] && \ |
129 |
compilers[${i}]="${compilers[${i}]} $(highlight '*' )" |
130 |
done |
131 |
write_numbered_list "${compilers[@]}" |
132 |
|
133 |
# now the libs |
134 |
libs=( $(find_all_libs) ) |
135 |
write_list_start "Installed libs:" |
136 |
for (( i = 0 ; i < ${#libs[@]} ; i = i + 1 )) ; do |
137 |
[ -f ${SPECSDIR}/${libs[$i]}/${active} ] && \ |
138 |
libs[${i}]="${libs[${i}]} $(highlight '*' )" |
139 |
done |
140 |
write_numbered_list "${libs[@]}" |
141 |
else |
142 |
write_kv_list_entry "(none found)" "" |
143 |
fi |
144 |
} |
145 |
|
146 |
|
147 |
### set action ### |
148 |
|
149 |
describe_set() { |
150 |
echo "Set active gnat compiler" |
151 |
} |
152 |
|
153 |
# The set action. Parameters: |
154 |
# $1 - name of profile to set, obligatory, passed by eselect |
155 |
# $2 - optional, name of env file to generate. Used from gnat.eclass. |
156 |
do_set() { |
157 |
if [[ -z ${1} ]] ; then |
158 |
# no parameter |
159 |
die -q "You didn't tell me which gnat to use" |
160 |
fi |
161 |
|
162 |
local toset=$(get_name_from_list $1) |
163 |
if [[ ${toset} == "(not-found)" ]] ; then |
164 |
die -q "I don't recognise the selection" |
165 |
fi |
166 |
|
167 |
# the action! |
168 |
# in this implementation simply create an appropriate env file |
169 |
local active=$(get_current_gnat) |
170 |
if [[ -z ${2} ]] ; then |
171 |
local envfile="${ENVDIR}/${MARKER}${toset}" |
172 |
|
173 |
# now we need to remove an old env file, which is guaranteed to |
174 |
# be unique by get_current_gnat above |
175 |
if [[ -n ${active} ]] ; then |
176 |
unset_env ${active} |
177 |
fi |
178 |
# just for a good measure remove the one we are going to write |
179 |
unset_env ${toset} |
180 |
else |
181 |
local envfile="$2" |
182 |
fi |
183 |
|
184 |
generate_envFile ${toset} ${envfile} |
185 |
|
186 |
# force update environment |
187 |
# should be replaced with "do_action env update" when #172472 gets resolved |
188 |
env-update &> /dev/null |
189 |
} |
190 |
|
191 |
|
192 |
|
193 |
### update action ### |
194 |
# |
195 |
# This action regenerates the /etc/env.d file for the current profile. Basically |
196 |
# the same as set, only it does not take any parameters. It should be called from ebuilds |
197 |
# installing Ada libs |
198 |
|
199 |
describe_update() { |
200 |
echo "Update active gnat profile picking up new libs." |
201 |
} |
202 |
|
203 |
do_update() { |
204 |
local toset=$(get_current_gnat) |
205 |
local envfile="${ENVDIR}/${MARKER}${toset}" |
206 |
generate_envFile ${toset} ${envfile} |
207 |
env-update &> /dev/null |
208 |
} |
209 |
|
210 |
### unset action ### |
211 |
|
212 |
describe_unset() { |
213 |
echo "Remove settings for currently active gnat" |
214 |
} |
215 |
|
216 |
do_unset() { |
217 |
local active=$(get_current_gnat) |
218 |
# check whether we have any profile set before removing anything.. |
219 |
if [[ -n ${active} ]] ; then |
220 |
unset_env ${active} |
221 |
env-update &> /dev/null |
222 |
fi |
223 |
} |
224 |
|
225 |
|
226 |
|
227 |
1.1 app-admin/eselect-gnat/files/gnat-common.bash |
228 |
|
229 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/eselect-gnat/files/gnat-common.bash?rev=1.1&view=markup |
230 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/app-admin/eselect-gnat/files/gnat-common.bash?rev=1.1&content-type=text/plain |
231 |
|
232 |
Index: gnat-common.bash |
233 |
=================================================================== |
234 |
# Copyright 1999-2007 Gentoo Foundation |
235 |
# Distributed under the terms of the GNU General Public License v2 |
236 |
# $Header: /var/cvsroot/gentoo-x86/app-admin/eselect-gnat/files/gnat-common.bash,v 1.1 2007/09/19 20:24:05 george Exp $ |
237 |
|
238 |
# |
239 |
# Original Author: George Shapovalov <george@g.o> |
240 |
# Purpose: Contains common vars/locations and functions for use by gnat.eclass, |
241 |
# gnat.eselect and gnatbuild.eclass. |
242 |
# |
243 |
# NOTE!!! |
244 |
# This eclass should just define vars (tyr to limit these!) and simple functions. |
245 |
# No bash extensions!! |
246 |
# That is, no portage or eclass internals are allowed! |
247 |
# |
248 |
|
249 |
|
250 |
|
251 |
# ---------------------------------- |
252 |
# Globals |
253 |
|
254 |
# Environmantal stuff (for env update) |
255 |
SPECSDIR="/usr/share/gnat/eselect" |
256 |
ENVDIR="/etc/env.d" |
257 |
MARKER="55gnat-" |
258 |
|
259 |
|
260 |
# ------------------------------------ |
261 |
# Helpers |
262 |
# |
263 |
# may be moved to a seperate eclass, if enough accumulated in this one and in |
264 |
# gnatbuild.eclass.. |
265 |
|
266 |
# get_all_profile_components splits gnat profile and returns pace separated list of its components: |
267 |
# x86_64-pc-linux-gnu-gnat-gcc-4.1 -> x86_64-pc-linux-gnu gcc 4.1 |
268 |
# args: |
269 |
# $1 - the string to split |
270 |
get_all_profile_components() { |
271 |
local GnatSLOT=${1##*-} |
272 |
local remainder=${1%-*} |
273 |
local GnatPkg=${remainder##*-} |
274 |
remainder=${remainder%-gnat-*} |
275 |
echo "${remainder} ${GnatPkg} ${GnatSLOT}" |
276 |
} |
277 |
|
278 |
# similar to above, returns only SLOT component: |
279 |
# x86_64-pc-linux-gnu-gnat-gcc-4.1 -> 4.1 |
280 |
# args: |
281 |
# $1 - the string to extract the slot from |
282 |
get_gnat_SLOT() { |
283 |
echo "${1##*-}" |
284 |
} |
285 |
|
286 |
# returns only Pkg component: |
287 |
# x86_64-pc-linux-gnu-gnat-gcc-4.1 -> gcc |
288 |
# args: |
289 |
# $1 - the string to extract the slot from |
290 |
get_gnat_Pkg() { |
291 |
local remainder=${1%-*} |
292 |
echo "${remainder##*-}" |
293 |
} |
294 |
|
295 |
# returns only Arch component: |
296 |
# x86_64-pc-linux-gnu-gnat-gcc-4.1 -> x86_64-pc-linux-gnu |
297 |
# args: |
298 |
# $1 - the string to extract the slot from |
299 |
get_gnat_Arch() { |
300 |
echo ${1%-gnat-*} |
301 |
} |
302 |
|
303 |
|
304 |
|
305 |
## ------------------------------------------- |
306 |
# gnat profile and lib detection functions |
307 |
|
308 |
|
309 |
# create a list of all gnat env.d files |
310 |
# for now use trivial implementation - store name of active profile in the |
311 |
# env file name, so it gets called 55gnat-${ARCH}-${PN}-${SLOT} |
312 |
get_env_list() { |
313 |
for fn in ${ENVDIR}/${MARKER}*; do |
314 |
echo $(basename ${fn}) |
315 |
done |
316 |
} |
317 |
|
318 |
|
319 |
|
320 |
# find installed compilers and return a list |
321 |
find_compilers() { |
322 |
[ ! -d ${SPECSDIR} ] && exit |
323 |
for fn in ${SPECSDIR}/*; do |
324 |
[ ! -d ${fn} ] && echo $(basename ${fn}); |
325 |
done |
326 |
} |
327 |
|
328 |
# find installed libs and return a list |
329 |
find_all_libs() { |
330 |
[ ! -d ${SPECSDIR} ] && exit |
331 |
for fn in ${SPECSDIR}/*; do |
332 |
[ -d ${fn} ] && echo $(basename ${fn}); |
333 |
done |
334 |
} |
335 |
|
336 |
# find libs that have been built for a given profile |
337 |
# Arguments: |
338 |
# $1 - gnat profile for which to detect active libs |
339 |
find_libs4profile() { |
340 |
libs=( $(find_all_libs) ) |
341 |
|
342 |
for (( i = 0 ; i < ${#libs[@]} ; i = i + 1 )) ; do |
343 |
[ -f ${SPECSDIR}/${libs[$i]}/$1 ] && echo "${libs[$i]}" |
344 |
done |
345 |
} |
346 |
|
347 |
|
348 |
|
349 |
|
350 |
## ----------------------- |
351 |
# princial action - central part of do_set and helpers |
352 |
|
353 |
|
354 |
# extracts values of the passed var definition from given spec file |
355 |
# params: |
356 |
# $1: spec file (as generated by gnabuild.eclass) |
357 |
# $2: variable name |
358 |
get_var_from_spec() { |
359 |
local var=$(grep -e "^ *$2=" $1|cut -d= -f2) |
360 |
echo ${var} |
361 |
} |
362 |
|
363 |
|
364 |
# Cycle through given libs and form a ':' separated list of settings for the given |
365 |
# var. Returned string starts with ':' if there is any non-empty setting, |
366 |
# otherwise returns empty string |
367 |
# params: |
368 |
# $1 - name of env var to process |
369 |
# $2 - name of gnat profile |
370 |
# $3.. - list of libs to check (to avoid its composition every time) |
371 |
# - the list is expanded to lest of args at the point of call |
372 |
get_lib_var_settings() { |
373 |
local envVar=$1 |
374 |
local toset=$2 |
375 |
#echo "get_lib_var_settings params:$@" >> /tmp/eselect-gnat.rep |
376 |
if [[ "none" != ${3} ]]; then |
377 |
local envString |
378 |
local specLine |
379 |
while [[ -n $3 ]]; do |
380 |
specLine=$(get_var_from_spec ${SPECSDIR}/$3/${toset} ${envVar}) |
381 |
#echo "$3:${specLine}." >> /tmp/eselect-gnat.rep |
382 |
[[ -n ${specLine} ]] && envString="${envString}:${specLine}" |
383 |
shift |
384 |
done |
385 |
echo "${envString}" |
386 |
fi |
387 |
} |
388 |
|
389 |
|
390 |
|
391 |
# The action! |
392 |
# Part common for do_set and do_update of gnat.eselect, also used in gnat.eclass |
393 |
# to set environment during lib build and installation |
394 |
# |
395 |
# params: |
396 |
# $1 - profile to set (toset param inside) |
397 |
# $2 - envfile |
398 |
|
399 |
generate_envFile() { |
400 |
local toset=$1 |
401 |
local envfile=$2 |
402 |
|
403 |
local binpath="$(get_var_from_spec ${SPECSDIR}/${toset} binpath)" |
404 |
local libexecpath="$(get_var_from_spec ${SPECSDIR}/${toset} libexecpath)" |
405 |
local libs=( $(find_libs4profile ${toset}) ) |
406 |
#echo "generate_envFile: ${libs[@]}" >> /tmp/eselect-gnat.rep |
407 |
if (( 0 == ${#libs[@]} )); then |
408 |
libs="none" |
409 |
fi |
410 |
|
411 |
local MyPath="${binpath}:${libexecpath}$(get_lib_var_settings PATH ${toset} ${libs[@]})" |
412 |
echo "PATH=${MyPath}" > "${envfile}" |
413 |
echo "ROOTPATH=${MyPath}" >> "${envfile}" |
414 |
echo "MANPATH=$(get_var_from_spec ${SPECSDIR}/${toset} manpath)$(get_lib_var_settings MANPATH ${toset} ${libs[@]})" >> "${envfile}" |
415 |
echo "INFOPATH=$(get_var_from_spec ${SPECSDIR}/${toset} infopath)$(get_lib_var_settings INFOPATH ${toset} ${libs[@]})" >> "${envfile}" |
416 |
# the next three use the common base |
417 |
local libBase=$(get_var_from_spec ${SPECSDIR}/${toset} ldpath) |
418 |
echo "LDPATH=${libBase}:${libBase}/adalib$(get_lib_var_settings LDPATH ${toset} ${libs[@]})" >> "${envfile}" |
419 |
echo "ADA_INCLUDE_PATH=${libBase}/adainclude$(get_lib_var_settings ADA_INCLUDE_PATH ${toset} ${libs[@]})" >> "${envfile}" |
420 |
echo "ADA_OBJECTS_PATH=${libBase}/adalib$(get_lib_var_settings ADA_OBJECTS_PATH ${toset} ${libs[@]})" >> "${envfile}" |
421 |
} |
422 |
|
423 |
|
424 |
|
425 |
|
426 |
1.1 app-admin/eselect-gnat/files/digest-eselect-gnat-1.1 |
427 |
|
428 |
<<Binary file>> |
429 |
|
430 |
|
431 |
-- |
432 |
gentoo-commits@g.o mailing list |