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 | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 13 | NPM_INSTALLDIR = "${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)}" |
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 | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 56 | local NPM_PACKFILE=$(npm pack .) |
| 57 | npm install --prefix ${D}${prefix} -g --arch=${NPM_ARCH} --target_arch=${NPM_ARCH} --production --no-registry ${NPM_PACKFILE} |
| 58 | ln -fs node_modules ${D}${libdir}/node |
| 59 | find ${D}${NPM_INSTALLDIR} -type f \( -name "*.a" -o -name "*.d" -o -name "*.o" \) -delete |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 60 | if [ -d ${D}${prefix}/etc ] ; then |
| 61 | # This will be empty |
| 62 | rmdir ${D}${prefix}/etc |
| 63 | fi |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | python populate_packages_prepend () { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 67 | instdir = d.expand('${D}${NPM_INSTALLDIR}') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 68 | extrapackages = oe.package.npm_split_package_dirs(instdir) |
| 69 | pkgnames = extrapackages.keys() |
| 70 | d.prependVar('PACKAGES', '%s ' % ' '.join(pkgnames)) |
| 71 | for pkgname in pkgnames: |
| 72 | pkgrelpath, pdata = extrapackages[pkgname] |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 73 | pkgpath = '${NPM_INSTALLDIR}/' + pkgrelpath |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 74 | # package names can't have underscores but npm packages sometimes use them |
| 75 | oe_pkg_name = pkgname.replace('_', '-') |
| 76 | expanded_pkgname = d.expand(oe_pkg_name) |
| 77 | d.setVar('FILES_%s' % expanded_pkgname, pkgpath) |
| 78 | if pdata: |
| 79 | version = pdata.get('version', None) |
| 80 | if version: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 81 | d.setVar('PKGV_%s' % expanded_pkgname, version) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 82 | description = pdata.get('description', None) |
| 83 | if description: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 84 | 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] | 85 | d.appendVar('RDEPENDS_%s' % d.getVar('PN'), ' %s' % ' '.join(pkgnames).replace('_', '-')) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | FILES_${PN} += " \ |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 89 | ${bindir} \ |
| 90 | ${libdir}/node \ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 91 | ${NPM_INSTALLDIR} \ |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 92 | " |
| 93 | |
| 94 | EXPORT_FUNCTIONS do_compile do_install |