From 6330c4483548c8e8c2b1d424eba8511dea3d6718 Mon Sep 17 00:00:00 2001 From: Dostoievski Batista Date: Thu, 11 Apr 2024 19:02:27 -0300 Subject: [PATCH] Add name option when building the patch This change add option '--name' to the patch builder script allowing user to select the desired file name for the patch file. If the 'name' option is not provided, file name will default to patch id from the recipe. Test plan: PASS: Build patch with --name parameter e.g: python3 patch_builder --recipe recipe.xml --name filename.patch PASS: Build patch without --name parameter e.g: python3 patch_builder --recipe recipe.xml Story: 2010676 Task: 49858 Change-Id: Ia9b936d44ef83e6ff3d9561b22ae045fb2891f33 --- build-tools/stx/patch/patch_builder.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/build-tools/stx/patch/patch_builder.py b/build-tools/stx/patch/patch_builder.py index e4597928..43b7ec3f 100755 --- a/build-tools/stx/patch/patch_builder.py +++ b/build-tools/stx/patch/patch_builder.py @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # -# Copyright (c) 2023 Wind River Systems, Inc. +# Copyright (c) 2024 Wind River Systems, Inc. # # SPDX-License-Identifier: Apache-2.0 # @@ -44,12 +44,13 @@ PATCH_SCRIPTS = { } class PatchBuilder(object): - def __init__(self, patch_recipe_file): + def __init__(self, patch_recipe_file, file_name): self.metadata = metadata.PatchMetadata(patch_recipe_file) self.metadata.parse_input_xml_data() self.fetch_debs = fetch_debs.FetchDebs() self.fetch_debs.need_dl_stx_pkgs = self.metadata.stx_packages self.fetch_debs.need_dl_binary_pkgs = self.metadata.binary_packages + self.patch_name = f'{self.metadata.patch_id}.patch' if file_name == None else file_name def get_md5(self, path): ''' @@ -64,7 +65,7 @@ class PatchBuilder(object): return int(md5.hexdigest(), 16) def build_patch(self): - logger.info(f"Generating patch {self.metadata.patch_id}") + logger.info(f"Generating patch {self.patch_name}") # Fetch debs from metadata and # Create software.tar, metadata.tar and signatures # Create a temporary working directory @@ -117,7 +118,7 @@ class PatchBuilder(object): os.remove("metadata.xml") # Pack .patch file - self.__sign_and_pack(f'{self.metadata.patch_id}.patch') + self.__sign_and_pack(self.patch_name) def copy_script(self, script_type, install_script): if not os.path.isfile(install_script): @@ -201,8 +202,11 @@ class PatchBuilder(object): @click.command() @click.option('--recipe', help='Patch recipe input XML file, examples are available under EXAMLES directory', required=True) -def build(recipe): - patch_builder = PatchBuilder(recipe) +@click.option('--name', help='Allow user to define name of the patch file. e.g.: test-sample-rr.patch. \ + Name will default to patch_id if not defined', + required=False) +def build(recipe, name: None): + patch_builder = PatchBuilder(recipe, name) patch_builder.build_patch() if __name__ == '__main__':