kde-plasma/breeze-gtk: x86 stable wrt bug #613144
[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                 CONFIG_CHECK="~PID_NS ~NET_NS ~SECCOMP_FILTER ~USER_NS ~ADVISE_SYSCALLS ~!COMPAT_VDSO"
36                 check_extra_config
37         fi
38 }
39
40 # @ECLASS-VARIABLE: CHROMIUM_LANGS
41 # @DEFAULT_UNSET
42 # @DESCRIPTION:
43 # List of language packs available for this package.
44
45 _chromium_set_l10n_IUSE() {
46         [[ ${EAPI:-0} == 0 ]] && die "EAPI=${EAPI} is not supported"
47
48         local lang
49         for lang in ${CHROMIUM_LANGS}; do
50                 # Default to enabled since we bundle them anyway.
51                 # USE-expansion will take care of disabling the langs the user has not
52                 # selected via L10N.
53                 IUSE+=" +l10n_${lang}"
54         done
55 }
56
57 if [[ ${CHROMIUM_LANGS} ]]; then
58         _chromium_set_l10n_IUSE
59 fi
60
61 # @FUNCTION: chromium_remove_language_paks
62 # @USAGE:
63 # @DESCRIPTION:
64 # Removes pak files from the current directory for languages that the user has
65 # not selected via the L10N variable.
66 # Also performs QA checks to ensure CHROMIUM_LANGS has been set correctly.
67 chromium_remove_language_paks() {
68         local lang pak
69
70         # Look for missing pak files.
71         for lang in ${CHROMIUM_LANGS}; do
72                 if [[ ! -e ${lang}.pak ]]; then
73                         # https://bugs.gentoo.org/583762
74                         if [[ ${lang} != sr-ME || ! -e me.pak  ]]; then
75                                 eqawarn "L10N warning: no .pak file for ${lang} (${lang}.pak not found)"
76                         fi
77                 fi
78         done
79
80         # Bug 588198
81         rm -f fake-bidi.pak || die
82
83         # Look for extra pak files.
84         # Remove pak files that the user does not want.
85         for pak in *.pak; do
86                 lang=${pak%.pak}
87
88                 if [[ ${lang} == en-US ]]; then
89                         continue
90                 fi
91
92                 # https://bugs.gentoo.org/583762
93                 if [[ ${lang} == me ]]; then
94                         if ! has sr-ME ${CHROMIUM_LANGS}; then
95                                 eqawarn "L10N warning: no sr-ME in LANGS"
96                         elif ! use l10n_sr-ME; then
97                                 rm "${pak}" || die
98                         fi
99                         continue
100                 fi
101
102                 if ! has ${lang} ${CHROMIUM_LANGS}; then
103                         eqawarn "L10N warning: no ${lang} in LANGS"
104                         continue
105                 fi
106                 if ! use l10n_${lang}; then
107                         rm "${pak}" || die
108                 fi
109         done
110 }
111
112 chromium_pkg_die() {
113         if [[ "${EBUILD_PHASE}" != "compile" ]]; then
114                 return
115         fi
116
117         # Prevent user problems like bug #348235.
118         eshopts_push -s extglob
119         if is-flagq '-g?(gdb)?([1-9])'; then
120                 ewarn
121                 ewarn "You have enabled debug info (i.e. -g or -ggdb in your CFLAGS/CXXFLAGS)."
122                 ewarn "This produces very large build files causes the linker to consume large"
123                 ewarn "amounts of memory."
124                 ewarn
125                 ewarn "Please try removing -g{,gdb} before reporting a bug."
126                 ewarn
127         fi
128         eshopts_pop
129
130         # ccache often causes bogus compile failures, especially when the cache gets
131         # corrupted.
132         if has ccache ${FEATURES}; then
133                 ewarn
134                 ewarn "You have enabled ccache. Please try disabling ccache"
135                 ewarn "before reporting a bug."
136                 ewarn
137         fi
138
139         # No ricer bugs.
140         if use_if_iuse custom-cflags; then
141                 ewarn
142                 ewarn "You have enabled the custom-cflags USE flag."
143                 ewarn "Please disable it before reporting a bug."
144                 ewarn
145         fi
146
147         # If the system doesn't have enough memory, the compilation is known to
148         # fail. Print info about memory to recognize this condition.
149         einfo
150         einfo "$(grep MemTotal /proc/meminfo)"
151         einfo "$(grep SwapTotal /proc/meminfo)"
152         einfo
153 }
154
155 # @VARIABLE: EGYP_CHROMIUM_COMMAND
156 # @DESCRIPTION:
157 # Path to the gyp_chromium script.
158 : ${EGYP_CHROMIUM_COMMAND:=build/gyp_chromium}
159
160 # @VARIABLE: EGYP_CHROMIUM_DEPTH
161 # @DESCRIPTION:
162 # Depth for egyp_chromium.
163 : ${EGYP_CHROMIUM_DEPTH:=.}
164
165 # @FUNCTION: egyp_chromium
166 # @USAGE: [gyp arguments]
167 # @DESCRIPTION:
168 # Calls EGYP_CHROMIUM_COMMAND with depth EGYP_CHROMIUM_DEPTH and given
169 # arguments. The full command line is echoed for logging.
170 egyp_chromium() {
171         set -- "${EGYP_CHROMIUM_COMMAND}" --depth="${EGYP_CHROMIUM_DEPTH}" "$@"
172         echo "$@"
173         "$@"
174 }
175
176 # @FUNCTION: gyp_use
177 # @USAGE: <USE flag> [GYP flag] [true suffix] [false suffix]
178 # @DESCRIPTION:
179 # If USE flag is set, echo -D[GYP flag]=[true suffix].
180 #
181 # If USE flag is not set, echo -D[GYP flag]=[false suffix].
182 #
183 # [GYP flag] defaults to use_[USE flag] with hyphens converted to underscores.
184 #
185 # [true suffix] defaults to 1. [false suffix] defaults to 0.
186 gyp_use() {
187         local gypflag="-D${2:-use_${1//-/_}}="
188         usex "$1" "${gypflag}" "${gypflag}"  "${3-1}" "${4-0}"
189 }