From 6999236de59ef0d40d03e129fbf5d3491a9f7b01 Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Wed, 11 May 2022 07:41:36 +0200 Subject: [PATCH] [Tizen] Create TPK package file as a flashbundle (#18197) --- .../lighting-app/linux/tizen-manifest.xml | 7 ++ scripts/build/builders/tizen.py | 74 +++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 examples/lighting-app/linux/tizen-manifest.xml diff --git a/examples/lighting-app/linux/tizen-manifest.xml b/examples/lighting-app/linux/tizen-manifest.xml new file mode 100644 index 00000000000000..5e0b1a623cea26 --- /dev/null +++ b/examples/lighting-app/linux/tizen-manifest.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/scripts/build/builders/tizen.py b/scripts/build/builders/tizen.py index 8ca2847d9295ea..60d29d0fafbf2b 100644 --- a/scripts/build/builders/tizen.py +++ b/scripts/build/builders/tizen.py @@ -13,7 +13,9 @@ # limitations under the License. import os +import shutil from enum import Enum, auto +from xml.etree import ElementTree as ET from .gn import GnBuilder @@ -33,6 +35,18 @@ def AppName(self): else: raise Exception('Unknown app type: %r' % self) + def PackageName(self): + return self.manifest.get('package') + + def PackageVersion(self): + return self.manifest.get('version') + + def PackageExecName(self): + return self.manifest.find('{*}service-application').get('exec') + + def parse_manifest(self, manifest: str): + self.manifest = ET.parse(manifest).getroot() + class TizenBoard(Enum): ARM = auto() @@ -64,6 +78,16 @@ def __init__(self, self.board = board self.extra_gn_options = [] + try: + # Try to load Tizen application XML manifest. We have to use + # try/except here, because of TestBuilder test. This test runs + # in a fake build root /TEST/BUILD/ROOT which obviously does + # not have Tizen manifest file. + self.app.parse_manifest( + os.path.join(self.root, "tizen-manifest.xml")) + except FileNotFoundError: + pass + if not enable_ble: self.extra_gn_options.append('chip_config_network_layer_ble=false') if not enable_wifi: @@ -87,6 +111,50 @@ def GnBuildArgs(self): 'sysroot="%s"' % os.environ['TIZEN_SDK_SYSROOT'], ] + def _generate_flashbundle(self): + + self.tizen_tpk_dir = os.path.join(self.output_dir, "tpk") + self.tizen_out_dir = os.path.join(self.tizen_tpk_dir, "out") + + # Create dirrectory where the TPK package file will be created + os.makedirs(self.tizen_out_dir, exist_ok=True) + + # Create a dummy project definition file, so the Tizen Studio CLI + # will recognize given directory as a Tizen project. + prj_def_file = os.path.join(self.tizen_tpk_dir, "project_def.prop") + with open(prj_def_file, "w") as f: + f.writelines(l + "\n" for l in [ + "# Generated by the build script. DO NOT EDIT!", + "APPNAME = %s" % self.app.AppName(), + "type = app", + ]) + + # Create a dummy project file, so the Tizen Studio CLI will not + # complain about invalid XPath (this file is not used anyway...) + prj_file = os.path.join(self.tizen_tpk_dir, ".project") + with open(prj_file, "w") as f: + f.writelines(l + "\n" for l in [ + "", + "", + ]) + + # Copy Tizen manifest file into the dummy Tizen project. + shutil.copy( + os.path.join(self.root, "tizen-manifest.xml"), + self.tizen_tpk_dir) + + # Create link with the application executable in the TPK package + # directory. This linked file will be used by the Tizen Studio CLI + # when creating TPK package. + exec = os.path.join(self.tizen_out_dir, self.app.PackageExecName()) + if not os.path.exists(exec): + os.symlink(os.path.join(self.output_dir, self.app.AppName()), + exec) + + self._Execute([self.tizen_sdk_cli, 'package', '--type', 'tpk', + '--sign', 'CHIP', '--', self.tizen_out_dir], + title='Generating TPK file for ' + self.identifier) + def build_outputs(self): return { '%s' % self.app.AppName(): @@ -94,3 +162,9 @@ def build_outputs(self): '%s.map' % self.app.AppName(): os.path.join(self.output_dir, '%s.map' % self.app.AppName()), } + + def flashbundle(self): + tpk = f'{self.app.PackageName()}-{self.app.PackageVersion()}.tpk' + return { + tpk: os.path.join(self.tizen_out_dir, tpk), + }