Skip to content

Commit

Permalink
[Tizen] Create TPK package file as a flashbundle (#18197)
Browse files Browse the repository at this point in the history
  • Loading branch information
arkq authored and pull[bot] committed Aug 16, 2023
1 parent 28197a6 commit 1330957
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
7 changes: 7 additions & 0 deletions examples/lighting-app/linux/tizen-manifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns="http://tizen.org/ns/packages" api-version="6.0" package="org.tizen.matter.example.lighting" version="1.0.0">
<profile name="mobile" />
<service-application appid="org.tizen.matter.example.lighting" exec="chip-lighting-app" type="capp" multiple="false" taskmanage="false" nodisplay="true">
<label>Matter Lighting Example</label>
</service-application>
</manifest>
74 changes: 74 additions & 0 deletions scripts/build/builders/tizen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand All @@ -87,10 +111,60 @@ 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 [
"<!-- Generated by the build script. DO NOT EDIT! -->",
"<projectDescription></projectDescription>",
])

# 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():
os.path.join(self.output_dir, self.app.AppName()),
'%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),
}

0 comments on commit 1330957

Please sign in to comment.