]> git.friedersdorff.com Git - max/gentoo-overlay.git/blob - dev-util/electron/electron-2.0.10.ebuild
b5e8cd34a41bd2261489822428a98e8bc6f19253
[max/gentoo-overlay.git] / dev-util / electron / electron-2.0.10.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI="6"
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 eapi7-ver gnome2-utils flag-o-matic multilib \
12         multiprocessing ninja-utils pax-utils portability python-any-r1 \
13         toolchain-funcs virtualx xdg-utils
14
15 # Keep this in sync with vendor/libchromiumcontent/VERSION
16 CHROMIUM_VERSION="61.0.3163.100"
17 # Keep this in sync with vendor/breakpad
18 BREAKPAD_COMMIT="82f0452e6b687b3c1e14e08d172b2f3fb79ae91a"
19 # Keep this in sync with vendor/breakpad/src (and find the corresponding
20 # commit in https://github.com/google/breakpad/)
21 BREAKPAD_SRC_COMMIT="67f738b7adb47dc1e3b272fb99062f4192fa6651"
22 # Keep this in sync with vendor/node
23 NODE_COMMIT="51abeb37cad3f2098c0f0fffdff739f4ac2393e8"
24 # Keep this in sync with vendor/native_mate
25 NATIVE_MATE_COMMIT="6a3d238b7e1e3742f2bb495336a84021d927a24f"
26 # Keep this in sync with vendor/pdf_viewer
27 PDF_VIEWER_COMMIT="a5251e497fb52e699b28f627e3cbb6d8cefb62df"
28 # Keep this in sync with vendor/pdf_viewer/vendor/grit
29 GRIT_COMMIT="9536fb6429147d27ef1563088341825db0a893cd"
30 # Keep this in sync with vendor/libchromiumcontent
31 LIBCHROMIUMCONTENT_COMMIT="cbd04c0dccc7655cd42f02baee3a622d5170ac08"
32 # Keep this in sync with package.json#devDependencies
33 ASAR_VERSION="0.13.0"
34 BROWSERIFY_VERSION="14.0.0"
35 NINJA_VERSION="1.8.2"
36 GENTOO_PATCHES_VERSION="f0fb7725cfe73704dce84ec51bdccc024dc7ceff"
37
38 PATCHES_P="gentoo-electron-patches-${GENTOO_PATCHES_VERSION}"
39 CHROMIUM_P="chromium-${CHROMIUM_VERSION}"
40 BREAKPAD_P="chromium-breakpad-${BREAKPAD_COMMIT}"
41 BREAKPAD_SRC_P="breakpad-${BREAKPAD_SRC_COMMIT}"
42 NODE_P="node-${NODE_COMMIT}"
43 NATIVE_MATE_P="native-mate-${NATIVE_MATE_COMMIT}"
44 PDF_VIEWER_P="pdf-viewer-${PDF_VIEWER_COMMIT}"
45 GRIT_P="grit-${GRIT_COMMIT}"
46 LIBCHROMIUMCONTENT_P="libchromiumcontent-${LIBCHROMIUMCONTENT_COMMIT}"
47 ASAR_P="asar-${ASAR_VERSION}"
48 BROWSERIFY_P="browserify-${BROWSERIFY_VERSION}"
49
50 DESCRIPTION="Cross platform application development framework based on web technologies"
51 HOMEPAGE="https://electronjs.org/"
52 SRC_URI="
53         https://commondatastorage.googleapis.com/chromium-browser-official/${CHROMIUM_P}.tar.xz
54         https://github.com/electron/electron/archive/v${PV}.tar.gz -> ${P}.tar.gz
55         https://github.com/electron/chromium-breakpad/archive/${BREAKPAD_COMMIT}.tar.gz -> electron-${BREAKPAD_P}.tar.gz
56         https://github.com/google/breakpad/archive/${BREAKPAD_SRC_COMMIT}.tar.gz -> electron-${BREAKPAD_SRC_P}.tar.gz
57         https://github.com/electron/node/archive/${NODE_COMMIT}.tar.gz -> electron-${NODE_P}.tar.gz
58         https://github.com/zcbenz/native-mate/archive/${NATIVE_MATE_COMMIT}.tar.gz -> electron-${NATIVE_MATE_P}.tar.gz
59         https://github.com/electron/pdf-viewer/archive/${PDF_VIEWER_COMMIT}.tar.gz -> electron-${PDF_VIEWER_P}.tar.gz
60         https://github.com/elprans/grit/archive/${GRIT_COMMIT}.tar.gz -> electron-${GRIT_P}.tar.gz
61         https://github.com/electron/libchromiumcontent/archive/${LIBCHROMIUMCONTENT_COMMIT}.tar.gz -> electron-${LIBCHROMIUMCONTENT_P}.tar.gz
62         https://github.com/elprans/asar/releases/download/v${ASAR_VERSION}-gentoo/asar-build.tar.gz -> ${ASAR_P}.tar.gz
63         https://github.com/elprans/node-browserify/releases/download/${BROWSERIFY_VERSION}-gentoo/browserify-build.tar.gz -> ${BROWSERIFY_P}.tar.gz
64         https://github.com/elprans/gentoo-electron-patches/archive/${GENTOO_PATCHES_VERSION}.tar.gz -> electron-patches-${GENTOO_PATCHES_VERSION}.tar.gz
65         https://github.com/ninja-build/ninja/archive/v${NINJA_VERSION}.tar.gz -> ninja-${NINJA_VERSION}.tar.gz
66 "
67
68 S="${WORKDIR}/${P}"
69 CHROMIUM_S="${S}/chromium"
70 NODE_S="${S}/vendor/node"
71 BREAKPAD_S="${S}/vendor/breakpad"
72 BREAKPAD_SRC_S="${BREAKPAD_S}/src"
73 NATIVE_MATE_S="${S}/vendor/native_mate"
74 PDF_VIEWER_S="${S}/vendor/pdf_viewer"
75 GRIT_S="${PDF_VIEWER_S}/vendor/grit"
76 LIBCC_S="${S}/vendor/libchromiumcontent"
77
78 LICENSE="BSD"
79 SLOT="$(ver_cut 1-2)"
80 KEYWORDS="~amd64"
81 IUSE="cups custom-cflags gconf gnome-keyring kerberos lto neon pic
82           +proprietary-codecs pulseaudio selinux +system-ffmpeg +tcmalloc"
83 RESTRICT="!system-ffmpeg? ( proprietary-codecs? ( bindist ) )"
84
85 # Native Client binaries are compiled with different set of flags, bug #452066.
86 QA_FLAGS_IGNORED=".*\.nexe"
87
88 # Native Client binaries may be stripped by the build system, which uses the
89 # right tools for it, bug #469144 .
90 QA_PRESTRIPPED=".*\.nexe"
91
92 COMMON_DEPEND="
93         app-arch/bzip2:=
94         >=app-eselect/eselect-electron-2.0
95         cups? ( >=net-print/cups-1.3.11:= )
96         dev-libs/expat:=
97         dev-libs/glib:2
98         >=dev-libs/icu-58:=
99         dev-libs/libxml2:=[icu]
100         dev-libs/libxslt:=
101         dev-libs/nspr:=
102         >=dev-libs/nss-3.14.3:=
103         >=dev-libs/re2-0.2016.05.01:=
104         gconf? ( >=gnome-base/gconf-2.24.0:= )
105         gnome-keyring? ( >=gnome-base/libgnome-keyring-3.12:= )
106         >=media-libs/alsa-lib-1.0.19:=
107         media-libs/fontconfig:=
108         media-libs/freetype:=
109         >=media-libs/harfbuzz-1.4.2:=[icu(+)]
110         media-libs/libexif:=
111         media-libs/libjpeg-turbo:=
112         media-libs/libpng:=
113         >=media-libs/libvpx-1.7.0:=[postproc,svc]
114         >=media-libs/openh264-1.6.0:=
115         pulseaudio? ( media-sound/pulseaudio:= )
116         system-ffmpeg? (
117                 >=media-video/ffmpeg-3:=
118                 || (
119                         media-video/ffmpeg[-samba]
120                         >=net-fs/samba-4.5.10-r1[-debug(-)]
121                 )
122                 !=net-fs/samba-4.5.12-r0
123                 media-libs/opus:=
124         )
125         >=net-dns/c-ares-1.13.0:=
126         >=net-libs/nghttp2-1.32.0:=
127         sys-apps/dbus:=
128         sys-apps/pciutils:=
129         virtual/udev
130         x11-libs/cairo:=
131         x11-libs/gdk-pixbuf:2
132         x11-libs/gtk+:3[X]
133         x11-libs/libdrm
134         x11-libs/libnotify:=
135         x11-libs/libX11:=
136         x11-libs/libXcomposite:=
137         x11-libs/libXcursor:=
138         x11-libs/libXdamage:=
139         x11-libs/libXext:=
140         x11-libs/libXfixes:=
141         >=x11-libs/libXi-1.6.0:=
142         x11-libs/libXrandr:=
143         x11-libs/libXrender:=
144         x11-libs/libXScrnSaver:=
145         x11-libs/libXtst:=
146         x11-libs/pango:=
147         app-arch/snappy:=
148         media-libs/flac:=
149         >=media-libs/libwebp-0.4.0:=
150         sys-libs/zlib:=[minizip]
151         kerberos? ( virtual/krb5 )
152 "
153 # For nvidia-drivers blocker, see bug #413637 .
154 RDEPEND="${COMMON_DEPEND}
155         !<dev-util/electron-0.36.12-r4
156         x11-misc/xdg-utils
157         virtual/opengl
158         virtual/ttf-fonts
159         selinux? ( sec-policy/selinux-chromium )
160         tcmalloc? ( !<x11-drivers/nvidia-drivers-331.20 )
161 "
162 # dev-vcs/git - https://bugs.gentoo.org/593476
163 DEPEND="${COMMON_DEPEND}
164         >=app-arch/gzip-1.7
165         !arm? (
166                 dev-lang/yasm
167         )
168         dev-lang/perl
169         dev-util/gn
170         >=dev-util/gperf-3.0.3
171         >=dev-util/ninja-1.7.2
172         >=net-libs/nodejs-4.6.1
173         sys-apps/hwids[usb(+)]
174         >=sys-devel/bison-2.4.3
175         sys-devel/flex
176         virtual/pkgconfig
177         dev-vcs/git
178         $(python_gen_any_dep '
179                 dev-python/beautifulsoup:python-2[${PYTHON_USEDEP}]
180                 >=dev-python/beautifulsoup-4.3.2:4[${PYTHON_USEDEP}]
181                 dev-python/html5lib[${PYTHON_USEDEP}]
182                 dev-python/simplejson[${PYTHON_USEDEP}]
183         ')
184 "
185
186 # Keep this in sync with the python_gen_any_dep call.
187 python_check_deps() {
188         has_version --host-root "dev-python/beautifulsoup:python-2[${PYTHON_USEDEP}]" &&
189         has_version --host-root ">=dev-python/beautifulsoup-4.3.2:4[${PYTHON_USEDEP}]" &&
190         has_version --host-root "dev-python/html5lib[${PYTHON_USEDEP}]" &&
191         has_version --host-root "dev-python/simplejson[${PYTHON_USEDEP}]"
192 }
193
194 if ! has chromium_pkg_die ${EBUILD_DEATH_HOOKS}; then
195         EBUILD_DEATH_HOOKS+=" chromium_pkg_die";
196 fi
197
198 pre_build_checks() {
199         if [[ ${MERGE_TYPE} != binary ]]; then
200                 local -x CPP="$(tc-getCXX) -E"
201                 if tc-is-clang && ! ver_test "$(clang-fullversion)" -ge 3.9.1; then
202                         # bugs: #601654
203                         die "At least clang 3.9.1 is required"
204                 fi
205                 if tc-is-gcc && ! ver_test "$(gcc-version)" -ge 4.9; then
206                         # bugs: #535730, #525374, #518668, #600288
207                         die "At least gcc 4.9 is required"
208                 fi
209         fi
210
211         # LTO pass requires more file descriptors
212         if use lto; then
213                 local lto_n_rlimit_min="16384"
214                 local maxfiles=$(ulimit -n -H)
215                 if [ "${maxfiles}" -lt "${lto_n_rlimit_min}" ]; then
216                         eerror ""
217                         eerror "Building with USE=\"lto\" requires file descriptor" \
218                                 "limit to be no less than ${lto_n_rlimit_min}."
219                         eerror "The current limit for portage is ${maxfiles}."
220                         eerror "Please add the following to /etc/security/limits.conf:"
221                         eerror ""
222                         eerror "   root hard    nofile  ${lto_n_rlimit_min}"
223                         eerror "   root soft    nofile  ${lto_n_rlimit_min}"
224                         eerror ""
225                         die
226                 fi
227         fi
228
229         # Check build requirements, bug #541816 and bug #471810 .
230         CHECKREQS_MEMORY="3G"
231         use lto && CHECKREQS_MEMORY="7G"
232         CHECKREQS_DISK_BUILD="5G"
233         eshopts_push -s extglob
234         if is-flagq '-g?(gdb)?([1-9])'; then
235                 CHECKREQS_DISK_BUILD="25G"
236                 CHECKREQS_MEMORY="16G"
237         fi
238         eshopts_pop
239         check-reqs_pkg_pretend
240 }
241
242 pkg_pretend() {
243         pre_build_checks
244 }
245
246 pkg_setup() {
247         pre_build_checks
248
249         # Make sure the build system will use the right python, bug #344367.
250         python-any-r1_pkg_setup
251
252         chromium_suid_sandbox_check_kernel_config
253 }
254
255 _unnest_patches() {
256         local _s="${1%/}/"
257         local path
258         local relpath
259         local out
260
261         (find "${_s}" -mindepth 2 -name '*.patch' -printf "%P\n" || die) \
262         | while read -r path; do
263                 relpath="$(dirname ${path})"
264                 out="${_s}/__${relpath////_}_$(basename ${path})"
265                 sed -r -e "s|^([-+]{3}) ([ab])/(.*)$|\1 \2/${relpath}/\3|g" \
266                         "${_s}/${path}" > "${out}" || die
267         done
268 }
269
270 _get_install_suffix() {
271         local c=(${SLOT//\// })
272         local slot=${c[0]}
273         local suffix
274
275         if [[ "${slot}" == "0" ]]; then
276                 suffix=""
277         else
278                 suffix="-${slot}"
279         fi
280
281         echo -n "${suffix}"
282 }
283
284 _get_install_dir() {
285         echo -n "/usr/$(get_libdir)/electron$(_get_install_suffix)"
286 }
287
288 _get_target_arch() {
289         local myarch="$(tc-arch)"
290         local target_arch
291
292         if [[ $myarch = amd64 ]] ; then
293                 target_arch=x64
294         elif [[ $myarch = x86 ]] ; then
295                 target_arch=ia32
296         elif [[ $myarch = arm64 ]] ; then
297                 target_arch=arm64
298         elif [[ $myarch = arm ]] ; then
299                 target_arch=arm
300         else
301                 die "Failed to determine target arch, got '$myarch'."
302         fi
303
304         echo -n "${target_arch}"
305 }
306
307 src_prepare() {
308         mv "${WORKDIR}/${CHROMIUM_P}" "${CHROMIUM_S}" || die
309         rm -r "${NODE_S}" &&
310                 mv "${WORKDIR}/${NODE_P}" "${NODE_S}" || die
311         rm -r "${BREAKPAD_S}" &&
312                 mv "${WORKDIR}/${BREAKPAD_P}" "${BREAKPAD_S}" || die
313         rm -r "${BREAKPAD_SRC_S}" &&
314                 mv "${WORKDIR}/${BREAKPAD_SRC_P}/src" "${BREAKPAD_SRC_S}" || die
315         rm -r "${NATIVE_MATE_S}" &&
316                 mv "${WORKDIR}/${NATIVE_MATE_P}" "${NATIVE_MATE_S}" || die
317         rm -r "${PDF_VIEWER_S}" &&
318                 mv "${WORKDIR}/${PDF_VIEWER_P}" "${PDF_VIEWER_S}" || die
319         rm -r "${GRIT_S}" &&
320                 mv "${WORKDIR}/${GRIT_P}" "${GRIT_S}" || die
321         rm -r "${LIBCC_S}" &&
322                 mv "${WORKDIR}/${LIBCHROMIUMCONTENT_P}" "${LIBCC_S}" || die
323         rsync -a "${WORKDIR}/${ASAR_P}/node_modules/" \
324                 "${S}/node_modules/" || die
325         rsync -a "${WORKDIR}/${BROWSERIFY_P}/node_modules/" \
326         "${S}/node_modules/" || die
327
328         # node patches
329         cd "${NODE_S}" || die
330         # make sure node uses the correct version of v8
331         rm -r deps/v8 || die
332         ln -s "${CHROMIUM_S}/v8" deps/ || die
333
334         # make sure we use python2.* while using gyp
335         sed -i -e "s/python/${EPYTHON}/" \
336                 deps/npm/node_modules/node-gyp/gyp/gyp || die
337         sed -i -e "s/|| 'python'/|| '${EPYTHON}'/" \
338                 deps/npm/node_modules/node-gyp/lib/configure.js || die
339
340         python_fix_shebang "${CHROMIUM_S}/chrome/browser"
341         python_fix_shebang "${CHROMIUM_S}/build/gyp_chromium"
342         python_fix_shebang "${S}/tools/"
343
344         # less verbose install output (stating the same as portage, basically)
345         sed -i -e "/print/d" tools/install.py || die
346
347         # proper libdir, hat tip @ryanpcmcquen
348         # https://github.com/iojs/io.js/issues/504
349         local LIBDIR=$(get_libdir)
350         sed -i -e "s|lib/|${LIBDIR}/|g" tools/install.py || die
351         sed -i -e "s/'lib'/'${LIBDIR}'/" lib/module.js || die
352         sed -i -e "s|\"lib\"|\"${LIBDIR}\"|" deps/npm/lib/npm.js || die
353
354         # Apply Gentoo patches for Electron itself.
355         cd "${S}" || die
356         _unnest_patches "${WORKDIR}/${PATCHES_P}/${PV}/electron/"
357         eapply "${WORKDIR}/${PATCHES_P}/${PV}/electron/"
358
359         # Apply Chromium patches from libchromiumcontent.
360         cd "${CHROMIUM_S}" || die
361         _unnest_patches "${LIBCC_S}/patches"
362         eapply "${LIBCC_S}/patches"
363
364         # Finally, apply Gentoo patches for Chromium.
365         eapply "${WORKDIR}/${PATCHES_P}/${PV}/chromium/"
366
367         # Merge chromiumcontent component into chromium source tree.
368         mkdir -p "${CHROMIUM_S}/chromiumcontent" || die
369         cp -a "${LIBCC_S}/chromiumcontent" "${CHROMIUM_S}/" || die
370         cp -a "${LIBCC_S}/tools/linux/" "${CHROMIUM_S}/tools/" || die
371
372         local keeplibs=(
373                 base/third_party/dmg_fp
374                 base/third_party/dynamic_annotations
375                 base/third_party/icu
376                 base/third_party/nspr
377                 base/third_party/superfasthash
378                 base/third_party/symbolize
379                 base/third_party/valgrind
380                 base/third_party/xdg_mime
381                 base/third_party/xdg_user_dirs
382                 breakpad/src/third_party/curl
383                 chrome/third_party/mozilla_security_manager
384                 courgette/third_party
385                 net/third_party/mozilla_security_manager
386                 net/third_party/nss
387                 third_party/WebKit
388                 third_party/analytics
389                 third_party/angle
390                 third_party/angle/src/common/third_party/base
391                 third_party/angle/src/common/third_party/murmurhash
392                 third_party/angle/src/third_party/compiler
393                 third_party/angle/src/third_party/libXNVCtrl
394                 third_party/angle/src/third_party/trace_event
395                 third_party/boringssl
396                 third_party/brotli
397                 third_party/cacheinvalidation
398                 third_party/catapult
399                 third_party/catapult/third_party/polymer
400                 third_party/catapult/third_party/py_vulcanize
401                 third_party/catapult/third_party/py_vulcanize/third_party/rcssmin
402                 third_party/catapult/third_party/py_vulcanize/third_party/rjsmin
403                 third_party/catapult/tracing/third_party/d3
404                 third_party/catapult/tracing/third_party/gl-matrix
405                 third_party/catapult/tracing/third_party/jszip
406                 third_party/catapult/tracing/third_party/mannwhitneyu
407                 third_party/catapult/tracing/third_party/oboe
408                 third_party/ced
409                 third_party/cld_2
410                 third_party/cld_3
411                 third_party/cros_system_api
412                 third_party/devscripts
413                 third_party/dom_distiller_js
414                 third_party/fips181
415                 third_party/flatbuffers
416                 third_party/flot
417                 third_party/freetype
418                 third_party/glslang-angle
419                 third_party/google_input_tools
420                 third_party/google_input_tools/third_party/closure_library
421                 third_party/google_input_tools/third_party/closure_library/third_party/closure
422                 third_party/googletest
423                 third_party/hunspell
424                 third_party/iccjpeg
425                 third_party/inspector_protocol
426                 third_party/jinja2
427                 third_party/jstemplate
428                 third_party/khronos
429                 third_party/leveldatabase
430                 third_party/libXNVCtrl
431                 third_party/libaddressinput
432                 third_party/libjingle
433                 third_party/libphonenumber
434                 third_party/libsecret
435                 third_party/libsrtp
436                 third_party/libudev
437                 third_party/libwebm
438                 third_party/libxml/chromium
439                 third_party/libyuv
440                 third_party/lss
441                 third_party/lzma_sdk
442                 third_party/markupsafe
443                 third_party/mesa
444                 third_party/modp_b64
445                 third_party/mt19937ar
446                 third_party/node
447                 third_party/node/node_modules/vulcanize/third_party/UglifyJS2
448                 third_party/openmax_dl
449                 third_party/ots
450                 third_party/pdfium
451                 third_party/pdfium/third_party/agg23
452                 third_party/pdfium/third_party/base
453                 third_party/pdfium/third_party/build
454                 third_party/pdfium/third_party/bigint
455                 third_party/pdfium/third_party/freetype
456                 third_party/pdfium/third_party/lcms2-2.6
457                 third_party/pdfium/third_party/libopenjpeg20
458                 third_party/pdfium/third_party/libpng16
459                 third_party/pdfium/third_party/libtiff
460                 third_party/ply
461                 third_party/polymer
462                 third_party/protobuf
463                 third_party/protobuf/third_party/six
464                 third_party/qcms
465                 third_party/sfntly
466                 third_party/skia
467                 third_party/skia/third_party/vulkan
468                 third_party/smhasher
469                 third_party/spirv-headers
470                 third_party/spirv-tools-angle
471                 third_party/sqlite
472                 third_party/swiftshader
473                 third_party/swiftshader/third_party/llvm-subzero
474                 third_party/swiftshader/third_party/subzero
475                 third_party/usrsctp
476                 third_party/vulkan
477                 third_party/vulkan-validation-layers
478                 third_party/web-animations-js
479                 third_party/webdriver
480                 third_party/webrtc
481                 third_party/widevine
482                 third_party/woff2
483                 third_party/zlib/google
484                 url/third_party/mozilla
485                 v8/src/third_party/valgrind
486                 v8/third_party/inspector_protocol
487
488                 # gyp -> gn leftovers
489                 base/third_party/libevent
490                 third_party/adobe
491                 third_party/speech-dispatcher
492                 third_party/usb_ids
493                 third_party/xdg-utils
494                 third_party/yasm/run_yasm.py
495         )
496         if ! use system-ffmpeg; then
497                 keeplibs+=( third_party/ffmpeg third_party/opus )
498         fi
499         if use tcmalloc; then
500                 keeplibs+=( third_party/tcmalloc )
501         fi
502
503         cd "${CHROMIUM_S}" || die
504
505         # Remove most bundled libraries. Some are still needed.
506         ebegin "Unbundling libraries"
507         build/linux/unbundle/remove_bundled_libraries.py \
508                 "${keeplibs[@]}" --do-remove || die
509         eend
510
511         cd "${S}" || die
512
513         eapply_user
514 }
515
516 src_configure() {
517         local myconf_gn=""
518         local myconf_gyp=""
519
520         cd "${CHROMIUM_S}" || die
521
522         # GN needs explicit config for Debug/Release as opposed to
523         # inferring it from build directory.
524         myconf_gn+=" is_debug=false"
525
526         # Disable nacl, we can't build without pnacl (http://crbug.com/269560).
527         myconf_gn+=" enable_nacl=false"
528
529         # Use system-provided libraries.
530         # TODO: freetype (https://bugs.chromium.org/p/pdfium/issues/detail?id=733).
531         # TODO: use_system_hunspell (upstream changes needed).
532         # TODO: use_system_libsrtp (bug #459932).
533         # TODO: xml (bug #616818).
534         # TODO: use_system_protobuf (bug #525560).
535         # TODO: use_system_ssl (http://crbug.com/58087).
536         # TODO: use_system_sqlite (http://crbug.com/22208).
537
538         # libevent: https://bugs.gentoo.org/593458
539         local gn_system_libraries=(
540                 flac
541                 harfbuzz-ng
542                 icu
543                 libdrm
544                 libjpeg
545                 libpng
546                 libvpx
547                 libwebp
548                 libxml
549                 libxslt
550                 openh264
551                 re2
552                 snappy
553                 yasm
554                 zlib)
555         if use system-ffmpeg; then
556                 gn_system_libraries+=( libvpx ffmpeg opus )
557         fi
558         build/linux/unbundle/replace_gn_files.py \
559                 --system-libraries ${gn_system_libraries[@]} || die
560
561         # Optional dependencies.
562         myconf_gn+=" use_cups=$(usex cups true false)"
563         myconf_gn+=" use_gconf=$(usex gconf true false)"
564         myconf_gn+=" use_gnome_keyring=$(usex gnome-keyring true false)"
565         myconf_gn+=" use_kerberos=$(usex kerberos true false)"
566         myconf_gn+=" use_pulseaudio=$(usex pulseaudio true false)"
567
568         # TODO: link_pulseaudio=true for GN.
569
570         myconf_gn+=" fieldtrial_testing_like_official_build=true"
571
572         if tc-is-clang; then
573                 myconf_gn+=" is_clang=true clang_base_path=\"/usr\" clang_use_chrome_plugins=false"
574         else
575                 myconf_gn+=" is_clang=false"
576         fi
577
578         # Never use bundled gold binary. Disable gold linker flags for now.
579         # Do not use bundled clang.
580         # Trying to use gold results in linker crash.
581         myconf_gn+=" use_gold=false use_sysroot=false"
582         myconf_gn+=" linux_use_bundled_binutils=false use_custom_libcxx=false"
583
584         ffmpeg_branding="$(usex proprietary-codecs Chrome Chromium)"
585         myconf_gn+=" proprietary_codecs=$(usex proprietary-codecs true false)"
586         myconf_gn+=" ffmpeg_branding=\"${ffmpeg_branding}\""
587
588         # Set up Google API keys, see http://www.chromium.org/developers/how-tos/api-keys .
589         # Note: these are for Gentoo use ONLY. For your own distribution,
590         # please get your own set of keys. Feel free to contact chromium@gentoo.org
591         # for more info.
592         local google_api_key="AIzaSyDEAOvatFo0eTgsV_ZlEzx0ObmepsMzfAc"
593         local google_default_client_id="329227923882.apps.googleusercontent.com"
594         local google_default_client_secret="vgKG0NNv7GoDpbtoFNLxCUXu"
595         myconf_gn+=" google_api_key=\"${google_api_key}\""
596         myconf_gn+=" google_default_client_id=\"${google_default_client_id}\""
597         myconf_gn+=" google_default_client_secret=\"${google_default_client_secret}\""
598
599         local target_arch=$(_get_target_arch)
600         local ffmpeg_target_arch="${target_arch}"
601
602         if [[ ${ffmpeg_target_arch} = arm ]]; then
603                 ffmpeg_target_arch=$(usex neon arm-neon arm)
604         fi
605
606         # Make sure that -Werror doesn't get added to CFLAGS by the build system.
607         # Depending on GCC version the warnings are different and we don't want
608         # the build to fail because of that.
609         myconf_gn+=" treat_warnings_as_errors=false"
610
611         # Disable fatal linker warnings, bug 506268.
612         myconf_gn+=" fatal_linker_warnings=false"
613
614         # Avoid CFLAGS problems, bug #352457, bug #390147.
615         if ! use custom-cflags; then
616                 replace-flags "-Os" "-O2"
617                 strip-flags
618
619                 filter-flags "-Wl,--as-needed"
620
621                 # Prevent linker from running out of address space, bug #471810 .
622                 if use x86; then
623                         filter-flags "-g*"
624                 fi
625
626                 # Prevent libvpx build failures. Bug 530248, 544702, 546984.
627                 if [[ ${myarch} == amd64 || ${myarch} == x86 ]]; then
628                         filter-flags -mno-mmx -mno-sse2 -mno-ssse3 -mno-sse4.1 -mno-avx -mno-avx2
629                 fi
630         fi
631
632         # Make sure the build system will use the right tools, bug #340795.
633         tc-export AR CC CXX NM
634
635         # Define a custom toolchain for GN
636         myconf_gn+=" custom_toolchain=\"${FILESDIR}/toolchain:default\""
637
638         if tc-is-cross-compiler; then
639                 tc-export BUILD_{AR,CC,CXX,NM}
640                 myconf_gn+=" host_toolchain=\"${FILESDIR}/toolchain:host\""
641                 myconf_gn+=" v8_snapshot_toolchain=\"${FILESDIR}/toolchain:host\""
642         else
643                 myconf_gn+=" host_toolchain=\"${FILESDIR}/toolchain:default\""
644         fi
645
646         # https://bugs.gentoo.org/588596
647         append-cxxflags $(test-flags-CXX -fno-delete-null-pointer-checks)
648
649         myconf_gn+=" icu_use_data_file=false"
650
651         use lto && myconf_gn+=" allow_posix_link_time_opt=true"
652
653         # Tools for building programs to be executed on the build system, bug #410883.
654         if tc-is-cross-compiler; then
655                 export AR_host=$(tc-getBUILD_AR)
656                 export CC_host=$(tc-getBUILD_CC)
657                 export CXX_host=$(tc-getBUILD_CXX)
658                 export NM_host=$(tc-getBUILD_NM)
659         fi
660
661         # Bug 491582.
662         export TMPDIR="${WORKDIR}/temp"
663         mkdir -p -m 755 "${TMPDIR}" || die
664
665         if ! use system-ffmpeg; then
666                 local build_ffmpeg_args=""
667                 if use pic && [[ "${ffmpeg_target_arch}" == "ia32" ]]; then
668                         build_ffmpeg_args+=" --disable-asm"
669                 fi
670
671                 # Re-configure bundled ffmpeg. See bug #491378 for example reasons.
672                 einfo "Configuring bundled ffmpeg..."
673                 pushd third_party/ffmpeg > /dev/null || die
674                 chromium/scripts/build_ffmpeg.py linux ${ffmpeg_target_arch} \
675                         --branding ${ffmpeg_branding} -- ${build_ffmpeg_args} || die
676                 chromium/scripts/copy_config.sh || die
677                 chromium/scripts/generate_gn.py || die
678                 popd > /dev/null || die
679         fi
680
681         third_party/libaddressinput/chromium/tools/update-strings.py || die
682
683         touch chrome/test/data/webui/i18n_process_css_test.html || die
684
685         einfo "Configuring bundled nodejs..."
686         pushd "${S}/vendor/node" > /dev/null || die
687         # --shared-libuv cannot be used as electron's node fork
688         # patches uv_loop structure.
689         ./configure --shared --without-bundled-v8 \
690                 --shared-http-parser --shared-zlib \
691                 --shared-nghttp2 --shared-cares \
692                 --without-npm --with-intl=system-icu --without-dtrace \
693                 --dest-cpu=${target_arch} --prefix="" || die
694         popd > /dev/null || die
695
696         # libchromiumcontent configuration
697         myconf_gn+=" root_extra_deps = [\"//chromiumcontent:chromiumcontent\"]"
698         myconf_gn+=" is_electron_build = true"
699         myconf_gn+=" is_component_build = false"
700         myconf_gn+=" use_allocator=$(usex tcmalloc \"tcmalloc\" \"none\")"
701
702         einfo "Configuring chromiumcontent..."
703         set -- gn gen --args="${myconf_gn} ${EXTRA_GN}" out/Release
704         echo "$@"
705         "$@" || die
706
707         cd "${S}" || die
708 }
709
710 eninja() {
711         if [[ -z ${NINJAOPTS+set} ]]; then
712                 local jobs=$(makeopts_jobs)
713                 local loadavg=$(makeopts_loadavg)
714
715                 if [[ ${MAKEOPTS} == *-j* && ${jobs} != 999 ]]; then
716                         NINJAOPTS+=" -j ${jobs}"
717                 fi
718                 if [[ ${MAKEOPTS} == *-l* && ${loadavg} != 999 ]]; then
719                         NINJAOPTS+=" -l ${loadavg}"
720                 fi
721         fi
722         set -- ninja -v ${NINJAOPTS} "$@"
723         echo "$@"
724         "$@" || die
725 }
726
727 src_compile() {
728         local compile_target="${S}/out/R"
729         local myconf_gyp=""
730         local chromium_target="${CHROMIUM_S}/out/Release"
731         local libcc_path="${S}/vendor/libchromiumcontent"
732         local libcc_dist_path="${libcc_path}/dist/main"
733         local libcc_dist_static_path="${libcc_dist_path}/static_library"
734         local libcc_dist_shared_path="${libcc_dist_path}/shared_library"
735         local libcc_output="${CHROMIUM_S}/out/Release/obj/chromiumcontent"
736         local libcc_output_shared="${libcc_output}-shared"
737         local target_arch=$(_get_target_arch)
738         local l=""
739         local create_dist_args=""
740
741         tc-export AR CC CXX NM
742
743         mkdir -p "${compile_target}" || die
744
745         cd "${CHROMIUM_S}" || die
746
747         # Build mksnapshot and pax-mark it.
748         eninja -C "${chromium_target}" mksnapshot || die
749         pax-mark m "${chromium_target}/mksnapshot"
750         cp -a "${chromium_target}/mksnapshot" "${compile_target}/" || die
751
752         # Build chromedriver.
753         eninja -C "${chromium_target}" chromedriver
754         cp -a "${chromium_target}/chromedriver" "${compile_target}/" || die
755
756         # Build libchromiumcontent components.
757         eninja -C "${chromium_target}" chromiumcontent:chromiumcontent
758         CHROMIUMCONTENT_2ND_PASS=1 \
759                 eninja -C "${chromium_target}" chromiumcontent:libs
760
761         cd "${S}" || die
762
763         # Gather and prepare built components of libchromiumcontent.
764         create_dist_args+=" --target_arch=${target_arch} --component=static_library"
765         create_dist_args+=" --no_zip"
766         create_dist_args+=" --system-icu"
767         CHROMIUM_BUILD_DIR="${chromium_target}" \
768         PYTHONPATH="${WORKDIR}/ninja-${NINJA_VERSION}/misc" \
769         "${EPYTHON}" "${libcc_path}"/script/create-dist ${create_dist_args} || die
770
771         # v8 is built as a shared library, so copy it manually
772         # for generate_filenames_gypi to find.
773         mkdir -p "${libcc_dist_shared_path}" || die
774         cp "${chromium_target}/libv8.so" "${libcc_dist_shared_path}" || die
775
776         "${EPYTHON}" "${libcc_path}"/tools/generate_filenames_gypi.py \
777                 "${libcc_dist_path}/filenames.gypi" \
778                 "${CHROMIUM_S}" \
779                 "${libcc_dist_shared_path}" \
780                 "${libcc_dist_static_path}"
781
782         # Configure electron.
783         myconf_gyp+="
784                 $(gyp_use cups)
785                 $(gyp_use gconf use_gconf)
786                 $(gyp_use gnome-keyring use_gnome_keyring)
787                 $(gyp_use gnome-keyring linux_link_gnome_keyring)
788                 $(gyp_use lto)"
789
790         myconf_gyp+=" -Duse_system_icu=1"
791
792         if [[ $(tc-getCC) == *clang* ]]; then
793                 myconf_gyp+=" -Dclang=1"
794         else
795                 myconf_gyp+=" -Dclang=0"
796         fi
797
798         # Never use bundled gold binary. Disable gold linker flags for now.
799         # Do not use bundled clang.
800         myconf_gyp+="
801                 -Dclang_use_chrome_plugins=0
802                 -Dhost_clang=0
803                 -Dlinux_use_bundled_binutils=0
804                 -Dlinux_use_bundled_gold=0
805                 -Dlinux_use_gold_flags=0
806                 -Dsysroot="
807
808         myconf_gyp+=" -Dtarget_arch=${target_arch}"
809         myconf_gyp+=" -Dpython=${EPYTHON}"
810
811         # Make sure that -Werror doesn't get added to CFLAGS by the build system.
812         # Depending on GCC version the warnings are different and we don't want
813         # the build to fail because of that.
814         myconf_gyp+=" -Dwerror="
815
816         # Disable fatal linker warnings, bug 506268.
817         myconf_gyp+=" -Ddisable_fatal_linker_warnings=1"
818
819         myconf_gyp+=" -Dicu_use_data_file_flag=0"
820         myconf_gyp+=" -Dgenerate_character_data=0"
821
822         myconf_gyp+=" -Dmas_build=0"
823         myconf_gyp+=" -Dlibchromiumcontent_component=0"
824         myconf_gyp+=" -Dcomponent=static_library"
825         myconf_gyp+=" -Dlibrary=static_library"
826         myconf_gyp+=" -Icommon.gypi electron.gyp"
827
828         EGYP_CHROMIUM_COMMAND="${CHROMIUM_S}/build/gyp_chromium" \
829                 egyp_chromium ${myconf_gyp} || die
830
831         mkdir -p "${compile_target}/lib/" || die
832         # Copy libv8 and snapshot files so the node binary can find them.
833         cp "${chromium_target}/libv8.so" "${compile_target}/lib/" || die
834         cp "${chromium_target}/natives_blob.bin" "${compile_target}" || die
835         cp "${chromium_target}/snapshot_blob.bin" "${compile_target}" || die
836
837         # Copy generated shim headers.
838         mkdir -p "${compile_target}/gen" || die
839         cp -r "${chromium_target}/gen/shim_headers" \
840                 "${compile_target}/gen" || die
841
842         # Build the Node binary and pax-mark it.
843         eninja -C ${compile_target} nodebin
844         pax-mark m ${compile_target}/nodebin
845
846         # Finally, build Electron.
847         eninja -C ${compile_target} electron
848         pax-mark m ${compile_target}/electron
849
850         echo "v${PV}" > ${compile_target}/version
851 }
852
853 src_install() {
854         local install_dir="$(_get_install_dir)"
855         local install_suffix="$(_get_install_suffix)"
856         local LIBDIR="${ED}/usr/$(get_libdir)"
857
858         pushd out/R/locales > /dev/null || die
859         chromium_remove_language_paks
860         popd > /dev/null || die
861
862         # Install Electron
863         insinto "${install_dir}"
864         exeinto "${install_dir}"
865         newexe out/R/nodebin node
866         doexe out/R/electron
867         doexe out/R/chromedriver
868         doexe out/R/mksnapshot
869         doins out/R/libv8.so
870         fperms +x "${install_dir}/libv8.so"
871         doins out/R/libnode.so
872         fperms +x "${install_dir}/libnode.so"
873         doins out/R/natives_blob.bin
874         doins out/R/snapshot_blob.bin
875         doins out/R/blink_image_resources_200_percent.pak
876         doins out/R/content_resources_200_percent.pak
877         doins out/R/content_shell.pak
878         doins out/R/pdf_viewer_resources.pak
879         doins out/R/ui_resources_200_percent.pak
880         doins out/R/views_resources_200_percent.pak
881         doins -r out/R/resources
882         doins -r out/R/locales
883         dosym "${install_dir}/electron" "/usr/bin/electron${install_suffix}"
884
885         doins out/R/version
886
887         # Install Node headers
888         HEADERS_ONLY=1 \
889                 "${S}/vendor/node/tools/install.py" install "${ED}" "/usr" || die
890         # set up a symlink structure that npm expects..
891         dodir /usr/include/node/deps/{v8,uv}
892         dosym . /usr/include/node/src
893         for var in deps/{uv,v8}/include; do
894                 dosym ../.. /usr/include/node/${var}
895         done
896
897         dodir "/usr/include/electron${install_suffix}"
898         mv "${ED}/usr/include/node" \
899            "${ED}/usr/include/electron${install_suffix}/node" || die
900 }
901
902 pkg_postinst() {
903         electron-config update
904 }
905
906 pkg_postrm() {
907         electron-config update
908 }