files: # Copyright 2012-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 copy, os, re
  from collections import OrderedDict
  import itertools, pathlib
  import pickle
  
  from . import environment
  from . import dependencies
  from . import mlog
  from .mesonlib import File, MesonException, listify, extract_as_list
  from .mesonlib import typeslistify, stringlistify, classify_unity_sources
  from .mesonlib import get_filenames_templates_dict, substitute_values
  from .mesonlib import for_windows, for_darwin, for_cygwin, for_android, has_path_sep
  from .compilers import is_object, clink_langs, sort_clink, lang_suffixes
  from .interpreterbase import FeatureNew
  
  pch_kwargs = set(['c_pch', 'cpp_pch'])
  
  lang_arg_kwargs = set([
      'c_args',
      'cpp_args',
      'd_args',
      'd_import_dirs',
      'd_unittest',
      'd_module_versions',
      'fortran_args',
      'java_args',
      'objc_args',
      'objcpp_args',
      'rust_args',
      'vala_args',
      'cs_args',
  ])
  
  vala_kwargs = set(['vala_header', 'vala_gir', 'vala_vapi'])
  rust_kwargs = set(['rust_crate_type'])
  cs_kwargs = set(['resources', 'cs_args'])
  
  buildtarget_kwargs = set([
      'build_by_default',
      'build_rpath',
      'dependencies',
      'extra_files',
      'gui_app',
      'link_with',
      'link_whole',
      'link_args',
      'link_depends',
      'implicit_include_directories',
      'include_directories',
      'install',
      'install_rpath',
      'install_dir',
      'install_mode',
      'name_prefix',
      'name_suffix',
      'native',
      'objects',
      'override_options',
      'sources',
  ])
  
  known_build_target_kwargs = (
      buildtarget_kwargs |
      lang_arg_kwargs |
      pch_kwargs |
      vala_kwargs |
      rust_kwargs |
      cs_kwargs)
  
  known_exe_kwargs = known_build_target_kwargs | {'implib', 'export_dynamic'}
  known_shlib_kwargs = known_build_target_kwargs | {'version', 'soversion', 'vs_module_defs'}
  
  
  [... the rest is omitted ...]
files: mesonbuild/build.py
files: # Copyright 2012-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 copy, os, re
  from collections import OrderedDict
  import itertools, pathlib
  import pickle
  
  from . import environment
  from . import dependencies
  from . import mlog
  from .mesonlib import File, MesonException, listify, extract_as_list
  from .mesonlib import typeslistify, stringlistify, classify_unity_sources
  from .mesonlib import get_filenames_templates_dict, substitute_values
  from .mesonlib import for_windows, for_darwin, for_cygwin, for_android, has_path_sep
  from .compilers import is_object, clink_langs, sort_clink, lang_suffixes
  from .interpreterbase import FeatureNew
  
  pch_kwargs = set(['c_pch', 'cpp_pch'])
  
  lang_arg_kwargs = set([
      'c_args',
      'cpp_args',
      'd_args',
      'd_import_dirs',
      'd_unittest',
      'd_module_versions',
      'fortran_args',
      'java_args',
      'objc_args',
      'objcpp_args',
      'rust_args',
      'vala_args',
      'cs_args',
  ])
  
  vala_kwargs = set(['vala_header', 'vala_gir', 'vala_vapi'])
  rust_kwargs = set(['rust_crate_type'])
  cs_kwargs = set(['resources', 'cs_args'])
  
  buildtarget_kwargs = set([
      'build_by_default',
      'build_rpath',
      'dependencies',
      'extra_files',
      'gui_app',
      'link_with',
      'link_whole',
      'link_args',
      'link_depends',
      'implicit_include_directories',
      'include_directories',
      'install',
      'install_rpath',
      'install_dir',
      'install_mode',
      'name_prefix',
      'name_suffix',
      'native',
      'objects',
      'override_options',
      'sources',
  ])
  
  known_build_target_kwargs = (
      buildtarget_kwargs |
      lang_arg_kwargs |
      pch_kwargs |
      vala_kwargs |
      rust_kwargs |
      cs_kwargs)
  
  known_exe_kwargs = known_build_target_kwargs | {'implib', 'export_dynamic'}
  known_shlib_kwargs = known_build_target_kwargs | {'version', 'soversion', 'vs_module_defs'}
  
  
  [... the rest is omitted ...]
files: mesonbuild/build.py
files: # 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, shlex
  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
  import argparse
  
  version = '0.48.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.')
  
      def set_value(self, newvalue):
          self.value = self.validate_value(newvalue)
  
  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_value(self, value):
          if not isinstance(value, str):
              raise MesonException('Value "%s" for string option "%s" is not a string.' % (str(value), self.name))
          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 __bool__(self):
          return self.value
  
      def validate_value(self, value):
          if isinstance(value, bool):
              return value
          if value.lower() == 'true':
              return True
          if value.lower() == 'false':
              return False
          raise MesonException('Value %s is not boolean (true or false).' % value)
  
  class UserIntegerOption(UserOption):
      def __init__(self, name, description, min_value, max_value, value
  
  [... the rest is omitted ...]
files: mesonbuild/coredata.py
files: # 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, shlex
  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
  import argparse
  
  version = '0.48.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.')
  
      def set_value(self, newvalue):
          self.value = self.validate_value(newvalue)
  
  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_value(self, value):
          if not isinstance(value, str):
              raise MesonException('Value "%s" for string option "%s" is not a string.' % (str(value), self.name))
          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 __bool__(self):
          return self.value
  
      def validate_value(self, value):
          if isinstance(value, bool):
              return value
          if value.lower() == 'true':
              return True
          if value.lower() == 'false':
              return False
          raise MesonException('Value %s is not boolean (true or false).' % value)
  
  class UserIntegerOption(UserOption):
      def __init__(self, name, description, min_value, max_value, value
  
  [... the rest is omitted ...]
files: mesonbuild/coredata.py
files: # 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 mparser
  from . import environment
  from . import coredata
  from . import dependencies
  from . import mlog
  from . import build
  from . import optinterpreter
  from . import compilers
  from .wrap import wrap, WrapMode
  from . import mesonlib
  from .mesonlib import FileMode, Popen_safe, listify, extract_as_list, has_path_sep
  from .dependencies import ExternalProgram
  from .dependencies import InternalDependency, Dependency, NotFoundDependency, DependencyException
  from .interpreterbase import InterpreterBase
  from .interpreterbase import check_stringlist, flatten, noPosargs, noKwargs, stringArgs, permittedKwargs, noArgsFlattening
  from .interpreterbase import InterpreterException, InvalidArguments, InvalidCode, SubdirDoneRequest
  from .interpreterbase import InterpreterObject, MutableInterpreterObject, Disabler
  from .interpreterbase import FeatureNew, FeatureDeprecated, FeatureNewKwargs
  from .modules import ModuleReturnValue
  
  import os, sys, shutil, uuid
  import re, shlex
  import subprocess
  from collections import namedtuple
  from pathlib import PurePath
  
  import importlib
  
  permitted_method_kwargs = {
      'partial_dependency': {'compile_args', 'link_args', 'links', 'includes',
                             'sources'},
  }
  
  def stringifyUserArguments(args):
      if isinstance(args, list):
          return '[%s]' % ', '.join([stringifyUserArguments(x) for x in args])
      elif isinstance(args, dict):
          return '{%s}' % ', '.join(['%s : %s' % (stringifyUserArguments(k), stringifyUserArguments(v)) for k, v in args.items()])
      elif isinstance(args, int):
          return str(args)
      elif isinstance(args, str):
          return "'%s'" % args
      raise InvalidArguments('Function accepts only strings, integers, lists and lists thereof.')
  
  
  class ObjectHolder:
      def __init__(self, obj, subproject=None):
          self.held_object = obj
          self.subproject = subproject
  
      def __repr__(self):
          return '<Holder: {!r}>'.format(self.held_object)
  
  class FeatureOptionHolder(InterpreterObject, ObjectHolder):
      def __init__(self, env, option):
          InterpreterObject.__init__(self)
          ObjectHolder.__init__(self, option)
          if option.is_auto():
              self.held
  
  [... the rest is omitted ...]
files: mesonbuild/interpreter.py
files: # 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 mparser
  from . import environment
  from . import coredata
  from . import dependencies
  from . import mlog
  from . import build
  from . import optinterpreter
  from . import compilers
  from .wrap import wrap, WrapMode
  from . import mesonlib
  from .mesonlib import FileMode, Popen_safe, listify, extract_as_list, has_path_sep
  from .dependencies import ExternalProgram
  from .dependencies import InternalDependency, Dependency, NotFoundDependency, DependencyException
  from .interpreterbase import InterpreterBase
  from .interpreterbase import check_stringlist, flatten, noPosargs, noKwargs, stringArgs, permittedKwargs, noArgsFlattening
  from .interpreterbase import InterpreterException, InvalidArguments, InvalidCode, SubdirDoneRequest
  from .interpreterbase import InterpreterObject, MutableInterpreterObject, Disabler
  from .interpreterbase import FeatureNew, FeatureDeprecated, FeatureNewKwargs
  from .modules import ModuleReturnValue
  
  import os, sys, shutil, uuid
  import re, shlex
  import subprocess
  from collections import namedtuple
  from pathlib import PurePath
  
  import importlib
  
  permitted_method_kwargs = {
      'partial_dependency': {'compile_args', 'link_args', 'links', 'includes',
                             'sources'},
  }
  
  def stringifyUserArguments(args):
      if isinstance(args, list):
          return '[%s]' % ', '.join([stringifyUserArguments(x) for x in args])
      elif isinstance(args, dict):
          return '{%s}' % ', '.join(['%s : %s' % (stringifyUserArguments(k), stringifyUserArguments(v)) for k, v in args.items()])
      elif isinstance(args, int):
          return str(args)
      elif isinstance(args, str):
          return "'%s'" % args
      raise InvalidArguments('Function accepts only strings, integers, lists and lists thereof.')
  
  
  class ObjectHolder:
      def __init__(self, obj, subproject=None):
          self.held_object = obj
          self.subproject = subproject
  
      def __repr__(self):
          return '<Holder: {!r}>'.format(self.held_object)
  
  class FeatureOptionHolder(InterpreterObject, ObjectHolder):
      def __init__(self, env, option):
          InterpreterObject.__init__(self)
          ObjectHolder.__init__(self, option)
          if option.is_auto():
              self.held
  
  [... the rest is omitted ...]
files: mesonbuild/interpreter.py
files: # 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.
  
  # This class contains the basic functionality needed to run any interpreter
  # or an interpreter-based tool.
  
  from . import mparser, mesonlib, mlog
  from . import environment, dependencies
  
  import os, copy, re, types
  from functools import wraps
  
  # Decorators for method calls.
  
  def check_stringlist(a, msg='Arguments must be strings.'):
      if not isinstance(a, list):
          mlog.debug('Not a list:', str(a))
          raise InvalidArguments('Argument not a list.')
      if not all(isinstance(s, str) for s in a):
          mlog.debug('Element not a string:', str(a))
          raise InvalidArguments(msg)
  
  def _get_callee_args(wrapped_args, want_subproject=False):
      s = wrapped_args[0]
      n = len(wrapped_args)
      # Raise an error if the codepaths are not there
      subproject = None
      if want_subproject and n == 2:
          if hasattr(s, 'subproject'):
              # Interpreter base types have 2 args: self, node
              node_or_state = wrapped_args[1]
              # args and kwargs are inside the node
              args = None
              kwargs = None
              subproject = s.subproject
          elif hasattr(wrapped_args[1], 'subproject'):
              # Module objects have 2 args: self, interpreter
              node_or_state = wrapped_args[1]
              # args and kwargs are inside the node
              args = None
              kwargs = None
              subproject = wrapped_args[1].subproject
          else:
              raise AssertionError('Unknown args: {!r}'.format(wrapped_args))
      elif n == 3:
          # Methods on objects (*Holder, MesonMain, etc) have 3 args: self, args, kwargs
          node_or_state = None # FIXME
          args = wrapped_args[1]
          kwargs = wrapped_args[2]
          if want_subproject:
              if hasattr(s, 'subproject'):
                  subproject = s.subproject
              elif hasattr(s, 'interpreter'):
                  subproject = s.interpreter.subproject
      elif n == 4:
          # Meson functions have 4 args: self, node, args, kwargs
          # Module functions have 4 args: self, state, args, kwargs; except,
          # PythonInstallation methods have self, interpreter, args, kwargs
          node_or_state = wrapped_args[1]
          args = wrapped_args
  
  [... the rest is omitted ...]
files: mesonbuild/interpreterbase.py
files: # 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.
  
  # This class contains the basic functionality needed to run any interpreter
  # or an interpreter-based tool.
  
  from . import mparser, mesonlib, mlog
  from . import environment, dependencies
  
  import os, copy, re, types
  from functools import wraps
  
  # Decorators for method calls.
  
  def check_stringlist(a, msg='Arguments must be strings.'):
      if not isinstance(a, list):
          mlog.debug('Not a list:', str(a))
          raise InvalidArguments('Argument not a list.')
      if not all(isinstance(s, str) for s in a):
          mlog.debug('Element not a string:', str(a))
          raise InvalidArguments(msg)
  
  def _get_callee_args(wrapped_args, want_subproject=False):
      s = wrapped_args[0]
      n = len(wrapped_args)
      # Raise an error if the codepaths are not there
      subproject = None
      if want_subproject and n == 2:
          if hasattr(s, 'subproject'):
              # Interpreter base types have 2 args: self, node
              node_or_state = wrapped_args[1]
              # args and kwargs are inside the node
              args = None
              kwargs = None
              subproject = s.subproject
          elif hasattr(wrapped_args[1], 'subproject'):
              # Module objects have 2 args: self, interpreter
              node_or_state = wrapped_args[1]
              # args and kwargs are inside the node
              args = None
              kwargs = None
              subproject = wrapped_args[1].subproject
          else:
              raise AssertionError('Unknown args: {!r}'.format(wrapped_args))
      elif n == 3:
          # Methods on objects (*Holder, MesonMain, etc) have 3 args: self, args, kwargs
          node_or_state = None # FIXME
          args = wrapped_args[1]
          kwargs = wrapped_args[2]
          if want_subproject:
              if hasattr(s, 'subproject'):
                  subproject = s.subproject
              elif hasattr(s, 'interpreter'):
                  subproject = s.interpreter.subproject
      elif n == 4:
          # Meson functions have 4 args: self, node, args, kwargs
          # Module functions have 4 args: self, state, args, kwargs; except,
          # PythonInstallation methods have self, interpreter, args, kwargs
          node_or_state = wrapped_args[1]
          args = wrapped_args
  
  [... the rest is omitted ...]
files: mesonbuild/interpreterbase.py
files: # Copyright 2013-2014 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 os
  import io
  import sys
  import time
  import platform
  from contextlib import contextmanager
  
  """This is (mostly) a standalone module used to write logging
  information about Meson runs. Some output goes to screen,
  some to logging dir and some goes to both."""
  
  def _windows_ansi():
      from ctypes import windll, byref
      from ctypes.wintypes import DWORD
  
      kernel = windll.kernel32
      stdout = kernel.GetStdHandle(-11)
      mode = DWORD()
      if not kernel.GetConsoleMode(stdout, byref(mode)):
          return False
      # ENABLE_VIRTUAL_TERMINAL_PROCESSING == 0x4
      # If the call to enable VT processing fails (returns 0), we fallback to
      # original behavior
      return kernel.SetConsoleMode(stdout, mode.value | 0x4) or os.environ.get('ANSICON')
  
  if platform.system().lower() == 'windows':
      colorize_console = os.isatty(sys.stdout.fileno()) and _windows_ansi()
  else:
      colorize_console = os.isatty(sys.stdout.fileno()) and os.environ.get('TERM') != 'dumb'
  log_dir = None
  log_file = None
  log_fname = 'meson-log.txt'
  log_depth = 0
  log_timestamp_start = None
  
  def initialize(logdir):
      global log_dir, log_file
      log_dir = logdir
      log_file = open(os.path.join(logdir, log_fname), 'w', encoding='utf8')
  
  def set_timestamp_start(start):
      global log_timestamp_start
      log_timestamp_start = start
  
  def shutdown():
      global log_file
      if log_file is not None:
          exception_around_goer = log_file
          log_file = None
          exception_around_goer.close()
  
  class AnsiDecorator:
      plain_code = "\033[0m"
  
      def __init__(self, text, code, quoted=False):
          self.text = text
          self.code = code
          self.quoted = quoted
  
      def get_text(self, with_codes):
          text = self.text
          if with_codes:
              text = self.code + self.text + AnsiDecorator.plain_code
          if self.quoted:
              text = '"{}"'.format(text)
          return text
  
  def bold(text, quoted=False):
      return AnsiDecorator(text,
  
  [... the rest is omitted ...]
files: mesonbuild/mlog.py
files: # Copyright 2013-2014 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 os
  import io
  import sys
  import time
  import platform
  from contextlib import contextmanager
  
  """This is (mostly) a standalone module used to write logging
  information about Meson runs. Some output goes to screen,
  some to logging dir and some goes to both."""
  
  def _windows_ansi():
      from ctypes import windll, byref
      from ctypes.wintypes import DWORD
  
      kernel = windll.kernel32
      stdout = kernel.GetStdHandle(-11)
      mode = DWORD()
      if not kernel.GetConsoleMode(stdout, byref(mode)):
          return False
      # ENABLE_VIRTUAL_TERMINAL_PROCESSING == 0x4
      # If the call to enable VT processing fails (returns 0), we fallback to
      # original behavior
      return kernel.SetConsoleMode(stdout, mode.value | 0x4) or os.environ.get('ANSICON')
  
  if platform.system().lower() == 'windows':
      colorize_console = os.isatty(sys.stdout.fileno()) and _windows_ansi()
  else:
      colorize_console = os.isatty(sys.stdout.fileno()) and os.environ.get('TERM') != 'dumb'
  log_dir = None
  log_file = None
  log_fname = 'meson-log.txt'
  log_depth = 0
  log_timestamp_start = None
  
  def initialize(logdir):
      global log_dir, log_file
      log_dir = logdir
      log_file = open(os.path.join(logdir, log_fname), 'w', encoding='utf8')
  
  def set_timestamp_start(start):
      global log_timestamp_start
      log_timestamp_start = start
  
  def shutdown():
      global log_file
      if log_file is not None:
          exception_around_goer = log_file
          log_file = None
          exception_around_goer.close()
  
  class AnsiDecorator:
      plain_code = "\033[0m"
  
      def __init__(self, text, code, quoted=False):
          self.text = text
          self.code = code
          self.quoted = quoted
  
      def get_text(self, with_codes):
          text = self.text
          if with_codes:
              text = self.code + self.text + AnsiDecorator.plain_code
          if self.quoted:
              text = '"{}"'.format(text)
          return text
  
  def bold(text, quoted=False):
      return AnsiDecorator(text,
  
  [... the rest is omitted ...]
files: mesonbuild/mlog.py
files: # Copyright 2015-2016 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.
  
  '''This module provides helper functions for Gnome/GLib related
  functionality such as gobject-introspection, gresources and gtk-doc'''
  
  import os
  import copy
  import subprocess
  
  from .. import build
  from .. import mlog
  from .. import mesonlib
  from .. import compilers
  from .. import interpreter
  from . import GResourceTarget, GResourceHeaderTarget, GirTarget, TypelibTarget, VapiTarget
  from . import get_include_args
  from . import ExtensionModule
  from . import ModuleReturnValue
  from ..mesonlib import MesonException, OrderedSet, Popen_safe, extract_as_list
  from ..dependencies import Dependency, PkgConfigDependency, InternalDependency
  from ..interpreterbase import noKwargs, permittedKwargs, FeatureNew, FeatureNewKwargs
  
  # gresource compilation is broken due to the way
  # the resource compiler and Ninja clash about it
  #
  # https://github.com/ninja-build/ninja/issues/1184
  # https://bugzilla.gnome.org/show_bug.cgi?id=774368
  gresource_dep_needed_version = '>= 2.51.1'
  
  native_glib_version = None
  girwarning_printed = False
  gdbuswarning_printed = False
  gresource_warning_printed = False
  _gir_has_extra_lib_arg = None
  
  def gir_has_extra_lib_arg(intr_obj):
      global _gir_has_extra_lib_arg
      if _gir_has_extra_lib_arg is not None:
          return _gir_has_extra_lib_arg
  
      _gir_has_extra_lib_arg = False
      try:
          g_ir_scanner = intr_obj.find_program_impl('g-ir-scanner').get_command()
          opts = Popen_safe(g_ir_scanner + ['--help'], stderr=subprocess.STDOUT)[1]
          _gir_has_extra_lib_arg = '--extra-library' in opts
      except (MesonException, FileNotFoundError, subprocess.CalledProcessError):
          pass
      return _gir_has_extra_lib_arg
  
  class GnomeModule(ExtensionModule):
      gir_dep = None
  
      @staticmethod
      def _get_native_glib_version(state):
          global native_glib_version
          if native_glib_version is None:
              glib_dep = PkgConfig
  
  [... the rest is omitted ...]
files: mesonbuild/modules/gnome.py
files: # Copyright 2015-2016 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.
  
  '''This module provides helper functions for Gnome/GLib related
  functionality such as gobject-introspection, gresources and gtk-doc'''
  
  import os
  import copy
  import subprocess
  
  from .. import build
  from .. import mlog
  from .. import mesonlib
  from .. import compilers
  from .. import interpreter
  from . import GResourceTarget, GResourceHeaderTarget, GirTarget, TypelibTarget, VapiTarget
  from . import get_include_args
  from . import ExtensionModule
  from . import ModuleReturnValue
  from ..mesonlib import MesonException, OrderedSet, Popen_safe, extract_as_list
  from ..dependencies import Dependency, PkgConfigDependency, InternalDependency
  from ..interpreterbase import noKwargs, permittedKwargs, FeatureNew, FeatureNewKwargs
  
  # gresource compilation is broken due to the way
  # the resource compiler and Ninja clash about it
  #
  # https://github.com/ninja-build/ninja/issues/1184
  # https://bugzilla.gnome.org/show_bug.cgi?id=774368
  gresource_dep_needed_version = '>= 2.51.1'
  
  native_glib_version = None
  girwarning_printed = False
  gdbuswarning_printed = False
  gresource_warning_printed = False
  _gir_has_extra_lib_arg = None
  
  def gir_has_extra_lib_arg(intr_obj):
      global _gir_has_extra_lib_arg
      if _gir_has_extra_lib_arg is not None:
          return _gir_has_extra_lib_arg
  
      _gir_has_extra_lib_arg = False
      try:
          g_ir_scanner = intr_obj.find_program_impl('g-ir-scanner').get_command()
          opts = Popen_safe(g_ir_scanner + ['--help'], stderr=subprocess.STDOUT)[1]
          _gir_has_extra_lib_arg = '--extra-library' in opts
      except (MesonException, FileNotFoundError, subprocess.CalledProcessError):
          pass
      return _gir_has_extra_lib_arg
  
  class GnomeModule(ExtensionModule):
      gir_dep = None
  
      @staticmethod
      def _get_native_glib_version(state):
          global native_glib_version
          if native_glib_version is None:
              glib_dep = PkgConfig
  
  [... the rest is omitted ...]
files: mesonbuild/modules/gnome.py