blob: fce4c1146f29cee55df7643b63bfa9723db013e6 [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001DEPENDS_prepend = "nodejs-native "
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002RDEPENDS_${PN}_prepend = "nodejs "
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05003S = "${WORKDIR}/npmpkg"
4
5NPM_INSTALLDIR = "${D}${libdir}/node_modules/${PN}"
6
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007# function maps arch names to npm arch names
8def npm_oe_arch_map(target_arch, d):
9 import re
10 if re.match('p(pc|owerpc)(|64)', target_arch): return 'ppc'
11 elif re.match('i.86$', target_arch): return 'ia32'
12 elif re.match('x86_64$', target_arch): return 'x64'
13 elif re.match('arm64$', target_arch): return 'arm'
14 return target_arch
15
16NPM_ARCH ?= "${@npm_oe_arch_map(d.getVar('TARGET_ARCH', True), d)}"
17
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050018npm_do_compile() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -060019 # Copy in any additionally fetched modules
20 if [ -d ${WORKDIR}/node_modules ] ; then
21 cp -a ${WORKDIR}/node_modules ${S}/
22 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050023 # changing the home directory to the working directory, the .npmrc will
24 # be created in this directory
25 export HOME=${WORKDIR}
26 npm config set dev false
27 npm set cache ${WORKDIR}/npm_cache
28 # clear cache before every build
29 npm cache clear
30 # Install pkg into ${S} without going to the registry
Patrick Williamsc0f7c042017-02-23 20:41:17 -060031 npm --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --production --no-registry install
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050032}
33
34npm_do_install() {
35 mkdir -p ${NPM_INSTALLDIR}/
36 cp -a ${S}/* ${NPM_INSTALLDIR}/ --no-preserve=ownership
37}
38
39python populate_packages_prepend () {
40 instdir = d.expand('${D}${libdir}/node_modules/${PN}')
41 extrapackages = oe.package.npm_split_package_dirs(instdir)
42 pkgnames = extrapackages.keys()
43 d.prependVar('PACKAGES', '%s ' % ' '.join(pkgnames))
44 for pkgname in pkgnames:
45 pkgrelpath, pdata = extrapackages[pkgname]
46 pkgpath = '${libdir}/node_modules/${PN}/' + pkgrelpath
47 # package names can't have underscores but npm packages sometimes use them
48 oe_pkg_name = pkgname.replace('_', '-')
49 expanded_pkgname = d.expand(oe_pkg_name)
50 d.setVar('FILES_%s' % expanded_pkgname, pkgpath)
51 if pdata:
52 version = pdata.get('version', None)
53 if version:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060054 d.setVar('PKGV_%s' % expanded_pkgname, version)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050055 description = pdata.get('description', None)
56 if description:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060057 d.setVar('SUMMARY_%s' % expanded_pkgname, description.replace(u"\u2018", "'").replace(u"\u2019", "'"))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050058 d.appendVar('RDEPENDS_%s' % d.getVar('PN', True), ' %s' % ' '.join(pkgnames).replace('_', '-'))
59}
60
61FILES_${PN} += " \
62 ${libdir}/node_modules/${PN} \
63"
64
65EXPORT_FUNCTIONS do_compile do_install