patch-builder: source controlled patch scripts

With this change, when a patch script path is provided by the user
in the patch XML, if it is not an absolute path and if the script
is not found in the current directory, then the search will
proceed into MY_REPO_ROOT_DIR.

The advantage of this is that the patch XML can now point
to source controlled scripts (saved in the STX repos) more easily,
without having to know the 'user' or 'project' used to create
the builder container where the patch-builder script is running.

Test Plan:
pass - Include script from source controlled repo

Story: 2011498
Task: 52895

Change-Id: I49efe3fa0bd2ac50e02e27942a715ad1c5c38cb6
Signed-off-by: Leonardo Fagundes Luz Serrano <Leonardo.FagundesLuzSerrano@windriver.com>
This commit is contained in:
Leonardo Fagundes Luz Serrano
2025-10-08 17:19:08 -03:00
parent 67ed517c9e
commit e543ce0732

View File

@@ -238,19 +238,32 @@ class PatchMetadata(object):
def check_script_path(self, script_path):
""" Process and validate script path
Check if path points to an existing file.
If path is relative, look for the script using as parent dir
the current directory, then fallback to MY_REPO_ROOT_DIR
(ie.: /localdisk/designer/USER/PROJECT/)
"""
# Case: No input provided
if not script_path:
# No scripts provided
return None
if not os.path.isabs(script_path):
script_path = os.path.join(os.getcwd(), script_path)
# Cases: Absolute path and path relative to curdir
candidate = os.path.abspath(script_path)
if os.path.isfile(candidate):
return candidate
if not os.path.isfile(script_path):
erro_msg = f"Install script {script_path} not found"
logger.error(erro_msg)
raise FileNotFoundError(erro_msg)
# Case: Path relative to MY_REPO_ROOT_DIR
parent = utils.get_env_variable('MY_REPO_ROOT_DIR')
candidate = os.path.join(parent, script_path)
if os.path.isfile(candidate):
return candidate
return script_path
msg = f"Script not found: {script_path}"
logger.error(msg)
raise FileNotFoundError(msg)
if __name__ == "__main__":