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