Gentoo Archives: gentoo-commits

From: "Chi-Thanh Christopher Nguyen (chithanh)" <chithanh@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] eselect r785 - trunk/extern/modules
Date: Sat, 27 Nov 2010 05:02:55
Message-Id: 20101127040229.C99AF20051@flycatcher.gentoo.org
1 Author: chithanh
2 Date: 2010-11-27 04:02:29 +0000 (Sat, 27 Nov 2010)
3 New Revision: 785
4
5 Modified:
6 trunk/extern/modules/mesa.eselect
7 Log:
8 Update mesa.eselect with comments from gentoo-devel, thanks to fauli for suggestions
9
10 Modified: trunk/extern/modules/mesa.eselect
11 ===================================================================
12 --- trunk/extern/modules/mesa.eselect 2010-11-26 16:53:53 UTC (rev 784)
13 +++ trunk/extern/modules/mesa.eselect 2010-11-27 04:02:29 UTC (rev 785)
14 @@ -6,25 +6,26 @@
15 MAINTAINER="x11@g.o"
16 SVN_DATE='$Date: $'
17 VERSION=$(svn_date_to_version "${SVN_DATE}" )
18 -EBUILD_VERSION="0.0.7"
19 +EBUILD_VERSION="0.0.8"
20
21 -CONFIG_DIR="${EROOT}/usr/share/mesa"
22 +MESA_CONF_DIR="${EROOT}/usr/share/mesa"
23 MESA_DIR="${EROOT}/usr/lib/mesa"
24 DRI_DIR="${EROOT}/usr/lib/dri"
25
26 -source "${CONFIG_DIR}"/eselect-mesa.conf || die "Failed to source config"
27 +source "${MESA_CONF_DIR}"/eselect-mesa.conf || die "Failed to source config"
28
29 # receives a filename of the driver as argument, outputs the architecture (classic or gallium)
30 drivername_to_architecture() {
31 local drivername=$1
32 - local x
33 - local y
34 - local z
35 - for x in ${MESA_IMPLEMENTATIONS}; do
36 - for y in classic gallium; do
37 - z=$(get_drivername ${x} ${y})
38 - if [[ ${drivername} == ${z} ]]; then
39 - echo ${y}
40 + local driver
41 + local implementation
42 + local comp
43 + for driver in ${MESA_IMPLEMENTATIONS}; do
44 + for implementation in classic gallium; do
45 + comp=$(get_drivername ${driver} ${implementation})
46 + # check if the driver name matches the parameter
47 + if [[ ${drivername} == ${comp} ]]; then
48 + echo ${implementation}
49 exit 0
50 fi
51 done
52 @@ -41,31 +42,37 @@
53 # receives the chipset family as argument, outputs the currently selected architecture for that family
54 get_current_implementation() {
55 local family=$1
56 - local y
57 - local z
58 + local implementation
59 + local drivername
60 + # the symlink is named the same as the classic driver
61 local current=$(get_drivername ${family} classic)
62
63 if [[ -L ${DRI_DIR}/${current} ]]; then
64 - for y in classic gallium; do
65 - z=$(get_drivername ${family} ${y})
66 - if [[ $(readlink ${DRI_DIR}/${current}) == "../mesa/${z}" && -f "${MESA_DIR}/${z}" ]]; then
67 - echo $(drivername_to_architecture ${z})
68 + for implementation in classic gallium; do
69 + drivername=$(get_drivername ${family} ${implementation})
70 + # read the symlink which points to the actual driver file
71 + if [[ $(readlink ${DRI_DIR}/${current}) == "../mesa/${drivername}" && -f "${MESA_DIR}/${drivername}" ]]; then
72 + echo $(drivername_to_architecture ${drivername})
73 fi
74 done
75 elif [[ -f ${DRI_DIR}/${current} ]]; then
76 + # if it is a file, assume classic
77 echo "classic"
78 fi
79 }
80
81 -# receives a family as argument, outputs all installed driver filenames
82 +# receives a family as argument, outputs all installed implementations
83 get_implementations() {
84 local ret
85 local family=$1
86 - local y
87 - local z
88 - for y in classic gallium; do
89 - z=$(get_drivername ${family} ${y})
90 - [ -f ${MESA_DIR}/${z} -o -L ${MESA_DIR}/${z} ] && ret+="${y} "
91 + local implementation
92 + local drivername
93 + # check which driver files exist in MESA_DIR
94 + for implementation in classic gallium; do
95 + drivername=$(get_drivername ${family} ${implementation})
96 + if [[ -f ${MESA_DIR}/${drivername} || -L ${MESA_DIR}/${drivername} ]]; then
97 + ret+="${implementation} "
98 + fi
99 done
100 echo ${ret}
101 }
102 @@ -77,12 +84,11 @@
103
104 do_show() {
105 local current
106 - local x
107 - local y
108 - for x in ${MESA_IMPLEMENTATIONS}; do
109 - current=$(get_current_implementation ${x})
110 + local driver
111 + for driver in ${MESA_IMPLEMENTATIONS}; do
112 + current=$(get_current_implementation ${driver})
113 if [[ -n ${current} ]]; then
114 - echo -n "${x} "
115 + echo -n "${driver} "
116 echo ${current}
117 fi
118 done
119 @@ -95,20 +101,19 @@
120 }
121
122 do_list() {
123 - local x
124 - local y
125 - local z
126 + local driver
127 local available
128
129 - for x in ${MESA_IMPLEMENTATIONS}; do
130 - write_list_start ${MESA_DRIVERS[${x},description]}
131 - available=( $(get_implementations ${x}) )
132 + # assemble the list of drivers with the installed implementations
133 + for driver in ${MESA_IMPLEMENTATIONS}; do
134 + write_list_start ${MESA_DRIVERS[${driver},description]}
135 + available=( $(get_implementations ${driver}) )
136 for (( i = 0 ; i < ${#available[@]} ; i = i + 1 )); do
137 - if [[ ${available[${i}]} == $(get_current_implementation ${x}) ]]; then
138 + if [[ ${available[${i}]} == $(get_current_implementation ${driver}) ]]; then
139 available[${i}]=$(highlight_marker "${available[${i}]}")
140 fi
141 - write_kv_list_entry "${available[${i}]}"
142 done
143 + write_numbered_list "${available[@]}"
144 done
145 }
146
147 @@ -129,15 +134,16 @@
148
149 do_set() {
150 if [[ "$1" == --auto ]]; then
151 - local x
152 - for x in ${MESA_IMPLEMENTATIONS}; do
153 - local y=( $(get_implementations ${x}) )
154 - # prefer default implementation
155 - if [[ ${y[1]} == ${MESA_DRIVERS[${x},default]} ]]; then
156 - y=${y[1]}
157 + local driver
158 + for driver in ${MESA_IMPLEMENTATIONS}; do
159 + local implementations=( $(get_implementations ${driver}) )
160 + # prefer default implementation if installed
161 + if [[ ${implementations[1]} == ${MESA_DRIVERS[${driver},default]} ]]; then
162 + implementations=${implementations[1]}
163 fi
164 - if [[ -n ${y} && ! -n $(get_current_implementation ${x}) ]]; then
165 - do_set ${x} ${y}
166 + # set the implementation if it is not already set
167 + if [[ -n ${implementations} && ! -n $(get_current_implementation ${driver}) ]]; then
168 + do_set ${driver} ${implementations}
169 fi
170 done
171 exit 0
172 @@ -147,6 +153,16 @@
173
174 local family=$(echo $1 | tr '[:upper:]' '[:lower:]')
175 local architecture=$(echo $2 | tr '[:upper:]' '[:lower:]')
176 +
177 + # architecture may be specified by its name or its index
178 + if is_number "${architecture}"; then
179 + # numeric index, find the architecture's name
180 + local implementations=( $(get_implementations ${family} ${architecture}) )
181 + [[ ${architecture} -ge 1 && ${architecture} -le ${#implementations[@]} ]] \
182 + || die -q "Number out of range: ${architecture}"
183 + architecture=${implementations[architecture-1]}
184 + fi
185 +
186 local symlink=$(get_drivername ${family} classic)
187 local target=$(get_drivername ${family} ${architecture})
188
189 @@ -155,7 +171,7 @@
190 elif [[ -e ${DRI_DIR}/${symlink} && ! -L ${DRI_DIR}/${symlink} ]]; then
191 die -q "Unable to update ${DRI_DIR}/${symlink} - not a symlink"
192 elif [[ -f ${MESA_DIR}/${target} ]]; then
193 - echo "Switching $1 to $2"
194 + echo "Switching ${family} to ${architecture}"
195 ln -s -f ../mesa/${target} ${DRI_DIR}/${symlink}
196 fi
197 }