www-client/chromium: security cleanup
[gentoo.git] / www-client / chromium / chromium-81.0.4044.43.ebuild
1 # Copyright 2009-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5 PYTHON_COMPAT=( python2_7 )
6
7 CHROMIUM_LANGS="am ar bg bn ca cs da de el en-GB es es-419 et fa fi fil fr gu he
8         hi hr hu id it ja kn ko lt lv ml mr ms nb nl pl pt-BR pt-PT ro ru sk sl sr
9         sv sw ta te th tr uk vi zh-CN zh-TW"
10
11 inherit check-reqs chromium-2 desktop flag-o-matic multilib ninja-utils pax-utils portability python-any-r1 readme.gentoo-r1 toolchain-funcs xdg-utils
12
13 DESCRIPTION="Open-source version of Google Chrome web browser"
14 HOMEPAGE="http://chromium.org/"
15 SRC_URI="https://commondatastorage.googleapis.com/chromium-browser-official/${P}.tar.xz"
16
17 LICENSE="BSD"
18 SLOT="0"
19 KEYWORDS="~amd64 ~arm64 ~x86"
20 IUSE="+closure-compile component-build cups cpu_flags_arm_neon gnome-keyring +hangouts kerberos pic +proprietary-codecs pulseaudio selinux +suid +system-ffmpeg +system-icu +system-libvpx +tcmalloc widevine"
21 RESTRICT="!system-ffmpeg? ( proprietary-codecs? ( bindist ) )"
22 REQUIRED_USE="component-build? ( !suid )"
23
24 COMMON_DEPEND="
25         >=app-accessibility/at-spi2-atk-2.26:2
26         app-arch/bzip2:=
27         cups? ( >=net-print/cups-1.3.11:= )
28         >=dev-libs/atk-2.26
29         dev-libs/expat:=
30         dev-libs/glib:2
31         system-icu? ( >=dev-libs/icu-65:= )
32         >=dev-libs/libxml2-2.9.4-r3:=[icu]
33         dev-libs/libxslt:=
34         dev-libs/nspr:=
35         >=dev-libs/nss-3.26:=
36         >=dev-libs/re2-0.2019.08.01:=
37         gnome-keyring? ( >=gnome-base/libgnome-keyring-3.12:= )
38         >=media-libs/alsa-lib-1.0.19:=
39         media-libs/fontconfig:=
40         media-libs/freetype:=
41         >=media-libs/harfbuzz-2.4.0:0=[icu(-)]
42         media-libs/libjpeg-turbo:=
43         media-libs/libpng:=
44         system-libvpx? ( media-libs/libvpx:=[postproc,svc] )
45         >=media-libs/openh264-1.6.0:=
46         pulseaudio? ( media-sound/pulseaudio:= )
47         system-ffmpeg? (
48                 >=media-video/ffmpeg-4:=
49                 || (
50                         media-video/ffmpeg[-samba]
51                         >=net-fs/samba-4.5.10-r1[-debug(-)]
52                 )
53                 >=media-libs/opus-1.3.1:=
54         )
55         sys-apps/dbus:=
56         sys-apps/pciutils:=
57         virtual/udev
58         x11-libs/cairo:=
59         x11-libs/gdk-pixbuf:2
60         x11-libs/gtk+:3[X]
61         x11-libs/libX11:=
62         x11-libs/libXcomposite:=
63         x11-libs/libXcursor:=
64         x11-libs/libXdamage:=
65         x11-libs/libXext:=
66         x11-libs/libXfixes:=
67         >=x11-libs/libXi-1.6.0:=
68         x11-libs/libXrandr:=
69         x11-libs/libXrender:=
70         x11-libs/libXScrnSaver:=
71         x11-libs/libXtst:=
72         x11-libs/pango:=
73         app-arch/snappy:=
74         media-libs/flac:=
75         >=media-libs/libwebp-0.4.0:=
76         sys-libs/zlib:=[minizip]
77         kerberos? ( virtual/krb5 )
78 "
79 # For nvidia-drivers blocker, see bug #413637 .
80 RDEPEND="${COMMON_DEPEND}
81         x11-misc/xdg-utils
82         virtual/opengl
83         virtual/ttf-fonts
84         selinux? ( sec-policy/selinux-chromium )
85         tcmalloc? ( !<x11-drivers/nvidia-drivers-331.20 )
86 "
87 DEPEND="${COMMON_DEPEND}
88 "
89 # dev-vcs/git - https://bugs.gentoo.org/593476
90 BDEPEND="
91         ${PYTHON_DEPS}
92         >=app-arch/gzip-1.7
93         !arm? (
94                 dev-lang/yasm
95         )
96         dev-lang/perl
97         dev-util/gn
98         dev-vcs/git
99         >=dev-util/gperf-3.0.3
100         >=dev-util/ninja-1.7.2
101         >=net-libs/nodejs-7.6.0[inspector]
102         sys-apps/hwids[usb(+)]
103         >=sys-devel/bison-2.4.3
104         sys-devel/flex
105         closure-compile? ( virtual/jre )
106         virtual/pkgconfig
107 "
108
109 : ${CHROMIUM_FORCE_CLANG=no}
110
111 if [[ ${CHROMIUM_FORCE_CLANG} == yes ]]; then
112         BDEPEND+=" >=sys-devel/clang-7"
113 fi
114
115 if ! has chromium_pkg_die ${EBUILD_DEATH_HOOKS}; then
116         EBUILD_DEATH_HOOKS+=" chromium_pkg_die";
117 fi
118
119 DISABLE_AUTOFORMATTING="yes"
120 DOC_CONTENTS="
121 Some web pages may require additional fonts to display properly.
122 Try installing some of the following packages if some characters
123 are not displayed properly:
124 - media-fonts/arphicfonts
125 - media-fonts/droid
126 - media-fonts/ipamonafont
127 - media-fonts/noto
128 - media-fonts/ja-ipafonts
129 - media-fonts/takao-fonts
130 - media-fonts/wqy-microhei
131 - media-fonts/wqy-zenhei
132
133 To fix broken icons on the Downloads page, you should install an icon
134 theme that covers the appropriate MIME types, and configure this as your
135 GTK+ icon theme.
136
137 For native file dialogs in KDE, install kde-apps/kdialog.
138 "
139
140 PATCHES=(
141         "${FILESDIR}/chromium-compiler-r11.patch"
142         "${FILESDIR}/chromium-fix-char_traits.patch"
143         "${FILESDIR}/chromium-78-protobuf-export.patch"
144         "${FILESDIR}/chromium-79-gcc-alignas.patch"
145         "${FILESDIR}/chromium-80-gcc-quiche.patch"
146         "${FILESDIR}/chromium-80-gcc-blink.patch"
147         "${FILESDIR}/chromium-81-gcc-noexcept.patch"
148         "${FILESDIR}/chromium-81-gcc-constexpr.patch"
149 )
150
151 pre_build_checks() {
152         if [[ ${MERGE_TYPE} != binary ]]; then
153                 local -x CPP="$(tc-getCXX) -E"
154                 if tc-is-gcc && ! ver_test "$(gcc-version)" -ge 8.0; then
155                         die "At least gcc 8.0 is required"
156                 fi
157                 # component build hangs with tcmalloc enabled due to sandbox issue, bug #695976.
158                 if has usersandbox ${FEATURES} && use tcmalloc && use component-build; then
159                         die "Component build with tcmalloc requires FEATURES=-usersandbox."
160                 fi
161                 if [[ ${CHROMIUM_FORCE_CLANG} == yes ]] || tc-is-clang; then
162                         if use component-build; then
163                                 die "Component build with clang requires fuzzer headers."
164                         fi
165                 fi
166         fi
167
168         # Check build requirements, bug #541816 and bug #471810 .
169         CHECKREQS_MEMORY="3G"
170         CHECKREQS_DISK_BUILD="7G"
171         if ( shopt -s extglob; is-flagq '-g?(gdb)?([1-9])' ); then
172                 CHECKREQS_DISK_BUILD="25G"
173                 if ! use component-build; then
174                         CHECKREQS_MEMORY="16G"
175                 fi
176         fi
177         check-reqs_pkg_setup
178 }
179
180 pkg_pretend() {
181         pre_build_checks
182 }
183
184 pkg_setup() {
185         pre_build_checks
186
187         chromium_suid_sandbox_check_kernel_config
188 }
189
190 src_prepare() {
191         # Calling this here supports resumption via FEATURES=keepwork
192         python_setup
193
194         default
195
196         mkdir -p third_party/node/linux/node-linux-x64/bin || die
197         ln -s "${EPREFIX}"/usr/bin/node third_party/node/linux/node-linux-x64/bin/node || die
198
199         local keeplibs=(
200                 base/third_party/cityhash
201                 base/third_party/double_conversion
202                 base/third_party/dynamic_annotations
203                 base/third_party/icu
204                 base/third_party/nspr
205                 base/third_party/superfasthash
206                 base/third_party/symbolize
207                 base/third_party/valgrind
208                 base/third_party/xdg_mime
209                 base/third_party/xdg_user_dirs
210                 buildtools/third_party/libc++
211                 buildtools/third_party/libc++abi
212                 chrome/third_party/mozilla_security_manager
213                 courgette/third_party
214                 net/third_party/mozilla_security_manager
215                 net/third_party/nss
216                 net/third_party/quic
217                 net/third_party/uri_template
218                 third_party/abseil-cpp
219                 third_party/angle
220                 third_party/angle/src/common/third_party/base
221                 third_party/angle/src/common/third_party/smhasher
222                 third_party/angle/src/common/third_party/xxhash
223                 third_party/angle/src/third_party/compiler
224                 third_party/angle/src/third_party/libXNVCtrl
225                 third_party/angle/src/third_party/trace_event
226                 third_party/angle/src/third_party/volk
227                 third_party/angle/third_party/glslang
228                 third_party/angle/third_party/spirv-headers
229                 third_party/angle/third_party/spirv-tools
230                 third_party/angle/third_party/vulkan-headers
231                 third_party/angle/third_party/vulkan-loader
232                 third_party/angle/third_party/vulkan-tools
233                 third_party/angle/third_party/vulkan-validation-layers
234                 third_party/apple_apsl
235                 third_party/axe-core
236                 third_party/blink
237                 third_party/boringssl
238                 third_party/boringssl/src/third_party/fiat
239                 third_party/breakpad
240                 third_party/breakpad/breakpad/src/third_party/curl
241                 third_party/brotli
242                 third_party/cacheinvalidation
243                 third_party/catapult
244                 third_party/catapult/common/py_vulcanize/third_party/rcssmin
245                 third_party/catapult/common/py_vulcanize/third_party/rjsmin
246                 third_party/catapult/third_party/beautifulsoup4
247                 third_party/catapult/third_party/html5lib-python
248                 third_party/catapult/third_party/polymer
249                 third_party/catapult/third_party/six
250                 third_party/catapult/tracing/third_party/d3
251                 third_party/catapult/tracing/third_party/gl-matrix
252                 third_party/catapult/tracing/third_party/jpeg-js
253                 third_party/catapult/tracing/third_party/jszip
254                 third_party/catapult/tracing/third_party/mannwhitneyu
255                 third_party/catapult/tracing/third_party/oboe
256                 third_party/catapult/tracing/third_party/pako
257                 third_party/ced
258                 third_party/cld_3
259                 third_party/closure_compiler
260                 third_party/crashpad
261                 third_party/crashpad/crashpad/third_party/lss
262                 third_party/crashpad/crashpad/third_party/zlib
263                 third_party/crc32c
264                 third_party/cros_system_api
265                 third_party/dav1d
266                 third_party/dawn
267                 third_party/depot_tools
268                 third_party/devscripts
269                 third_party/devtools-frontend
270                 third_party/devtools-frontend/src/front_end/third_party/fabricjs
271                 third_party/devtools-frontend/src/front_end/third_party/wasmparser
272                 third_party/devtools-frontend/src/third_party
273                 third_party/dom_distiller_js
274                 third_party/emoji-segmenter
275                 third_party/flatbuffers
276                 third_party/freetype
277                 third_party/libgifcodec
278                 third_party/glslang
279                 third_party/google_input_tools
280                 third_party/google_input_tools/third_party/closure_library
281                 third_party/google_input_tools/third_party/closure_library/third_party/closure
282                 third_party/googletest
283                 third_party/hunspell
284                 third_party/iccjpeg
285                 third_party/inspector_protocol
286                 third_party/jinja2
287                 third_party/jsoncpp
288                 third_party/jstemplate
289                 third_party/khronos
290                 third_party/leveldatabase
291                 third_party/libXNVCtrl
292                 third_party/libaddressinput
293                 third_party/libaom
294                 third_party/libaom/source/libaom/third_party/vector
295                 third_party/libaom/source/libaom/third_party/x86inc
296                 third_party/libjingle
297                 third_party/libphonenumber
298                 third_party/libsecret
299                 third_party/libsrtp
300                 third_party/libsync
301                 third_party/libudev
302                 third_party/libwebm
303                 third_party/libxml/chromium
304                 third_party/libyuv
305                 third_party/llvm
306                 third_party/lss
307                 third_party/lzma_sdk
308                 third_party/markupsafe
309                 third_party/mesa
310                 third_party/metrics_proto
311                 third_party/modp_b64
312                 third_party/nasm
313                 third_party/node
314                 third_party/node/node_modules/polymer-bundler/lib/third_party/UglifyJS2
315                 third_party/one_euro_filter
316                 third_party/openscreen
317                 third_party/openscreen/src/third_party/tinycbor/src/src
318                 third_party/ots
319                 third_party/pdfium
320                 third_party/pdfium/third_party/agg23
321                 third_party/pdfium/third_party/base
322                 third_party/pdfium/third_party/bigint
323                 third_party/pdfium/third_party/freetype
324                 third_party/pdfium/third_party/lcms
325                 third_party/pdfium/third_party/libopenjpeg20
326                 third_party/pdfium/third_party/libpng16
327                 third_party/pdfium/third_party/libtiff
328                 third_party/pdfium/third_party/skia_shared
329                 third_party/perfetto
330                 third_party/pffft
331                 third_party/ply
332                 third_party/polymer
333                 third_party/private-join-and-compute
334                 third_party/protobuf
335                 third_party/protobuf/third_party/six
336                 third_party/pyjson5
337                 third_party/qcms
338                 third_party/rnnoise
339                 third_party/s2cellid
340                 third_party/simplejson
341                 third_party/skia
342                 third_party/skia/include/third_party/skcms
343                 third_party/skia/include/third_party/vulkan
344                 third_party/skia/third_party/skcms
345                 third_party/skia/third_party/vulkan
346                 third_party/smhasher
347                 third_party/spirv-headers
348                 third_party/SPIRV-Tools
349                 third_party/sqlite
350                 third_party/swiftshader
351                 third_party/swiftshader/third_party/llvm-7.0
352                 third_party/swiftshader/third_party/llvm-subzero
353                 third_party/swiftshader/third_party/marl
354                 third_party/swiftshader/third_party/subzero
355                 third_party/swiftshader/third_party/SPIRV-Headers/include/spirv/unified1
356                 third_party/unrar
357                 third_party/usrsctp
358                 third_party/vulkan
359                 third_party/web-animations-js
360                 third_party/webdriver
361                 third_party/webrtc
362                 third_party/webrtc/common_audio/third_party/fft4g
363                 third_party/webrtc/common_audio/third_party/spl_sqrt_floor
364                 third_party/webrtc/modules/third_party/fft
365                 third_party/webrtc/modules/third_party/g711
366                 third_party/webrtc/modules/third_party/g722
367                 third_party/webrtc/rtc_base/third_party/base64
368                 third_party/webrtc/rtc_base/third_party/sigslot
369                 third_party/widevine
370                 third_party/woff2
371                 third_party/wuffs
372                 third_party/zlib/google
373                 tools/grit/third_party/six
374                 url/third_party/mozilla
375                 v8/src/third_party/siphash
376                 v8/src/third_party/valgrind
377                 v8/src/third_party/utf8-decoder
378                 v8/third_party/inspector_protocol
379                 v8/third_party/v8
380
381                 # gyp -> gn leftovers
382                 base/third_party/libevent
383                 third_party/adobe
384                 third_party/speech-dispatcher
385                 third_party/usb_ids
386                 third_party/xdg-utils
387                 third_party/yasm/run_yasm.py
388         )
389         if ! use system-ffmpeg; then
390                 keeplibs+=( third_party/ffmpeg third_party/opus )
391         fi
392         if ! use system-icu; then
393                 keeplibs+=( third_party/icu )
394         fi
395         if ! use system-libvpx; then
396                 keeplibs+=( third_party/libvpx )
397                 keeplibs+=( third_party/libvpx/source/libvpx/third_party/x86inc )
398         fi
399         if use tcmalloc; then
400                 keeplibs+=( third_party/tcmalloc )
401         fi
402
403         # Remove most bundled libraries. Some are still needed.
404         build/linux/unbundle/remove_bundled_libraries.py "${keeplibs[@]}" --do-remove || die
405 }
406
407 src_configure() {
408         # Calling this here supports resumption via FEATURES=keepwork
409         python_setup
410
411         local myconf_gn=""
412
413         # Make sure the build system will use the right tools, bug #340795.
414         tc-export AR CC CXX NM
415
416         if [[ ${CHROMIUM_FORCE_CLANG} == yes ]] && ! tc-is-clang; then
417                 # Force clang since gcc is pretty broken at the moment.
418                 CC=${CHOST}-clang
419                 CXX=${CHOST}-clang++
420                 strip-unsupported-flags
421         fi
422
423         if tc-is-clang; then
424                 myconf_gn+=" is_clang=true clang_use_chrome_plugins=false"
425         else
426                 myconf_gn+=" is_clang=false"
427         fi
428
429         # Define a custom toolchain for GN
430         myconf_gn+=" custom_toolchain=\"//build/toolchain/linux/unbundle:default\""
431
432         if tc-is-cross-compiler; then
433                 tc-export BUILD_{AR,CC,CXX,NM}
434                 myconf_gn+=" host_toolchain=\"//build/toolchain/linux/unbundle:host\""
435                 myconf_gn+=" v8_snapshot_toolchain=\"//build/toolchain/linux/unbundle:host\""
436         else
437                 myconf_gn+=" host_toolchain=\"//build/toolchain/linux/unbundle:default\""
438         fi
439
440         # GN needs explicit config for Debug/Release as opposed to inferring it from build directory.
441         myconf_gn+=" is_debug=false"
442
443         # Component build isn't generally intended for use by end users. It's mostly useful
444         # for development and debugging.
445         myconf_gn+=" is_component_build=$(usex component-build true false)"
446
447         myconf_gn+=" use_allocator=$(usex tcmalloc \"tcmalloc\" \"none\")"
448
449         # Disable nacl, we can't build without pnacl (http://crbug.com/269560).
450         myconf_gn+=" enable_nacl=false"
451
452         # Use system-provided libraries.
453         # TODO: freetype -- remove sources (https://bugs.chromium.org/p/pdfium/issues/detail?id=733).
454         # TODO: use_system_hunspell (upstream changes needed).
455         # TODO: use_system_libsrtp (bug #459932).
456         # TODO: use_system_protobuf (bug #525560).
457         # TODO: use_system_ssl (http://crbug.com/58087).
458         # TODO: use_system_sqlite (http://crbug.com/22208).
459
460         # libevent: https://bugs.gentoo.org/593458
461         local gn_system_libraries=(
462                 flac
463                 fontconfig
464                 freetype
465                 # Need harfbuzz_from_pkgconfig target
466                 #harfbuzz-ng
467                 libdrm
468                 libjpeg
469                 libpng
470                 libwebp
471                 libxml
472                 libxslt
473                 openh264
474                 re2
475                 snappy
476                 yasm
477                 zlib
478         )
479         if use system-ffmpeg; then
480                 gn_system_libraries+=( ffmpeg opus )
481         fi
482         if use system-icu; then
483                 gn_system_libraries+=( icu )
484         fi
485         if use system-libvpx; then
486                 gn_system_libraries+=( libvpx )
487         fi
488         build/linux/unbundle/replace_gn_files.py --system-libraries "${gn_system_libraries[@]}" || die
489
490         # See dependency logic in third_party/BUILD.gn
491         myconf_gn+=" use_system_harfbuzz=true"
492
493         # Optional dependencies.
494         myconf_gn+=" closure_compile=$(usex closure-compile true false)"
495         myconf_gn+=" enable_hangout_services_extension=$(usex hangouts true false)"
496         myconf_gn+=" enable_widevine=$(usex widevine true false)"
497         myconf_gn+=" use_cups=$(usex cups true false)"
498         myconf_gn+=" use_gnome_keyring=$(usex gnome-keyring true false)"
499         myconf_gn+=" use_kerberos=$(usex kerberos true false)"
500         myconf_gn+=" use_pulseaudio=$(usex pulseaudio true false)"
501
502         # TODO: link_pulseaudio=true for GN.
503
504         myconf_gn+=" fieldtrial_testing_like_official_build=true"
505
506         # Never use bundled gold binary. Disable gold linker flags for now.
507         # Do not use bundled clang.
508         # Trying to use gold results in linker crash.
509         myconf_gn+=" use_gold=false use_sysroot=false linux_use_bundled_binutils=false use_custom_libcxx=false"
510
511         # Disable forced lld, bug 641556
512         myconf_gn+=" use_lld=false"
513
514         ffmpeg_branding="$(usex proprietary-codecs Chrome Chromium)"
515         myconf_gn+=" proprietary_codecs=$(usex proprietary-codecs true false)"
516         myconf_gn+=" ffmpeg_branding=\"${ffmpeg_branding}\""
517
518         # Set up Google API keys, see http://www.chromium.org/developers/how-tos/api-keys .
519         # Note: these are for Gentoo use ONLY. For your own distribution,
520         # please get your own set of keys. Feel free to contact chromium@gentoo.org
521         # for more info.
522         local google_api_key="AIzaSyDEAOvatFo0eTgsV_ZlEzx0ObmepsMzfAc"
523         local google_default_client_id="329227923882.apps.googleusercontent.com"
524         local google_default_client_secret="vgKG0NNv7GoDpbtoFNLxCUXu"
525         myconf_gn+=" google_api_key=\"${google_api_key}\""
526         myconf_gn+=" google_default_client_id=\"${google_default_client_id}\""
527         myconf_gn+=" google_default_client_secret=\"${google_default_client_secret}\""
528         local myarch="$(tc-arch)"
529
530         # Avoid CFLAGS problems, bug #352457, bug #390147.
531         if ! use custom-cflags; then
532                 replace-flags "-Os" "-O2"
533                 strip-flags
534
535                 # Prevent linker from running out of address space, bug #471810 .
536                 if use x86; then
537                         filter-flags "-g*"
538                 fi
539
540                 # Prevent libvpx build failures. Bug 530248, 544702, 546984.
541                 if [[ ${myarch} == amd64 || ${myarch} == x86 ]]; then
542                         filter-flags -mno-mmx -mno-sse2 -mno-ssse3 -mno-sse4.1 -mno-avx -mno-avx2
543                 fi
544         fi
545
546         if [[ $myarch = amd64 ]] ; then
547                 myconf_gn+=" target_cpu=\"x64\""
548                 ffmpeg_target_arch=x64
549         elif [[ $myarch = x86 ]] ; then
550                 myconf_gn+=" target_cpu=\"x86\""
551                 ffmpeg_target_arch=ia32
552
553                 # This is normally defined by compiler_cpu_abi in
554                 # build/config/compiler/BUILD.gn, but we patch that part out.
555                 append-flags -msse2 -mfpmath=sse -mmmx
556         elif [[ $myarch = arm64 ]] ; then
557                 myconf_gn+=" target_cpu=\"arm64\""
558                 ffmpeg_target_arch=arm64
559         elif [[ $myarch = arm ]] ; then
560                 myconf_gn+=" target_cpu=\"arm\""
561                 ffmpeg_target_arch=$(usex cpu_flags_arm_neon arm-neon arm)
562         else
563                 die "Failed to determine target arch, got '$myarch'."
564         fi
565
566         # Make sure that -Werror doesn't get added to CFLAGS by the build system.
567         # Depending on GCC version the warnings are different and we don't want
568         # the build to fail because of that.
569         myconf_gn+=" treat_warnings_as_errors=false"
570
571         # Disable fatal linker warnings, bug 506268.
572         myconf_gn+=" fatal_linker_warnings=false"
573
574         # Bug 491582.
575         export TMPDIR="${WORKDIR}/temp"
576         mkdir -p -m 755 "${TMPDIR}" || die
577
578         # https://bugs.gentoo.org/654216
579         addpredict /dev/dri/ #nowarn
580
581         #if ! use system-ffmpeg; then
582         if false; then
583                 local build_ffmpeg_args=""
584                 if use pic && [[ "${ffmpeg_target_arch}" == "ia32" ]]; then
585                         build_ffmpeg_args+=" --disable-asm"
586                 fi
587
588                 # Re-configure bundled ffmpeg. See bug #491378 for example reasons.
589                 einfo "Configuring bundled ffmpeg..."
590                 pushd third_party/ffmpeg > /dev/null || die
591                 chromium/scripts/build_ffmpeg.py linux ${ffmpeg_target_arch} \
592                         --branding ${ffmpeg_branding} -- ${build_ffmpeg_args} || die
593                 chromium/scripts/copy_config.sh || die
594                 chromium/scripts/generate_gn.py || die
595                 popd > /dev/null || die
596         fi
597
598         # Chromium relies on this, but was disabled in >=clang-10, crbug.com/1042470
599         append-cxxflags $(test-flags-CXX -flax-vector-conversions=all)
600
601         # Explicitly disable ICU data file support for system-icu builds.
602         if use system-icu; then
603                 myconf_gn+=" icu_use_data_file=false"
604         fi
605
606         einfo "Configuring Chromium..."
607         set -- gn gen --args="${myconf_gn} ${EXTRA_GN}" out/Release
608         echo "$@"
609         "$@" || die
610 }
611
612 src_compile() {
613         # Final link uses lots of file descriptors.
614         ulimit -n 2048
615
616         # Calling this here supports resumption via FEATURES=keepwork
617         python_setup
618
619         #"${EPYTHON}" tools/clang/scripts/update.py --force-local-build --gcc-toolchain /usr --skip-checkout --use-system-cmake --without-android || die
620
621         # Build mksnapshot and pax-mark it.
622         local x
623         for x in mksnapshot v8_context_snapshot_generator; do
624                 if tc-is-cross-compiler; then
625                         eninja -C out/Release "host/${x}"
626                         pax-mark m "out/Release/host/${x}"
627                 else
628                         eninja -C out/Release "${x}"
629                         pax-mark m "out/Release/${x}"
630                 fi
631         done
632
633         # Even though ninja autodetects number of CPUs, we respect
634         # user's options, for debugging with -j 1 or any other reason.
635         eninja -C out/Release chrome chromedriver
636         use suid && eninja -C out/Release chrome_sandbox
637
638         pax-mark m out/Release/chrome
639
640         # Build manpage; bug #684550
641         sed -e 's|@@PACKAGE@@|chromium-browser|g;
642                 s|@@MENUNAME@@|Chromium|g;' \
643                 chrome/app/resources/manpage.1.in > \
644                 out/Release/chromium-browser.1 || die
645
646         # Build desktop file; bug #706786
647         sed -e 's|@@MENUNAME@@|Chromium|g;
648                 s|@@USR_BIN_SYMLINK_NAME@@|chromium-browser|g;
649                 s|@@PACKAGE@@|chromium-browser|g;
650                 s|\(^Exec=\)/usr/bin/|\1|g;' \
651                 chrome/installer/linux/common/desktop.template > \
652                 out/Release/chromium-browser-chromium.desktop || die
653 }
654
655 src_install() {
656         local CHROMIUM_HOME="/usr/$(get_libdir)/chromium-browser"
657         exeinto "${CHROMIUM_HOME}"
658         doexe out/Release/chrome
659
660         if use suid; then
661                 newexe out/Release/chrome_sandbox chrome-sandbox
662                 fperms 4755 "${CHROMIUM_HOME}/chrome-sandbox"
663         fi
664
665         doexe out/Release/chromedriver
666
667         local sedargs=( -e "s:/usr/lib/:/usr/$(get_libdir)/:g" )
668         sed "${sedargs[@]}" "${FILESDIR}/chromium-launcher-r3.sh" > chromium-launcher.sh || die
669         doexe chromium-launcher.sh
670
671         # It is important that we name the target "chromium-browser",
672         # xdg-utils expect it; bug #355517.
673         dosym "${CHROMIUM_HOME}/chromium-launcher.sh" /usr/bin/chromium-browser
674         # keep the old symlink around for consistency
675         dosym "${CHROMIUM_HOME}/chromium-launcher.sh" /usr/bin/chromium
676
677         dosym "${CHROMIUM_HOME}/chromedriver" /usr/bin/chromedriver
678
679         # Allow users to override command-line options, bug #357629.
680         insinto /etc/chromium
681         newins "${FILESDIR}/chromium.default" "default"
682
683         pushd out/Release/locales > /dev/null || die
684         chromium_remove_language_paks
685         popd
686
687         insinto "${CHROMIUM_HOME}"
688         doins out/Release/*.bin
689         doins out/Release/*.pak
690         doins out/Release/*.so
691
692         if ! use system-icu; then
693                 doins out/Release/icudtl.dat
694         fi
695
696         doins -r out/Release/locales
697         doins -r out/Release/resources
698
699         if [[ -d out/Release/swiftshader ]]; then
700                 insinto "${CHROMIUM_HOME}/swiftshader"
701                 doins out/Release/swiftshader/*.so
702         fi
703
704         # Install icons
705         local branding size
706         for size in 16 24 32 48 64 128 256 ; do
707                 case ${size} in
708                         16|32) branding="chrome/app/theme/default_100_percent/chromium" ;;
709                                 *) branding="chrome/app/theme/chromium" ;;
710                 esac
711                 newicon -s ${size} "${branding}/product_logo_${size}.png" \
712                         chromium-browser.png
713         done
714
715         # Install desktop entry
716         domenu out/Release/chromium-browser-chromium.desktop
717
718         # Install GNOME default application entry (bug #303100).
719         insinto /usr/share/gnome-control-center/default-apps
720         newins "${FILESDIR}"/chromium-browser.xml chromium-browser.xml
721
722         # Install manpage; bug #684550
723         doman out/Release/chromium-browser.1
724         dosym chromium-browser.1 /usr/share/man/man1/chromium.1
725
726         readme.gentoo_create_doc
727 }
728
729 pkg_postrm() {
730         xdg_icon_cache_update
731         xdg_desktop_database_update
732 }
733
734 pkg_postinst() {
735         xdg_icon_cache_update
736         xdg_desktop_database_update
737         readme.gentoo_print_elog
738 }