Skip to content

Commit

Permalink
[Meson] Formatting Meson prefix parameter (#14295)
Browse files Browse the repository at this point in the history
* Formatting Meson.prefix. Removed useless variables

* Added asserts
  • Loading branch information
franramirez688 authored Jul 19, 2023
1 parent cc65e31 commit 89f01e1
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 14 deletions.
2 changes: 1 addition & 1 deletion conan/tools/meson/meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def configure(self, reconfigure=False):
cmd += "".join([f'{cmd_param} "{meson_option}"' for meson_option in meson_filenames])
cmd += ' "{}" "{}"'.format(build_folder, source_folder)
if self._conanfile.package_folder:
cmd += ' -Dprefix="{}"'.format(self._conanfile.package_folder)
cmd += ' -Dprefix="{}"'.format(self._conanfile.package_folder.replace("\\", "/"))
if reconfigure:
cmd += ' --reconfigure'
self._conanfile.output.info("Meson configure cmd: {}".format(cmd))
Expand Down
21 changes: 8 additions & 13 deletions conan/tools/meson/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ class MesonToolchain(object):
[constants]
preprocessor_definitions = [{% for it, value in preprocessor_definitions.items() -%}
'-D{{ it }}="{{ value}}"'{%- if not loop.last %}, {% endif %}{% endfor %}]
# Constants to be overridden by conan_meson_deps_flags.ini (if exists)
deps_c_args = []
deps_c_link_args = []
deps_cpp_args = []
deps_cpp_link_args = []
[project options]
{% for it, value in project_options.items() -%}
Expand Down Expand Up @@ -69,16 +64,16 @@ class MesonToolchain(object):
{% if backend %}backend = '{{backend}}' {% endif %}
{% if pkg_config_path %}pkg_config_path = '{{pkg_config_path}}'{% endif %}
# C/C++ arguments
c_args = {{c_args}} + preprocessor_definitions + deps_c_args
c_link_args = {{c_link_args}} + deps_c_link_args
cpp_args = {{cpp_args}} + preprocessor_definitions + deps_cpp_args
cpp_link_args = {{cpp_link_args}} + deps_cpp_link_args
c_args = {{c_args}} + preprocessor_definitions
c_link_args = {{c_link_args}}
cpp_args = {{cpp_args}} + preprocessor_definitions
cpp_link_args = {{cpp_link_args}}
{% if is_apple_system %}
# Objective-C/C++ arguments
objc_args = {{objc_args}} + preprocessor_definitions + deps_c_args
objc_link_args = {{objc_link_args}} + deps_c_link_args
objcpp_args = {{objcpp_args}} + preprocessor_definitions + deps_cpp_args
objcpp_link_args = {{objcpp_link_args}} + deps_cpp_link_args
objc_args = {{objc_args}} + preprocessor_definitions
objc_link_args = {{objc_link_args}}
objcpp_args = {{objcpp_args}} + preprocessor_definitions
objcpp_link_args = {{objcpp_link_args}}
{% endif %}
{% for context, values in cross_build.items() %}
Expand Down
61 changes: 61 additions & 0 deletions conans/test/functional/toolchains/meson/test_meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,3 +235,64 @@ def build(self):
# Checking the order of the appended user file (the order matters)
match = re.search(r"meson setup --native-file .* --native-file \"myfilename\.ini\"", client.out)
assert match


@pytest.mark.tool("meson")
@pytest.mark.skipif(platform.system() != "Windows", reason="Only for Windows")
@pytest.mark.skipif(sys.version_info.minor < 8, reason="Latest Meson versions needs Python >= 3.8")
def test_meson_using_prefix_path_in_application():
"""
Issue related https://github.com/conan-io/conan/issues/14213
"""
meson_build = textwrap.dedent("""
project('myhello ', 'c')
executable('myhello', 'src/main.c', install: true)
prefix_dir = get_option('prefix')
cfg_var = configuration_data()
cfg_var.set_quoted('MYHELLO_PREFIX', prefix_dir)
config_file = configure_file(
configuration: cfg_var,
output: 'config.h'
)
""")
main_c = textwrap.dedent("""
#include <config.h>
int main(void) {
return 0;
}
char *issue_func() {
return (MYHELLO_PREFIX);
}
""")
conanfile = textwrap.dedent("""
from conan import ConanFile
from conan.tools.meson import Meson
from conan.tools.layout import basic_layout
class myhelloConan(ConanFile):
name = "demo"
version = "0.1"
settings = "os", "compiler", "build_type", "arch"
exports_sources = "meson.build", "*.c"
package_type = "application"
generators = "MesonToolchain"
def layout(self):
basic_layout(self)
def build(self):
meson = Meson(self)
meson.configure()
meson.build()
""")
client = TestClient()
client.save({"conanfile.py": conanfile,
"src/main.c": main_c,
"meson.build": meson_build})
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

0 comments on commit 89f01e1

Please sign in to comment.