Пример #1
0
 def simple_output_test(self):
     stream = StringIO()
     output = ConanOutput(stream)
     output.rewrite_line("This is a very long line that has to be truncated somewhere, "
                         "because it is so long it doesn't fit in the output terminal")
     self.assertIn("This is a very long line that ha ... esn't fit in the output terminal",
                   stream.getvalue())
Пример #2
0
def download(url, filename, verify=True):
    out = ConanOutput(sys.stdout, True)
    if verify:
        # We check the certificate using a list of known verifiers
        import conans.client.rest.cacert as cacert
        verify = cacert.file_path
    downloader = Downloader(requests, out, verify=verify)
    downloader.download(url, filename)
    out.writeln("")
Пример #3
0
def get_command():

    def instance_remote_manager(client_cache):
        requester = requests.Session()
        requester.proxies = client_cache.conan_config.proxies
        # Verify client version against remotes
        version_checker_requester = VersionCheckerRequester(requester, Version(CLIENT_VERSION),
                                                            Version(MIN_SERVER_COMPATIBLE_VERSION),
                                                            out)
        # To handle remote connections
        rest_api_client = RestApiClient(out, requester=version_checker_requester)
        # To store user and token
        localdb = LocalDB(client_cache.localdb)
        # Wraps RestApiClient to add authentication support (same interface)
        auth_manager = ConanApiAuthManager(rest_api_client, user_io, localdb)
        # Handle remote connections
        remote_manager = RemoteManager(client_cache, auth_manager, out)
        return remote_manager

    use_color = get_env("CONAN_COLOR_DISPLAY", 1)
    if use_color and hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
        import colorama
        colorama.init()
        color = True
    else:
        color = False
    out = ConanOutput(sys.stdout, color)
    user_io = UserIO(out=out)

    user_folder = os.getenv("CONAN_USER_HOME", conan_expand_user("~"))

    try:
        # To capture exceptions in conan.conf parsing
        client_cache = ClientCache(user_folder, None, out)
        # obtain a temp ConanManager instance to execute the migrations
        remote_manager = instance_remote_manager(client_cache)

        # Get a DiskSearchManager
        search_adapter = DiskSearchAdapter()
        search_manager = DiskSearchManager(client_cache, search_adapter)
        manager = ConanManager(client_cache, user_io, ConanRunner(), remote_manager, search_manager)

        client_cache = migrate_and_get_client_cache(user_folder, out, manager)
    except Exception as e:
        out.error(str(e))
        sys.exit(True)

    # Get the new command instance after migrations have been done
    remote_manager = instance_remote_manager(client_cache)

    # Get a search manager
    search_adapter = DiskSearchAdapter()
    search_manager = DiskSearchManager(client_cache, search_adapter)
    command = Command(client_cache, user_io, ConanRunner(), remote_manager, search_manager)
    return command
Пример #4
0
    def factory():
        """Factory"""

        def instance_remote_manager(client_cache):
            requester = get_basic_requester(client_cache)
            # Verify client version against remotes
            version_checker_requester = VersionCheckerRequester(requester, Version(CLIENT_VERSION),
                                                                Version(MIN_SERVER_COMPATIBLE_VERSION),
                                                                out)
            # To handle remote connections
            put_headers = client_cache.read_put_headers()
            rest_api_client = RestApiClient(out, requester=version_checker_requester, put_headers=put_headers)
            # To store user and token
            localdb = LocalDB(client_cache.localdb)
            # Wraps RestApiClient to add authentication support (same interface)
            auth_manager = ConanApiAuthManager(rest_api_client, user_io, localdb)
            # Handle remote connections
            remote_manager = RemoteManager(client_cache, auth_manager, out)
            return remote_manager

        use_color = get_env("CONAN_COLOR_DISPLAY", 1)
        if use_color and hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
            import colorama
            colorama.init()
            color = True
        else:
            color = False
        out = ConanOutput(sys.stdout, color)
        user_io = UserIO(out=out)

        user_folder = os.getenv("CONAN_USER_HOME", conan_expand_user("~"))

        try:
            client_cache = migrate_and_get_client_cache(user_folder, out)
        except Exception as e:
            out.error(str(e))
            raise

        with tools.environment_append(client_cache.conan_config.env_vars):
            # Adjust CONAN_LOGGING_LEVEL with the env readed
            conans.util.log.logger = configure_logger()

            # Get the new command instance after migrations have been done
            remote_manager = instance_remote_manager(client_cache)

            # Get a search manager
            search_adapter = DiskSearchAdapter()
            search_manager = DiskSearchManager(client_cache, search_adapter)
            conan = Conan(client_cache, user_io, get_conan_runner(), remote_manager, search_manager)

        return conan
Пример #5
0
def main(args):
    """ main entry point of the conans application, using a Command to
    parse parameters
    """
    if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
        import colorama
        colorama.init()
        color = True
    else:
        color = False
    out = ConanOutput(sys.stdout, color)
    user_io = UserIO(out=out)

    user_folder = os.path.expanduser("~")
    try:
        # To capture exceptions in conan.conf parsing
        paths = migrate_and_get_paths(user_folder, out)
    except Exception as e:
        out.error(str(e))
        sys.exit(True)

    requester = requests.Session()
    requester.proxies = paths.conan_config.proxies
    # Verify client version against remotes
    version_checker_requester = VersionCheckerRequester(requester, Version(CLIENT_VERSION),
                                                        Version(MIN_SERVER_COMPATIBLE_VERSION),
                                                        out)
    # To handle remote connections
    rest_api_client = RestApiClient(out, requester=version_checker_requester)
    # To store user and token
    localdb = LocalDB(paths.localdb)
    # Wraps RestApiClient to add authentication support (same interface)
    auth_manager = ConanApiAuthManager(rest_api_client, user_io, localdb)
    # Handle remote connections
    remote_manager = RemoteManager(paths, paths.conan_config.remotes, auth_manager, out)

    command = Command(paths, user_io, ConanRunner(), remote_manager, localdb)
    current_dir = os.getcwd()
    try:
        import signal

        def sigint_handler(signal, frame):
            print('You pressed Ctrl+C!')
            sys.exit(0)

        signal.signal(signal.SIGINT, sigint_handler)
        error = command.run(args)
    finally:
        os.chdir(current_dir)
    sys.exit(error)
Пример #6
0
 def __init__(self, ins=sys.stdin, out=None):
     """
     Params:
         ins: input stream
         out: ConanOutput, should have "write" method
     """
     self._ins = ins
     if not out:
         out = ConanOutput(sys.stdout)
     self.out = out
     self._interactive = True
Пример #7
0
    def no_configuration_test(self):
        dummy = """GlobalSection
            EndGlobalSection
     GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Win32 = Debug|Win32
        Debug|x64 = Debug|x64
        Release|Win32 = Release|Win32
        Release|x64 = Release|x64
    EndGlobalSection
"""
        folder = temp_folder()
        path = os.path.join(folder, "dummy.sln")
        save(path, dummy)
        new_out = StringIO()
        command = build_sln_command(Settings({}),
                                    sln_path=path,
                                    targets=None,
                                    upgrade_project=False,
                                    build_type='Debug',
                                    arch="x86",
                                    parallel=False,
                                    output=ConanOutput(new_out))
        self.assertIn('/p:Configuration="Debug" /p:Platform="x86"', command)
        self.assertIn(
            "WARN: ***** The configuration Debug|x86 does not exist in this solution *****",
            new_out.getvalue())

        # use platforms
        new_out = StringIO()
        command = build_sln_command(Settings({}),
                                    sln_path=path,
                                    targets=None,
                                    upgrade_project=False,
                                    build_type='Debug',
                                    arch="x86",
                                    parallel=False,
                                    platforms={"x86": "Win32"},
                                    output=ConanOutput(new_out))
        self.assertIn('/p:Configuration="Debug" /p:Platform="Win32"', command)
        self.assertNotIn("WARN", new_out.getvalue())
        self.assertNotIn("ERROR", new_out.getvalue())
Пример #8
0
    def test(self):
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "a_file.txt")
        save(file_path, "my content!")
        txz = os.path.join(tmp_dir, "sample.tar.xz")
        with tarfile.open(txz, "w:xz") as tar:
            tar.add(file_path, "a_file.txt")

        dest_folder = temp_folder()
        unzip(txz, dest_folder, output=ConanOutput(StringIO()))
        content = load(os.path.join(dest_folder, "a_file.txt"))
        self.assertEqual(content, "my content!")
Пример #9
0
    def add_repositories_exception_cases_test(self):
        os_info = OSInfo()
        os_info.is_macos = False
        os_info.is_linux = True
        os_info.is_windows = False
        os_info.linux_distro = "fedora"  # Will instantiate DnfTool

        with six.assertRaisesRegex(self, ConanException, "add_repository not implemented"):
            new_out = StringIO()
            spt = SystemPackageTool(os_info=os_info, output=ConanOutput(new_out))
            spt.add_repository(repository="deb http://repo/url/ saucy universe multiverse",
                               repo_key=None)
Пример #10
0
    def conan_compiler_info(self):
        """return the compiler and its version readed in conan.conf"""
        out = ConanOutput(sys.stdout)
        cache = ClientCache(os.environ.get("CONAN_USER_HOME", "~/"), None, out)

        if hasattr(cache, "default_profile"):
            profile = cache.default_profile
            settings = profile.settings
        else:
            settings = dict(cache.conan_config.get_conf("settings_defaults"))

        return settings["compiler"], settings["compiler.version"]
Пример #11
0
    def no_build_type_test(self):
        with self.assertRaises(ConanException):
            with warnings.catch_warnings(record=True) as w:
                warnings.simplefilter("always")

                new_out = StringIO()
                build_sln_command(Settings({}), sln_path='dummy.sln', targets=None,
                                  upgrade_project=False, build_type=None, arch='x86', parallel=False,
                                  output=ConanOutput(new_out))

                self.assertEqual(len(w), 1)
                self.assertTrue(issubclass(w[0].category, DeprecationWarning))
Пример #12
0
 def __init__(self, conanfile, *args, **kwargs):
     msg = ("\n*****************************************************************\n"
            "*****************************************************************\n"
            "'from conans import MSBuildToolchain' has been deprecated and moved.\n"
            "It will be removed in next Conan release.\n"
            "Use 'from conan.tools.microsoft import MSBuildToolchain' instead.\n"
            "*****************************************************************\n"
            "*****************************************************************\n")
     ConanOutput(conanfile.output._stream,
                 color=conanfile.output._color).writeln(msg, front=Color.BRIGHT_RED)
     warnings.warn(msg)
     super(MSBuildToolchain, self).__init__(conanfile, *args, **kwargs)
Пример #13
0
    def test_replace_in_file(self):
        output = ConanOutput(sys.stdout)
        replace_in_file(self.win_file, "nis", "nus", output=output)
        replace_in_file(self.bytes_file, "nis", "nus", output=output)

        content = tools.load(self.win_file)
        self.assertNotIn("nis", content)
        self.assertIn("nus", content)

        content = tools.load(self.bytes_file)
        self.assertNotIn("nis", content)
        self.assertIn("nus", content)
Пример #14
0
    def setUp(self):
        self.server = TestServerLauncher()
        self.server.start()
        self.api = RestApiClient(ConanOutput(sys.stdout, Color),
                                 requester=requests)
        self.api.remote_url = "http://localhost:%s" % str(self.server.port)

        time.sleep(0.05)  # necessary in linux
        # Authenticate user
        token = self.api.authenticate("private_user", "private_pass")
        self.api.token = token
        self.local_folder = temp_folder()
Пример #15
0
 def toolset_test(self):
     new_out = StringIO()
     command = build_sln_command(MockSettings({"compiler": "Visual Studio",
                                               "compiler.version": "17",
                                               "build_type": "Debug",
                                               "compiler.runtime": "MDd",
                                               "cppstd": "17"}),
                                 sln_path='dummy.sln', targets=None,
                                 upgrade_project=False, build_type='Debug', arch='armv7',
                                 parallel=False, toolset="v110", output=ConanOutput(new_out))
     self.assertTrue(command.startswith('msbuild "dummy.sln" /p:Configuration="Debug" '
                                        '/p:Platform="ARM" '
                                        '/p:PlatformToolset="v110" '
                                        '/p:ForceImportBeforeCppTargets='), command)
Пример #16
0
    def setUpClass(cls):
        if not cls.server:
            plugin = VersionCheckerPlugin(Version("0.16.0"), Version("0.16.0"), ["ImCool"])
            cls.server = TestServerLauncher(server_version=Version("0.16.0"),
                                            min_client_compatible_version=Version("0.16.0"),
                                            plugins=[plugin])
            cls.server.start()

            cls.api = RestApiClient(ConanOutput(sys.stdout, Color), requester=requests)
            cls.api.remote_url = "http://localhost:%s" % str(cls.server.port)

            # Authenticate user
            token = cls.api.authenticate("private_user", "private_pass")
            cls.api.token = token
Пример #17
0
 def positive_test(self):
     output = ConanOutput(StringIO())
     command = build_sln_command(Settings({}),
                                 sln_path='dummy.sln',
                                 targets=None,
                                 upgrade_project=False,
                                 build_type='Debug',
                                 arch='x86',
                                 parallel=False,
                                 output=output)
     self.assertIn('msbuild "dummy.sln"', command)
     self.assertIn('/p:Platform="x86"', command)
     self.assertNotIn('devenv "dummy.sln" /upgrade', command)
     self.assertNotIn('/m:%s' % cpu_count(output=output), command)
     self.assertNotIn('/target:teapot', command)
Пример #18
0
    def vcvars_raises_when_not_found_test(self):
        text = """
os: [Windows]
compiler:
    Visual Studio:
        version: ["5"]
        """
        settings = Settings.loads(text)
        settings.os = "Windows"
        settings.compiler = "Visual Studio"
        settings.compiler.version = "5"
        with six.assertRaisesRegex(self, ConanException,
                                   "VS non-existing installation: Visual Studio 5"):
            output = ConanOutput(StringIO())
            tools.vcvars_command(settings, output=output)
Пример #19
0
    def test_patterns(self):
        # Test setup
        src_dir = temp_folder()
        files = {
            "foo/file.cpp": "code",
            "foo/bar/file.txt": "text",
            "foo/bar/file.cpp": "more code",
            "foo/bar/baz/file.txt": "more text"
        }
        matches = {
            "*.cpp": ["foo/file.cpp", "foo/bar/file.cpp"],
            "*.txt": ["foo/bar/file.txt", "foo/bar/baz/file.txt"],
            "foo/bar/*":
            ["foo/bar/file.txt", "foo/bar/file.cpp", "foo/bar/baz/file.txt"],
            "foo/bar/baz/*": ["foo/bar/baz/file.txt"],
            "*": [
                "foo/file.cpp", "foo/bar/file.txt", "foo/bar/file.cpp",
                "foo/bar/baz/file.txt"
            ],
            "nothing": []
        }
        save_files(src_dir, files)

        for extension in ["zip", "tar", "tar.gz"]:
            # GIVEN an archive with files inside
            archive_dir = temp_folder()
            archive = os.path.join(archive_dir, "archive.%s" % extension)
            create_archive(archive, src_dir, files)

            for (pattern, paths) in matches.items():
                # WHEN a pattern is used for file extraction
                dst_dir = temp_folder()
                unzip(archive,
                      dst_dir,
                      pattern=pattern,
                      output=ConanOutput(sys.stdout))

                # THEN only and all files matching the pattern are extracted
                actual = set()
                expected = set(
                    map(lambda x: os.path.join(dst_dir, *x.split("/")), paths))
                for extracted_dir, _, extracted_files in os.walk(dst_dir):
                    actual.update(
                        map(lambda x: os.path.join(extracted_dir, x),
                            extracted_files))

                self.assertSetEqual(expected, actual)
Пример #20
0
 def write_toolchain_files(self):
     # Warning
     msg = (
         "\n*****************************************************************\n"
         "******************************************************************\n"
         "'write_toolchain_files()' has been deprecated and moved.\n"
         "It will be removed in next Conan release.\n"
         "Use 'generate()' method instead.\n"
         "********************************************************************\n"
         "********************************************************************\n"
     )
     from conans.client.output import Color, ConanOutput
     ConanOutput(self._conanfile.output._stream,
                 color=self._conanfile.output._color).writeln(
                     msg, front=Color.BRIGHT_RED)
     warnings.warn(msg)
     self.generate()
Пример #21
0
    def positive_test(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            output = ConanOutput(StringIO())
            command = build_sln_command(Settings({}), sln_path='dummy.sln', targets=None,
                                        upgrade_project=False, build_type='Debug', arch='x86',
                                        parallel=False, output=output)

            self.assertEqual(len(w), 1)
            self.assertTrue(issubclass(w[0].category, DeprecationWarning))

        self.assertIn('msbuild "dummy.sln"', command)
        self.assertIn('/p:Platform="x86"', command)
        self.assertNotIn('devenv "dummy.sln" /upgrade', command)
        self.assertNotIn('/m:%s' % cpu_count(output=output), command)
        self.assertNotIn('/target:teapot', command)
Пример #22
0
 def test_untar(self):
     tmp_dir = temp_folder()
     file_path = os.path.join(tmp_dir, "example.txt")
     save(file_path, "Hello world!")
     tar_path = os.path.join(tmp_dir, "sample.tar")
     try:
         old_path = os.getcwd()
         os.chdir(tmp_dir)
         import tarfile
         tar = tarfile.open(tar_path, "w")
         tar.add("example.txt")
         tar.close()
     finally:
         os.chdir(old_path)
     output_dir = os.path.join(tmp_dir, "output_dir")
     tools.unzip(tar_path, output_dir, output=ConanOutput(stream=sys.stdout))
     content = load(os.path.join(output_dir, "example.txt"))
     self.assertEqual(content, "Hello world!")
Пример #23
0
def CMakeToolchain(conanfile, **kwargs):
    # Warning
    msg = ("\n*****************************************************************\n"
           "*****************************************************************\n"
           "'from conans import CMakeToolchain' has been deprecated and moved.\n"
           "It will be removed in next Conan release.\n"
           "Use 'from conan.tools.cmake import CMakeToolchain' instead.\n"
           "*****************************************************************\n"
           "*****************************************************************\n")
    from conans.client.output import Color, ConanOutput
    ConanOutput(conanfile.output._stream,
                color=conanfile.output._color).writeln(msg, front=Color.BRIGHT_RED)
    warnings.warn(msg)
    try:
        from conan.tools.cmake import CMakeToolchain as _CMakeToolchain
        return _CMakeToolchain(conanfile, **kwargs)
    except ImportError:
        raise Exception("Python 2.7 is no longer supported for CMakeToolchain")
Пример #24
0
def main(args):
    """ main entry point of the conans application, using a Command to
    parse parameters
    """
    if hasattr(sys.stdout, "isatty") and sys.stdout.isatty():
        import colorama
        colorama.init()
        color = True
    else:
        color = False
    out = ConanOutput(sys.stdout, color)
    user_io = UserIO(out=out)

    user_folder = os.path.expanduser("~")
    paths = migrate_and_get_paths(user_folder, out)

    # Verify client version against remotes
    version_checker_requester = VersionCheckerRequester(
        requests, Version(CLIENT_VERSION),
        Version(MIN_SERVER_COMPATIBLE_VERSION), out)
    # To handle remote connections
    rest_api_client = RestApiClient(out, requester=version_checker_requester)
    # To store user and token
    localdb = LocalDB(paths.localdb)
    # Wraps RestApiClient to add authentication support (same interface)
    auth_manager = ConanApiAuthManager(rest_api_client, user_io, localdb)
    # Handle remote connections
    remote_manager = RemoteManager(paths, paths.conan_config.remotes,
                                   auth_manager, out)

    command = Command(paths, user_io, os.system, remote_manager, localdb)
    current_dir = os.getcwd()
    try:
        import signal

        def sigint_handler(signal, frame):
            print('You pressed Ctrl+C!')
            sys.exit(0)

        signal.signal(signal.SIGINT, sigint_handler)
        error = command.run(args)
    finally:
        os.chdir(current_dir)
    sys.exit(error)
Пример #25
0
 def properties_file_test(self):
     new_out = StringIO()
     command = build_sln_command(MockSettings({"compiler": "Visual Studio",
                                               "compiler.version": "17",
                                               "build_type": "Debug",
                                               "compiler.runtime": "MDd",
                                               "cppstd": "17"}),
                                 sln_path='dummy.sln', targets=None,
                                 upgrade_project=False, build_type='Debug', arch='armv7',
                                 parallel=False, output=ConanOutput(new_out))
     self.assertTrue(command.startswith('msbuild "dummy.sln" /p:Configuration="Debug" '
                                        '/p:Platform="ARM" '
                                        '/p:ForceImportBeforeCppTargets='), command)
     path_tmp = command.split("/p:ForceImportBeforeCppTargets=")[1][1:-1]  # remove quotes
     self.assertTrue(os.path.exists(path_tmp))
     contents = load(path_tmp)
     self.assertIn("<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>", contents)
     self.assertIn("<AdditionalOptions>/std:c++17 %(AdditionalOptions)</AdditionalOptions>",
                   contents)
Пример #26
0
def download(url,
             filename,
             verify=True,
             out=None,
             retry=2,
             retry_wait=5,
             overwrite=False,
             auth=None,
             headers=None):
    out = out or ConanOutput(sys.stdout, True)
    downloader = Downloader(_global_requester, out, verify=verify)
    downloader.download(url,
                        filename,
                        retry=retry,
                        retry_wait=retry_wait,
                        overwrite=overwrite,
                        auth=auth,
                        headers=headers)
    out.writeln("")
Пример #27
0
    def __init__(self, *args):
        if len(args) == 2:
            deps_cpp_info = args[0]
            deps_env_info = DepsEnvInfo()
            settings = args[1]
            self.output = ConanOutput(sys.stdout)
        elif len(args) == 1:  # conanfile (new interface)
            self.conanfile = args[0]
            self.output = self.conanfile.output
            deps_cpp_info = self.conanfile.deps_cpp_info
            deps_env_info = self.conanfile.deps_env_info
            settings = self.conanfile.settings

        assert isinstance(settings, Settings)

        self._settings = settings
        self._deps_cpp_info = deps_cpp_info
        self._deps_env_info = deps_env_info
        try:
            self.compiler = str(self._settings.compiler)
        except:
            self.compiler = None

        try:
            self.arch = str(self._settings.arch)
        except:
            self.arch = None

        try:
            self.os = str(self._settings.os)
        except:
            self.os = None

        try:
            self.build_type = str(self._settings.build_type)
        except:
            self.build_type = None

        try:
            self.libcxx = str(self.compiler.libcxx)
        except:
            self.libcxx = None
Пример #28
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
Пример #29
0
    def test_short_paths_unzip_output(self):
        if platform.system() != "Windows":
            return
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "src/"*40, "example.txt")
        save(file_path, "Hello world!")

        zip_path = os.path.join(tmp_dir, 'example.zip')
        zipf = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
        for root, _, files in os.walk(tmp_dir):
            for f in files:
                zipf.write(os.path.join(root, f), os.path.join("src/"*20, f))
        zipf.close()

        output_dir = os.path.join(tmp_dir, "dst/"*40, "output_dir")
        new_out = six.StringIO()
        tools.unzip(zip_path, output_dir, output=ConanOutput(new_out))

        output = new_out.getvalue()
        self.assertIn("ERROR: Error extract src/src", output)
Пример #30
0
    def test_unzip_output(self):
        tmp_dir = temp_folder()
        file_path = os.path.join(tmp_dir, "example.txt")
        save(file_path, "Hello world!")

        zip_path = os.path.join(tmp_dir, 'example.zip')
        zipf = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)
        for root, _, files in os.walk(tmp_dir):
            for f in files:
                zipf.write(os.path.join(root, f), f)
        zipf.close()

        output_dir = os.path.join(tmp_dir, "output_dir")
        new_out = six.StringIO()
        tools.unzip(zip_path, output_dir, output=ConanOutput(new_out))

        output = new_out.getvalue()
        six.assertRegex(self, output, "Unzipping [\d]+B")
        content = load(os.path.join(output_dir, "example.txt"))
        self.assertEqual(content, "Hello world!")
Пример #31
0
    def test_permissions(self):
        if platform.system() != "Windows":
            for keep_permissions in [True, False]:
                for perm_set in [stat.S_IRWXU, stat.S_IRUSR]:
                    tmp_dir = temp_folder()
                    file_path = os.path.join(tmp_dir, "a_file.txt")
                    save(file_path, "contents")
                    os.chmod(file_path, perm_set)
                    zf = zipfile.ZipFile(os.path.join(tmp_dir, 'zipfile.zip'), mode='w')
                    zf.write(file_path, basename(file_path))
                    zf.close()

                    # Unzip and check permissions are kept
                    dest_dir = temp_folder()
                    unzip(os.path.join(tmp_dir, 'zipfile.zip'), dest_dir,
                          keep_permissions=keep_permissions, output=ConanOutput(StringIO()))

                    dest_file = os.path.join(dest_dir, "a_file.txt")
                    if keep_permissions:
                        self.assertEquals(stat.S_IMODE(os.stat(dest_file).st_mode), perm_set)
                    else:
                        self.assertNotEquals(stat.S_IMODE(os.stat(dest_file).st_mode), perm_set)
Пример #32
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
        description='Modify Conan settings.yml configuration')
    parser.add_argument('--merge-file',
                        nargs='*',
                        default=[],
                        help='YAML config file to merge')
    parser.add_argument('--method', default='METHOD_MERGE')
    bool_arg(parser, 'mergelists', True)
    bool_arg(parser, 'interpolate', False)
    bool_arg(parser, 'castinterpolated', False)
    bool_arg(parser, 'usedefaultyamlloader', False)
    bool_arg(parser, 'failonmissingfiles', True)
    args = parser.parse_args()

    in_data = get_stdin() or ''
    in_data += "\n"  # newline is used to distinguish yaml from filename

    output = ConanOutput(sys.stdout, sys.stderr, True)
    conan_cache = cache.ClientCache(
        os.path.join(get_conan_user_home(), '.conan'), output)
    path = conan_cache.settings_path

    existing = cache.load(path) \
        if os.path.exists(path) \
        else default_settings()
    method = hiyapyco.METHODS[args.method]
    settings = hiyapyco.load([existing, in_data],
                             *args.merge_file,
                             mergelists=args.mergelists,
                             method=method,
                             interpolate=args.interpolate,
                             castinterpolated=args.castinterpolated,
                             usedefaultyamlloader=args.usedefaultyamlloader,
                             failonmissingfiles=args.failonmissingfiles)
    settings_yml = hiyapyco.dump(settings)
    cache.save(path, normalize(settings_yml), only_if_modified=True)
Пример #33
0
    def properties_file_test(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            new_out = StringIO()
            command = build_sln_command(MockSettings({
                "compiler": "Visual Studio",
                "compiler.version": "17",
                "build_type": "Debug",
                "compiler.runtime": "MDd",
                "cppstd": "17"
            }),
                                        sln_path='dummy.sln',
                                        targets=None,
                                        upgrade_project=False,
                                        build_type='Debug',
                                        arch='armv7',
                                        parallel=False,
                                        output=ConanOutput(new_out))

            self.assertEqual(len(w), 1)
            self.assertTrue(issubclass(w[0].category, DeprecationWarning))

        self.assertTrue(
            command.startswith('msbuild "dummy.sln" /p:Configuration="Debug" '
                               '/p:UseEnv=false '
                               '/p:Platform="ARM" '
                               '/verbosity:minimal '
                               '/p:ForceImportBeforeCppTargets='), command)
        path_tmp = command.split("/p:ForceImportBeforeCppTargets=")[1][
            1:-1]  # remove quotes
        self.assertTrue(os.path.exists(path_tmp))
        contents = load(path_tmp)
        self.assertIn("<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>",
                      contents)
        self.assertIn(
            "<AdditionalOptions>/std:c++17 %(AdditionalOptions)</AdditionalOptions>",
            contents)
Пример #34
0
    def toolset_test(self):
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")

            new_out = StringIO()
            command = build_sln_command(MockSettings({"compiler": "Visual Studio",
                                                      "compiler.version": "17",
                                                      "build_type": "Debug",
                                                      "compiler.runtime": "MDd",
                                                      "cppstd": "17"}),
                                        sln_path='dummy.sln', targets=None,
                                        upgrade_project=False, build_type='Debug', arch='armv7',
                                        parallel=False, toolset="v110", output=ConanOutput(new_out))

            self.assertEqual(len(w), 1)
            self.assertTrue(issubclass(w[0].category, DeprecationWarning))

        self.assertTrue(command.startswith('msbuild "dummy.sln" /p:Configuration="Debug" '
                                           '/p:UseEnv=false '
                                           '/p:Platform="ARM" '
                                           '/p:PlatformToolset="v110" '
                                           '/verbosity:minimal '
                                           '/p:ForceImportBeforeCppTargets='), command)
Пример #35
0
def download(url,
             filename,
             verify=True,
             out=None,
             retry=2,
             retry_wait=5,
             overwrite=False,
             auth=None,
             headers=None):
    out = out or ConanOutput(sys.stdout, True)
    if verify:
        # We check the certificate using a list of known verifiers
        import conans.client.rest.cacert as cacert
        verify = cacert.file_path
    downloader = Downloader(_global_requester, out, verify=verify)
    downloader.download(url,
                        filename,
                        retry=retry,
                        retry_wait=retry_wait,
                        overwrite=overwrite,
                        auth=auth,
                        headers=headers)
    out.writeln("")
Пример #36
0
class ConfigureEnvironment(object):

    def __init__(self, *args):
        if len(args) == 2:
            deps_cpp_info = args[0]
            deps_env_info = DepsEnvInfo()
            settings = args[1]
            self.output = ConanOutput(sys.stdout)
        elif len(args) == 1:  # conanfile (new interface)
            self.conanfile = args[0]
            self.output = self.conanfile.output
            deps_cpp_info = self.conanfile.deps_cpp_info
            deps_env_info = self.conanfile.deps_env_info
            settings = self.conanfile.settings

        assert isinstance(settings, Settings)

        self.output.warn("""
***********************************************************************

    WARNING!!!

    ConfigureEnvironment class is deprecated and will be removed soon.
    With ConfigureEnvironment, env variables from profiles and/or
    command line are not applied.

    Replace it with the right one according your needs:
      - AutoToolsBuildEnvironment
      - VisualStudioBuildEnvironment

    Check docs.conan.io


***********************************************************************
        """)

        self._settings = settings
        self._deps_cpp_info = deps_cpp_info
        self._deps_env_info = deps_env_info
        try:
            self.compiler = str(self._settings.compiler)
        except:
            self.compiler = None

        try:
            self.arch = str(self._settings.arch)
        except:
            self.arch = None

        try:
            self.os = str(self._settings.os)
        except:
            self.os = None

        try:
            self.build_type = str(self._settings.build_type)
        except:
            self.build_type = None

        try:
            self.libcxx = str(self._settings.compiler.libcxx)
        except:
            self.libcxx = None

    def _gcc_arch_flags(self):
        if self.arch == "x86_64" or self.arch == "sparcv9":
            return "-m64"
        elif self.arch == "x86" or self.arch == "sparc":
            return "-m32"
        else:
            return "";

    def _gcc_lib_flags(self):
        lib_flags = []
        if self.libcxx:
            if str(self.libcxx) == "libstdc++":
                lib_flags.append("-D_GLIBCXX_USE_CXX11_ABI=0")
            elif str(self.libcxx) == "libstdc++11":
                lib_flags.append("-D_GLIBCXX_USE_CXX11_ABI=1")

            if "clang" in str(self.compiler):
                if str(self.libcxx) == "libc++":
                    lib_flags.append("-stdlib=libc++")
                else:
                    lib_flags.append("-stdlib=libstdc++")

            elif str(self.compiler) == "sun-cc":
                if str(self.libcxx) == "libCstd":
                    lib_flags.append("-library=Cstd")
                elif str(self.libcxx) == "libstdcxx":
                    lib_flags.append("-library=stdcxx4")
                elif str(self.libcxx) == "libstlport":
                    lib_flags.append("-library=stlport4")
                elif str(self.libcxx) == "libstdc++":
                    lib_flags.append("-library=stdcpp")

        return lib_flags

    def _gcc_env(self):
        libflags = " ".join(["-l%s" % lib for lib in self._deps_cpp_info.libs])
        libs = 'LIBS="%s"' % libflags
        archflag = self._gcc_arch_flags()
        exe_linker_flags = " ".join(self._deps_cpp_info.exelinkflags)
        shared_linker_flags = " ".join(self._deps_cpp_info.sharedlinkflags)
        lib_paths = " ".join(["-L%s" % lib for lib in self._deps_cpp_info.lib_paths])
        ldflags = 'LDFLAGS="%s %s %s %s $LDFLAGS"' % (lib_paths, archflag,
                                                      exe_linker_flags, shared_linker_flags)
        if self.build_type == "Debug":
            debug = "-g"
        else:
            debug = "-s -DNDEBUG" if self.compiler == "gcc" else "-DNDEBUG"
        include_flags = " ".join(['-I%s' % i for i in self._deps_cpp_info.include_paths])
        defines = " ".join(['-D%s' % i for i in self._deps_cpp_info.defines])
        cflags = 'CFLAGS="$CFLAGS %s %s %s %s %s"' % (archflag,
                                                      " ".join(self._deps_cpp_info.cflags),
                                                      debug, include_flags, defines)

        # Append the definition for libcxx
        all_cpp_flags = copy.copy(self._deps_cpp_info.cppflags)
        all_cpp_flags.extend(self._gcc_lib_flags())

        cpp_flags = 'CPPFLAGS="$CPPFLAGS %s %s %s %s %s"' % (archflag, " ".join(all_cpp_flags),
                                                             debug, include_flags, defines)
        include_paths = ":".join(['"%s"' % lib for lib in self._deps_cpp_info.include_paths])
        headers_flags = ('C_INCLUDE_PATH=$C_INCLUDE_PATH:{0} '
                         'CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:{0}'.format(include_paths))
        command = "env %s %s %s %s %s" % (libs, ldflags, cflags, cpp_flags, headers_flags)
        # Do not include "export" command, they are passed to env
        command += " ".join(get_setenv_variables_commands(self._deps_env_info, ""))
        return command

    @property
    def command_line_env(self):
        if self.os == "Linux" or self.os == "Macos" or self.os == "FreeBSD" or self.os == "SunOS":
            if self.compiler == "gcc" or "clang" in str(self.compiler) or "sun-cc" in str(self.compiler):
                return self._gcc_env()
        elif self.os == "Windows":
            commands = []
            commands.append("@echo off")
            vcvars = ""
            if self.compiler == "Visual Studio":
                cl_args = " ".join(['/I"%s"' % lib for lib in self._deps_cpp_info.include_paths])
                lib_paths = ";".join(['%s' % lib for lib in self._deps_cpp_info.lib_paths])
                commands.append('if defined LIB (SET "LIB=%LIB%;{0}") else (SET "LIB={0}")'.
                                format(lib_paths))
                commands.append('if defined CL (SET "CL=%CL% {0}") else (SET "CL={0}")'.
                                format(cl_args))
                vcvars = tools.vcvars_command(self._settings)
                if vcvars:
                    vcvars += " && "
            elif self.compiler == "gcc":
                include_paths = ";".join(['%s'
                                          % lib for lib in self._deps_cpp_info.include_paths])
                commands.append('if defined C_INCLUDE_PATH (SET "C_INCLUDE_PATH=%C_INCLUDE_PATH%;{0}")'
                                ' else (SET "C_INCLUDE_PATH={0}")'.format(include_paths))
                commands.append('if defined CPLUS_INCLUDE_PATH '
                                '(SET "CPLUS_INCLUDE_PATH=%CPLUS_INCLUDE_PATH%;{0}")'
                                ' else (SET "CPLUS_INCLUDE_PATH={0}")'.format(include_paths))

                lib_paths = ";".join([lib for lib in self._deps_cpp_info.lib_paths])
                commands.append('if defined LIBRARY_PATH (SET "LIBRARY_PATH=%LIBRARY_PATH%;{0}")'
                                ' else (SET "LIBRARY_PATH={0}")'.format(lib_paths))

            commands.extend(get_setenv_variables_commands(self._deps_env_info, "SET"))
            save("_conan_env.bat", "\r\n".join(commands))
            command = "%scall _conan_env.bat" % vcvars
            return command

        return " && ".join(get_setenv_variables_commands(self._deps_env_info))

    # alias for backward compatibility
    command_line = command_line_env

    @property
    def compile_flags(self):
        if self.compiler == "gcc" or "clang" in str(self.compiler) or self.compiler == "sun-cc":
            flags = []
            flags.append(self._gcc_arch_flags())
            flags.extend(self._deps_cpp_info.exelinkflags)
            flags.extend(self._deps_cpp_info.sharedlinkflags)
            if self.build_type == "Debug":
                flags.append("-g")
            else:
                flags.append("-s -DNDEBUG" if self.compiler == "gcc" else "-DNDEBUG")
            flags.extend('-D%s' % i for i in self._deps_cpp_info.defines)
            flags.extend('-I"%s"' % i for i in self._deps_cpp_info.include_paths)
            flags.extend('-L"%s"' % i for i in self._deps_cpp_info.lib_paths)
            flags.extend("-l%s" % lib for lib in self._deps_cpp_info.libs)
            flags.extend(self._deps_cpp_info.cppflags)
            flags.extend(self._gcc_lib_flags())

            return " ".join(flags)
        if self.compiler == "Visual Studio":
            libs = " ".join("%s.lib" % lib for lib in self._deps_cpp_info.libs)
            return libs

        return ""
Пример #37
0
    def __init__(self, *args):
        if len(args) == 2:
            deps_cpp_info = args[0]
            deps_env_info = DepsEnvInfo()
            settings = args[1]
            self.output = ConanOutput(sys.stdout)
        elif len(args) == 1:  # conanfile (new interface)
            self.conanfile = args[0]
            self.output = self.conanfile.output
            deps_cpp_info = self.conanfile.deps_cpp_info
            deps_env_info = self.conanfile.deps_env_info
            settings = self.conanfile.settings

        assert isinstance(settings, Settings)

        self.output.warn("""
***********************************************************************

    WARNING!!!

    ConfigureEnvironment class is deprecated and will be removed soon.
    With ConfigureEnvironment, env variables from profiles and/or
    command line are not applied.

    Replace it with the right one according your needs:
      - AutoToolsBuildEnvironment
      - VisualStudioBuildEnvironment

    Check docs.conan.io


***********************************************************************
        """)

        self._settings = settings
        self._deps_cpp_info = deps_cpp_info
        self._deps_env_info = deps_env_info
        try:
            self.compiler = str(self._settings.compiler)
        except:
            self.compiler = None

        try:
            self.arch = str(self._settings.arch)
        except:
            self.arch = None

        try:
            self.os = str(self._settings.os)
        except:
            self.os = None

        try:
            self.build_type = str(self._settings.build_type)
        except:
            self.build_type = None

        try:
            self.libcxx = str(self._settings.compiler.libcxx)
        except:
            self.libcxx = None
Пример #38
0
import requests
from patch import fromfile, fromstring

from conans.client.output import ConanOutput
from conans.client.rest.uploader_downloader import Downloader
from conans.client.runner import ConanRunner
from conans.errors import ConanException
from conans.model.version import Version
# noinspection PyUnresolvedReferences
from conans.util.files import _generic_algorithm_sum, load, save, sha256sum, sha1sum, md5sum, md5
from conans.util.log import logger

# Default values
_global_requester = requests
_global_output = ConanOutput(sys.stdout)


def unix_path(path):
    """"Used to translate windows paths to MSYS unix paths like
    c/users/path/to/file"""
    pattern = re.compile(r'([a-z]):\\', re.IGNORECASE)
    return pattern.sub('/\\1/', path).replace('\\', '/').lower()


def escape_windows_cmd(command):
    """ To use in a regular windows cmd.exe
        1. Adds escapes so the argument can be unpacked by CommandLineToArgvW()
        2. Adds escapes for cmd.exe so the argument survives cmd.exe's substitutions.

        Useful to escape commands to be executed in a windows bash (msys2, cygwin etc)
Пример #39
0
 def __init__(self):
     self._buffer = StringIO()
     ConanOutput.__init__(self, self._buffer, color=False)