Gentoo Archives: gentoo-commits

From: "Ulrich Mueller (ulm)" <ulm@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in app-eselect/eselect-gnat/files: gnat.eselect-1.3 gnat-common-1.4-r1.bash gnat.eselect-1.4 gnat.eselect-1.5 gnat-common-1.3-r1.bash
Date: Tue, 31 Mar 2015 16:49:00
Message-Id: 20150331164857.EBCB514EE1@oystercatcher.gentoo.org
1 ulm 15/03/31 16:48:57
2
3 Added: gnat.eselect-1.3 gnat-common-1.4-r1.bash
4 gnat.eselect-1.4 gnat.eselect-1.5
5 gnat-common-1.3-r1.bash
6 Log:
7 Move package from app-admin to app-eselect category.
8
9 (Portage version: 2.2.18/cvs/Linux x86_64, RepoMan options: --force, signed Manifest commit with key 9433907D693FB5B8!)
10
11 Revision Changes Path
12 1.1 app-eselect/eselect-gnat/files/gnat.eselect-1.3
13
14 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-eselect/eselect-gnat/files/gnat.eselect-1.3?rev=1.1&view=markup
15 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-eselect/eselect-gnat/files/gnat.eselect-1.3?rev=1.1&content-type=text/plain
16
17 Index: gnat.eselect-1.3
18 ===================================================================
19 # Copyright 1999-2015 Gentoo Foundation
20 # Distributed under the terms of the GNU General Public License v2
21 # $Id: gnat.eselect-1.3,v 1.1 2015/03/31 16:48:57 ulm Exp $
22
23 DESCRIPTION="Manage the installed gnat compilers"
24 MAINTAINER="ada@g.o"
25 SVN_DATE='$Date: 2015/03/31 16:48:57 $'
26 VERSION=$(svn_date_to_version "${SVN_DATE}" )
27
28 # "inheriting" common stuff
29 # this crude sourcing has to stay the way it is, as common code
30 # cannot be part of some eclass (bug #192505)
31 . /usr/share/gnat/lib/gnat-common.bash
32
33
34 ### Phylosophy
35 # Each gnat installs a "specs" file named ${ARCH}-${PN}-${SLOT} under ${SPECSDIR}
36 # Each lib creates a dir with its name under ${SPECSDIR} and populates it with
37 # similar specs files (same name scheme)
38 # Recognizing gnat specs from lib specs is then eazy - test entry for being a
39 # dir, then just check what gnat profiles are installed for each lib..
40 # doset then creates env file that combines settings for gnat and for the
41 # corresponding profile of each installed lib..
42
43
44 ### Helpers
45
46 # return *the* name of the active profile, checking that we do not have multiple
47 # env files.
48 # There can be only one!
49 get_current_gnat() {
50 local profiles=( $(get_env_list) )
51
52 if [ ${profiles[@]} == "${MARKER}*" ]; then exit; fi
53
54 if (( 1 == ${#profiles[@]} )); then
55 local active=${profiles[0]#${MARKER}}
56 else
57 die -q "${ENVDIR} contains multiple gnat profiles, please cleanup!"
58 fi
59
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 # check if the passed arg represents the installed gnat and return it or
68 # not_found
69 # takes args:
70 # $1 - list ID to check
71 get_name_from_list() {
72 compiler=$1
73
74 compilers=( $(find_all_compilers) )
75 for (( i = 0 ; i < ${#compilers[@]} ; i = i + 1 )) ; do
76 if [[ ${compilers[$i]} == ${compiler} ]] ; then
77 echo ${compiler}
78 return
79 fi
80 done
81
82 echo "(not-found)"
83 }
84
85
86 # removes env files (for compiler and libs)
87 # params:
88 # $1: the name of profile for which to remove env file
89 unset_env() {
90 rm -f ${ENVDIR}/${MARKER}$1 &> /dev/null
91 }
92
93
94 ### show action ###
95
96 describe_show() {
97 echo "Show the active gnat compiler/profile and installed libs"
98 }
99
100 do_show() {
101 write_list_start "Current gnat version:"
102 active=$(get_current_gnat)
103 if [ ! -z ${active} ] ; then # not sure why [ -n ] does not do the same
104 write_kv_list_entry "$active" ""
105 libs=( $(find_libs4profile ${active}) )
106 write_list_start "Active libs:"
107 write_numbered_list "${libs[@]}"
108 else
109 write_kv_list_entry "(none set)" ""
110 fi
111 }
112
113 ### list action ###
114
115 describe_list() {
116 echo "List installed gnat compilers and libs"
117 }
118
119 do_list() {
120 compilers=( $(find_all_compilers ) )
121 active=$(get_current_gnat)
122
123 write_list_start "Available gnat compilers:"
124
125 if [[ -n ${compilers[@]} ]] ; then
126 local i
127 for (( i = 0 ; i < ${#compilers[@]} ; i = i + 1 )) ; do
128 linkversion=${compilers[${i}]}
129
130 [[ $linkversion == $active ]] && \
131 compilers[${i}]="${compilers[${i}]} $(highlight '*' )"
132 done
133 write_numbered_list "${compilers[@]}"
134
135 # now the libs
136 libs=( $(find_all_libs) )
137 write_list_start "Installed libs:"
138 for (( i = 0 ; i < ${#libs[@]} ; i = i + 1 )) ; do
139 [ -f ${SPECSDIR}/${libs[$i]}/${active} ] && \
140 libs[${i}]="${libs[${i}]} $(highlight '*' )"
141 done
142 write_numbered_list "${libs[@]}"
143 else
144 write_kv_list_entry "(none found)" ""
145 fi
146 }
147
148
149 ### set action ###
150
151 describe_set() {
152 echo "Set active gnat compiler"
153 }
154
155 # The set action. Parameters:
156 # $1 - name of profile to set, obligatory, passed by eselect
157 # $2 - optional, name of env file to generate. Used from gnat.eclass.
158 do_set() {
159 if [[ -z ${1} ]] ; then
160 # no parameter
161 die -q "You didn't tell me which gnat to use"
162 fi
163
164 local toset=$(get_name_from_list $1)
165 if [[ ${toset} == "(not-found)" ]] ; then
166 die -q "I don't recognise the selection"
167 fi
168
169 # the action!
170 # in this implementation simply create an appropriate env file
171 local active=$(get_current_gnat)
172 if [[ -z ${2} ]] ; then
173 local envfile="${ENVDIR}/${MARKER}${toset}"
174
175 # now we need to remove an old env file, which is guaranteed to
176 # be unique by get_current_gnat above
177 if [[ -n ${active} ]] ; then
178 unset_env ${active}
179 fi
180 # just for a good measure remove the one we are going to write
181 unset_env ${toset}
182 else
183 local envfile="$2"
184 fi
185
186 generate_envFile ${toset} ${envfile}
187
188 # force update environment
189 # should be replaced with "do_action env update" when #172472 gets resolved
190 env-update &> /dev/null
191 }
192
193
194
195 ### update action ###
196 #
197 # This action regenerates the /etc/env.d file for the current profile. Basically
198 # the same as set, only it does not take any parameters. It should be called from ebuilds
199 # installing Ada libs
200
201 describe_update() {
202 echo "Update active gnat profile picking up new libs."
203 }
204
205 do_update() {
206 local toset=$(get_current_gnat)
207 local envfile="${ENVDIR}/${MARKER}${toset}"
208 generate_envFile ${toset} ${envfile}
209 do_action env update &> /dev/null
210 }
211
212 ### unset action ###
213
214 describe_unset() {
215 echo "Remove settings for currently active gnat"
216 }
217
218 do_unset() {
219 local active=$(get_current_gnat)
220 # check whether we have any profile set before removing anything..
221 if [[ -n ${active} ]] ; then
222 unset_env ${active}
223 do_action env update &> /dev/null
224 fi
225 }
226
227
228
229 1.1 app-eselect/eselect-gnat/files/gnat-common-1.4-r1.bash
230
231 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-eselect/eselect-gnat/files/gnat-common-1.4-r1.bash?rev=1.1&view=markup
232 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-eselect/eselect-gnat/files/gnat-common-1.4-r1.bash?rev=1.1&content-type=text/plain
233
234 Index: gnat-common-1.4-r1.bash
235 ===================================================================
236 # Copyright 1999-2015 Gentoo Foundation
237 # Distributed under the terms of the GNU General Public License v2
238 # $Header: /var/cvsroot/gentoo-x86/app-eselect/eselect-gnat/files/gnat-common-1.4-r1.bash,v 1.1 2015/03/31 16:48:57 ulm Exp $
239
240 #
241 # Author: George Shapovalov <george@g.o>
242 # Purpose: Contains common vars/locations and functions for use by gnat.eclass,
243 # gnat.eselect and gnatbuild.eclass.
244 #
245 # NOTE!!!
246 # This code should just define vars (try to limit these!) and simple functions.
247 # No bash extensions!!
248 # That is, no portage or eclass constructs are allowed!
249 #
250
251
252
253 # ----------------------------------
254 # Globals
255
256 # Environmantal stuff (for env update)
257 SPECSDIR="/usr/share/gnat/eselect"
258 ENVDIR="/etc/env.d"
259 MARKER="55gnat-"
260
261 # User configurable settings
262 SETTINGSDIR="/etc/ada"
263 PRIMELIST="${SETTINGSDIR}/primary_compilers"
264
265 ## Lib install locations
266 ##
267 ## Gnat profile dependent files go under under ${LibTop}/${Gnat_Profile}/${PN}
268 ## and common files go unde SpecsDir, DataDir
269 #PREFIX=/usr
270 ## Replace %LIBDIR% below with $(get_libdir) in eclasses and ebuilds (top level Ok, inherit multilib)
271 ## or $(profile2libdir ${profile}) in this code, eselect module or anywhere
272 ## outside portage (as profile will be available only during actual execution, this only should
273 ## be done inside corresponding functions).
274 #AdalibSpecsDir=${PREFIX}/include/ada
275 #AdalibDataDir=${PREFIX}/share/ada
276 #AdalibLibTop=${PREFIX}/%LIBDIR%/ada
277
278
279 # ------------------------------------
280 # Helpers
281 #
282
283 # get_all_profile_components splits gnat profile and returns pace separated list of its components:
284 # x86_64-pc-linux-gnu-gnat-gcc-4.1 -> x86_64-pc-linux-gnu gcc 4.1
285 # args:
286 # $1 - the string to split
287 get_all_profile_components() {
288 local GnatSLOT=${1##*-}
289 local remainder=${1%-*}
290 local GnatPkg=${remainder##*-}
291 remainder=${remainder%-gnat-*}
292 echo "${remainder} ${GnatPkg} ${GnatSLOT}"
293 }
294
295 # similar to above, returns only SLOT component:
296 # x86_64-pc-linux-gnu-gnat-gcc-4.1 -> 4.1
297 # args:
298 # $1 - the string to extract the slot from
299 get_gnat_SLOT() {
300 echo "${1##*-}"
301 }
302
303 # returns only Pkg component:
304 # x86_64-pc-linux-gnu-gnat-gcc-4.1 -> gcc
305 # args:
306 # $1 - the string to extract the slot from
307 get_gnat_Pkg() {
308 local remainder=${1%-*}
309 echo "${remainder##*-}"
310 }
311
312 # returns only Arch component:
313 # x86_64-pc-linux-gnu-gnat-gcc-4.1 -> x86_64-pc-linux-gnu
314 # args:
315 # $1 - the string to extract the slot from
316 get_gnat_Arch() {
317 echo ${1%-gnat-*}
318 }
319
320
321
322 ## -------------------------------------------
323 # gnat profile and lib detection functions
324
325
326 # create a list of all gnat env.d files
327 # for now use trivial implementation - store name of active profile in the
328 # env file name, so it gets called 55gnat-${ARCH}-${PN}-${SLOT}
329 get_env_list() {
330 for fn in ${ENVDIR}/${MARKER}*; do
331 echo $(basename ${fn})
332 done
333 }
334
335
336
337 # find all installed compilers and return a list
338 find_all_compilers() {
339 [[ ! -d ${SPECSDIR} ]] && exit
340 for fn in ${SPECSDIR}/*; do
341 [[ ! -d ${fn} ]] && echo $(basename ${fn});
342 done
343 }
344
345 # find installed primary compilers and return a list
346 find_primary_compilers() {
347 [[ ! -f ${PRIMELIST} ]] && exit
348 for fn in $(cat ${PRIMELIST}); do
349 [[ -f ${SPECSDIR}/${fn} ]] && echo ${fn};
350 done
351 }
352
353 # find installed libs and return a list
354 find_all_libs() {
355 [[ ! -d ${SPECSDIR} ]] && exit
356 for fn in ${SPECSDIR}/*; do
357 [[ -d ${fn} ]] && echo $(basename ${fn});
358 done
359 }
360
361 # find libs that have been built for a given profile
362 # Arguments:
363 # $1 - gnat profile for which to detect active libs
364 find_libs4profile() {
365 libs=( $(find_all_libs) )
366
367 for (( i = 0 ; i < ${#libs[@]} ; i = i + 1 )) ; do
368 [[ -f ${SPECSDIR}/${libs[$i]}/$1 ]] && echo "${libs[$i]}"
369 done
370 }
371
372
373
374
375 ## -----------------------
376 # main action - central part of do_set and helpers
377
378
379 # extracts values of the passed var definition from given spec file
380 # params:
381 # $1: spec file (as generated by gnabuild.eclass)
382 # $2: variable name
383 get_var_from_spec() {
384 local var=$(grep -e "^ *$2=" $1|cut -d= -f2)
385 echo ${var}
386 }
387
388
389 # Cycle through given libs and form a ':' separated list of settings for the given
390 # var. Repeating settings are omitted, that is unique entry is added only first
391 # time it is encountered.
392 #
393 # params:
394 # $1 - name of env var to process
395 # $2 - name of gnat profile
396 # $3.. - list of libs to check (to avoid its composition every time)
397 # - the list is expanded to list of args at the point of call
398 get_lib_var_settings() {
399 local envVar=$1
400 local toset=$2
401 #echo "get_lib_var_settings params:$@" >> /tmp/eselect-gnat.rep
402 if [[ "none" != ${3} ]]; then
403 local envString
404 local specLine=$(get_var_from_spec ${SPECSDIR}/$3/${toset} ${envVar})
405 if [[ -n ${specLine} ]]; then
406 envString="${specLine}"
407 fi
408 shift
409 #
410 while [[ -n $3 ]]; do
411 specLine=$(get_var_from_spec ${SPECSDIR}/$3/${toset} ${envVar})
412 #echo "$3:${specLine}." >> /tmp/eselect-gnat.rep
413 if [[ -n ${specLine} ]] && [[ ! ${envString} =~ ${specLine} ]]; then
414 envString="${envString}:${specLine}"
415 fi
416 shift
417 done
418 echo "${envString}"
419 fi
420 }
421
422
423
424 # The action!
425 # Part common for do_set and do_update of gnat.eselect, also used in gnat.eclass
426 # to set environment during lib build and installation
427 #
428 # params:
429 # $1 - profile to set (toset param inside)
430 # $2 - envfile
431
432 generate_envFile() {
433 local toset=$1
434 local envfile=$2
435
436 local binpath="$(get_var_from_spec ${SPECSDIR}/${toset} binpath)"
437 local libexecpath="$(get_var_from_spec ${SPECSDIR}/${toset} libexecpath)"
438 local libs=( $(find_libs4profile ${toset}) )
439 #echo "generate_envFile: ${libs[@]}" >> /tmp/eselect-gnat.rep
440 if (( 0 == ${#libs[@]} )); then
441 libs="none"
442 fi
443
444 local MyPath="${binpath}:${libexecpath}:$(get_lib_var_settings PATH ${toset} ${libs[@]})"
445 echo "PATH=${MyPath}" > "${envfile}"
446 echo "ROOTPATH=${MyPath}" >> "${envfile}"
447 echo "MANPATH=$(get_var_from_spec ${SPECSDIR}/${toset} manpath):$(get_lib_var_settings MANPATH ${toset} ${libs[@]})" >> "${envfile}"
448 echo "INFOPATH=$(get_var_from_spec ${SPECSDIR}/${toset} infopath):$(get_lib_var_settings INFOPATH ${toset} ${libs[@]})" >> "${envfile}"
449 # the next three use the common base
450 local libBase=$(get_var_from_spec ${SPECSDIR}/${toset} ldpath)
451 echo "LDPATH=${libBase}:${libBase}/adalib:$(get_lib_var_settings LDPATH ${toset} ${libs[@]})" >> "${envfile}"
452 echo "ADA_INCLUDE_PATH=${libBase}/adainclude:$(get_lib_var_settings ADA_INCLUDE_PATH ${toset} ${libs[@]})" >> "${envfile}"
453 echo "ADA_OBJECTS_PATH=${libBase}/adalib:$(get_lib_var_settings ADA_OBJECTS_PATH ${toset} ${libs[@]})" >> "${envfile}"
454 # ADA_PROJECT_PATH may not be set in any of the installed packages,
455 # we should only create this line if cumulative var is non-empty
456 My_ProjectPath=$(get_lib_var_settings ADA_PROJECT_PATH ${toset} ${libs[@]})
457 if [[ -n ${My_ProjectPath} ]]; then
458 echo "ADA_PROJECT_PATH=${My_ProjectPath}" >> "${envfile}"
459 fi
460 }
461
462
463
464
465 1.1 app-eselect/eselect-gnat/files/gnat.eselect-1.4
466
467 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-eselect/eselect-gnat/files/gnat.eselect-1.4?rev=1.1&view=markup
468 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-eselect/eselect-gnat/files/gnat.eselect-1.4?rev=1.1&content-type=text/plain
469
470 Index: gnat.eselect-1.4
471 ===================================================================
472 # Copyright 1999-2015 Gentoo Foundation
473 # Distributed under the terms of the GNU General Public License v2
474 # $Id: gnat.eselect-1.4,v 1.1 2015/03/31 16:48:57 ulm Exp $
475
476 DESCRIPTION="Manage the installed gnat compilers"
477 MAINTAINER="ada@g.o"
478 SVN_DATE='$Date: 2015/03/31 16:48:57 $'
479 VERSION=$(svn_date_to_version "${SVN_DATE}" )
480
481 # "inheriting" common stuff
482 # this crude sourcing has to stay the way it is, as common code
483 # cannot be part of some eclass (bug #192505)
484 . /usr/share/gnat/lib/gnat-common.bash
485
486
487 ### Phylosophy
488 # Each gnat installs a "specs" file named ${ARCH}-${PN}-${SLOT} under ${SPECSDIR}
489 # Each lib creates a dir with its name under ${SPECSDIR} and populates it with
490 # similar specs files (same name scheme)
491 # Recognizing gnat specs from lib specs is then eazy - test entry for being a
492 # dir, then just check what gnat profiles are installed for each lib..
493 # doset then creates env file that combines settings for gnat and for the
494 # corresponding profile of each installed lib..
495
496
497 ### Helpers
498
499 # return *the* name of the active profile, checking that we do not have multiple
500 # env files.
501 # There can be only one!
502 get_current_gnat() {
503 local profiles=( $(get_env_list) )
504
505 if [ ${profiles[@]} == "${MARKER}*" ]; then exit; fi
506
507 if (( 1 == ${#profiles[@]} )); then
508 local active=${profiles[0]#${MARKER}}
509 else
510 die -q "${ENVDIR} contains multiple gnat profiles, please cleanup!"
511 fi
512
513 echo ${active}
514 # disabling this check, as we want to use get_current_gnat with empty profile
515 # as an indication that last gnat in SLOT was removed
516 # if [ -f ${SPECSDIR}/${active} ]; then
517 # echo ${active}
518 # else
519 # die -q "the active env.d profile does not correspond to any installed gnat!"
520 # fi
521 }
522
523 # validity check that was removed from get_current_gnat, in case we need it
524 # somewhere..
525 # Arguments:
526 # $1 - name of the gnat profiel to check
527 profile_is_valid() {
528 if [[ -n $1 ]] ; then
529 [[ -f ${SPECSDIR}/$1 ]] || return 1
530 fi
531 }
532
533 # check if the passed arg represents the installed gnat and return it or
534 # not_found
535 # takes args:
536 # $1 - list ID to check
537 get_name_from_list() {
538 compiler=$1
539
540 compilers=( $(find_all_compilers) )
541 for (( i = 0 ; i < ${#compilers[@]} ; i = i + 1 )) ; do
542 if [[ ${compilers[$i]} == ${compiler} ]] ; then
543 echo ${compiler}
544 return
545 fi
546 done
547
548 echo "(not-found)"
549 }
550
551
552 # removes env files (for compiler and libs)
553 # params:
554 # $1: the name of profile for which to remove env file
555 unset_env() {
556 rm -f ${ENVDIR}/${MARKER}$1 &> /dev/null
557 }
558
559
560 ### show action ###
561
562 describe_show() {
563 echo "Show the active gnat compiler/profile and installed libs"
564 }
565
566 do_show() {
567 active=$(get_current_gnat)
568 if $(profile_is_valid ${active}); then
569 write_list_start "Current gnat version:"
570 if [[ -n ${active} ]] ; then
571 write_kv_list_entry "$active" ""
572 libs=( $(find_libs4profile ${active}) )
573 write_list_start "Active libs:"
574 write_numbered_list "${libs[@]}"
575 else
576 write_kv_list_entry "(none set)" ""
577 fi
578 else
579 write_error_msg "The active profile in ${ENVDIR} is not valid! Please set a valid profile!"
580 fi
581 }
582
583 ### list action ###
584
585 describe_list() {
586 echo "List installed gnat compilers and libs"
587 }
588
589 do_list() {
590 compilers=( $(find_all_compilers ) )
591 active=$(get_current_gnat)
592
593 write_list_start "Available gnat compilers:"
594
595 if [[ -n ${compilers[@]} ]] ; then
596 local i
597 for (( i = 0 ; i < ${#compilers[@]} ; i = i + 1 )) ; do
598 linkversion=${compilers[${i}]}
599
600 [[ $linkversion == $active ]] && \
601 compilers[${i}]="${compilers[${i}]} $(highlight '*' )"
602 done
603 write_numbered_list "${compilers[@]}"
604
605 # now the libs
606 libs=( $(find_all_libs) )
607 write_list_start "Installed libs:"
608 for (( i = 0 ; i < ${#libs[@]} ; i = i + 1 )) ; do
609 [ -f ${SPECSDIR}/${libs[$i]}/${active} ] && \
610 libs[${i}]="${libs[${i}]} $(highlight '*' )"
611 done
612 write_numbered_list "${libs[@]}"
613 else
614 write_kv_list_entry "(none found)" ""
615 fi
616 }
617
618
619 ### set action ###
620
621 describe_set() {
622 echo "Set active gnat compiler"
623 }
624
625 # The set action. Parameters:
626 # $1 - name of profile to set, obligatory, passed by eselect
627 # $2 - optional, name of env file to generate. Used from gnat.eclass.
628 do_set() {
629 if [[ -z ${1} ]] ; then
630 # no parameter
631 die -q "You didn't tell me which gnat to use"
632 fi
633
634 local toset=$(get_name_from_list $1)
635 if [[ ${toset} == "(not-found)" ]] ; then
636 die -q "I don't recognise the selection"
637 fi
638
639 # the action!
640 # in this implementation simply create an appropriate env file
641 local active=$(get_current_gnat)
642 if [[ -z ${2} ]] ; then
643 local envfile="${ENVDIR}/${MARKER}${toset}"
644
645 # now we need to remove an old env file, which is guaranteed to
646 # be unique by get_current_gnat above
647 if [[ -n ${active} ]] ; then
648 unset_env ${active}
649 fi
650 # just for a good measure remove the one we are going to write
651 unset_env ${toset}
652 else
653 local envfile="$2"
654 fi
655
656 generate_envFile ${toset} ${envfile}
657
658 # force update environment
659 # should be replaced with "do_action env update" when #172472 gets resolved
660 env-update &> /dev/null
661 }
662
663
664
665 ### update action ###
666 #
667 # This action regenerates the /etc/env.d file for the current profile. Basically
668 # the same as set, only it does not take any parameters. It should be called from ebuilds
669 # installing Ada libs or in the pkg_postrm in gnatbuild.eclass, to clean up the
670 # profile if last gnat in SLOT was removed.
671
672 describe_update() {
673 echo "Update active gnat profile picking up new libs."
674 }
675
676 do_update() {
677 local toset=$(get_current_gnat)
678 local envfile="${ENVDIR}/${MARKER}${toset}"
679 # now check whether to update or unset the profile
680 if $(profile_is_valid ${toset}); then
681 generate_envFile ${toset} ${envfile}
682 else
683 unset_env ${toset}
684 fi
685 do_action env update &> /dev/null
686 }
687
688 ### unset action ###
689
690 describe_unset() {
691 echo "Remove settings for currently active gnat"
692 }
693
694 do_unset() {
695 local active=$(get_current_gnat)
696 # check whether we have any profile set before removing anything..
697 if [[ -n ${active} ]] ; then
698 unset_env ${active}
699 do_action env update &> /dev/null
700 fi
701 }
702
703
704
705 1.1 app-eselect/eselect-gnat/files/gnat.eselect-1.5
706
707 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-eselect/eselect-gnat/files/gnat.eselect-1.5?rev=1.1&view=markup
708 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-eselect/eselect-gnat/files/gnat.eselect-1.5?rev=1.1&content-type=text/plain
709
710 Index: gnat.eselect-1.5
711 ===================================================================
712 # Copyright 1999-2015 Gentoo Foundation
713 # Distributed under the terms of the GNU General Public License v2
714 # $Id: gnat.eselect-1.5,v 1.1 2015/03/31 16:48:57 ulm Exp $
715
716 DESCRIPTION="Manage the installed gnat compilers"
717 MAINTAINER="ada@g.o"
718 SVN_DATE='$Date: 2015/03/31 16:48:57 $'
719 VERSION=$(svn_date_to_version "${SVN_DATE}" )
720
721 # "inheriting" common stuff
722 # this crude sourcing has to stay the way it is, as common code
723 # cannot be part of some eclass (bug #192505)
724 . /usr/share/gnat/lib/gnat-common.bash
725
726
727 ### Phylosophy
728 # Each gnat installs a "specs" file named ${ARCH}-${PN}-${SLOT} under ${SPECSDIR}
729 # Each lib creates a dir with its name under ${SPECSDIR} and populates it with
730 # similar specs files (same name scheme)
731 # Recognizing gnat specs from lib specs is then eazy - test entry for being a
732 # dir, then just check what gnat profiles are installed for each lib..
733 # doset then creates env file that combines settings for gnat and for the
734 # corresponding profile of each installed lib..
735
736
737 ### Helpers
738
739 # return *the* name of the active profile, checking that we do not have multiple
740 # env files.
741 # There can be only one!
742 get_current_gnat() {
743 local profiles=( $(get_env_list) )
744
745 if [ ${profiles[@]} == "${MARKER}*" ]; then exit; fi
746
747 if (( 1 == ${#profiles[@]} )); then
748 local active=${profiles[0]#${MARKER}}
749 else
750 die -q "${ENVDIR} contains multiple gnat profiles, please cleanup!"
751 fi
752
753 echo ${active}
754 # disabling this check, as we want to use get_current_gnat with empty profile
755 # as an indication that last gnat in SLOT was removed
756 # if [ -f ${SPECSDIR}/${active} ]; then
757 # echo ${active}
758 # else
759 # die -q "the active env.d profile does not correspond to any installed gnat!"
760 # fi
761 }
762
763 # validity check that was removed from get_current_gnat, in case we need it
764 # somewhere..
765 # Arguments:
766 # $1 - name of the gnat profiel to check
767 profile_is_valid() {
768 if [[ -n $1 ]] ; then
769 [[ -f ${SPECSDIR}/$1 ]] || return 1
770 fi
771 }
772
773 # check if the passed arg represents the installed gnat and return it or
774 # not_found
775 # takes args:
776 # $1 - list ID to check
777 get_name_from_list() {
778 compiler=$1
779
780 compilers=( $(find_all_compilers) )
781 for (( i = 0 ; i < ${#compilers[@]} ; i = i + 1 )) ; do
782 if [[ ${compilers[$i]} == ${compiler} ]] ; then
783 echo ${compiler}
784 return
785 fi
786 done
787
788 echo "(not-found)"
789 }
790
791
792 # removes env files (for compiler and libs)
793 # params:
794 # $1: the name of profile for which to remove env file
795 unset_env() {
796 rm -f ${ENVDIR}/${MARKER}$1 &> /dev/null
797 }
798
799
800 ### show action ###
801
802 describe_show() {
803 echo "Show the active gnat compiler/profile and installed libs"
804 }
805
806 do_show() {
807 active=$(get_current_gnat)
808 if $(profile_is_valid ${active}); then
809 write_list_start "Current gnat version:"
810 if [[ -n ${active} ]] ; then
811 write_kv_list_entry "$active" ""
812 libs=( $(find_libs4profile ${active}) )
813 write_list_start "Active libs:"
814 write_numbered_list "${libs[@]}"
815 else
816 write_kv_list_entry "(none set)" ""
817 fi
818 else
819 write_error_msg "The active profile in ${ENVDIR} is not valid! Please set a valid profile!"
820 fi
821 }
822
823 ### list action ###
824
825 describe_list() {
826 echo "List installed gnat compilers and libs"
827 }
828
829 do_list() {
830 compilers=( $(find_all_compilers ) )
831 active=$(get_current_gnat)
832
833 write_list_start "Available gnat compilers:"
834
835 local i
836 for (( i = 0 ; i < ${#compilers[@]} ; i = i + 1 )) ; do
837 linkversion=${compilers[${i}]}
838
839 [[ $linkversion == $active ]] && \
840 compilers[${i}]=$(highlight_marker "${compilers[${i}]}")
841 done
842 write_numbered_list -m "(none)" "${compilers[@]}"
843
844 # now the libs
845 libs=( $(find_all_libs) )
846 write_list_start "Installed libs:"
847 for (( i = 0 ; i < ${#libs[@]} ; i = i + 1 )) ; do
848 [ -f ${SPECSDIR}/${libs[$i]}/${active} ] && \
849 libs[${i}]=$(highlight_marker "${libs[${i}]}")
850 done
851 write_numbered_list -m "(no libs)" "${libs[@]}"
852 }
853
854
855 ### set action ###
856
857 describe_set() {
858 echo "Set active gnat compiler"
859 }
860
861 # The set action. Parameters:
862 # $1 - name of profile to set, obligatory, passed by eselect
863 # $2 - optional, name of env file to generate. Used from gnat.eclass.
864 do_set() {
865 if [[ -z ${1} ]] ; then
866 # no parameter
867 die -q "You didn't tell me which gnat to use"
868 fi
869
870 local toset=$(get_name_from_list $1)
871 if [[ ${toset} == "(not-found)" ]] ; then
872 die -q "I don't recognise the selection"
873 fi
874
875 # the action!
876 # in this implementation simply create an appropriate env file
877 local active=$(get_current_gnat)
878 if [[ -z ${2} ]] ; then
879 local envfile="${ENVDIR}/${MARKER}${toset}"
880
881 # now we need to remove an old env file, which is guaranteed to
882 # be unique by get_current_gnat above
883 if [[ -n ${active} ]] ; then
884 unset_env ${active}
885 fi
886 # just for a good measure remove the one we are going to write
887 unset_env ${toset}
888 else
889 local envfile="$2"
890 fi
891
892 generate_envFile ${toset} ${envfile}
893
894 # force update environment
895 # should be replaced with "do_action env update" when #172472 gets resolved
896 env-update &> /dev/null
897 }
898
899
900
901 ### update action ###
902 #
903 # This action regenerates the /etc/env.d file for the current profile. Basically
904 # the same as set, only it does not take any parameters. It should be called from ebuilds
905 # installing Ada libs or in the pkg_postrm in gnatbuild.eclass, to clean up the
906 # profile if last gnat in SLOT was removed.
907
908 describe_update() {
909 echo "Update active gnat profile picking up new libs."
910 }
911
912 do_update() {
913 local toset=$(get_current_gnat)
914 local envfile="${ENVDIR}/${MARKER}${toset}"
915 # now check whether to update or unset the profile
916 if $(profile_is_valid ${toset}); then
917 generate_envFile ${toset} ${envfile}
918 else
919 unset_env ${toset}
920 fi
921 do_action env update &> /dev/null
922 }
923
924 ### unset action ###
925
926 describe_unset() {
927 echo "Remove settings for currently active gnat"
928 }
929
930 do_unset() {
931 local active=$(get_current_gnat)
932 # check whether we have any profile set before removing anything..
933 if [[ -n ${active} ]] ; then
934 unset_env ${active}
935 do_action env update &> /dev/null
936 fi
937 }
938
939
940
941 1.1 app-eselect/eselect-gnat/files/gnat-common-1.3-r1.bash
942
943 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-eselect/eselect-gnat/files/gnat-common-1.3-r1.bash?rev=1.1&view=markup
944 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/app-eselect/eselect-gnat/files/gnat-common-1.3-r1.bash?rev=1.1&content-type=text/plain
945
946 Index: gnat-common-1.3-r1.bash
947 ===================================================================
948 # Copyright 1999-2015 Gentoo Foundation
949 # Distributed under the terms of the GNU General Public License v2
950 # $Header: /var/cvsroot/gentoo-x86/app-eselect/eselect-gnat/files/gnat-common-1.3-r1.bash,v 1.1 2015/03/31 16:48:57 ulm Exp $
951
952 #
953 # Original Author: George Shapovalov <george@g.o>
954 # Purpose: Contains common vars/locations and functions for use by gnat.eclass,
955 # gnat.eselect and gnatbuild.eclass.
956 #
957 # NOTE!!!
958 # This code should just define vars (try to limit these!) and simple functions.
959 # No bash extensions!!
960 # That is, no portage or eclass constructs are allowed!
961 #
962
963
964
965 # ----------------------------------
966 # Globals
967
968 # Environmantal stuff (for env update)
969 SPECSDIR="/usr/share/gnat/eselect"
970 ENVDIR="/etc/env.d"
971 MARKER="55gnat-"
972
973 # User configurable settings
974 SETTINGSDIR="/etc/ada"
975 PRIMELIST="${SETTINGSDIR}/primary_compilers"
976
977 ## Lib install locations
978 ##
979 ## Gnat profile dependent files go under under ${LibTop}/${Gnat_Profile}/${PN}
980 ## and common files go unde SpecsDir, DataDir
981 #PREFIX=/usr
982 ## Replace %LIBDIR% below with $(get_libdir) in eclasses and ebuilds (top level Ok, inherit multilib)
983 ## or $(profile2libdir ${profile}) in this code, eselect module or anywhere
984 ## outside portage (as profile will be available only during actual execution, this only should
985 ## be done inside corresponding functions).
986 #AdalibSpecsDir=${PREFIX}/include/ada
987 #AdalibDataDir=${PREFIX}/share/ada
988 #AdalibLibTop=${PREFIX}/%LIBDIR%/ada
989
990
991 # ------------------------------------
992 # Helpers
993 #
994
995 # get_all_profile_components splits gnat profile and returns pace separated list of its components:
996 # x86_64-pc-linux-gnu-gnat-gcc-4.1 -> x86_64-pc-linux-gnu gcc 4.1
997 # args:
998 # $1 - the string to split
999 get_all_profile_components() {
1000 local GnatSLOT=${1##*-}
1001 local remainder=${1%-*}
1002 local GnatPkg=${remainder##*-}
1003 remainder=${remainder%-gnat-*}
1004 echo "${remainder} ${GnatPkg} ${GnatSLOT}"
1005 }
1006
1007 # similar to above, returns only SLOT component:
1008 # x86_64-pc-linux-gnu-gnat-gcc-4.1 -> 4.1
1009 # args:
1010 # $1 - the string to extract the slot from
1011 get_gnat_SLOT() {
1012 echo "${1##*-}"
1013 }
1014
1015 # returns only Pkg component:
1016 # x86_64-pc-linux-gnu-gnat-gcc-4.1 -> gcc
1017 # args:
1018 # $1 - the string to extract the slot from
1019 get_gnat_Pkg() {
1020 local remainder=${1%-*}
1021 echo "${remainder##*-}"
1022 }
1023
1024 # returns only Arch component:
1025 # x86_64-pc-linux-gnu-gnat-gcc-4.1 -> x86_64-pc-linux-gnu
1026 # args:
1027 # $1 - the string to extract the slot from
1028 get_gnat_Arch() {
1029 echo ${1%-gnat-*}
1030 }
1031
1032
1033
1034 ## -------------------------------------------
1035 # gnat profile and lib detection functions
1036
1037
1038 # create a list of all gnat env.d files
1039 # for now use trivial implementation - store name of active profile in the
1040 # env file name, so it gets called 55gnat-${ARCH}-${PN}-${SLOT}
1041 get_env_list() {
1042 for fn in ${ENVDIR}/${MARKER}*; do
1043 echo $(basename ${fn})
1044 done
1045 }
1046
1047
1048
1049 # find all installed compilers and return a list
1050 find_all_compilers() {
1051 [[ ! -d ${SPECSDIR} ]] && exit
1052 for fn in ${SPECSDIR}/*; do
1053 [[ ! -d ${fn} ]] && echo $(basename ${fn});
1054 done
1055 }
1056
1057 # find installed primary compilers and return a list
1058 find_primary_compilers() {
1059 [[ ! -f ${PRIMELIST} ]] && exit
1060 for fn in $(cat ${PRIMELIST}); do
1061 [[ -f ${SPECSDIR}/${fn} ]] && echo ${fn};
1062 done
1063 }
1064
1065 # find installed libs and return a list
1066 find_all_libs() {
1067 [[ ! -d ${SPECSDIR} ]] && exit
1068 for fn in ${SPECSDIR}/*; do
1069 [[ -d ${fn} ]] && echo $(basename ${fn});
1070 done
1071 }
1072
1073 # find libs that have been built for a given profile
1074 # Arguments:
1075 # $1 - gnat profile for which to detect active libs
1076 find_libs4profile() {
1077 libs=( $(find_all_libs) )
1078
1079 for (( i = 0 ; i < ${#libs[@]} ; i = i + 1 )) ; do
1080 [[ -f ${SPECSDIR}/${libs[$i]}/$1 ]] && echo "${libs[$i]}"
1081 done
1082 }
1083
1084
1085
1086
1087 ## -----------------------
1088 # main action - central part of do_set and helpers
1089
1090
1091 # extracts values of the passed var definition from given spec file
1092 # params:
1093 # $1: spec file (as generated by gnabuild.eclass)
1094 # $2: variable name
1095 get_var_from_spec() {
1096 local var=$(grep -e "^ *$2=" $1|cut -d= -f2)
1097 echo ${var}
1098 }
1099
1100
1101 # Cycle through given libs and form a ':' separated list of settings for the given
1102 # var. Returned string starts with ':' if there is any non-empty setting,
1103 # otherwise returns empty string. Repeating settings are omitted, that is
1104 # unique entry is added only first time it is encountered. No need to have some
1105 # common dir listed many times in PATH for example.
1106 #
1107 # params:
1108 # $1 - name of env var to process
1109 # $2 - name of gnat profile
1110 # $3.. - list of libs to check (to avoid its composition every time)
1111 # - the list is expanded to list of args at the point of call
1112 get_lib_var_settings() {
1113 local envVar=$1
1114 local toset=$2
1115 #echo "get_lib_var_settings params:$@" >> /tmp/eselect-gnat.rep
1116 if [[ "none" != ${3} ]]; then
1117 local envString
1118 local specLine
1119 while [[ -n $3 ]]; do
1120 specLine=$(get_var_from_spec ${SPECSDIR}/$3/${toset} ${envVar})
1121 #echo "$3:${specLine}." >> /tmp/eselect-gnat.rep
1122 if [[ -n ${specLine} ]] && [[ ! ${envString} =~ ${specLine} ]]; then
1123 envString="${envString}:${specLine}"
1124 fi
1125 shift
1126 done
1127 echo "${envString}"
1128 fi
1129 }
1130
1131
1132
1133 # The action!
1134 # Part common for do_set and do_update of gnat.eselect, also used in gnat.eclass
1135 # to set environment during lib build and installation
1136 #
1137 # params:
1138 # $1 - profile to set (toset param inside)
1139 # $2 - envfile
1140
1141 generate_envFile() {
1142 local toset=$1
1143 local envfile=$2
1144
1145 local binpath="$(get_var_from_spec ${SPECSDIR}/${toset} binpath)"
1146 local libexecpath="$(get_var_from_spec ${SPECSDIR}/${toset} libexecpath)"
1147 local libs=( $(find_libs4profile ${toset}) )
1148 #echo "generate_envFile: ${libs[@]}" >> /tmp/eselect-gnat.rep
1149 if (( 0 == ${#libs[@]} )); then
1150 libs="none"
1151 fi
1152
1153 local MyPath="${binpath}:${libexecpath}$(get_lib_var_settings PATH ${toset} ${libs[@]})"
1154 echo "PATH=${MyPath}" > "${envfile}"
1155 echo "ROOTPATH=${MyPath}" >> "${envfile}"
1156 echo "MANPATH=$(get_var_from_spec ${SPECSDIR}/${toset} manpath)$(get_lib_var_settings MANPATH ${toset} ${libs[@]})" >> "${envfile}"
1157 echo "INFOPATH=$(get_var_from_spec ${SPECSDIR}/${toset} infopath)$(get_lib_var_settings INFOPATH ${toset} ${libs[@]})" >> "${envfile}"
1158 # the next three use the common base
1159 local libBase=$(get_var_from_spec ${SPECSDIR}/${toset} ldpath)
1160 echo "LDPATH=${libBase}:${libBase}/adalib$(get_lib_var_settings LDPATH ${toset} ${libs[@]})" >> "${envfile}"
1161 echo "ADA_INCLUDE_PATH=${libBase}/adainclude$(get_lib_var_settings ADA_INCLUDE_PATH ${toset} ${libs[@]})" >> "${envfile}"
1162 echo "ADA_OBJECTS_PATH=${libBase}/adalib$(get_lib_var_settings ADA_OBJECTS_PATH ${toset} ${libs[@]})" >> "${envfile}"
1163 # ADA_PROJECT_PATH may not be set in any of the installed packages,
1164 # we should only create this line if cumulative var is non-empty
1165 My_ProjectPath=$(get_lib_var_settings ADA_PROJECT_PATH ${toset} ${libs[@]})
1166 if [[ -n ${My_ProjectPath} ]]; then
1167 echo "ADA_PROJECT_PATH=${My_ProjectPath}" >> "${envfile}"
1168 fi
1169 }