From 4eea01983d23694e3f288d9521aad5eca2bb5a51 Mon Sep 17 00:00:00 2001 From: Jonathan Maw Date: Fri, 24 May 2019 14:42:08 +0100 Subject: Report progress when resolving elements --- src/buildstream/_context.py | 5 +++++ src/buildstream/_progress.py | 3 +++ src/buildstream/_project.py | 8 ++++++-- src/buildstream/element.py | 10 +++++++--- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/buildstream/_context.py b/src/buildstream/_context.py index 8345ec195..1da80d4e0 100644 --- a/src/buildstream/_context.py +++ b/src/buildstream/_context.py @@ -565,6 +565,7 @@ class Context(): self._last_progress_length = 0 progress = Progress(self, activity_name, total=total, unique_id=unique_id) yield progress + self._finish_progress() def report_progress(self, message_text, unique_id=None): new_len = len(message_text) @@ -679,6 +680,10 @@ class Context(): def set_artifact_files_optional(self): self.require_artifact_files = False + def _finish_progress(self): + sys.stderr.write("\n") + sys.stderr.flush() + # _record_message() # # Records the message if recording is enabled diff --git a/src/buildstream/_progress.py b/src/buildstream/_progress.py index d762f7385..82f6d4066 100644 --- a/src/buildstream/_progress.py +++ b/src/buildstream/_progress.py @@ -35,6 +35,9 @@ class Progress(): self._total += count self._check_report_progress() + def get_total(self): + return self._total + def add_progress(self, count): self._count += count self._check_report_progress() diff --git a/src/buildstream/_project.py b/src/buildstream/_project.py index 3d5714f86..1da89872e 100644 --- a/src/buildstream/_project.py +++ b/src/buildstream/_project.py @@ -454,9 +454,13 @@ class Project(): ticker=None, fetch_subprojects=fetch_subprojects) - with self._context.timed_activity("Resolving elements"): + # meta_elements is a list of target meta elements in a tree structure, + # not a list of all elements. + total_elements = progress.get_total() + + with self._context.progress_activity("Resolving elements", total=total_elements) as progress: elements = [ - Element._new_from_meta(meta) + Element._new_from_meta(meta, progress) for meta in meta_elements ] diff --git a/src/buildstream/element.py b/src/buildstream/element.py index 08326c6f3..3d8d01434 100644 --- a/src/buildstream/element.py +++ b/src/buildstream/element.py @@ -962,12 +962,13 @@ class Element(Plugin): # # Args: # meta (MetaElement): The meta element + # progress (Progress): An object to report progress to # # Returns: # (Element): A newly created Element instance # @classmethod - def _new_from_meta(cls, meta): + def _new_from_meta(cls, meta, progress=None): if not meta.first_pass: meta.project.ensure_fully_loaded() @@ -993,15 +994,18 @@ class Element(Plugin): # Instantiate dependencies for meta_dep in meta.dependencies: - dependency = Element._new_from_meta(meta_dep) + dependency = Element._new_from_meta(meta_dep, progress) element.__runtime_dependencies.append(dependency) dependency.__reverse_dependencies.add(element) for meta_dep in meta.build_dependencies: - dependency = Element._new_from_meta(meta_dep) + dependency = Element._new_from_meta(meta_dep, progress) element.__build_dependencies.append(dependency) dependency.__reverse_dependencies.add(element) + if progress: + progress.add_progress(1) + return element # _clear_meta_elements_cache() -- cgit v1.2.1