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 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 5 | def node_pkgname(d): |
| 6 | bpn = d.getVar('BPN') |
| 7 | if bpn.startswith("node-"): |
| 8 | return bpn[5:] |
| 9 | return bpn |
| 10 | |
| 11 | NPMPN ?= "${@node_pkgname(d)}" |
| 12 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 13 | NPM_INSTALLDIR = "${libdir}/node/${NPMPN}" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 14 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 15 | # function maps arch names to npm arch names |
| 16 | def 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 24 | NPM_ARCH ?= "${@npm_oe_arch_map(d.getVar('TARGET_ARCH'), d)}" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 25 | NPM_INSTALL_DEV ?= "0" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 26 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 27 | npm_do_compile() { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 28 | # Copy in any additionally fetched modules |
| 29 | if [ -d ${WORKDIR}/node_modules ] ; then |
| 30 | cp -a ${WORKDIR}/node_modules ${S}/ |
| 31 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 32 | # changing the home directory to the working directory, the .npmrc will |
| 33 | # be created in this directory |
| 34 | export HOME=${WORKDIR} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 35 | if [ "${NPM_INSTALL_DEV}" = "1" ]; then |
| 36 | npm config set dev true |
| 37 | else |
| 38 | npm config set dev false |
| 39 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 40 | npm set cache ${WORKDIR}/npm_cache |
| 41 | # clear cache before every build |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 42 | npm cache clear --force |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 43 | # Install pkg into ${S} without going to the registry |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 44 | 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | npm_do_install() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 52 | # changing the home directory to the working directory, the .npmrc will |
| 53 | # be created in this directory |
| 54 | export HOME=${WORKDIR} |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 55 | mkdir -p ${D}${libdir}/node_modules |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 56 | npm pack . |
| 57 | npm install --prefix ${D}${prefix} -g --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --production --no-registry ${NPMPN}-${PV}.tgz |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 58 | mv ${D}${libdir}/node_modules ${D}${libdir}/node |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 59 | if [ -d ${D}${prefix}/etc ] ; then |
| 60 | # This will be empty |
| 61 | rmdir ${D}${prefix}/etc |
| 62 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | python populate_packages_prepend () { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 66 | instdir = d.expand('${D}${NPM_INSTALLDIR}') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 67 | 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 Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 72 | pkgpath = '${NPM_INSTALLDIR}/' + pkgrelpath |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 73 | # 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 80 | d.setVar('PKGV_%s' % expanded_pkgname, version) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 81 | description = pdata.get('description', None) |
| 82 | if description: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 83 | d.setVar('SUMMARY_%s' % expanded_pkgname, description.replace(u"\u2018", "'").replace(u"\u2019", "'")) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 84 | d.appendVar('RDEPENDS_%s' % d.getVar('PN'), ' %s' % ' '.join(pkgnames).replace('_', '-')) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | FILES_${PN} += " \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 88 | ${NPM_INSTALLDIR} \ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 89 | " |
| 90 | |
| 91 | EXPORT_FUNCTIONS do_compile do_install |