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