files.new_contents: # Copyright 2012-2018 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 pickle, os, uuid
  import sys
  from pathlib import PurePath
  from collections import OrderedDict
  from .mesonlib import MesonException
  from .mesonlib import default_libdir, default_libexecdir, default_prefix
  import ast
  
  version = '0.45.0.dev1'
  backendlist = ['ninja', 'vs', 'vs2010', 'vs2015', 'vs2017', 'xcode']
  
  default_yielding = False
  
  class UserOption:
      def __init__(self, name, description, choices, yielding):
          super().__init__()
          self.name = name
          self.choices = choices
          self.description = description
          if yielding is None:
              yielding = default_yielding
          if not isinstance(yielding, bool):
              raise MesonException('Value of "yielding" must be a boolean.')
          self.yielding = yielding
  
      # Check that the input is a valid value and return the
      # "cleaned" or "native" version. For example the Boolean
      # option could take the string "true" and return True.
      def validate_value(self, value):
          raise RuntimeError('Derived option class did not override validate_value.')
  
  class UserStringOption(UserOption):
      def __init__(self, name, description, value, choices=None, yielding=None):
          super().__init__(name, description, choices, yielding)
          self.set_value(value)
  
      def validate(self, value):
          if not isinstance(value, str):
              raise MesonException('Value "%s" for string option "%s" is not a string.' % (str(value), self.name))
  
      def set_value(self, newvalue):
          self.validate(newvalue)
          self.value = newvalue
  
      def validate_value(self, value):
          self.validate(value)
          return value
  
  class UserBooleanOption(UserOption):
      def __init__(self, name, description, value, yielding=None):
          super().__init__(name, description, [True, False], yielding)
          self.set_value(value)
  
      def tobool(self, thing):
          if isinstance(thing, bool):
              return thing
          if thing.lower() == 'true':
              return True
          if thing.lower() == 'false':
              return False
          raise MesonException('Value %s is not boolean (true or false).' % thing)
  
      def set_value(self, newvalue):
          self.value = self.tobool(newvalue)
  
      def __bool__(self):
          return self.value
  
      def validate_value(self, value):
          return self.tobool(value)
  
  class UserIntegerOption(UserOption):
      def __init__(self, name, description, min_value, max_value, value, yielding=None):
          super().__init__(name, description, [True, False], yielding)
          self.min_value = min_value
          self.max_value = max_value
          self.set_value(value)
          c = []
          if min_value is not None:
              c.append('>=' + str(min_value))
          if max_value is not None:
              c.append('<=' + str(max_value))
          self.choices = ', '.join(c)
  
      def set_value(self, newvalue):
          if isinstance(newvalue, str):
              newvalue = self.toint(newvalue)
          if not isinstance(newvalue, int):
              raise MesonException('New value for integer option is not an integer.')
          if self.min_value is not None and newvalue < self.min_value:
              raise MesonException('New value %d is less than minimum value %d.' % (newvalue, self.min_value))
          if self.max_value is not None and newvalue > self.max_value:
              raise MesonException('New value %d is more than maximum value %d.' % (newvalue, self.max_value))
          self.value = newvalue
  
      def toint(self, valuestring):
          try:
              return int(valuestring)
          except:
              raise MesonException('Value string "%s" is not convertable to an integer.' % valuestring)
  
      def validate
  
  [... the rest is omitted ...]
files.new_path: mesonbuild/coredata.py
files.old_contents: # Copyright 2012-2018 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 pickle, os, uuid
  import sys
  from pathlib import PurePath
  from collections import OrderedDict
  from .mesonlib import MesonException
  from .mesonlib import default_libdir, default_libexecdir, default_prefix
  import ast
  
  version = '0.45.0.dev1'
  backendlist = ['ninja', 'vs', 'vs2010', 'vs2015', 'vs2017', 'xcode']
  
  default_yielding = False
  
  class UserOption:
      def __init__(self, name, description, choices, yielding):
          super().__init__()
          self.name = name
          self.choices = choices
          self.description = description
          if yielding is None:
              yielding = default_yielding
          if not isinstance(yielding, bool):
              raise MesonException('Value of "yielding" must be a boolean.')
          self.yielding = yielding
  
      # Check that the input is a valid value and return the
      # "cleaned" or "native" version. For example the Boolean
      # option could take the string "true" and return True.
      def validate_value(self, value):
          raise RuntimeError('Derived option class did not override validate_value.')
  
  class UserStringOption(UserOption):
      def __init__(self, name, description, value, choices=None, yielding=None):
          super().__init__(name, description, choices, yielding)
          self.set_value(value)
  
      def validate(self, value):
          if not isinstance(value, str):
              raise MesonException('Value "%s" for string option "%s" is not a string.' % (str(value), self.name))
  
      def set_value(self, newvalue):
          self.validate(newvalue)
          self.value = newvalue
  
      def validate_value(self, value):
          self.validate(value)
          return value
  
  class UserBooleanOption(UserOption):
      def __init__(self, name, description, value, yielding=None):
          super().__init__(name, description, [True, False], yielding)
          self.set_value(value)
  
      def tobool(self, thing):
          if isinstance(thing, bool):
              return thing
          if thing.lower() == 'true':
              return True
          if thing.lower() == 'false':
              return False
          raise MesonException('Value %s is not boolean (true or false).' % thing)
  
      def set_value(self, newvalue):
          self.value = self.tobool(newvalue)
  
      def __bool__(self):
          return self.value
  
      def validate_value(self, value):
          return self.tobool(value)
  
  class UserIntegerOption(UserOption):
      def __init__(self, name, description, min_value, max_value, value, yielding=None):
          super().__init__(name, description, [True, False], yielding)
          self.min_value = min_value
          self.max_value = max_value
          self.set_value(value)
          c = []
          if min_value is not None:
              c.append('>=' + str(min_value))
          if max_value is not None:
              c.append('<=' + str(max_value))
          self.choices = ', '.join(c)
  
      def set_value(self, newvalue):
          if isinstance(newvalue, str):
              newvalue = self.toint(newvalue)
          if not isinstance(newvalue, int):
              raise MesonException('New value for integer option is not an integer.')
          if self.min_value is not None and newvalue < self.min_value:
              raise MesonException('New value %d is less than minimum value %d.' % (newvalue, self.min_value))
          if self.max_value is not None and newvalue > self.max_value:
              raise MesonException('New value %d is more than maximum value %d.' % (newvalue, self.max_value))
          self.value = newvalue
  
      def toint(self, valuestring):
          try:
              return int(valuestring)
          except:
              raise MesonException('Value string "%s" is not convertable to an integer.' % valuestring)
  
      def validate
  
  [... the rest is omitted ...]
files.old_path: mesonbuild/coredata.py
files.new_contents: #!/usr/bin/env python3
  # Copyright 2016-2017 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.
  
  import stat
  import shlex
  import subprocess
  import re, json
  import tempfile
  import textwrap
  import os
  import shutil
  import sys
  import unittest
  from unittest import mock
  from configparser import ConfigParser
  from glob import glob
  from pathlib import PurePath
  
  import mesonbuild.mlog
  import mesonbuild.compilers
  import mesonbuild.environment
  import mesonbuild.mesonlib
  import mesonbuild.coredata
  import mesonbuild.modules.gnome
  from mesonbuild.interpreter import ObjectHolder
  from mesonbuild.mesonlib import (
      is_linux, is_windows, is_osx, is_cygwin, is_dragonflybsd,
      windows_proof_rmtree, python_command, meson_command, version_compare,
  )
  from mesonbuild.environment import Environment, detect_ninja
  from mesonbuild.mesonlib import MesonException, EnvironmentException
  from mesonbuild.dependencies import PkgConfigDependency, ExternalProgram
  
  from run_tests import exe_suffix, get_fake_options
  from run_tests import get_builddir_target_args, get_backend_commands, Backend
  from run_tests import ensure_backend_detects_changes, run_configure, meson_exe
  from run_tests import should_run_linux_cross_tests
  
  
  def get_dynamic_section_entry(fname, entry):
      try:
          raw_out = subprocess.check_output(['readelf', '-d', fname],
                                            universal_newlines=True)
      except FileNotFoundError:
          # FIXME: Try using depfixer.py:Elf() as a fallback
          raise unittest.SkipTest('readelf not found')
      pattern = re.compile(entry + r': \[(.*?)\]')
      for line in raw_out.split('\n'):
          m = pattern.search(line)
          if m is not None:
              return m.group(1)
      return None # The file did not contain the specified entry.
  
  def get_soname(fname):
      return get_dynamic_section_entry(fname, 'soname')
  
  def get_rpath(fname):
      return get_dynamic_section_entry(fname, r'(?:rpath|runpath)')
  
  class InternalTests(unittest.TestCase):
  
      def test_version_number(self):
          searchfunc = mesonbuild.environment.search_version
          self.assertEqual(searchfunc('foobar 1.2.3'), '1.2.3')
          self.assertEqual(searchfunc('1.2.3'), '1.2.3')
          self.assertEqual(searchfunc('foobar 2016.10.28 1.2.3'), '1.2.3')
          self.assertEqual(searchfunc('2016.10.28 1.2.3'), '1.2.3')
          self.assertEqual(searchfunc('foobar 2016.10.128'), 'unknown version')
          self.assertEqual(searchfunc('2016.10.128'), 'unknown version')
  
      def test_mode_symbolic_to_bits(self):
          modefunc = mesonbuild.mesonlib.FileMode.perms_s_to_bits
          self.assertEqual(modefunc('---------'), 0)
          self.assertEqual(modefunc('r--------'), stat.S_IRUSR)
          self.assertEqual(modefunc('---r-----'), stat.S_IRGRP)
          self.assertEqual(modefunc('------r--'), stat.S_IROTH)
          self.assertEqual(modefunc('-w-------'), stat.S_IWUSR)
          self.assertEqual(modefunc('----w----'), stat.S_IWGRP)
          self.assertEqual(modefunc('-------w-'), stat.S_IWOTH)
          self.assertEqual(modefunc('--x------'), stat.S_IXUSR)
          self.assertEqual(modefunc('-----x---'), stat.S_IXGRP)
          self.assertEqual(modefunc('--------x'), stat.S_IXOTH)
          self.assertEqual(modefunc('--S------'), stat.S_ISUID)
          self.assertEqual(modefunc('-----
  
  [... the rest is omitted ...]
files.new_path: run_unittests.py
files.old_contents: #!/usr/bin/env python3
  # Copyright 2016-2017 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.
  
  import stat
  import shlex
  import subprocess
  import re, json
  import tempfile
  import textwrap
  import os
  import shutil
  import sys
  import unittest
  from unittest import mock
  from configparser import ConfigParser
  from glob import glob
  from pathlib import PurePath
  
  import mesonbuild.mlog
  import mesonbuild.compilers
  import mesonbuild.environment
  import mesonbuild.mesonlib
  import mesonbuild.coredata
  import mesonbuild.modules.gnome
  from mesonbuild.interpreter import ObjectHolder
  from mesonbuild.mesonlib import (
      is_linux, is_windows, is_osx, is_cygwin, is_dragonflybsd,
      windows_proof_rmtree, python_command, meson_command, version_compare,
  )
  from mesonbuild.environment import Environment, detect_ninja
  from mesonbuild.mesonlib import MesonException, EnvironmentException
  from mesonbuild.dependencies import PkgConfigDependency, ExternalProgram
  
  from run_tests import exe_suffix, get_fake_options
  from run_tests import get_builddir_target_args, get_backend_commands, Backend
  from run_tests import ensure_backend_detects_changes, run_configure, meson_exe
  from run_tests import should_run_linux_cross_tests
  
  
  def get_dynamic_section_entry(fname, entry):
      try:
          raw_out = subprocess.check_output(['readelf', '-d', fname],
                                            universal_newlines=True)
      except FileNotFoundError:
          # FIXME: Try using depfixer.py:Elf() as a fallback
          raise unittest.SkipTest('readelf not found')
      pattern = re.compile(entry + r': \[(.*?)\]')
      for line in raw_out.split('\n'):
          m = pattern.search(line)
          if m is not None:
              return m.group(1)
      return None # The file did not contain the specified entry.
  
  def get_soname(fname):
      return get_dynamic_section_entry(fname, 'soname')
  
  def get_rpath(fname):
      return get_dynamic_section_entry(fname, r'(?:rpath|runpath)')
  
  class InternalTests(unittest.TestCase):
  
      def test_version_number(self):
          searchfunc = mesonbuild.environment.search_version
          self.assertEqual(searchfunc('foobar 1.2.3'), '1.2.3')
          self.assertEqual(searchfunc('1.2.3'), '1.2.3')
          self.assertEqual(searchfunc('foobar 2016.10.28 1.2.3'), '1.2.3')
          self.assertEqual(searchfunc('2016.10.28 1.2.3'), '1.2.3')
          self.assertEqual(searchfunc('foobar 2016.10.128'), 'unknown version')
          self.assertEqual(searchfunc('2016.10.128'), 'unknown version')
  
      def test_mode_symbolic_to_bits(self):
          modefunc = mesonbuild.mesonlib.FileMode.perms_s_to_bits
          self.assertEqual(modefunc('---------'), 0)
          self.assertEqual(modefunc('r--------'), stat.S_IRUSR)
          self.assertEqual(modefunc('---r-----'), stat.S_IRGRP)
          self.assertEqual(modefunc('------r--'), stat.S_IROTH)
          self.assertEqual(modefunc('-w-------'), stat.S_IWUSR)
          self.assertEqual(modefunc('----w----'), stat.S_IWGRP)
          self.assertEqual(modefunc('-------w-'), stat.S_IWOTH)
          self.assertEqual(modefunc('--x------'), stat.S_IXUSR)
          self.assertEqual(modefunc('-----x---'), stat.S_IXGRP)
          self.assertEqual(modefunc('--------x'), stat.S_IXOTH)
          self.assertEqual(modefunc('--S------'), stat.S_ISUID)
          self.assertEqual(modefunc('-----
  
  [... the rest is omitted ...]
files.old_path: run_unittests.py