Skip to content

Commit 2d829b4

Browse files
authored
Merge pull request #607 from jkloetzke/import-scm-root
Add recipe-relative import SCMs
2 parents e325c8a + 4a6ef0c commit 2d829b4

File tree

8 files changed

+52
-7
lines changed

8 files changed

+52
-7
lines changed

doc/manual/configuration.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,7 @@ git | ``url``: URL of remote repository
957957
| ``dissociate``: (Boolean, default false). Dissociate the reference (see man git-clone).
958958
import | ``url``: Directory path relative to project root.
959959
| ``prune`` (\*): Delete destination directory before importing files.
960+
| ``recipeRelative`` (\*): Whether ``url`` is relative to recipe or project root. (optional)
960961
svn | ``url``: URL of SVN module
961962
| ``revision``: Optional revision number (optional)
962963
| ``sslVerify`` (\*): Whether to verify the SSL certificate when fetching (optional)
@@ -1109,15 +1110,15 @@ git
11091110

11101111
import
11111112
The ``import`` SCM copies the directory specified in ``url`` to the
1112-
workspace. By default the destination is always overwritten and obsolete
1113+
workspace. By default, the destination is always overwritten and obsolete
11131114
files are deleted. Set ``prune`` to ``False`` to only overwrite if the
11141115
source file was changed more recently than the exiting destination in the
1115-
workspace. Before Bob 0.18 the default was the other way around (see
1116+
workspace. Before Bob 0.18, the default was the other way around (see
11161117
:ref:`policies-pruneImportScm`).
11171118

1118-
In contrast to the other SCMs that fetch across the network the ``import``
1119+
In contrast to the other SCMs that fetch across the network, the ``import``
11191120
SCM is always updated, even if ``--build-only`` is used. Because only local
1120-
files are imported there is no possibility to inadvertely fetch unwanted
1121+
files are imported, there is no possibility to inadvertently fetch unwanted
11211122
changes from other users. The files should thus always be edited at the
11221123
import source location and not in the workspace.
11231124

@@ -1126,6 +1127,11 @@ import
11261127
content is included in the job configuration that will get too large
11271128
otherwise.
11281129

1130+
By default, the directory given in ``url`` is interpreted relative to the
1131+
project root. Alternatively, ``url`` can be made relative to the recipe
1132+
itself if ``recipeRelative`` is set to ``True``. This is recommended
1133+
especially for recipes that are included as layers into other projects.
1134+
11291135
svn
11301136
The `Svn`_ SCM, like git, requires the ``url`` attribute too. If you specify a
11311137
numeric ``revision`` Bob considers the SCM as deterministic.

pym/bob/input.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,9 @@ def validate(self, data):
370370

371371
def Scm(spec, env, overrides, recipeSet):
372372
# resolve with environment
373-
spec = { k : ( env.substitute(v, "checkoutSCM::"+k) if isinstance(v, str) else v)
373+
spec = { k : ( env.substitute(v, "checkoutSCM::"+k)
374+
if isinstance(v, str) and k not in ('__source', 'recipe')
375+
else v )
374376
for (k, v) in spec.items() }
375377

376378
# apply overrides before creating scm instances. It's possible to switch the Scm type with an override..

pym/bob/scm/imp.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ class ImportScm(Scm):
116116
DEFAULTS = {
117117
schema.Optional('dir') : str,
118118
schema.Optional('prune') : bool,
119+
schema.Optional('recipeRelative') : bool,
119120
}
120121

121122
__SCHEMA = {
@@ -134,6 +135,11 @@ def __init__(self, spec, overrides=[], pruneDefault=None, fixDigestBug=False, pr
134135
self.__data = spec.get("__data")
135136
self.__projectRoot = spec.get("__projectRoot", projectRoot)
136137
self.__fixDigestBug = fixDigestBug
138+
self.__recipeRelative = spec.get("recipeRelative", False)
139+
140+
def _getSrcDir(self):
141+
rootDir = os.path.dirname(self._getRecipe()) if self.__recipeRelative else self.__projectRoot
142+
return os.path.join(rootDir, self.__url)
137143

138144
def getProperties(self, isJenkins, pretty=False):
139145
ret = super().getProperties(isJenkins)
@@ -142,9 +148,10 @@ def getProperties(self, isJenkins, pretty=False):
142148
'url' : self.__url,
143149
'dir' : self.__dir,
144150
'prune' : self.__prune,
151+
'recipeRelative' : self.__recipeRelative,
145152
})
146153
if isJenkins:
147-
ret['__data'] = packTree(self.__url)
154+
ret['__data'] = packTree(self._getSrcDir())
148155
else:
149156
ret['__projectRoot'] = self.__projectRoot
150157
return ret
@@ -154,7 +161,7 @@ async def invoke(self, invoker):
154161
os.makedirs(dest, exist_ok=True)
155162
if self.__prune: emptyDirectory(dest)
156163
if self.__data is None:
157-
src = os.path.join(self.__projectRoot, self.__url)
164+
src = self._getSrcDir()
158165
if not os.path.isdir(src):
159166
invoker.fail("Cannot import '{}': not a directory!".format(src))
160167
copyTree(src, dest, invoker)

pym/bob/scm/scm.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ def _diffSpec(self, oldScm):
231231
ret -= {"if"}
232232
return ret
233233

234+
def _getRecipe(self):
235+
return self.__recipe
236+
234237
def getSource(self):
235238
return self.__source
236239

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bobMinimumVersion: "0.25"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
root: True
2+
checkoutSCM:
3+
scm: import
4+
url: data
5+
recipeRelative: True
6+
buildScript: cp -a "$1/"* .
7+
packageScript: cp -a "$1/"* .
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/bash -e
2+
#
3+
# Test recipeRelative "import" SCM property
4+
#
5+
. ../../test-lib.sh 2>/dev/null || { echo "Must run in script directory!" ; exit 1 ; }
6+
7+
cleanup
8+
9+
# First try in-tree build
10+
run_bob dev sub::root
11+
diff -Nrq recipes/sub/data dev/dist/sub/root/1/workspace
12+
13+
# Out of tree builds should work as well
14+
build="$(mktemp -d)"
15+
trap 'rm -rf "$build"' EXIT
16+
run_bob init . "$build"
17+
run_bob -C "$build" dev sub::root
18+
diff -Nrq recipes/sub/data "$build/dev/dist/sub/root/1/workspace"

0 commit comments

Comments
 (0)