From e39254a59438434e5c99b5dfe0b7209cf1b288ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kl=C3=B6tzke?= Date: Fri, 27 Dec 2024 22:11:21 +0100 Subject: [PATCH] import: add recipe relative urls The import SCM base directory is the project root directory. This is useless for recipes in layers because they don't know their location in the project. The new "recipeRelative" property can pivot the base directory to the one where the recipe is located. --- pym/bob/scm/imp.py | 11 +++++++++-- pym/bob/scm/scm.py | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pym/bob/scm/imp.py b/pym/bob/scm/imp.py index 076171f6..43b4a917 100644 --- a/pym/bob/scm/imp.py +++ b/pym/bob/scm/imp.py @@ -116,6 +116,7 @@ class ImportScm(Scm): DEFAULTS = { schema.Optional('dir') : str, schema.Optional('prune') : bool, + schema.Optional('recipeRelative') : bool, } __SCHEMA = { @@ -134,6 +135,11 @@ def __init__(self, spec, overrides=[], pruneDefault=None, fixDigestBug=False, pr self.__data = spec.get("__data") self.__projectRoot = spec.get("__projectRoot", projectRoot) self.__fixDigestBug = fixDigestBug + self.__recipeRelative = spec.get("recipeRelative", False) + + def _getSrcDir(self): + rootDir = os.path.dirname(self._getRecipe()) if self.__recipeRelative else self.__projectRoot + return os.path.join(rootDir, self.__url) def getProperties(self, isJenkins, pretty=False): ret = super().getProperties(isJenkins) @@ -142,9 +148,10 @@ def getProperties(self, isJenkins, pretty=False): 'url' : self.__url, 'dir' : self.__dir, 'prune' : self.__prune, + 'recipeRelative' : self.__recipeRelative, }) if isJenkins: - ret['__data'] = packTree(self.__url) + ret['__data'] = packTree(self._getSrcDir()) else: ret['__projectRoot'] = self.__projectRoot return ret @@ -154,7 +161,7 @@ async def invoke(self, invoker): os.makedirs(dest, exist_ok=True) if self.__prune: emptyDirectory(dest) if self.__data is None: - src = os.path.join(self.__projectRoot, self.__url) + src = self._getSrcDir() if not os.path.isdir(src): invoker.fail("Cannot import '{}': not a directory!".format(src)) copyTree(src, dest, invoker) diff --git a/pym/bob/scm/scm.py b/pym/bob/scm/scm.py index abbd2eb0..bef6adbd 100644 --- a/pym/bob/scm/scm.py +++ b/pym/bob/scm/scm.py @@ -231,6 +231,9 @@ def _diffSpec(self, oldScm): ret -= {"if"} return ret + def _getRecipe(self): + return self.__recipe + def getSource(self): return self.__source