Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qt refactor option handling and error reporting #24876

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 60 additions & 22 deletions recipes/qt/5.x.x/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from conan import ConanFile
from conan import ConanFile, conan_version
from conan.errors import ConanException, ConanInvalidConfiguration
from conan.tools.android import android_abi
from conan.tools.apple import is_apple_os
Expand Down Expand Up @@ -123,9 +123,10 @@
"sysroot": None,
"config": None,
"multiconfiguration": False,
"essential_modules": not os.getenv('CONAN_CENTER_BUILD_SERVICE')
}
default_options.update({f"{status}_modules": False for status in _module_statuses if status != "essential"})
# essential_modules, addon_modules, deprecated_modules, preview_modules:
# these are only provided for convenience, set to False by default
default_options.update({f"{status}_modules": False for status in _module_statuses})

no_copy_source = True
short_paths = True
Expand Down Expand Up @@ -207,6 +208,10 @@
if self.settings.os != "Android":
del self.options.android_sdk

def _debug_output(self, message):
if Version(conan_version) >= "2":
self.output.debug(message)

Check failure on line 213 in recipes/qt/5.x.x/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Instance of 'ScopedOutput' has no 'debug' member. Please, check https://github.com/conan-io/conan-center-index/blob/master/docs/v2_linter.md

def configure(self):
# if self.settings.os != "Linux":
# self.options.with_libiconv = False # QTBUG-84708
Expand Down Expand Up @@ -249,25 +254,50 @@
for m in submodules_tree:
assert m in ["qtbase", "qtqa", "qtrepotools"] or m in self._submodules, "module %s is not present in recipe options : (%s)" % (m, ",".join(self._submodules))

for m in self._submodules:
if m not in submodules_tree:
delattr(self.options, m)
for module in self._submodules:
if module not in submodules_tree:
self._debug_output(f"qt5: removing {module} from options as it is not an option for this version, or it is ignored or obsolete")
self.options.rm_safe(module)

# Requested modules:
# - any module for non-removed options that have 'True' value
# - any enabled via `xxx_modules` that does not have a 'False' value
# Note that at this point, the submodule options dont have a value unless one is given externally
# to the recipe (e.g. via the command line, a profile, or a consumer)
requested_modules = set([module for module in self._submodules if self.options.get_safe(module)])
for module in [m for m in self._submodules if m in submodules_tree]:
status = submodules_tree[module]['status']
is_disabled = self.options.get_safe(module) == False
if self.options.get_safe(f"{status}_modules"):
if not is_disabled:
requested_modules.add(module)
else:
self.output.warning(f"qt5: {module} requested because {status}_modules=True"
f" but it has been explicitly disabled with {module}=False")

self.output.info(f"qt5: requested modules {list(requested_modules)}")

def _enablemodule(mod):
if mod != "qtbase":
setattr(self.options, mod, True)
for req in submodules_tree[mod]["depends"]:
_enablemodule(req)
required_modules = {}
for module in requested_modules:
deps = submodules_tree[module]["depends"]
for dep in deps:
required_modules.setdefault(dep,[]).append(module)

for module in self._submodules:
if self.options.get_safe(module):
_enablemodule(module)
else:
if module in submodules_tree:
for status in self._module_statuses:
if getattr(self.options, f"{status}_modules") and submodules_tree[module]['status'] == status:
_enablemodule(module)
break
required_but_disabled = [m for m in required_modules.keys() if self.options.get_safe(m) == False]
if required_modules:
self._debug_output(f"qt5: required_modules modules {list(required_modules.keys())}")
if required_but_disabled:
required_by = set()
for m in required_but_disabled:
required_by.update(required_modules[m])
raise ConanInvalidConfiguration(f"Modules {required_but_disabled} are explicitly disabled, "
f"but are required by {list(required_by)}, enabled by other options")

enabled_modules = requested_modules.union(set(required_modules.keys()))
enabled_modules.discard("qtbase")

for module in list(enabled_modules):
setattr(self.options, module, True)

for module in self._submodules:
if module in self.options and not self.options.get_safe(module):
Expand All @@ -283,6 +313,16 @@
if self.options.qtwebengine:
self.options.with_fontconfig = True

for status in self._module_statuses:
# These are convenience only, should not affect package_id
option_name = f"{status}_modules"
self._debug_output(f"qt5 removing convenience option: {option_name},"
f" see individual module options")
self.options.rm_safe(option_name)

for option in self.options.items():
self._debug_output(f"qt5 option {option[0]}={option[1]}")

def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, "11")
Expand Down Expand Up @@ -438,8 +478,6 @@
self.info.settings.compiler.runtime_type = "Release/Debug"
if self.info.settings.os == "Android":
del self.info.options.android_sdk
for status in self._module_statuses:
delattr(self.info.options, f"{status}_modules")

def build_requirements(self):
if self._settings_build.os == "Windows" and is_msvc(self):
Expand Down Expand Up @@ -938,7 +976,7 @@
filecontents += 'set(CMAKE_AUTOMOC_MACRO_NAMES "Q_OBJECT" "Q_GADGET" "Q_GADGET_EXPORT" "Q_NAMESPACE" "Q_NAMESPACE_EXPORT")\n'
save(self, os.path.join(self.package_folder, self._cmake_core_extras_file), filecontents)

def _create_private_module(module, dependencies=[]):

Check warning on line 979 in recipes/qt/5.x.x/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Dangerous default value [] as argument
if "Core" not in dependencies:
dependencies.append("Core")
dependencies_string = ';'.join(f'Qt5::{dependency}' for dependency in dependencies)
Expand Down Expand Up @@ -1009,7 +1047,7 @@
reqs.append(corrected_req)
return reqs

def _create_module(module, requires=[], has_include_dir=True):

Check warning on line 1050 in recipes/qt/5.x.x/conanfile.py

View workflow job for this annotation

GitHub Actions / Lint changed conanfile.py (v2 migration)

Dangerous default value [] as argument
componentname = f"qt{module}"
assert componentname not in self.cpp_info.components, f"Module {module} already present in self.cpp_info.components"
self.cpp_info.components[componentname].set_property("cmake_target_name", f"Qt5::{module}")
Expand Down
94 changes: 64 additions & 30 deletions recipes/qt/6.x.x/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import platform
import textwrap

from conan import ConanFile
from conan import ConanFile, conan_version
from conan.tools.apple import is_apple_os
from conan.tools.build import cross_building, check_min_cppstd, default_cppstd
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
Expand Down Expand Up @@ -122,9 +122,10 @@ class QtConan(ConanFile):
"sysroot": None,
"multiconfiguration": False,
"disabled_features": "",
"essential_modules": not os.getenv('CONAN_CENTER_BUILD_SERVICE')
}
default_options.update({f"{status}_modules": False for status in _module_statuses if status != "essential"})
# essential_modules, addon_modules, deprecated_modules, preview_modules:
# these are only provided for convenience, set to False by default
default_options.update({f"{status}_modules": False for status in _module_statuses})

short_paths = True

Expand Down Expand Up @@ -182,9 +183,10 @@ def config_options(self):
if self.settings.os != "Linux":
self.options.qtwayland = False

for m in self._submodules:
if m not in self._get_module_tree:
delattr(self.options, m)
for submodule in self._submodules:
if submodule not in self._get_module_tree:
self._debug_output(f"Qt6: Removing {submodule} option as it is not in the module tree for this version, or is marked as obsolete or ignore")
self.options.rm_safe(submodule)

@property
def _minimum_compilers_version(self):
Expand All @@ -197,6 +199,10 @@ def _minimum_compilers_version(self):
"apple-clang": "12" if Version(self.version) >= "6.5.0" else "11"
}

def _debug_output(self, message):
if Version(conan_version) >= "2":
self.output.debug(message)

def configure(self):
if not self.options.gui:
del self.options.opengl
Expand All @@ -213,28 +219,48 @@ def configure(self):
if self.options.multiconfiguration:
del self.settings.build_type

def _enablemodule(mod):
if mod != "qtbase":
setattr(self.options, mod, True)
for req in self._get_module_tree[mod]["depends"]:
_enablemodule(req)

# enable all modules which are
# - required by a module explicitely enabled by the consumer
for module_name, module in self._get_module_tree.items():
if getattr(self.options, module_name):
_enablemodule(module_name)
else:
for status in self._module_statuses:
if getattr(self.options, f"{status}_modules") and module['status'] == status:
_enablemodule(module_name)
break

# disable all modules which are:
# - not explicitely enabled by the consumer and
# - not required by a module explicitely enabled by the consumer
for module in self._get_module_tree:
if getattr(self.options, module).value is None:
# Requested modules:
# - any module for non-removed options that have 'True' value
# - any enabled via `xxx_modules` that does not have a 'False' value
# Note that at this point, the submodule options dont have a value unless one is given externally
# to the recipe (e.g. via the command line, a profile, or a consumer)
requested_modules = set([module for module in self._submodules if self.options.get_safe(module)])
for module in [m for m in self._submodules if m in self._get_module_tree]:
status = self._get_module_tree[module]['status']
is_disabled = self.options.get_safe(module) == False
if self.options.get_safe(f"{status}_modules"):
if not is_disabled:
requested_modules.add(module)
else:
self.output.warning(f"qt6: {module} requested because {status}_modules=True"
f" but it has been explicitly disabled with {module}=False")

self.output.info(f"qt6: requested modules {list(requested_modules)}")

required_modules = {}
for module in requested_modules:
deps = self._get_module_tree[module]["depends"]
for dep in deps:
required_modules.setdefault(dep,[]).append(module)

required_but_disabled = [m for m in required_modules.keys() if self.options.get_safe(m) == False]
if required_modules:
self._debug_output(f"qt6: required_modules modules {list(required_modules.keys())}")
if required_but_disabled:
required_by = set()
for m in required_but_disabled:
required_by.update(required_modules[m])
raise ConanInvalidConfiguration(f"Modules {required_but_disabled} are explicitly disabled, "
f"but are required by {list(required_by)}, enabled by other options")

enabled_modules = requested_modules.union(set(required_modules.keys()))
enabled_modules.discard("qtbase")

for module in list(enabled_modules):
setattr(self.options, module, True)

for module in self._submodules:
if module in self.options and not self.options.get_safe(module):
setattr(self.options, module, False)

if not self.options.get_safe("qtmultimedia"):
Expand All @@ -247,6 +273,16 @@ def _enablemodule(mod):
if self.options.get_safe("qtwebengine"):
self.options.with_fontconfig = True

for status in self._module_statuses:
# These are convenience only, should not affect package_id
option_name = f"{status}_modules"
self._debug_output(f"qt6 removing convenience option: {option_name},"
f" see individual module options")
self.options.rm_safe(option_name)

for option in self.options.items():
self._debug_output(f"qt6 option: {option}")

def validate(self):
if os.getenv('CONAN_CENTER_BUILD_SERVICE') is not None:
if self.info.settings.compiler == "gcc" and Version(self.info.settings.compiler.version) >= "11" or \
Expand Down Expand Up @@ -649,8 +685,6 @@ def package_id(self):
self.info.settings.compiler.runtime_type = "Release/Debug"
if self.info.settings.os == "Android":
del self.info.options.android_sdk
for status in self._module_statuses:
delattr(self.info.options, f"{status}_modules")

def source(self):
destination = self.source_folder
Expand Down
Loading