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

Add unix_path_package_info_legacy compatibility function #12887

Merged
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
2 changes: 1 addition & 1 deletion conan/tools/microsoft/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from conan.tools.microsoft.layout import vs_layout
from conan.tools.microsoft.msbuild import MSBuild
from conan.tools.microsoft.msbuilddeps import MSBuildDeps
from conan.tools.microsoft.subsystems import unix_path
from conan.tools.microsoft.subsystems import unix_path, unix_path_package_info_legacy
from conan.tools.microsoft.toolchain import MSBuildToolchain
from conan.tools.microsoft.nmaketoolchain import NMakeToolchain
from conan.tools.microsoft.nmakedeps import NMakeDeps
Expand Down
6 changes: 6 additions & 0 deletions conan/tools/microsoft/subsystems.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from conans.client.subsystems import deduce_subsystem, subsystem_path
from conans.client.tools.win import unix_path as unix_path_legacy_tools


def unix_path(conanfile, path, scope="build"):
subsystem = deduce_subsystem(conanfile, scope=scope)
return subsystem_path(subsystem, path)

def unix_path_package_info_legacy(conanfile, path, path_flavor=None):
# Call legacy implementation, which has different logic
# to autodeduce the subsystem type for the conversion.
return unix_path_legacy_tools(path, path_flavor)
27 changes: 22 additions & 5 deletions conans/test/unittests/tools/microsoft/test_subsystem.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import mock
import textwrap

import pytest

from conan.tools.microsoft import unix_path
from conan.tools.microsoft import unix_path, unix_path_package_info_legacy
from conans.model.conf import ConfDefinition
from conans.test.utils.mocks import MockSettings, ConanFileMock


@pytest.mark.parametrize("subsystem, expected_path", [
expected_results = [
("msys2", '/c/path/to/stuff'),
("msys", '/c/path/to/stuff'),
("cygwin", '/cygdrive/c/path/to/stuff'),
("wsl", '/mnt/c/path/to/stuff'),
("sfu", '/dev/fs/C/path/to/stuff')
])
]

@pytest.mark.parametrize("subsystem, expected_path", expected_results)
def test_unix_path(subsystem, expected_path):
c = ConfDefinition()
c.loads(textwrap.dedent("""\
Expand All @@ -29,3 +30,19 @@ def test_unix_path(subsystem, expected_path):

path = unix_path(conanfile, "c:/path/to/stuff")
assert expected_path == path

@mock.patch("platform.system", mock.MagicMock(return_value='Windows'))
@pytest.mark.parametrize("subsystem, expected_path", expected_results)
def test_unix_path_package_info_legacy_windows(subsystem, expected_path):
test_path = "c:/path/to/stuff"
conanfile = ConanFileMock()
package_info_legacy_path = unix_path_package_info_legacy(conanfile, test_path, path_flavor=subsystem)
assert expected_path == package_info_legacy_path

@mock.patch("platform.system", mock.MagicMock(return_value='Darwin'))
@pytest.mark.parametrize("subsystem, expected_path", expected_results)
def test_unix_path_package_info_legacy_not_windows(subsystem, expected_path):
test_path = "c:/path/to/stuff"
conanfile = ConanFileMock()
package_info_legacy_path = unix_path_package_info_legacy(conanfile, test_path, path_flavor=subsystem)
assert test_path == package_info_legacy_path