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