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

Docs for 11580 - validate_build() #2667

Merged
merged 3 commits into from Jul 28, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions migrating_to_2.0/recipes.rst
Expand Up @@ -193,6 +193,35 @@ are valid.
raise ConanInvalidConfiguration("This package is not compatible with Windows")


If you are not checking if the resulting binary is valid for the current configuration but need to check if a package
can be built or not for a specific configuration you must use the ``validate_build()`` method instead using ``self.settings``
and ``self.options`` to perform the checks:


.. code-block:: python

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration

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

def package_id(self):
# For this package, it doesn't matter the compiler used for the binary package
del self.info.settings.compiler

def validate_build(self):
# But we know this cannot be build with "gcc"
if self.settings.compiler == "gcc":
raise ConanInvalidConfiguration("This doesn't build in GCC")

def validate(self):
# We shouldn't check here if the self.info.settings.compiler because it has been removed in the package_id()
# so it doesn't make sense to check if the binary is compatible with gcc because the compiler doesn't matter
pass


The layout() method
-------------------
Expand Down
45 changes: 45 additions & 0 deletions reference/conanfile/methods.rst
Expand Up @@ -636,6 +636,51 @@ raise an error, but in the best case it will be wasted resources (compatible pac
strongly recommended to properly define the ``package_id()`` method to no include incompatible configurations.


validate_build()
----------------

.. warning::

This is an **experimental** feature subject to breaking changes in future releases.

Available since: `1.51.0 <https://github.com/conan-io/conan/releases/tag/1.41.0>`_
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, guys, seems there is a mistake in a tag version (inside the hyperlink)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed! thanks.


The ``validate_build()`` method is used to verify if a configuration is valid for building a package. It is different
from the ``validate()`` method that checks if the binary package is "impossible" or invalid for a given configuration.

In Conan 2.0, the ``validate()`` method should do the checks of the settings and options using the ``self.info.settings``
and ``self.info.options``.

The ``validate_build()`` method has to use always the ``self.settings`` and ``self.options``:

.. code-block:: python

from conan import ConanFile
from conan.errors import ConanInvalidConfiguration

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

def package_id(self):
# For this package, it doesn't matter the compiler used for the binary package
del self.info.settings.compiler

def validate_build(self):
# But we know this cannot be build with "gcc"
if self.settings.compiler == "gcc":
raise ConanInvalidConfiguration("This doesn't build in GCC")

def validate(self):
# We shouldn't check here the self.info.settings.compiler because it has been removed in the package_id()
# so it doesn't make sense to check if the binary is compatible with gcc because the compiler doesn't matter
pass





.. _method_requirements:

requirements()
Expand Down