aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild
diff options
context:
space:
mode:
authorNirbheek Chauhan <nirbheek@centricular.com>2019-07-20 14:02:15 +0000
committerJussi Pakkanen <jpakkane@gmail.com>2019-07-20 17:02:15 +0300
commit9c2724bce5c6a904d1bffdb55921071163812a0e (patch)
tree57cd3503d9b72839162fee20154559bee181e472 /mesonbuild
parent4200afc74d1e6ba6d117e900799d0d82a85bae8a (diff)
downloadmeson-9c2724bce5c6a904d1bffdb55921071163812a0e.zip
meson-9c2724bce5c6a904d1bffdb55921071163812a0e.tar.gz
meson-9c2724bce5c6a904d1bffdb55921071163812a0e.tar.bz2
Add optional progress bar when generating build.ninja
Diffstat (limited to 'mesonbuild')
-rw-r--r--mesonbuild/backend/ninjabackend.py6
-rw-r--r--mesonbuild/compilers/compilers.py6
-rw-r--r--mesonbuild/mesonlib.py55
-rw-r--r--mesonbuild/wrap/wrap.py18
4 files changed, 67 insertions, 18 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index b57a783..ce5565f 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -32,7 +32,7 @@ from .. import compilers
from ..compilers import Compiler, CompilerArgs, CCompiler, VisualStudioLikeCompiler, FortranCompiler
from ..linkers import ArLinker
from ..mesonlib import (
- File, LibType, MachineChoice, MesonException, OrderedSet, PerMachine
+ File, LibType, MachineChoice, MesonException, OrderedSet, PerMachine, ProgressBar
)
from ..mesonlib import get_compiler_for_source, has_path_sep
from .backends import CleanTrees
@@ -294,7 +294,7 @@ int dummy;
self.build_elements = []
self.generate_phony()
self.add_build_comment(NinjaComment('Build rules for targets'))
- for t in self.build.get_targets().values():
+ for t in ProgressBar(self.build.get_targets().values(), desc='Generating targets'):
self.generate_target(t)
self.add_build_comment(NinjaComment('Test rules'))
self.generate_tests()
@@ -903,7 +903,7 @@ int dummy;
r.write(outfile)
def write_builds(self, outfile):
- for b in self.build_elements:
+ for b in ProgressBar(self.build_elements, desc='Writing build.ninja'):
b.write(outfile)
def generate_phony(self):
diff --git a/mesonbuild/compilers/compilers.py b/mesonbuild/compilers/compilers.py
index 71d96d4..df448f0 100644
--- a/mesonbuild/compilers/compilers.py
+++ b/mesonbuild/compilers/compilers.py
@@ -574,9 +574,9 @@ class CompilerArgs(list):
def append_direct(self, arg):
'''
- Append the specified argument without any reordering or de-dup
- except for absolute paths where the order of include search directories
- is not relevant
+ Append the specified argument without any reordering or de-dup except
+ for absolute paths to libraries, etc, which can always be de-duped
+ safely.
'''
if os.path.isabs(arg):
self.append(arg)
diff --git a/mesonbuild/mesonlib.py b/mesonbuild/mesonlib.py
index 585a5bb..3de6462 100644
--- a/mesonbuild/mesonlib.py
+++ b/mesonbuild/mesonlib.py
@@ -1306,3 +1306,58 @@ class LibType(Enum):
STATIC = 1
PREFER_SHARED = 2
PREFER_STATIC = 3
+
+
+class ProgressBarFallback:
+ '''Fallback progress bar implementation when tqdm is not found'''
+ def __init__(self, iterable=None, total=None, bar_type=None, desc=None):
+ if iterable is not None:
+ self.iterable = iter(iterable)
+ return
+ self.total = total
+ self.done = 0
+ self.printed_dots = 0
+ if self.total and bar_type == 'download':
+ print('Download size:', self.total)
+ if desc:
+ print('{}: '.format(desc), end='')
+
+ # Pretend to be an iterator when called as one and don't print any
+ # progress
+ def __iter__(self):
+ return self.iterable
+
+ def __next__(self):
+ return next(self.iterable)
+
+ def print_dot(self):
+ print('.', end='')
+ sys.stdout.flush()
+ self.printed_dots += 1
+
+ def update(self, progress):
+ self.done += progress
+ if not self.total:
+ # Just print one dot per call if we don't have a total length
+ self.print_dot()
+ return
+ ratio = int(self.done / self.total * 10)
+ while self.printed_dots < ratio:
+ self.print_dot()
+
+ def close(self):
+ print('')
+
+try:
+ from tqdm import tqdm
+
+ class ProgressBar(tqdm):
+ def __init__(self, *args, bar_type=None, **kwargs):
+ if bar_type == 'download':
+ kwargs.update({'unit': 'bytes', 'leave': True})
+ else:
+ kwargs.update({'leave': False})
+ kwargs['ncols'] = 100
+ super().__init__(*args, **kwargs)
+except ImportError:
+ ProgressBar = ProgressBarFallback
diff --git a/mesonbuild/wrap/wrap.py b/mesonbuild/wrap/wrap.py
index 55f86bc..4b2a323 100644
--- a/mesonbuild/wrap/wrap.py
+++ b/mesonbuild/wrap/wrap.py
@@ -18,8 +18,9 @@ import urllib.request, os, hashlib, shutil, tempfile, stat
import subprocess
import sys
import configparser
+
from . import WrapMode
-from ..mesonlib import MesonException
+from ..mesonlib import ProgressBar, MesonException
try:
import ssl
@@ -278,24 +279,17 @@ class Resolver:
tmpfile.write(block)
hashvalue = h.hexdigest()
return hashvalue, tmpfile.name
- print('Download size:', dlsize)
- print('Downloading: ', end='')
sys.stdout.flush()
- printed_dots = 0
- downloaded = 0
+ progress_bar = ProgressBar(bar_type='download', total=dlsize,
+ desc='Downloading')
while True:
block = resp.read(blocksize)
if block == b'':
break
- downloaded += len(block)
h.update(block)
tmpfile.write(block)
- ratio = int(downloaded / dlsize * 10)
- while printed_dots < ratio:
- print('.', end='')
- sys.stdout.flush()
- printed_dots += 1
- print('')
+ progress_bar.update(len(block))
+ progress_bar.close()
hashvalue = h.hexdigest()
return hashvalue, tmpfile.name