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 | |
| 13 | NPM_INSTALLDIR = "${D}${libdir}/node_modules/${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)}" |
| 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} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 55 | mkdir -p ${NPM_INSTALLDIR}/ |
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 | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 58 | if [ -d ${D}${prefix}/etc ] ; then |
| 59 | # This will be empty |
| 60 | rmdir ${D}${prefix}/etc |
| 61 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | python populate_packages_prepend () { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 65 | instdir = d.expand('${D}${libdir}/node_modules/${NPMPN}') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 66 | 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 Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 71 | pkgpath = '${libdir}/node_modules/${NPMPN}/' + pkgrelpath |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 72 | # 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 79 | d.setVar('PKGV_%s' % expanded_pkgname, version) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 80 | description = pdata.get('description', None) |
| 81 | if description: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 82 | 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] | 83 | d.appendVar('RDEPENDS_%s' % d.getVar('PN'), ' %s' % ' '.join(pkgnames).replace('_', '-')) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | FILES_${PN} += " \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 87 | ${libdir}/node_modules/${NPMPN} \ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 88 | " |
| 89 | |
| 90 | EXPORT_FUNCTIONS do_compile do_install |