Repository: mesonbuild/meson

Issue:
meson >=0.46.0 fails to configure when cc.has_header and/or cc.has_function called more than once with the same argument
hi

actually, not sure whether this is a problem with glib or meson, so
cross posting.

meson >=0.46.0 is failing the configuration step of (at least)
glib-2.56.1 and 2.57.1 (the ones that I have tested).

The reason seems to be calling cc.has_header and/or cc.has_function
more than once with the same argument in meson.build [1].

termios.h occurs twice in the definition of the "headers" variable
(this definitely looks like a typo in glib's meson.build) and this crashes
the meson run upon the second "cc.has_header(termios.h)" call in the
following "foreach h : headers" loop.

Same thing for gmtime_r which occurs twice in the "functions" variable
definition (another typo?) and crashes the meson run in the following
"foreach f : functions" loop upon the second
cc.has_function(gmtime_r)" call

Similarly, cc.has_header('alloca.h') is called twice: a first time in
the "foreach h : headers" loop and a second time at line 1350 (of
2.57.1's meson.build [1]); same for cc.has_header('sys/types.h'),
called the first time in the "foreach h : headers" loop and the second
time at line 1354 (of 2.57.1's meson.build [1]).

Note that meson 0.45.1 gives no errors (everything else unchanged).

To better explain what I mean, the following hack fixes things for me
for both glib-2.56.1 and glib-2.57.1 (patch shown for 2.57.1's
meson.build [1]):

diff -c ./meson.build.MESON_0_46_FIX ./meson.build
*** ./meson.build.MESON_0_46_FIX	2018-05-23 18:04:02.934965026 +0200
--- ./meson.build	2018-05-23 18:04:02.954965106 +0200
***************
*** 207,213 ****
    'string.h',
    'strings.h',
    'memory.h',
-   'alloca.h',
    'locale.h',
    'xlocale.h',
    'float.h',
--- 207,212 ----
***************
*** 235,248 ****
    'sys/mntctl.h',
    'fstab.h',
    'linux/magic.h',
-   'termios.h',
    'dirent.h', # MSC does not come with this by default
    'sys/time.h', # MSC does not come with this by default
    'sys/times.h',
    'sys/wait.h',
    'unistd.h',
    'values.h',
-   'sys/types.h',
    'sys/uio.h',
    'sys/mkdev.h',
    'sys/mount.h',
--- 234,245 ----
***************
*** 399,405 ****
    'getvfsstat',
    'fallocate',
    'localtime_r',
-   'gmtime_r',
    'getpwuid_r',
    'getgrgid_r',
    'prlimit',
--- 396,401 ----


[1] https://github.com/GNOME/glib/blob/master/meson.build

ciao
gabriele




Discussion:
What's the backtrace outputted by Meson when this happens?
here it is:


++ meson --prefix=/opt/stow.d/versions/glib-2.57.1/usr --libdir=/opt/stow.d/versions/glib-2.57.1/usr/lib64 -Dwith-pcre=system -Dwith-docs=no -Dselinux=false .build /home/balducci/tmp/install-us-d/glib-2.56.1.d/glib-2.57.1
Traceback (most recent call last):
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/compilers/compilers.py", line 799, in compile
    raise StopIteration
StopIteration

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/mesonmain.py", line 364, in run
    app.generate()
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/mesonmain.py", line 135, in generate
    self._generate(env)
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/mesonmain.py", line 186, in _generate
    intr.run()
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreter.py", line 3261, in run
    super().run()
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreterbase.py", line 215, in run
    self.evaluate_codeblock(self.ast, start=1)
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreterbase.py", line 239, in evaluate_codeblock
    raise e
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreterbase.py", line 231, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreterbase.py", line 274, in evaluate_statement
    return self.evaluate_foreach(cur)
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreterbase.py", line 448, in evaluate_foreach
    self.evaluate_codeblock(node.block)
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreterbase.py", line 239, in evaluate_codeblock
    raise e
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreterbase.py", line 231, in evaluate_codeblock
    self.evaluate_statement(cur)
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreterbase.py", line 254, in evaluate_statement
    return self.evaluate_if(cur)
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreterbase.py", line 301, in evaluate_if
    result = self.evaluate_statement(i.condition)
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreterbase.py", line 248, in evaluate_statement
    return self.method_call(cur)
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreterbase.py", line 538, in method_call
    return obj.method_call(method_name, args, kwargs)
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreterbase.py", line 140, in method_call
    return method(args, kwargs)
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreterbase.py", line 115, in wrapped
    return f(obj, args, kwargs)
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/interpreter.py", line 1163, in has_header_method
    haz = self.compiler.has_header(hname, prefix, self.environment, extra_args, deps)
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/compilers/c.py", line 280, in has_header
    dependencies, 'preprocess')
  File "/usr/python3/site_python3/lib64/meson.egg/mesonbuild/compilers/c.py", line 339, in compiles
    return p.returncode == 0
  File "/usr/python3/bin/../../../opt/stow.d/stow/python3/usr/python3/bin/../lib64/python3.7/contextlib.py", line 119, in __exit__
    next(self.gen)
RuntimeError: generator raised StopIteration
The Meson build system
Version: 0.46.1
Source dir: /home/balducci/tmp/install-us-d/glib-2.56.1.d/glib-2.57.1
Build dir: /home/balducci/tmp/install-us-d/glib-2.56.1.d/glib-2.57.1/.build
Build type: native build
WARNING: Unknown command line options: "with-docs, with-pcre"
This will become a hard error in a future Meson release.
Project name: glib
Native C compiler: gcc -m64 (gcc 8.1.0 "gcc (GCC) 8.1.0")
Appending CFLAGS from environment: '-I/usr/python3/include  -I/usr/Xorg/include'
Appending LDFLAGS from environment: '-L/usr/python3/lib64 -L/usr/Xorg/lib64 '
Appending CPPFLAGS from environment: '-I/usr/python3/include '
Native C++ compiler: g++ -m64 (gcc 8.1.0 "g++ (GCC) 8.1.0")
Appending CXXFLAGS from environment: '-I/usr/python3/include  -I/usr/Xorg/include'
Appending LDFLAGS from environment: '-L/usr/python3/lib64 -L/usr/Xorg/lib64 '
Appending CPPFLAGS from environment: '-I/usr/python3/include '
Build machine cpu family: x86_64
Build machine cpu: x86_64
Compiler for C supports arguments -fno-strict-aliasing: YES
Checking if "GNU C visibility attributes test" compiles: YES
Compiler for C supports arguments -fvisibility=hidden: YES
Has header "stdlib.h": YES
Has header "string.h": YES
Has header "strings.h": YES
Has header "memory.h": YES
Has header "alloca.h": YES
Has header "locale.h": YES
Has header "xlocale.h": YES
Has header "float.h": YES
Has header "limits.h": YES
Has header "pwd.h": YES
Has header "grp.h": YES
Has header "poll.h": YES
Has header "termios.h": YES
Has header "sys/param.h": YES
Has header "sys/resource.h": YES
Has header "mach/mach_time.h": NO
Has header "sys/select.h": YES
Has header "stdint.h": YES
Has header "inttypes.h": YES
Has header "sched.h": YES
Has header "malloc.h": YES
Has header "sys/vfs.h": YES
Has header "sys/vmount.h": NO
Has header "sys/statfs.h": YES
Has header "sys/statvfs.h": YES
Has header "sys/filio.h": NO
Has header "mntent.h": YES
Has header "sys/mnttab.h": NO
Has header "sys/vfstab.h": NO
Has header "sys/mntctl.h": NO
Has header "fstab.h": YES
Has header "linux/magic.h": YES


Weird that I don't hit that exception here, but there is clearly a meson bug.

As a side note, this makes me wonder if we could use that cache to make meson print warning when a project does the same check twice. That could help projects like glib to remove duplicated code.
This is due to Python 3.7 and its change re StopIteration: https://www.python.org/dev/peps/pep-0479

Resolving patch:
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -796,7 +796,7 @@ def compile(self, code, extra_args=None, mode='link', want_output=False):
                 mlog.debug('Cached compiler stdout:\n', p.stdo)
                 mlog.debug('Cached compiler stderr:\n', p.stde)
                 yield p
-                raise StopIteration
+                return
         try:
             with tempfile.TemporaryDirectory() as tmpdirname:
                 if isinstance(code, str):


Test patch: