Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input: apply env substition to checkoutAssert #567

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
jkloetzke marked this conversation as resolved.
Show resolved Hide resolved

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
Loading