Repository: conan-io/conan-center-index

Issue:
[package] qt/6.3.1:  Component qt::qtWebEngineCore library 'Qt6WebEngineCore' is listed in the recipe, but not found installed at self.cpp_info.libdirs
### Package and Environment Details

* Package Name/Version: **qt/6.3.1**
* Operating System+version: **Fedora Linux 36**
* Compiler+version: **GCC 12**
* Conan version: **conan 1.50.0**
* Python version: **Python 3.10.5**


### Conan profile

Configuration for profile linux/gcc/debug:

[settings]
os=Linux
arch=x86_64
compiler=gcc
compiler.version=12
compiler.libcxx=libstdc++11
compiler.cppstd=17
build_type=Debug
[options]
[conf]
[build_requires]
[env]

### Steps to reproduce

1. Install Conan Hooks.
2. `cd recipes/qt/6.x.x/`
3. `conan create . qt/6.3.1@ -o:h qt:qtwebchannel=True -o:h qt:qtwebengine=True -o:h qt:qtpositioning=True -o:h qt:shared=True -o:h qt:gui=True -o:h qt:qtdeclarative=True -o:h qt:qtmultimedia=True -o:h qt:with_dbus=True -o:h qt:with_mysql=False -o:h qt:with_zstd=True -pr:b linux/gcc/release -pr:h linux/gcc/debug -u -b outdated -b cascade -k`

### Logs

<details><summary>Click to expand log</summary>

```
[HOOK - conan-center.py] post_package_info(): [CMAKE FILE NOT IN BUILD FOLDERS (KB-H019)] OK
[HOOK - conan-center.py] post_package_info(): ERROR: [LIBRARY DOES NOT EXIST (KB-H054)] Component qt::qtWebEngineCore library 'Qt6WebEngineCore' is listed in the recipe, but not found installed at self.cpp_info.libdirs. Make sure you compiled the library correctly. If so, then the library name should probably be fixed. Otherwise, then the component should be removed. (https://github.com/conan-io/conan-center-index/blob/master/docs/error_knowledge_base.md#KB-H054) 
[HOOK - conan-center.py] post_package_info(): ERROR: [LIBRARY DOES NOT EXIST (KB-H054)] Component qt::qtWebEngineQuick library 'Qt6WebEngineQuick' is listed in the recipe, but not found installed at self.cpp_info.libdirs. Make sure you compiled the library correctly. If so, then the library name should probably be fixed. Otherwise, then the component should be removed. (https://github.com/conan-io/conan-center-index/blob/master/docs/error_knowledge_base.md#KB-H054) 
[HOOK - conan-center.py] post_package_info(): ERROR: [LIBRARY DOES NOT EXIST (KB-H054)] Component qt::qtWebEngineWidgets library 'Qt6WebEngineWidgets' is listed in the recipe, but not found installed at self.cpp_info.libdirs. Make sure you compiled the library correctly. If so, then the library name should probably be fixed. Otherwise, then the component should be removed. (https://github.com/conan-io/conan-center-index/blob/master/docs/error_knowledge_base.md#KB-H054) 
[HOOK - conan-center.py] post_package_info(): ERROR: [INCLUDE PATH DOES NOT EXIST (KB-H071)] Component qt::qtWebEngineCore include dir 'include/QtWebEngineCore' is listed in the recipe, but not found in package folder. The include dir should probably be fixed or removed. (https://github.com/conan-io/conan-center-index/blob/master/docs/error_knowledge_base.md#KB-H071) 
[HOOK - conan-center.py] post_package_info(): ERROR: [INCLUDE PATH DOES NOT EXIST (KB-H071)] Component qt::qtWebEngineQuick include dir 'include/QtWebEngineQuick' is listed in the recipe, but not found in package folder. The include dir should probably be fixed or removed. (https://github.com/conan-io/conan-center-index/blob/master/docs/error_knowledge_base.md#KB-H071) 
[HOOK - conan-center.py] post_package_info(): ERROR: [INCLUDE PATH DOES NOT EXIST (KB-H071)] Component qt::qtWebEngineWidgets include dir 'include/QtWebEngineWidgets' is listed in the recipe, but not found in package folder. The include dir should probably be fixed or removed. (https://github.com/conan-io/conan-center-index/blob/master/docs/error_knowledge_base.md#KB-H071) 
ERROR: 
	ConanException: [HOOK - conan-center.py] post_package_info(): Some checks failed running the hook, check the output
```

[conan-create-qt-6-qtwebengine.txt](https://github.com/conan-io/conan-center-index/files/9033174/conan-create-qt-6-qtwebengine.txt)


</details>



Discussion:
This reuses a binary from cache, so there is not log of the build in this file. Please retry with `-b qt` and send the full log.
> This reuses a binary from cache, so there is not log of the build in this file. Please retry with `-b qt` and send the full log.

Sorry about that. Here's the new log:

[conan-create-qt-6-qtwebengine.txt](https://github.com/conan-io/conan-center-index/files/9034659/conan-create-qt-6-qtwebengine.txt)

Log says 
```
WARNING: QtWebEngine won't be built. Python3 html5lib is missing.
WARNING: QtPdf won't be built. Python3 html5lib is missing.
```
> Log says
> 
> ```
> WARNING: QtWebEngine won't be built. Python3 html5lib is missing.
> WARNING: QtPdf won't be built. Python3 html5lib is missing.
> ```

Thanks for pointing that out! I've installed `python3-html5lib` along with a few other packages that appear to be needed, `cups-devel` and `libxshmfence-devel`. I'm now stuck at another error where GN can't find NSS.

```
CMake Error at /var/home/jordan/.conan/data/qt/6.3.1/_/_/source/qt6/qtwebengine/cmake/Gn.cmake:72 (message):
  

  -- GN FAILED

  ERROR at //build/config/linux/pkg_config.gni:103:17: Script returned
  non-zero exit code.

      pkgresult = exec_script(pkg_config_script, args, "value")
                  ^----------

  Current dir:
  /var/home/jordan/.conan/data/qt/6.3.1/_/_/build/63c29bf534713f8341b2442f99c2a1b88368381a/qtwebengine/src/pdf/Debug/x86_64/


  Command: /usr/bin/python3
  /var/home/jordan/.conan/data/qt/6.3.1/_/_/source/qt6/qtwebengine/src/3rdparty/chromium/build/config/linux/pkg-config.py
  -p
  /var/home/jordan/.conan/data/pkgconf/1.7.4/_/_/package/24647d9fe8ec489125dfbae4b3ebefaf7581674c/bin/pkgconf
  nss -v -lssl3

  Returned 1.

  stderr:

  

  Package nss was not found in the pkg-config search path.

  Perhaps you should add the directory containing `nss.pc'

  to the PKG_CONFIG_PATH environment variable

  Package 'nss', required by 'virtual:world', not found

  Could not run pkg-config.

  

  See //build/config/linux/nss/BUILD.gn:15:3: whence it was called.

    pkg_config("system_nss_no_ssl_config") {
    ^---------------------------------------

  See //crypto/BUILD.gn:215:24: which caused the file to be included.

      public_configs = [ "//build/config/linux/nss:system_nss_no_ssl_config" ]
                         ^--------------------------------------------------

  

  

  1



ninja: build stopped: subcommand failed.
ERROR: qt/6.3.1: Error in package() method, line 736
	cmake.install()
	ConanException: Error 1 while executing cmake --build '/var/home/jordan/.conan/data/qt/6.3.1/_/_/build/63c29bf534713f8341b2442f99c2a1b88368381a' '--target' 'install' '--' '-j12'
```

[conan-create-qt-6-qtwebengine.txt](https://github.com/conan-io/conan-center-index/files/9035504/conan-create-qt-6-qtwebengine.txt)

your log both says
`qt/6.3.1: Generator pkg_config created nss.pc`
and
```
 Package nss was not found in the pkg-config search path.

  Perhaps you should add the directory containing `nss.pc'

  to the PKG_CONFIG_PATH environment variable
```
and the recipe sets this variable in https://github.com/conan-io/conan-center-index/blob/master/recipes/qt/6.x.x/conanfile.py#L699

I have no idea what is wrong here.
Also, it "should not" be necessary to install system xshmfence, because qt recipe should rely on the conan package `libxshmfence/1.3`
> your log both says `qt/6.3.1: Generator pkg_config created nss.pc` and
> 
> ```
>  Package nss was not found in the pkg-config search path.
> 
>   Perhaps you should add the directory containing `nss.pc'
> 
>   to the PKG_CONFIG_PATH environment variable
> ```
> 
> and the recipe sets this variable in https://github.com/conan-io/conan-center-index/blob/master/recipes/qt/6.x.x/conanfile.py#L699
> 
> I have no idea what is wrong here. Also, it "should not" be necessary to install system xshmfence, because qt recipe should rely on the conan package `libxshmfence/1.3`

An issue with how Qt's calling into GN most likely?
@ericLemanissier Looking at the log output, it appears this error is happening in the `package()` method? The error happens after `qt` notes that it is calling the `package` method. That means the issue might be that `cmake` is either reconfiguring without the proper environment setup and/or the `cmake.install` command is happening without the proper environment and needs it.
owww, very good catch !
We should extract most of the environment setup in

https://github.com/conan-io/conan-center-index/blob/master/recipes/qt/6.x.x/conanfile.py#L695-L721

into its own `@contextmanagger`, like
https://github.com/conan-io/conan-center-index/blob/b5a9d42e63a69f4fbd989152a257bda1df2d1076/recipes/gn/all/test_package/conanfile.py#L12

then we would be able to re-use the same environment in package(self). Would you have the possibility to try and make a PR for this?
> owww, very good catch ! We should extract most of the environment setup in
> 
> https://github.com/conan-io/conan-center-index/blob/master/recipes/qt/6.x.x/conanfile.py#L695-L721
> 
> into its own `@contextmanagger`, like
> 
> https://github.com/conan-io/conan-center-index/blob/b5a9d42e63a69f4fbd989152a257bda1df2d1076/recipes/gn/all/test_package/conanfile.py#L12
> 
> then we would be able to re-use the same environment in package(self). Would you have the possibility to try and make a PR for this?

No problem, I really appreciate the help with all of this. Thanks!

Resolving patch:
diff --git a/recipes/qt/6.x.x/conanfile.py b/recipes/qt/6.x.x/conanfile.py
--- a/recipes/qt/6.x.x/conanfile.py
+++ b/recipes/qt/6.x.x/conanfile.py
@@ -1,13 +1,16 @@
-from conan.tools.microsoft import msvc_runtime_flag
-from conans import ConanFile, tools, RunEnvironment, CMake
-from conans.errors import ConanInvalidConfiguration
-from conans.model import Generator
+from contextlib import contextmanager
+
 import configparser
 import functools
 import glob
 import os
 import textwrap
 
+from conan.tools.microsoft import msvc_runtime_flag
+from conans import ConanFile, tools, RunEnvironment, CMake
+from conans.errors import ConanInvalidConfiguration
+from conans.model import Generator
+
 required_conan_version = ">=1.43.0"
 
 
@@ -554,6 +557,28 @@ def _xplatform(self):
 
         return None
 
+    @contextmanager
+    def _build_context(self):
+        with tools.vcvars(self) if self._is_msvc else tools.no_op():
+            # next lines force cmake package to be in PATH before the one provided by visual studio (vcvars)
+            build_env = tools.RunEnvironment(self).vars if self._is_msvc else {}
+            build_env["MAKEFLAGS"] = "j%d" % tools.cpu_count()
+            build_env["PKG_CONFIG_PATH"] = [self.build_folder]
+            if self.settings.os == "Windows":
+                if not "PATH" in build_env:
+                    build_env["PATH"] = []
+                build_env["PATH"].append(os.path.join(self.source_folder, "qt6", "gnuwin32", "bin"))
+            if self._is_msvc:
+                # this avoids cmake using gcc from strawberryperl
+                build_env["CC"] = "cl"
+                build_env["CXX"] = "cl"
+            with tools.environment_append(build_env):
+
+                if tools.os_info.is_macos:
+                    tools.save(".qmake.stash" , "")
+                    tools.save(".qmake.super" , "")
+                yield
+
     @functools.lru_cache(1)
     def _configure_cmake(self):
         cmake = CMake(self, generator="Ninja")
@@ -713,34 +738,18 @@ def build(self):
             tools.replace_in_file(f,
                 " IMPORTED)\n",
                 " IMPORTED GLOBAL)\n", strict=False)
-        with tools.vcvars(self) if self._is_msvc else tools.no_op():
-            # next lines force cmake package to be in PATH before the one provided by visual studio (vcvars)
-            build_env = tools.RunEnvironment(self).vars if self._is_msvc else {}
-            build_env["MAKEFLAGS"] = "j%d" % tools.cpu_count()
-            build_env["PKG_CONFIG_PATH"] = [self.build_folder]
-            if self.settings.os == "Windows":
-                if not "PATH" in build_env:
-                    build_env["PATH"] = []
-                build_env["PATH"].append(os.path.join(self.source_folder, "qt6", "gnuwin32", "bin"))
-            if self._is_msvc:
-                # this avoids cmake using gcc from strawberryperl
-                build_env["CC"] = "cl"
-                build_env["CXX"] = "cl"
-            with tools.environment_append(build_env):
-
-                if tools.os_info.is_macos:
-                    tools.save(".qmake.stash" , "")
-                    tools.save(".qmake.super" , "")
+            
+        with self._build_context():
+            cmake = self._configure_cmake()
+            if tools.os_info.is_macos:
+                tools.save("bash_env", 'export DYLD_LIBRARY_PATH="%s"' % ":".join(RunEnvironment(self).vars["DYLD_LIBRARY_PATH"]))
+            with tools.environment_append({
+                "BASH_ENV": os.path.abspath("bash_env")
+            }) if tools.os_info.is_macos else tools.no_op():
+                with tools.run_environment(self):
+                    with tools.remove_from_path("perl") if self.settings.os == "Windows" else tools.no_op():
+                        cmake.build()
 
-                cmake = self._configure_cmake()
-                if tools.os_info.is_macos:
-                    tools.save("bash_env", 'export DYLD_LIBRARY_PATH="%s"' % ":".join(RunEnvironment(self).vars["DYLD_LIBRARY_PATH"]))
-                with tools.environment_append({
-                    "BASH_ENV": os.path.abspath("bash_env")
-                }) if tools.os_info.is_macos else tools.no_op():
-                    with tools.run_environment(self):
-                        with tools.remove_from_path("perl") if self.settings.os == "Windows" else tools.no_op():
-                            cmake.build()
     @property
     def _cmake_executables_file(self):
         return os.path.join("lib", "cmake", "Qt6Core", "conan_qt_executables_variables.cmake")
@@ -753,8 +762,9 @@ def _cmake_qt6_private_file(self, module):
         return os.path.join("lib", "cmake", "Qt6{0}".format(module), "conan_qt_qt6_{0}private.cmake".format(module.lower()))
 
     def package(self):
-        cmake = self._configure_cmake()
-        cmake.install()
+        with self._build_context():
+            cmake = self._configure_cmake()
+            cmake.install()
         tools.save(os.path.join(self.package_folder, "bin", "qt.conf"), qt.content_template("..", "res", self.settings.os))
         self.copy("*LICENSE*", src="qt6/", dst="licenses")
         for module in self._get_module_tree:


Test patch: