Merge pull request #2264 from jeandet/master

Some refactoring, introduction of listify function.
pull/2249/head
Jussi Pakkanen 8 years ago committed by GitHub
commit 1556b1bdb0
  1. 108
      mesonbuild/build.py
  2. 5
      mesonbuild/compilers/c.py
  3. 7
      mesonbuild/dependencies/base.py
  4. 6
      mesonbuild/dependencies/misc.py
  5. 9
      mesonbuild/dependencies/ui.py
  6. 70
      mesonbuild/interpreter.py
  7. 20
      mesonbuild/mesonlib.py
  8. 65
      mesonbuild/modules/gnome.py
  9. 3
      mesonbuild/modules/pkgconfig.py
  10. 19
      mesonbuild/modules/qt4.py
  11. 19
      mesonbuild/modules/qt5.py
  12. 4
      mesonbuild/modules/unstable_simd.py
  13. 6
      mesonbuild/modules/windows.py

@ -19,7 +19,7 @@ import itertools
from . import environment from . import environment
from . import dependencies from . import dependencies
from . import mlog from . import mlog
from .mesonlib import File, MesonException from .mesonlib import File, MesonException, listify, extract_as_list
from .mesonlib import flatten, typeslistify, stringlistify, classify_unity_sources from .mesonlib import flatten, typeslistify, stringlistify, classify_unity_sources
from .mesonlib import get_filenames_templates_dict, substitute_values from .mesonlib import get_filenames_templates_dict, substitute_values
from .environment import for_windows, for_darwin, for_cygwin from .environment import for_windows, for_darwin, for_cygwin
@ -414,8 +414,7 @@ class BuildTarget(Target):
raise InvalidArguments(msg) raise InvalidArguments(msg)
def process_sourcelist(self, sources): def process_sourcelist(self, sources):
if not isinstance(sources, list): sources = listify(sources)
sources = [sources]
added_sources = {} # If the same source is defined multiple times, use it only once. added_sources = {} # If the same source is defined multiple times, use it only once.
for s in sources: for s in sources:
# Holder unpacking. Ugly. # Holder unpacking. Ugly.
@ -528,8 +527,7 @@ class BuildTarget(Target):
generated twice, since the output needs to be passed to the ld_args and generated twice, since the output needs to be passed to the ld_args and
link_depends. link_depends.
""" """
if not isinstance(sources, list): sources = listify(sources)
sources = [sources]
for s in sources: for s in sources:
if hasattr(s, 'held_object'): if hasattr(s, 'held_object'):
s = s.held_object s = s.held_object
@ -551,8 +549,7 @@ class BuildTarget(Target):
return self.kwargs return self.kwargs
def unpack_holder(self, d): def unpack_holder(self, d):
if not isinstance(d, list): d = listify(d)
d = [d]
newd = [] newd = []
for i in d: for i in d:
if isinstance(i, list): if isinstance(i, list):
@ -610,64 +607,33 @@ class BuildTarget(Target):
self.copy_kwargs(kwargs) self.copy_kwargs(kwargs)
kwargs.get('modules', []) kwargs.get('modules', [])
self.need_install = kwargs.get('install', self.need_install) self.need_install = kwargs.get('install', self.need_install)
llist = kwargs.get('link_with', []) llist = extract_as_list(kwargs, 'link_with')
if not isinstance(llist, list):
llist = [llist]
for linktarget in llist: for linktarget in llist:
# Sorry for this hack. Keyword targets are kept in holders # Sorry for this hack. Keyword targets are kept in holders
# in kwargs. Unpack here without looking at the exact type. # in kwargs. Unpack here without looking at the exact type.
if hasattr(linktarget, "held_object"): if hasattr(linktarget, "held_object"):
linktarget = linktarget.held_object linktarget = linktarget.held_object
self.link(linktarget) self.link(linktarget)
lwhole = kwargs.get('link_whole', []) lwhole = extract_as_list(kwargs, 'link_whole')
if not isinstance(lwhole, list):
lwhole = [lwhole]
for linktarget in lwhole: for linktarget in lwhole:
# Sorry for this hack. Keyword targets are kept in holders # Sorry for this hack. Keyword targets are kept in holders
# in kwargs. Unpack here without looking at the exact type. # in kwargs. Unpack here without looking at the exact type.
if hasattr(linktarget, "held_object"): if hasattr(linktarget, "held_object"):
linktarget = linktarget.held_object linktarget = linktarget.held_object
self.link_whole(linktarget) self.link_whole(linktarget)
c_pchlist = kwargs.get('c_pch', [])
if not isinstance(c_pchlist, list): c_pchlist, cpp_pchlist, clist, cpplist, cslist, valalist, objclist, objcpplist, fortranlist, rustlist \
c_pchlist = [c_pchlist] = extract_as_list(kwargs, 'c_pch', 'cpp_pch', 'c_args', 'cpp_args', 'cs_args', 'vala_args', 'objc_args',
'objcpp_args', 'fortran_args', 'rust_args')
self.add_pch('c', c_pchlist) self.add_pch('c', c_pchlist)
cpp_pchlist = kwargs.get('cpp_pch', [])
if not isinstance(cpp_pchlist, list):
cpp_pchlist = [cpp_pchlist]
self.add_pch('cpp', cpp_pchlist) self.add_pch('cpp', cpp_pchlist)
clist = kwargs.get('c_args', []) compiler_args = {'c': clist, 'cpp': cpplist, 'cs': cslist, 'vala': valalist, 'objc': objclist, 'objcpp': objcpplist,
if not isinstance(clist, list): 'fortran': fortranlist, 'rust': rustlist
clist = [clist] }
self.add_compiler_args('c', clist) for key, value in compiler_args.items():
cpplist = kwargs.get('cpp_args', []) self.add_compiler_args(key, value)
if not isinstance(cpplist, list):
cpplist = [cpplist]
self.add_compiler_args('cpp', cpplist)
cslist = kwargs.get('cs_args', [])
if not isinstance(cslist, list):
cslist = [cslist]
self.add_compiler_args('cs', cslist)
valalist = kwargs.get('vala_args', [])
if not isinstance(valalist, list):
valalist = [valalist]
self.add_compiler_args('vala', valalist)
objclist = kwargs.get('objc_args', [])
if not isinstance(objclist, list):
objclist = [objclist]
self.add_compiler_args('objc', objclist)
objcpplist = kwargs.get('objcpp_args', [])
if not isinstance(objcpplist, list):
objcpplist = [objcpplist]
self.add_compiler_args('objcpp', objcpplist)
fortranlist = kwargs.get('fortran_args', [])
if not isinstance(fortranlist, list):
fortranlist = [fortranlist]
self.add_compiler_args('fortran', fortranlist)
rustlist = kwargs.get('rust_args', [])
if not isinstance(rustlist, list):
rustlist = [rustlist]
self.add_compiler_args('rust', rustlist)
if not isinstance(self, Executable): if not isinstance(self, Executable):
self.vala_header = kwargs.get('vala_header', self.name + '.h') self.vala_header = kwargs.get('vala_header', self.name + '.h')
self.vala_vapi = kwargs.get('vala_vapi', self.name + '.vapi') self.vala_vapi = kwargs.get('vala_vapi', self.name + '.vapi')
@ -700,14 +666,10 @@ This will become a hard error in a future Meson release.''')
self.process_link_depends(kwargs.get('link_depends', []), environment) self.process_link_depends(kwargs.get('link_depends', []), environment)
# Target-specific include dirs must be added BEFORE include dirs from # Target-specific include dirs must be added BEFORE include dirs from
# internal deps (added inside self.add_deps()) to override them. # internal deps (added inside self.add_deps()) to override them.
inclist = kwargs.get('include_directories', []) inclist = extract_as_list(kwargs, 'include_directories')
if not isinstance(inclist, list):
inclist = [inclist]
self.add_include_dirs(inclist) self.add_include_dirs(inclist)
# Add dependencies (which also have include_directories) # Add dependencies (which also have include_directories)
deplist = kwargs.get('dependencies', []) deplist = extract_as_list(kwargs, 'dependencies')
if not isinstance(deplist, list):
deplist = [deplist]
self.add_deps(deplist) self.add_deps(deplist)
# If an item in this list is False, the output corresponding to # If an item in this list is False, the output corresponding to
# the list index of that item will not be installed # the list index of that item will not be installed
@ -723,9 +685,7 @@ This will become a hard error in a future Meson release.''')
raise InvalidArguments('Argument gui_app must be boolean.') raise InvalidArguments('Argument gui_app must be boolean.')
elif 'gui_app' in kwargs: elif 'gui_app' in kwargs:
raise InvalidArguments('Argument gui_app can only be used on executables.') raise InvalidArguments('Argument gui_app can only be used on executables.')
extra_files = kwargs.get('extra_files', []) extra_files = extract_as_list(kwargs, 'extra_files')
if not isinstance(extra_files, list):
extra_files = [extra_files]
for i in extra_files: for i in extra_files:
assert(isinstance(i, File)) assert(isinstance(i, File))
trial = os.path.join(environment.get_source_dir(), i.subdir, i.fname) trial = os.path.join(environment.get_source_dir(), i.subdir, i.fname)
@ -738,9 +698,7 @@ This will become a hard error in a future Meson release.''')
self.build_rpath = kwargs.get('build_rpath', '') self.build_rpath = kwargs.get('build_rpath', '')
if not isinstance(self.build_rpath, str): if not isinstance(self.build_rpath, str):
raise InvalidArguments('Build_rpath is not a string.') raise InvalidArguments('Build_rpath is not a string.')
resources = kwargs.get('resources', []) resources = extract_as_list(kwargs, 'resources')
if not isinstance(resources, list):
resources = [resources]
for r in resources: for r in resources:
if not isinstance(r, str): if not isinstance(r, str):
raise InvalidArguments('Resource argument is not a string.') raise InvalidArguments('Resource argument is not a string.')
@ -829,8 +787,7 @@ This will become a hard error in a future Meson release.''')
return self.include_dirs return self.include_dirs
def add_deps(self, deps): def add_deps(self, deps):
if not isinstance(deps, list): deps = listify(deps)
deps = [deps]
for dep in deps: for dep in deps:
if hasattr(dep, 'held_object'): if hasattr(dep, 'held_object'):
dep = dep.held_object dep = dep.held_object
@ -1058,9 +1015,7 @@ class Generator:
self.arglist = args self.arglist = args
if 'output' not in kwargs: if 'output' not in kwargs:
raise InvalidArguments('Generator must have "output" keyword argument.') raise InvalidArguments('Generator must have "output" keyword argument.')
outputs = kwargs['output'] outputs = listify(kwargs['output'])
if not isinstance(outputs, list):
outputs = [outputs]
for rule in outputs: for rule in outputs:
if not isinstance(rule, str): if not isinstance(rule, str):
raise InvalidArguments('"output" may only contain strings.') raise InvalidArguments('"output" may only contain strings.')
@ -1556,8 +1511,7 @@ class CustomTarget(Target):
return deps return deps
def flatten_command(self, cmd): def flatten_command(self, cmd):
if not isinstance(cmd, list): cmd = listify(cmd)
cmd = [cmd]
final_cmd = [] final_cmd = []
for c in cmd: for c in cmd:
if hasattr(c, 'held_object'): if hasattr(c, 'held_object'):
@ -1592,9 +1546,7 @@ class CustomTarget(Target):
self.sources.append(s) self.sources.append(s)
if 'output' not in kwargs: if 'output' not in kwargs:
raise InvalidArguments('Missing keyword argument "output".') raise InvalidArguments('Missing keyword argument "output".')
self.outputs = kwargs['output'] self.outputs = listify(kwargs['output'])
if not isinstance(self.outputs, list):
self.outputs = [self.outputs]
# This will substitute values from the input into output and return it. # This will substitute values from the input into output and return it.
inputs = get_sources_string_names(self.sources) inputs = get_sources_string_names(self.sources)
values = get_filenames_templates_dict(inputs, []) values = get_filenames_templates_dict(inputs, [])
@ -1648,18 +1600,13 @@ class CustomTarget(Target):
self.build_always = kwargs.get('build_always', False) self.build_always = kwargs.get('build_always', False)
if not isinstance(self.build_always, bool): if not isinstance(self.build_always, bool):
raise InvalidArguments('Argument build_always must be a boolean.') raise InvalidArguments('Argument build_always must be a boolean.')
extra_deps = kwargs.get('depends', []) extra_deps, depend_files = extract_as_list(kwargs, 'depends', 'depend_files', pop = False)
if not isinstance(extra_deps, list):
extra_deps = [extra_deps]
for ed in extra_deps: for ed in extra_deps:
while hasattr(ed, 'held_object'): while hasattr(ed, 'held_object'):
ed = ed.held_object ed = ed.held_object
if not isinstance(ed, (CustomTarget, BuildTarget)): if not isinstance(ed, (CustomTarget, BuildTarget)):
raise InvalidArguments('Can only depend on toplevel targets: custom_target or build_target (executable or a library)') raise InvalidArguments('Can only depend on toplevel targets: custom_target or build_target (executable or a library)')
self.extra_depends.append(ed) self.extra_depends.append(ed)
depend_files = kwargs.get('depend_files', [])
if not isinstance(depend_files, list):
depend_files = [depend_files]
for i in depend_files: for i in depend_files:
if isinstance(i, (File, str)): if isinstance(i, (File, str)):
self.depend_files.append(i) self.depend_files.append(i)
@ -1809,8 +1756,7 @@ class Data:
self.sources = sources self.sources = sources
self.install_dir = install_dir self.install_dir = install_dir
self.install_mode = install_mode self.install_mode = install_mode
if not isinstance(self.sources, list): self.sources = listify(self.sources)
self.sources = [self.sources]
for s in self.sources: for s in self.sources:
assert(isinstance(s, File)) assert(isinstance(s, File))

@ -16,7 +16,7 @@ import subprocess, os.path, tempfile
from .. import mlog from .. import mlog
from .. import coredata from .. import coredata
from ..mesonlib import EnvironmentException, version_compare, Popen_safe from ..mesonlib import EnvironmentException, version_compare, Popen_safe, listify
from .compilers import ( from .compilers import (
GCC_MINGW, GCC_MINGW,
@ -1013,8 +1013,7 @@ class VisualStudioCCompiler(CCompiler):
def get_link_whole_for(self, args): def get_link_whole_for(self, args):
# Only since VS2015 # Only since VS2015
if not isinstance(args, list): args = listify(args)
args = [args]
return ['/WHOLEARCHIVE:' + x for x in args] return ['/WHOLEARCHIVE:' + x for x in args]
def get_instruction_set_args(self, instruction_set): def get_instruction_set_args(self, instruction_set):

@ -23,7 +23,7 @@ from enum import Enum
from .. import mlog from .. import mlog
from .. import mesonlib from .. import mesonlib
from ..mesonlib import MesonException, Popen_safe, flatten, version_compare_many from ..mesonlib import MesonException, Popen_safe, flatten, version_compare_many, listify
# These must be defined in this file to avoid cyclical references. # These must be defined in this file to avoid cyclical references.
@ -374,10 +374,7 @@ class ExternalProgram:
def __init__(self, name, command=None, silent=False, search_dir=None): def __init__(self, name, command=None, silent=False, search_dir=None):
self.name = name self.name = name
if command is not None: if command is not None:
if not isinstance(command, list): self.command = listify(command)
self.command = [command]
else:
self.command = command
else: else:
self.command = self._search(name, search_dir) self.command = self._search(name, search_dir)
if not silent: if not silent:

@ -24,7 +24,7 @@ import sysconfig
from .. import mlog from .. import mlog
from .. import mesonlib from .. import mesonlib
from ..mesonlib import Popen_safe from ..mesonlib import Popen_safe, extract_as_list
from ..environment import detect_cpu_family from ..environment import detect_cpu_family
from .base import DependencyException, DependencyMethods from .base import DependencyException, DependencyMethods
@ -132,9 +132,7 @@ class BoostDependency(ExternalDependency):
return args return args
def get_requested(self, kwargs): def get_requested(self, kwargs):
candidates = kwargs.get('modules', []) candidates = extract_as_list(kwargs, 'modules')
if not isinstance(candidates, list):
candidates = [candidates]
for c in candidates: for c in candidates:
if not isinstance(c, str): if not isinstance(c, str):
raise DependencyException('Boost module argument is not a string.') raise DependencyException('Boost module argument is not a string.')

@ -23,7 +23,7 @@ from collections import OrderedDict
from .. import mlog from .. import mlog
from .. import mesonlib from .. import mesonlib
from ..mesonlib import MesonException, Popen_safe, version_compare from ..mesonlib import MesonException, Popen_safe, version_compare, extract_as_list
from ..environment import for_windows, detect_cpu from ..environment import for_windows, detect_cpu
from .base import DependencyException, DependencyMethods from .base import DependencyException, DependencyMethods
@ -468,12 +468,9 @@ class WxDependency(ExternalDependency):
self.link_args = out.split() self.link_args = out.split()
def get_requested(self, kwargs): def get_requested(self, kwargs):
modules = 'modules' if 'modules' not in kwargs:
if modules not in kwargs:
return [] return []
candidates = kwargs[modules] candidates = extract_as_list(kwargs, 'modules')
if not isinstance(candidates, list):
candidates = [candidates]
for c in candidates: for c in candidates:
if not isinstance(c, str): if not isinstance(c, str):
raise DependencyException('wxwidgets module argument is not a string') raise DependencyException('wxwidgets module argument is not a string')

@ -21,7 +21,7 @@ from . import optinterpreter
from . import compilers from . import compilers
from .wrap import wrap, WrapMode from .wrap import wrap, WrapMode
from . import mesonlib from . import mesonlib
from .mesonlib import FileMode, Popen_safe from .mesonlib import FileMode, Popen_safe, listify, extract_as_list
from .dependencies import ExternalProgram from .dependencies import ExternalProgram
from .dependencies import InternalDependency, Dependency, DependencyException from .dependencies import InternalDependency, Dependency, DependencyException
from .interpreterbase import InterpreterBase from .interpreterbase import InterpreterBase
@ -264,8 +264,7 @@ class DependencyHolder(InterpreterObject):
return self.held_object.get_version() return self.held_object.get_version()
def pkgconfig_method(self, args, kwargs): def pkgconfig_method(self, args, kwargs):
if not isinstance(args, list): args = listify(args)
args = [args]
if len(args) != 1: if len(args) != 1:
raise InterpreterException('get_pkgconfig_variable takes exactly one argument.') raise InterpreterException('get_pkgconfig_variable takes exactly one argument.')
varname = args[0] varname = args[0]
@ -669,9 +668,7 @@ class CompilerHolder(InterpreterObject):
if not isinstance(nobuiltins, bool): if not isinstance(nobuiltins, bool):
raise InterpreterException('Type of no_builtin_args not a boolean.') raise InterpreterException('Type of no_builtin_args not a boolean.')
args = [] args = []
incdirs = kwargs.get('include_directories', []) incdirs = extract_as_list(kwargs, 'include_directories')
if not isinstance(incdirs, list):
incdirs = [incdirs]
for i in incdirs: for i in incdirs:
if not isinstance(i, IncludeDirsHolder): if not isinstance(i, IncludeDirsHolder):
raise InterpreterException('Include directories argument must be an include_directories object.') raise InterpreterException('Include directories argument must be an include_directories object.')
@ -688,8 +685,7 @@ class CompilerHolder(InterpreterObject):
def determine_dependencies(self, kwargs): def determine_dependencies(self, kwargs):
deps = kwargs.get('dependencies', None) deps = kwargs.get('dependencies', None)
if deps is not None: if deps is not None:
if not isinstance(deps, list): deps = listify(deps)
deps = [deps]
final_deps = [] final_deps = []
for d in deps: for d in deps:
try: try:
@ -1460,8 +1456,7 @@ class Interpreter(InterpreterBase):
raise InterpreterException('Module returned a value of unknown type.') raise InterpreterException('Module returned a value of unknown type.')
def process_new_values(self, invalues): def process_new_values(self, invalues):
if not isinstance(invalues, list): invalues = listify(invalues)
invalues = [invalues]
for v in invalues: for v in invalues:
if isinstance(v, (build.BuildTarget, build.CustomTarget, build.RunTarget)): if isinstance(v, (build.BuildTarget, build.CustomTarget, build.RunTarget)):
self.add_target(v.name, v) self.add_target(v.name, v)
@ -1541,19 +1536,12 @@ class Interpreter(InterpreterBase):
version = kwargs.get('version', self.project_version) version = kwargs.get('version', self.project_version)
if not isinstance(version, str): if not isinstance(version, str):
raise InterpreterException('Version must be a string.') raise InterpreterException('Version must be a string.')
incs = kwargs.get('include_directories', []) incs = extract_as_list(kwargs, 'include_directories')
if not isinstance(incs, list): libs = extract_as_list(kwargs, 'link_with')
incs = [incs] sources = extract_as_list(kwargs, 'sources')
libs = kwargs.get('link_with', [])
if not isinstance(libs, list):
libs = [libs]
sources = kwargs.get('sources', [])
if not isinstance(sources, list):
sources = [sources]
sources = self.source_strings_to_files(self.flatten(sources)) sources = self.source_strings_to_files(self.flatten(sources))
deps = self.flatten(kwargs.get('dependencies', [])) deps = self.flatten(kwargs.get('dependencies', []))
if not isinstance(deps, list): deps = listify(deps)
deps = [deps]
compile_args = mesonlib.stringlistify(kwargs.get('compile_args', [])) compile_args = mesonlib.stringlistify(kwargs.get('compile_args', []))
link_args = mesonlib.stringlistify(kwargs.get('link_args', [])) link_args = mesonlib.stringlistify(kwargs.get('link_args', []))
final_deps = [] final_deps = []
@ -1741,8 +1729,7 @@ class Interpreter(InterpreterBase):
return ConfigurationDataHolder() return ConfigurationDataHolder()
def parse_default_options(self, default_options): def parse_default_options(self, default_options):
if not isinstance(default_options, list): default_options = listify(default_options)
default_options = [default_options]
for option in default_options: for option in default_options:
if not isinstance(option, str): if not isinstance(option, str):
mlog.debug(option) mlog.debug(option)
@ -2288,12 +2275,8 @@ class Interpreter(InterpreterBase):
elif len(args) == 1: elif len(args) == 1:
if 'command' not in kwargs: if 'command' not in kwargs:
raise InterpreterException('Missing "command" keyword argument') raise InterpreterException('Missing "command" keyword argument')
all_args = kwargs['command'] all_args = extract_as_list(kwargs, 'command')
if not isinstance(all_args, list): deps = extract_as_list(kwargs, 'depends')
all_args = [all_args]
deps = kwargs.get('depends', [])
if not isinstance(deps, list):
deps = [deps]
else: else:
raise InterpreterException('Run_target needs at least one positional argument.') raise InterpreterException('Run_target needs at least one positional argument.')
@ -2344,8 +2327,7 @@ class Interpreter(InterpreterBase):
if isinstance(envlist, EnvironmentVariablesHolder): if isinstance(envlist, EnvironmentVariablesHolder):
env = envlist.held_object env = envlist.held_object
else: else:
if not isinstance(envlist, list): envlist = listify(envlist)
envlist = [envlist]
# Convert from array to environment object # Convert from array to environment object
env = EnvironmentVariablesHolder() env = EnvironmentVariablesHolder()
for e in envlist: for e in envlist:
@ -2374,9 +2356,7 @@ class Interpreter(InterpreterBase):
par = kwargs.get('is_parallel', True) par = kwargs.get('is_parallel', True)
if not isinstance(par, bool): if not isinstance(par, bool):
raise InterpreterException('Keyword argument is_parallel must be a boolean.') raise InterpreterException('Keyword argument is_parallel must be a boolean.')
cmd_args = kwargs.get('args', []) cmd_args = extract_as_list(kwargs, 'args')
if not isinstance(cmd_args, list):
cmd_args = [cmd_args]
for i in cmd_args: for i in cmd_args:
if not isinstance(i, (str, mesonlib.File, TargetHolder)): if not isinstance(i, (str, mesonlib.File, TargetHolder)):
raise InterpreterException('Command line arguments must be strings, files or targets.') raise InterpreterException('Command line arguments must be strings, files or targets.')
@ -2515,9 +2495,7 @@ class Interpreter(InterpreterBase):
if not isinstance(install_dir, str): if not isinstance(install_dir, str):
raise InvalidArguments('Keyword argument install_dir not a string.') raise InvalidArguments('Keyword argument install_dir not a string.')
if 'exclude_files' in kwargs: if 'exclude_files' in kwargs:
exclude = kwargs['exclude_files'] exclude = extract_as_list(kwargs, 'exclude_files')
if not isinstance(exclude, list):
exclude = [exclude]
for f in exclude: for f in exclude:
if not isinstance(f, str): if not isinstance(f, str):
raise InvalidArguments('Exclude argument not a string.') raise InvalidArguments('Exclude argument not a string.')
@ -2527,9 +2505,7 @@ class Interpreter(InterpreterBase):
else: else:
exclude_files = set() exclude_files = set()
if 'exclude_directories' in kwargs: if 'exclude_directories' in kwargs:
exclude = kwargs['exclude_directories'] exclude = extract_as_list(kwargs, 'exclude_directories')
if not isinstance(exclude, list):
exclude = [exclude]
for d in exclude: for d in exclude:
if not isinstance(d, str): if not isinstance(d, str):
raise InvalidArguments('Exclude argument not a string.') raise InvalidArguments('Exclude argument not a string.')
@ -2692,9 +2668,7 @@ different subdirectory.
if re.fullmatch('[_a-zA-Z][_0-9a-zA-Z]*', setup_name) is None: if re.fullmatch('[_a-zA-Z][_0-9a-zA-Z]*', setup_name) is None:
raise InterpreterException('Setup name may only contain alphanumeric characters.') raise InterpreterException('Setup name may only contain alphanumeric characters.')
try: try:
inp = kwargs.get('exe_wrapper', []) inp = extract_as_list(kwargs, 'exe_wrapper')
if not isinstance(inp, list):
inp = [inp]
exe_wrapper = [] exe_wrapper = []
for i in inp: for i in inp:
if hasattr(i, 'held_object'): if hasattr(i, 'held_object'):
@ -2836,8 +2810,7 @@ different subdirectory.
is_cross = False is_cross = False
try: try:
kw_src = self.flatten(kwargs['sources']) kw_src = self.flatten(kwargs['sources'])
if not isinstance(kw_src, list): kw_src = listify(kw_src)
kw_src = [kw_src]
except KeyError: except KeyError:
kw_src = [] kw_src = []
sources += kw_src sources += kw_src
@ -2845,12 +2818,9 @@ different subdirectory.
objs = self.flatten(kwargs.get('objects', [])) objs = self.flatten(kwargs.get('objects', []))
kwargs['dependencies'] = self.flatten(kwargs.get('dependencies', [])) kwargs['dependencies'] = self.flatten(kwargs.get('dependencies', []))
if 'extra_files' in kwargs: if 'extra_files' in kwargs:
ef = kwargs['extra_files'] ef = extract_as_list(kwargs, 'extra_files')
if not isinstance(ef, list):
ef = [ef]
kwargs['extra_files'] = self.source_strings_to_files(ef) kwargs['extra_files'] = self.source_strings_to_files(ef)
if not isinstance(objs, list): objs = listify(objs)
objs = [objs]
self.check_sources_exist(os.path.join(self.source_root, self.subdir), sources) self.check_sources_exist(os.path.join(self.source_root, self.subdir), sources)
if targetholder is ExecutableHolder: if targetholder is ExecutableHolder:
targetclass = build.Executable targetclass = build.Executable

@ -473,6 +473,26 @@ def replace_if_different(dst, dst_tmp):
else: else:
os.unlink(dst_tmp) os.unlink(dst_tmp)
def listify(*args):
'''
Returns a list with all args embedded in a list if they are not of type list.
This function preserves order.
'''
if len(args) == 1: # Special case with one single arg
return args[0] if type(args[0]) is list else [args[0]]
return [item if type(item) is list else [item] for item in args]
def extract_as_list(dict_object, *keys, pop = False):
'''
Extracts all values from given dict_object and listifies them.
'''
if pop:
return listify(*[dict_object.pop(key, []) for key in keys])
return listify(*[dict_object.get(key, []) for key in keys])
def typeslistify(item, types): def typeslistify(item, types):
''' '''
Ensure that type(@item) is one of @types or a Ensure that type(@item) is one of @types or a

@ -98,17 +98,12 @@ class GnomeModule(ExtensionModule):
cmd = ['glib-compile-resources', '@INPUT@'] cmd = ['glib-compile-resources', '@INPUT@']
source_dirs = kwargs.pop('source_dir', []) source_dirs, dependencies = mesonlib.extract_as_list(kwargs, 'source_dir', 'dependencies', pop=True)
if not isinstance(source_dirs, list):
source_dirs = [source_dirs]
if len(args) < 2: if len(args) < 2:
raise MesonException('Not enough arguments; the name of the resource ' raise MesonException('Not enough arguments; the name of the resource '
'and the path to the XML file are required') 'and the path to the XML file are required')
dependencies = kwargs.pop('dependencies', [])
if not isinstance(dependencies, list):
dependencies = [dependencies]
# Validate dependencies # Validate dependencies
for (ii, dep) in enumerate(dependencies): for (ii, dep) in enumerate(dependencies):
if hasattr(dep, 'held_object'): if hasattr(dep, 'held_object'):
@ -328,8 +323,7 @@ class GnomeModule(ExtensionModule):
cflags = OrderedSet() cflags = OrderedSet()
ldflags = OrderedSet() ldflags = OrderedSet()
gi_includes = OrderedSet() gi_includes = OrderedSet()
if not isinstance(deps, list): deps = mesonlib.listify(deps)
deps = [deps]
for dep in deps: for dep in deps:
if hasattr(dep, 'held_object'): if hasattr(dep, 'held_object'):
@ -464,17 +458,14 @@ class GnomeModule(ExtensionModule):
scan_command += ['--filelist=' + gir_filelist_filename] scan_command += ['--filelist=' + gir_filelist_filename]
if 'link_with' in kwargs: if 'link_with' in kwargs:
link_with = kwargs.pop('link_with') link_with = mesonlib.extract_as_list(kwargs, 'link_with', pop = True)
if not isinstance(link_with, list):
link_with = [link_with]
for link in link_with: for link in link_with:
scan_command += self._get_link_args(state, link.held_object, depends, scan_command += self._get_link_args(state, link.held_object, depends,
use_gir_args=True) use_gir_args=True)
if 'includes' in kwargs: if 'includes' in kwargs:
includes = kwargs.pop('includes') includes = mesonlib.extract_as_list(kwargs, 'includes', pop = True)
if not isinstance(includes, list):
includes = [includes]
for inc in includes: for inc in includes:
if hasattr(inc, 'held_object'): if hasattr(inc, 'held_object'):
inc = inc.held_object inc = inc.held_object
@ -515,17 +506,17 @@ class GnomeModule(ExtensionModule):
# FIXME: Linking directly to libasan is not recommended but g-ir-scanner # FIXME: Linking directly to libasan is not recommended but g-ir-scanner
# does not understand -f LDFLAGS. https://bugzilla.gnome.org/show_bug.cgi?id=783892 # does not understand -f LDFLAGS. https://bugzilla.gnome.org/show_bug.cgi?id=783892
# ldflags += compilers.sanitizer_link_args(sanitize) # ldflags += compilers.sanitizer_link_args(sanitize)
if kwargs.get('symbol_prefix'): if 'symbol_prefix' in kwargs:
sym_prefix = kwargs.pop('symbol_prefix') sym_prefix = kwargs.pop('symbol_prefix')
if not isinstance(sym_prefix, str): if not isinstance(sym_prefix, str):
raise MesonException('Gir symbol prefix must be str') raise MesonException('Gir symbol prefix must be str')
scan_command += ['--symbol-prefix=%s' % sym_prefix] scan_command += ['--symbol-prefix=%s' % sym_prefix]
if kwargs.get('identifier_prefix'): if 'identifier_prefix' in kwargs:
identifier_prefix = kwargs.pop('identifier_prefix') identifier_prefix = kwargs.pop('identifier_prefix')
if not isinstance(identifier_prefix, str): if not isinstance(identifier_prefix, str):
raise MesonException('Gir identifier prefix must be str') raise MesonException('Gir identifier prefix must be str')
scan_command += ['--identifier-prefix=%s' % identifier_prefix] scan_command += ['--identifier-prefix=%s' % identifier_prefix]
if kwargs.get('export_packages'): if 'export_packages' in kwargs:
pkgs = kwargs.pop('export_packages') pkgs = kwargs.pop('export_packages')
if isinstance(pkgs, str): if isinstance(pkgs, str):
scan_command += ['--pkg-export=%s' % pkgs] scan_command += ['--pkg-export=%s' % pkgs]
@ -534,9 +525,7 @@ class GnomeModule(ExtensionModule):
else: else:
raise MesonException('Gir export packages must be str or list') raise MesonException('Gir export packages must be str or list')
deps = kwargs.pop('dependencies', []) deps = mesonlib.extract_as_list(kwargs, 'dependencies', pop = True)
if not isinstance(deps, list):
deps = [deps]
deps = (girtarget.get_all_link_deps() + girtarget.get_external_deps() + deps = (girtarget.get_all_link_deps() + girtarget.get_external_deps() +
deps) deps)
# Need to recursively add deps on GirTarget sources from our # Need to recursively add deps on GirTarget sources from our
@ -593,9 +582,7 @@ class GnomeModule(ExtensionModule):
for i in gi_includes: for i in gi_includes:
scan_command += ['--add-include-path=%s' % i] scan_command += ['--add-include-path=%s' % i]
inc_dirs = kwargs.pop('include_directories', []) inc_dirs = mesonlib.extract_as_list(kwargs, 'include_directories', pop = True)
if not isinstance(inc_dirs, list):
inc_dirs = [inc_dirs]
for incd in inc_dirs: for incd in inc_dirs:
if not isinstance(incd.held_object, (str, build.IncludeDirs)): if not isinstance(incd.held_object, (str, build.IncludeDirs)):
raise MesonException( raise MesonException(
@ -618,7 +605,7 @@ class GnomeModule(ExtensionModule):
scankwargs = {'output': girfile, scankwargs = {'output': girfile,
'command': scan_command, 'command': scan_command,
'depends': depends} 'depends': depends}
if kwargs.get('install'): if 'install' in kwargs:
scankwargs['install'] = kwargs['install'] scankwargs['install'] = kwargs['install']
scankwargs['install_dir'] = kwargs.get('install_dir_gir', scankwargs['install_dir'] = kwargs.get('install_dir_gir',
os.path.join(state.environment.get_datadir(), 'gir-1.0')) os.path.join(state.environment.get_datadir(), 'gir-1.0'))
@ -636,7 +623,7 @@ class GnomeModule(ExtensionModule):
'output': typelib_output, 'output': typelib_output,
'command': typelib_cmd, 'command': typelib_cmd,
} }
if kwargs.get('install'): if 'install' in kwargs:
typelib_kwargs['install'] = kwargs['install'] typelib_kwargs['install'] = kwargs['install']
typelib_kwargs['install_dir'] = kwargs.get('install_dir_typelib', typelib_kwargs['install_dir'] = kwargs.get('install_dir_typelib',
os.path.join(state.environment.get_libdir(), 'girepository-1.0')) os.path.join(state.environment.get_libdir(), 'girepository-1.0'))
@ -759,9 +746,7 @@ This will become a hard error in the future.''')
if mode not in VALID_MODES: if mode not in VALID_MODES:
raise MesonException('gtkdoc: Mode {} is not a valid mode: {}'.format(mode, VALID_MODES)) raise MesonException('gtkdoc: Mode {} is not a valid mode: {}'.format(mode, VALID_MODES))
src_dirs = kwargs['src_dir'] src_dirs = mesonlib.extract_as_list(kwargs, 'src_dir')
if not isinstance(src_dirs, list):
src_dirs = [src_dirs]
header_dirs = [] header_dirs = []
for src_dir in src_dirs: for src_dir in src_dirs:
if hasattr(src_dir, 'held_object'): if hasattr(src_dir, 'held_object'):
@ -806,9 +791,7 @@ This will become a hard error in the future.''')
def _get_build_args(self, kwargs, state): def _get_build_args(self, kwargs, state):
args = [] args = []
cflags, ldflags, gi_includes = self._get_dependencies_flags(kwargs.get('dependencies', []), state, include_rpath=True) cflags, ldflags, gi_includes = self._get_dependencies_flags(kwargs.get('dependencies', []), state, include_rpath=True)
inc_dirs = kwargs.get('include_directories', []) inc_dirs = mesonlib.extract_as_list(kwargs, 'include_directories')
if not isinstance(inc_dirs, list):
inc_dirs = [inc_dirs]
for incd in inc_dirs: for incd in inc_dirs:
if not isinstance(incd.held_object, (str, build.IncludeDirs)): if not isinstance(incd.held_object, (str, build.IncludeDirs)):
raise MesonException( raise MesonException(
@ -839,9 +822,7 @@ This will become a hard error in the future.''')
if kwarg_name not in kwargs: if kwarg_name not in kwargs:
return [] return []
new_args = kwargs[kwarg_name] new_args = mesonlib.extract_as_list(kwargs, kwarg_name)
if not isinstance(new_args, list):
new_args = [new_args]
args = [] args = []
for i in new_args: for i in new_args:
if expend_file_state and isinstance(i, mesonlib.File): if expend_file_state and isinstance(i, mesonlib.File):
@ -1200,12 +1181,8 @@ G_END_DECLS'''
@staticmethod @staticmethod
def _vapi_args_to_command(prefix, variable, kwargs, accept_vapi=False): def _vapi_args_to_command(prefix, variable, kwargs, accept_vapi=False):
arg_list = kwargs.get(variable) arg_list = mesonlib.extract_as_list(kwargs, variable)
if not arg_list:
return []
ret = [] ret = []
if not isinstance(arg_list, list):
arg_list = [arg_list]
for arg in arg_list: for arg in arg_list:
if not isinstance(arg, str): if not isinstance(arg, str):
types = 'strings' + ' or InternalDependencys' if accept_vapi else '' types = 'strings' + ' or InternalDependencys' if accept_vapi else ''
@ -1224,9 +1201,7 @@ G_END_DECLS'''
arg_list = kwargs.get('packages') arg_list = kwargs.get('packages')
if not arg_list: if not arg_list:
return [], [], [], [] return [], [], [], []
if not isinstance(arg_list, list): arg_list = mesonlib.listify(arg_list)
arg_list = [arg_list]
vapi_depends = [] vapi_depends = []
vapi_packages = [] vapi_packages = []
vapi_includes = [] vapi_includes = []
@ -1300,12 +1275,10 @@ G_END_DECLS'''
cmd += pkg_cmd cmd += pkg_cmd
cmd += ['--metadatadir=' + source_dir] cmd += ['--metadatadir=' + source_dir]
inputs = kwargs.get('sources') if 'sources' not in kwargs:
if not inputs:
raise MesonException('sources are required to generate the vapi file') raise MesonException('sources are required to generate the vapi file')
if not isinstance(inputs, list): inputs = mesonlib.extract_as_list(kwargs, 'sources')
inputs = [inputs]
link_with = [] link_with = []
for i in inputs: for i in inputs:

@ -108,8 +108,7 @@ class PkgConfigModule(ExtensionModule):
ofile.write('\n') ofile.write('\n')
def process_libs(self, libs): def process_libs(self, libs):
if not isinstance(libs, list): libs = mesonlib.listify(libs)
libs = [libs]
processed_libs = [] processed_libs = []
for l in libs: for l in libs:
if hasattr(l, 'held_object'): if hasattr(l, 'held_object'):

@ -15,7 +15,7 @@
import os import os
from .. import mlog from .. import mlog
from .. import build from .. import build
from ..mesonlib import MesonException, Popen_safe from ..mesonlib import MesonException, Popen_safe, extract_as_list
from ..dependencies import Qt4Dependency from ..dependencies import Qt4Dependency
from . import ExtensionModule from . import ExtensionModule
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
@ -99,21 +99,8 @@ class Qt4Module(ExtensionModule):
@permittedKwargs({'moc_headers', 'moc_sources', 'ui_files', 'qresources', 'method'}) @permittedKwargs({'moc_headers', 'moc_sources', 'ui_files', 'qresources', 'method'})
def preprocess(self, state, args, kwargs): def preprocess(self, state, args, kwargs):
rcc_files = kwargs.pop('qresources', []) rcc_files, ui_files, moc_headers, moc_sources, sources \
if not isinstance(rcc_files, list): = extract_as_list(kwargs, 'qresources', 'ui_files', 'moc_headers', 'moc_sources', 'sources', pop = True)
rcc_files = [rcc_files]
ui_files = kwargs.pop('ui_files', [])
if not isinstance(ui_files, list):
ui_files = [ui_files]
moc_headers = kwargs.pop('moc_headers', [])
if not isinstance(moc_headers, list):
moc_headers = [moc_headers]
moc_sources = kwargs.pop('moc_sources', [])
if not isinstance(moc_sources, list):
moc_sources = [moc_sources]
sources = kwargs.pop('sources', [])
if not isinstance(sources, list):
sources = [sources]
sources += args[1:] sources += args[1:]
method = kwargs.get('method', 'auto') method = kwargs.get('method', 'auto')
self._detect_tools(state.environment, method) self._detect_tools(state.environment, method)

@ -15,7 +15,7 @@
import os import os
from .. import mlog from .. import mlog
from .. import build from .. import build
from ..mesonlib import MesonException, Popen_safe from ..mesonlib import MesonException, Popen_safe, extract_as_list
from ..dependencies import Qt5Dependency from ..dependencies import Qt5Dependency
from . import ExtensionModule from . import ExtensionModule
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
@ -105,21 +105,8 @@ class Qt5Module(ExtensionModule):
@permittedKwargs({'moc_headers', 'moc_sources', 'ui_files', 'qresources', 'method'}) @permittedKwargs({'moc_headers', 'moc_sources', 'ui_files', 'qresources', 'method'})
def preprocess(self, state, args, kwargs): def preprocess(self, state, args, kwargs):
rcc_files = kwargs.pop('qresources', []) rcc_files, ui_files, moc_headers, moc_sources, sources \
if not isinstance(rcc_files, list): = extract_as_list(kwargs, 'qresources', 'ui_files', 'moc_headers', 'moc_sources', 'sources', pop = True)
rcc_files = [rcc_files]
ui_files = kwargs.pop('ui_files', [])
if not isinstance(ui_files, list):
ui_files = [ui_files]
moc_headers = kwargs.pop('moc_headers', [])
if not isinstance(moc_headers, list):
moc_headers = [moc_headers]
moc_sources = kwargs.pop('moc_sources', [])
if not isinstance(moc_sources, list):
moc_sources = [moc_sources]
sources = kwargs.pop('sources', [])
if not isinstance(sources, list):
sources = [sources]
sources += args[1:] sources += args[1:]
method = kwargs.get('method', 'auto') method = kwargs.get('method', 'auto')
self._detect_tools(state.environment, method) self._detect_tools(state.environment, method)

@ -73,9 +73,7 @@ class SimdModule(ExtensionModule):
} }
lib_kwargs.update(basic_kwargs) lib_kwargs.update(basic_kwargs)
langarg_key = compiler.get_language() + '_args' langarg_key = compiler.get_language() + '_args'
old_lang_args = lib_kwargs.get(langarg_key, []) old_lang_args = mesonlib.extract_as_list(lib_kwargs, langarg_key)
if not isinstance(old_lang_args, list):
old_lang_args = [old_lang_args]
all_lang_args = old_lang_args + args all_lang_args = old_lang_args + args
lib_kwargs[langarg_key] = all_lang_args lib_kwargs[langarg_key] = all_lang_args
result.append(interpreter.func_static_lib(None, [libname], lib_kwargs)) result.append(interpreter.func_static_lib(None, [libname], lib_kwargs))

@ -16,7 +16,7 @@ import os
from .. import mlog from .. import mlog
from .. import mesonlib, dependencies, build from .. import mesonlib, dependencies, build
from ..mesonlib import MesonException from ..mesonlib import MesonException, extract_as_list
from . import get_include_args from . import get_include_args
from . import ModuleReturnValue from . import ModuleReturnValue
from . import ExtensionModule from . import ExtensionModule
@ -35,9 +35,7 @@ class WindowsModule(ExtensionModule):
comp = self.detect_compiler(state.compilers) comp = self.detect_compiler(state.compilers)
extra_args = mesonlib.stringlistify(kwargs.get('args', [])) extra_args = mesonlib.stringlistify(kwargs.get('args', []))
inc_dirs = kwargs.pop('include_directories', []) inc_dirs = extract_as_list(kwargs, 'include_directories', pop = True)
if not isinstance(inc_dirs, list):
inc_dirs = [inc_dirs]
for incd in inc_dirs: for incd in inc_dirs:
if not isinstance(incd.held_object, (str, build.IncludeDirs)): if not isinstance(incd.held_object, (str, build.IncludeDirs)):
raise MesonException('Resource include dirs should be include_directories().') raise MesonException('Resource include dirs should be include_directories().')

Loading…
Cancel
Save