Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ota requestor variants for efr32 builds in build_examples #16228

Merged
merged 2 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 105 additions & 49 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,21 +112,85 @@ def Accept(self, name: str):
return False


class HostBuildVariant:
class BuildVariant:
def __init__(self, name: str, validator=AcceptAnyName(), conflicts: List[str] = [], **buildargs):
self.name = name
self.validator = validator
self.conflicts = conflicts
self.buildargs = buildargs


def HasConflicts(items: List[HostBuildVariant]) -> bool:
def HasConflicts(items: List[BuildVariant]) -> bool:
for a, b in combinations(items, 2):
if (a.name in b.conflicts) or (b.name in a.conflicts):
return True
return False


class VariantBuilder:
"""Handles creating multiple build variants based on a starting target.
"""

def __init__(self, targets: List[Target]):
self.targets = targets
self.variants = []
self.glob_whitelist = []

def WhitelistVariantNameForGlob(self, name):
"""
Whitelist the specified variant to be allowed for globbing.

By default we do not want a 'build all' to select all variants, so
variants are generally glob-blacklisted.
"""
self.glob_whitelist.append(name)

def AppendVariant(self, **args):
"""
Add another variant to accepted variants. Arguments are construction
variants to BuildVariant.

Example usage:

builder.AppendVariant(name="ipv6only", enable_ipv4=False)
"""
self.variants.append(BuildVariant(**args))

def AllVariants(self):
"""
Yields a list of acceptable variants for the given targets.

Handles conflict resolution between build variants and globbing whiltelist
targets.
"""
for target in self.targets:
yield target

# skip variants that do not work for this target
ok_variants = [
v for v in self.variants if v.validator.Accept(target.name)]

# Build every possible variant
for variant_count in range(1, len(ok_variants) + 1):
for subgroup in combinations(ok_variants, variant_count):
if HasConflicts(subgroup):
continue

# Target ready to be created - no conflicts
variant_target = target.Clone()
for option in subgroup:
variant_target = variant_target.Extend(
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:
variant_target = variant_target.GlobBlacklist(
'Reduce default build variants')

yield variant_target


def HostTargets():
target = Target(HostBoard.NATIVE.PlatformName(), HostBuilder)
targets = [
Expand Down Expand Up @@ -159,50 +223,32 @@ def HostTargets():
app_targets.append(target.Extend(
'ota-requestor', app=HostApp.OTA_REQUESTOR, enable_ble=False))

builder = VariantBuilder([])

# Possible build variants. Note that number of potential
# builds is exponential here
variants = [
HostBuildVariant(name="ipv6only", enable_ipv4=False),
HostBuildVariant(name="no-ble", enable_ble=False),
HostBuildVariant(name="tsan", conflicts=['asan'], use_tsan=True),
HostBuildVariant(name="asan", conflicts=['tsan'], use_asan=True),
HostBuildVariant(name="libfuzzer", use_libfuzzer=True, use_clang=True),
HostBuildVariant(name="test-group",
validator=AcceptNameWithSubstrings(['-all-clusters', '-chip-tool']), test_group=True),
HostBuildVariant(name="same-event-loop",
validator=AcceptNameWithSubstrings(['-chip-tool']), separate_event_loop=False),
]

glob_whitelist = set(['ipv6only'])
builder.AppendVariant(name="ipv6only", enable_ipv4=False),
builder.AppendVariant(name="no-ble", enable_ble=False),
builder.AppendVariant(name="tsan", conflicts=['asan'], use_tsan=True),
builder.AppendVariant(name="asan", conflicts=['tsan'], use_asan=True),
builder.AppendVariant(
name="libfuzzer", use_libfuzzer=True, use_clang=True),
builder.AppendVariant(name="test-group", validator=AcceptNameWithSubstrings(
['-all-clusters', '-chip-tool']), test_group=True),
builder.AppendVariant(name="same-event-loop", validator=AcceptNameWithSubstrings(
['-chip-tool']), separate_event_loop=False),

builder.WhitelistVariantNameForGlob('ipv6only')

for target in app_targets:
yield target

if 'rpc-console' in target.name:
# rpc console has only one build variant right now
continue

# skip variants that do not work for this target
ok_variants = [v for v in variants if v.validator.Accept(target.name)]

# Build every possible variant
for variant_count in range(1, len(ok_variants) + 1):
for subgroup in combinations(ok_variants, variant_count):
if HasConflicts(subgroup):
continue

# Target ready to be created - no conflicts
variant_target = target.Clone()
for option in subgroup:
variant_target = variant_target.Extend(
option.name, **option.buildargs)

# Only a few are whitelisted for globs
if '-'.join([o.name for o in subgroup]) not in glob_whitelist:
variant_target = variant_target.GlobBlacklist(
'Reduce default build variants')
yield target
else:
builder.targets.append(target)

yield variant_target
for target in builder.AllVariants():
yield target

# Without extra build variants
yield targets[0].Extend('chip-cert', app=HostApp.CERT_TOOL)
Expand Down Expand Up @@ -261,19 +307,29 @@ def Efr32Targets():
'only user requested')
]

builder = VariantBuilder([])

for board_target in board_targets:
yield board_target.Extend('window-covering', app=Efr32App.WINDOW_COVERING)
yield board_target.Extend('switch', app=Efr32App.SWITCH)
yield board_target.Extend('unit-test', app=Efr32App.UNIT_TEST)
builder.targets.append(board_target.Extend(
'window-covering', app=Efr32App.WINDOW_COVERING))
builder.targets.append(board_target.Extend(
'switch', app=Efr32App.SWITCH))
builder.targets.append(board_target.Extend(
'unit-test', app=Efr32App.UNIT_TEST))
builder.targets.append(
board_target.Extend('light', app=Efr32App.LIGHT))
builder.targets.append(board_target.Extend('lock', app=Efr32App.LOCK))

rpc_aware_targets = [
board_target.Extend('light', app=Efr32App.LIGHT),
board_target.Extend('lock', app=Efr32App.LOCK)
]
# Possible build variants. Note that number of potential
# builds is exponential here
builder.AppendVariant(name="rpc", validator=AcceptNameWithSubstrings(
['-light', '-lock']), enable_rpcs=True)
builder.AppendVariant(name="with-ota-requestor", enable_ota_requestor=True)

for target in rpc_aware_targets:
yield target
yield target.Extend('rpc', enable_rpcs=True)
builder.WhitelistVariantNameForGlob('rpc')

for target in builder.AllVariants():
yield target


def NrfTargets():
Expand Down
18 changes: 11 additions & 7 deletions scripts/build/builders/efr32.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,23 @@ def __init__(self,
runner,
app: Efr32App = Efr32App.LIGHT,
board: Efr32Board = Efr32Board.BRD4161A,
enable_rpcs: bool = False):
enable_rpcs: bool = False,
enable_ota_requestor: bool = False,
):
super(Efr32Builder, self).__init__(
root=app.BuildRoot(root),
runner=runner)
self.app = app
self.board = board
self.enable_rpcs = enable_rpcs
self.extra_gn_options = ['efr32_board="%s"' % board.GnArgName()]

if enable_rpcs:
self.extra_gn_options.append('import("//with_pw_rpc.gni")')

if enable_ota_requestor:
self.extra_gn_options.append('chip_enable_ota_requestor=true')

def GnBuildArgs(self):
args = ['efr32_board="%s"' % self.board.GnArgName()]
if self.enable_rpcs:
args.append('import("//with_pw_rpc.gni")')
return args
return self.extra_gn_options

def build_outputs(self):
items = {}
Expand Down
56 changes: 56 additions & 0 deletions scripts/build/testdata/all_targets_except_host.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,60 +20,116 @@ cyw30739-cyw930739m2evb_01-ota-requestor (NOGLOB: Running out of XIP flash space
cyw30739-cyw930739m2evb_01-ota-requestor-no-progress-logging
efr32-brd4161a-light
efr32-brd4161a-light-rpc
efr32-brd4161a-light-rpc-with-ota-requestor (NOGLOB: Reduce default build variants)
efr32-brd4161a-light-with-ota-requestor (NOGLOB: Reduce default build variants)
efr32-brd4161a-lock
efr32-brd4161a-lock-rpc
efr32-brd4161a-lock-rpc-with-ota-requestor (NOGLOB: Reduce default build variants)
efr32-brd4161a-lock-with-ota-requestor (NOGLOB: Reduce default build variants)
efr32-brd4161a-switch
efr32-brd4161a-switch-with-ota-requestor (NOGLOB: Reduce default build variants)
efr32-brd4161a-unit-test
efr32-brd4161a-unit-test-with-ota-requestor (NOGLOB: Reduce default build variants)
efr32-brd4161a-window-covering
efr32-brd4161a-window-covering-with-ota-requestor (NOGLOB: Reduce default build variants)
efr32-brd4163a-light (NOGLOB: only user requested)
efr32-brd4163a-light-rpc (NOGLOB: only user requested)
efr32-brd4163a-light-rpc-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4163a-light-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4163a-lock (NOGLOB: only user requested)
efr32-brd4163a-lock-rpc (NOGLOB: only user requested)
efr32-brd4163a-lock-rpc-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4163a-lock-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4163a-switch (NOGLOB: only user requested)
efr32-brd4163a-switch-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4163a-unit-test (NOGLOB: only user requested)
efr32-brd4163a-unit-test-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4163a-window-covering (NOGLOB: only user requested)
efr32-brd4163a-window-covering-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4164a-light (NOGLOB: only user requested)
efr32-brd4164a-light-rpc (NOGLOB: only user requested)
efr32-brd4164a-light-rpc-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4164a-light-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4164a-lock (NOGLOB: only user requested)
efr32-brd4164a-lock-rpc (NOGLOB: only user requested)
efr32-brd4164a-lock-rpc-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4164a-lock-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4164a-switch (NOGLOB: only user requested)
efr32-brd4164a-switch-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4164a-unit-test (NOGLOB: only user requested)
efr32-brd4164a-unit-test-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4164a-window-covering (NOGLOB: only user requested)
efr32-brd4164a-window-covering-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4166a-light (NOGLOB: only user requested)
efr32-brd4166a-light-rpc (NOGLOB: only user requested)
efr32-brd4166a-light-rpc-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4166a-light-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4166a-lock (NOGLOB: only user requested)
efr32-brd4166a-lock-rpc (NOGLOB: only user requested)
efr32-brd4166a-lock-rpc-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4166a-lock-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4166a-switch (NOGLOB: only user requested)
efr32-brd4166a-switch-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4166a-unit-test (NOGLOB: only user requested)
efr32-brd4166a-unit-test-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4166a-window-covering (NOGLOB: only user requested)
efr32-brd4166a-window-covering-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4170a-light (NOGLOB: only user requested)
efr32-brd4170a-light-rpc (NOGLOB: only user requested)
efr32-brd4170a-light-rpc-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4170a-light-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4170a-lock (NOGLOB: only user requested)
efr32-brd4170a-lock-rpc (NOGLOB: only user requested)
efr32-brd4170a-lock-rpc-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4170a-lock-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4170a-switch (NOGLOB: only user requested)
efr32-brd4170a-switch-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4170a-unit-test (NOGLOB: only user requested)
efr32-brd4170a-unit-test-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4170a-window-covering (NOGLOB: only user requested)
efr32-brd4170a-window-covering-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4186a-light (NOGLOB: only user requested)
efr32-brd4186a-light-rpc (NOGLOB: only user requested)
efr32-brd4186a-light-rpc-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4186a-light-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4186a-lock (NOGLOB: only user requested)
efr32-brd4186a-lock-rpc (NOGLOB: only user requested)
efr32-brd4186a-lock-rpc-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4186a-lock-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4186a-switch (NOGLOB: only user requested)
efr32-brd4186a-switch-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4186a-unit-test (NOGLOB: only user requested)
efr32-brd4186a-unit-test-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4186a-window-covering (NOGLOB: only user requested)
efr32-brd4186a-window-covering-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4187a-light (NOGLOB: only user requested)
efr32-brd4187a-light-rpc (NOGLOB: only user requested)
efr32-brd4187a-light-rpc-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4187a-light-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4187a-lock (NOGLOB: only user requested)
efr32-brd4187a-lock-rpc (NOGLOB: only user requested)
efr32-brd4187a-lock-rpc-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4187a-lock-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4187a-switch (NOGLOB: only user requested)
efr32-brd4187a-switch-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4187a-unit-test (NOGLOB: only user requested)
efr32-brd4187a-unit-test-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4187a-window-covering (NOGLOB: only user requested)
efr32-brd4187a-window-covering-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4304a-light (NOGLOB: only user requested)
efr32-brd4304a-light-rpc (NOGLOB: only user requested)
efr32-brd4304a-light-rpc-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4304a-light-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4304a-lock (NOGLOB: only user requested)
efr32-brd4304a-lock-rpc (NOGLOB: only user requested)
efr32-brd4304a-lock-rpc-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4304a-lock-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4304a-switch (NOGLOB: only user requested)
efr32-brd4304a-switch-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4304a-unit-test (NOGLOB: only user requested)
efr32-brd4304a-unit-test-with-ota-requestor (NOGLOB: only user requested)
efr32-brd4304a-window-covering (NOGLOB: only user requested)
efr32-brd4304a-window-covering-with-ota-requestor (NOGLOB: only user requested)
esp32-c3devkit-all-clusters
esp32-devkitc-all-clusters
esp32-devkitc-all-clusters-ipv6only
Expand Down
Loading