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 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 16 | NPM_ARCH ?= "${@npm_oe_arch_map(d.getVar('TARGET_ARCH'), d)}" |
| 17 | NPM_INSTALL_DEV = "0" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 18 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 19 | npm_do_compile() { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 20 | # Copy in any additionally fetched modules |
| 21 | if [ -d ${WORKDIR}/node_modules ] ; then |
| 22 | cp -a ${WORKDIR}/node_modules ${S}/ |
| 23 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 24 | # changing the home directory to the working directory, the .npmrc will |
| 25 | # be created in this directory |
| 26 | export HOME=${WORKDIR} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 27 | if [ "${NPM_INSTALL_DEV}" = "1" ]; then |
| 28 | npm config set dev true |
| 29 | else |
| 30 | npm config set dev false |
| 31 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 32 | npm set cache ${WORKDIR}/npm_cache |
| 33 | # clear cache before every build |
| 34 | npm cache clear |
| 35 | # Install pkg into ${S} without going to the registry |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 36 | if [ "${NPM_INSTALL_DEV}" = "1" ]; then |
| 37 | npm --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --no-registry install |
| 38 | else |
| 39 | npm --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --production --no-registry install |
| 40 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | npm_do_install() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 44 | # changing the home directory to the working directory, the .npmrc will |
| 45 | # be created in this directory |
| 46 | export HOME=${WORKDIR} |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 47 | mkdir -p ${NPM_INSTALLDIR}/ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 48 | npm install --prefix ${D}${prefix} -g --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --production --no-registry |
| 49 | if [ -d ${D}${prefix}/etc ] ; then |
| 50 | # This will be empty |
| 51 | rmdir ${D}${prefix}/etc |
| 52 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | python populate_packages_prepend () { |
| 56 | instdir = d.expand('${D}${libdir}/node_modules/${PN}') |
| 57 | extrapackages = oe.package.npm_split_package_dirs(instdir) |
| 58 | pkgnames = extrapackages.keys() |
| 59 | d.prependVar('PACKAGES', '%s ' % ' '.join(pkgnames)) |
| 60 | for pkgname in pkgnames: |
| 61 | pkgrelpath, pdata = extrapackages[pkgname] |
| 62 | pkgpath = '${libdir}/node_modules/${PN}/' + pkgrelpath |
| 63 | # package names can't have underscores but npm packages sometimes use them |
| 64 | oe_pkg_name = pkgname.replace('_', '-') |
| 65 | expanded_pkgname = d.expand(oe_pkg_name) |
| 66 | d.setVar('FILES_%s' % expanded_pkgname, pkgpath) |
| 67 | if pdata: |
| 68 | version = pdata.get('version', None) |
| 69 | if version: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 70 | d.setVar('PKGV_%s' % expanded_pkgname, version) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 71 | description = pdata.get('description', None) |
| 72 | if description: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 73 | 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] | 74 | d.appendVar('RDEPENDS_%s' % d.getVar('PN'), ' %s' % ' '.join(pkgnames).replace('_', '-')) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | FILES_${PN} += " \ |
| 78 | ${libdir}/node_modules/${PN} \ |
| 79 | " |
| 80 | |
| 81 | EXPORT_FUNCTIONS do_compile do_install |