Skip to content
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

cmd_wrapper must get the conanfile argument #13564

Merged
merged 1 commit into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions conan/internal/conan_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def __init__(self, cache):
else:
self._wrapper = None

def wrap(self, cmd):
def wrap(self, cmd, conanfile, **kwargs):
if self._wrapper is None:
return cmd
return self._wrapper(cmd)
return self._wrapper(cmd, conanfile=conanfile, **kwargs)


class ConanFileHelpers:
Expand Down
2 changes: 1 addition & 1 deletion conans/model/conan_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def generators_path(self) -> Path:
def run(self, command, stdout=None, cwd=None, ignore_errors=False, env="", quiet=False,
shell=True, scope="build"):
# NOTE: "self.win_bash" is the new parameter "win_bash" for Conan 2.0
command = self._conan_helpers.cmd_wrapper.wrap(command)
command = self._conan_helpers.cmd_wrapper.wrap(command, conanfile=self)
if env == "": # This default allows not breaking for users with ``env=None`` indicating
# they don't want any env-file applied
env = "conanbuild" if scope == "build" else "conanrun"
Expand Down
25 changes: 23 additions & 2 deletions conans/test/integration/extensions/test_plugin_cmd_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@ def test_plugin_cmd_wrapper():
c = TestClient()
plugins = os.path.join(c.cache.cache_folder, "extensions", "plugins")
wrapper = textwrap.dedent("""
def cmd_wrapper(cmd):
def cmd_wrapper(cmd, **kwargs):
return 'echo "{}"'.format(cmd)
""")
# TODO: Decide name
save(os.path.join(plugins, "cmd_wrapper.py"), wrapper)
conanfile = textwrap.dedent("""
from conan import ConanFile
Expand All @@ -28,6 +27,28 @@ def generate(self):
assert 'Other stuff' in c.out


def test_plugin_cmd_wrapper_conanfile():
"""
we can get the name of the caller conanfile too
"""
c = TestClient()
plugins = os.path.join(c.cache.cache_folder, "extensions", "plugins")
wrapper = textwrap.dedent("""
def cmd_wrapper(cmd, conanfile, **kwargs):
return 'echo "{}!:{}!"'.format(conanfile.ref, cmd)
""")
save(os.path.join(plugins, "cmd_wrapper.py"), wrapper)
conanfile = textwrap.dedent("""
from conan import ConanFile
class Pkg(ConanFile):
def generate(self):
self.run("Hello world")
""")
c.save({"conanfile.py": conanfile})
c.run("install . --name=pkg --version=0.1")
assert 'pkg/0.1!:Hello world!' in c.out


def test_plugin_profile_error_vs():
c = TestClient()
c.save({"conanfile.py": GenConanfile("pkg", "1.0")})
Expand Down