net-libs/nodejs: Call xdg_environment_reset() from xdg-utils.eclass
[gentoo.git] / net-libs / nodejs / nodejs-99999999.ebuild
1 # Copyright 1999-2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 EAPI=7
5 PYTHON_COMPAT=( python2_7 )
6 PYTHON_REQ_USE="threads"
7 inherit bash-completion-r1 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 +snapshot +ssl systemtap test"
17 REQUIRED_USE="
18         inspector? ( icu ssl )
19         npm? ( ssl )
20 "
21
22 RDEPEND="
23         >=dev-libs/libuv-1.30.1:=
24         >=net-dns/c-ares-1.15.0
25         >=net-libs/http-parser-2.9.0:=
26         >=net-libs/nghttp2-1.39.1
27         sys-libs/zlib
28         icu? ( >=dev-libs/icu-64.2:= )
29         ssl? ( >=dev-libs/openssl-1.1.1:0= )
30 "
31 DEPEND="
32         ${RDEPEND}
33         ${PYTHON_DEPS}
34         systemtap? ( dev-util/systemtap )
35         test? ( net-misc/curl )
36 "
37 PATCHES=(
38         "${FILESDIR}"/${PN}-10.3.0-global-npm-config.patch
39 )
40
41 pkg_pretend() {
42         (use x86 && ! use cpu_flags_x86_sse2) && \
43                 die "Your CPU doesn't support the required SSE2 instruction."
44
45         ( [[ ${MERGE_TYPE} != "binary" ]] && ! test-flag-CXX -std=c++11 ) && \
46                 die "Your compiler doesn't support C++11. Use GCC 4.8, Clang 3.3 or newer."
47 }
48
49 src_prepare() {
50         tc-export CC CXX PKG_CONFIG
51         export V=1
52         export BUILDTYPE=Release
53
54         # fix compilation on Darwin
55         # https://code.google.com/p/gyp/issues/detail?id=260
56         sed -i -e "/append('-arch/d" tools/gyp/pylib/gyp/xcode_emulation.py || die
57
58         # make sure we use python2.* while using gyp
59         sed -i -e "s/python/${EPYTHON}/" deps/npm/node_modules/node-gyp/gyp/gyp || die
60         sed -i -e "s/|| 'python2'/|| '${EPYTHON}'/" deps/npm/node_modules/node-gyp/lib/configure.js || 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         default
89 }
90
91 src_configure() {
92         xdg_environment_reset
93
94         local myconf=(
95                 --shared-cares --shared-http-parser --shared-libuv --shared-nghttp2
96                 --shared-zlib
97         )
98         use debug && myconf+=( --debug )
99         use icu && myconf+=( --with-intl=system-icu ) || myconf+=( --with-intl=none )
100         use inspector || myconf+=( --without-inspector )
101         use npm || myconf+=( --without-npm )
102         use snapshot && myconf+=( --with-snapshot )
103         use ssl && myconf+=( --shared-openssl --openssl-use-def-ca-store ) || myconf+=( --without-ssl )
104
105         local myarch=""
106         case ${ABI} in
107                 amd64) myarch="x64";;
108                 arm) myarch="arm";;
109                 arm64) myarch="arm64";;
110                 ppc64) myarch="ppc64";;
111                 x32) myarch="x32";;
112                 x86) myarch="ia32";;
113                 *) myarch="${ABI}";;
114         esac
115
116         GYP_DEFINES="linux_use_gold_flags=0
117                 linux_use_bundled_binutils=0
118                 linux_use_bundled_gold=0" \
119         "${PYTHON}" configure \
120                 --prefix="${EPREFIX}"/usr \
121                 --dest-cpu=${myarch} \
122                 $(use_with systemtap dtrace) \
123                 "${myconf[@]}" || die
124 }
125
126 src_compile() {
127         emake -C out mksnapshot
128         pax-mark m "out/${BUILDTYPE}/mksnapshot"
129         emake -C out
130 }
131
132 src_install() {
133         local LIBDIR="${ED}/usr/$(get_libdir)"
134         default
135
136         pax-mark -m "${ED}"/usr/bin/node
137
138         # set up a symlink structure that node-gyp expects..
139         dodir /usr/include/node/deps/{v8,uv}
140         dosym . /usr/include/node/src
141         for var in deps/{uv,v8}/include; do
142                 dosym ../.. /usr/include/node/${var}
143         done
144
145         if use doc; then
146                 # Patch docs to make them offline readable
147                 for i in `grep -rl 'fonts.googleapis.com' "${S}"/out/doc/api/*`; do
148                         sed -i '/fonts.googleapis.com/ d' $i;
149                 done
150                 # Install docs
151                 docinto html
152                 dodoc -r "${S}"/doc/*
153         fi
154
155         if use npm; then
156                 dodir /etc/npm
157
158                 # Install bash completion for `npm`
159                 # We need to temporarily replace default config path since
160                 # npm otherwise tries to write outside of the sandbox
161                 local npm_config="usr/$(get_libdir)/node_modules/npm/lib/config/core.js"
162                 sed -i -e "s|'/etc'|'${ED}/etc'|g" "${ED}/${npm_config}" || die
163                 local tmp_npm_completion_file="$(emktemp)"
164                 "${ED}/usr/bin/npm" completion > "${tmp_npm_completion_file}"
165                 newbashcomp "${tmp_npm_completion_file}" npm
166                 sed -i -e "s|'${ED}/etc'|'/etc'|g" "${ED}/${npm_config}" || die
167
168                 # Move man pages
169                 doman "${LIBDIR}"/node_modules/npm/man/man{1,5,7}/*
170
171                 # Clean up
172                 rm "${LIBDIR}"/node_modules/npm/{.mailmap,.npmignore,Makefile} || die
173                 rm -rf "${LIBDIR}"/node_modules/npm/{doc,html,man} || die
174
175                 local find_exp="-or -name"
176                 local find_name=()
177                 for match in "AUTHORS*" "CHANGELOG*" "CONTRIBUT*" "README*" \
178                         ".travis.yml" ".eslint*" ".wercker.yml" ".npmignore" \
179                         "*.md" "*.markdown" "*.bat" "*.cmd"; do
180                         find_name+=( ${find_exp} "${match}" )
181                 done
182
183                 # Remove various development and/or inappropriate files and
184                 # useless docs of dependend packages.
185                 find "${LIBDIR}"/node_modules \
186                         \( -type d -name examples \) -or \( -type f \( \
187                                 -iname "LICEN?E*" \
188                                 "${find_name[@]}" \
189                         \) \) -exec rm -rf "{}" \;
190         fi
191
192         mv "${ED}"/usr/share/doc/node "${ED}"/usr/share/doc/${PF} || die
193 }
194
195 src_test() {
196         out/${BUILDTYPE}/cctest || die
197         "${PYTHON}" tools/test.py --mode=${BUILDTYPE,,} -J message parallel sequential || die
198 }
199
200 pkg_postinst() {
201         elog "The global npm config lives in /etc/npm. This deviates slightly"
202         elog "from upstream which otherwise would have it live in /usr/etc/."
203         elog ""
204         elog "Protip: When using node-gyp to install native modules, you can"
205         elog "avoid having to download extras by doing the following:"
206         elog "$ node-gyp --nodedir /usr/include/node <command>"
207 }