files.new_contents: import os, subprocess
  import argparse
  import asyncio
  import threading
  import copy
  import shutil
  from concurrent.futures.thread import ThreadPoolExecutor
  from pathlib import Path
  import typing as T
  
  from . import mlog
  from .mesonlib import quiet_git, GitException, Popen_safe, MesonException, windows_proof_rmtree
  from .wrap.wrap import PackageDefinition, Resolver, WrapException, ALL_TYPES
  from .wrap import wraptool
  
  ALL_TYPES_STRING = ', '.join(ALL_TYPES)
  
  class Logger:
      def __init__(self, total_tasks: int) -> None:
          self.lock = threading.Lock()
          self.total_tasks = total_tasks
          self.completed_tasks = 0
          self.running_tasks = set()
          self.should_erase_line = ''
  
      def flush(self) -> None:
          if self.should_erase_line:
              print(self.should_erase_line, end='\r')
              self.should_erase_line = ''
  
      def print_progress(self) -> None:
          line = f'Progress: {self.completed_tasks} / {self.total_tasks}'
          max_len = shutil.get_terminal_size().columns - len(line)
          running = ', '.join(self.running_tasks)
          if len(running) + 3 > max_len:
              running = running[:max_len - 6] + '...'
          line = line + f' ({running})'
          print(self.should_erase_line, line, sep='', end='\r')
          self.should_erase_line = '\x1b[K'
  
      def start(self, wrap_name: str) -> None:
          with self.lock:
              self.running_tasks.add(wrap_name)
              self.print_progress()
  
      def done(self, wrap_name: str, log_queue: T.List[T.Tuple[mlog.TV_LoggableList, T.Any]]) -> None:
          with self.lock:
              self.flush()
              for args, kwargs in log_queue:
                  mlog.log(*args, **kwargs)
              self.running_tasks.remove(wrap_name)
              self.completed_tasks += 1
              self.print_progress()
  
  
  class Runner:
      def __init__(self, logger: Logger, r: Resolver, wrap: PackageDefinition, repo_dir: str, options: argparse.Namespace) -> None:
          # FIXME: Do a copy because Resolver.resolve() is stateful method that
          # cannot be called from multiple threads.
          self.wrap_resolver = copy.copy(r)
          self.wrap = wrap
          self.repo_dir = repo_dir
          self.options = options
          self.run_method = options.subprojects_func.__get__(self)
          self.log_queue = []
          self.logger = logger
  
      def log(self, *args, **kwargs):
          self.log_queue.append((args, kwargs))
  
      def run(self):
          self.logger.start(self.wrap.name)
          result = self.run_method()
          self
  
  [... the rest is omitted ...]
files.new_path: mesonbuild/msubprojects.py
files.old_contents: import os, subprocess
  import argparse
  import asyncio
  import threading
  import copy
  import shutil
  from concurrent.futures.thread import ThreadPoolExecutor
  from pathlib import Path
  import typing as T
  
  from . import mlog
  from .mesonlib import quiet_git, GitException, Popen_safe, MesonException, windows_proof_rmtree
  from .wrap.wrap import PackageDefinition, Resolver, WrapException, ALL_TYPES
  from .wrap import wraptool
  
  ALL_TYPES_STRING = ', '.join(ALL_TYPES)
  
  class Logger:
      def __init__(self, total_tasks: int) -> None:
          self.lock = threading.Lock()
          self.total_tasks = total_tasks
          self.completed_tasks = 0
          self.running_tasks = set()
          self.should_erase_line = ''
  
      def flush(self) -> None:
          if self.should_erase_line:
              print(self.should_erase_line, end='\r')
              self.should_erase_line = ''
  
      def print_progress(self) -> None:
          line = f'Progress: {self.completed_tasks} / {self.total_tasks}'
          max_len = shutil.get_terminal_size().columns - len(line)
          running = ', '.join(self.running_tasks)
          if len(running) + 3 > max_len:
              running = running[:max_len - 6] + '...'
          line = line + f' ({running})'
          print(self.should_erase_line, line, sep='', end='\r')
          self.should_erase_line = '\x1b[K'
  
      def start(self, wrap_name: str) -> None:
          with self.lock:
              self.running_tasks.add(wrap_name)
              self.print_progress()
  
      def done(self, wrap_name: str, log_queue: T.List[T.Tuple[mlog.TV_LoggableList, T.Any]]) -> None:
          with self.lock:
              self.flush()
              for args, kwargs in log_queue:
                  mlog.log(*args, **kwargs)
              self.running_tasks.remove(wrap_name)
              self.completed_tasks += 1
              self.print_progress()
  
  
  class Runner:
      def __init__(self, logger: Logger, r: Resolver, wrap: PackageDefinition, repo_dir: str, options: argparse.Namespace) -> None:
          # FIXME: Do a copy because Resolver.resolve() is stateful method that
          # cannot be called from multiple threads.
          self.wrap_resolver = copy.copy(r)
          self.wrap = wrap
          self.repo_dir = repo_dir
          self.options = options
          self.run_method = options.subprojects_func.__get__(self)
          self.log_queue = []
          self.logger = logger
  
      def log(self, *args, **kwargs):
          self.log_queue.append((args, kwargs))
  
      def run(self):
          self.logger.start(self.wrap.name)
          result = self.run_method()
          self
  
  [... the rest is omitted ...]
files.old_path: mesonbuild/msubprojects.py
files.new_contents: # Copyright 2015 The Meson development team
  
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  
  #     http://www.apache.org/licenses/LICENSE-2.0
  
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  from .. import mlog
  import contextlib
  import urllib.request
  import urllib.error
  import urllib.parse
  import os
  import hashlib
  import shutil
  import tempfile
  import stat
  import subprocess
  import sys
  import configparser
  import typing as T
  import textwrap
  
  from pathlib import Path
  from . import WrapMode
  from .. import coredata
  from ..mesonlib import quiet_git, GIT, ProgressBar, MesonException
  from  .. import mesonlib
  
  if T.TYPE_CHECKING:
      import http.client
  
  try:
      # Importing is just done to check if SSL exists, so all warnings
      # regarding 'imported but unused' can be safely ignored
      import ssl  # noqa
      has_ssl = True
  except ImportError:
      has_ssl = False
  
  REQ_TIMEOUT = 600.0
  SSL_WARNING_PRINTED = False
  WHITELIST_SUBDOMAIN = 'wrapdb.mesonbuild.com'
  
  ALL_TYPES = ['file', 'git', 'hg', 'svn']
  
  def whitelist_wrapdb(urlstr: str) -> urllib.parse.ParseResult:
      """ raises WrapException if not whitelisted subdomain """
      url = urllib.parse.urlparse(urlstr)
      if not url.hostname:
          raise WrapException(f'{urlstr} is not a valid URL')
      if not url.hostname.endswith(WHITELIST_SUBDOMAIN):
          raise WrapException(f'{urlstr} is not a whitelisted WrapDB URL')
      if has_ssl and not url.scheme == 'https':
          raise WrapException(f'WrapDB did not have expected SSL https url, instead got {urlstr}')
      return url
  
  def open_wrapdburl(urlstring: str) -> 'http.client.HTTPResponse':
      global SSL_WARNING_PRINTED
  
      url = whitelist_wrapdb(urlstring)
      if has_ssl:
          try:
              return T.cast('http.client.HTTPResponse', urllib.request.urlopen(urllib.parse.urlunparse(url), timeout=REQ_TIMEOUT))
          except urllib.error.URLError as excp:
              raise WrapException(f'WrapDB connection failed to {urlstring} with error {excp}')
  
      # following code is only for those without Python SSL
      nossl_url = url._replace(scheme='http')
      if not SSL_WARNING_PRINTED:
  
  
  [... the rest is omitted ...]
files.new_path: mesonbuild/wrap/wrap.py
files.old_contents: # Copyright 2015 The Meson development team
  
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  
  #     http://www.apache.org/licenses/LICENSE-2.0
  
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  from .. import mlog
  import contextlib
  import urllib.request
  import urllib.error
  import urllib.parse
  import os
  import hashlib
  import shutil
  import tempfile
  import stat
  import subprocess
  import sys
  import configparser
  import typing as T
  import textwrap
  
  from pathlib import Path
  from . import WrapMode
  from .. import coredata
  from ..mesonlib import quiet_git, GIT, ProgressBar, MesonException
  from  .. import mesonlib
  
  if T.TYPE_CHECKING:
      import http.client
  
  try:
      # Importing is just done to check if SSL exists, so all warnings
      # regarding 'imported but unused' can be safely ignored
      import ssl  # noqa
      has_ssl = True
  except ImportError:
      has_ssl = False
  
  REQ_TIMEOUT = 600.0
  SSL_WARNING_PRINTED = False
  WHITELIST_SUBDOMAIN = 'wrapdb.mesonbuild.com'
  
  ALL_TYPES = ['file', 'git', 'hg', 'svn']
  
  def whitelist_wrapdb(urlstr: str) -> urllib.parse.ParseResult:
      """ raises WrapException if not whitelisted subdomain """
      url = urllib.parse.urlparse(urlstr)
      if not url.hostname:
          raise WrapException(f'{urlstr} is not a valid URL')
      if not url.hostname.endswith(WHITELIST_SUBDOMAIN):
          raise WrapException(f'{urlstr} is not a whitelisted WrapDB URL')
      if has_ssl and not url.scheme == 'https':
          raise WrapException(f'WrapDB did not have expected SSL https url, instead got {urlstr}')
      return url
  
  def open_wrapdburl(urlstring: str) -> 'http.client.HTTPResponse':
      global SSL_WARNING_PRINTED
  
      url = whitelist_wrapdb(urlstring)
      if has_ssl:
          try:
              return T.cast('http.client.HTTPResponse', urllib.request.urlopen(urllib.parse.urlunparse(url), timeout=REQ_TIMEOUT))
          except urllib.error.URLError as excp:
              raise WrapException(f'WrapDB connection failed to {urlstring} with error {excp}')
  
      # following code is only for those without Python SSL
      nossl_url = url._replace(scheme='http')
      if not SSL_WARNING_PRINTED:
  
  
  [... the rest is omitted ...]
files.old_path: mesonbuild/wrap/wrap.py
files.new_contents: #!/usr/bin/env python3
  # Copyright 2016-2021 The Meson development team
  
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  
  #     http://www.apache.org/licenses/LICENSE-2.0
  
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  # Work around some pathlib bugs...
  from mesonbuild import _pathlib
  import sys
  sys.modules['pathlib'] = _pathlib
  
  import time
  import stat
  import subprocess
  import re
  import json
  import tempfile
  import textwrap
  import os
  import shutil
  import unittest
  import platform
  import pickle
  import functools
  import io
  import operator
  import threading
  import zipfile, tarfile
  import hashlib
  from itertools import chain
  from unittest import mock
  from configparser import ConfigParser
  from contextlib import contextmanager
  from glob import glob
  from pathlib import (PurePath, Path)
  from distutils.dir_util import copy_tree
  import typing as T
  
  import mesonbuild.mlog
  import mesonbuild.depfile
  import mesonbuild.dependencies.base
  import mesonbuild.dependencies.factory
  import mesonbuild.compilers
  import mesonbuild.envconfig
  import mesonbuild.environment
  import mesonbuild.mesonlib
  import mesonbuild.coredata
  import mesonbuild.modules.gnome
  from mesonbuild.interpreter import Interpreter
  from mesonbuild.interpreterbase import typed_pos_args, InvalidArguments, ObjectHolder
  from mesonbuild.interpreterbase import typed_pos_args, InvalidArguments, typed_kwargs, ContainerTypeInfo, KwargInfo
  from mesonbuild.ast import AstInterpreter
  from mesonbuild.mesonlib import (
      BuildDirLock, LibType, MachineChoice, PerMachine, Version, is_windows,
      is_osx, is_cygwin, is_dragonflybsd, is_openbsd, is_haiku, is_sunos,
      windows_proof_rmtree, windows_proof_rm, python_command,
      version_compare, split_args, quote_arg, relpath, is_linux, git,
      search_version
  )
  from mesonbuild.compilers import (
      detect_static_linker, detect_c_compiler, detect_cpp_compiler,
      detect_objc_compiler, detect_objcpp_compiler, detect_d_compiler,
      detect_swift_compiler, compiler_from_language
  )
  from mesonbuild.environment import detect_ninja
  from mesonbuild.mesonlib import MesonException, EnvironmentException, OptionKey
  from mesonbuild.dependencies import PkgConfigDependency
  from mesonbuild.programs import ExternalProgram
  import mesonbuild.dependencies.base
  from mes
  
  [... the rest is omitted ...]
files.new_path: run_unittests.py
files.old_contents: #!/usr/bin/env python3
  # Copyright 2016-2021 The Meson development team
  
  # Licensed under the Apache License, Version 2.0 (the "License");
  # you may not use this file except in compliance with the License.
  # You may obtain a copy of the License at
  
  #     http://www.apache.org/licenses/LICENSE-2.0
  
  # Unless required by applicable law or agreed to in writing, software
  # distributed under the License is distributed on an "AS IS" BASIS,
  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  # See the License for the specific language governing permissions and
  # limitations under the License.
  
  # Work around some pathlib bugs...
  from mesonbuild import _pathlib
  import sys
  sys.modules['pathlib'] = _pathlib
  
  import time
  import stat
  import subprocess
  import re
  import json
  import tempfile
  import textwrap
  import os
  import shutil
  import unittest
  import platform
  import pickle
  import functools
  import io
  import operator
  import threading
  import zipfile, tarfile
  import hashlib
  from itertools import chain
  from unittest import mock
  from configparser import ConfigParser
  from contextlib import contextmanager
  from glob import glob
  from pathlib import (PurePath, Path)
  from distutils.dir_util import copy_tree
  import typing as T
  
  import mesonbuild.mlog
  import mesonbuild.depfile
  import mesonbuild.dependencies.base
  import mesonbuild.dependencies.factory
  import mesonbuild.compilers
  import mesonbuild.envconfig
  import mesonbuild.environment
  import mesonbuild.mesonlib
  import mesonbuild.coredata
  import mesonbuild.modules.gnome
  from mesonbuild.interpreter import Interpreter
  from mesonbuild.interpreterbase import typed_pos_args, InvalidArguments, ObjectHolder
  from mesonbuild.interpreterbase import typed_pos_args, InvalidArguments, typed_kwargs, ContainerTypeInfo, KwargInfo
  from mesonbuild.ast import AstInterpreter
  from mesonbuild.mesonlib import (
      BuildDirLock, LibType, MachineChoice, PerMachine, Version, is_windows,
      is_osx, is_cygwin, is_dragonflybsd, is_openbsd, is_haiku, is_sunos,
      windows_proof_rmtree, windows_proof_rm, python_command,
      version_compare, split_args, quote_arg, relpath, is_linux, git,
      search_version
  )
  from mesonbuild.compilers import (
      detect_static_linker, detect_c_compiler, detect_cpp_compiler,
      detect_objc_compiler, detect_objcpp_compiler, detect_d_compiler,
      detect_swift_compiler, compiler_from_language
  )
  from mesonbuild.environment import detect_ninja
  from mesonbuild.mesonlib import MesonException, EnvironmentException, OptionKey
  from mesonbuild.dependencies import PkgConfigDependency
  from mesonbuild.programs import ExternalProgram
  import mesonbuild.dependencies.base
  from mes
  
  [... the rest is omitted ...]
files.old_path: run_unittests.py