blob: c351ff0866b0f9b152555d8679426130f7bbb5f8 [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
13NPM_INSTALLDIR = "${D}${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)}"
25NPM_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}
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050055 mkdir -p ${NPM_INSTALLDIR}/
Brad Bishop316dfdd2018-06-25 12:45:53 -040056 npm pack .
57 npm install --prefix ${D}${prefix} -g --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --production --no-registry ${NPMPN}-${PV}.tgz
Brad Bishop6e60e8b2018-02-01 10:27:11 -050058 if [ -d ${D}${prefix}/etc ] ; then
59 # This will be empty
60 rmdir ${D}${prefix}/etc
61 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050062}
63
64python populate_packages_prepend () {
Brad Bishop316dfdd2018-06-25 12:45:53 -040065 instdir = d.expand('${D}${libdir}/node_modules/${NPMPN}')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050066 extrapackages = oe.package.npm_split_package_dirs(instdir)
67 pkgnames = extrapackages.keys()
68 d.prependVar('PACKAGES', '%s ' % ' '.join(pkgnames))
69 for pkgname in pkgnames:
70 pkgrelpath, pdata = extrapackages[pkgname]
Brad Bishop316dfdd2018-06-25 12:45:53 -040071 pkgpath = '${libdir}/node_modules/${NPMPN}/' + pkgrelpath
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050072 # package names can't have underscores but npm packages sometimes use them
73 oe_pkg_name = pkgname.replace('_', '-')
74 expanded_pkgname = d.expand(oe_pkg_name)
75 d.setVar('FILES_%s' % expanded_pkgname, pkgpath)
76 if pdata:
77 version = pdata.get('version', None)
78 if version:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060079 d.setVar('PKGV_%s' % expanded_pkgname, version)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050080 description = pdata.get('description', None)
81 if description:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060082 d.setVar('SUMMARY_%s' % expanded_pkgname, description.replace(u"\u2018", "'").replace(u"\u2019", "'"))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050083 d.appendVar('RDEPENDS_%s' % d.getVar('PN'), ' %s' % ' '.join(pkgnames).replace('_', '-'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050084}
85
86FILES_${PN} += " \
Brad Bishop316dfdd2018-06-25 12:45:53 -040087 ${libdir}/node_modules/${NPMPN} \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050088"
89
90EXPORT_FUNCTIONS do_compile do_install