From 0c40313bd5271aa709860b64af3012251d699536 Mon Sep 17 00:00:00 2001 From: Ralf Hubert Date: Fri, 31 May 2024 09:08:01 +0200 Subject: [PATCH] input: apply env substition to checkoutAssert MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If variables are used to control the checkout of a package the checkoutAssert might need to be variable as well. Co-authored-by: Jan Klötzke --- doc/manual/configuration.rst | 2 ++ pym/bob/input.py | 26 ++++++++++++------- .../checkoutAssert/recipes/root.yaml | 4 +-- test/black-box/checkoutAssert/run.sh | 2 +- 4 files changed, 22 insertions(+), 12 deletions(-) diff --git a/doc/manual/configuration.rst b/doc/manual/configuration.rst index a97949a2d..547f71d66 100644 --- a/doc/manual/configuration.rst +++ b/doc/manual/configuration.rst @@ -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: diff --git a/pym/bob/input.py b/pym/bob/input.py index c0c1f5a2e..1eeb03cbe 100644 --- a/pym/bob/input.py +++ b/pym/bob/input.py @@ -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 { @@ -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=[], @@ -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 @@ -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 @@ -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): diff --git a/test/black-box/checkoutAssert/recipes/root.yaml b/test/black-box/checkoutAssert/recipes/root.yaml index f2c15c19b..c9a6e18d6 100644 --- a/test/black-box/checkoutAssert/recipes/root.yaml +++ b/test/black-box/checkoutAssert/recipes/root.yaml @@ -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 diff --git a/test/black-box/checkoutAssert/run.sh b/test/black-box/checkoutAssert/run.sh index d0be22329..831f160d4 100755 --- a/test/black-box/checkoutAssert/run.sh +++ b/test/black-box/checkoutAssert/run.sh @@ -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