chromium-2.eclass: warn on CONFIG_GRKERNSEC
[gentoo.git] / eclass / chromium-2.eclass
1 # Copyright 1999-2016 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: chromium-2.eclass
5 # @MAINTAINER:
6 # Chromium Herd <chromium@gentoo.org>
7 # @AUTHOR:
8 # Mike Gilbert <floppym@gentoo.org>
9 # @BLURB: Shared functions for chromium and google-chrome
10
11 inherit eutils linux-info
12
13 if [[ ${PN} == chromium ]]; then
14         IUSE+=" custom-cflags"
15 fi
16
17 # @FUNCTION: chromium_suid_sandbox_check_kernel_config
18 # @USAGE:
19 # @DESCRIPTION:
20 # Ensures the system kernel supports features needed for SUID sandbox to work.
21 chromium_suid_sandbox_check_kernel_config() {
22         has "${EAPI:-0}" 0 1 2 3 && die "EAPI=${EAPI} is not supported"
23
24         if [[ "${MERGE_TYPE}" == "source" || "${MERGE_TYPE}" == "binary" ]]; then
25                 # Warn if the kernel does not support features needed for sandboxing.
26                 # Bug #363987.
27                 ERROR_PID_NS="PID_NS is required for sandbox to work"
28                 ERROR_NET_NS="NET_NS is required for sandbox to work"
29                 ERROR_USER_NS="USER_NS is required for sandbox to work"
30                 ERROR_SECCOMP_FILTER="SECCOMP_FILTER is required for sandbox to work"
31                 # Warn if the kernel does not support features needed for the browser to work
32                 # (bug #552576, bug #556286).
33                 ERROR_ADVISE_SYSCALLS="CONFIG_ADVISE_SYSCALLS is required for the renderer (bug #552576)"
34                 ERROR_COMPAT_VDSO="CONFIG_COMPAT_VDSO causes segfaults (bug #556286)"
35                 ERROR_GRKERNSEC="CONFIG_GRKERNSEC breaks sandbox (bug #613668)"
36                 CONFIG_CHECK="~PID_NS ~NET_NS ~SECCOMP_FILTER ~USER_NS ~ADVISE_SYSCALLS ~!COMPAT_VDSO ~!GRKERNSEC"
37                 check_extra_config
38         fi
39 }
40
41 # @ECLASS-VARIABLE: CHROMIUM_LANGS
42 # @DEFAULT_UNSET
43 # @DESCRIPTION:
44 # List of language packs available for this package.
45
46 _chromium_set_l10n_IUSE() {
47         [[ ${EAPI:-0} == 0 ]] && die "EAPI=${EAPI} is not supported"
48
49         local lang
50         for lang in ${CHROMIUM_LANGS}; do
51                 # Default to enabled since we bundle them anyway.
52                 # USE-expansion will take care of disabling the langs the user has not
53                 # selected via L10N.
54                 IUSE+=" +l10n_${lang}"
55         done
56 }
57
58 if [[ ${CHROMIUM_LANGS} ]]; then
59         _chromium_set_l10n_IUSE
60 fi
61
62 # @FUNCTION: chromium_remove_language_paks
63 # @USAGE:
64 # @DESCRIPTION:
65 # Removes pak files from the current directory for languages that the user has
66 # not selected via the L10N variable.
67 # Also performs QA checks to ensure CHROMIUM_LANGS has been set correctly.
68 chromium_remove_language_paks() {
69         local lang pak
70
71         # Look for missing pak files.
72         for lang in ${CHROMIUM_LANGS}; do
73                 if [[ ! -e ${lang}.pak ]]; then
74                         # https://bugs.gentoo.org/583762
75                         if [[ ${lang} != sr-ME || ! -e me.pak  ]]; then
76                                 eqawarn "L10N warning: no .pak file for ${lang} (${lang}.pak not found)"
77                         fi
78                 fi
79         done
80
81         # Bug 588198
82         rm -f fake-bidi.pak || die
83
84         # Look for extra pak files.
85         # Remove pak files that the user does not want.
86         for pak in *.pak; do
87                 lang=${pak%.pak}
88
89                 if [[ ${lang} == en-US ]]; then
90                         continue
91                 fi
92
93                 # https://bugs.gentoo.org/583762
94                 if [[ ${lang} == me ]]; then
95                         if ! has sr-ME ${CHROMIUM_LANGS}; then
96                                 eqawarn "L10N warning: no sr-ME in LANGS"
97                         elif ! use l10n_sr-ME; then
98                                 rm "${pak}" || die
99                         fi
100                         continue
101                 fi
102
103                 if ! has ${lang} ${CHROMIUM_LANGS}; then
104                         eqawarn "L10N warning: no ${lang} in LANGS"
105                         continue
106                 fi
107                 if ! use l10n_${lang}; then
108                         rm "${pak}" || die
109                 fi
110         done
111 }
112
113 chromium_pkg_die() {
114         if [[ "${EBUILD_PHASE}" != "compile" ]]; then
115                 return
116         fi
117
118         # Prevent user problems like bug #348235.
119         eshopts_push -s extglob
120         if is-flagq '-g?(gdb)?([1-9])'; then
121                 ewarn
122                 ewarn "You have enabled debug info (i.e. -g or -ggdb in your CFLAGS/CXXFLAGS)."
123                 ewarn "This produces very large build files causes the linker to consume large"
124                 ewarn "amounts of memory."
125                 ewarn
126                 ewarn "Please try removing -g{,gdb} before reporting a bug."
127                 ewarn
128         fi
129         eshopts_pop
130
131         # ccache often causes bogus compile failures, especially when the cache gets
132         # corrupted.
133         if has ccache ${FEATURES}; then
134                 ewarn
135                 ewarn "You have enabled ccache. Please try disabling ccache"
136                 ewarn "before reporting a bug."
137                 ewarn
138         fi
139
140         # No ricer bugs.
141         if use_if_iuse custom-cflags; then
142                 ewarn
143                 ewarn "You have enabled the custom-cflags USE flag."
144                 ewarn "Please disable it before reporting a bug."
145                 ewarn
146         fi
147
148         # If the system doesn't have enough memory, the compilation is known to
149         # fail. Print info about memory to recognize this condition.
150         einfo
151         einfo "$(grep MemTotal /proc/meminfo)"
152         einfo "$(grep SwapTotal /proc/meminfo)"
153         einfo
154 }
155
156 # @VARIABLE: EGYP_CHROMIUM_COMMAND
157 # @DESCRIPTION:
158 # Path to the gyp_chromium script.
159 : ${EGYP_CHROMIUM_COMMAND:=build/gyp_chromium}
160
161 # @VARIABLE: EGYP_CHROMIUM_DEPTH
162 # @DESCRIPTION:
163 # Depth for egyp_chromium.
164 : ${EGYP_CHROMIUM_DEPTH:=.}
165
166 # @FUNCTION: egyp_chromium
167 # @USAGE: [gyp arguments]
168 # @DESCRIPTION:
169 # Calls EGYP_CHROMIUM_COMMAND with depth EGYP_CHROMIUM_DEPTH and given
170 # arguments. The full command line is echoed for logging.
171 egyp_chromium() {
172         set -- "${EGYP_CHROMIUM_COMMAND}" --depth="${EGYP_CHROMIUM_DEPTH}" "$@"
173         echo "$@"
174         "$@"
175 }
176
177 # @FUNCTION: gyp_use
178 # @USAGE: <USE flag> [GYP flag] [true suffix] [false suffix]
179 # @DESCRIPTION:
180 # If USE flag is set, echo -D[GYP flag]=[true suffix].
181 #
182 # If USE flag is not set, echo -D[GYP flag]=[false suffix].
183 #
184 # [GYP flag] defaults to use_[USE flag] with hyphens converted to underscores.
185 #
186 # [true suffix] defaults to 1. [false suffix] defaults to 0.
187 gyp_use() {
188         local gypflag="-D${2:-use_${1//-/_}}="
189         usex "$1" "${gypflag}" "${gypflag}"  "${3-1}" "${4-0}"
190 }