Skip to content

Commit

Permalink
Merge pull request #567 from rhubert/checkoutAssert_Env
Browse files Browse the repository at this point in the history
input: apply env substition to checkoutAssert
  • Loading branch information
jkloetzke authored Jun 5, 2024
2 parents 8f17598 + 0c40313 commit 63a01b7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
2 changes: 2 additions & 0 deletions doc/manual/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,8 @@ Line numbers start at 1 and are inclusive. The ``start`` line is always taken
into account even if the ``end`` line is equal or smaller. The line terminator
is always ``\n`` (ASCII "LF", 0x0a) regardless of the host operating system.

String substitution is applied to every setting.

Example::

checkoutAssert:
Expand Down
26 changes: 17 additions & 9 deletions pym/bob/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,16 +401,23 @@ class CheckoutAssert:
SCHEMA = schema.Schema({
'file' : str,
'digestSHA1' : str,
schema.Optional('start') : schema.And(int, lambda n: n >= 1),
schema.Optional('end') : schema.And(int, lambda n: n >= 1),
schema.Optional('start') : schema.Or(str, int),
schema.Optional('end') : schema.Or(str, int)
})

def __init__(self, spec):
def __init__(self, spec, env=None):
if env is not None:
spec = {k: ( env.substitute(v, "checkoutAssert::"+ k) if isinstance(v, str) else v)
for (k, v) in spec.items()}
self.__source = spec['__source']
self.__file = spec['file']
self.__digestSHA1 = spec['digestSHA1']
self.__start = spec.get('start', 1)
self.__end = spec.get('end', 0xffffffff)
self.__start = int(spec.get('start', 1))
self.__end = int(spec.get('end', 0xffffffff))
if self.__start < 1:
raise ParseError("CheckoutAssert: First line must be greater than zero")
if self.__end < 1:
raise ParseError("CheckoutAssert: Last line must be greater than zero")

def getProperties(self):
return {
Expand Down Expand Up @@ -1220,7 +1227,7 @@ def _getFingerprintScript(self):


class CoreCheckoutStep(CoreStep):
__slots__ = ( "scmList", "__checkoutUpdateIf", "__checkoutUpdateDeterministic" )
__slots__ = ( "scmList", "__checkoutUpdateIf", "__checkoutUpdateDeterministic", "__checkoutAsserts" )

def __init__(self, corePackage, checkout=None, checkoutSCMs=[],
fullEnv=Env(), digestEnv=Env(), env=Env(), args=[],
Expand Down Expand Up @@ -1261,6 +1268,7 @@ def __init__(self, corePackage, checkout=None, checkoutSCMs=[],
isValid = False
self.scmList = []

self.__checkoutAsserts = [ CheckoutAssert (a, fullEnv) for a in corePackage.recipe.checkoutAsserts ]
self.__checkoutUpdateIf = checkoutUpdateIf
self.__checkoutUpdateDeterministic = checkoutUpdateDeterministic
deterministic = corePackage.recipe.checkoutDeterministic
Expand Down Expand Up @@ -1306,14 +1314,14 @@ def getMainScript(self):
return self.corePackage.recipe.checkoutMainScript

def getPostRunCmds(self):
return [s.getProperties() for s in self.corePackage.recipe.checkoutAsserts]
return [s.getProperties() for s in self.__checkoutAsserts]

def getDigestScript(self):
if self.isValid:
recipe = self.corePackage.recipe
return "\n".join([s.asDigestScript() for s in self.scmList]
+ [recipe.checkoutDigestScript]
+ [s.asDigestScript() for s in recipe.checkoutAsserts])
+ [s.asDigestScript() for s in self.__checkoutAsserts])
else:
return None

Expand Down Expand Up @@ -2667,7 +2675,7 @@ def checkoutDeterministic(self):

@property
def checkoutAsserts(self):
return [ CheckoutAssert(cassert) for cassert in self.__checkoutAsserts ]
return self.__checkoutAsserts

@property
def checkoutVars(self):
Expand Down
4 changes: 2 additions & 2 deletions test/black-box/checkoutAssert/recipes/root.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ checkoutScript: |
checkoutAssert:
-
file: gpl3.txt
start: 1
start: "${GPL3_START}"
end: 4
digestSHA1: 158b94393dfdad277ff26017663c1c56676aaa84
digestSHA1: "${GPL3_1_4_SHA1}"
-
file: gpl3.txt
digestSHA1: 08481bca10b37e1d13d9163515522f774c262cdb
Expand Down
2 changes: 1 addition & 1 deletion test/black-box/checkoutAssert/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
cleanup

# checkoutAssert shouldn't trigger in this test
run_bob dev root
run_bob dev root -DGPL3_START=1 -DGPL3_1_4_SHA1=158b94393dfdad277ff26017663c1c56676aaa84

# checkoutAssert should make the build fail in this test
expect_fail run_bob dev root_fail

0 comments on commit 63a01b7

Please sign in to comment.