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] install-qa-checks.d: Add a check for Gentoo path policies (FHS-y)
Date: Tue, 04 Sep 2018 17:58:08
Message-Id: 20180904175800.3870-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 | 77 +++++++++++++++++++++++++++
12 1 file changed, 77 insertions(+)
13 create mode 100644 bin/install-qa-check.d/08gentoo-paths
14
15 Changes in v3:
16 * stopped allowing install to /root.
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..3ee887df0
21 --- /dev/null
22 +++ b/bin/install-qa-check.d/08gentoo-paths
23 @@ -0,0 +1,77 @@
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 + )
41 +
42 + # directories in /usr which can be installed to by ebuilds
43 + # /usr/games is not included as it is banned nowadays
44 + local allowed_paths_usr=(
45 + "${allowed_common_dirs[@]}"
46 + include libexec share src
47 + # toolchain stuff
48 + "${CHOST}" "${CTARGET}"
49 + )
50 +
51 +
52 + # the logic
53 + # ---------
54 + local bad_paths=()
55 + local x
56 +
57 + local shopt_save=$(shopt -p nullglob)
58 + shopt -s nullglob
59 +
60 + # 1. check for unexpected top-level directories
61 + local toplevel_dirs=( "${ED%/}"/* )
62 + for x in "${toplevel_dirs[@]##*/}"; do
63 + if ! has "${x}" "${allowed_paths_toplevel[@]}"; then
64 + bad_paths+=( "/${x}" )
65 + fi
66 + done
67 +
68 + # 2. check for unexpected /usr subdirectories
69 + local usr_dirs=( "${ED%/}"/usr/* )
70 + for x in "${usr_dirs[@]##*/}"; do
71 + if ! has "${x}" "${allowed_paths_usr[@]}"; then
72 + bad_paths+=( "/usr/${x}" )
73 + fi
74 + done
75 +
76 + # 3. check for unexpected /usr/share/doc subdirectories
77 + local doc_dirs=( "${ED%/}"/usr/share/doc/* )
78 + for x in "${doc_dirs[@]##*/}"; do
79 + if [[ ${x} != ${PF} ]]; then
80 + bad_paths+=( "/usr/share/doc/${x}" )
81 + fi
82 + done
83 +
84 + ${shopt_save}
85 +
86 + # report
87 + # ------
88 + if [[ -n ${bad_paths[@]} ]]; then
89 + eqawarn "The ebuild is installing to one or more unexpected paths:"
90 + eqawarn
91 + eqatag -v non-gentoo-paths "${bad_paths[@]}"
92 + eqawarn
93 + eqawarn "Please fix the ebuild to use correct FHS/Gentoo policy paths."
94 + fi
95 +}
96 +
97 +gentoo_path_check
98 +: # guarantee successful exit
99 +
100 +# vim:ft=sh
101 --
102 2.18.0

Replies