net-fs/openafs-kernel: remove vulnerable versions
[gentoo.git] / eclass / chromium.eclass
1 # Copyright 1999-2015 Gentoo Foundation
2 # Distributed under the terms of the GNU General Public License v2
3 # $Id$
4
5 # @ECLASS: chromium.eclass
6 # @MAINTAINER:
7 # Chromium Herd <chromium@gentoo.org>
8 # @AUTHOR:
9 # Mike Gilbert <floppym@gentoo.org>
10 # @BLURB: Shared functions for chromium and google-chrome
11
12 inherit eutils fdo-mime gnome2-utils linux-info
13
14 if [[ ${CHROMIUM_EXPORT_PHASES} != no ]]; then
15         EXPORT_FUNCTIONS pkg_preinst pkg_postinst pkg_postrm
16 fi
17
18 if [[ ${PN} == chromium ]]; then
19         IUSE+=" custom-cflags"
20 fi
21
22 # @FUNCTION: chromium_suid_sandbox_check_kernel_config
23 # @USAGE:
24 # @DESCRIPTION:
25 # Ensures the system kernel supports features needed for SUID sandbox to work.
26 chromium_suid_sandbox_check_kernel_config() {
27         has "${EAPI:-0}" 0 1 2 3 && die "EAPI=${EAPI} is not supported"
28
29         if [[ "${MERGE_TYPE}" == "source" || "${MERGE_TYPE}" == "binary" ]]; then
30                 # Warn if the kernel does not support features needed for sandboxing.
31                 # Bug #363987.
32                 ERROR_PID_NS="PID_NS is required for sandbox to work"
33                 ERROR_NET_NS="NET_NS is required for sandbox to work"
34                 ERROR_USER_NS="USER_NS is required for sandbox to work"
35                 ERROR_SECCOMP_FILTER="SECCOMP_FILTER is required for sandbox to work"
36                 # Warn if the kernel does not support features needed for the browser to work
37                 # (bug #552576, bug #556286).
38                 ERROR_ADVISE_SYSCALLS="CONFIG_ADVISE_SYSCALLS is required for the renderer (bug #552576)"
39                 ERROR_COMPAT_VDSO="CONFIG_COMPAT_VDSO causes segfaults (bug #556286)"
40                 CONFIG_CHECK="~PID_NS ~NET_NS ~SECCOMP_FILTER ~USER_NS ~ADVISE_SYSCALLS ~!COMPAT_VDSO"
41                 check_extra_config
42         fi
43 }
44
45 # @ECLASS-VARIABLE: CHROMIUM_LANGS
46 # @DEFAULT_UNSET
47 # @DESCRIPTION:
48 # List of language packs available for this package.
49
50 _chromium_set_linguas_IUSE() {
51         [[ ${EAPI:-0} == 0 ]] && die "EAPI=${EAPI} is not supported"
52
53         local lang
54         for lang in ${CHROMIUM_LANGS}; do
55                 # Default to enabled since we bundle them anyway.
56                 # USE-expansion will take care of disabling the langs the user has not
57                 # selected via LINGUAS.
58                 IUSE+=" +linguas_${lang}"
59         done
60 }
61
62 if [[ ${CHROMIUM_LANGS} ]]; then
63         _chromium_set_linguas_IUSE
64 fi
65
66 _chromium_crlang() {
67         local x
68         for x in "$@"; do
69                 case $x in
70                         es_LA) echo es-419 ;;
71                         *) echo "${x/_/-}" ;;
72                 esac
73         done
74 }
75
76 _chromium_syslang() {
77         local x
78         for x in "$@"; do
79                 case $x in
80                         es-419) echo es_LA ;;
81                         *) echo "${x/-/_}" ;;
82                 esac
83         done
84 }
85
86 _chromium_strip_pak() {
87         local x
88         for x in "$@"; do
89                 echo "${x%.pak}"
90         done
91 }
92
93 # @FUNCTION: chromium_remove_language_paks
94 # @USAGE:
95 # @DESCRIPTION:
96 # Removes pak files from the current directory for languages that the user has
97 # not selected via the LINGUAS variable.
98 # Also performs QA checks to ensure CHROMIUM_LANGS has been set correctly.
99 chromium_remove_language_paks() {
100         local crlangs=$(_chromium_crlang ${CHROMIUM_LANGS})
101         local present_crlangs=$(_chromium_strip_pak *.pak)
102         local present_langs=$(_chromium_syslang ${present_crlangs})
103         local lang
104
105         # Look for missing pak files.
106         for lang in ${crlangs}; do
107                 if ! has ${lang} ${present_crlangs}; then
108                         eqawarn "LINGUAS warning: no .pak file for ${lang} (${lang}.pak not found)"
109                 fi
110         done
111
112         # Look for extra pak files.
113         # Remove pak files that the user does not want.
114         for lang in ${present_langs}; do
115                 if [[ ${lang} == en_US ]]; then
116                         continue
117                 fi
118                 if ! has ${lang} ${CHROMIUM_LANGS}; then
119                         eqawarn "LINGUAS warning: no ${lang} in LANGS"
120                         continue
121                 fi
122                 if ! use linguas_${lang}; then
123                         rm "$(_chromium_crlang ${lang}).pak" || die
124                 fi
125         done
126 }
127
128 chromium_pkg_preinst() {
129         gnome2_icon_savelist
130 }
131
132 chromium_pkg_postinst() {
133         fdo-mime_desktop_database_update
134         gnome2_icon_cache_update
135
136         # For more info see bug #292201, bug #352263, bug #361859.
137         if ! has_version x11-themes/gnome-icon-theme &&
138                 ! has_version x11-themes/oxygen-icons ; then
139                 elog
140                 elog "Depending on your desktop environment, you may need"
141                 elog "to install additional packages to get icons on the Downloads page."
142                 elog
143                 elog "For KDE, the required package is kde-apps/oxygen-icons."
144                 elog
145                 elog "For other desktop environments, try one of the following:"
146                 elog " - x11-themes/gnome-icon-theme"
147                 elog " - x11-themes/tango-icon-theme"
148         fi
149
150         # For more info see bug #359153.
151         elog
152         elog "Some web pages may require additional fonts to display properly."
153         elog "Try installing some of the following packages if some characters"
154         elog "are not displayed properly:"
155         elog " - media-fonts/arphicfonts"
156         elog " - media-fonts/bitstream-cyberbit"
157         elog " - media-fonts/droid"
158         elog " - media-fonts/ipamonafont"
159         elog " - media-fonts/ja-ipafonts"
160         elog " - media-fonts/takao-fonts"
161         elog " - media-fonts/wqy-microhei"
162         elog " - media-fonts/wqy-zenhei"
163 }
164
165 chromium_pkg_postrm() {
166         gnome2_icon_cache_update
167 }
168
169 chromium_pkg_die() {
170         if [[ "${EBUILD_PHASE}" != "compile" ]]; then
171                 return
172         fi
173
174         # Prevent user problems like bug #348235.
175         eshopts_push -s extglob
176         if is-flagq '-g?(gdb)?([1-9])'; then
177                 ewarn
178                 ewarn "You have enabled debug info (i.e. -g or -ggdb in your CFLAGS/CXXFLAGS)."
179                 ewarn "This produces very large build files causes the linker to consume large"
180                 ewarn "amounts of memory."
181                 ewarn
182                 ewarn "Please try removing -g{,gdb} before reporting a bug."
183                 ewarn
184         fi
185         eshopts_pop
186
187         # ccache often causes bogus compile failures, especially when the cache gets
188         # corrupted.
189         if has ccache ${FEATURES}; then
190                 ewarn
191                 ewarn "You have enabled ccache. Please try disabling ccache"
192                 ewarn "before reporting a bug."
193                 ewarn
194         fi
195
196         # No ricer bugs.
197         if use_if_iuse custom-cflags; then
198                 ewarn
199                 ewarn "You have enabled the custom-cflags USE flag."
200                 ewarn "Please disable it before reporting a bug."
201                 ewarn
202         fi
203
204         # If the system doesn't have enough memory, the compilation is known to
205         # fail. Print info about memory to recognize this condition.
206         einfo
207         einfo "$(grep MemTotal /proc/meminfo)"
208         einfo "$(grep SwapTotal /proc/meminfo)"
209         einfo
210 }
211
212 # @VARIABLE: EGYP_CHROMIUM_COMMAND
213 # @DESCRIPTION:
214 # Path to the gyp_chromium script.
215 : ${EGYP_CHROMIUM_COMMAND:=build/gyp_chromium}
216
217 # @VARIABLE: EGYP_CHROMIUM_DEPTH
218 # @DESCRIPTION:
219 # Depth for egyp_chromium.
220 : ${EGYP_CHROMIUM_DEPTH:=.}
221
222 # @FUNCTION: egyp_chromium
223 # @USAGE: [gyp arguments]
224 # @DESCRIPTION:
225 # Calls EGYP_CHROMIUM_COMMAND with depth EGYP_CHROMIUM_DEPTH and given
226 # arguments. The full command line is echoed for logging.
227 egyp_chromium() {
228         set -- "${EGYP_CHROMIUM_COMMAND}" --depth="${EGYP_CHROMIUM_DEPTH}" "$@"
229         echo "$@"
230         "$@"
231 }
232
233 # @FUNCTION: gyp_use
234 # @USAGE: <USE flag> [GYP flag] [true suffix] [false suffix]
235 # @DESCRIPTION:
236 # If USE flag is set, echo -D[GYP flag]=[true suffix].
237 #
238 # If USE flag is not set, echo -D[GYP flag]=[false suffix].
239 #
240 # [GYP flag] defaults to use_[USE flag] with hyphens converted to underscores.
241 #
242 # [true suffix] defaults to 1. [false suffix] defaults to 0.
243 gyp_use() {
244         local gypflag="-D${2:-use_${1//-/_}}="
245         usex "$1" "${gypflag}" "${gypflag}"  "${3-1}" "${4-0}"
246 }
247
248 # @FUNCTION: chromium_bundled_v8_version
249 # @USAGE: [path to version.cc]
250 # @DESCRIPTION:
251 # Outputs the version of v8 parsed from a (bundled) copy of the source code.
252 chromium_bundled_v8_version() {
253         local vf=${1:-v8/src/version.cc}
254         local major minor build patch
255         major=$(sed -ne 's/#define MAJOR_VERSION *\([0-9]*\)/\1/p' "${vf}")
256         minor=$(sed -ne 's/#define MINOR_VERSION *\([0-9]*\)/\1/p' "${vf}")
257         build=$(sed -ne 's/#define BUILD_NUMBER *\([0-9]*\)/\1/p' "${vf}")
258         patch=$(sed -ne 's/#define PATCH_LEVEL *\([0-9]*\)/\1/p' "${vf}")
259         echo "${major}.${minor}.${build}.${patch}"
260 }
261
262 # @FUNCTION: chromium_installed_v8_version
263 # @USAGE:
264 # @DESCRIPTION:
265 # Outputs the version of dev-lang/v8 currently installed on the host system.
266 chromium_installed_v8_version() {
267         local cpf=$(best_version dev-lang/v8)
268         local pvr=${cpf#dev-lang/v8-}
269         echo "${pvr%-r*}"
270 }