Line 0
Link Here
|
|
|
1 |
# Copyright 1999-2022 Gentoo Authors |
2 |
# Distributed under the terms of the GNU General Public License v2 |
3 |
|
4 |
EAPI=7 |
5 |
|
6 |
PYTHON_COMPAT=( python3_{8..10} ) |
7 |
PYTHON_REQ_USE="threads(+)" |
8 |
|
9 |
inherit bash-completion-r1 flag-o-matic pax-utils python-any-r1 toolchain-funcs xdg-utils |
10 |
|
11 |
DESCRIPTION="A JavaScript runtime built on Chrome's V8 JavaScript engine" |
12 |
HOMEPAGE="https://nodejs.org/" |
13 |
LICENSE="Apache-1.1 Apache-2.0 BSD BSD-2 MIT" |
14 |
|
15 |
if [[ ${PV} == *9999 ]]; then |
16 |
inherit git-r3 |
17 |
EGIT_REPO_URI="https://github.com/nodejs/node" |
18 |
SLOT="0" |
19 |
else |
20 |
SRC_URI="https://nodejs.org/dist/v${PV}/node-v${PV}.tar.xz" |
21 |
SLOT="0/$(ver_cut 1)" |
22 |
KEYWORDS="~amd64 ~arm ~arm64 ~ppc64 -riscv ~x86 ~amd64-linux ~x64-macos" |
23 |
S="${WORKDIR}/node-v${PV}" |
24 |
fi |
25 |
|
26 |
IUSE="cpu_flags_x86_sse2 debug doc +icu inspector lto +npm pax-kernel +snapshot +ssl +system-icu +system-ssl systemtap test" |
27 |
REQUIRED_USE="inspector? ( icu ssl ) |
28 |
npm? ( ssl ) |
29 |
system-icu? ( icu ) |
30 |
system-ssl? ( ssl )" |
31 |
|
32 |
RESTRICT="!test? ( test )" |
33 |
|
34 |
RDEPEND=">=app-arch/brotli-1.0.9:= |
35 |
>=dev-libs/libuv-1.40.0:= |
36 |
>=net-dns/c-ares-1.17.2:= |
37 |
>=net-libs/nghttp2-1.41.0:= |
38 |
sys-libs/zlib |
39 |
system-icu? ( >=dev-libs/icu-67:= ) |
40 |
system-ssl? ( |
41 |
>=dev-libs/openssl-1.1.1:0= |
42 |
<dev-libs/openssl-3.0.0_beta1:0= |
43 |
)" |
44 |
BDEPEND="${PYTHON_DEPS} |
45 |
sys-apps/coreutils |
46 |
virtual/pkgconfig |
47 |
systemtap? ( dev-util/systemtap ) |
48 |
test? ( net-misc/curl ) |
49 |
pax-kernel? ( sys-apps/elfix )" |
50 |
DEPEND="${RDEPEND}" |
51 |
|
52 |
PATCHES=( |
53 |
"${FILESDIR}"/${PN}-12.22.5-shared_c-ares_nameser_h.patch |
54 |
"${FILESDIR}"/${PN}-14.15.0-fix_ppc64_crashes.patch |
55 |
"${FILESDIR}"/${P}-global-npm-config.patch |
56 |
) |
57 |
|
58 |
pkg_pretend() { |
59 |
(use x86 && ! use cpu_flags_x86_sse2) && \ |
60 |
die "Your CPU doesn't support the required SSE2 instruction." |
61 |
} |
62 |
|
63 |
src_prepare() { |
64 |
tc-export AR CC CXX PKG_CONFIG |
65 |
export V=1 |
66 |
export BUILDTYPE=Release |
67 |
|
68 |
# fix compilation on Darwin |
69 |
# https://code.google.com/p/gyp/issues/detail?id=260 |
70 |
sed -i -e "/append('-arch/d" tools/gyp/pylib/gyp/xcode_emulation.py || die |
71 |
|
72 |
# less verbose install output (stating the same as portage, basically) |
73 |
sed -i -e "/print/d" tools/install.py || die |
74 |
|
75 |
# proper libdir, hat tip @ryanpcmcquen https://github.com/iojs/io.js/issues/504 |
76 |
local LIBDIR=$(get_libdir) |
77 |
sed -i -e "s|lib/|${LIBDIR}/|g" tools/install.py || die |
78 |
sed -i -e "s/'lib'/'${LIBDIR}'/" deps/npm/lib/npm.js || die |
79 |
|
80 |
# Avoid writing a depfile, not useful |
81 |
sed -i -e "/DEPFLAGS =/d" tools/gyp/pylib/gyp/generator/make.py || die |
82 |
|
83 |
sed -i -e "/'-O3'/d" common.gypi node.gypi || 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 |
# All this test does is check if the npm CLI produces warnings of any sort, |
95 |
# failing if it does. Overkill, much? Especially given one possible warning |
96 |
# is that there is a newer version of npm available upstream (yes, it does |
97 |
# use the network if available), thus making it a real possibility for this |
98 |
# test to begin failing one day even though it was fine before. |
99 |
rm -f test/parallel/test-release-npm.js |
100 |
|
101 |
default |
102 |
} |
103 |
|
104 |
src_configure() { |
105 |
xdg_environment_reset |
106 |
|
107 |
# LTO compiler flags are handled by configure.py itself |
108 |
filter-flags '-flto*' |
109 |
|
110 |
local myconf=( |
111 |
--shared-brotli |
112 |
--shared-cares |
113 |
--shared-libuv |
114 |
--shared-nghttp2 |
115 |
--shared-zlib |
116 |
) |
117 |
use debug && myconf+=( --debug ) |
118 |
use lto && myconf+=( --enable-lto ) |
119 |
if use system-icu; then |
120 |
myconf+=( --with-intl=system-icu ) |
121 |
elif use icu; then |
122 |
myconf+=( --with-intl=full-icu ) |
123 |
else |
124 |
myconf+=( --with-intl=none ) |
125 |
fi |
126 |
use inspector || myconf+=( --without-inspector ) |
127 |
use npm || myconf+=( --without-npm ) |
128 |
use snapshot || myconf+=( --without-node-snapshot ) |
129 |
if use ssl; then |
130 |
use system-ssl && myconf+=( --shared-openssl --openssl-use-def-ca-store ) |
131 |
else |
132 |
myconf+=( --without-ssl ) |
133 |
fi |
134 |
|
135 |
local myarch="" |
136 |
case ${ABI} in |
137 |
amd64) myarch="x64";; |
138 |
arm) myarch="arm";; |
139 |
arm64) myarch="arm64";; |
140 |
ppc64) myarch="ppc64";; |
141 |
x32) myarch="x32";; |
142 |
x86) myarch="ia32";; |
143 |
*) myarch="${ABI}";; |
144 |
esac |
145 |
|
146 |
GYP_DEFINES="linux_use_gold_flags=0 |
147 |
linux_use_bundled_binutils=0 |
148 |
linux_use_bundled_gold=0" \ |
149 |
"${EPYTHON}" configure.py \ |
150 |
--prefix="${EPREFIX}"/usr \ |
151 |
--dest-cpu=${myarch} \ |
152 |
$(use_with systemtap dtrace) \ |
153 |
"${myconf[@]}" || die |
154 |
} |
155 |
|
156 |
src_compile() { |
157 |
emake -C out |
158 |
} |
159 |
|
160 |
src_install() { |
161 |
local LIBDIR="${ED}/usr/$(get_libdir)" |
162 |
default |
163 |
|
164 |
pax-mark -m "${ED}"/usr/bin/node |
165 |
|
166 |
# set up a symlink structure that node-gyp expects.. |
167 |
dodir /usr/include/node/deps/{v8,uv} |
168 |
dosym . /usr/include/node/src |
169 |
for var in deps/{uv,v8}/include; do |
170 |
dosym ../.. /usr/include/node/${var} |
171 |
done |
172 |
|
173 |
if use doc; then |
174 |
docinto html |
175 |
dodoc -r "${S}"/doc/* |
176 |
fi |
177 |
|
178 |
if use npm; then |
179 |
dodir /etc/npm |
180 |
|
181 |
# Install bash completion for `npm` |
182 |
# We need to temporarily replace default config path since |
183 |
# npm otherwise tries to write outside of the sandbox |
184 |
local npm_config="usr/$(get_libdir)/node_modules/npm/lib/config/core.js" |
185 |
sed -i -e "s|'/etc'|'${ED}/etc'|g" "${ED}/${npm_config}" || die |
186 |
local tmp_npm_completion_file="$(TMPDIR="${T}" mktemp -t npm.XXXXXXXXXX)" |
187 |
"${ED}/usr/bin/npm" completion > "${tmp_npm_completion_file}" |
188 |
newbashcomp "${tmp_npm_completion_file}" npm |
189 |
sed -i -e "s|'${ED}/etc'|'/etc'|g" "${ED}/${npm_config}" || die |
190 |
|
191 |
# Move man pages |
192 |
doman "${LIBDIR}"/node_modules/npm/man/man{1,5,7}/* |
193 |
|
194 |
# Clean up |
195 |
rm -f "${LIBDIR}"/node_modules/npm/{.mailmap,.npmignore,Makefile} |
196 |
rm -rf "${LIBDIR}"/node_modules/npm/{doc,html,man} |
197 |
|
198 |
local find_exp="-or -name" |
199 |
local find_name=() |
200 |
for match in "AUTHORS*" "CHANGELOG*" "CONTRIBUT*" "README*" \ |
201 |
".travis.yml" ".eslint*" ".wercker.yml" ".npmignore" \ |
202 |
"*.md" "*.markdown" "*.bat" "*.cmd"; do |
203 |
find_name+=( ${find_exp} "${match}" ) |
204 |
done |
205 |
|
206 |
# Remove various development and/or inappropriate files and |
207 |
# useless docs of dependend packages. |
208 |
find "${LIBDIR}"/node_modules \ |
209 |
\( -type d -name examples \) -or \( -type f \( \ |
210 |
-iname "LICEN?E*" \ |
211 |
"${find_name[@]}" \ |
212 |
\) \) -exec rm -rf "{}" \; |
213 |
fi |
214 |
|
215 |
mv "${ED}"/usr/share/doc/node "${ED}"/usr/share/doc/${PF} || die |
216 |
} |
217 |
|
218 |
src_test() { |
219 |
if has usersandbox ${FEATURES}; then |
220 |
rm -f "${S}"/test/parallel/test-fs-mkdir.js |
221 |
ewarn "You are emerging ${PN} with 'usersandbox' enabled. Excluding tests known to fail in this mode." \ |
222 |
"For full test coverage, emerge =${CATEGORY}/${PF} with 'FEATURES=-usersandbox'." |
223 |
fi |
224 |
|
225 |
out/${BUILDTYPE}/cctest || die |
226 |
"${EPYTHON}" tools/test.py --mode=${BUILDTYPE,,} --flaky-tests=dontcare -J message parallel sequential || die |
227 |
} |