chromium-2.eclass: drop phase functions
[gentoo.git] / eclass / chromium-2.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-2.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 linux-info
13
14 if [[ ${PN} == chromium ]]; then
15         IUSE+=" custom-cflags"
16 fi
17
18 # @FUNCTION: chromium_suid_sandbox_check_kernel_config
19 # @USAGE:
20 # @DESCRIPTION:
21 # Ensures the system kernel supports features needed for SUID sandbox to work.
22 chromium_suid_sandbox_check_kernel_config() {
23         has "${EAPI:-0}" 0 1 2 3 && die "EAPI=${EAPI} is not supported"
24
25         if [[ "${MERGE_TYPE}" == "source" || "${MERGE_TYPE}" == "binary" ]]; then
26                 # Warn if the kernel does not support features needed for sandboxing.
27                 # Bug #363987.
28                 ERROR_PID_NS="PID_NS is required for sandbox to work"
29                 ERROR_NET_NS="NET_NS is required for sandbox to work"
30                 ERROR_USER_NS="USER_NS is required for sandbox to work"
31                 ERROR_SECCOMP_FILTER="SECCOMP_FILTER is required for sandbox to work"
32                 # Warn if the kernel does not support features needed for the browser to work
33                 # (bug #552576, bug #556286).
34                 ERROR_ADVISE_SYSCALLS="CONFIG_ADVISE_SYSCALLS is required for the renderer (bug #552576)"
35                 ERROR_COMPAT_VDSO="CONFIG_COMPAT_VDSO causes segfaults (bug #556286)"
36                 CONFIG_CHECK="~PID_NS ~NET_NS ~SECCOMP_FILTER ~USER_NS ~ADVISE_SYSCALLS ~!COMPAT_VDSO"
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_linguas_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 LINGUAS.
54                 IUSE+=" +linguas_${lang}"
55         done
56 }
57
58 if [[ ${CHROMIUM_LANGS} ]]; then
59         _chromium_set_linguas_IUSE
60 fi
61
62 _chromium_crlang() {
63         echo "${@/_/-}"
64 }
65
66 _chromium_syslang() {
67         echo "${@/-/_}"
68 }
69
70 _chromium_strip_pak() {
71         local x
72         for x in "$@"; do
73                 echo "${x%.pak}"
74         done
75 }
76
77 # @FUNCTION: chromium_remove_language_paks
78 # @USAGE:
79 # @DESCRIPTION:
80 # Removes pak files from the current directory for languages that the user has
81 # not selected via the LINGUAS variable.
82 # Also performs QA checks to ensure CHROMIUM_LANGS has been set correctly.
83 chromium_remove_language_paks() {
84         local crlangs=$(_chromium_crlang ${CHROMIUM_LANGS})
85         local present_crlangs=$(_chromium_strip_pak *.pak)
86         local present_langs=$(_chromium_syslang ${present_crlangs})
87         local lang
88
89         # Look for missing pak files.
90         for lang in ${crlangs}; do
91                 if ! has ${lang} ${present_crlangs}; then
92                         eqawarn "LINGUAS warning: no .pak file for ${lang} (${lang}.pak not found)"
93                 fi
94         done
95
96         # Look for extra pak files.
97         # Remove pak files that the user does not want.
98         for lang in ${present_langs}; do
99                 if [[ ${lang} == en_US ]]; then
100                         continue
101                 fi
102                 if ! has ${lang} ${CHROMIUM_LANGS}; then
103                         eqawarn "LINGUAS warning: no ${lang} in LANGS"
104                         continue
105                 fi
106                 if ! use linguas_${lang}; then
107                         rm "$(_chromium_crlang ${lang}).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 }