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: add preprocessor_definitions to Meson + CC/CXX from build requirements #8353
Merged
memsharded
merged 5 commits into
conan-io:develop
from
SSE4:meson_preprocessor_definitions
Jun 23, 2021
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4239b67
- add preprocessor_definitions to Meson
SSE4 b442e5a
- fix env propagation
SSE4 e4e7444
Update test_ios.py
SSE4 1565f8c
Merge remote-tracking branch 'origin/develop' into meson_preprocessor…
lasote 303bd4f
New environment mechanism adopted
lasote 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
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
53 changes: 53 additions & 0 deletions
53
conans/test/functional/toolchains/meson/test_meson_build_require.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,53 @@ | ||
import pytest | ||
|
||
from conans.test.assets.genconanfile import GenConanfile | ||
from conans.test.functional.toolchains.meson._base import get_meson_version | ||
from conans.test.utils.tools import TestClient | ||
|
||
@pytest.mark.toolchain | ||
@pytest.mark.tool_meson | ||
@pytest.mark.skipif(get_meson_version() < "0.56.0", reason="requires meson >= 0.56.0") | ||
def test_env_vars_from_build_require(): | ||
br = str(GenConanfile().with_name("hello_compiler").with_version("1.0").with_import("import os")) | ||
br += """ | ||
def package_info(self): | ||
{} | ||
""" | ||
vars = ["CC", "CC_LD", "CXX", "CXX_LD", "AR", "STRIP", "AS", "WINDRES", "PKG_CONFIG", "LD"] | ||
lines = "\n ".join(['self.buildenv_info.define("{var}", "{var}_VALUE")'.format(var=var) | ||
for var in vars]) | ||
cf = br.format(lines) | ||
|
||
client = TestClient() | ||
client.save({"conanfile.py": cf}) | ||
client.run("create .") | ||
|
||
conanfile = GenConanfile().with_settings("os", "arch", "compiler", "build_type")\ | ||
.with_name("consumer").with_version("1.0").with_generator("MesonToolchain")\ | ||
.with_build_requirement("hello_compiler/1.0") | ||
client.save({"conanfile.py": conanfile}) | ||
client.run("install . -pr:h=default -pr:b=default") | ||
content = client.load("conan_meson_native.ini") | ||
assert "c = 'CC_VALUE'" in content | ||
assert "cpp = 'CXX_VALUE'" in content | ||
assert "c_ld = 'CC_LD_VALUE'" in content | ||
assert "cpp_ld = 'CXX_LD_VALUE'" in content | ||
assert "ar = 'AR_VALUE'" in content | ||
assert "strip = 'STRIP_VALUE'" in content | ||
assert "as = 'AS_VALUE'" in content | ||
assert "windres = 'WINDRES_VALUE'" in content | ||
assert "pkgconfig = 'PKG_CONFIG_VALUE'" in content | ||
|
||
# Now change the build require to declare only LD | ||
lines = '\n self.buildenv_info.define("LD", "LD_VALUE")' | ||
cf = br.format(lines) | ||
client = TestClient() | ||
client.save({"conanfile.py": cf}) | ||
client.run("create .") | ||
|
||
# Create the consumer again, now the LD env var will be applied | ||
client.save({"conanfile.py": conanfile}) | ||
client.run("install . -pr:h=default -pr:b=default") | ||
content = client.load("conan_meson_native.ini") | ||
assert "c_ld = 'LD_VALUE'" in content | ||
assert "cpp_ld = 'LD_VALUE'" in content |
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 have merged this PR, because it is already an improvement.
But this is a bit "hardcoded". The
VirtualEnv
might be used ingenerate()
in a different way, to customize what gets pulled into the environment, and users might prioritize dependencies, [conf], environment, or other stuff, but that will not be taken into account here.It seems the ideal is that the MesonToolchain could use the
conanbuildenv.xx
script, or some other way to reuse the build environment. But I ignore how Meson works for this, I guess the activation ofconanbuildenv.xx
is still necessary?