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

validate_build over settings #11580

Merged
merged 8 commits into from Jul 12, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions conans/client/graph/graph_binaries.py
Expand Up @@ -50,6 +50,7 @@ def _evaluate_build(node, build_mode):
conanfile.output.info('Forced build from source')
node.binary = BINARY_BUILD
node.prev = None
_call_validate_build(node)
return True

def _evaluate_clean_pkg_folder_dirty(self, node, package_layout, pref):
Expand Down Expand Up @@ -178,6 +179,7 @@ def _evaluate_node(self, node, build_mode, update, remotes):
pref = PackageReference(locked.ref, locked.package_id, locked.prev) # Keep locked PREV
self._process_node(node, pref, build_mode, update, remotes)
if node.binary == BINARY_MISSING and build_mode.allowed(node.conanfile):
_call_validate_build(node)
node.binary = BINARY_BUILD
if node.binary == BINARY_BUILD:
locked.unlock_prev()
Expand Down Expand Up @@ -232,6 +234,7 @@ def _evaluate_node(self, node, build_mode, update, remotes):
node.binary = BINARY_INVALID
if node.binary == BINARY_MISSING and build_mode.allowed(node.conanfile):
node.binary = BINARY_BUILD
_call_validate_build(conanfile)

if locked:
# package_id was not locked, this means a base lockfile that is being completed
Expand Down Expand Up @@ -295,6 +298,7 @@ def _process_node(self, node, pref, build_mode, update, remotes):
conanfile.output.info("Outdated package!")
node.binary = BINARY_BUILD
node.prev = None
_call_validate_build(conanfile)
lasote marked this conversation as resolved.
Show resolved Hide resolved
else:
conanfile.output.info("Package is up to date")

Expand Down Expand Up @@ -451,3 +455,14 @@ def reevaluate_node(self, node, remotes, build_mode, update):
output.info("Binary for updated ID from: %s" % node.binary)
if node.binary == BINARY_BUILD:
output.info("Binary for the updated ID has to be built")


def _call_validate_build(node):
conanfile = node.conanfile
if hasattr(conanfile, "validate_build") and callable(conanfile.validate_build):
with conanfile_exception_formatter(str(conanfile), "validate_build"):
try:
conanfile.validate_build()
except ConanInvalidConfiguration as e:
conanfile.info.invalid = str(e)
lasote marked this conversation as resolved.
Show resolved Hide resolved
node.binary = BINARY_INVALID
42 changes: 42 additions & 0 deletions conans/test/integration/graph/test_validate_build.py
@@ -0,0 +1,42 @@
import textwrap

from conans.test.utils.tools import TestClient


def test_basic_validate_build_test():

t = TestClient()
conanfile = textwrap.dedent("""
from conan import ConanFile
from conans.errors import ConanInvalidConfiguration

class myConan(ConanFile):
name = "foo"
version = "1.0"
settings = "os", "arch", "compiler"

def validate_build(self):
if self.settings.compiler == "gcc":
raise ConanInvalidConfiguration("This doesn't build in GCC")

def package_id(self):
del self.info.settings.compiler
""")

settings_gcc = "-s compiler=gcc -s compiler.libcxx=libstdc++11 -s compiler.version=11"
settings_clang = "-s compiler=clang -s compiler.libcxx=libc++ -s compiler.version=8"

t.save({"conanfile.py": conanfile})
t.run(f"create . {settings_gcc}", assert_error=True)

assert "This doesn't build in GCC" in t.out

t.run(f"create . {settings_clang}")

# Now with GCC again, but now we have the binary, we don't need to build, so it doesn't fail
t.run(f"create . {settings_gcc} --build missing")
assert "foo/1.0: Already installed!" in t.out

# But if I force the build... it will fail
t.run(f"create . {settings_gcc} ", assert_error=True)
assert "This doesn't build in GCC" in t.out