net-libs/nodejs: Version 10.20.1
[gentoo.git] / net-libs / nodejs / nodejs-99999999.ebuild
1 # Copyright 1999-2020 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5 PYTHON_COMPAT=( python3_{6,7} )
6 PYTHON_REQ_USE="threads(+)"
7 inherit bash-completion-r1 eutils flag-o-matic git-r3 pax-utils python-any-r1 toolchain-funcs xdg-utils
8
9 DESCRIPTION="A JavaScript runtime built on Chrome's V8 JavaScript engine"
10 HOMEPAGE="https://nodejs.org/"
11 EGIT_REPO_URI="https://github.com/nodejs/node"
12
13 LICENSE="Apache-1.1 Apache-2.0 BSD BSD-2 MIT"
14 SLOT="0"
15 KEYWORDS=""
16 IUSE="cpu_flags_x86_sse2 debug doc icu inspector +npm pax_kernel +snapshot +ssl +system-ssl systemtap test"
17 RESTRICT="!test? ( test )"
18 REQUIRED_USE="
19         inspector? ( icu ssl )
20         npm? ( ssl )
21         system-ssl? ( ssl )
22 "
23
24 RDEPEND="
25         >=dev-libs/libuv-1.35.0:=
26         >=net-dns/c-ares-1.15.0
27         >=net-libs/nghttp2-1.39.2
28         sys-libs/zlib
29         icu? ( >=dev-libs/icu-66.1:= )
30         system-ssl? ( >=dev-libs/openssl-1.1.1:0= )
31 "
32 BDEPEND="
33         ${PYTHON_DEPS}
34         systemtap? ( dev-util/systemtap )
35         test? ( net-misc/curl )
36         pax_kernel? ( sys-apps/elfix )
37 "
38 DEPEND="
39         ${RDEPEND}
40 "
41 PATCHES=(
42         "${FILESDIR}"/${PN}-10.3.0-global-npm-config.patch
43 )
44
45 pkg_pretend() {
46         (use x86 && ! use cpu_flags_x86_sse2) && \
47                 die "Your CPU doesn't support the required SSE2 instruction."
48
49         ( [[ ${MERGE_TYPE} != "binary" ]] && ! test-flag-CXX -std=c++11 ) && \
50                 die "Your compiler doesn't support C++11. Use GCC 4.8, Clang 3.3 or newer."
51 }
52
53 src_prepare() {
54         tc-export CC CXX PKG_CONFIG
55         export V=1
56         export BUILDTYPE=Release
57
58         # fix compilation on Darwin
59         # https://code.google.com/p/gyp/issues/detail?id=260
60         sed -i -e "/append('-arch/d" tools/gyp/pylib/gyp/xcode_emulation.py || die
61
62         # less verbose install output (stating the same as portage, basically)
63         sed -i -e "/print/d" tools/install.py || die
64
65         # proper libdir, hat tip @ryanpcmcquen https://github.com/iojs/io.js/issues/504
66         local LIBDIR=$(get_libdir)
67         sed -i -e "s|lib/|${LIBDIR}/|g" tools/install.py || die
68         sed -i -e "s/'lib'/'${LIBDIR}'/" deps/npm/lib/npm.js || die
69
70         # Avoid writing a depfile, not useful
71         sed -i -e "/DEPFLAGS =/d" tools/gyp/pylib/gyp/generator/make.py || die
72
73         sed -i -e "/'-O3'/d" common.gypi node.gypi || die
74
75         # Avoid a test that I've only been able to reproduce from emerge. It doesnt
76         # seem sandbox related either (invoking it from a sandbox works fine).
77         # The issue is that no stdin handle is openened when asked for one.
78         # It doesn't really belong upstream , so it'll just be removed until someone
79         # with more gentoo-knowledge than me (jbergstroem) figures it out.
80         rm test/parallel/test-stdout-close-unref.js || die
81
82         # debug builds. change install path, remove optimisations and override buildtype
83         if use debug; then
84                 sed -i -e "s|out/Release/|out/Debug/|g" tools/install.py || die
85                 BUILDTYPE=Debug
86         fi
87
88         # We need to disable mprotect on two files when it builds Bug 694100.
89         use pax_kernel && PATCHES+=( "${FILESDIR}"/${PN}-13.2.0-paxmarking.patch )
90
91         default
92 }
93
94 src_configure() {
95         xdg_environment_reset
96
97         local myconf=(
98                 --shared-cares --shared-libuv --shared-nghttp2 --shared-zlib
99         )
100         use debug && myconf+=( --debug )
101         use icu && myconf+=( --with-intl=system-icu ) || myconf+=( --with-intl=none )
102         use inspector || myconf+=( --without-inspector )
103         use npm || myconf+=( --without-npm )
104         use snapshot || myconf+=( --without-node-snapshot )
105         if use ssl; then
106                 use system-ssl && myconf+=( --shared-openssl --openssl-use-def-ca-store )
107         else
108                 myconf+=( --without-ssl )
109         fi
110
111         local myarch=""
112         case ${ABI} in
113                 amd64) myarch="x64";;
114                 arm) myarch="arm";;
115                 arm64) myarch="arm64";;
116                 ppc64) myarch="ppc64";;
117                 x32) myarch="x32";;
118                 x86) myarch="ia32";;
119                 *) myarch="${ABI}";;
120         esac
121
122         GYP_DEFINES="linux_use_gold_flags=0
123                 linux_use_bundled_binutils=0
124                 linux_use_bundled_gold=0" \
125         "${EPYTHON}" configure.py \
126                 --prefix="${EPREFIX}"/usr \
127                 --dest-cpu=${myarch} \
128                 $(use_with systemtap dtrace) \
129                 "${myconf[@]}" || die
130 }
131
132 src_compile() {
133         emake -C out
134 }
135
136 src_install() {
137         local LIBDIR="${ED}/usr/$(get_libdir)"
138         default
139
140         pax-mark -m "${ED}"/usr/bin/node
141
142         # set up a symlink structure that node-gyp expects..
143         dodir /usr/include/node/deps/{v8,uv}
144         dosym . /usr/include/node/src
145         for var in deps/{uv,v8}/include; do
146                 dosym ../.. /usr/include/node/${var}
147         done
148
149         if use doc; then
150                 docinto html
151                 dodoc -r "${S}"/doc/*
152         fi
153
154         if use npm; then
155                 dodir /etc/npm
156
157                 # Install bash completion for `npm`
158                 # We need to temporarily replace default config path since
159                 # npm otherwise tries to write outside of the sandbox
160                 local npm_config="usr/$(get_libdir)/node_modules/npm/lib/config/core.js"
161                 sed -i -e "s|'/etc'|'${ED}/etc'|g" "${ED}/${npm_config}" || die
162                 local tmp_npm_completion_file="$(emktemp)"
163                 "${ED}/usr/bin/npm" completion > "${tmp_npm_completion_file}"
164                 newbashcomp "${tmp_npm_completion_file}" npm
165                 sed -i -e "s|'${ED}/etc'|'/etc'|g" "${ED}/${npm_config}" || die
166
167                 # Move man pages
168                 doman "${LIBDIR}"/node_modules/npm/man/man{1,5,7}/*
169
170                 # Clean up
171                 rm "${LIBDIR}"/node_modules/npm/{.mailmap,.npmignore,Makefile} || die
172                 rm -rf "${LIBDIR}"/node_modules/npm/{doc,html,man} || die
173
174                 local find_exp="-or -name"
175                 local find_name=()
176                 for match in "AUTHORS*" "CHANGELOG*" "CONTRIBUT*" "README*" \
177                         ".travis.yml" ".eslint*" ".wercker.yml" ".npmignore" \
178                         "*.md" "*.markdown" "*.bat" "*.cmd"; do
179                         find_name+=( ${find_exp} "${match}" )
180                 done
181
182                 # Remove various development and/or inappropriate files and
183                 # useless docs of dependend packages.
184                 find "${LIBDIR}"/node_modules \
185                         \( -type d -name examples \) -or \( -type f \( \
186                                 -iname "LICEN?E*" \
187                                 "${find_name[@]}" \
188                         \) \) -exec rm -rf "{}" \;
189         fi
190
191         mv "${ED}"/usr/share/doc/node "${ED}"/usr/share/doc/${PF} || die
192 }
193
194 src_test() {
195         out/${BUILDTYPE}/cctest || die
196         "${EPYTHON}" tools/test.py --mode=${BUILDTYPE,,} -J message parallel sequential || die
197 }
198
199 pkg_postinst() {
200         elog "The global npm config lives in /etc/npm. This deviates slightly"
201         elog "from upstream which otherwise would have it live in /usr/etc/."
202         elog ""
203         elog "Protip: When using node-gyp to install native modules, you can"
204         elog "avoid having to download extras by doing the following:"
205         elog "$ node-gyp --nodedir /usr/include/node <command>"
206 }