da-viper wrote:

>  If we pass in an output file, _compiler_supports shouldn't muck with it, and 
> trust that the caller is in charge.

I agree with this, also the way `_compiler_supports` currently works reuses the 
same `OnDiskTempFile` for every call to it. 
it only works because we only use the `__enter__` and `__exit__` functions. 

Instead we default to `None` and create it if it is needed. and let python 
handle the refcounting.
```py
class OnDiskTempFile:
    ...
    def __exit__(self, exc_type, exc_val, exc_tb):
        self.__del__() # if we don't need it past the with scope. 

    def __del__(self): # will clean up after the last reference
       if self.path and os.path.exists(self.path):
            os.remove(self.path)
```

```py
def _compiler_supports(compiler, flag, source="int main() {}", 
output_file=None):
    """Test whether the compiler supports the given flag."""
    if output_file is None:
        output_file  = OnDiskTempFile()

    if platform.system() == "Darwin":
        compiler = "xcrun " + compiler

    try:
        cmd = "echo '%s' | %s %s -x c -o %s -" % (
            source,
            compiler,
            flag,
            output_file.path if output_file else output_file.path,
        )
        subprocess.check_call(cmd, shell=True)
    except subprocess.CalledProcessError:
        return False
    return True
```

https://github.com/llvm/llvm-project/pull/176463
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to