Repository: conan-io/conan

Issue:
[bug] Private requires must be associated with a component, but if associated, generator fails
I'm in a damned if you do, damned if you don't situation. I have a conanfile with a private `requires` reference that defines components. While [_raise_incorrect_components_definition](https://github.com/conan-io/conan/blob/develop/conans/model/build_info.py#L244) has been very helpful in getting the component `requires` right, it also forces you to list the private package `requires` in one of the component `requires`.

However, when building something downstream with an exported package of this conanfile, e.g. the `cmake_find_package` generator fails since the private `requires` hasn't been loaded (which to me is correct behavior).

### Environment Details
  * Conan version: 1.30.2

### Steps to reproduce

Sketch of conanfile:

```
class Pkg(ConanFile):
    ...

    def requirement(self):
         self.requires("<private-pkg-ref>", private=predicate(self.options))

    def package_info(self):
         self.cpp_info.components["part"].libs = ...
```

### Logs

`conan create -tf .conan_test_package .`

When omitting the private requires from component requires:
```
ERROR: 
	ConanException: <pkg> package_info(): Package require '<private-pkg-name>' not used in components requires
```

In the test package when specifying the private requires in component requires:
```
<pkg> (test package): ERROR: Generator cmake_find_package(file:None) failed
'<private-pkg-name>'
```

### Fix suggestion

If I haven't made any logical errors, I think this could be fixed fairly easily with a tiny patch (it might also warrant a test, really):

```diff
diff --git a/conans/model/build_info.py b/conans/model/build_info.py
index befa221c..7c5faf45 100644
--- a/conans/model/build_info.py
+++ b/conans/model/build_info.py
@@ -269,7 +269,8 @@ class CppInfo(_CppInfo):
             raise ConanException("self.cpp_info.components cannot be used with self.cpp_info configs"
                                  " (release/debug/...) at the same time")
 
-        pkg_requires = [require.ref.name for require in package_requires.values()]
+        pkg_requires = [require.ref.name for require in package_requires.values()
+                        if not require.private]
 
         def _check_components_requires_instersection(comp_requires):
             reqs = [it.split(COMPONENT_SCOPE)[0] for it in comp_requires if COMPONENT_SCOPE in it]
```


Discussion:

Resolving patch:
diff --git a/conans/model/build_info.py b/conans/model/build_info.py
--- a/conans/model/build_info.py
+++ b/conans/model/build_info.py
@@ -275,14 +275,27 @@ def _check_components_requires_instersection(comp_requires):
             reqs = [it.split(COMPONENT_SCOPE)[0] for it in comp_requires if COMPONENT_SCOPE in it]
             # Raise on components requires without package requires
             for pkg_require in pkg_requires:
+                if package_requires[pkg_require].private or package_requires[pkg_require].override:
+                    # Not standard requires, skip
+                    continue
                 if pkg_require not in reqs:
                     raise ConanException("Package require '%s' not used in components requires"
                                          % pkg_require)
             # Raise on components requires requiring inexistent package requires
             for comp_require in reqs:
+                reason = None
                 if comp_require not in pkg_requires:
+                    reason = "not defined as a recipe requirement"
+                elif package_requires[comp_require].private and package_requires[comp_require].override:
+                    reason = "it was defined as an overridden private recipe requirement"
+                elif package_requires[comp_require].private:
+                    reason = "it was defined as a private recipe requirement"
+                elif package_requires[comp_require].override:
+                    reason = "it was defined as an overridden recipe requirement"
+
+                if reason is not None:
                     raise ConanException("Package require '%s' declared in components requires "
-                                         "but not defined as a recipe requirement" % comp_require)
+                                         "but %s" % (comp_require, reason))
 
         if self.components:
             # Raise on component name


Test patch: