Skip to content

Commit

Permalink
Merge pull request google#101 from gendx/verbose-build
Browse files Browse the repository at this point in the history
Add a --verbose-build option to the deploy script.
  • Loading branch information
gendx authored Apr 28, 2020
2 parents b486ff4 + c780d76 commit 20674c5
Showing 1 changed file with 41 additions and 10 deletions.
51 changes: 41 additions & 10 deletions deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,14 @@ def __init__(self, args):
port=None,
)

def checked_command(self, cmd, env=None, cwd=None):
stdout = None if self.args.verbose_build else subprocess.DEVNULL
try:
subprocess.run(
cmd, stdout=stdout, timeout=None, check=True, env=env, cwd=cwd)
except subprocess.CalledProcessError as e:
fatal("Failed to execute {}: {}".format(cmd[0], str(e)))

def checked_command_output(self, cmd, env=None, cwd=None):
cmd_output = ""
try:
Expand Down Expand Up @@ -300,10 +308,18 @@ def update_rustc_if_needed(self):
target_toolchain[1] in current_version):
info("Updating rust toolchain to {}".format("-".join(target_toolchain)))
# Need to update
self.checked_command_output(
["rustup", "install", target_toolchain_fullstring])
self.checked_command_output(
["rustup", "target", "add", SUPPORTED_BOARDS[self.args.board].arch])
rustup_install = ["rustup"]
if self.args.verbose_build:
rustup_install.append("--verbose")
rustup_install.extend(["install", target_toolchain_fullstring])
self.checked_command(rustup_install)

rustup_target = ["rustup"]
if self.args.verbose_build:
rustup_target.append("--verbose")
rustup_target.extend(
["target", "add", SUPPORTED_BOARDS[self.args.board].arch])
self.checked_command(rustup_target)
info("Rust toolchain up-to-date")

def build_tockos(self):
Expand All @@ -312,7 +328,11 @@ def build_tockos(self):
out_directory = os.path.join("third_party", "tock", "target", props.arch,
"release")
os.makedirs(out_directory, exist_ok=True)
self.checked_command_output(["make"], cwd=props.path)

env = os.environ.copy()
if self.args.verbose_build:
env["V"] = "1"
self.checked_command(["make"], cwd=props.path, env=env)

def build_example(self):
info("Building example {}".format(self.args.application))
Expand Down Expand Up @@ -347,7 +367,9 @@ def _build_app_or_example(self, is_example):
]
if is_example:
command.extend(["--example", self.args.application])
self.checked_command_output(command, env=env)
if self.args.verbose_build:
command.append("--verbose")
self.checked_command(command, env=env)
app_path = os.path.join("target", props.arch, "release")
if is_example:
app_path = os.path.join(app_path, "examples")
Expand Down Expand Up @@ -383,6 +405,8 @@ def create_tab_file(self, binaries):
elf2tab_args = [
"elf2tab", package_parameter, self.args.application, "-o", tab_filename
]
if self.args.verbose_build:
elf2tab_args.append("--verbose")
for arch, app_file in binaries.items():
dest_file = os.path.join(self.tab_folder, "{}.elf".format(arch))
shutil.copyfile(app_file, dest_file)
Expand All @@ -392,7 +416,7 @@ def create_tab_file(self, binaries):
"--stack={}".format(STACK_SIZE), "--app-heap={}".format(APP_HEAP_SIZE),
"--kernel-heap=1024", "--protected-region-size=64"
])
self.checked_command_output(elf2tab_args)
self.checked_command(elf2tab_args)

def install_tab_file(self, tab_filename):
assert self.args.application
Expand Down Expand Up @@ -616,14 +640,14 @@ def run(self):

if self.args.programmer == "pyocd":
info("Flashing HEX file")
self.checked_command_output([
self.checked_command([
"pyocd", "flash", "--target={}".format(board_props.pyocd_target),
"--format=hex", "--erase=auto", dest_file
])
if self.args.programmer == "nordicdfu":
info("Creating DFU package")
dfu_pkg_file = "target/{}_dfu.zip".format(self.args.board)
self.checked_command_output([
self.checked_command([
"nrfutil", "pkg", "generate", "--hw-version=52", "--sd-req=0",
"--application-version=1", "--application={}".format(dest_file),
dfu_pkg_file
Expand Down Expand Up @@ -674,7 +698,7 @@ def main(args):
choices=("boards", "programmers"),
default=None,
dest="listing",
help=("List supported boards or programmers, 1 per line and then exit."),
help="List supported boards or programmers, 1 per line and then exit.",
)
action_group.add_argument(
"--board",
Expand Down Expand Up @@ -711,6 +735,13 @@ def main(args):
help=("Only compiles and flash the application/example. "
"Otherwise TockOS will also be bundled and flashed."),
)
main_parser.add_argument(
"--verbose-build",
action="store_true",
default=False,
dest="verbose_build",
help="Build everything in verbose mode.",
)

main_parser.add_argument(
"--panic-console",
Expand Down

0 comments on commit 20674c5

Please sign in to comment.