예제 #1
0
 def with_pacman(self):
     if self.is_linux:
         return self.linux_distro in ["arch", "manjaro"]
     elif self.is_windows and which('uname.exe'):
         uname = check_output_runner(['uname.exe', '-s'])
         return uname.startswith('MSYS_NT') and which('pacman.exe')
     return False
예제 #2
0
 def test_system_package_tool_installed(self):
     if (platform.system() != "Linux" and platform.system() != "Macos"
             and platform.system() != "Windows"):
         return
     if platform.system() == "Windows" and not which("choco.exe"):
         return
     spt = SystemPackageTool(output=self.out)
     expected_package = "git"
     if platform.system() == "Windows" and which("choco.exe"):
         spt = SystemPackageTool(tool=ChocolateyTool(output=self.out),
                                 output=self.out)
         # Git is not installed by default on Chocolatey
         expected_package = "chocolatey"
     else:
         if platform.system() != "Windows" and not which("git"):
             return
     # The expected should be installed on development/testing machines
     self.assertTrue(spt._tool.installed(expected_package))
     self.assertTrue(spt.installed(expected_package))
     # This package hopefully doesn't exist
     self.assertFalse(
         spt._tool.installed(
             "oidfjgesiouhrgioeurhgielurhgaeiorhgioearhgoaeirhg"))
     self.assertFalse(
         spt.installed("oidfjgesiouhrgioeurhgielurhgaeiorhgioearhgoaeirhg"))
예제 #3
0
파일: env.py 프로젝트: 19317362/conan
def remove_from_path(command):
    curpath = os.getenv("PATH")
    first_it = True
    for n in range(30):
        if not first_it:
            with environment_append({"PATH": curpath}):
                the_command = which(command)
        else:
            the_command = which(command)
            first_it = False

        if not the_command:
            break
        new_path = []
        for entry in curpath.split(os.pathsep):
            if not _path_equals(entry, os.path.dirname(the_command)):
                new_path.append(entry)

        curpath = os.pathsep.join(new_path)
    else:

        raise ConanException("Error in tools.remove_from_path!! couldn't remove the tool '%s' "
                             "from the path after 30 attempts, still found in '%s' this is a Conan client bug, please open an issue at: "
                             "https://github.com/conan-io/conan\n\nPATH=%s" % (command, the_command, os.getenv("PATH")))

    with environment_append({"PATH": curpath}):
        yield
예제 #4
0
파일: env.py 프로젝트: ytimenkov/conan
def remove_from_path(command):
    curpath = os.getenv("PATH")
    first_it = True
    for n in range(30):
        if not first_it:
            with environment_append({"PATH": curpath}):
                the_command = which(command)
        else:
            the_command = which(command)
            first_it = False

        if not the_command:
            break
        new_path = []
        for entry in curpath.split(os.pathsep):
            if not _path_equals(entry, os.path.dirname(the_command)):
                new_path.append(entry)

        curpath = os.pathsep.join(new_path)
    else:

        raise ConanException(
            "Error in tools.remove_from_path!! couldn't remove the tool '%s' "
            "from the path after 30 attempts, still found in '%s' this is a Conan client bug, please open an issue at: "
            "https://github.com/conan-io/conan\n\nPATH=%s" %
            (command, the_command, os.getenv("PATH")))

    with environment_append({"PATH": curpath}):
        yield
예제 #5
0
 def vswhere_path_test(self):
     """
     Locate vswhere in PATH or in ProgramFiles
     """
     # vswhere not found
     with tools.environment_append({"ProgramFiles": None, "ProgramFiles(x86)": None, "PATH": ""}):
         with six.assertRaisesRegex(self, ConanException, "Cannot locate vswhere"):
             vswhere()
     # vswhere in ProgramFiles but not in PATH
     program_files = get_env("ProgramFiles(x86)") or get_env("ProgramFiles")
     vswhere_path = None
     if program_files:
         expected_path = os.path.join(program_files, "Microsoft Visual Studio", "Installer",
                                      "vswhere.exe")
         if os.path.isfile(expected_path):
             vswhere_path = expected_path
             with tools.environment_append({"PATH": ""}):
                 self.assertTrue(vswhere())
     # vswhere in PATH but not in ProgramFiles
     env = {"ProgramFiles": None, "ProgramFiles(x86)": None}
     if not which("vswhere") and vswhere_path:
             vswhere_folder = os.path.join(program_files, "Microsoft Visual Studio", "Installer")
             env.update({"PATH": [vswhere_folder]})
     with tools.environment_append(env):
         self.assertTrue(vswhere())
예제 #6
0
def rename(conanfile, src, dst):
    """
    rename a file or folder to avoid "Access is denied" error on Windows
    :param conanfile: conanfile object
    :param src: Source file or folder
    :param dst: Destination file or folder
    :return: None
    """
    # FIXME: This function has been copied from legacy. Needs to fix: which() call and wrap subprocess call.
    if os.path.exists(dst):
        raise ConanException("rename {} to {} failed, dst exists.".format(
            src, dst))

    if platform.system() == "Windows" and which("robocopy") and os.path.isdir(
            src):
        # /move Moves files and directories, and deletes them from the source after they are copied.
        # /e Copies subdirectories. Note that this option includes empty directories.
        # /ndl Specifies that directory names are not to be logged.
        # /nfl Specifies that file names are not to be logged.
        process = subprocess.Popen(
            ["robocopy", "/move", "/e", "/ndl", "/nfl", src, dst],
            stdout=subprocess.PIPE)
        process.communicate()
        if process.returncode > 7:  # https://ss64.com/nt/robocopy-exit.html
            raise ConanException("rename {} to {} failed.".format(src, dst))
    else:
        try:
            os.rename(src, dst)
        except Exception as err:
            raise ConanException("rename {} to {} failed: {}".format(
                src, dst, err))
예제 #7
0
 def _is_sudo_enabled():
     if "CONAN_SYSREQUIRES_SUDO" not in os.environ:
         if not which("sudo"):
             return False
         if os.name == 'posix' and os.geteuid() == 0:
             return False
         if os.name == 'nt':
             return False
     return get_env("CONAN_SYSREQUIRES_SUDO", True)
예제 #8
0
파일: android.py 프로젝트: zhengweina/conan
 def _guess_android_ndk(self):
     # TODO: Do not use envvar! This has to be provided by the user somehow
     android_ndk = os.getenv("CONAN_CMAKE_ANDROID_NDK")
     if not android_ndk:
         android_ndk = which('ndk-build')
         android_ndk = os.path.dirname(android_ndk) if android_ndk else None
     if not android_ndk:
         raise ConanException('Cannot find ANDROID_NDK (ndk-build) in the PATH')
     return android_ndk
예제 #9
0
class FunctionalToolsTest(unittest.TestCase):
    output = TestBufferConanOutput()

    @pytest.mark.tool_file  # Needs the "file" command, not by default in linux
    @pytest.mark.skipif(
        which("file") is None,
        reason="Needs the 'file' command, not by default in linux")
    def test_unix_to_dos_unit(self):
        def save_file(contents):
            tmp = temp_folder()
            filepath = os.path.join(tmp, "a_file.txt")
            save(filepath, contents)
            return filepath

        fp = save_file(b"a line\notherline\n")
        if platform.system() != "Windows":
            output = check_output_runner(["file", fp],
                                         stderr=subprocess.STDOUT)
            self.assertIn("ASCII text", str(output))
            self.assertNotIn("CRLF", str(output))

            tools.unix2dos(fp)
            output = check_output_runner(["file", fp],
                                         stderr=subprocess.STDOUT)
            self.assertIn("ASCII text", str(output))
            self.assertIn("CRLF", str(output))
        else:
            fc = tools.load(fp)
            self.assertNotIn("\r\n", fc)
            tools.unix2dos(fp)
            fc = tools.load(fp)
            self.assertIn("\r\n", fc)

        self.assertEqual("a line\r\notherline\r\n", str(tools.load(fp)))

        fp = save_file(b"a line\r\notherline\r\n")
        if platform.system() != "Windows":
            output = check_output_runner(["file", fp],
                                         stderr=subprocess.STDOUT)
            self.assertIn("ASCII text", str(output))
            self.assertIn("CRLF", str(output))

            tools.dos2unix(fp)
            output = check_output_runner(["file", fp],
                                         stderr=subprocess.STDOUT)
            self.assertIn("ASCII text", str(output))
            self.assertNotIn("CRLF", str(output))
        else:
            fc = tools.load(fp)
            self.assertIn("\r\n", fc)
            tools.dos2unix(fp)
            fc = tools.load(fp)
            self.assertNotIn("\r\n", fc)

        self.assertEqual("a line\notherline\n", str(tools.load(fp)))
예제 #10
0
    def system_package_tool_fail_when_not_0_returned_test(self):
        def get_linux_error_message():
            """
            Get error message for Linux platform if distro is supported, None otherwise
            """
            os_info = OSInfo()
            update_command = None
            if os_info.with_apt:
                update_command = "sudo -A apt-get update"
            elif os_info.with_yum:
                update_command = "sudo -A yum check-update -y"
            elif os_info.with_dnf:
                update_command = "sudo -A dnf check-update -y"
            elif os_info.with_zypper:
                update_command = "sudo -A zypper --non-interactive ref"
            elif os_info.with_pacman:
                update_command = "sudo -A pacman -Syyu --noconfirm"

            return ("Command '{0}' failed".format(update_command)
                    if update_command is not None else None)

        platform_update_error_msg = {
            "Linux":
            get_linux_error_message(),
            "Darwin":
            "Command 'brew update' failed",
            "Windows":
            "Command 'choco outdated' failed" if which("choco.exe") else None,
        }

        runner = RunnerMock(return_ok=False)
        output = ConanOutput(StringIO())
        pkg_tool = ChocolateyTool(
            output=output) if which("choco.exe") else None
        spt = SystemPackageTool(runner=runner, tool=pkg_tool, output=output)

        msg = platform_update_error_msg.get(platform.system(), None)
        if msg is not None:
            with six.assertRaisesRegex(self, ConanException, msg):
                spt.update()
        else:
            spt.update()  # Won't raise anything because won't do anything
예제 #11
0
    def with_apt(self):
        if not self.is_linux:
            return False

        apt_location = which('apt-get')
        if apt_location:
            # Check if we actually have the official apt package.
            try:
                output = check_output_runner([apt_location, 'moo'])
            except CalledProcessErrorWithStderr:
                return False
            else:
                # Yes, we have mooed today. :-) MOOOOOOOO.
                return True
        else:
            return False
예제 #12
0
def remove_from_path(command):
    curpath = os.getenv("PATH")
    while 1:
        with environment_append({"PATH": curpath}):
            the_command = which(command)
        if not the_command:
            break
        new_path = []
        if "sysnative" in the_command and platform.system() == "Windows":
            the_command = the_command.replace("sysnative", "system32")
        for entry in curpath.split(os.pathsep):
            if entry != os.path.dirname(the_command):
                new_path.append(entry)
        curpath = os.pathsep.join(new_path)

    with environment_append({"PATH": curpath}):
        yield
예제 #13
0
    def __enter__(self):
        if self._var_to_add:
            for name, value in self._var_to_add:
                os.environ[name] = value
        if self._var_to_remove:
            for name in self._var_to_add:
                os.environ[name] = None
        if self._paths_to_add:
            os.environ['PATH'] = "%s%s%s" % (os.environ['PATH'], os.pathsep,
                                             os.pathsep.join(
                                                 self._paths_to_add))

        if self._cmds_to_remove:
            for cmd in self._cmds_to_remove:
                self._paths_to_remove.extend(which(cmd))

        if self._paths_to_remove:
            env = os.environ['PATH'].split(os.pathsep)
            os.environ['PATH'] = os.pathsep.join(
                [p for p in env if p not in self._paths_to_remove])
예제 #14
0
    def with_apt(self):
        if not self.is_linux:
            return False

        # https://github.com/conan-io/conan/issues/8737 zypper-aptitude can fake it
        if "opensuse" in self.linux_distro or "sles" in self.linux_distro:
            return False

        apt_location = which('apt-get')
        if apt_location:
            # Check if we actually have the official apt package.
            try:
                output = check_output_runner([apt_location, 'moo'])
            except CalledProcessErrorWithStderr:
                return False
            else:
                # Yes, we have mooed today. :-) MOOOOOOOO.
                return True
        else:
            return False
예제 #15
0
from conans.util.runners import version_runner


def get_meson_version():
    try:
        out = version_runner(["meson", "--version"])
        version_line = decode_text(out).split('\n', 1)[0]
        version_str = version_line.rsplit(' ', 1)[-1]
        return Version(version_str)
    except Exception:
        return Version("0.0.0")


@pytest.mark.toolchain
@pytest.mark.tool_meson
@unittest.skipUnless(which("meson") and get_meson_version() >= Version("0.56.0"),
                     "requires meson >= 0.56.0")
class MesonToolchainTest(unittest.TestCase):
    _conanfile_py = textwrap.dedent("""
    from conans import ConanFile, tools
    from conan.tools.meson import 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
예제 #16
0
    def system_package_tool_test(self):

        with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "True"}):
            runner = RunnerMock()
            # fake os info to linux debian, default sudo
            os_info = OSInfo()
            os_info.is_macos = False
            os_info.is_linux = True
            os_info.is_windows = False
            os_info.linux_distro = "debian"

            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A apt-get update")

            os_info.linux_distro = "ubuntu"
            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A apt-get update")

            os_info.linux_distro = "knoppix"
            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A apt-get update")

            os_info.linux_distro = "neon"
            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A apt-get update")

            os_info.linux_distro = "fedora"
            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A yum update -y")

            os_info.linux_distro = "opensuse"
            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A zypper --non-interactive ref")

            os_info.linux_distro = "redhat"
            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)
            spt.install("a_package", force=False)
            self.assertEqual(runner.command_called, "rpm -q a_package")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "sudo -A yum install -y a_package")

            os_info.linux_distro = "debian"
            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)
            with self.assertRaises(ConanException):
                runner.return_ok = False
                spt.install("a_package")
                self.assertEqual(runner.command_called,
                                 "sudo -A apt-get install -y --no-install-recommends a_package")

            runner.return_ok = True
            spt.install("a_package", force=False)
            self.assertEqual(runner.command_called,
                             'dpkg-query -W -f=\'${Status}\' a_package | grep -q "ok installed"')

            os_info.is_macos = True
            os_info.is_linux = False
            os_info.is_windows = False

            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "brew update")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "brew install a_package")

            os_info.is_freebsd = True
            os_info.is_macos = False

            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A pkg update")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "sudo -A pkg install -y a_package")
            spt.install("a_package", force=False)
            self.assertEqual(runner.command_called, "pkg info a_package")

            # Chocolatey is an optional package manager on Windows
            if platform.system() == "Windows" and which("choco.exe"):
                os_info.is_freebsd = False
                os_info.is_windows = True
                spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out,
                                        tool=ChocolateyTool(output=self.out))
                spt.update()
                self.assertEqual(runner.command_called, "choco outdated")
                spt.install("a_package", force=True)
                self.assertEqual(runner.command_called, "choco install --yes a_package")
                spt.install("a_package", force=False)
                self.assertEqual(runner.command_called,
                                 'choco search --local-only --exact a_package | '
                                 'findstr /c:"1 packages installed."')

        with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "False"}):

            os_info = OSInfo()
            os_info.is_linux = True
            os_info.linux_distro = "redhat"
            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "yum install -y a_package")
            spt.update()
            self.assertEqual(runner.command_called, "yum update -y")

            os_info.linux_distro = "ubuntu"
            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called,
                             "apt-get install -y --no-install-recommends a_package")

            spt.update()
            self.assertEqual(runner.command_called, "apt-get update")

            os_info.is_macos = True
            os_info.is_linux = False
            os_info.is_windows = False
            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)

            spt.update()
            self.assertEqual(runner.command_called, "brew update")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "brew install a_package")

            os_info.is_freebsd = True
            os_info.is_macos = False
            os_info.is_windows = False

            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "pkg update")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "pkg install -y a_package")
            spt.install("a_package", force=False)
            self.assertEqual(runner.command_called, "pkg info a_package")

            os_info.is_solaris = True
            os_info.is_freebsd = False
            os_info.is_windows = False

            spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "pkgutil --catalog")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "pkgutil --install --yes a_package")

        with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "True"}):

            # Chocolatey is an optional package manager on Windows
            if platform.system() == "Windows" and which("choco.exe"):
                os_info.is_solaris = False
                os_info.is_windows = True

                spt = SystemPackageTool(runner=runner, os_info=os_info, output=self.out,
                                        tool=ChocolateyTool(output=self.out))
                spt.update()
                self.assertEqual(runner.command_called, "choco outdated")
                spt.install("a_package", force=True)
                self.assertEqual(runner.command_called, "choco install --yes a_package")
                spt.install("a_package", force=False)
                self.assertEqual(runner.command_called,
                                 'choco search --local-only --exact a_package | '
                                 'findstr /c:"1 packages installed."')
예제 #17
0
 def bash_path():
     if os.getenv("CONAN_BASH_PATH"):
         return os.getenv("CONAN_BASH_PATH")
     return which("bash")
예제 #18
0
 def with_dnf(self):
     return self.is_linux and self.linux_distro == "fedora" and which('dnf')
예제 #19
0
    def system_package_tool_test(self, patched_with_apt):

        with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "True"}):
            runner = RunnerMock()
            # fake os info to linux debian, default sudo
            os_info = OSInfo()
            os_info.is_macos = False
            os_info.is_linux = True
            os_info.is_windows = False
            patched_with_apt.return_value = True

            os_info.linux_distro = "debian"

            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A apt-get update")

            os_info.linux_distro = "ubuntu"
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A apt-get update")

            os_info.linux_distro = "knoppix"
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A apt-get update")

            os_info.linux_distro = "neon"
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A apt-get update")

            # We'll be testing non-Ubuntu and non-Debian-based distros.
            patched_with_apt.return_value = False

            with mock.patch("conans.client.tools.oss.which",
                            return_value=True):
                os_info.linux_distro = "fedora"
                spt = SystemPackageTool(runner=runner,
                                        os_info=os_info,
                                        output=self.out)
                spt.update()
                self.assertEqual(runner.command_called,
                                 "sudo -A dnf check-update -y")

            # Without DNF in the path,
            os_info.linux_distro = "fedora"
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called,
                             "sudo -A yum check-update -y")

            os_info.linux_distro = "opensuse"
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called,
                             "sudo -A zypper --non-interactive ref")

            os_info.linux_distro = "redhat"
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.install("a_package", force=False)
            self.assertEqual(runner.command_called, "rpm -q a_package")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called,
                             "sudo -A yum install -y a_package")

            settings = MockSettings({
                "arch": "x86",
                "arch_build": "x86_64",
                "os": "Linux",
                "os_build": "Linux"
            })
            conanfile = MockConanfile(settings)
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out,
                                    conanfile=conanfile)
            spt.install("a_package", force=False)
            self.assertEqual(runner.command_called, "rpm -q a_package.i?86")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called,
                             "sudo -A yum install -y a_package.i?86")

            os_info.linux_distro = "debian"
            patched_with_apt.return_value = True
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            with self.assertRaises(ConanException):
                runner.return_ok = False
                spt.install("a_package")
                self.assertEqual(
                    runner.command_called,
                    "sudo -A apt-get install -y --no-install-recommends a_package"
                )

            runner.return_ok = True
            spt.install("a_package", force=False)
            self.assertEqual(
                runner.command_called,
                'dpkg-query -W -f=\'${Status}\' a_package | grep -q "ok installed"'
            )

            os_info.is_macos = True
            os_info.is_linux = False
            os_info.is_windows = False
            patched_with_apt.return_value = False

            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "brew update")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "brew install a_package")

            os_info.is_freebsd = True
            os_info.is_macos = False
            patched_with_apt.return_value = False

            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "sudo -A pkg update")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called,
                             "sudo -A pkg install -y a_package")
            spt.install("a_package", force=False)
            self.assertEqual(runner.command_called, "pkg info a_package")

            # Chocolatey is an optional package manager on Windows
            if platform.system() == "Windows" and which("choco.exe"):
                os_info.is_freebsd = False
                os_info.is_windows = True
                patched_with_apt.return_value = False
                spt = SystemPackageTool(runner=runner,
                                        os_info=os_info,
                                        output=self.out,
                                        tool=ChocolateyTool(output=self.out))
                spt.update()
                self.assertEqual(runner.command_called, "choco outdated")
                spt.install("a_package", force=True)
                self.assertEqual(runner.command_called,
                                 "choco install --yes a_package")
                spt.install("a_package", force=False)
                self.assertEqual(
                    runner.command_called,
                    'choco search --local-only --exact a_package | '
                    'findstr /c:"1 packages installed."')

        with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "False"}):

            os_info = OSInfo()
            os_info.is_linux = True
            os_info.linux_distro = "redhat"
            patched_with_apt.return_value = False

            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "yum install -y a_package")
            spt.update()
            self.assertEqual(runner.command_called, "yum check-update -y")

            os_info.linux_distro = "ubuntu"
            patched_with_apt.return_value = True
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.install("a_package", force=True)
            self.assertEqual(
                runner.command_called,
                "apt-get install -y --no-install-recommends a_package")

            spt.update()
            self.assertEqual(runner.command_called, "apt-get update")

            for arch, distro_arch in {
                    "x86_64": "",
                    "x86": ":i386",
                    "ppc32": ":powerpc",
                    "ppc64le": ":ppc64el",
                    "armv7": ":arm",
                    "armv7hf": ":armhf",
                    "armv8": ":arm64",
                    "s390x": ":s390x"
            }.items():
                settings = MockSettings({
                    "arch": arch,
                    "arch_build": "x86_64",
                    "os": "Linux",
                    "os_build": "Linux"
                })
                conanfile = MockConanfile(settings)
                spt = SystemPackageTool(runner=runner,
                                        os_info=os_info,
                                        output=self.out,
                                        conanfile=conanfile)
                spt.install("a_package", force=True)
                self.assertEqual(
                    runner.command_called,
                    "apt-get install -y --no-install-recommends a_package%s" %
                    distro_arch)

            for arch, distro_arch in {"x86_64": "", "x86": ":all"}.items():
                settings = MockSettings({
                    "arch": arch,
                    "arch_build": "x86_64",
                    "os": "Linux",
                    "os_build": "Linux"
                })
                conanfile = MockConanfile(settings)
                spt = SystemPackageTool(runner=runner,
                                        os_info=os_info,
                                        output=self.out,
                                        conanfile=conanfile)
                spt.install("a_package", force=True, arch_names={"x86": "all"})
                self.assertEqual(
                    runner.command_called,
                    "apt-get install -y --no-install-recommends a_package%s" %
                    distro_arch)

            os_info.is_macos = True
            os_info.is_linux = False
            os_info.is_windows = False
            patched_with_apt.return_value = False
            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)

            spt.update()
            self.assertEqual(runner.command_called, "brew update")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "brew install a_package")

            os_info.is_freebsd = True
            os_info.is_macos = False
            os_info.is_windows = False
            patched_with_apt.return_value = False

            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "pkg update")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called, "pkg install -y a_package")
            spt.install("a_package", force=False)
            self.assertEqual(runner.command_called, "pkg info a_package")

            os_info.is_solaris = True
            os_info.is_freebsd = False
            os_info.is_windows = False
            patched_with_apt.return_value = False

            spt = SystemPackageTool(runner=runner,
                                    os_info=os_info,
                                    output=self.out)
            spt.update()
            self.assertEqual(runner.command_called, "pkgutil --catalog")
            spt.install("a_package", force=True)
            self.assertEqual(runner.command_called,
                             "pkgutil --install --yes a_package")

        with tools.environment_append({"CONAN_SYSREQUIRES_SUDO": "True"}):

            # Chocolatey is an optional package manager on Windows
            if platform.system() == "Windows" and which("choco.exe"):
                os_info.is_solaris = False
                os_info.is_windows = True
                patched_with_apt.return_value = False

                spt = SystemPackageTool(runner=runner,
                                        os_info=os_info,
                                        output=self.out,
                                        tool=ChocolateyTool(output=self.out))
                spt.update()
                self.assertEqual(runner.command_called, "choco outdated")
                spt.install("a_package", force=True)
                self.assertEqual(runner.command_called,
                                 "choco install --yes a_package")
                spt.install("a_package", force=False)
                self.assertEqual(
                    runner.command_called,
                    'choco search --local-only --exact a_package | '
                    'findstr /c:"1 packages installed."')
예제 #20
0
 def skip(self):
     return not (os_info.is_windows or tools_files.which("pwsh"))