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
fix: sysroot property #16011
Open
ErniGH
wants to merge
5
commits into
conan-io:develop2
Choose a base branch
from
ErniGH:erni/fi-toolbuild-sysroot-Meson
base: develop2
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
fix: sysroot property #16011
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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): | ||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Who is adding this to the file then? |
||
|
||
# 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}") | ||
uilianries marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
sys_root
is a property, does it still need to be added as a flag? Wouldn't Meson take care of that automatically?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it looks weird. I'm going to figure out how Meson manages this attribute because I think that it should automatically inject that one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's needed: https://mesonbuild.com/Cross-compilation.html#properties
The
sys_root
property only configures thePKG_CONFIG_SYSROOT_DIR
, nothing more.But how Meson users manage
--sysroot
then?They pass to
c_flags
andcxx_flags
:On the other hand, Conan users could have it defined in
tools.build:cflags
and so on.