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 os, pickle, re, shlex, subprocess
  from collections import OrderedDict
  import itertools
  from pathlib import PurePath
  
  from . import backends
  from .. import modules
  from .. import environment, mesonlib
  from .. import build
  from .. import mlog
  from .. import dependencies
  from .. import compilers
  from ..compilers import CompilerArgs
  from ..linkers import ArLinker
  from ..mesonlib import File, MesonException, OrderedSet
  from ..mesonlib import get_compiler_for_source, has_path_sep
  from .backends import CleanTrees, InstallData
  from ..build import InvalidArguments
  
  if mesonlib.is_windows():
      quote_func = lambda s: '"{}"'.format(s)
      execute_wrapper = 'cmd /c'
      rmfile_prefix = 'del /f /s /q {} &&'
  else:
      quote_func = shlex.quote
      execute_wrapper = ''
      rmfile_prefix = 'rm -f {} &&'
  
  def ninja_quote(text, is_build_line=False):
      if is_build_line:
          qcs = ('$', ' ', ':')
      else:
          qcs = ('$', ' ')
      for char in qcs:
          text = text.replace(char, '$' + char)
      if '\n' in text:
          errmsg = '''Ninja does not support newlines in rules. The content was:
  
  %s
  
  Please report this error with a test case to the Meson bug tracker.''' % text
          raise MesonException(errmsg)
      return text
  
  
  class NinjaBuildElement:
      def __init__(self, all_outputs, outfilenames, rule, infilenames):
          if isinstance(outfilenames, str):
              self.outfilenames = [outfilenames]
          else:
              self.outfilenames = outfilenames
          assert(isinstance(rule, str))
          self.rule = rule
          if isinstance(infilenames, str):
              self.infilenames = [infilenames]
          else:
              self.infilenames = infilenames
          self.deps = set()
          self.orderdeps = set()
          self.elems = []
          self.all_outputs = all_outputs
  
      def add_dep(self, dep):
          if isinstance(dep, list):
              self.deps.update(dep)
          else:
              self.deps.add(dep)
  
      def add_orderdep(self, dep):
          if isinstance(dep, list):
              self.orderdeps.update(dep)
          else:
              self.orderdeps.add(dep)
  
      def add_item(self, name, elems):
          if isinstance(elems, str):
              elems = [elems]
          self.elems.append((name, elems))
  
      def write(self, outfile):
          self.check_outputs()
          line = 'build %s: %s %s' % (' '.join([ninja_quote(i, True) for i in self.outfilenames]),
                                      self.rule,
                                      ' '.join([ninja_quote(i,
  
  [... the rest is omitted ...]
files: mesonbuild/backend/ninjabackend.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 os, pickle, re, shlex, subprocess
  from collections import OrderedDict
  import itertools
  from pathlib import PurePath
  
  from . import backends
  from .. import modules
  from .. import environment, mesonlib
  from .. import build
  from .. import mlog
  from .. import dependencies
  from .. import compilers
  from ..compilers import CompilerArgs
  from ..linkers import ArLinker
  from ..mesonlib import File, MesonException, OrderedSet
  from ..mesonlib import get_compiler_for_source
  from .backends import CleanTrees, InstallData
  from ..build import InvalidArguments
  
  if mesonlib.is_windows():
      quote_func = lambda s: '"{}"'.format(s)
      execute_wrapper = 'cmd /c'
      rmfile_prefix = 'del /f /s /q {} &&'
  else:
      quote_func = shlex.quote
      execute_wrapper = ''
      rmfile_prefix = 'rm -f {} &&'
  
  def ninja_quote(text, is_build_line=False):
      if is_build_line:
          qcs = ('$', ' ', ':')
      else:
          qcs = ('$', ' ')
      for char in qcs:
          text = text.replace(char, '$' + char)
      if '\n' in text:
          errmsg = '''Ninja does not support newlines in rules. The content was:
  
  %s
  
  Please report this error with a test case to the Meson bug tracker.''' % text
          raise MesonException(errmsg)
      return text
  
  
  class NinjaBuildElement:
      def __init__(self, all_outputs, outfilenames, rule, infilenames):
          if isinstance(outfilenames, str):
              self.outfilenames = [outfilenames]
          else:
              self.outfilenames = outfilenames
          assert(isinstance(rule, str))
          self.rule = rule
          if isinstance(infilenames, str):
              self.infilenames = [infilenames]
          else:
              self.infilenames = infilenames
          self.deps = set()
          self.orderdeps = set()
          self.elems = []
          self.all_outputs = all_outputs
  
      def add_dep(self, dep):
          if isinstance(dep, list):
              self.deps.update(dep)
          else:
              self.deps.add(dep)
  
      def add_orderdep(self, dep):
          if isinstance(dep, list):
              self.orderdeps.update(dep)
          else:
              self.orderdeps.add(dep)
  
      def add_item(self, name, elems):
          if isinstance(elems, str):
              elems = [elems]
          self.elems.append((name, elems))
  
      def write(self, outfile):
          self.check_outputs()
          line = 'build %s: %s %s' % (' '.join([ninja_quote(i, True) for i in self.outfilenames]),
                                      self.rule,
                                      ' '.join([ninja_quote(i, True) for i in
  
  [... the rest is omitted ...]
files: mesonbuild/backend/ninjabackend.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, clike_langs, sort_clike, lang_suffixes
  
  known_basic_kwargs = {'install': True,
                        'c_pch': True,
                        'cpp_pch': True,
                        'c_args': True,
                        'objc_args': True,
                        'objcpp_args': True,
                        'cpp_args': True,
                        'cs_args': True,
                        'vala_args': True,
                        'fortran_args': True,
                        'd_args': True,
                        'd_import_dirs': True,
                        'd_unittest': True,
                        'd_module_versions': True,
                        'java_args': True,
                        'rust_args': True,
                        'link_args': True,
                        'link_depends': True,
                        'link_with': True,
                        'link_whole': True,
                        'implicit_include_directories': True,
                        'include_directories': True,
                        'dependencies': True,
                        'install_dir': True,
                        'main_class': True,
                        'name_suffix': True,
                        'gui_app': True,
                        'extra_files': True,
                        'install_rpath': True,
                        'build_rpath': True,
                        'resources': True,
                        'sources': True,
                        'objects': True,
                        'native': True,
                        'build_by_default': True,
                        'override_options': True,
                        }
  
  # These contain kwargs supported by both static and shared libraries. These are
  # combined here because a library() call might be shared_library() or
  # static_library() at runtime based on the configuration.
  # FIXME: Find a way to pass that info down here so we can have proper target
  # kwargs checking when specifically using shared_library() or static_library().
  known_lib_kwargs = known_basic_kwargs.copy()
  known_lib_kwargs.update({'version': True, # Only for shared libs
                           'soversion': True, # Only for shared libs
                           'name_prefix': True,
                           'vs_module_defs': True, # Only for shared libs
                           'vala_header': True,
                           'vala_vapi': True,
                           'vala_gir': True,
                           'pic': True, # Only for static libs
                           'rust_crate_type': True, # Only for Rust libs
                           })
  
  known_exe_kwargs = known_basic_kwargs.copy()
  known_exe_kwargs.update({'implib': True,
                           'export
  
  [... 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
  from .compilers import is_object, clike_langs, sort_clike, lang_suffixes
  
  known_basic_kwargs = {'install': True,
                        'c_pch': True,
                        'cpp_pch': True,
                        'c_args': True,
                        'objc_args': True,
                        'objcpp_args': True,
                        'cpp_args': True,
                        'cs_args': True,
                        'vala_args': True,
                        'fortran_args': True,
                        'd_args': True,
                        'd_import_dirs': True,
                        'd_unittest': True,
                        'd_module_versions': True,
                        'java_args': True,
                        'rust_args': True,
                        'link_args': True,
                        'link_depends': True,
                        'link_with': True,
                        'link_whole': True,
                        'implicit_include_directories': True,
                        'include_directories': True,
                        'dependencies': True,
                        'install_dir': True,
                        'main_class': True,
                        'name_suffix': True,
                        'gui_app': True,
                        'extra_files': True,
                        'install_rpath': True,
                        'build_rpath': True,
                        'resources': True,
                        'sources': True,
                        'objects': True,
                        'native': True,
                        'build_by_default': True,
                        'override_options': True,
                        }
  
  # These contain kwargs supported by both static and shared libraries. These are
  # combined here because a library() call might be shared_library() or
  # static_library() at runtime based on the configuration.
  # FIXME: Find a way to pass that info down here so we can have proper target
  # kwargs checking when specifically using shared_library() or static_library().
  known_lib_kwargs = known_basic_kwargs.copy()
  known_lib_kwargs.update({'version': True, # Only for shared libs
                           'soversion': True, # Only for shared libs
                           'name_prefix': True,
                           'vs_module_defs': True, # Only for shared libs
                           'vala_header': True,
                           'vala_vapi': True,
                           'vala_gir': True,
                           'pic': True, # Only for static libs
                           'rust_crate_type': True, # Only for Rust libs
                           })
  
  known_exe_kwargs = known_basic_kwargs.copy()
  known_exe_kwargs.update({'implib': True,
                           'export_dynamic': True
  
  
  [... 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 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, DependencyException
  from .interpreterbase import InterpreterBase
  from .interpreterbase import check_stringlist, noPosargs, noKwargs, stringArgs, permittedKwargs, permittedMethodKwargs
  from .interpreterbase import InterpreterException, InvalidArguments, InvalidCode
  from .interpreterbase import InterpreterObject, MutableInterpreterObject, Disabler
  from .modules import ModuleReturnValue
  
  import os, sys, shutil, uuid
  import re, shlex
  from collections import namedtuple
  from pathlib import PurePath
  
  import importlib
  
  
  def stringifyUserArguments(args):
      if isinstance(args, list):
          return '[%s]' % ', '.join([stringifyUserArguments(x) for x in args])
      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):
          self.held_object = obj
  
      def __repr__(self):
          return '<Holder: {!r}>'.format(self.held_object)
  
  
  class TryRunResultHolder(InterpreterObject):
      def __init__(self, res):
          super().__init__()
          self.res = res
          self.methods.update({'returncode': self.returncode_method,
                               'compiled': self.compiled_method,
                               'stdout': self.stdout_method,
                               'stderr': self.stderr_method,
                               })
  
      def returncode_method(self, args, kwargs):
          return self.res.returncode
  
      def compiled_method(self, args, kwargs):
          return self.res.compiled
  
      def stdout_method(self, args, kwargs):
          return self.res.stdout
  
      def stderr_method(self, args, kwargs):
          return self.res.stderr
  
  class RunProcess(InterpreterObject):
  
      def __init__(self, cmd, args, source_dir, build_dir, subdir, mesonintrospect, in_builddir=False):
          super().__init__()
          if not isinstance(cmd, ExternalProgram):
              raise AssertionError('BUG: RunProcess must be passed an ExternalProgram')
          pc, self.stdout, self.stderr = self.run_command(cmd, args, source_dir, build_dir, subdir, mesonintrospect, in_builddir)
          self.returncode = pc.returncode
          self.methods.update({'returncode': self.returncode_method,
                               'stdout': self.stdout_method,
                               'stderr': self.stderr_method,
                               })
  
      def run_command(self, cmd, args, source
  
  [... 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
  from .dependencies import ExternalProgram
  from .dependencies import InternalDependency, Dependency, DependencyException
  from .interpreterbase import InterpreterBase
  from .interpreterbase import check_stringlist, noPosargs, noKwargs, stringArgs, permittedKwargs, permittedMethodKwargs
  from .interpreterbase import InterpreterException, InvalidArguments, InvalidCode
  from .interpreterbase import InterpreterObject, MutableInterpreterObject, Disabler
  from .modules import ModuleReturnValue
  
  import os, sys, shutil, uuid
  import re, shlex
  from collections import namedtuple
  from pathlib import PurePath
  
  import importlib
  
  
  def stringifyUserArguments(args):
      if isinstance(args, list):
          return '[%s]' % ', '.join([stringifyUserArguments(x) for x in args])
      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):
          self.held_object = obj
  
      def __repr__(self):
          return '<Holder: {!r}>'.format(self.held_object)
  
  
  class TryRunResultHolder(InterpreterObject):
      def __init__(self, res):
          super().__init__()
          self.res = res
          self.methods.update({'returncode': self.returncode_method,
                               'compiled': self.compiled_method,
                               'stdout': self.stdout_method,
                               'stderr': self.stderr_method,
                               })
  
      def returncode_method(self, args, kwargs):
          return self.res.returncode
  
      def compiled_method(self, args, kwargs):
          return self.res.compiled
  
      def stdout_method(self, args, kwargs):
          return self.res.stdout
  
      def stderr_method(self, args, kwargs):
          return self.res.stderr
  
  class RunProcess(InterpreterObject):
  
      def __init__(self, cmd, args, source_dir, build_dir, subdir, mesonintrospect, in_builddir=False):
          super().__init__()
          if not isinstance(cmd, ExternalProgram):
              raise AssertionError('BUG: RunProcess must be passed an ExternalProgram')
          pc, self.stdout, self.stderr = self.run_command(cmd, args, source_dir, build_dir, subdir, mesonintrospect, in_builddir)
          self.returncode = pc.returncode
          self.methods.update({'returncode': self.returncode_method,
                               'stdout': self.stdout_method,
                               'stderr': self.stderr_method,
                               })
  
      def run_command(self, cmd, args, source_dir, build_dir,
  
  [... the rest is omitted ...]
files: mesonbuild/interpreter.py
files: # Copyright 2012-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.
  
  """A library of random helper functionality."""
  
  import sys
  import stat
  import time
  import platform, subprocess, operator, os, shutil, re
  import collections
  from mesonbuild import mlog
  
  from glob import glob
  
  def detect_meson_py_location():
      c = sys.argv[0]
      c_dir, c_fname = os.path.split(c)
  
      # get the absolute path to the <mesontool> folder
      m_dir = None
      if os.path.isabs(c):
          # $ /foo/<mesontool>.py <args>
          m_dir = c_dir
      elif c_dir == '':
          # $ <mesontool> <args> (gets run from /usr/bin/<mesontool>)
          in_path_exe = shutil.which(c_fname)
          if in_path_exe:
              if not os.path.isabs(in_path_exe):
                  m_dir = os.getcwd()
                  c_fname = in_path_exe
              else:
                  m_dir, c_fname = os.path.split(in_path_exe)
      else:
          m_dir = os.path.abspath(c_dir)
  
      # find meson in m_dir
      if m_dir is not None:
          for fname in ['meson', 'meson.py']:
              m_path = os.path.join(m_dir, fname)
              if os.path.exists(m_path):
                  return m_path
  
      # No meson found, which means that either:
      # a) meson is not installed
      # b) meson is installed to a non-standard location
      # c) the script that invoked mesonlib is not the one of meson tools (e.g. run_unittests.py)
      fname = os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'meson.py'))
      if os.path.exists(fname):
          return fname
      # If meson is still not found, we might be imported by out-of-source tests
      # https://github.com/mesonbuild/meson/issues/3015
      exe = shutil.which('meson')
      if exe is None:
          exe = shutil.which('meson.py')
      if exe is not None:
          return exe
      # Give up.
      raise RuntimeError('Could not determine how to run Meson. Please file a bug with details.')
  
  if os.path.basename(sys.executable) == 'meson.exe':
      # In Windows and using the MSI installed executable.
      meson_command = [sys.executable]
      python_command = [sys.executable, 'runpython']
  else:
      python_command = [sys.executable]
      meson_command = python_command + [detect_meson_py_location()]
  
  def is_ascii_string(astring):
      try:
          if isinstance(astring, str):
              astring.encode('ascii')
          if isinstance(astring, bytes):
              astring.decode('ascii')
      except UnicodeDecodeError:
          return False
      return True
  
  def check_direntry_issues(d
  
  [... the rest is omitted ...]
files: mesonbuild/mesonlib.py
files: # Copyright 2012-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.
  
  """A library of random helper functionality."""
  
  import sys
  import stat
  import time
  import platform, subprocess, operator, os, shutil, re
  import collections
  from mesonbuild import mlog
  
  from glob import glob
  
  def detect_meson_py_location():
      c = sys.argv[0]
      c_dir, c_fname = os.path.split(c)
  
      # get the absolute path to the <mesontool> folder
      m_dir = None
      if os.path.isabs(c):
          # $ /foo/<mesontool>.py <args>
          m_dir = c_dir
      elif c_dir == '':
          # $ <mesontool> <args> (gets run from /usr/bin/<mesontool>)
          in_path_exe = shutil.which(c_fname)
          if in_path_exe:
              if not os.path.isabs(in_path_exe):
                  m_dir = os.getcwd()
                  c_fname = in_path_exe
              else:
                  m_dir, c_fname = os.path.split(in_path_exe)
      else:
          m_dir = os.path.abspath(c_dir)
  
      # find meson in m_dir
      if m_dir is not None:
          for fname in ['meson', 'meson.py']:
              m_path = os.path.join(m_dir, fname)
              if os.path.exists(m_path):
                  return m_path
  
      # No meson found, which means that either:
      # a) meson is not installed
      # b) meson is installed to a non-standard location
      # c) the script that invoked mesonlib is not the one of meson tools (e.g. run_unittests.py)
      fname = os.path.normpath(os.path.join(os.path.dirname(__file__), '..', 'meson.py'))
      if os.path.exists(fname):
          return fname
      # If meson is still not found, we might be imported by out-of-source tests
      # https://github.com/mesonbuild/meson/issues/3015
      exe = shutil.which('meson')
      if exe is None:
          exe = shutil.which('meson.py')
      if exe is not None:
          return exe
      # Give up.
      raise RuntimeError('Could not determine how to run Meson. Please file a bug with details.')
  
  if os.path.basename(sys.executable) == 'meson.exe':
      # In Windows and using the MSI installed executable.
      meson_command = [sys.executable]
      python_command = [sys.executable, 'runpython']
  else:
      python_command = [sys.executable]
      meson_command = python_command + [detect_meson_py_location()]
  
  def is_ascii_string(astring):
      try:
          if isinstance(astring, str):
              astring.encode('ascii')
          if isinstance(astring, bytes):
              astring.decode('ascii')
      except UnicodeDecodeError:
          return False
      return True
  
  def check_direntry_issues(d
  
  [... the rest is omitted ...]
files: mesonbuild/mesonlib.py
files: # Copyright 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.
  
  import os
  import subprocess
  import shutil
  import argparse
  from .. import mlog
  from ..mesonlib import has_path_sep
  from . import destdir_join
  from .gettext import read_linguas
  
  parser = argparse.ArgumentParser()
  parser.add_argument('command')
  parser.add_argument('--id', dest='project_id')
  parser.add_argument('--subdir', dest='subdir')
  parser.add_argument('--installdir', dest='install_dir')
  parser.add_argument('--sources', dest='sources')
  parser.add_argument('--media', dest='media', default='')
  parser.add_argument('--langs', dest='langs', default='')
  parser.add_argument('--symlinks', type=bool, dest='symlinks', default=False)
  
  def build_pot(srcdir, project_id, sources):
      # Must be relative paths
      sources = [os.path.join('C', source) for source in sources]
      outfile = os.path.join(srcdir, project_id + '.pot')
      subprocess.call(['itstool', '-o', outfile] + sources)
  
  def update_po(srcdir, project_id, langs):
      potfile = os.path.join(srcdir, project_id + '.pot')
      for lang in langs:
          pofile = os.path.join(srcdir, lang, lang + '.po')
          subprocess.call(['msgmerge', '-q', '-o', pofile, pofile, potfile])
  
  def build_translations(srcdir, blddir, langs):
      for lang in langs:
          outdir = os.path.join(blddir, lang)
          os.makedirs(outdir, exist_ok=True)
          subprocess.call([
              'msgfmt', os.path.join(srcdir, lang, lang + '.po'),
              '-o', os.path.join(outdir, lang + '.gmo')
          ])
  
  def merge_translations(blddir, sources, langs):
      for lang in langs:
          subprocess.call([
              'itstool', '-m', os.path.join(blddir, lang, lang + '.gmo'),
              '-o', os.path.join(blddir, lang)
          ] + sources)
  
  def install_help(srcdir, blddir, sources, media, langs, install_dir, destdir, project_id, symlinks):
      c_install_dir = os.path.join(install_dir, 'C', project_id)
      for lang in langs + ['C']:
          indir = destdir_join(destdir, os.path.join(install_dir, lang, project_id))
          os.makedirs(indir, exist_ok=True)
          for source in sources:
              infile = os.path.join(srcdir if lang == 'C' else blddir, lang, source)
              outfile = os.path.join(indir, source)
              mlog.log('Installing %s to %s' % (infile, outfile))
              shutil.copyfile(infile, outfile)
              shutil.copystat(infile, outfile)
          for m in media:
              inf
  
  [... the rest is omitted ...]
files: mesonbuild/scripts/yelphelper.py
files: # Copyright 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.
  
  import os
  import subprocess
  import shutil
  import argparse
  from .. import mlog
  from . import destdir_join
  from .gettext import read_linguas
  
  parser = argparse.ArgumentParser()
  parser.add_argument('command')
  parser.add_argument('--id', dest='project_id')
  parser.add_argument('--subdir', dest='subdir')
  parser.add_argument('--installdir', dest='install_dir')
  parser.add_argument('--sources', dest='sources')
  parser.add_argument('--media', dest='media', default='')
  parser.add_argument('--langs', dest='langs', default='')
  parser.add_argument('--symlinks', type=bool, dest='symlinks', default=False)
  
  def build_pot(srcdir, project_id, sources):
      # Must be relative paths
      sources = [os.path.join('C', source) for source in sources]
      outfile = os.path.join(srcdir, project_id + '.pot')
      subprocess.call(['itstool', '-o', outfile] + sources)
  
  def update_po(srcdir, project_id, langs):
      potfile = os.path.join(srcdir, project_id + '.pot')
      for lang in langs:
          pofile = os.path.join(srcdir, lang, lang + '.po')
          subprocess.call(['msgmerge', '-q', '-o', pofile, pofile, potfile])
  
  def build_translations(srcdir, blddir, langs):
      for lang in langs:
          outdir = os.path.join(blddir, lang)
          os.makedirs(outdir, exist_ok=True)
          subprocess.call([
              'msgfmt', os.path.join(srcdir, lang, lang + '.po'),
              '-o', os.path.join(outdir, lang + '.gmo')
          ])
  
  def merge_translations(blddir, sources, langs):
      for lang in langs:
          subprocess.call([
              'itstool', '-m', os.path.join(blddir, lang, lang + '.gmo'),
              '-o', os.path.join(blddir, lang)
          ] + sources)
  
  def install_help(srcdir, blddir, sources, media, langs, install_dir, destdir, project_id, symlinks):
      c_install_dir = os.path.join(install_dir, 'C', project_id)
      for lang in langs + ['C']:
          indir = destdir_join(destdir, os.path.join(install_dir, lang, project_id))
          os.makedirs(indir, exist_ok=True)
          for source in sources:
              infile = os.path.join(srcdir if lang == 'C' else blddir, lang, source)
              outfile = os.path.join(indir, source)
              mlog.log('Installing %s to %s' % (infile, outfile))
              shutil.copyfile(infile, outfile)
              shutil.copystat(infile, outfile)
          for m in media:
              infile = os.path.join(srcdir, lang
  
  [... the rest is omitted ...]
files: mesonbuild/scripts/yelphelper.py