1 |
Add checks for common mistakes when installing bash completion files: |
2 |
legacy directory, incorrect naming, missing aliases, deprecated 'have' |
3 |
function. |
4 |
|
5 |
Changes in v2: |
6 |
|
7 |
- silenced output (error) when sourcing completion files, |
8 |
|
9 |
- faked _have() to enable all conditional completions in the tested |
10 |
files. |
11 |
--- |
12 |
bin/misc-functions.sh | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 |
1 file changed, 124 insertions(+) |
14 |
|
15 |
diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh |
16 |
index e45d810..9cc7d40 100755 |
17 |
--- a/bin/misc-functions.sh |
18 |
+++ b/bin/misc-functions.sh |
19 |
@@ -610,6 +610,130 @@ install_qa_check() { |
20 |
fi |
21 |
fi |
22 |
|
23 |
+ # Check for correct bash-completion install path. |
24 |
+ local syscompdir=$(pkg-config --variable=completionsdir bash-completion 2>/dev/null) |
25 |
+ : ${syscompdir:=/usr/share/bash-completion/completions} |
26 |
+ |
27 |
+ local instcompdir |
28 |
+ if [[ -d ${ED}/usr/share/bash-completion/completions ]]; then |
29 |
+ instcompdir=${ED}/usr/share/bash-completion/completions |
30 |
+ elif [[ -d ${ED}/usr/share/bash-completion ]]; then |
31 |
+ if [[ ${syscompdir} != /usr/share/bash-completion ]]; then |
32 |
+ eqawarn "Bash completions were installed in legacy location. Please update" |
33 |
+ eqawarn "the ebuild to get the install paths using bash-completion-r1.eclass." |
34 |
+ eqawarn |
35 |
+ fi |
36 |
+ |
37 |
+ instcompdir=${ED}/usr/share/bash-completion |
38 |
+ fi |
39 |
+ |
40 |
+ # Do a few QA tests on bash completions. |
41 |
+ if [[ -n ${instcompdir} && -f ${EROOT}/usr/share/bash-completion/bash_completion ]]; then |
42 |
+ ( |
43 |
+ _get_completions() { |
44 |
+ # source the file |
45 |
+ source "${1}" &>/dev/null |
46 |
+ |
47 |
+ [[ ${USED_HAVE} == yes ]] && echo '__HAVE_USED__' |
48 |
+ |
49 |
+ # print the completed commands |
50 |
+ while read -a args; do |
51 |
+ [[ ${args[0]} == complete ]] || continue |
52 |
+ # command always comes last, one per line |
53 |
+ echo "${args[$(( ${#args[@]} - 1))]}" |
54 |
+ done < <(complete -p) |
55 |
+ } |
56 |
+ |
57 |
+ # load the global helpers |
58 |
+ source "${EROOT}"/usr/share/bash-completion/bash_completion |
59 |
+ |
60 |
+ # clean up predefined completions |
61 |
+ complete -r |
62 |
+ |
63 |
+ # force all completions on |
64 |
+ _have() { |
65 |
+ return 0 |
66 |
+ } |
67 |
+ |
68 |
+ local USED_HAVE=no |
69 |
+ # add a replacement for have() |
70 |
+ have() { |
71 |
+ USED_HAVE=yes |
72 |
+ |
73 |
+ unset -v have |
74 |
+ _have ${1} && have=yes |
75 |
+ } |
76 |
+ |
77 |
+ local f c completions |
78 |
+ local all_compls=() |
79 |
+ local all_files=() |
80 |
+ local qa_warnings=() |
81 |
+ |
82 |
+ for f in "${instcompdir}"/*; do |
83 |
+ # ignore directories and other non-files |
84 |
+ [[ ! -f ${f} ]] && continue |
85 |
+ |
86 |
+ # skip the common code file |
87 |
+ # (in case we're run in /usr/share/bash-completion) |
88 |
+ [[ ${f##*/} == bash_completion ]] && continue |
89 |
+ |
90 |
+ completions=( $(_get_completions "${f}") ) |
91 |
+ |
92 |
+ if [[ ${completions[0]} == __HAVE_USED__ ]]; then |
93 |
+ qa_warnings+=( |
94 |
+ "${f##*/}: 'have' command is deprecated and must not be used." |
95 |
+ ) |
96 |
+ unset 'completions[0]' |
97 |
+ fi |
98 |
+ |
99 |
+ if [[ -z ${completions[@]} ]]; then |
100 |
+ qa_warnings+=( |
101 |
+ "${f##*/}: does not define any completions (failed to source?)." |
102 |
+ ) |
103 |
+ continue |
104 |
+ fi |
105 |
+ |
106 |
+ for c in "${completions[@]}"; do |
107 |
+ if [[ ${c} == /* ]]; then |
108 |
+ qa_warnings+=( |
109 |
+ "${f##*/}: absolute paths can not be used for completions (on '${c}')." |
110 |
+ ) |
111 |
+ else |
112 |
+ all_compls+=( "${c}" ) |
113 |
+ fi |
114 |
+ done |
115 |
+ |
116 |
+ if ! has "${f##*/}" "${all_compls[@]}"; then |
117 |
+ qa_warnings+=( |
118 |
+ "${f##*/}: incorrect name, no completions for '${f##*/}' command defined." |
119 |
+ ) |
120 |
+ fi |
121 |
+ |
122 |
+ all_files+=( "${f##*/}" ) |
123 |
+ done |
124 |
+ |
125 |
+ for c in "${all_compls[@]}"; do |
126 |
+ if ! has "${c}" "${all_files[@]}"; then |
127 |
+ qa_warnings+=( |
128 |
+ "${c}: missing alias (symlink) for completed command." |
129 |
+ ) |
130 |
+ fi |
131 |
+ done |
132 |
+ |
133 |
+ if [[ -n ${qa_warnings[@]} ]]; then |
134 |
+ eqawarn "Problems with installed bash completions were found:" |
135 |
+ eqawarn |
136 |
+ for c in "${qa_warnings[@]}"; do |
137 |
+ eqawarn " ${c}" |
138 |
+ done |
139 |
+ eqawarn |
140 |
+ eqawarn "For more details on installing bash-completions, please see:" |
141 |
+ eqawarn "https://wiki.gentoo.org/wiki/Bash/Installing_completion_files" |
142 |
+ eqawarn |
143 |
+ fi |
144 |
+ ) |
145 |
+ fi |
146 |
+ |
147 |
# Look for leaking LDFLAGS into pkg-config files |
148 |
f=$(egrep -sH '^Libs.*-Wl,(-O[012]|--hash-style)' "${ED}"/usr/*/pkgconfig/*.pc) |
149 |
if [[ -n ${f} ]] ; then |
150 |
-- |
151 |
2.1.0 |