diff --git a/conans/client/cmd/build.py b/conans/client/cmd/build.py index 6cda8eb6c04..1a4207bfabf 100644 --- a/conans/client/cmd/build.py +++ b/conans/client/cmd/build.py @@ -12,7 +12,7 @@ def cmd_build(app, conanfile_path, base_path, source_folder, build_folder, package_folder, install_folder, test=False, should_configure=True, should_build=True, should_install=True, should_test=True, layout_source_folder=None, - layout_build_folder=None): + layout_build_folder=None, conf=None): """ Call to build() method saved on the conanfile.py param conanfile_path: path to a conanfile.py """ @@ -29,6 +29,8 @@ def cmd_build(app, conanfile_path, base_path, source_folder, build_folder, packa "requirements and generators from '%s' file" % (CONANFILE, CONANFILE, CONANFILE_TXT)) + if conf: + conan_file.conf.compose_conf(conf) if test: try: conan_file.requires.add_ref(test) diff --git a/conans/client/cmd/test.py b/conans/client/cmd/test.py index 4c2f580dd60..996ff39b1c2 100644 --- a/conans/client/cmd/test.py +++ b/conans/client/cmd/test.py @@ -32,7 +32,7 @@ def install_build_and_test(app, conanfile_abs_path, reference, graph_info, if build_modes is None: build_modes = ["never"] try: - install_folder = deps_install(app=app, + install_folder, conanfile = deps_install(app=app, create_reference=reference, ref_or_path=conanfile_abs_path, install_folder=test_build_folder, @@ -53,7 +53,7 @@ def install_build_and_test(app, conanfile_abs_path, reference, graph_info, cmd_build(app, conanfile_abs_path, test_build_folder, source_folder=base_folder, build_folder=test_build_folder, package_folder=os.path.join(test_build_folder, "package"), - install_folder=install_folder, test=reference) + install_folder=install_folder, test=reference, conf=conanfile.conf) finally: if delete_after_build: # Required for windows where deleting the cwd is not possible. diff --git a/conans/client/manager.py b/conans/client/manager.py index f27fba83241..d0160ce5ca1 100644 --- a/conans/client/manager.py +++ b/conans/client/manager.py @@ -146,4 +146,4 @@ def deps_install(app, ref_or_path, install_folder, base_folder, graph_info, remo if hasattr(deploy_conanfile, "deploy") and callable(deploy_conanfile.deploy): run_deploy(deploy_conanfile, install_folder) - return install_folder + return install_folder, conanfile diff --git a/conans/test/integration/toolchains/env/test_virtualenv_winbash.py b/conans/test/integration/toolchains/env/test_virtualenv_winbash.py index e79fdbd0f23..dc231f5d85e 100644 --- a/conans/test/integration/toolchains/env/test_virtualenv_winbash.py +++ b/conans/test/integration/toolchains/env/test_virtualenv_winbash.py @@ -1,9 +1,11 @@ import os import platform +import textwrap import pytest from conans.test.assets.genconanfile import GenConanfile +from conans.test.conftest import tools_locations from conans.test.utils.tools import TestClient from conans.tools import save @@ -166,3 +168,54 @@ def test_nowinbash_virtual_cygwin(client): assert not os.path.exists(os.path.join(client.current_folder, "conanrunenv.bat")) run_contents = client.load("conanrunenv.sh") assert 'export RUNTIME_VAR="/cygdrive/c/path/to/exe"' in run_contents + + +@pytest.mark.skipif(platform.system() != "Windows", reason="Requires Windows") +@pytest.mark.tool_msys2 +def test_conf_inherited_in_test_package(): + client = TestClient() + bash_path = tools_locations["msys2"]["system"]["path"]["Windows"] + "/bash.exe" + conanfile = textwrap.dedent(""" + from conan import ConanFile + + class Recipe(ConanFile): + name="msys2" + version="1.0" + + def package_info(self): + self.conf_info.define("tools.microsoft.bash:subsystem", "msys2") + self.conf_info.define("tools.microsoft.bash:path", "{}") + """.format(bash_path)) + client.save({"conanfile.py": conanfile}) + client.run("create .") + + conanfile = textwrap.dedent(""" + from conan import ConanFile + + class Recipe(ConanFile): + name="consumer" + version="1.0" + """) + test_package = textwrap.dedent(""" + from conan import ConanFile + + class Recipe(ConanFile): + name="test" + version="1.0" + win_bash = True + + def build_requirements(self): + self.tool_requires(self.tested_reference_str) + self.tool_requires("msys2/1.0") + + def build(self): + self.output.warning(self.conf.get("tools.microsoft.bash:subsystem")) + self.run("aclocal --version") + + def test(self): + pass + """) + client.save({"conanfile.py": conanfile, "test_package/conanfile.py": test_package}) + client.run("create . -s:b os=Windows -s:h os=Windows") + assert "are needed to run commands in a Windows subsystem" not in client.out + assert "aclocal (GNU automake)" in client.out