Skip to content

Commit 6b3815e

Browse files
committed
languages: handle included files out of band
Extracting included files in the executed script itself requires some code for each supported language. It's also cumbersome to clean up. Instead let the invoker handle the dirty details and just add the right reference in the final script.
1 parent 9ebb277 commit 6b3815e

File tree

3 files changed

+91
-62
lines changed

3 files changed

+91
-62
lines changed

pym/bob/input.py

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,19 @@ def fetchScripts(recipe, prefix, resolveBash, resolvePwsh):
136136
def mergeScripts(fragments, glue):
137137
"""Join all scripts of the recipe and its classes.
138138
139-
The result is a tuple with (setupScript, mainScript, digestScript)
139+
The result is a tuple with (setupScript, mainScript, digestScript, includedFiles)
140140
"""
141+
141142
return (
142143
joinScripts((f[0][0] for f in fragments), glue),
143144
joinScripts((f[1][0] for f in fragments), glue),
144145
joinScripts(
145146
( joinScripts((f[0][1] for f in fragments), "\n"),
146147
joinScripts((f[1][1] for f in fragments), "\n"),
147-
), "\n")
148+
), "\n"),
149+
{ name : content for name, content in
150+
chain.from_iterable(chain(f[0][2].items(), f[1][2].items()) for f in fragments)
151+
},
148152
)
149153

150154

@@ -790,6 +794,9 @@ def getPostRunCmds(self):
790794
def getDigestScript(self):
791795
raise NotImplementedError
792796

797+
def getIncludedFiles(self):
798+
raise NotImplementedError
799+
793800
def getLabel(self):
794801
raise NotImplementedError
795802

@@ -1042,6 +1049,9 @@ def getDigestScript(self):
10421049
"""
10431050
return self._coreStep.getDigestScript()
10441051

1052+
def getIncludedFiles(self):
1053+
return self._coreStep.getIncludedFiles()
1054+
10451055
def isDeterministic(self):
10461056
"""Return whether the step is deterministic.
10471057
@@ -1458,6 +1468,9 @@ def getDigestScript(self):
14581468
else:
14591469
return None
14601470

1471+
def getIncludedFiles(self):
1472+
return self.corePackage.recipe.checkoutIncludedFiles
1473+
14611474
@property
14621475
def fingerprintMask(self):
14631476
return 0
@@ -1537,7 +1550,7 @@ def hasNetAccess(self):
15371550
class CoreBuildStep(CoreStep):
15381551
__slots__ = []
15391552

1540-
def __init__(self, corePackage, script=(None, None, None), digestEnv=Env(), env=Env(), args=[]):
1553+
def __init__(self, corePackage, script=(None, None, None, {}), digestEnv=Env(), env=Env(), args=[]):
15411554
isValid = script[1] is not None
15421555
super().__init__(corePackage, isValid, True, digestEnv, env, args)
15431556

@@ -1568,6 +1581,9 @@ def getMainScript(self):
15681581
def getDigestScript(self):
15691582
return self.corePackage.recipe.buildDigestScript
15701583

1584+
def getIncludedFiles(self):
1585+
return self.corePackage.recipe.buildIncludedFiles
1586+
15711587
@property
15721588
def fingerprintMask(self):
15731589
# Remove bits of all tools that are not used in buildStep
@@ -1591,7 +1607,7 @@ def hasNetAccess(self):
15911607
class CorePackageStep(CoreStep):
15921608
__slots__ = []
15931609

1594-
def __init__(self, corePackage, script=(None, None, None), digestEnv=Env(), env=Env(), args=[]):
1610+
def __init__(self, corePackage, script=(None, None, None, {}), digestEnv=Env(), env=Env(), args=[]):
15951611
isValid = script[1] is not None
15961612
super().__init__(corePackage, isValid, True, digestEnv, env, args)
15971613

@@ -1622,6 +1638,9 @@ def getMainScript(self):
16221638
def getDigestScript(self):
16231639
return self.corePackage.recipe.packageDigestScript
16241640

1641+
def getIncludedFiles(self):
1642+
return self.corePackage.recipe.packageIncludedFiles
1643+
16251644
@property
16261645
def fingerprintMask(self):
16271646
return self.corePackage.fingerprintMask
@@ -1884,7 +1903,7 @@ def resolve(self, text, section):
18841903
raise ParseError("Bad substiturion in {}: {}".format(section, str(e)))
18851904
return resolver.resolve(ret)
18861905
else:
1887-
return (None, None)
1906+
return (None, None, {})
18881907

18891908
def mergeFilter(left, right):
18901909
if left is None:
@@ -2316,7 +2335,7 @@ def coDet(r):
23162335

23172336
# the package step must always be valid
23182337
if self.__package[1] is None:
2319-
self.__package = (None, "", 'da39a3ee5e6b4b0d3255bfef95601890afd80709')
2338+
self.__package = (None, "", 'da39a3ee5e6b4b0d3255bfef95601890afd80709', {})
23202339

23212340
# final shared value
23222341
self.__shared = self.__shared == True
@@ -2643,7 +2662,7 @@ def prepare(self, inputEnv, sandboxEnabled, inputStates, inputSandbox=None,
26432662
directPackages, indirectPackages, states, uidGen(), doFingerprint)
26442663

26452664
# optional checkout step
2646-
if self.__checkout != (None, None, None) or self.__checkoutSCMs or self.__checkoutAsserts:
2665+
if self.__checkout != (None, None, None, {}) or self.__checkoutSCMs or self.__checkoutAsserts:
26472666
checkoutDigestEnv = env.prune(self.__checkoutVars)
26482667
checkoutEnv = ( env.prune(self.__checkoutVars | self.__checkoutVarsWeak)
26492668
if self.__checkoutVarsWeak else checkoutDigestEnv )
@@ -2653,7 +2672,7 @@ def prepare(self, inputEnv, sandboxEnabled, inputStates, inputSandbox=None,
26532672
srcCoreStep = p.createInvalidCoreCheckoutStep()
26542673

26552674
# optional build step
2656-
if self.__build != (None, None, None):
2675+
if self.__build != (None, None, None, {}):
26572676
buildDigestEnv = env.prune(self.__buildVars)
26582677
buildEnv = ( env.prune(self.__buildVars | self.__buildVarsWeak)
26592678
if self.__buildVarsWeak else buildDigestEnv )
@@ -2765,6 +2784,10 @@ def checkoutMainScript(self):
27652784
def checkoutDigestScript(self):
27662785
return self.__checkout[2] or ""
27672786

2787+
@property
2788+
def checkoutIncludedFiles(self):
2789+
return self.__checkout[3]
2790+
27682791
@property
27692792
def checkoutDeterministic(self):
27702793
return self.__checkoutDeterministic
@@ -2793,6 +2816,10 @@ def buildMainScript(self):
27932816
def buildDigestScript(self):
27942817
return self.__build[2]
27952818

2819+
@property
2820+
def buildIncludedFiles(self):
2821+
return self.__build[3]
2822+
27962823
@property
27972824
def buildVars(self):
27982825
return self.__buildVars
@@ -2813,6 +2840,10 @@ def packageMainScript(self):
28132840
def packageDigestScript(self):
28142841
return self.__package[2]
28152842

2843+
@property
2844+
def packageIncludedFiles(self):
2845+
return self.__package[3]
2846+
28162847
@property
28172848
def packageVars(self):
28182849
return self.__packageVars

pym/bob/invoker.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import os
2020
import re
2121
import shutil
22+
import stat
2223
import subprocess
2324
import sys
2425
import tempfile
@@ -266,7 +267,6 @@ def __getSandboxCmds(self, tmpDir):
266267
#FIXME: if verbosity >= 4: cmdArgs.append('-D')
267268
cmdArgs.extend(["-S", tmpDir])
268269
cmdArgs.extend(["-H", "bob"])
269-
cmdArgs.extend(["-d", "/tmp"])
270270
sandboxRootFs = os.path.abspath(self.__spec.sandboxRootWorkspace)
271271
for f in os.listdir(sandboxRootFs):
272272
cmdArgs.extend(["-M", os.path.join(sandboxRootFs, f), "-m", "/"+f])
@@ -301,6 +301,16 @@ async def executeStep(self, mode, clean=False, keepSandbox=False):
301301
# also used as ephemeral sandbox container.
302302
tmpDir = tempfile.mkdtemp()
303303

304+
# Create /tmp in sandbox container. Receives included files and
305+
# needs to be there anyway.
306+
os.mkdir(os.path.join(tmpDir, "tmp"), 0o755)
307+
for name, content in self.__spec.includedFiles.items():
308+
fn = os.path.join(tmpDir, "tmp", name)
309+
with open(fn, "wb") as f:
310+
f.write(content)
311+
# Set explicit mode to retain Bob 0.19 behaviour.
312+
os.chmod(fn, stat.S_IREAD|stat.S_IWRITE)
313+
304314
# prepare workspace
305315
clean = self.__spec.clean if self.__spec.clean is not None else clean
306316
if not os.path.isdir(self.__spec.workspaceWorkspacePath):
@@ -468,6 +478,7 @@ async def executeFingerprint(self, keepSandbox=False):
468478

469479
# Setup workspace
470480
cmdArgs = self.__getSandboxCmds(tmpDir)
481+
cmdArgs.extend(["-d", "/tmp"])
471482
cmdArgs.extend(["-d", "/bob/fingerprint"])
472483
cmdArgs.extend(["-W", "/bob/fingerprint"])
473484

0 commit comments

Comments
 (0)