blob: 4b1f0a39f0fbdffade8e1b20532357ead6972ba9 [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
Brad Bishop316dfdd2018-06-25 12:45:53 -04005def node_pkgname(d):
6 bpn = d.getVar('BPN')
7 if bpn.startswith("node-"):
8 return bpn[5:]
9 return bpn
10
11NPMPN ?= "${@node_pkgname(d)}"
12
Brad Bishop15ae2502019-06-18 21:44:24 -040013NPM_INSTALLDIR = "${libdir}/node_modules/${NPMPN}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050014
Patrick Williamsc0f7c042017-02-23 20:41:17 -060015# function maps arch names to npm arch names
16def npm_oe_arch_map(target_arch, d):
17 import re
18 if re.match('p(pc|owerpc)(|64)', target_arch): return 'ppc'
19 elif re.match('i.86$', target_arch): return 'ia32'
20 elif re.match('x86_64$', target_arch): return 'x64'
21 elif re.match('arm64$', target_arch): return 'arm'
22 return target_arch
23
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024NPM_ARCH ?= "${@npm_oe_arch_map(d.getVar('TARGET_ARCH'), d)}"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080025NPM_INSTALL_DEV ?= "0"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060026
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050027npm_do_compile() {
Patrick Williamsc0f7c042017-02-23 20:41:17 -060028 # Copy in any additionally fetched modules
29 if [ -d ${WORKDIR}/node_modules ] ; then
30 cp -a ${WORKDIR}/node_modules ${S}/
31 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050032 # changing the home directory to the working directory, the .npmrc will
33 # be created in this directory
34 export HOME=${WORKDIR}
Brad Bishop6e60e8b2018-02-01 10:27:11 -050035 if [ "${NPM_INSTALL_DEV}" = "1" ]; then
36 npm config set dev true
37 else
38 npm config set dev false
39 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050040 npm set cache ${WORKDIR}/npm_cache
41 # clear cache before every build
Brad Bishop316dfdd2018-06-25 12:45:53 -040042 npm cache clear --force
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050043 # Install pkg into ${S} without going to the registry
Brad Bishop6e60e8b2018-02-01 10:27:11 -050044 if [ "${NPM_INSTALL_DEV}" = "1" ]; then
45 npm --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --no-registry install
46 else
47 npm --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --production --no-registry install
48 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050049}
50
51npm_do_install() {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050052 # changing the home directory to the working directory, the .npmrc will
53 # be created in this directory
54 export HOME=${WORKDIR}
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080055 mkdir -p ${D}${libdir}/node_modules
Brad Bishop15ae2502019-06-18 21:44:24 -040056 local NPM_PACKFILE=$(npm pack .)
57 npm install --prefix ${D}${prefix} -g --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --production --no-registry ${NPM_PACKFILE}
58 ln -fs node_modules ${D}${libdir}/node
59 find ${D}${NPM_INSTALLDIR} -type f \( -name "*.a" -o -name "*.d" -o -name "*.o" \) -delete
Brad Bishop6e60e8b2018-02-01 10:27:11 -050060 if [ -d ${D}${prefix}/etc ] ; then
61 # This will be empty
62 rmdir ${D}${prefix}/etc
63 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050064}
65
66python populate_packages_prepend () {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080067 instdir = d.expand('${D}${NPM_INSTALLDIR}')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050068 extrapackages = oe.package.npm_split_package_dirs(instdir)
69 pkgnames = extrapackages.keys()
70 d.prependVar('PACKAGES', '%s ' % ' '.join(pkgnames))
71 for pkgname in pkgnames:
72 pkgrelpath, pdata = extrapackages[pkgname]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080073 pkgpath = '${NPM_INSTALLDIR}/' + pkgrelpath
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050074 # package names can't have underscores but npm packages sometimes use them
75 oe_pkg_name = pkgname.replace('_', '-')
76 expanded_pkgname = d.expand(oe_pkg_name)
77 d.setVar('FILES_%s' % expanded_pkgname, pkgpath)
78 if pdata:
79 version = pdata.get('version', None)
80 if version:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060081 d.setVar('PKGV_%s' % expanded_pkgname, version)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050082 description = pdata.get('description', None)
83 if description:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060084 d.setVar('SUMMARY_%s' % expanded_pkgname, description.replace(u"\u2018", "'").replace(u"\u2019", "'"))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050085 d.appendVar('RDEPENDS_%s' % d.getVar('PN'), ' %s' % ' '.join(pkgnames).replace('_', '-'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050086}
87
88FILES_${PN} += " \
Brad Bishop15ae2502019-06-18 21:44:24 -040089 ${bindir} \
90 ${libdir}/node \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080091 ${NPM_INSTALLDIR} \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050092"
93
94EXPORT_FUNCTIONS do_compile do_install