Add optional progress bar when generating build.ninja

pull/5305/merge
Nirbheek Chauhan 5 years ago committed by Jussi Pakkanen
parent 4200afc74d
commit 9c2724bce5
  1. 6
      mesonbuild/backend/ninjabackend.py
  2. 6
      mesonbuild/compilers/compilers.py
  3. 55
      mesonbuild/mesonlib.py
  4. 18
      mesonbuild/wrap/wrap.py
  5. 1
      setup.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):

@ -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)

@ -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

@ -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

@ -49,6 +49,7 @@ if sys.platform != 'win32':
if __name__ == '__main__':
setup(name='meson',
version=version,
extras_require={'progress': ['tqdm']},
packages=packages,
package_data=package_data,
entry_points=entries,

Loading…
Cancel
Save