Gentoo Archives: gentoo-portage-dev

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

Replies