Skip to content

fix: sysroot property #16011

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

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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: 8 additions & 0 deletions conan/tools/meson/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,14 @@ def _sanitize_format(v):
# These link_args have already the LDFLAGS env value so let's add only the new possible ones
self.objc_link_args.extend(apple_flags + extra_flags["ldflags"])
self.objcpp_link_args.extend(apple_flags + extra_flags["ldflags"])
# Meson properties
sys_root = self._conanfile.conf.get("tools.build:sysroot", check_type=str)
if sys_root:
self.properties["sys_root"] = sys_root
self.c_args.append("--sysroot=" + sys_root)
self.cpp_args.append("--sysroot=" + sys_root)
self.c_link_args.append("--sysroot=" + sys_root)
self.cpp_link_args.append("--sysroot=" + sys_root)

if self.libcxx:
self.cpp_args.append(self.libcxx)
Expand Down
143 changes: 142 additions & 1 deletion conans/test/functional/toolchains/meson/test_meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from conans.model.recipe_ref import RecipeReference
from conans.test.assets.sources import gen_function_cpp, gen_function_h
from conans.test.functional.toolchains.meson._base import TestMesonBase
from conans.test.utils.tools import TestClient
from conans.test.utils.tools import TestClient, GenConanfile


class MesonToolchainTest(TestMesonBase):
Expand Down Expand Up @@ -309,3 +309,144 @@ def build(self):
client.run("build .")
assert "unrecognized character escape sequence" not in str(client.out) # if Visual
assert "unknown escape sequence" not in str(client.out) # if mingw


@pytest.mark.tool("meson")
@pytest.mark.skipif(sys.version_info.minor < 8, reason="Latest Meson versions needs Python >= 3.8")
@pytest.mark.skipif(platform.system() != "Darwin", reason="Requires apple-clang")
def test_meson_sysroot_flag():
"""
Testing when users pass tools.build:sysroot on the profile
"""
profile = textwrap.dedent("""
[settings]
os = Macos
os.version=10.11
arch = armv7
compiler = apple-clang
compiler.version = 12.0
compiler.libcxx = libc++

[conf]
tools.build:sysroot = /my/new/sysroot/path
""")
myfilename = textwrap.dedent("""
[project options]
my_option = 'fake-option'
""")
conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.meson import Meson
class Pkg(ConanFile):
name = "test_name"
version = "1.0"
settings = "os", "compiler", "build_type", "arch"
generators = "MesonToolchain"
exports_sources = "meson.build", "src/*"
def build(self):
meson = Meson(self)
meson.configure()
meson.build()
def layout(self):
self.folders.build = "./test-build"
""")
client = TestClient()
client.save({"conanfile.py": conanfile,
"build/myfilename.ini": myfilename,
"meson.build": "project('tutorial', 'cpp')", # dummy one
"profile": profile})

client.run("install . -pr=profile")
client.run("build . -pr=profile", assert_error=False)

# Check the meson configuration file
conan_meson = client.load("conan_meson_cross.ini")
assert re.search(r"sys_root = '/my/new/sysroot/path'", conan_meson)
assert re.search(r"c_args =.+--sysroot=/my/new/sysroot/path.+", conan_meson)
assert re.search(r"c_link_args =.+--sysroot=/my/new/sysroot/path.+", conan_meson)
assert re.search(r"cpp_args =.+--sysroot=/my/new/sysroot/path.+", conan_meson)
assert re.search(r"cpp_link_args =.+--sysroot=/my/new/sysroot/path.+", conan_meson)

# Check the meson-log.txt
conan_log = client.load("./test-build/meson-logs/meson-log.txt")
assert r"--sysroot=/my/new/sysroot/path" in conan_log


@pytest.mark.tool("autotools")
@pytest.mark.tool("meson")
@pytest.mark.skipif(platform.system() != "Linux", reason="Requires --sysroot on Linux")
def test_meson_sysroot_flag_cross():
"""
Testing when users pass tools.build:sysroot on the profile
"""
profile = textwrap.dedent("""
[settings]
os=Linux
arch=armv8
compiler=gcc
compiler.version=8
compiler.libcxx=libstdc++11
build_type=Release

[conf]
tools.build:sysroot = /my/new/sysroot/path
tools.build:compiler_executables={"c": "gcc", "cpp": "g++"}
""")
myfilename = textwrap.dedent("""
[project options]
my_option = 'fake-option'
""")
conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.meson import MesonToolchain, Meson
from conan.tools.gnu import PkgConfigDeps
class Pkg(ConanFile):
name = "test_name"
version = "1.0"
settings = "os", "compiler", "build_type", "arch"
exports_sources = "meson.build", "src/*"
#tool_requires = "pkgconf/2.1.0"
def build(self):
meson = Meson(self)
meson.configure()
meson.build()
def layout(self):
self.folders.build = "./test-build"
def requirements(self):
self.requires("foo/1.0")
def generate(self):
tc = MesonToolchain(self)
tc.generate()
tc = PkgConfigDeps(self)
tc.generate()
""")
meson_build = textwrap.dedent("""
project('test_name', 'cpp')
pkg = import('pkgconfig')
zdep = dependency('foo', version : '>=0.1')
shared_library('test_name', 'src/test_name.cpp', install: true, dependencies : zdep)
install_headers('src/test_name.h')
""")
client = TestClient()
client.save({"conanfile.py": conanfile,
"build/myfilename.ini": myfilename,
"meson.build": meson_build,
"profile": profile,
"foo/conanfile.py": GenConanfile("foo", "1.0")})

client.run("create foo")
client.run("install . -pr:h=profile")
client.run("build . -pr:h=profile", assert_error=True)

# Check the meson configuration file
print(f"CACHE: {client.cache_folder}")
conan_meson = client.load("conan_meson_cross.ini")
assert "sys_root = '/my/new/sysroot/path'\n" in conan_meson
assert re.search(r"c_args =.+--sysroot=/my/new/sysroot/path.+", conan_meson)
assert re.search(r"c_link_args =.+--sysroot=/my/new/sysroot/path.+", conan_meson)
assert re.search(r"cpp_args =.+--sysroot=/my/new/sysroot/path.+", conan_meson)
assert re.search(r"cpp_link_args =.+--sysroot=/my/new/sysroot/path.+", conan_meson)

# Check the meson-log.txt
conan_log = client.load("./test-build/meson-logs/meson-log.txt")
assert r"--sysroot=/my/new/sysroot/path" in conan_log