add is_system kwarg to dependency

Also adds the is_system and as_system methods to
the dependency holder.
pull/5953/head
Daniel Mensinger 5 years ago
parent f508b4cf80
commit 8593506b7b
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 28
      mesonbuild/dependencies/base.py
  2. 30
      mesonbuild/interpreter.py

@ -104,6 +104,14 @@ class Dependency:
return methods return methods
@classmethod
def _process_is_system_kw(cls, kwargs):
if 'is_system' not in kwargs:
return False
if not isinstance(kwargs['is_system'], bool):
raise DependencyException('The is_system kwarg must be a boolean type')
return kwargs['is_system']
def __init__(self, type_name, kwargs): def __init__(self, type_name, kwargs):
self.name = "null" self.name = "null"
self.version = None self.version = None
@ -117,6 +125,7 @@ class Dependency:
self.raw_link_args = None self.raw_link_args = None
self.sources = [] self.sources = []
self.methods = self._process_method_kw(kwargs) self.methods = self._process_method_kw(kwargs)
self.is_system = self._process_is_system_kw(kwargs)
self.ext_deps = [] # type: List[Dependency] self.ext_deps = [] # type: List[Dependency]
def __repr__(self): def __repr__(self):
@ -124,7 +133,21 @@ class Dependency:
return s.format(self.__class__.__name__, self.name, self.is_found) return s.format(self.__class__.__name__, self.name, self.is_found)
def get_compile_args(self): def get_compile_args(self):
return self.compile_args if not self.is_system:
return self.compile_args
system_args = []
for i in self.compile_args:
if i.startswith('-I') or i.startswith('/I'):
# -isystem and -idirafter, both mark directories as system
# directories. However, both affect the search oder, which
# can lead to nasty bugs with -isystem:
# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70129
system_args += ['-idirafter' + i[2:]]
else:
system_args += [i]
return system_args
def get_link_args(self, raw=False): def get_link_args(self, raw=False):
if raw and self.raw_link_args is not None: if raw and self.raw_link_args is not None:
@ -152,6 +175,9 @@ class Dependency:
else: else:
return 'unknown' return 'unknown'
def get_is_system(self) -> bool:
return self.is_system
def get_exe_args(self, compiler): def get_exe_args(self, compiler):
return [] return []

@ -34,13 +34,12 @@ from .interpreterbase import ObjectHolder
from .modules import ModuleReturnValue from .modules import ModuleReturnValue
from .cmake import CMakeInterpreter from .cmake import CMakeInterpreter
from pathlib import Path from pathlib import Path, PurePath
import os, shutil, uuid import os, shutil, uuid
import re, shlex import re, shlex, copy
import subprocess import subprocess
from collections import namedtuple from collections import namedtuple
from itertools import chain from itertools import chain
from pathlib import PurePath
import functools import functools
from typing import Sequence, List, Union, Optional, Dict, Any from typing import Sequence, List, Union, Optional, Dict, Any
@ -413,6 +412,8 @@ class DependencyHolder(InterpreterObject, ObjectHolder):
'get_configtool_variable': self.configtool_method, 'get_configtool_variable': self.configtool_method,
'get_variable': self.variable_method, 'get_variable': self.variable_method,
'partial_dependency': self.partial_dependency_method, 'partial_dependency': self.partial_dependency_method,
'is_system': self.is_system_method,
'as_system': self.as_system_method,
}) })
def found(self): def found(self):
@ -474,6 +475,27 @@ class DependencyHolder(InterpreterObject, ObjectHolder):
def variable_method(self, args, kwargs): def variable_method(self, args, kwargs):
return self.held_object.get_variable(**kwargs) return self.held_object.get_variable(**kwargs)
@FeatureNew('dep.is_system', '0.52.0')
@noPosargs
@permittedKwargs({})
def is_system_method(self, args, kwargs):
return self.held_object.get_is_system()
@FeatureNew('dep.as_system', '0.52.0')
@permittedKwargs({})
def as_system_method(self, args, kwargs):
args = listify(args)
new_is_system = True
if len(args) > 1:
raise InterpreterException('as_system takes only one optional value')
if len(args) == 1:
if not isinstance(args[0], bool):
raise InterpreterException('as_system takes only a boolean value')
new_is_system = args[0]
new_dep = copy.deepcopy(self.held_object)
new_dep.is_system = new_is_system
return DependencyHolder(new_dep, self.subproject)
class ExternalProgramHolder(InterpreterObject, ObjectHolder): class ExternalProgramHolder(InterpreterObject, ObjectHolder):
def __init__(self, ep): def __init__(self, ep):
InterpreterObject.__init__(self) InterpreterObject.__init__(self)
@ -1998,6 +2020,7 @@ permitted_kwargs = {'add_global_arguments': {'language', 'native'},
'version', 'version',
'private_headers', 'private_headers',
'cmake_args', 'cmake_args',
'is_system',
}, },
'declare_dependency': {'include_directories', 'declare_dependency': {'include_directories',
'link_with', 'link_with',
@ -3049,6 +3072,7 @@ external dependencies (including libraries) must go to "dependencies".''')
elif name == 'openmp': elif name == 'openmp':
FeatureNew('OpenMP Dependency', '0.46.0').use(self.subproject) FeatureNew('OpenMP Dependency', '0.46.0').use(self.subproject)
@FeatureNewKwargs('dependency', '0.52.0', ['is_system'])
@FeatureNewKwargs('dependency', '0.50.0', ['not_found_message', 'cmake_module_path', 'cmake_args']) @FeatureNewKwargs('dependency', '0.50.0', ['not_found_message', 'cmake_module_path', 'cmake_args'])
@FeatureNewKwargs('dependency', '0.49.0', ['disabler']) @FeatureNewKwargs('dependency', '0.49.0', ['disabler'])
@FeatureNewKwargs('dependency', '0.40.0', ['method']) @FeatureNewKwargs('dependency', '0.40.0', ['method'])

Loading…
Cancel
Save