[Notes] [Git][BuildStream/buildstream][chandan/bst-checkout-build] Refactor and simplify _prepare_sandbox for elements



Title: GitLab

Benjamin Schubert pushed to branch chandan/bst-checkout-build at BuildStream / buildstream

Commits:

3 changed files:

Changes:

  • buildstream/_frontend/cli.py
    ... ... @@ -647,16 +647,24 @@ def shell(app, element, sysroot, mount, isolate, build_, command):
    647 647
     def checkout(app, element, location, force, deps, integrate, hardlinks, tar):
    
    648 648
         """Checkout a built artifact to the specified location
    
    649 649
         """
    
    650
    +    from ..element import Scope
    
    650 651
     
    
    651 652
         if hardlinks and tar:
    
    652 653
             click.echo("ERROR: options --hardlinks and --tar conflict", err=True)
    
    653 654
             sys.exit(-1)
    
    654 655
     
    
    656
    +    if deps == "run":
    
    657
    +        scope = Scope.RUN
    
    658
    +    elif deps == "build":
    
    659
    +        scope = Scope.BUILD
    
    660
    +    elif deps == "none":
    
    661
    +        scope = Scope.NONE
    
    662
    +
    
    655 663
         with app.initialized():
    
    656 664
             app.stream.checkout(element,
    
    657 665
                                 location=location,
    
    658 666
                                 force=force,
    
    659
    -                            deps=deps,
    
    667
    +                            scope=scope,
    
    660 668
                                 integrate=integrate,
    
    661 669
                                 hardlinks=hardlinks,
    
    662 670
                                 tar=tar)
    

  • buildstream/_stream.py
    ... ... @@ -357,7 +357,7 @@ class Stream():
    357 357
         #    target (str): Target to checkout
    
    358 358
         #    location (str): Location to checkout the artifact to
    
    359 359
         #    force (bool): Whether files can be overwritten if necessary
    
    360
    -    #    deps (str): The dependencies to checkout
    
    360
    +    #    scope (str): The scope of dependencies to checkout
    
    361 361
         #    integrate (bool): Whether to run integration commands
    
    362 362
         #    hardlinks (bool): Whether checking out files hardlinked to
    
    363 363
         #                      their artifacts is acceptable
    
    ... ... @@ -370,7 +370,7 @@ class Stream():
    370 370
         def checkout(self, target, *,
    
    371 371
                      location=None,
    
    372 372
                      force=False,
    
    373
    -                 deps='run',
    
    373
    +                 scope=Scope.RUN,
    
    374 374
                      integrate=True,
    
    375 375
                      hardlinks=False,
    
    376 376
                      tar=False):
    
    ... ... @@ -403,7 +403,7 @@ class Stream():
    403 403
     
    
    404 404
             # Stage deps into a temporary sandbox first
    
    405 405
             try:
    
    406
    -            with target._prepare_sandbox(Scope.RUN, None, deps=deps,
    
    406
    +            with target._prepare_sandbox(scope=scope, directory=None,
    
    407 407
                                              integrate=integrate) as sandbox:
    
    408 408
     
    
    409 409
                     # Copy or move the sandbox to the target directory
    

  • buildstream/element.py
    ... ... @@ -1315,7 +1315,7 @@ class Element(Plugin):
    1315 1315
         # is used to stage things by the `bst checkout` codepath
    
    1316 1316
         #
    
    1317 1317
         @contextmanager
    
    1318
    -    def _prepare_sandbox(self, scope, directory, deps='run', integrate=True):
    
    1318
    +    def _prepare_sandbox(self, scope, directory, shell=False, integrate=True):
    
    1319 1319
             # bst shell and bst checkout require a local sandbox.
    
    1320 1320
             with self.__sandbox(directory, config=self.__sandbox_config, allow_remote=False) as sandbox:
    
    1321 1321
     
    
    ... ... @@ -1324,26 +1324,18 @@ class Element(Plugin):
    1324 1324
     
    
    1325 1325
                 # Stage something if we need it
    
    1326 1326
                 if not directory:
    
    1327
    -                if scope == Scope.BUILD:
    
    1327
    +                if shell and scope == Scope.BUILD:
    
    1328 1328
                         self.stage(sandbox)
    
    1329
    -                elif scope == Scope.RUN:
    
    1330
    -
    
    1331
    -                    if deps == 'build':
    
    1332
    -                        dependency_scope = Scope.BUILD
    
    1333
    -                    elif deps == 'run':
    
    1334
    -                        dependency_scope = Scope.RUN
    
    1335
    -                    else:
    
    1336
    -                        dependency_scope = Scope.NONE
    
    1337
    -
    
    1329
    +                else:
    
    1338 1330
                         # Stage deps in the sandbox root
    
    1339 1331
                         with self.timed_activity("Staging dependencies", silent_nested=True):
    
    1340
    -                        self.stage_dependency_artifacts(sandbox, dependency_scope)
    
    1332
    +                        self.stage_dependency_artifacts(sandbox, scope)
    
    1341 1333
     
    
    1342 1334
                         # Run any integration commands provided by the dependencies
    
    1343 1335
                         # once they are all staged and ready
    
    1344 1336
                         if integrate:
    
    1345 1337
                             with self.timed_activity("Integrating sandbox"):
    
    1346
    -                            for dep in self.dependencies(dependency_scope):
    
    1338
    +                            for dep in self.dependencies(scope):
    
    1347 1339
                                     dep.integrate(sandbox)
    
    1348 1340
     
    
    1349 1341
                 yield sandbox
    
    ... ... @@ -1845,7 +1837,7 @@ class Element(Plugin):
    1845 1837
         # If directory is not specified, one will be staged using scope
    
    1846 1838
         def _shell(self, scope=None, directory=None, *, mounts=None, isolate=False, prompt=None, command=None):
    
    1847 1839
     
    
    1848
    -        with self._prepare_sandbox(scope, directory) as sandbox:
    
    1840
    +        with self._prepare_sandbox(scope, directory, shell=True) as sandbox:
    
    1849 1841
                 environment = self.get_environment()
    
    1850 1842
                 environment = copy.copy(environment)
    
    1851 1843
                 flags = SandboxFlags.INTERACTIVE | SandboxFlags.ROOT_READ_ONLY
    



  • [Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]