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