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

Fix disabled dependencies variable substitutions #575

Merged
merged 3 commits into from
Jul 9, 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
19 changes: 13 additions & 6 deletions pym/bob/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -2321,6 +2321,19 @@ def prepare(self, inputEnv, sandboxEnabled, inputStates, inputSandbox=None,
env.setFunArgs({ "recipe" : self, "sandbox" : bool(sandbox) and sandboxEnabled,
"__tools" : tools })

skip = dep.condition and not all(env.evaluate(cond, "dependency "+dep.recipe)
for cond in dep.condition)
# The dependency name is always substituted because we allow
# provideDeps to name a disabled dependency. But in case the
# substiturion fails, the error is silently ignored.
try:
recipe = env.substitute(dep.recipe, "dependency::"+dep.recipe)
resolvedDeps.append(recipe)
except ParseError:
if skip: continue
raise
if skip: continue

thisDepEnv = depEnv
thisDepTools = depTools
thisDepDiffTools = depDiffTools
Expand All @@ -2336,12 +2349,6 @@ def prepare(self, inputEnv, sandboxEnabled, inputStates, inputSandbox=None,
# Clear sandbox, if any
thisDepDiffSandbox = None

recipe = env.substitute(dep.recipe, "dependency::"+dep.recipe)
resolvedDeps.append(recipe)

if dep.condition and not all(env.evaluate(cond, "dependency "+recipe)
for cond in dep.condition): continue

if dep.toolOverride:
try:
thisDepTools = thisDepTools.derive({
Expand Down
44 changes: 44 additions & 0 deletions test/unit/test_input_recipeset.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,21 @@ def testVariableDeps(self):
p = packages.walkPackagePath("root/b-foo")
self.assertEqual(p.getName(), "b-foo")

def testDepConditionCheckOrder(self):
"""Dependency conditions are tested before any other substitutions."""
self.writeRecipe("root", """\
root: True
depends:
- if: "false"
name: "$DOES_NOT_EXIST"
environment:
FOO: "$DOES_NOT_EXIST"
buildScript: "true"
packageScript: "true"
""")
packages = self.generate()
packages.getRootPackage() # Must not fail due to substitution error

def testGlobProvideDeps(self):
"""Test globbing pattern in provideDeps"""
self.writeRecipe("root", """\
Expand Down Expand Up @@ -491,6 +506,35 @@ def testIncompatible(self):
packages = recipes.generatePackages(lambda x,y: "unused")
self.assertRaises(ParseError, packages.getRootPackage)

def testProvideDisabled(self):
"""Providing disabled dependencies is not considered an error."""
self.writeRecipe("root", """\
root: True
depends:
- intermediate
buildScript: "true"
packageScript: "true"
""")
self.writeRecipe("intermediate", """\
depends:
- if: "false"
name: a
- if: "true"
name: b
buildScript: "true"
packageScript: "true"
provideDeps: ["a", "b"]
""")
self.writeRecipe("a", "packageScript: a")
self.writeRecipe("b", "packageScript: b")
packages = self.generate()
#packages.walkPackagePath("root")
rootArgs = packages.walkPackagePath("root").getBuildStep().getArguments()
self.assertEqual(len(rootArgs), 3)
self.assertEqual(rootArgs[0].getPackage().getName(), "root")
self.assertEqual(rootArgs[1].getPackage().getName(), "intermediate")
self.assertEqual(rootArgs[2].getPackage().getName(), "b")

def testCyclic(self):
"""Cyclic dependencies must be detected during parsing"""
self.writeRecipe("a", """\
Expand Down
Loading