Skip to content

Commit df37550

Browse files
committed
urlscm: separate download directory
1 parent 5ae94e9 commit df37550

File tree

6 files changed

+44
-8
lines changed

6 files changed

+44
-8
lines changed

Diff for: doc/manual/policies.rst

+16
Original file line numberDiff line numberDiff line change
@@ -626,3 +626,19 @@ New behavior
626626
passed to the ``fingerprintScript``. Other environment variables are unset
627627
but whitelisted variables (see :ref:`configuration-config-whitelist`) are
628628
still available.
629+
630+
scmOnlyExtracted
631+
~~~~~~~~~~~~~~~~
632+
633+
Introduced in: 0.25
634+
635+
This policy controls if the downloaded file of a UrlScm is stored in the source
636+
workspace when extractors are available for it.
637+
638+
Old behavior
639+
Downloaded original and `.extracted` canary file are part of the source
640+
workspace.
641+
642+
New behavior
643+
If a extractor is available the downloaded file and the canary are stored in
644+
workspace/../_downloaded.

Diff for: pym/bob/builder.py

+2
Original file line numberDiff line numberDiff line change
@@ -1216,6 +1216,8 @@ async def _cookCheckoutStep(self, checkoutStep, depth):
12161216
os.rename(scmPath, atticPath)
12171217
BobState().setAtticDirectoryState(atticPath, scmSpec)
12181218
atticPaths.add(scmPath, atticPath)
1219+
downloadPath = os.path.normpath(os.path.join(prettySrcPath, "..", "_download", scmDir))
1220+
shutil.rmtree(downloadPath, ignore_errors=True)
12191221
del oldCheckoutState[scmDir]
12201222
BobState().setDirectoryState(prettySrcPath, oldCheckoutState)
12211223

Diff for: pym/bob/input.py

+6
Original file line numberDiff line numberDiff line change
@@ -2959,6 +2959,7 @@ class RecipeSet:
29592959
schema.Optional('gitCommitOnBranch') : bool,
29602960
schema.Optional('fixImportScmVariant') : bool,
29612961
schema.Optional('defaultFileMode') : bool,
2962+
schema.Optional('scmOnlyExtracted') : bool,
29622963
},
29632964
error="Invalid policy specified! Are you using an appropriate version of Bob?"
29642965
),
@@ -3046,6 +3047,11 @@ def __init__(self):
30463047
InfoOnce("defaultFileMode policy not set. File mode of URL SCMs not set for locally copied files.",
30473048
help="See http://bob-build-tool.readthedocs.io/en/latest/manual/policies.html#defaultfilemode for more information.")
30483049
),
3050+
"scmOnlyExtracted": (
3051+
"0.24.1.dev105",
3052+
InfoOnce("scmOnlyExtracted policy is not set. Downloaded original is part of the source workspace",
3053+
help="See http://bob-build-tool.readthedocs.io/en/latest/manual/policies.html#scmOnlyExtracted for more information.")
3054+
),
30493055
}
30503056
self.__buildHooks = {}
30513057
self.__sandboxOpts = {}

Diff for: pym/bob/intermediate.py

+1
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ def fromRecipeSet(cls, recipeSet):
549549
'gitCommitOnBranch' : recipeSet.getPolicy('gitCommitOnBranch'),
550550
'fixImportScmVariant' : recipeSet.getPolicy('fixImportScmVariant'),
551551
'defaultFileMode' : recipeSet.getPolicy('defaultFileMode'),
552+
'scmOnlyExtracted' : recipeSet.getPolicy('scmOnlyExtracted'),
552553
}
553554
self.__data['archiveSpec'] = recipeSet.archiveSpec()
554555
self.__data['envWhiteList'] = sorted(recipeSet.envWhiteList())

Diff for: pym/bob/scm/__init__.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ def getScm(spec, overrides=[], recipeSet=None):
6262
recipeSet and recipeSet.getPolicy('scmIgnoreUser'),
6363
recipeSet.getPreMirrors() if recipeSet else [],
6464
recipeSet.getFallbackMirrors() if recipeSet else [],
65-
recipeSet and recipeSet.getPolicy('defaultFileMode'))
65+
recipeSet and recipeSet.getPolicy('defaultFileMode'),
66+
recipeSet and recipeSet.getPolicy('scmOnlyExtracted'))
6667
else:
6768
raise ParseError("Unknown SCM '{}'".format(scm))

Diff for: pym/bob/scm/url.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ class UrlScm(Scm):
223223
}
224224

225225
def __init__(self, spec, overrides=[], stripUser=None,
226-
preMirrors=[], fallbackMirrors=[], defaultFileMode=None):
226+
preMirrors=[], fallbackMirrors=[], defaultFileMode=None,
227+
onlyExtracted=True):
227228
super().__init__(spec, overrides)
228229
self.__url = spec["url"]
229230
self.__digestSha1 = spec.get("digestSHA1")
@@ -262,6 +263,7 @@ def __init__(self, spec, overrides=[], stripUser=None,
262263
self.__fallbackMirrorsUrls = spec.get("fallbackMirrors")
263264
self.__fallbackMirrorsUpload = spec.get("__fallbackMirrorsUpload")
264265
self.__fileMode = spec.get("fileMode", 0o600 if defaultFileMode else None)
266+
self.__onlyExtracted = spec.get("onlyExtracted", onlyExtracted)
265267

266268
def getProperties(self, isJenkins, pretty=False):
267269
ret = super().getProperties(isJenkins)
@@ -282,6 +284,7 @@ def getProperties(self, isJenkins, pretty=False):
282284
'fallbackMirrors' : self.__getFallbackMirrorsUrls(),
283285
'__fallbackMirrorsUpload' : self.__getFallbackMirrorsUpload(),
284286
'fileMode' : dumpMode(self.__fileMode) if pretty else self.__fileMode,
287+
'onlyExtracted' : self.__onlyExtracted,
285288
})
286289
return ret
287290

@@ -536,9 +539,14 @@ async def switch(self, invoker, oldScm):
536539
return True
537540

538541
async def invoke(self, invoker):
539-
os.makedirs(invoker.joinPath(self.__dir), exist_ok=True)
540-
workspaceFile = os.path.join(self.__dir, self.__fn)
541-
destination = invoker.joinPath(self.__dir, self.__fn)
542+
extractors = self.__getExtractors()
543+
downloadDestination = ""
544+
if extractors and self.__onlyExtracted:
545+
downloadDestination = os.path.join("..", "_download", self.__dir)
546+
547+
os.makedirs(invoker.joinPath(self.__dir, downloadDestination), exist_ok=True)
548+
destination = invoker.joinPath(self.__dir, downloadDestination, self.__fn)
549+
workspaceFile = os.path.join(self.__dir, downloadDestination, self.__fn)
542550

543551
# Download only if necessary
544552
if not self.isDeterministic() or not os.path.isfile(destination):
@@ -587,8 +595,7 @@ async def invoke(self, invoker):
587595
await self._put(invoker, workspaceFile, destination, url)
588596

589597
# Run optional extractors
590-
extractors = self.__getExtractors()
591-
canary = invoker.joinPath(self.__dir, "." + self.__fn + ".extracted")
598+
canary = invoker.joinPath(self.__dir, downloadDestination, "." + self.__fn + ".extracted")
592599
if extractors and isYounger(destination, canary):
593600
for cmd in extractors:
594601
if shutil.which(cmd[0]) is None: continue
@@ -672,7 +679,10 @@ def __getExtractors(self):
672679
strip = [extractor[3].format(self.__strip)]
673680
else:
674681
strip = []
675-
ret.append([extractor[1]] + [a.format(self.__fn) for a in extractor[2]] + strip)
682+
fileToExtract = self.__fn
683+
if self.__onlyExtracted:
684+
fileToExtract = os.path.join("..", "_download", self.__dir, self.__fn)
685+
ret.append([extractor[1]] + [a.format(fileToExtract) for a in extractor[2]] + strip)
676686

677687
if not ret:
678688
raise BuildError("Extractor does not support 'stripComponents'!")

0 commit comments

Comments
 (0)