How it works...

The preceding code will install the Node.js package into your image. However, most times we only need to add our Node.js application and add Node.js as a dependency.

We can add simple Node.js scripts, as we explained in Adding data, scripts or configuration files, in Chapter 3, The Software Layer, with a recipe that just installs the JavaScript scripts in the root filesystem.

However, Node.js applications are usually built on modules, each one of them with its own license. We could create a Yocto recipe that uses the npm tool to install dependencies, but we would also need to manually trace all their different licenses.

The devtool command-line utility can do this for us automatically either installing from the npm registry or from a Git repository. For example, to install the nodejs-helloworld package we can do the following:

$ devtool add "npm://registry.npmjs.org;name=nodejs-helloworld;version=1.0.1"

Here, both the name and version are mandatory. The devtool command-line tool creates a skeleton recipe for us that looks as follows:

SUMMARY = "An example node.js hello world server"                                        
LICENSE = "MIT"                                                                  
LIC_FILES_CHKSUM = "file://LICENSE;md5=2459e4101d5fabab9d291bde6cdc5a56"         
 
SRC_URI = "npm://registry.npmjs.org;name=nodejs-helloworld;version=${PV}"
NPM_SHRINKWRAP := "${THISDIR}/${PN}/npm-shrinkwrap.json" NPM_LOCKDOWN := "${THISDIR}/${PN}/lockdown.json"
inherit npm
# Must be set after inherit npm since that itself sets S S = "${WORKDIR}/npmpkg" LICENSE_${PN} = "MIT"

As we can see in the previous code, shrinkwrap and lockdown JSON files are generated so the versions are frozen to ensure build integrity.

Alternatively, it can be generated from the Git repository:

$ devtool add https://github.com/yoctocookbook2ndedition/nodejs-helloworld.git

In this case, the devtool command-line tool creates a skeleton recipe for us that looks as follows:

SUMMARY = "An example node.js hello world server"                                
LICENSE = "MIT"                                                                  
LIC_FILES_CHKSUM = "file://LICENSE;md5=2459e4101d5fabab9d291bde6cdc5a56"         
  
SRC_URI = "git://github.com/yoctocookbook2ndedition/nodejs-helloworld.git;protocol=https"
PV = "1.0.1+git${SRCPV}" SRCREV = "41c359a25365880ef880c10c2d405314439d6666"
NPM_SHRINKWRAP := "${THISDIR}/${PN}/npm-shrinkwrap.json" NPM_LOCKDOWN := "${THISDIR}/${PN}/lockdown.json"
inherit npm
# Must be set after inherit npm since that itself sets S S = "${WORKDIR}/git" LICENSE_${PN} = "MIT"

It would also have listed all license dependencies, if there were any, and added all the module dependencies as different packages under the same recipe.

We can now follow the usual devtool workflow as explained in the Using the extensible SDK section, to build, test, and integrate them into our final images.

The package can then be added to our target image by adding the following to either its recipe or conf/local.conf:

IMAGE_INSTALL_append = " nodejs-helloworld" 
Note that the meta-openembedded Yocto 2.4 Rocko branch has been updated to Node.js 8.4.0. Unfortunately, this newer version does not work well with the npm class and devtool command-line utility in Poky. The previous 4.8.3 Node.js version from meta-openembedded was working correctly. However, even when using 4.8.3, there are open issues like the following:
https://bugzilla.yoctoproject.org/show_bug.cgi?id=11728
Until this is fixed in the Yocto 2.4 Rocko branch, the following revert in Poky will leave a working revision:
git revert ebe531b38bea54bd29ed7b3d2ea6c533b9331953
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset