Skip to content

Commit

Permalink
input: move tool fingerprint mask into steps
Browse files Browse the repository at this point in the history
To calculate the variant-id, the applicable tools for each step must be
known. The variant-id of a step is calculated already in its
constructor. So far this worked because the list of used tools was
static for each recipe. Now that we want to make tool usage conditional,
we have to pass the tool mask directly into each step.
  • Loading branch information
jkloetzke committed Aug 2, 2024
1 parent f6e486b commit 9e546cc
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions pym/bob/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -1360,10 +1360,12 @@ def hasNetAccess(self):


class CoreBuildStep(CoreStep):
__slots__ = []
__slots__ = ["fingerprintMask"]

def __init__(self, corePackage, script=(None, None, None), digestEnv=Env(), env=Env(), args=[]):
def __init__(self, corePackage, script=(None, None, None), digestEnv=Env(),
env=Env(), args=[], fingerprintMask=0):
isValid = script[1] is not None
self.fingerprintMask = fingerprintMask
super().__init__(corePackage, isValid, True, digestEnv, env, args)

def _getToolKeys(self):
Expand Down Expand Up @@ -1393,19 +1395,6 @@ def getMainScript(self):
def getDigestScript(self):
return self.corePackage.recipe.buildDigestScript

@property
def fingerprintMask(self):
# Remove bits of all tools that are not used in buildStep
ret = self.corePackage.fingerprintMask
i = 3
ourToolKeys = self.corePackage.recipe.toolDepBuild
packageToolKeys = self.corePackage.recipe.toolDepPackage
for t in sorted(packageToolKeys):
if t not in ourToolKeys:
ret &= ~i
i <<= 2
return ret

class BuildStep(Step):

def hasNetAccess(self):
Expand All @@ -1414,10 +1403,12 @@ def hasNetAccess(self):


class CorePackageStep(CoreStep):
__slots__ = []
__slots__ = ["fingerprintMask"]

def __init__(self, corePackage, script=(None, None, None), digestEnv=Env(), env=Env(), args=[]):
def __init__(self, corePackage, script=(None, None, None), digestEnv=Env(), env=Env(), args=[],
fingerprintMask=0):
isValid = script[1] is not None
self.fingerprintMask = fingerprintMask
super().__init__(corePackage, isValid, True, digestEnv, env, args)

def _getToolKeys(self):
Expand Down Expand Up @@ -1447,10 +1438,6 @@ def getMainScript(self):
def getDigestScript(self):
return self.corePackage.recipe.packageDigestScript

@property
def fingerprintMask(self):
return self.corePackage.fingerprintMask

class PackageStep(Step):

def isShared(self):
Expand Down Expand Up @@ -1480,10 +1467,10 @@ def refDeref(self, stack, inputTools, inputSandbox, pathFormatter, cache=None):
class CorePackage:
__slots__ = ("recipe", "internalRef", "directDepSteps", "indirectDepSteps",
"states", "tools", "sandbox", "checkoutStep", "buildStep", "packageStep",
"pkgId", "fingerprintMask", "metaEnv")
"pkgId", "metaEnv")

def __init__(self, recipe, tools, diffTools, sandbox, diffSandbox,
directDepSteps, indirectDepSteps, states, pkgId, fingerprintMask, metaEnv):
directDepSteps, indirectDepSteps, states, pkgId, metaEnv):
self.recipe = recipe
self.tools = tools
self.sandbox = sandbox
Expand All @@ -1492,7 +1479,6 @@ def __init__(self, recipe, tools, diffTools, sandbox, diffSandbox,
self.indirectDepSteps = indirectDepSteps
self.states = states
self.pkgId = pkgId
self.fingerprintMask = fingerprintMask
self.metaEnv = metaEnv

def refDeref(self, stack, inputTools, inputSandbox, pathFormatter):
Expand All @@ -1509,16 +1495,17 @@ def createInvalidCoreCheckoutStep(self):
ret = self.checkoutStep = CoreCheckoutStep(self)
return ret

def createCoreBuildStep(self, script, digestEnv, env, args):
ret = self.buildStep = CoreBuildStep(self, script, digestEnv, env, args)
def createCoreBuildStep(self, script, digestEnv, env, args, fingerprintMask):
ret = self.buildStep = CoreBuildStep(self, script, digestEnv, env, args,
fingerprintMask)
return ret

def createInvalidCoreBuildStep(self, args):
ret = self.buildStep = CoreBuildStep(self, args=args)
return ret

def createCorePackageStep(self, script, digestEnv, env, args):
ret = self.packageStep = CorePackageStep(self, script, digestEnv, env, args)
def createCorePackageStep(self, script, digestEnv, env, args, fingerprintMask):
ret = self.packageStep = CorePackageStep(self, script, digestEnv, env, args, fingerprintMask)
return ret

def getCorePackageStep(self):
Expand Down Expand Up @@ -2525,6 +2512,16 @@ def prepare(self, inputEnv, sandboxEnabled, inputStates, inputSandbox=None,
if doFingerprint:
doFingerprint |= doFingerprintMaybe

# Remove bits of all tools that are not used in buildStep. In case
# you're wondering: the checkout step is never fingerprinted because
# the sources are hashed.
doFingerprintBuild = doFingerprint
mask = 3
for t in sorted(self.__toolDepPackage):
if t not in self.__toolDepBuild:
doFingerprintBuild &= ~mask
mask <<= 2

# check that all tools that are required are available
toolsDetached = tools.detach()
if self.__recipeSet.getPolicy('noUndefinedTools') and \
Expand All @@ -2536,7 +2533,7 @@ def prepare(self, inputEnv, sandboxEnabled, inputStates, inputSandbox=None,
# touchedTools = tools.touchedKeys()
# diffTools = { n : t for n,t in diffTools.items() if n in touchedTools }
p = CorePackage(self, toolsDetached, diffTools, sandbox, diffSandbox,
directPackages, indirectPackages, states, uidGen(), doFingerprint, metaEnv)
directPackages, indirectPackages, states, uidGen(), metaEnv)

# optional checkout step
if self.__checkout != (None, None, None) or self.__checkoutSCMs or self.__checkoutAsserts:
Expand Down Expand Up @@ -2570,7 +2567,7 @@ def prepare(self, inputEnv, sandboxEnabled, inputStates, inputSandbox=None,
buildEnv = ( env.prune(self.__buildVars | self.__buildVarsWeak)
if self.__buildVarsWeak else buildDigestEnv )
buildCoreStep = p.createCoreBuildStep(self.__build, buildDigestEnv, buildEnv,
[CoreRef(srcCoreStep)] + results)
[CoreRef(srcCoreStep)] + results, doFingerprintBuild)
else:
buildCoreStep = p.createInvalidCoreBuildStep([CoreRef(srcCoreStep)] + results)

Expand All @@ -2579,7 +2576,7 @@ def prepare(self, inputEnv, sandboxEnabled, inputStates, inputSandbox=None,
packageEnv = ( env.prune(self.__packageVars | self.__packageVarsWeak)
if self.__packageVarsWeak else packageDigestEnv )
packageCoreStep = p.createCorePackageStep(self.__package, packageDigestEnv, packageEnv,
[CoreRef(buildCoreStep)])
[CoreRef(buildCoreStep)], doFingerprint)

# provide environment
provideEnv = {}
Expand Down

0 comments on commit 9e546cc

Please sign in to comment.