Repository: conan-io/conan

Issue:
AutoTools PKG_CONFIG_PATH value should be a list
Hi,

Currently, AutoTools is able to generate `PKG_CONFIG_PATH` automatically. However, the value set is not a list. See: https://github.com/conan-io/conan/blob/develop/conans/client/build/autotools_environment.py#L134 (L135 and L141)

As a consequence, every previous value(s) set or "append" to `PKG_CONFIG_PATH` in dependencies are destroyed by `environment_append`. As `PKG_CONFIG_PATH ` is supposed to be a list of paths, it should be a list. It should have the same behaviour as `PATH`. Validated locally: declare as a list in lines quoted before solves the issue. Thus, `environment_append` does not overwrite previous value(s). 


Discussion:
Hi @guyguy333 

It seems that the purpose of setting that value was setting only the paths for the conan generated package config, and the issue could arise when trying to use any other system packages which PKG_CONFIG_PATH is defined somewhere else. Could this be the case?  We'd need the feedback of @lasote, but yes, it looks like we need to have a look at this, thanks for reporting!
Hi @memsharded,

Thanks for looking this issue. I think the case you quoted makes sense. However, my use case is a bit different. Let's suppose A depends on B and A is looking for B through pkg-config. What I did in B is as simple as it. However, this value is removed by autotools then.

```python
def package_info(self):
        self.env_info.PKG_CONFIG_PATH.append(os.path.join(self.package_folder, "lib", "pkgconfig"))
```

pkg-config generator can't be used here because B generates multiple pkg-config files and this is not handled by Conan currently. (It should be treated in another issue I guess).


> pkg-config generator can't be used here because B generates multiple pkg-config files and this is not handled by Conan currently. (It should be treated in another issue I guess).

I see, yes it seems that conan is not prepared to define a custom PKG_CONFIG_PATH, but it is somehow automatically managed/integrated with the pkg_config generator. No need to open another issue, I think it is very closely related to be followed in this one. Thanks for the feedback.

Resolving patch:
diff --git a/conans/client/build/autotools_environment.py b/conans/client/build/autotools_environment.py
--- a/conans/client/build/autotools_environment.py
+++ b/conans/client/build/autotools_environment.py
@@ -133,12 +133,12 @@ def configure(self, configure_dir=None, args=None, build=None, host=None, target
 
         if pkg_config_paths:
             pkg_env = {"PKG_CONFIG_PATH":
-                       os.pathsep.join(get_abs_path(f, self._conanfile.install_folder)
-                                       for f in pkg_config_paths)}
+                       [os.pathsep.join(get_abs_path(f, self._conanfile.install_folder)
+                                       for f in pkg_config_paths)]}
         else:
             # If we are using pkg_config generator automate the pcs location, otherwise it could
             # read wrong files
-            pkg_env = {"PKG_CONFIG_PATH": self._conanfile.install_folder} \
+            pkg_env = {"PKG_CONFIG_PATH": [self._conanfile.install_folder]} \
                 if "pkg_config" in self._conanfile.generators else {}
 
         if self._conanfile.package_folder is not None:


Test patch:
diff --git a/conans/test/build_helpers/autotools_configure_test.py b/conans/test/build_helpers/autotools_configure_test.py
--- a/conans/test/build_helpers/autotools_configure_test.py
+++ b/conans/test/build_helpers/autotools_configure_test.py
@@ -413,18 +413,29 @@ def build(self):
         client.run("create . conan/testing")
         self.assertNotIn("PKG_CONFIG_PATH=", client.out)
 
+        ref = ConanFileReference.loads("Hello/1.2.1@conan/testing")
+        builds_folder = client.client_cache.builds(ref)
+        bf = os.path.join(builds_folder, os.listdir(builds_folder)[0])
+
         client.save({CONANFILE: conanfile % ("'pkg_config'", "")})
         client.run("create . conan/testing")
-        self.assertIn("PKG_CONFIG_PATH=%s" % client.client_cache.conan_folder, client.out)
+        self.assertIn("PKG_CONFIG_PATH=%s" % bf, client.out)
+
+        # The previous values in the environment should be kept too
+        with tools.environment_append({"PKG_CONFIG_PATH": "Some/value"}):
+            client.run("create . conan/testing")
+            self.assertIn("PKG_CONFIG_PATH=%s:Some/value" % bf, client.out)
 
         client.save({CONANFILE: conanfile % ("'pkg_config'",
                                              "pkg_config_paths=['/tmp/hello', 'foo']")})
         client.run("create . conan/testing")
-        ref = ConanFileReference.loads("Hello/1.2.1@conan/testing")
-        builds_folder = client.client_cache.builds(ref)
-        bf = os.path.join(builds_folder, os.listdir(builds_folder)[0])
         self.assertIn("PKG_CONFIG_PATH=/tmp/hello:%s/foo" % bf, client.out)
 
+        # The previous values in the environment should be kept too
+        with tools.environment_append({"PKG_CONFIG_PATH": "Some/value"}):
+            client.run("create . conan/testing")
+            self.assertIn("PKG_CONFIG_PATH=/tmp/hello:%s/foo:Some/value" % bf, client.out)
+
     def cross_build_command_test(self):
         runner = RunnerMock()
         conanfile = MockConanfile(MockSettings({}), None, runner)