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 v2] install-qa-checks.d: Add a check for Gentoo path policies (FHS-y)
Date: Tue, 04 Sep 2018 17:53:47
Message-Id: 20180904175338.3146-1-mgorny@gentoo.org
1 Add a check that verifies whether ebuilds don't install to paths
2 forbidden by the policy. This mostly aims to verbosely report bugs
3 such as missing dependencies causing empty install paths, resulting
4 in files ending up in / and bad upstreams. This should also help
5 detect the relatively common mistake of using /usr/share/doc/${P}
6 instead of ${PF}.
7
8 The initial list of allowed paths was based on what ebuilds installed
9 to my system.
10 ---
11 bin/install-qa-check.d/08gentoo-paths | 80 +++++++++++++++++++++++++++
12 1 file changed, 80 insertions(+)
13 create mode 100644 bin/install-qa-check.d/08gentoo-paths
14
15 Changes in v2:
16 * added a comment wrt /usr/games (as suggested by ulm).
17
18 diff --git a/bin/install-qa-check.d/08gentoo-paths b/bin/install-qa-check.d/08gentoo-paths
19 new file mode 100644
20 index 000000000..946185cc2
21 --- /dev/null
22 +++ b/bin/install-qa-check.d/08gentoo-paths
23 @@ -0,0 +1,80 @@
24 +# Check whether ebuilds are not installing new, non-Gentoo-ey paths.
25 +
26 +gentoo_path_check() {
27 + # allowed path definitions
28 + # ------------------------
29 +
30 + # directories common to / and /usr
31 + local allowed_common_dirs=(
32 + bin lib lib32 lib64 libx32 sbin
33 + )
34 +
35 + # toplevel directories which can be installed to by ebuilds
36 + # /home is not included as no ebuilds should install files there
37 + local allowed_paths_toplevel=(
38 + "${allowed_common_dirs[@]}"
39 + boot dev etc opt srv usr var
40 + # TODO: do we need it? gconf installs empty dir there but that's
41 + # all
42 + root
43 + )
44 +
45 + # directories in /usr which can be installed to by ebuilds
46 + # /usr/games is not included as it is banned nowadays
47 + local allowed_paths_usr=(
48 + "${allowed_common_dirs[@]}"
49 + include libexec share src
50 + # toolchain stuff
51 + "${CHOST}" "${CTARGET}"
52 + )
53 +
54 +
55 + # the logic
56 + # ---------
57 + local bad_paths=()
58 + local x
59 +
60 + local shopt_save=$(shopt -p nullglob)
61 + shopt -s nullglob
62 +
63 + # 1. check for unexpected top-level directories
64 + local toplevel_dirs=( "${ED%/}"/* )
65 + for x in "${toplevel_dirs[@]##*/}"; do
66 + if ! has "${x}" "${allowed_paths_toplevel[@]}"; then
67 + bad_paths+=( "/${x}" )
68 + fi
69 + done
70 +
71 + # 2. check for unexpected /usr subdirectories
72 + local usr_dirs=( "${ED%/}"/usr/* )
73 + for x in "${usr_dirs[@]##*/}"; do
74 + if ! has "${x}" "${allowed_paths_usr[@]}"; then
75 + bad_paths+=( "/usr/${x}" )
76 + fi
77 + done
78 +
79 + # 3. check for unexpected /usr/share/doc subdirectories
80 + local doc_dirs=( "${ED%/}"/usr/share/doc/* )
81 + for x in "${doc_dirs[@]##*/}"; do
82 + if [[ ${x} != ${PF} ]]; then
83 + bad_paths+=( "/usr/share/doc/${x}" )
84 + fi
85 + done
86 +
87 + ${shopt_save}
88 +
89 + # report
90 + # ------
91 + if [[ -n ${bad_paths[@]} ]]; then
92 + eqawarn "The ebuild is installing to one or more unexpected paths:"
93 + eqawarn
94 + eqatag -v non-gentoo-paths "${bad_paths[@]}"
95 + eqawarn
96 + eqawarn "Please fix the ebuild to use correct FHS/Gentoo policy paths."
97 + fi
98 +}
99 +
100 +gentoo_path_check
101 +: # guarantee successful exit
102 +
103 +# vim:ft=sh
104 --
105 2.18.0

Replies