summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2020-01-22 21:04:30 +0530
committerNirbheek Chauhan <nirbheek@centricular.com>2020-01-22 21:23:50 +0530
commit79db2391ae804311469299dfdba5726e694c0f84 (patch)
tree1afa39c783ccf5cae7806a01d020113ea481f826
parent77f733daab6ffab07d8c7b50790a43371abd6018 (diff)
downloadmeson-nirbheek/fix-git-colors-windows-again-again.tar.gz
Move git helper out into mesonlib for reusenirbheek/fix-git-colors-windows-again-again
Reuse the git helper for `meson wrap` and `meson subprojects` so we don't need to maintain the same git-colors-on-windows workarounds in multiple places.
-rw-r--r--mesonbuild/mesonlib.py14
-rwxr-xr-xmesonbuild/msubprojects.py10
-rw-r--r--mesonbuild/wrap/wrap.py16
3 files changed, 18 insertions, 22 deletions
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index 9ae7b76cf..85d883bef 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -56,6 +56,20 @@ else:
python_command = [sys.executable]
meson_command = None
+GIT = shutil.which('git')
+def git(cmd: T.List[str], workingdir: str, **kwargs) -> subprocess.CompletedProcess:
+ pc = subprocess.run([GIT, '-C', workingdir] + cmd,
+ # Redirect stdin to DEVNULL otherwise git messes up the
+ # console and ANSI colors stop working on Windows.
+ stdin=subprocess.DEVNULL, **kwargs)
+ # Sometimes git calls git recursively, such as `git submodule update
+ # --recursive` which will be without the above workaround, so set the
+ # console mode again just in case.
+ if platform.system().lower() == 'windows':
+ mlog._windows_ansi()
+ return pc
+
+
def set_meson_command(mainfile):
global python_command
global meson_command
diff --git a/mesonbuild/msubprojects.py b/mesonbuild/msubprojects.py
index c69684fb3..d6f07152f 100755
--- a/mesonbuild/msubprojects.py
+++ b/mesonbuild/msubprojects.py
@@ -2,7 +2,7 @@ import os, subprocess
import argparse
from . import mlog
-from .mesonlib import Popen_safe
+from .mesonlib import git, Popen_safe
from .wrap.wrap import API_ROOT, PackageDefinition, Resolver, WrapException
from .wrap import wraptool
@@ -40,12 +40,8 @@ def update_file(wrap, repo_dir, options):
' In that case, delete', mlog.bold(repo_dir), 'and run', mlog.bold('meson --reconfigure'))
def git_output(cmd, workingdir):
- return subprocess.check_output(['git', '-C', workingdir] + cmd,
- # Redirect stdin to DEVNULL otherwise git
- # messes up the console and ANSI colors stop
- # working on Windows.
- stdin=subprocess.DEVNULL,
- stderr=subprocess.STDOUT).decode()
+ return git(cmd, workingdir, check=True, universal_newlines=True,
+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout
def git_show(repo_dir):
commit_message = git_output(['show', '--quiet', '--pretty=format:%h%n%d%n%s%n[%an]'], repo_dir)
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index 92e37de08..e9b47a0a4 100644
--- a/mesonbuild/wrap/wrap.py
+++ b/mesonbuild/wrap/wrap.py
@@ -18,7 +18,6 @@ import urllib.request
import urllib.error
import urllib.parse
import os
-import platform
import hashlib
import shutil
import tempfile
@@ -29,7 +28,7 @@ import configparser
import typing as T
from . import WrapMode
-from ..mesonlib import ProgressBar, MesonException
+from ..mesonlib import git, GIT, ProgressBar, MesonException
if T.TYPE_CHECKING:
import http.client
@@ -44,23 +43,10 @@ except ImportError:
has_ssl = False
API_ROOT = 'http://wrapdb.mesonbuild.com/v1/'
-GIT = shutil.which('git')
REQ_TIMEOUT = 600.0
SSL_WARNING_PRINTED = False
WHITELIST_SUBDOMAIN = 'wrapdb.mesonbuild.com'
-def git(cmd: T.List[str], workingdir: str, **kwargs) -> subprocess.CompletedProcess:
- pc = subprocess.run([GIT, '-C', workingdir] + cmd,
- # Redirect stdin to DEVNULL otherwise git messes up the
- # console and ANSI colors stop working on Windows.
- stdin=subprocess.DEVNULL, **kwargs)
- # Sometimes git calls git recursively, such as `git submodule update
- # --recursive` which will be without the above workaround, so set the
- # console mode again just in case.
- if platform.system().lower() == 'windows':
- mlog._windows_ansi()
- return pc
-
def quiet_git(cmd: T.List[str], workingdir: str) -> T.Tuple[bool, str]:
if not GIT:
return False, 'Git program not found.'