aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/compilers
diff options
context:
space:
mode:
Diffstat (limited to 'mesonbuild/compilers')
-rw-r--r--mesonbuild/compilers/compilers.py18
-rw-r--r--mesonbuild/compilers/d.py9
-rw-r--r--mesonbuild/compilers/mixins/gnu.py9
-rw-r--r--mesonbuild/compilers/mixins/visualstudio.py12
4 files changed, 41 insertions, 7 deletions
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index b79fa41..ac74fc3 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -420,7 +420,7 @@ class CompilerArgs(list):
# Arg prefixes that override by prepending instead of appending
prepend_prefixes = ('-I', '-L')
# Arg prefixes and args that must be de-duped by returning 2
- dedup2_prefixes = ('-I', '-L', '-D', '-U')
+ dedup2_prefixes = ('-I', '-isystem', '-L', '-D', '-U')
dedup2_suffixes = ()
dedup2_args = ()
# Arg prefixes and args that must be de-duped by returning 1
@@ -548,6 +548,22 @@ class CompilerArgs(list):
# Last occurrence of a library
new.insert(group_end + 1, '-Wl,--end-group')
new.insert(group_start, '-Wl,--start-group')
+ # Remove system/default include paths added with -isystem
+ if hasattr(self.compiler, 'get_default_include_dirs'):
+ default_dirs = self.compiler.get_default_include_dirs()
+ bad_idx_list = []
+ for i, each in enumerate(new):
+ # Remove the -isystem and the path if the path is a dafault path
+ if (each == '-isystem' and
+ i < (len(new) - 1) and
+ new[i + 1] in default_dirs):
+ bad_idx_list += [i, i + 1]
+ elif each.startswith('-isystem=') and each[9:] in default_dirs:
+ bad_idx_list += [i]
+ elif each.startswith('-isystem') and each[8:] in default_dirs:
+ bad_idx_list += [i]
+ for i in reversed(bad_idx_list):
+ new.pop(i)
return self.compiler.unix_args_to_native(new)
def append_direct(self, arg):
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py
index 5e0c173..346f18e 100644
--- a/mesonbuild/compilers/d.py
+++ b/mesonbuild/compilers/d.py
@@ -285,7 +285,14 @@ class DmdLikeCompilerMixin:
if arg.startswith('-isystem='):
dcargs.append('-I=' + arg[9:])
else:
- dcargs.append('-I')
+ dcargs.append('-I' + arg[8:])
+ continue
+ elif arg.startswith('-idirafter'):
+ # same as -isystem, but appends the path instead
+ if arg.startswith('-idirafter='):
+ dcargs.append('-I=' + arg[11:])
+ else:
+ dcargs.append('-I' + arg[10:])
continue
elif arg.startswith('-L/') or arg.startswith('-L./'):
# we need to handle cases where -L is set by e.g. a pkg-config
diff --git a/mesonbuild/compilers/mixins/gnu.py b/mesonbuild/compilers/mixins/gnu.py
index 998b86c..f4ce5b9 100644
--- a/mesonbuild/compilers/mixins/gnu.py
+++ b/mesonbuild/compilers/mixins/gnu.py
@@ -84,14 +84,13 @@ gnu_color_args = {
} # type: typing.Dict[str, typing.List[str]]
-# TODO: The result from calling compiler should be cached. So that calling this
-# function multiple times don't add latency.
-def gnulike_default_include_dirs(compiler: typing.List[str], lang: str) -> typing.List[str]:
+@functools.lru_cache(maxsize=None)
+def gnulike_default_include_dirs(compiler: typing.Tuple[str], lang: str) -> typing.List[str]:
if lang == 'cpp':
lang = 'c++'
env = os.environ.copy()
env["LC_ALL"] = 'C'
- cmd = compiler + ['-x{}'.format(lang), '-E', '-v', '-']
+ cmd = list(compiler) + ['-x{}'.format(lang), '-E', '-v', '-']
p = subprocess.Popen(
cmd,
stdin=subprocess.DEVNULL,
@@ -171,7 +170,7 @@ class GnuLikeCompiler(metaclass=abc.ABCMeta):
return gnulike_instruction_set_args.get(instruction_set, None)
def get_default_include_dirs(self) -> typing.List[str]:
- return gnulike_default_include_dirs(self.exelist, self.language)
+ return gnulike_default_include_dirs(tuple(self.exelist), self.language)
@abc.abstractmethod
def openmp_flags(self) -> typing.List[str]:
diff --git a/mesonbuild/compilers/mixins/visualstudio.py b/mesonbuild/compilers/mixins/visualstudio.py
index 48a2229..9fddbb4 100644
--- a/mesonbuild/compilers/mixins/visualstudio.py
+++ b/mesonbuild/compilers/mixins/visualstudio.py
@@ -228,6 +228,18 @@ class VisualStudioLikeCompiler(metaclass=abc.ABCMeta):
continue
else:
i = name + '.lib'
+ elif i.startswith('-isystem'):
+ # just use /I for -isystem system include path s
+ if i.startswith('-isystem='):
+ i = '/I' + i[9:]
+ else:
+ i = '/I' + i[8:]
+ elif i.startswith('-idirafter'):
+ # same as -isystem, but appends the path instead
+ if i.startswith('-idirafter='):
+ i = '/I' + i[11:]
+ else:
+ i = '/I' + i[10:]
# -pthread in link flags is only used on Linux
elif i == '-pthread':
continue