From e7c6652dcc043f1787a0653fdb24cd4466e89d0a Mon Sep 17 00:00:00 2001 From: Arkadiusz Bokowy Date: Tue, 5 Apr 2022 05:29:47 +0200 Subject: [PATCH] Add possibility to build Tizen apps with various options (#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 Co-authored-by: Restyled.io --- .flake8 | 2 + scripts/build/README.md | 14 +-- scripts/build/build/__init__.py | 19 ++- scripts/build/build/targets.py | 117 ++++++++++++------ scripts/build/build_examples.py | 42 ++++--- scripts/build/builders/ameba.py | 1 - scripts/build/builders/android.py | 4 +- scripts/build/builders/esp32.py | 1 - scripts/build/builders/host.py | 14 ++- scripts/build/builders/k32w.py | 2 +- scripts/build/builders/mbed.py | 4 +- scripts/build/builders/nrf.py | 8 +- scripts/build/builders/telink.py | 1 - scripts/build/builders/tizen.py | 28 +++-- scripts/build/runner/__init__.py | 4 +- scripts/build/runner/shell.py | 3 +- scripts/build/setup.py | 4 + scripts/build/test.py | 9 +- scripts/build/test_glob_matcher.py | 4 +- .../testdata/all_targets_except_host.txt | 7 ++ .../build/testdata/build_all_except_host.txt | 42 +++++++ 21 files changed, 222 insertions(+), 108 deletions(-) create mode 100644 .flake8 diff --git a/.flake8 b/.flake8 new file mode 100644 index 00000000000000..28e6208b8c07ee --- /dev/null +++ b/.flake8 @@ -0,0 +1,2 @@ +[flake8] +max-line-length = 132 diff --git a/scripts/build/README.md b/scripts/build/README.md index 27a436fca0d834..d2279c18460adb 100644 --- a/scripts/build/README.md +++ b/scripts/build/README.md @@ -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 @@ -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 ``` diff --git a/scripts/build/build/__init__.py b/scripts/build/build/__init__.py index 29334fbacf4e1f..6d85fd8b12c3a3 100644 --- a/scripts/build/build/__init__.py +++ b/scripts/build/build/__init__.py @@ -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 @@ -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 diff --git a/scripts/build/build/targets.py b/scripts/build/build/targets.py index 1c0a79b72304d6..ec310f80a7b489 100644 --- a/scripts/build/build/targets.py +++ b/scripts/build/build/targets.py @@ -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 @@ -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) @@ -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 @@ -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 @@ -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 @@ -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') @@ -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 ( @@ -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( @@ -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]: @@ -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) @@ -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 @@ -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(): @@ -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(): @@ -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(): @@ -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) @@ -505,6 +543,7 @@ def Bl602Targets(): cc13x2x7_26x2x7Targets(), Cyw30739Targets(), QorvoTargets(), + TizenTargets(), Bl602Targets(), ] @@ -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) diff --git a/scripts/build/build_examples.py b/scripts/build/build_examples.py index c88194b11e8b9f..f9897a69a85589 100755 --- a/scripts/build/build_examples.py +++ b/scripts/build/build_examples.py @@ -14,16 +14,17 @@ # See the License for the specific language governing permissions and # limitations under the License. -from glob_matcher import GlobMatcher -from runner import PrintOnlyRunner, ShellRunner - -import build -import coloredlogs -import click import logging import os import sys +import click +import coloredlogs + +import build +from glob_matcher import GlobMatcher +from runner import PrintOnlyRunner, ShellRunner + sys.path.append(os.path.abspath(os.path.dirname(__file__))) @@ -42,7 +43,9 @@ def CommaSeparate(items) -> str: def ValidateRepoPath(context, parameter, value): - """Validates that the given path looks like a valid chip repository checkout.""" + """ + Validates that the given path looks like a valid chip repository checkout. + """ if value.startswith('/TEST/'): # Hackish command to allow for unit testing return value @@ -51,8 +54,8 @@ def ValidateRepoPath(context, parameter, value): expected_file = os.path.join(value, name) if not os.path.exists(expected_file): raise click.BadParameter( - "'%s' does not look like a valid repository path: %s not found." % - (value, expected_file)) + ("'%s' does not look like a valid repository path: " + "%s not found.") % (value, expected_file)) return value @@ -117,15 +120,16 @@ def ValidateRepoPath(context, parameter, value): is_flag=True, help='Skip timestaps in log output') @click.pass_context -def main(context, log_level, target, target_glob, skip_target_glob, repo, out_prefix, clean, - dry_run, dry_run_output, enable_flashbundle, no_log_timestamps): +def main(context, log_level, target, target_glob, skip_target_glob, repo, + out_prefix, clean, dry_run, dry_run_output, enable_flashbundle, + no_log_timestamps): # Ensures somewhat pretty logging of what is going on log_fmt = '%(asctime)s %(levelname)-7s %(message)s' if no_log_timestamps: log_fmt = '%(levelname)-7s %(message)s' coloredlogs.install(level=__LOG_LEVELS__[log_level], fmt=log_fmt) - if not 'PW_PROJECT_ROOT' in os.environ: + if 'PW_PROJECT_ROOT' not in os.environ: raise click.UsageError(""" PW_PROJECT_ROOT not set in the current environment. @@ -139,13 +143,15 @@ def main(context, log_level, target, target_glob, skip_target_glob, repo, out_pr runner = ShellRunner(root=repo) if 'all' in target: - # NOTE: ALL includes things that are glob blacklisted (so that 'targets' works and - # displays all) + # NOTE: The "all" target includes things that are glob blacklisted + # (so that 'targets' works and displays all) targets = build.ALL_TARGETS else: requested_targets = set([t.lower for t in target]) targets = [ - target for target in build.ALL_TARGETS if target.name.lower in requested_targets] + target for target in build.ALL_TARGETS + if target.name.lower in requested_targets + ] actual_targes = set([t.name.lower for t in targets]) if requested_targets != actual_targes: @@ -183,9 +189,11 @@ def cmd_generate(context): @main.command( - 'targets', help='List the targets that would be generated/built given the input arguments') + 'targets', + help=('List the targets that would be generated/built given ' + 'the input arguments')) @click.pass_context -def cmd_generate(context): +def cmd_targets(context): for builder in context.obj.builders: if builder.target.IsGlobBlacklisted: print("%s (NOGLOB: %s)" % diff --git a/scripts/build/builders/ameba.py b/scripts/build/builders/ameba.py index 2302a78c97e19b..a961ca71df5377 100644 --- a/scripts/build/builders/ameba.py +++ b/scripts/build/builders/ameba.py @@ -13,7 +13,6 @@ # limitations under the License. import os - from enum import Enum, auto from .builder import Builder diff --git a/scripts/build/builders/android.py b/scripts/build/builders/android.py index 72ae967dd89617..52b6317959269e 100644 --- a/scripts/build/builders/android.py +++ b/scripts/build/builders/android.py @@ -14,7 +14,6 @@ import os import shlex - from enum import Enum, auto from .builder import Builder @@ -117,7 +116,8 @@ def validate_build_environment(self): # New SDK manager at cmdline-tools/latest/bin/ new_sdk_manager = os.path.join(os.environ['ANDROID_HOME'], 'cmdline-tools', 'latest', 'bin', 'sdkmanager') - if not (os.path.isfile(sdk_manager) and os.access(sdk_manager, os.X_OK)) and not (os.path.isfile(new_sdk_manager) and os.access(new_sdk_manager, os.X_OK)): + if (not (os.path.isfile(sdk_manager) and os.access(sdk_manager, os.X_OK)) and + not (os.path.isfile(new_sdk_manager) and os.access(new_sdk_manager, os.X_OK))): raise Exception("'%s' and '%s' is not executable by the current user" % (sdk_manager, new_sdk_manager)) diff --git a/scripts/build/builders/esp32.py b/scripts/build/builders/esp32.py index 14d8aca532c1e3..8f3f43393d0f2e 100644 --- a/scripts/build/builders/esp32.py +++ b/scripts/build/builders/esp32.py @@ -15,7 +15,6 @@ import logging import os import shlex - from enum import Enum, auto from .builder import Builder diff --git a/scripts/build/builders/host.py b/scripts/build/builders/host.py index 07957aa2d36f82..8c68088f699f22 100644 --- a/scripts/build/builders/host.py +++ b/scripts/build/builders/host.py @@ -13,9 +13,8 @@ # limitations under the License. import os - -from platform import uname from enum import Enum, auto +from platform import uname from .gn import GnBuilder @@ -130,7 +129,7 @@ def BoardName(self): arch = 'x64' elif arch == 'i386' or arch == 'i686': arch = 'x86' - elif arch == 'aarch64' or arch == 'aarch64_be' or arch == 'armv8b' or arch == 'armv8l': + elif arch in ('aarch64', 'aarch64_be', 'armv8b', 'armv8l'): arch = 'arm64' return arch @@ -206,7 +205,8 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE, enable_ip if app == HostApp.CERT_TOOL: # Certification only built for openssl if self.board == HostBoard.ARM64: - # OpenSSL and MBEDTLS conflict. We only cross compile with mbedtls + # OpenSSL and mbedTLS conflicts. + # We only cross compile with mbedTLS. raise Exception( "Cannot cross compile CERT TOOL: ssl library conflict") self.extra_gn_options.append('chip_crypto="openssl"') @@ -248,13 +248,15 @@ def GnBuildEnv(self): return None elif self.board == HostBoard.ARM64: return { - 'PKG_CONFIG_PATH': self.SysRootPath('SYSROOT_AARCH64') + '/lib/aarch64-linux-gnu/pkgconfig', + 'PKG_CONFIG_PATH': os.path.join( + self.SysRootPath('SYSROOT_AARCH64'), + 'lib/aarch64-linux-gnu/pkgconfig'), } else: raise Exception('Unknown host board type: %r' % self) def SysRootPath(self, name): - if not name in os.environ: + if name not in os.environ: raise Exception('Missing environment variable "%s"' % name) return os.environ[name] diff --git a/scripts/build/builders/k32w.py b/scripts/build/builders/k32w.py index 1cc0d6678cd848..e5624ca621ff66 100644 --- a/scripts/build/builders/k32w.py +++ b/scripts/build/builders/k32w.py @@ -74,7 +74,7 @@ def GnBuildArgs(self): args.append('chip_with_low_power=1') else: args.append('chip_with_low_power=0') - + if self.tokenizer: args.append('chip_pw_tokenizer_logging=true') diff --git a/scripts/build/builders/mbed.py b/scripts/build/builders/mbed.py index 49767fe82c2d1a..cc1d999f71eec7 100644 --- a/scripts/build/builders/mbed.py +++ b/scripts/build/builders/mbed.py @@ -12,12 +12,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -import logging import os -import platform import shlex - from enum import Enum, auto + from .builder import Builder diff --git a/scripts/build/builders/nrf.py b/scripts/build/builders/nrf.py index ccc916faf9c74e..b2a89f3d690453 100644 --- a/scripts/build/builders/nrf.py +++ b/scripts/build/builders/nrf.py @@ -15,7 +15,6 @@ import logging import os import shlex - from enum import Enum, auto from .builder import Builder @@ -79,7 +78,10 @@ def _FlashBundlePrefix(self): raise Exception('Unknown app type: %r' % self) def FlashBundleName(self): - '''Nrf build script will generate a file naming .flashbundle.txt, go through the output dir to find the file and return it.''' + ''' + Nrf build script will generate a file naming .flashbundle.txt, + go through the output dir to find the file and return it. + ''' return self._FlashBundlePrefix() + '.flashbundle.txt' @@ -135,7 +137,7 @@ def generate(self): try: self._Execute( ['python3', 'scripts/setup/nrfconnect/update_ncs.py', '--check']) - except Exception as e: + except Exception: logging.exception('Failed to validate ZEPHYR_BASE status') logging.error( 'To update $ZEPHYR_BASE run: python3 scripts/setup/nrfconnect/update_ncs.py --update --shallow') diff --git a/scripts/build/builders/telink.py b/scripts/build/builders/telink.py index d4570ed2966d39..7aff204beec33c 100644 --- a/scripts/build/builders/telink.py +++ b/scripts/build/builders/telink.py @@ -15,7 +15,6 @@ import logging import os import shlex - from enum import Enum, auto from .builder import Builder diff --git a/scripts/build/builders/tizen.py b/scripts/build/builders/tizen.py index 7ebacb90c9ec9b..53c852bcb05a4b 100644 --- a/scripts/build/builders/tizen.py +++ b/scripts/build/builders/tizen.py @@ -13,7 +13,6 @@ # limitations under the License. import os - from enum import Enum, auto from .gn import GnBuilder @@ -51,30 +50,43 @@ def __init__(self, root, runner, app: TizenApp = TizenApp.LIGHT, - board: TizenBoard = TizenBoard.ARM): + board: TizenBoard = TizenBoard.ARM, + enable_ble: bool = True, + enable_wifi: bool = True, + use_asan: bool = False, + use_tsan: bool = False, + ): super(TizenBuilder, self).__init__( root=os.path.join(root, 'examples', app.ExampleName(), 'linux'), runner=runner) + self.app = app self.board = board + self.extra_gn_options = [] + + if not enable_ble: + self.extra_gn_options.append('chip_config_network_layer_ble=false') + if not enable_wifi: + self.extra_gn_options.append('chip_enable_wifi=false') + if use_asan: + self.extra_gn_options.append('is_asan=true') + if use_tsan: + raise Exception("TSAN sanitizer not supported by Tizen toolchain") def GnBuildArgs(self): if 'TIZEN_HOME' not in os.environ: raise Exception( - "Environment TIZEN_HOME missing, cannot build tizen libraries") - - return [ + "Environment TIZEN_HOME missing, cannot build Tizen target") + return self.extra_gn_options + [ 'target_os="tizen"', 'target_cpu="%s"' % self.board.TargetCpuName(), 'sysroot="%s"' % os.environ['TIZEN_HOME'], ] def build_outputs(self): - items = { + 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()), } - - return items diff --git a/scripts/build/runner/__init__.py b/scripts/build/runner/__init__.py index 791753a838aa32..2cdcdd3e8e8f21 100644 --- a/scripts/build/runner/__init__.py +++ b/scripts/build/runner/__init__.py @@ -1,2 +1,4 @@ -from .shell import ShellRunner from .printonly import PrintOnlyRunner +from .shell import ShellRunner + +__all__ = ['PrintOnlyRunner', 'ShellRunner'] diff --git a/scripts/build/runner/shell.py b/scripts/build/runner/shell.py index 71c34f4ee143c5..d8c2ae3cfb79bf 100644 --- a/scripts/build/runner/shell.py +++ b/scripts/build/runner/shell.py @@ -64,7 +64,8 @@ def Run(self, cmd, title=None): if title: logging.info(title) - with subprocess.Popen(cmd, cwd=self.root_dir, stdout=outpipe, stderr=errpipe) as s: + with subprocess.Popen(cmd, cwd=self.root_dir, + stdout=outpipe, stderr=errpipe) as s: outpipe.close() errpipe.close() code = s.wait() diff --git a/scripts/build/setup.py b/scripts/build/setup.py index b5c82aaf37f4dc..e9776293c2ade0 100644 --- a/scripts/build/setup.py +++ b/scripts/build/setup.py @@ -24,5 +24,9 @@ description='Generate build commands for the CHIP SDK Examples', packages=setuptools.find_packages(), package_data={'build_examples': ['py.typed']}, + install_requires=[ + 'click >= 6.7.0', + 'coloredlogs >= 7.3.0' + ], zip_safe=False, ) diff --git a/scripts/build/test.py b/scripts/build/test.py index d25e74ec037b65..ac788c06f6f9f1 100644 --- a/scripts/build/test.py +++ b/scripts/build/test.py @@ -14,18 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -import click -import coloredlogs import difflib -import logging import os import subprocess import sys -import time import unittest - -from builders.host import HostBoard - from typing import List SCRIPT_ROOT = os.path.dirname(__file__) @@ -93,7 +86,7 @@ def assertCommandOutput(self, expected_file: str, args: List[str]): msg += "Expected file can be found in %s" % reference for l in diffs: msg += ("\n " + l.replace(ROOT, - '{root}').replace(OUT, '{out}').strip()) + '{root}').replace(OUT, '{out}').strip()) self.fail(msg) def test_output(self): diff --git a/scripts/build/test_glob_matcher.py b/scripts/build/test_glob_matcher.py index e175ff4347d9bb..e1ee0f8a70f3c1 100644 --- a/scripts/build/test_glob_matcher.py +++ b/scripts/build/test_glob_matcher.py @@ -14,10 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -from glob_matcher import GlobMatcher - import unittest +from glob_matcher import GlobMatcher + class TestGlobMatcher(unittest.TestCase): diff --git a/scripts/build/testdata/all_targets_except_host.txt b/scripts/build/testdata/all_targets_except_host.txt index 464a4c7294b686..647e0b0a02bfc3 100644 --- a/scripts/build/testdata/all_targets_except_host.txt +++ b/scripts/build/testdata/all_targets_except_host.txt @@ -193,3 +193,10 @@ qpg-persistent-storage qpg-shell telink-tlsr9518adk80d-light tizen-arm-light +tizen-arm-light-asan (NOGLOB: Reduce default build variants) +tizen-arm-light-no-ble (NOGLOB: Reduce default build variants) +tizen-arm-light-no-ble-asan (NOGLOB: Reduce default build variants) +tizen-arm-light-no-ble-no-wifi (NOGLOB: Reduce default build variants) +tizen-arm-light-no-ble-no-wifi-asan (NOGLOB: Reduce default build variants) +tizen-arm-light-no-wifi (NOGLOB: Reduce default build variants) +tizen-arm-light-no-wifi-asan (NOGLOB: Reduce default build variants) diff --git a/scripts/build/testdata/build_all_except_host.txt b/scripts/build/testdata/build_all_except_host.txt index 7ad5c54a89da61..552aea9f5efdae 100644 --- a/scripts/build/testdata/build_all_except_host.txt +++ b/scripts/build/testdata/build_all_except_host.txt @@ -910,6 +910,27 @@ west build --cmake-only -d {out}/telink-tlsr9518adk80d-light -b tlsr9518adk80d { # Generating tizen-arm-light gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/linux '--args=target_os="tizen" target_cpu="arm" sysroot="TEST_TIZEN_HOME"' {out}/tizen-arm-light +# Generating tizen-arm-light-asan +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/linux '--args=is_asan=true target_os="tizen" target_cpu="arm" sysroot="TEST_TIZEN_HOME"' {out}/tizen-arm-light-asan + +# Generating tizen-arm-light-no-ble +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/linux '--args=chip_config_network_layer_ble=false target_os="tizen" target_cpu="arm" sysroot="TEST_TIZEN_HOME"' {out}/tizen-arm-light-no-ble + +# Generating tizen-arm-light-no-ble-asan +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/linux '--args=chip_config_network_layer_ble=false is_asan=true target_os="tizen" target_cpu="arm" sysroot="TEST_TIZEN_HOME"' {out}/tizen-arm-light-no-ble-asan + +# Generating tizen-arm-light-no-ble-no-wifi +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/linux '--args=chip_config_network_layer_ble=false chip_enable_wifi=false target_os="tizen" target_cpu="arm" sysroot="TEST_TIZEN_HOME"' {out}/tizen-arm-light-no-ble-no-wifi + +# Generating tizen-arm-light-no-ble-no-wifi-asan +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/linux '--args=chip_config_network_layer_ble=false chip_enable_wifi=false is_asan=true target_os="tizen" target_cpu="arm" sysroot="TEST_TIZEN_HOME"' {out}/tizen-arm-light-no-ble-no-wifi-asan + +# Generating tizen-arm-light-no-wifi +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/linux '--args=chip_enable_wifi=false target_os="tizen" target_cpu="arm" sysroot="TEST_TIZEN_HOME"' {out}/tizen-arm-light-no-wifi + +# Generating tizen-arm-light-no-wifi-asan +gn gen --check --fail-on-unused-args --export-compile-commands --root={root}/examples/lighting-app/linux '--args=chip_enable_wifi=false is_asan=true target_os="tizen" target_cpu="arm" sysroot="TEST_TIZEN_HOME"' {out}/tizen-arm-light-no-wifi-asan + # Building ameba-amebad-all-clusters ninja -C {out}/ameba-amebad-all-clusters @@ -1768,3 +1789,24 @@ ninja -C {out}/telink-tlsr9518adk80d-light # Building tizen-arm-light ninja -C {out}/tizen-arm-light + +# Building tizen-arm-light-asan +ninja -C {out}/tizen-arm-light-asan + +# Building tizen-arm-light-no-ble +ninja -C {out}/tizen-arm-light-no-ble + +# Building tizen-arm-light-no-ble-asan +ninja -C {out}/tizen-arm-light-no-ble-asan + +# Building tizen-arm-light-no-ble-no-wifi +ninja -C {out}/tizen-arm-light-no-ble-no-wifi + +# Building tizen-arm-light-no-ble-no-wifi-asan +ninja -C {out}/tizen-arm-light-no-ble-no-wifi-asan + +# Building tizen-arm-light-no-wifi +ninja -C {out}/tizen-arm-light-no-wifi + +# Building tizen-arm-light-no-wifi-asan +ninja -C {out}/tizen-arm-light-no-wifi-asan