def _check_and_get_version(self, tool: T.List[str], returncode: int) -> T.Tuple[bool, T.Union[str, None]]:
        """Check whether a command is valid and get its version"""
        p, out = Popen_safe(tool + [self.version_arg])[:2]
        valid = True
        if p.returncode != returncode:
            if self.skip_version:
                # maybe the executable is valid even if it doesn't support --version
                p = Popen_safe(tool + [self.skip_version])[0]
                if p.returncode != returncode:
                    valid = False
            else:
                valid = False
        version = self._sanitize_version(out.strip())
        return valid, version
Check whether a command is valid and get its version
mesonbuild/dependencies/configtool.py