-
Notifications
You must be signed in to change notification settings - Fork 970
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
BugFix: MesonToolchain does not pick up CC/CXX from build requirements (in build profile) #8362
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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 |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import os | ||
import textwrap | ||
|
||
from conans.test.assets.sources import gen_function_cpp, gen_function_h | ||
from conans.test.functional.toolchains.meson._base import TestMesonBase | ||
|
||
|
||
class MesonToolchainTest(TestMesonBase): | ||
|
||
_conanfile_br = textwrap.dedent(""" | ||
from conans import ConanFile | ||
|
||
|
||
class BuildRequires(ConanFile): | ||
|
||
def package_info(self): | ||
self.env_info.CC = "custom C compiler" | ||
self.env_info.CXX = "custom CXX compiler" | ||
""") | ||
|
||
_conanfile_py = textwrap.dedent(""" | ||
from conans import ConanFile, tools | ||
from conan.tools.meson import Meson, MesonToolchain | ||
|
||
|
||
class App(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = {"shared": [True, False], "fPIC": [True, False]} | ||
default_options = {"shared": False, "fPIC": True} | ||
build_requires = ("br/1.0@",) | ||
generators = ("virtualenv",) | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def generate(self): | ||
tc = MesonToolchain(self) | ||
tc.generate() | ||
|
||
def build(self): | ||
meson = Meson(self) | ||
meson.configure() | ||
meson.build() | ||
""") | ||
|
||
_meson_build = textwrap.dedent(""" | ||
project('tutorial', 'cpp') | ||
hello = library('hello', 'hello.cpp') | ||
executable('demo', 'main.cpp', link_with: hello) | ||
""") | ||
|
||
def test_build(self): | ||
self.t.save({"conanfile.py": self._conanfile_br}) | ||
self.t.run("create . br/1.0@") | ||
|
||
hello_h = gen_function_h(name="hello") | ||
hello_cpp = gen_function_cpp(name="hello") | ||
app = gen_function_cpp(name="main", includes=["hello"], calls=["hello"]) | ||
|
||
self.t.save({"conanfile.py": self._conanfile_py, | ||
"meson.build": self._meson_build, | ||
"hello.h": hello_h, | ||
"hello.cpp": hello_cpp, | ||
"main.cpp": app}, clean_first=True) | ||
|
||
self.t.run("install . %s" % self._settings_str) | ||
|
||
content = self.t.load("conan_meson_native.ini") | ||
|
||
self.assertIn("c = 'custom C compiler", content) | ||
self.assertIn("cpp = 'custom CXX compiler", content) |
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
67 changes: 67 additions & 0 deletions
67
conans/test/functional/toolchains/meson/test_preprocessor_definitions.py
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import os | ||
import textwrap | ||
|
||
from conans.test.assets.sources import gen_function_cpp, gen_function_h | ||
from conans.test.functional.toolchains.meson._base import TestMesonBase | ||
|
||
|
||
class MesonPreprocessorDefinitionsTest(TestMesonBase): | ||
_conanfile_py = textwrap.dedent(""" | ||
from conans import ConanFile, tools | ||
from conan.tools.meson import Meson, MesonToolchain | ||
|
||
|
||
class App(ConanFile): | ||
settings = "os", "arch", "compiler", "build_type" | ||
options = {"shared": [True, False], "fPIC": [True, False]} | ||
default_options = {"shared": False, "fPIC": True} | ||
|
||
def config_options(self): | ||
if self.settings.os == "Windows": | ||
del self.options.fPIC | ||
|
||
def generate(self): | ||
tc = MesonToolchain(self) | ||
tc.preprocessor_definitions["TEST_DEFINITION1"] = "TestPpdValue1" | ||
tc.preprocessor_definitions["TEST_DEFINITION2"] = "TestPpdValue2" | ||
tc.generate() | ||
|
||
def build(self): | ||
meson = Meson(self) | ||
meson.configure() | ||
meson.build() | ||
""") | ||
|
||
_meson_build = textwrap.dedent(""" | ||
project('tutorial', 'cpp') | ||
hello = library('hello', 'hello.cpp') | ||
executable('demo', 'main.cpp', link_with: hello) | ||
""") | ||
|
||
def test_build(self): | ||
hello_h = gen_function_h(name="hello") | ||
hello_cpp = gen_function_cpp(name="hello", | ||
preprocessor=["TEST_DEFINITION1", "TEST_DEFINITION2"]) | ||
app = gen_function_cpp(name="main", includes=["hello"], calls=["hello"]) | ||
|
||
self.t.save({"conanfile.py": self._conanfile_py, | ||
"meson.build": self._meson_build, | ||
"hello.h": hello_h, | ||
"hello.cpp": hello_cpp, | ||
"main.cpp": app}) | ||
|
||
self.t.run("install . %s" % self._settings_str) | ||
|
||
content = self.t.load("conan_meson_native.ini") | ||
|
||
self.assertIn("[built-in options]", content) | ||
self.assertIn("buildtype = 'release'", content) | ||
|
||
self.t.run("build .") | ||
self.t.run_command(os.path.join("build", "demo")) | ||
|
||
self.assertIn("hello: Release!", self.t.out) | ||
self.assertIn("TEST_DEFINITION1: TestPpdValue1", self.t.out) | ||
self.assertIn("TEST_DEFINITION2: TestPpdValue2", self.t.out) | ||
|
||
self._check_binary() |
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.
I'd prefer to wait until we have the new env management there: #8534, because partially providing it, then breaking could be probably more annoying that having to wait.