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

Set pw_command_launcher from build_example.py CLI #23702

Merged
merged 4 commits into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
7 changes: 5 additions & 2 deletions scripts/build/build/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def __init__(self, runner, repository_path: str, output_prefix: str):
self.completed_steps = set()

def SetupBuilders(self, targets: Sequence[str],
enable_flashbundle: bool):
enable_flashbundle: bool,
andy31415 marked this conversation as resolved.
Show resolved Hide resolved
pw_command_launcher: str):
"""
Configures internal builders for the given platform/board/app
combination.
Expand All @@ -35,7 +36,9 @@ def SetupBuilders(self, targets: Sequence[str],
for target in targets:
found = False
for choice in BUILD_TARGETS:
builder = choice.Create(target, self.runner, self.repository_path, self.output_prefix, enable_flashbundle)
builder = choice.Create(
target, self.runner, self.repository_path, self.output_prefix,
enable_flashbundle, pw_command_launcher)
if builder:
self.builders.append(builder)
found = True
Expand Down
5 changes: 3 additions & 2 deletions scripts/build/build/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def StringIntoTargetParts(self, value: str):
return _StringIntoParts(value, suffix, self.fixed_targets, self.modifiers)

def Create(self, name: str, runner, repository_path: str, output_prefix: str,
enable_flashbundle: bool):
enable_flashbundle: bool, pw_command_launcher: str):

parts = self.StringIntoTargetParts(name)

Expand All @@ -348,6 +348,7 @@ def Create(self, name: str, runner, repository_path: str, output_prefix: str,
builder.identifier = name
builder.output_dir = os.path.join(output_prefix, name)
builder.chip_dir = repository_path
builder.enable_flashbundle(enable_flashbundle)
builder.enable_flashbundle = enable_flashbundle
builder.pw_command_launcher = pw_command_launcher

return builder
10 changes: 8 additions & 2 deletions scripts/build/build_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,15 @@ def ValidateRepoPath(context, parameter, value):
default=False,
is_flag=True,
help='Skip timestaps in log output')
@click.option(
'--pw-command-launcher',
help=(
'Set pigweed command launcher. E.g.: "--pw-command-launcher=ccache" '
'for using ccache when building examples.'))
@click.pass_context
def main(context, log_level, target, repo,
out_prefix, clean, dry_run, dry_run_output, enable_flashbundle,
no_log_timestamps):
no_log_timestamps, pw_command_launcher):
# Ensures somewhat pretty logging of what is going on
log_fmt = '%(asctime)s %(levelname)-7s %(message)s'
if no_log_timestamps:
Expand All @@ -136,7 +141,8 @@ def main(context, log_level, target, repo,
context.obj = build.Context(
repository_path=repo, output_prefix=out_prefix, runner=runner)
context.obj.SetupBuilders(
targets=requested_targets, enable_flashbundle=enable_flashbundle)
targets=requested_targets, enable_flashbundle=enable_flashbundle,
pw_command_launcher=pw_command_launcher)

if clean:
context.obj.CleanOutputDirectories()
Expand Down
15 changes: 8 additions & 7 deletions scripts/build/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@
class Builder(ABC):
"""Generic builder base class for CHIP.

Provides ability to boostrap and copy output artifacts and subclasses can use
a generic shell runner.
Provides ability to bootstrap and copy output artifacts and subclasses can
use a generic shell runner.

"""

def __init__(self, root, runner):
self.root = os.path.abspath(root)
self._runner = runner
self._enable_flashbundle = False

# Set post-init once actual build target is known
self.identifier = None
self.output_dir = None

def enable_flashbundle(self, enable_flashbundle: bool):
self._enable_flashbundle = enable_flashbundle
# Enable flashbundle generation stage
self.enable_flashbundle = False
# Allow to override the default build command
self.pw_command_launcher = None

@abstractmethod
def generate(self):
Expand Down Expand Up @@ -81,13 +82,13 @@ def flashbundle(self):

def outputs(self):
artifacts = self.build_outputs()
if self._enable_flashbundle:
if self.enable_flashbundle:
artifacts.update(self.flashbundle())
return artifacts

def build(self):
self._build()
if self._enable_flashbundle:
if self.enable_flashbundle:
self._generate_flashbundle()

def _Execute(self, cmdarray, title=None):
Expand Down
5 changes: 4 additions & 1 deletion scripts/build/builders/gn.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ def generate(self):
'--root=%s' % self.root
]

extra_args = self.GnBuildArgs()
extra_args = []
if self.pw_command_launcher:
extra_args.append('pw_command_launcher="%s"' % self.pw_command_launcher)
extra_args.extend(self.GnBuildArgs() or [])
if extra_args:
cmd += ['--args=%s' % ' '.join(extra_args)]

Expand Down