From f718407f50abd40fa6f7c362a5a36e11b9961a45 Mon Sep 17 00:00:00 2001 From: Luis Date: Thu, 28 Jul 2022 10:22:47 +0200 Subject: [PATCH 1/3] Docs for 11580 --- reference/conanfile/methods.rst | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/reference/conanfile/methods.rst b/reference/conanfile/methods.rst index 45aa4356bd6..194f1cf03d7 100644 --- a/reference/conanfile/methods.rst +++ b/reference/conanfile/methods.rst @@ -636,6 +636,47 @@ 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.41.0 `_ + +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") + + + + + + .. _method_requirements: requirements() From 6313815f20a566ee4229513bf79debca5e0dab53 Mon Sep 17 00:00:00 2001 From: Luis Date: Thu, 28 Jul 2022 10:23:48 +0200 Subject: [PATCH 2/3] typo --- reference/conanfile/methods.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/reference/conanfile/methods.rst b/reference/conanfile/methods.rst index 194f1cf03d7..6bbc9517d32 100644 --- a/reference/conanfile/methods.rst +++ b/reference/conanfile/methods.rst @@ -643,7 +643,7 @@ validate_build() This is an **experimental** feature subject to breaking changes in future releases. -Available since: `1.41.0 `_ +Available since: `1.51.0 `_ 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. @@ -672,7 +672,7 @@ The ``validate_build()`` method has to use always the ``self.settings`` and ``se if self.settings.compiler == "gcc": raise ConanInvalidConfiguration("This doesn't build in GCC") - + From aec6cb7fb57aa4ce7f0ef6c6a903217287f7b8df Mon Sep 17 00:00:00 2001 From: Luis Date: Thu, 28 Jul 2022 10:31:13 +0200 Subject: [PATCH 3/3] More complete --- migrating_to_2.0/recipes.rst | 29 +++++++++++++++++++++++++++++ reference/conanfile/methods.rst | 4 ++++ 2 files changed, 33 insertions(+) diff --git a/migrating_to_2.0/recipes.rst b/migrating_to_2.0/recipes.rst index c227bb785e5..82b30272773 100644 --- a/migrating_to_2.0/recipes.rst +++ b/migrating_to_2.0/recipes.rst @@ -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 ------------------- diff --git a/reference/conanfile/methods.rst b/reference/conanfile/methods.rst index 6bbc9517d32..5d356bfaf10 100644 --- a/reference/conanfile/methods.rst +++ b/reference/conanfile/methods.rst @@ -672,6 +672,10 @@ The ``validate_build()`` method has to use always the ``self.settings`` and ``se 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