dev-qt/qttest: stable 5.14.2 for ppc, bug #719732
[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                         eqawarn "L10N warning: no .pak file for ${lang} (${lang}.pak not found)"
75                 fi
76         done
77
78         # Bug 588198
79         rm -f fake-bidi.pak || die
80         rm -f fake-bidi.pak.info || die
81
82         # Look for extra pak files.
83         # Remove pak files that the user does not want.
84         for pak in *.pak; do
85                 lang=${pak%.pak}
86
87                 if [[ ${lang} == en-US ]]; then
88                         continue
89                 fi
90
91                 if ! has ${lang} ${CHROMIUM_LANGS}; then
92                         eqawarn "L10N warning: no ${lang} in LANGS"
93                         continue
94                 fi
95
96                 if ! use l10n_${lang}; then
97                         rm "${pak}" || die
98                         rm -f "${pak}.info" || die
99                 fi
100         done
101 }
102
103 chromium_pkg_die() {
104         if [[ "${EBUILD_PHASE}" != "compile" ]]; then
105                 return
106         fi
107
108         # Prevent user problems like bug #348235.
109         if ( shopt -s extglob; is-flagq '-g?(gdb)?([1-9])' ); then
110                 ewarn
111                 ewarn "You have enabled debug info (i.e. -g or -ggdb in your CFLAGS/CXXFLAGS)."
112                 ewarn "This produces very large build files causes the linker to consume large"
113                 ewarn "amounts of memory."
114                 ewarn
115                 ewarn "Please try removing -g{,gdb} before reporting a bug."
116                 ewarn
117         fi
118
119         # ccache often causes bogus compile failures, especially when the cache gets
120         # corrupted.
121         if has ccache ${FEATURES}; then
122                 ewarn
123                 ewarn "You have enabled ccache. Please try disabling ccache"
124                 ewarn "before reporting a bug."
125                 ewarn
126         fi
127
128         # No ricer bugs.
129         if use_if_iuse custom-cflags; then
130                 ewarn
131                 ewarn "You have enabled the custom-cflags USE flag."
132                 ewarn "Please disable it before reporting a bug."
133                 ewarn
134         fi
135
136         # If the system doesn't have enough memory, the compilation is known to
137         # fail. Print info about memory to recognize this condition.
138         einfo
139         einfo "$(grep MemTotal /proc/meminfo)"
140         einfo "$(grep SwapTotal /proc/meminfo)"
141         einfo
142 }
143
144 # @VARIABLE: EGYP_CHROMIUM_COMMAND
145 # @DESCRIPTION:
146 # Path to the gyp_chromium script.
147 : ${EGYP_CHROMIUM_COMMAND:=build/gyp_chromium}
148
149 # @VARIABLE: EGYP_CHROMIUM_DEPTH
150 # @DESCRIPTION:
151 # Depth for egyp_chromium.
152 : ${EGYP_CHROMIUM_DEPTH:=.}
153
154 # @FUNCTION: egyp_chromium
155 # @USAGE: [gyp arguments]
156 # @DESCRIPTION:
157 # Calls EGYP_CHROMIUM_COMMAND with depth EGYP_CHROMIUM_DEPTH and given
158 # arguments. The full command line is echoed for logging.
159 egyp_chromium() {
160         set -- "${EGYP_CHROMIUM_COMMAND}" --depth="${EGYP_CHROMIUM_DEPTH}" "$@"
161         echo "$@"
162         "$@"
163 }
164
165 # @FUNCTION: gyp_use
166 # @USAGE: <USE flag> [GYP flag] [true suffix] [false suffix]
167 # @DESCRIPTION:
168 # If USE flag is set, echo -D[GYP flag]=[true suffix].
169 #
170 # If USE flag is not set, echo -D[GYP flag]=[false suffix].
171 #
172 # [GYP flag] defaults to use_[USE flag] with hyphens converted to underscores.
173 #
174 # [true suffix] defaults to 1. [false suffix] defaults to 0.
175 gyp_use() {
176         local gypflag="-D${2:-use_${1//-/_}}="
177         usex "$1" "${gypflag}" "${gypflag}"  "${3-1}" "${4-0}"
178 }