Skip to content

Commit

Permalink
(#13668) xkbcommon: Revert using a separate directory for the build c…
Browse files Browse the repository at this point in the history
…ontext

* xkbcommon: Revert using a separate directory for the build context

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.

* Remove lingering import

* Improve the set of topics
  • Loading branch information
jwillikers authored Oct 24, 2022
1 parent 63083cc commit ac2e523
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions recipes/xkbcommon/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import glob
import os
import shutil

from conan import ConanFile
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import copy, get, mkdir, replace_in_file, rmdir
from conan.tools.files import copy, get, replace_in_file, rmdir
from conan.tools.gnu import PkgConfigDeps
from conan.tools.layout import basic_layout
from conan.tools.meson import Meson, MesonToolchain
Expand All @@ -18,7 +16,7 @@
class XkbcommonConan(ConanFile):
name = "xkbcommon"
description = "keymap handling library for toolkits and window systems"
topics = ("keyboard")
topics = ("keyboard", "wayland", "x11", "xkb")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/xkbcommon/libxkbcommon"
license = "MIT"
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 ac2e523

Please sign in to comment.