Repository: google/OpenSK
File: deploy.py (Python)

Code before:
    env["RUSTFLAGS"] = " ".join(rust_flags)
    env["APP_HEAP_SIZE"] = str(APP_HEAP_SIZE)

    command = [
        "cargo", "build", "--release", f"--target={props.arch}",
        f"--features={','.join(self.args.features)}"
    ]
    if is_example:
      command.extend(["--example", self.args.application])
    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")
    app_path = os.path.join(app_path, self.args.application)
    # Create a TAB file
    self.create_tab_file({props.arch: app_path})

  def _check_invariants(self):
    """Runs selected unit tests to check preconditions in the code."""
    print("Testing invariants in customization.rs...")
    self.checked_command_output(
        ["cargo", "test", "--features=std", "--lib", "customization"])
    self.checked_command_output(
        ["cargo", "test", "--features=std", "--lib", "api::customization"])

  def generate_crypto_materials(self, force_regenerate: bool):
    """Calls a shell script that generates cryptographic material."""
    has_error = subprocess.call([
        os.path.join("tools", "gen_key_materials.sh"),
        "Y" if force_regenerate else "N",
    ])
    if has_error:
      error(("Something went wrong while trying to generate ECC "
             "key and/or certificate for OpenSK"))

  def create_tab_file(self, binary_names: Dict[str, str]):
    """Checks and uses elf2tab to generated an TAB file out of the binaries."""
    assert binary_names
    assert self.args.application
    info("Generating Tock TAB file for application/example "
         f"{self.args.application}")
    elf2tab_ver = self.checked_command_output(
        ["elf2tab/bin/elf2tab", "--version"]).split(
            "\n", maxsplit=1)[0]
    if elf2tab_ver != "elf2tab 0.7.0":
      error(("Detected unsupported elf2tab version {elf2tab_ver!a}. The "
             "following commands may fail. Please use 0.7.0 instead."))
    os.makedirs(self.tab_folder, exist_ok=True)
    tab_filename = os.path.join(self.tab_folder, f"{self.args.application}.tab")

Review comment (suggestion):
I'm surprised we need this. The command above should also contain `api::customization` because it just greps anything in the test name. I would remove it if it's the case because we test twice.

Code after:
    env["RUSTFLAGS"] = " ".join(rust_flags)
    env["APP_HEAP_SIZE"] = str(APP_HEAP_SIZE)

    command = [
        "cargo", "build", "--release", f"--target={props.arch}",
        f"--features={','.join(self.args.features)}"
    ]
    if is_example:
      command.extend(["--example", self.args.application])
    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")
    app_path = os.path.join(app_path, self.args.application)
    # Create a TAB file
    self.create_tab_file({props.arch: app_path})

  def _check_invariants(self):
    """Runs selected unit tests to check preconditions in the code."""
    print("Testing invariants in customization.rs...")
    self.checked_command_output(
        ["cargo", "test", "--features=std", "--lib", "customization"])

  def generate_crypto_materials(self, force_regenerate: bool):
    """Calls a shell script that generates cryptographic material."""
    has_error = subprocess.call([
        os.path.join("tools", "gen_key_materials.sh"),
        "Y" if force_regenerate else "N",
    ])
    if has_error:
      error(("Something went wrong while trying to generate ECC "
             "key and/or certificate for OpenSK"))

  def create_tab_file(self, binary_names: Dict[str, str]):
    """Checks and uses elf2tab to generated an TAB file out of the binaries."""
    assert binary_names
    assert self.args.application
    info("Generating Tock TAB file for application/example "
         f"{self.args.application}")
    elf2tab_ver = self.checked_command_output(
        ["elf2tab/bin/elf2tab", "--version"]).split(
            "\n", maxsplit=1)[0]
    if elf2tab_ver != "elf2tab 0.7.0":
      error(("Detected unsupported elf2tab version {elf2tab_ver!a}. The "
             "following commands may fail. Please use 0.7.0 instead."))
    os.makedirs(self.tab_folder, exist_ok=True)
    tab_filename = os.path.join(self.tab_folder, f"{self.args.application}.tab")
    elf2tab_args = [
        "elf2tab/bin/elf2tab", "--deterministic", "--package-name",