Skip to content

Commit

Permalink
import: add recipe relative urls
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jkloetzke committed Jan 8, 2025
1 parent 8502cf9 commit e39254a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pym/bob/scm/imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class ImportScm(Scm):
DEFAULTS = {
schema.Optional('dir') : str,
schema.Optional('prune') : bool,
schema.Optional('recipeRelative') : bool,
}

__SCHEMA = {
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions pym/bob/scm/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ def _diffSpec(self, oldScm):
ret -= {"if"}
return ret

def _getRecipe(self):
return self.__recipe

def getSource(self):
return self.__source

Expand Down

0 comments on commit e39254a

Please sign in to comment.