Skip to content

Commit

Permalink
xkbcommon: Revert using a separate directory for the build context
Browse files Browse the repository at this point in the history
I made an oops in my previous change.
This actually does end up breaking cross-compilation.
The requirements of `wayland-scanner` aren't available in the build context.
This causes pkg-config to fail to "find" `wayland-scanner`.
The `expat` and `libxml2` files would need to be in this same directory.
Omitting the separate build context directory for pkg-config files works around this issue for now.
Work will need to be done upstream to ensure dependencies are also made available in the build context for PkgConfigDeps.
See conan-io/conan#12342 for progress on the issue upstream.

It's important to note that pointing Meson to the generators directory for "native" pkg-config files isn't the safest thing to do.
It's possible for Meson to mistakenly think dependencies in the generators directory are meant for the build context when they are of course meant for the host context whenever they lack the `_BUILD` suffix.

I've also placed `wayland-protocols` in the build context.
While it provides XML files only, really, this maps to how it is used.
  • Loading branch information
jwillikers committed Oct 21, 2022
1 parent a7ee4fb commit 674aea3
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions recipes/xkbcommon/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import glob
import os
import shutil

from conan import ConanFile
from conan.tools.apple import fix_apple_shared_install_name
Expand Down Expand Up @@ -106,38 +104,41 @@ def generate(self):
if self._has_xkbregistry_option:
tc.project_options["enable-xkbregistry"] = self.options.xkbregistry
if self._has_build_profile:
tc.project_options["build.pkg_config_path"] = os.path.join(self.generators_folder, "build")
tc.project_options["build.pkg_config_path"] = self.generators_folder
tc.generate()

pkg_config_deps = PkgConfigDeps(self)
if self._has_build_profile and self.options.get_safe("with_wayland"):
pkg_config_deps.build_context_activated = ["wayland", "wayland-protocols"]
pkg_config_deps.build_context_suffix = {"wayland": "_BUILD"}
pkg_config_deps.build_context_suffix = {"wayland": "_BUILD", "wayland-protocols": "_BUILD"}
pkg_config_deps.generate()
if self._has_build_profile and self.options.get_safe("with_wayland"):
mkdir(self, os.path.join(self.generators_folder, "build"))
for pc in glob.glob(os.path.join(self.generators_folder, "*_BUILD.pc")):
original_pc = os.path.basename(pc)[:-9] + ".pc"
shutil.move(pc, os.path.join(self.generators_folder, "build", original_pc))

virtual_build_env = VirtualBuildEnv(self)
virtual_build_env.generate()

def build(self):
# Conan doesn't provide a `wayland-scanner.pc` file for the package in the _build_ context
if self.options.get_safe("with_wayland") and not self._has_build_profile:
if self.options.get_safe("with_wayland"):
meson_build_file = os.path.join(self.source_folder, "meson.build")
replace_in_file(self, meson_build_file,
"wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)",
"# wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)")

replace_in_file(self, meson_build_file,
"if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()",
"if not wayland_client_dep.found() or not wayland_protocols_dep.found()")

replace_in_file(self, meson_build_file,
"wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))",
"wayland_scanner = find_program('wayland-scanner')")
# Patch the build system to use the pkg-config files generated for the build context.
if self._has_build_profile:
replace_in_file(self, meson_build_file,
"wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)",
"wayland_scanner_dep = dependency('wayland-scanner_BUILD', required: false, native: true)")
replace_in_file(self, meson_build_file,
"wayland_protocols_dep = dependency('wayland-protocols', version: '>=1.12', required: false)",
"wayland_protocols_dep = dependency('wayland-protocols_BUILD', version: '>=1.12', required: false, native: true)")
else:
replace_in_file(self, meson_build_file,
"wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)",
"# wayland_scanner_dep = dependency('wayland-scanner', required: false, native: true)")

replace_in_file(self, meson_build_file,
"if not wayland_client_dep.found() or not wayland_protocols_dep.found() or not wayland_scanner_dep.found()",
"if not wayland_client_dep.found() or not wayland_protocols_dep.found()")

replace_in_file(self, meson_build_file,
"wayland_scanner = find_program(wayland_scanner_dep.get_pkgconfig_variable('wayland_scanner'))",
"wayland_scanner = find_program('wayland-scanner')")

meson = Meson(self)
meson.configure()
Expand Down

0 comments on commit 674aea3

Please sign in to comment.