You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildstream.apache.org by ro...@apache.org on 2020/12/29 13:42:41 UTC

[buildstream] 01/05: Issue #113: Split tracking and saving in `bst build`

This is an automated email from the ASF dual-hosted git repository.

root pushed a commit to branch tracking-changes
in repository https://gitbox.apache.org/repos/asf/buildstream.git

commit e4b6fd09a47c82d8af5f247116a2a886b8f76c60
Author: Tristan Maat <tr...@codethink.co.uk>
AuthorDate: Fri Oct 20 15:07:01 2017 +0100

    Issue #113: Split tracking and saving in `bst build`
---
 buildstream/_frontend/main.py        | 11 ++++++++---
 buildstream/_pipeline.py             |  9 ++++++---
 buildstream/_scheduler/trackqueue.py | 17 ++++++++++-------
 3 files changed, 24 insertions(+), 13 deletions(-)

diff --git a/buildstream/_frontend/main.py b/buildstream/_frontend/main.py
index d706458..8613e1f 100644
--- a/buildstream/_frontend/main.py
+++ b/buildstream/_frontend/main.py
@@ -195,16 +195,21 @@ def cli(context, **kwargs):
               help="Build elements that would not be needed for the current build plan")
 @click.option('--track', default=False, is_flag=True,
               help="Track new source references before building (implies --all)")
+@click.option('--track-save', default=False, is_flag=True,
+              help="Track new source references before building, updating their "
+                   "corresponding element files")
 @click.argument('elements', nargs=-1,
                 type=click.Path(dir_okay=False, readable=True))
 @click.pass_obj
-def build(app, elements, all, track):
+def build(app, elements, all, track, track_save):
     """Build elements in a pipeline"""
 
-    app.initialize(elements, rewritable=track, inconsistent=track, use_remote_cache=True)
+    track_first = track or track_save
+
+    app.initialize(elements, rewritable=track_save, inconsistent=track_first, use_remote_cache=True)
     app.print_heading()
     try:
-        app.pipeline.build(app.scheduler, all, track)
+        app.pipeline.build(app.scheduler, all, track_first, track_save)
         click.echo("")
         app.print_summary()
     except PipelineError:
diff --git a/buildstream/_pipeline.py b/buildstream/_pipeline.py
index 2a64e2f..fa7e8dc 100644
--- a/buildstream/_pipeline.py
+++ b/buildstream/_pipeline.py
@@ -384,9 +384,12 @@ class Pipeline():
     #    scheduler (Scheduler): The scheduler to run this pipeline on
     #    build_all (bool): Whether to build all elements, or only those
     #                      which are required to build the target.
-    #    track_first (bool): Track sources before fetching and building (implies build_all)
+    #    track_first (list): Elements whose sources to track prior to
+    #                        building
+    #    save (bool): Whether to save the tracking results in the
+    #                 elements
     #
-    def build(self, scheduler, build_all, track_first):
+    def build(self, scheduler, build_all, track_first, save):
         if len(self.unused_workspaces) > 0:
             self.message(MessageType.WARN, "Unused workspaces",
                          detail="\n".join([el + "-" + str(src) for el, src, _
@@ -409,7 +412,7 @@ class Pipeline():
         push = None
         queues = []
         if track_first:
-            track = TrackQueue()
+            track = TrackQueue(save=save)
             queues.append(track)
         if self.artifacts.can_fetch():
             pull = PullQueue()
diff --git a/buildstream/_scheduler/trackqueue.py b/buildstream/_scheduler/trackqueue.py
index df73a72..8c0ffdc 100644
--- a/buildstream/_scheduler/trackqueue.py
+++ b/buildstream/_scheduler/trackqueue.py
@@ -39,8 +39,9 @@ class TrackQueue(Queue):
     complete_name = "Tracked"
     queue_type = QueueType.FETCH
 
-    def __init__(self):
+    def __init__(self, save=True):
         super(TrackQueue, self).__init__()
+        self.save = save
 
     def process(self, element):
         return element._track()
@@ -69,12 +70,14 @@ class TrackQueue(Queue):
 
                 # Here we are in master process, what to do if writing
                 # to the disk fails for some reason ?
-                try:
-                    _yaml.dump(toplevel, fullname)
-                except OSError as e:
-                    source.error("Failed to update project file",
-                                 detail="{}: Failed to rewrite tracked source to file {}: {}"
-                                 .format(source, fullname, e))
+                if self.save:
+                    try:
+                        _yaml.dump(toplevel, fullname)
+                    except OSError as e:
+                        source.error("Failed to update project file",
+                                     detail="{}: Failed to rewrite "
+                                     "tracked source to file {}: {}"
+                                     .format(source, fullname, e))
 
         # Forcefully recalculate the element's consistency state after successfully
         # tracking, this is avoid a following fetch queue operating on the sources