blob: 6dbae6bc79cd5550c08975eb02fa60c49e27fc0e [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 Bishop1a4b7ee2018-12-16 17:11:34 -080013NPM_INSTALLDIR = "${libdir}/node/${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 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 Bishop1a4b7ee2018-12-16 17:11:34 -080058 mv ${D}${libdir}/node_modules ${D}${libdir}/node
Brad Bishop6e60e8b2018-02-01 10:27:11 -050059 if [ -d ${D}${prefix}/etc ] ; then
60 # This will be empty
61 rmdir ${D}${prefix}/etc
62 fi
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050063}
64
65python populate_packages_prepend () {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080066 instdir = d.expand('${D}${NPM_INSTALLDIR}')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050067 extrapackages = oe.package.npm_split_package_dirs(instdir)
68 pkgnames = extrapackages.keys()
69 d.prependVar('PACKAGES', '%s ' % ' '.join(pkgnames))
70 for pkgname in pkgnames:
71 pkgrelpath, pdata = extrapackages[pkgname]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080072 pkgpath = '${NPM_INSTALLDIR}/' + pkgrelpath
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050073 # package names can't have underscores but npm packages sometimes use them
74 oe_pkg_name = pkgname.replace('_', '-')
75 expanded_pkgname = d.expand(oe_pkg_name)
76 d.setVar('FILES_%s' % expanded_pkgname, pkgpath)
77 if pdata:
78 version = pdata.get('version', None)
79 if version:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060080 d.setVar('PKGV_%s' % expanded_pkgname, version)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050081 description = pdata.get('description', None)
82 if description:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060083 d.setVar('SUMMARY_%s' % expanded_pkgname, description.replace(u"\u2018", "'").replace(u"\u2019", "'"))
Brad Bishop6e60e8b2018-02-01 10:27:11 -050084 d.appendVar('RDEPENDS_%s' % d.getVar('PN'), ' %s' % ' '.join(pkgnames).replace('_', '-'))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050085}
86
87FILES_${PN} += " \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080088 ${NPM_INSTALLDIR} \
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050089"
90
91EXPORT_FUNCTIONS do_compile do_install