From c1fa37d5415017d94c0ab337dffb235091451c78 Mon Sep 17 00:00:00 2001 From: Dostoievski Batista Date: Thu, 31 Oct 2024 15:04:25 -0300 Subject: [PATCH] Add option for activation scripts on patch build This change adds the option 'activation scripts' to the patch recipe, allowing the user to add one or multiples scripts that will be copied to the patch and added to the metadata. Test plan: PASS - Create patch with one activation script, check if file is on patch and check value in the patch's metadata. PASS - Create patch with multiple activation scripts, check if files are inside the patch and check values in the patch's metadata. PASS - Create patch without any activation script, check if files are inside the patch and check if value in the patch's metadata. PASS - Check if patch-builder fails when patch recipe doesn't have activate script element. Story: 2010676 Task: 51239 Change-Id: I7073f59dfd7eefa0986a39fd70d4207bb437c9ba Signed-off-by: Dostoievski Batista --- .../EXAMPLES/patch-recipe-sample-binary.xml | 1 + .../EXAMPLES/patch-recipe-sample-insvc.xml | 1 + .../EXAMPLES/patch-recipe-sample-large.xml | 1 + .../patch/EXAMPLES/patch-recipe-sample.xml | 1 + build-tools/stx/patch/README.md | 9 ++++- .../stx/patch/config/patch-recipe-schema.xsd | 7 ++++ build-tools/stx/patch/metadata.py | 35 ++++++++++++++++++- build-tools/stx/patch/patch-builder | 5 +++ 8 files changed, 58 insertions(+), 2 deletions(-) diff --git a/build-tools/stx/patch/EXAMPLES/patch-recipe-sample-binary.xml b/build-tools/stx/patch/EXAMPLES/patch-recipe-sample-binary.xml index 2e6df778..95e65f07 100644 --- a/build-tools/stx/patch/EXAMPLES/patch-recipe-sample-binary.xml +++ b/build-tools/stx/patch/EXAMPLES/patch-recipe-sample-binary.xml @@ -17,6 +17,7 @@ --> + scripts/pre-install.sh diff --git a/build-tools/stx/patch/EXAMPLES/patch-recipe-sample-insvc.xml b/build-tools/stx/patch/EXAMPLES/patch-recipe-sample-insvc.xml index 9477475e..1622a5e0 100644 --- a/build-tools/stx/patch/EXAMPLES/patch-recipe-sample-insvc.xml +++ b/build-tools/stx/patch/EXAMPLES/patch-recipe-sample-insvc.xml @@ -12,6 +12,7 @@ DEV + diff --git a/build-tools/stx/patch/EXAMPLES/patch-recipe-sample-large.xml b/build-tools/stx/patch/EXAMPLES/patch-recipe-sample-large.xml index 63e01c28..e5c2623e 100644 --- a/build-tools/stx/patch/EXAMPLES/patch-recipe-sample-large.xml +++ b/build-tools/stx/patch/EXAMPLES/patch-recipe-sample-large.xml @@ -17,6 +17,7 @@ --> + scripts/pre-install.sh diff --git a/build-tools/stx/patch/EXAMPLES/patch-recipe-sample.xml b/build-tools/stx/patch/EXAMPLES/patch-recipe-sample.xml index aaa64a74..aee60f68 100644 --- a/build-tools/stx/patch/EXAMPLES/patch-recipe-sample.xml +++ b/build-tools/stx/patch/EXAMPLES/patch-recipe-sample.xml @@ -17,6 +17,7 @@ --> + scripts/pre-install.sh diff --git a/build-tools/stx/patch/README.md b/build-tools/stx/patch/README.md index 22e0a925..bab171d0 100644 --- a/build-tools/stx/patch/README.md +++ b/build-tools/stx/patch/README.md @@ -39,9 +39,16 @@ The patch builder requires the following tags in the input xml (or patch recipe) --> + + + + scripts/pre-install.sh scripts/post-install.sh diff --git a/build-tools/stx/patch/config/patch-recipe-schema.xsd b/build-tools/stx/patch/config/patch-recipe-schema.xsd index 753942e4..cab7831e 100644 --- a/build-tools/stx/patch/config/patch-recipe-schema.xsd +++ b/build-tools/stx/patch/config/patch-recipe-schema.xsd @@ -22,6 +22,13 @@ + + + + + + + diff --git a/build-tools/stx/patch/metadata.py b/build-tools/stx/patch/metadata.py index 02cde61e..213cad72 100644 --- a/build-tools/stx/patch/metadata.py +++ b/build-tools/stx/patch/metadata.py @@ -45,6 +45,7 @@ PACKAGES = 'packages' STX_PACKAGES = 'stx_packages' BINARY_PACKAGES = 'binary_packages' SEMANTICS = 'semantics' +ACTIVATION_SCRIPTS = 'activation_scripts' class PatchMetadata(object): @@ -53,6 +54,7 @@ class PatchMetadata(object): self.stx_packages = [] self.binary_packages = [] self.requires = [] + self.activation_scripts = [] # Verify if the path to the patch builder folder is set if not PATCH_BUILDER_PATH: @@ -138,6 +140,13 @@ class PatchMetadata(object): else: self.__add_text_tag_to_xml(top_tag, POST_INSTALL, "") + if self.activation_scripts: + activation_scripts_tag = ET.SubElement(top_tag, ACTIVATION_SCRIPTS) + for script in self.activation_scripts: + self.__add_text_tag_to_xml(activation_scripts_tag, "script", script.split('/')[-1]) + else: + self.__add_text_tag_to_xml(top_tag, ACTIVATION_SCRIPTS, "") + packages_tag = ET.SubElement(top_tag, PACKAGES) for package in sorted(self.debs): self.__add_text_tag_to_xml(packages_tag, "deb", package) @@ -152,6 +161,19 @@ class PatchMetadata(object): return [tag_content] return tag_content + def _validate_activation_script(self, script_list): + ''' + Validate if scripts filename start with an integer + ''' + for fullpath_script in script_list: + try: + name = os.path.basename(fullpath_script) + int(name.split("-")[0]) + except Exception: + logger.error("Error while parsing the activation script:") + logger.error("Filename '%s' doesn't start with an integer." % fullpath_script) + sys.exit(1) + def parse_metadata(self, patch_recipe): self.patch_id = f"{patch_recipe[COMPONENT]}-{patch_recipe[SW_VERSION]}" self.sw_version = patch_recipe[SW_VERSION] @@ -172,6 +194,17 @@ class PatchMetadata(object): if 'id' in patch_recipe[REQUIRES]: self.requires = self.__tag_to_list(patch_recipe[REQUIRES]['id']) self.semantics = patch_recipe[SEMANTICS] + if 'script' in patch_recipe[ACTIVATION_SCRIPTS]: + # the xml parser transform the 'script' value in string or in + # array depending on how much elements we add. + scripts_lst = [] + if isinstance(patch_recipe[ACTIVATION_SCRIPTS]['script'], str): + scripts_lst.append(self.check_script_path(patch_recipe[ACTIVATION_SCRIPTS]['script'])) + else: + for script in patch_recipe[ACTIVATION_SCRIPTS]['script']: + scripts_lst.append(self.check_script_path(script)) + self._validate_activation_script(scripts_lst) + self.activation_scripts = scripts_lst self.debs = [] if self.status != 'DEV' and self.status != 'REL': @@ -202,7 +235,7 @@ class PatchMetadata(object): logger.error(f"Line {error.line}: {error.message}") sys.exit(1) - print(xml_dict) + logger.info(xml_dict) self.parse_metadata(xml_dict) diff --git a/build-tools/stx/patch/patch-builder b/build-tools/stx/patch/patch-builder index 99d9cbdb..dd0f1e34 100755 --- a/build-tools/stx/patch/patch-builder +++ b/build-tools/stx/patch/patch-builder @@ -97,6 +97,11 @@ class PatchBuilder(object): logger.debug(f"Copying post-install script: {post_install}") self.copy_rename_script(post_install, "POST_INSTALL") + # Copy all activate scripts + if self.metadata.activation_scripts: + for script in self.metadata.activation_scripts: + self.copy_rename_script(path_to_script=script, rename=False) + # if the patch includes the 'software' package we need to make deploy-precheck # and upgrade_utils.py from .deb file accessible directly from patch file if 'software' in self.metadata.stx_packages: