Skip to content
Open
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
8 changes: 6 additions & 2 deletions conan/tools/meson/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,12 @@ def __init__(self, conanfile, backend=None, native=False):
compilers_by_conf = self._conanfile_conf.get("tools.build:compiler_executables", default={},
check_type=dict)
# Read the VirtualBuildEnv to update the variables
build_env = self._conanfile.buildenv_build.vars(self._conanfile) if native else (
VirtualBuildEnv(self._conanfile, auto_generate=True).vars())
venv = VirtualBuildEnv(self._conanfile, auto_generate=True)
if native:
# respect any vars from build requirements but prefer build profile vars if there are any
build_env = self._conanfile.buildenv_build.compose_env(venv.environment()).vars(self._conanfile)
else:
build_env = venv.vars()
#: Sets the Meson ``c`` variable, defaulting to the ``CC`` build environment value.
#: If provided as a blank-separated string, it will be transformed into a list.
#: Otherwise, it remains a single string.
Expand Down
62 changes: 62 additions & 0 deletions test/integration/toolchains/meson/test_mesontoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,68 @@ def generate(self):
assert "[host_machine]" in cross_content


def test_native_attribute_respects_environment_from_build_requirement():
"""
Tests that environment vars set by build requirements are respected by the
native toolchain configuration
"""
host = textwrap.dedent("""
[settings]
arch=armv8
build_type=Release
compiler=gcc
compiler.cppstd=gnu17
compiler.libcxx=libstdc++11
compiler.version=11
os=Linux

[conf]
tools.build:compiler_executables={"c": "gcc", "cpp": "g++"}
""")
build = textwrap.dedent("""
[settings]
os=Linux
arch=x86_64
compiler=clang
compiler.version=12
compiler.libcxx=libc++
compiler.cppstd=11

[conf]
tools.build:compiler_executables={"c": "clang", "cpp": "clang++"}
""")
client = TestClient()
pkgconf = textwrap.dedent(r"""
from conan import ConanFile
class Pkg(ConanFile):
settings = "os"
def package_info(self):
self.buildenv_info.define_path("PKG_CONFIG", "/usr/local/mypkgconf")
""")
conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.meson import MesonToolchain
class Pkg(ConanFile):
settings = "os", "compiler", "arch", "build_type"
tool_requires = "pkgconf/1.0"
def generate(self):
tc = MesonToolchain(self)
tc.generate()
# We're cross-building, no need to check it
tc = MesonToolchain(self, native=True)
tc.generate()
""")
client.save({"host": host,
"build": build,
"pkgconf/conanfile.py": pkgconf,
"conanfile.py": conanfile})

client.run("export pkgconf --name=pkgconf --version=1.0")
client.run("install . -pr:h host -pr:b build --build='*'")
native_content = client.load(MesonToolchain.native_filename)
assert "pkg-config = '/usr/local/mypkgconf'" in native_content


def test_native_attribute_error():
client = TestClient()
conanfile = textwrap.dedent("""
Expand Down
Loading