Repository: mesonbuild/meson

Issue:
"generator doesn't stop" building harfbuzz in MSYS2/MinGW32 on Win7, but works on Win10
**Describe the bug**
I'm using the [media-autobuild suite](https://github.com/m-ab-s/media-autobuild_suite/) (a set of batch and shell scripts which keeps an MSYS2 envirponment up-to-date before building software) to build several audio / video tools, up to an ffmpeg combining previously built libraries of different codecs.
One of the used libraries is harfbuzz, which MABS builds using meson. This worked regularly, even a few weeks ago, but suddenly it started failing (possibly after an MSYS2 update) on one PC which still runs Windows 7, even after completely re-installing MSYS2 and MinGW, but works with the same set of host software on another PC running Windows 10.
There are other projects (e.g. dav1d) which are still built successfully using meson.

**To Reproduce**
[logs.zip](https://github.com/mesonbuild/meson/files/5501015/logs.zip) collected by MABS, I added some possibly meson specific files (most interesting logs will be in harfbuzz-git/build-32bit).

I am not able to produce a minimum source to reproduce this issue, because I am not a C/C++ developer, only a user of the media-autobuild suite. So I can only hope that the logs with the stack trace help to at least guess what may cause this issue, and to learn what it even means, to support the MABS team finding a possible solution.

**Expected behavior**
Prepare and run compilation, as it used to work a few weeks ago.

**system parameters**
* Windows 7 SP1 German, MSYS2/MinGW
* Python 3.8.6-5 provided by MSYS2
* meson 0.56.0-1 provided by MSYS2
* ninja 1.10.1-1 provided by MSYS2


Discussion:
That error message does not come from Meson but somewhere inside Python's stdlib. I have no idea what could be causing that and neither does Google (searching for the error message got zero relevant hits, which is unusual). Given that Windows 7 is officially no longer supported by Microsoft, I doubt anyone on the Meson team has the time to debug this. Sorry.

The only thing I can recommend is that you try to build your project with an older release. If that breaks, then the issue is somewhere else. If it works, then you might be able to find the actual breaking commit using Git bisection. If that points to something obvious, then this might be fixable.
Logs:

```python
  File "E:/MABS/msys64/mingw32/lib/python3.8/site-packages/mesonbuild/compilers/mixins/clike.py", line 610, in sizeof
    res = self.run(t.format(**fargs), env, extra_args=extra_args,
  File "E:/MABS/msys64/mingw32/lib/python3.8/site-packages/mesonbuild/compilers/mixins/clike.py", line 486, in run
    return compilers.RunResult(False)
  File "E:/MABS/msys64/mingw32/lib/python3.8/contextlib.py", line 120, in __exit__
    next(self.gen)
  File "E:/MABS/msys64/mingw32/lib/python3.8/site-packages/mesonbuild/compilers/compilers.py", line 1181, in _build_wrapper
    yield r
  File "E:/MABS/msys64/mingw32/lib/python3.8/contextlib.py", line 124, in __exit__
    raise RuntimeError("generator didn't stop")
RuntimeError: generator didn't stop
```

This mainly means a contextmanager generator yielded more than once:

```python
from contextlib import contextmanager

@contextmanager
def foo():
    yield
    yield

with foo():
    pass
```

But I don't see how that's possible in the current code, so not sure... :/ (maybe a MSYS2 problem...)
It's a meson bug: https://github.com/mesonbuild/meson/blob/b6dc4d5e5c6e838de0b52e62d982ba2547eb366d/mesonbuild/compilers/compilers.py#L788

tempfile.TemporaryDirectory will `__exit__` and throw an error because the directory isn't empty which makes the genereator yield a second time, leading to the above error.

Resolving patch:
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -785,7 +785,7 @@ def compile(self, code: 'mesonlib.FileOrString',
             # On Windows antivirus programs and the like hold on to files so
             # they can't be deleted. There's not much to do in this case. Also,
             # catch OSError because the directory is then no longer empty.
-            yield None
+            return
 
     @contextlib.contextmanager
     def cached_compile(self, code: str, cdata: coredata.CoreData, *,


Test patch: