Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1 | DEPENDS_prepend = "nodejs-native " |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2 | RDEPENDS_${PN}_prepend = "nodejs " |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 3 | S = "${WORKDIR}/npmpkg" |
| 4 | |
| 5 | NPM_INSTALLDIR = "${D}${libdir}/node_modules/${PN}" |
| 6 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7 | # function maps arch names to npm arch names |
| 8 | def 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 | |
| 16 | NPM_ARCH ?= "${@npm_oe_arch_map(d.getVar('TARGET_ARCH', True), d)}" |
| 17 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 18 | npm_do_compile() { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 19 | # Copy in any additionally fetched modules |
| 20 | if [ -d ${WORKDIR}/node_modules ] ; then |
| 21 | cp -a ${WORKDIR}/node_modules ${S}/ |
| 22 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 23 | # 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 31 | npm --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --production --no-registry install |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | npm_do_install() { |
| 35 | mkdir -p ${NPM_INSTALLDIR}/ |
| 36 | cp -a ${S}/* ${NPM_INSTALLDIR}/ --no-preserve=ownership |
| 37 | } |
| 38 | |
| 39 | python 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 54 | d.setVar('PKGV_%s' % expanded_pkgname, version) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 55 | description = pdata.get('description', None) |
| 56 | if description: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 57 | d.setVar('SUMMARY_%s' % expanded_pkgname, description.replace(u"\u2018", "'").replace(u"\u2019", "'")) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 58 | d.appendVar('RDEPENDS_%s' % d.getVar('PN', True), ' %s' % ' '.join(pkgnames).replace('_', '-')) |
| 59 | } |
| 60 | |
| 61 | FILES_${PN} += " \ |
| 62 | ${libdir}/node_modules/${PN} \ |
| 63 | " |
| 64 | |
| 65 | EXPORT_FUNCTIONS do_compile do_install |