Repository: conan-io/conan

Issue:
[bug] components versions and generators
When using a recipe declaring components, the global version of the recipe does not seem to be propagated to the components, which can be seen when using `pkg_config` generator
This is a problem, because some libraries check their requirements' version via pkg-config, eg https://gitlab.gnome.org/GNOME/atk/-/blob/master/meson.build#L98, so currently they fail to use conan generated pkg-config files

### Environment Details (include every applicable attribute)
  * Conan version: 1.28.0

### Steps to reproduce (Include if Applicable)
checkout https://github.com/conan-io/conan-center-index/tree/dedc63dc32ca949f0b6448b72fce3efeb1212a3f/recipes/glib/all
`conan create . glib/2.65.0@`

### Logs (Executed commands with output) (Include/Attach if Applicable)
generated `glib.pc` (the package-wide file) has `Version: 2.65.0`
generated `gio-2.0.pc` (component file) has `Version: None`



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
@@ -166,7 +166,7 @@ def set_cppflags(self, value):
 
 class Component(_CppInfo):
 
-    def __init__(self, rootpath):
+    def __init__(self, rootpath, version):
         super(Component, self).__init__()
         self.rootpath = rootpath
         self.includedirs.append(DEFAULT_INCLUDE)
@@ -176,6 +176,7 @@ def __init__(self, rootpath):
         self.builddirs.append(DEFAULT_BUILD)
         self.frameworkdirs.append(DEFAULT_FRAMEWORK)
         self.requires = []
+        self.version = version
 
 
 class CppInfo(_CppInfo):
@@ -196,7 +197,7 @@ def __init__(self, ref_name, root_folder):
         self.resdirs.append(DEFAULT_RES)
         self.builddirs.append(DEFAULT_BUILD)
         self.frameworkdirs.append(DEFAULT_FRAMEWORK)
-        self.components = DefaultOrderedDict(lambda: Component(self.rootpath))
+        self.components = DefaultOrderedDict(lambda: Component(self.rootpath, self.version))
         # public_deps is needed to accumulate list of deps for cmake targets
         self.public_deps = []
         self._configs = {}


Test patch:
diff --git a/conans/test/functional/generators/components/pkg_config_test.py b/conans/test/functional/generators/components/pkg_config_test.py
--- a/conans/test/functional/generators/components/pkg_config_test.py
+++ b/conans/test/functional/generators/components/pkg_config_test.py
@@ -80,6 +80,8 @@ def basic_test(self):
         self.assertNotIn("Requires:", client.load(os.path.join(client.current_folder, "bye.pc")))
         self.assertIn("Requires: bye hello",
                       client.load(os.path.join(client.current_folder, "greetings.pc")))
+        for f in ["hello.pc", "bye.pc", "greetings.pc", "world.pc", "helloworld.pc", "worldall.pc"]:
+            self.assertIn("Version: 0.0.1", client.load(os.path.join(client.current_folder, f)))
         libs = self._get_libs_from_pkg_config("greetings", client.current_folder)
         self.assertListEqual(["-lbye", "-lhello"], libs)
 
@@ -113,6 +115,8 @@ def package_info(self):
         self.assertListEqual(["-lHelloworld", "-lhello"], libs)
         libs = self._get_libs_from_pkg_config("World", client.current_folder)
         self.assertListEqual(["-lWorldall", "-lbye", "-lHelloworld", "-lhello"], libs)
+        for f in ["Hello.pc", "Bye.pc", "Greetings.pc", "World.pc", "Helloworld.pc", "Worldall.pc"]:
+            self.assertIn("Version: 0.0.1", client.load(os.path.join(client.current_folder, f)))
 
     def pkg_config_components_test(self):
         client = TestClient()
@@ -142,6 +146,8 @@ def package_info(self):
         self.assertIn("Requires: helloworld worldall", world_pc)
         libs = self._get_libs_from_pkg_config("world", client.current_folder)
         self.assertListEqual(["-lworldall", "-lhelloworld", "-lhello", "-lbye"], libs)
+        for f in ["hello.pc", "bye.pc", "greetings.pc", "world.pc", "helloworld.pc", "worldall.pc"]:
+            self.assertIn("Version: 0.0.1", client.load(os.path.join(client.current_folder, f)))
 
     def recipe_with_components_requiring_recipe_without_components_test(self):
         client = TestClient()
@@ -177,6 +183,8 @@ def package_info(self):
         self.assertListEqual(["-lhelloworld", "-lhello", "-lbye"], libs)
         libs = self._get_libs_from_pkg_config("worldall", client.current_folder)
         self.assertListEqual(["-lworldall", "-lhelloworld", "-lhello", "-lbye"], libs)
+        for f in ["greetings.pc", "world.pc", "helloworld.pc", "worldall.pc"]:
+            self.assertIn("Version: 0.0.1", client.load(os.path.join(client.current_folder, f)))
 
     def same_names_test(self):
         client = TestClient()
@@ -196,6 +204,7 @@ def package_info(self):
         client.run("create .")
         client.run("install hello/0.0.1@ -g pkg_config")
         self.assertNotIn("Requires:", client.load(os.path.join(client.current_folder, "hello.pc")))
+        self.assertIn("Version: 0.0.1", client.load(os.path.join(client.current_folder, "hello.pc")))
 
     def component_not_found_same_name_as_pkg_require_test(self):
         zlib = GenConanfile("zlib", "0.1").with_setting("build_type")\