Gentoo Archives: gentoo-portage-dev

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