Build and Test

Version added 07-Mar-2018| Modified 12-Apr-2018

After developing the JS service, you must build and verify its functionality.

 

Add Recipe File

webOS OSE uses OpenEmbedded of Yocto project to build its components. You must write a recipe that configures the build environment. For more details about the recipe, see Yocto project reference manual.

  • Create and update the file : <js-service-name>.bb

  • Directory : build-webos/meta-webosose/meta-webos/recipes-webos/<js-service-name>

where <js-service-name> is the name of the JS service. For the sample JS service, <js-service-name> must be replaced by 'com.example.service.js'.

SUMMARY = "JS Service Sample"
AUTHOR = "Author's name <Author's e-mail>"
LICENSE = "Apache-2.0"
LIC_FILES_CHKSUM = "file://${COMMON_LICENSE_DIR}/Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10"
 
WEBOS_VERSION = "0.0.1"
PR = "r0"
 
inherit webos_component
inherit webos_submissions
inherit webos_cmake
inherit webos_system_bus
 
FILES_${PN} += "${webos_servicesdir}/${PN}/*"

A brief explanation of the above file:

  • Lines(1~4) : Basic descriptions of the component.

  • Line(6) : Version of the component. For the webOS OSE component, this field is mandatory.

  • Line(7) : Revision version of the recipe. Each recipe requires a counter to track its modification history. Make sure that you increment the version when you edit the recipe, unless you only change the value of the WEBOS_VERSION field or comments.

  • Line(9) : Inherits common functions of webOS OSE. For all components of webOS OSE, this entry is required.

  • Line(10) : Inherits the WEBOS_VERSION value. If you develop your component on a local repository, this entry is required.

  • Line(11) : Instructs OpenEmbedded that the component uses CMake for configuration, which is the preferred choice for webOS components.

  • Line(12) : To register component as service and install LS2 configuration files.

  • Line(14) : Appends the list of files and directories that are placed in a package. Add /usr/palm/service/com.example.service.js directory subfiles for packaging.

 

Configure Local Source Directory

To build a component that is located on the local system, you must specify the directory information.

  • Update the file : webos-local.conf

  • Directory : build-webos

For the sample JS service (com.example.service.js), you must provide the local path where the source exists.

INHERIT += "externalsrc"
EXTERNALSRC_pn-com.example.service.js = "/home/username/project/com.example.service.js/"
EXTERNALSRC_BUILD_pn-com.example.service.js = "/home/username/project/com.example.service.js/build/"
PR_append_pn-com.example.service.js =".local0"

A brief explanation of the above file:

  • Line(1) : Inherit externalsrc bbclass file.

  • Line(2) : The local source directory. The syntax of the property is EXTERNALSRC_pn-<component>. We recommend that you add trailing slash (/) at the end of local directory paths.

  • Line(3) : The local build directory. The syntax of the property is EXTERNALSRC_BUILD_pn-<component>. 

  • Line(4) : The appended revision version (PR) for building local source files. The syntax of the property is PR_append_pn-<component>. This property is optional.

 

Build, Run, and Verify

 

  1. Build the JS service.

    To build the component on the OpenEmbedded environment, enter the following commands on the shell.

    build-webos$ source oe-init-build-env
    build-webos$ bitbake com.example.service.js

    For more information, see Building webOS OSE.

     

  2. Copy the IPK to target.

    When the build is successful, oe-related directories are created under the root directory. These directories are linked to the directory where the build output is generated from the actual build-webos sub-directory.

    com.example.service.js$
    ├── CMakeLists.txt
    ├── README.md
    ├── files
    │   └── sysbus
    │       ├── com.example.service.js.api.json
    │       ├── com.example.service.js.perm.json
    │       ├── com.example.service.js.role.json.in
    │       └── com.example.service.js.service.in
    ├── com_example_service_js.js
    ├── package.json
    ├── oe-logs -> /home/username/build/build-webos/BUILD/work/raspberrypi3-webos-linux/com.example.service.js/0.0.1-r0.local0/temp
    ├── oe-workdir -> /home/username/build/build-webos/BUILD/work/raspberrypi3-webos-linux/com.example.service.js/0.0.1-r0.local0

    If you go to oe-workdir/deploy-ipks/raspberrypi3, you can see that com.example.service.js_0.0.1-r0.local0_raspberrypi3.ipk file.

    com.example.service.js/oe-workdir/deploy-ipks/raspberrypi3
    └── com.example.service.js_0.0.1-r0.local0_raspberrypi3.ipk

    Copy the IPK file to target using the 'scp' command.

    com.example.service.js/oe-workdir/deploy-ipks/raspberrypi3$ scp com.example.service.js_0.0.1-r0.local0_raspberrypi3.ipk root@192.168.0.12:/media/internal/downloads

     

  3. Install the IPK (file: com.example.service.js_0.0.1-r0.local0_raspberrypi3.ipk) on the target, by connecting to the target with SSH.

    $ ssh root@192.168.0.12
    root@raspberrypi3:~# cd /media/internal/downloads/
    root@raspberrypi3:/media/internal/downloads# opkg install com.example.service.js_0.0.1-r0.local0_raspberrypi3.ipk
    
    Installing com.example.service.js (0.0.1) on root.
    Configuring com.example.service.js.	 

     

  4. Discover LS2 configuration files.

    In order to make LS2 scan the LS configuration files (service, role, permission) of com.example.service.js, enter the ls-control scan command or reboot the target.

    root@raspberrypi3:/media/internal/downloads# ls-control scan-services
    
    telling hub to reload setting and rescan all directories

     

  5. Run the service. Since it is a dynamic service, it is executed when its method is called 

    Calling the "hello" method:

    root@raspberrypi3:/# luna-send -n 1 -f luna://com.example.service.js/hello '{}'
    {
        "answer": "Hello, JS Service!!",
        "returnValue": true
    }
    

    Calling the "locale" method:

    root@raspberrypi3:/# luna-send -n 1 -f luna://com.example.service.js/locale '{}'
    {
        "message": "You appear to have your locale set to: en-US",
        "returnValue": true
    }

     

  6. Verify the execution of the service.

    If you check ls-monitor immediately after calling the com.example.service.js/hello method, you can see that the service is executed dynamically.

    root@raspberrypi3:/# ls-monitor -l | grep example
    868           com.example.service.js            /usr/bin/node                          dynamic                 K4Nuvsrx
    

    If the service is not used for 5 seconds, it is terminated. Run the ls-monitor command again after about 5 seconds, and you will see that the service has been terminated.

    root@raspberrypi3:/# ls-monitor -l | grep example
    
Except as noted, this content is licensed under Creative Commons Attribution 4.0 and sample code is licensed under Apache License 2.0.