Skip to content

Commit

Permalink
Add possibility to build Tizen apps with various options (project-chi…
Browse files Browse the repository at this point in the history
…p#16701)

* [build] Fix warnings reported by flake8 checker

* [build] Allow to build Tizen apps with variants

This change adds a possibility to build Tizen applications with e.g.
ASAN sanitizer enabled. Please note, that with current Tizen SDK there
is no TSAN library (TSAN for ARMv7) provided, so it's not possible to
enable this sanitizer.

* Restyled by autopep8

Co-authored-by: Justin Wood <[email protected]>
Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
3 people authored and chencheung committed Apr 6, 2022
1 parent 3f7a3b5 commit 203e4fb
Show file tree
Hide file tree
Showing 21 changed files with 222 additions and 108 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
max-line-length = 132
14 changes: 7 additions & 7 deletions scripts/build/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ followed by platform-specific instructions.
The file BUILDING.md describes general requirements and examples. Typical usage
is:

```
```sh
source scripts/activate
gn gen out/host
ninja -C out/host
Expand All @@ -34,37 +34,37 @@ Usage examples:

1. Compiles all targets

```
```sh
./scripts/build/build_examples.py --target all build
```

2. Compile the all clusters app for a ESP32 DevKitC

```
```sh
./scripts/build/build_examples.py --target esp32-devkitc-all-clusters build
```

3. Generate all the makefiles (but do not compile) using a specific output root

```
```sh
./scripts/build/build_examples.py --target linux-x64-chip-tool --out-prefix ./mydir gen
```

4. Compile the qpg lock app and copy the output in a 'artifact' folder. Note the
argument order (artifact copying is an argument for the build command)

```
```sh
./scripts/build/build_examples.py --target qpg-lock build --copy-artifacts-to /tmp/artifacts
```

5. Find out all possible targets for compiling the 'light' app:

```
```sh
./scripts/build/build_examples.py --target-glob '*light' --log-level fatal targets
```

6. Compile everything except linux or darwin:

```
```sh
./scripts/build/build_examples.py --skip-target-glob '{darwin,linux}-*' --log-level fatal build
```
19 changes: 13 additions & 6 deletions scripts/build/build/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import logging
import os
import shutil

from enum import Enum, auto
from typing import Sequence

from .targets import Target, ALL
from .targets import ALL, Target

ALL_TARGETS = ALL

Expand All @@ -27,19 +26,27 @@ def __init__(self, runner, repository_path: str, output_prefix: str):
self.output_prefix = output_prefix
self.completed_steps = set()

def SetupBuilders(self, targets: Sequence[Target], enable_flashbundle: bool):
"""Configures internal builders for the given platform/board/app combination. """
def SetupBuilders(self, targets: Sequence[Target],
enable_flashbundle: bool):
"""
Configures internal builders for the given platform/board/app
combination.
"""

self.builders = []
for target in targets:
self.builders.append(target.Create(
self.runner, self.repository_path, self.output_prefix, enable_flashbundle))
self.runner, self.repository_path, self.output_prefix,
enable_flashbundle))

# whenever builders change, assume generation is required again
self.completed_steps.discard(BuildSteps.GENERATED)

def Generate(self):
"""Performs a build generation IFF code generation has not yet been performed."""
"""
Performs a build generation IF code generation has not yet been
performed.
"""
if BuildSteps.GENERATED in self.completed_steps:
return

Expand Down
117 changes: 77 additions & 40 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,19 @@
# limitations under the License.

import os

from typing import Any, List
from itertools import combinations
from typing import List

from builders.ameba import AmebaApp, AmebaBoard, AmebaBuilder
from builders.android import AndroidBoard, AndroidApp, AndroidBuilder
from builders.android import AndroidApp, AndroidBoard, AndroidBuilder
from builders.cc13x2x7_26x2x7 import cc13x2x7_26x2x7App, cc13x2x7_26x2x7Builder
from builders.cyw30739 import Cyw30739Builder, Cyw30739App, Cyw30739Board
from builders.efr32 import Efr32Builder, Efr32App, Efr32Board
from builders.esp32 import Esp32Builder, Esp32Board, Esp32App
from builders.host import HostBuilder, HostApp, HostBoard
from builders.infineon import InfineonBuilder, InfineonApp, InfineonBoard
from builders.cyw30739 import Cyw30739App, Cyw30739Board, Cyw30739Builder
from builders.efr32 import Efr32App, Efr32Board, Efr32Builder
from builders.esp32 import Esp32App, Esp32Board, Esp32Builder
from builders.host import HostApp, HostBoard, HostBuilder
from builders.infineon import InfineonApp, InfineonBoard, InfineonBuilder
from builders.k32w import K32WApp, K32WBuilder
from builders.mbed import MbedApp, MbedBoard, MbedProfile, MbedBuilder
from builders.mbed import MbedApp, MbedBoard, MbedBuilder, MbedProfile
from builders.nrf import NrfApp, NrfBoard, NrfConnectBuilder
from builders.qpg import QpgApp, QpgBoard, QpgBuilder
from builders.telink import TelinkApp, TelinkBoard, TelinkBuilder
Expand Down Expand Up @@ -68,7 +67,8 @@ def Extend(self, suffix, **kargs):
clone.create_kw_args.update(kargs)
return clone

def Create(self, runner, repository_path: str, output_prefix: str, enable_flashbundle: bool):
def Create(self, runner, repository_path: str, output_prefix: str,
enable_flashbundle: bool):
builder = self.builder_class(
repository_path, runner=runner, **self.create_kw_args)

Expand Down Expand Up @@ -115,7 +115,9 @@ def Accept(self, name: str):


class BuildVariant:
def __init__(self, name: str, validator=AcceptAnyName(), conflicts: List[str] = [], requires: List[str] = [], **buildargs):
def __init__(self, name: str, validator=AcceptAnyName(),
conflicts: List[str] = [], requires: List[str] = [],
**buildargs):
self.name = name
self.validator = validator
self.conflicts = conflicts
Expand All @@ -138,7 +140,7 @@ def AllRequirementsMet(items: List[BuildVariant]) -> bool:

for item in items:
for requirement in item.requires:
if not requirement in available:
if requirement not in available:
return False

return True
Expand Down Expand Up @@ -178,8 +180,8 @@ def AllVariants(self):
"""
Yields a list of acceptable variants for the given targets.
Handles conflict resolution between build variants and globbing whiltelist
targets.
Handles conflict resolution between build variants and globbing
whitelist targets.
"""
for target in self.targets:
yield target
Expand All @@ -204,8 +206,9 @@ def AllVariants(self):
option.name, **option.buildargs)

# Only a few are whitelisted for globs
if '-'.join([o.name for o in subgroup]) not in self.glob_whitelist:
if not variant_target.glob_blacklist_reason:
name = '-'.join([o.name for o in subgroup])
if name not in self.glob_whitelist:
if not variant_target.IsGlobBlacklisted:
variant_target = variant_target.GlobBlacklist(
'Reduce default build variants')

Expand All @@ -214,9 +217,9 @@ def AllVariants(self):

def HostTargets():
target = Target(HostBoard.NATIVE.PlatformName(), HostBuilder)
targets = [
target.Extend(HostBoard.NATIVE.BoardName(), board=HostBoard.NATIVE)
]
target_native = target.Extend(HostBoard.NATIVE.BoardName(), board=HostBoard.NATIVE)

targets = [target_native]

# x64 linux supports cross compile
if (HostBoard.NATIVE.PlatformName() == 'linux') and (
Expand All @@ -227,9 +230,9 @@ def HostTargets():

# Don't cross compile some builds
app_targets.append(
targets[0].Extend('rpc-console', app=HostApp.RPC_CONSOLE))
target_native.Extend('rpc-console', app=HostApp.RPC_CONSOLE))
app_targets.append(
targets[0].Extend('tv-app', app=HostApp.TV_APP))
target_native.Extend('tv-app', app=HostApp.TV_APP))

for target in targets:
app_targets.append(target.Extend(
Expand Down Expand Up @@ -276,11 +279,14 @@ def HostTargets():
yield target

# Without extra build variants
yield targets[0].Extend('chip-cert', app=HostApp.CERT_TOOL)
yield targets[0].Extend('address-resolve-tool', app=HostApp.ADDRESS_RESOLVE)
yield targets[0].Extend('address-resolve-tool-clang', app=HostApp.ADDRESS_RESOLVE, use_clang=True).GlobBlacklist("Reduce default build variants")
yield targets[0].Extend('address-resolve-tool-platform-mdns', app=HostApp.ADDRESS_RESOLVE, use_platform_mdns=True).GlobBlacklist("Reduce default build variants")
yield targets[0].Extend('address-resolve-tool-platform-mdns-ipv6only', app=HostApp.ADDRESS_RESOLVE, use_platform_mdns=True, enable_ipv4=False).GlobBlacklist("Reduce default build variants")
yield target_native.Extend('chip-cert', app=HostApp.CERT_TOOL)
yield target_native.Extend('address-resolve-tool', app=HostApp.ADDRESS_RESOLVE)
yield target_native.Extend('address-resolve-tool-clang', app=HostApp.ADDRESS_RESOLVE,
use_clang=True).GlobBlacklist("Reduce default build variants")
yield target_native.Extend('address-resolve-tool-platform-mdns', app=HostApp.ADDRESS_RESOLVE,
use_platform_mdns=True).GlobBlacklist("Reduce default build variants")
yield target_native.Extend('address-resolve-tool-platform-mdns-ipv6only', app=HostApp.ADDRESS_RESOLVE,
use_platform_mdns=True, enable_ipv4=False).GlobBlacklist("Reduce default build variants")

test_target = Target(HostBoard.NATIVE.PlatformName(), HostBuilder)
for board in [HostBoard.NATIVE, HostBoard.FAKE]:
Expand All @@ -291,9 +297,12 @@ def Esp32Targets():
esp32_target = Target('esp32', Esp32Builder)

yield esp32_target.Extend('m5stack-all-clusters', board=Esp32Board.M5Stack, app=Esp32App.ALL_CLUSTERS)
yield esp32_target.Extend('m5stack-all-clusters-ipv6only', board=Esp32Board.M5Stack, app=Esp32App.ALL_CLUSTERS, enable_ipv4=False)
yield esp32_target.Extend('m5stack-all-clusters-rpc', board=Esp32Board.M5Stack, app=Esp32App.ALL_CLUSTERS, enable_rpcs=True)
yield esp32_target.Extend('m5stack-all-clusters-rpc-ipv6only', board=Esp32Board.M5Stack, app=Esp32App.ALL_CLUSTERS, enable_rpcs=True, enable_ipv4=False)
yield esp32_target.Extend('m5stack-all-clusters-ipv6only', board=Esp32Board.M5Stack, app=Esp32App.ALL_CLUSTERS,
enable_ipv4=False)
yield esp32_target.Extend('m5stack-all-clusters-rpc', board=Esp32Board.M5Stack, app=Esp32App.ALL_CLUSTERS,
enable_rpcs=True)
yield esp32_target.Extend('m5stack-all-clusters-rpc-ipv6only', board=Esp32Board.M5Stack, app=Esp32App.ALL_CLUSTERS,
enable_rpcs=True, enable_ipv4=False)

yield esp32_target.Extend('c3devkit-all-clusters', board=Esp32Board.C3DevKit, app=Esp32App.ALL_CLUSTERS)

Expand Down Expand Up @@ -381,7 +390,8 @@ def NrfTargets():

if '-nrf5340dk-' in rpc.name:
rpc = rpc.GlobBlacklist(
'Compile failure due to pw_build args not forwarded to proto compiler. https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/66760')
'Compile failure due to pw_build args not forwarded to proto compiler. '
'https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/66760')

yield rpc

Expand Down Expand Up @@ -423,8 +433,12 @@ def MbedTargets():

for target in app_targets:
yield target.Extend('release', profile=MbedProfile.RELEASE)
yield target.Extend('develop', profile=MbedProfile.DEVELOP).GlobBlacklist('Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html')
yield target.Extend('debug', profile=MbedProfile.DEBUG).GlobBlacklist('Compile only for debugging purpose - https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html')
yield target.Extend('develop', profile=MbedProfile.DEVELOP).GlobBlacklist(
'Compile only for debugging purpose - '
'https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html')
yield target.Extend('debug', profile=MbedProfile.DEBUG).GlobBlacklist(
'Compile only for debugging purpose - '
'https://os.mbed.com/docs/mbed-os/latest/program-setup/build-profiles-and-rules.html')


def InfineonTargets():
Expand Down Expand Up @@ -453,10 +467,12 @@ def K32WTargets():
yield target.Extend('light', app=K32WApp.LIGHT).GlobBlacklist("Debug builds broken due to LWIP_DEBUG redefition")

yield target.Extend('light-release', app=K32WApp.LIGHT, release=True)
yield target.Extend('light-tokenizer-release', app=K32WApp.LIGHT, tokenizer=True, release=True).GlobBlacklist("Only on demand build")
yield target.Extend('light-tokenizer-release', app=K32WApp.LIGHT,
tokenizer=True, release=True).GlobBlacklist("Only on demand build")
yield target.Extend('shell-release', app=K32WApp.SHELL, release=True)
yield target.Extend('lock-release', app=K32WApp.LOCK, release=True)
yield target.Extend('lock-low-power-release', app=K32WApp.LOCK, low_power=True, release=True).GlobBlacklist("Only on demand build")
yield target.Extend('lock-low-power-release', app=K32WApp.LOCK,
low_power=True, release=True).GlobBlacklist("Only on demand build")


def cc13x2x7_26x2x7Targets():
Expand All @@ -469,10 +485,15 @@ def cc13x2x7_26x2x7Targets():


def Cyw30739Targets():
yield Target('cyw30739-cyw930739m2evb_01-light', Cyw30739Builder, board=Cyw30739Board.CYW930739M2EVB_01, app=Cyw30739App.LIGHT)
yield Target('cyw30739-cyw930739m2evb_01-lock', Cyw30739Builder, board=Cyw30739Board.CYW930739M2EVB_01, app=Cyw30739App.LOCK)
yield Target('cyw30739-cyw930739m2evb_01-ota-requestor', Cyw30739Builder, board=Cyw30739Board.CYW930739M2EVB_01, app=Cyw30739App.OTA_REQUESTOR).GlobBlacklist("Running out of XIP flash space")
yield Target('cyw30739-cyw930739m2evb_01-ota-requestor-no-progress-logging', Cyw30739Builder, board=Cyw30739Board.CYW930739M2EVB_01, app=Cyw30739App.OTA_REQUESTOR, progress_logging=False)
yield Target('cyw30739-cyw930739m2evb_01-light', Cyw30739Builder,
board=Cyw30739Board.CYW930739M2EVB_01, app=Cyw30739App.LIGHT)
yield Target('cyw30739-cyw930739m2evb_01-lock', Cyw30739Builder,
board=Cyw30739Board.CYW930739M2EVB_01, app=Cyw30739App.LOCK)
yield Target('cyw30739-cyw930739m2evb_01-ota-requestor', Cyw30739Builder,
board=Cyw30739Board.CYW930739M2EVB_01, app=Cyw30739App.OTA_REQUESTOR).GlobBlacklist(
"Running out of XIP flash space")
yield Target('cyw30739-cyw930739m2evb_01-ota-requestor-no-progress-logging', Cyw30739Builder,
board=Cyw30739Board.CYW930739M2EVB_01, app=Cyw30739App.OTA_REQUESTOR, progress_logging=False)


def QorvoTargets():
Expand All @@ -484,6 +505,23 @@ def QorvoTargets():
yield target.Extend('persistent-storage', board=QpgBoard.QPG6105, app=QpgApp.PERSISTENT_STORAGE)


def TizenTargets():

# Possible build variants.
# NOTE: The number of potential builds is exponential here.
builder = VariantBuilder()
builder.AppendVariant(name="no-ble", enable_ble=False)
builder.AppendVariant(name="no-wifi", enable_wifi=False)
builder.AppendVariant(name="asan", use_asan=True)

target = Target('tizen-arm', TizenBuilder, board=TizenBoard.ARM)

builder.targets.append(target.Extend('light', app=TizenApp.LIGHT))

for target in builder.AllVariants():
yield target


def Bl602Targets():
target = Target('bl602', Bl602Builder)

Expand All @@ -505,6 +543,7 @@ def Bl602Targets():
cc13x2x7_26x2x7Targets(),
Cyw30739Targets(),
QorvoTargets(),
TizenTargets(),
Bl602Targets(),
]

Expand All @@ -515,8 +554,6 @@ def Bl602Targets():
# Simple targets added one by one
ALL.append(Target('telink-tlsr9518adk80d-light', TelinkBuilder,
board=TelinkBoard.TLSR9518ADK80D, app=TelinkApp.LIGHT))
ALL.append(Target('tizen-arm-light', TizenBuilder,
board=TizenBoard.ARM, app=TizenApp.LIGHT))

# have a consistent order overall
ALL.sort(key=lambda t: t.name)
Loading

0 comments on commit 203e4fb

Please sign in to comment.