[Notes] [Git][BuildStream/buildstream][jonathan/junction-no-tmpdir] 2 commits: loader.py: Load junction from workspace if one's open



Title: GitLab

Jonathan Maw pushed to branch jonathan/junction-no-tmpdir at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • buildstream/_loader/loader.py
    ... ... @@ -49,12 +49,10 @@ from .._message import Message, MessageType
    49 49
     #    context (Context): The Context object
    
    50 50
     #    project (Project): The toplevel Project object
    
    51 51
     #    parent (Loader): A parent Loader object, in the case this is a junctioned Loader
    
    52
    -#    tempdir (str): A directory to cleanup with the Loader, given to the loader by a parent
    
    53
    -#                   loader in the case that this loader is a subproject loader.
    
    54 52
     #
    
    55 53
     class Loader():
    
    56 54
     
    
    57
    -    def __init__(self, context, project, *, parent=None, tempdir=None):
    
    55
    +    def __init__(self, context, project, *, parent=None):
    
    58 56
     
    
    59 57
             # Ensure we have an absolute path for the base directory
    
    60 58
             basedir = project.element_path
    
    ... ... @@ -73,7 +71,6 @@ class Loader():
    73 71
             self._options = project.options      # Project options (OptionPool)
    
    74 72
             self._basedir = basedir              # Base project directory
    
    75 73
             self._first_pass_options = project.first_pass_config.options  # Project options (OptionPool)
    
    76
    -        self._tempdir = tempdir              # A directory to cleanup
    
    77 74
             self._parent = parent                # The parent loader
    
    78 75
     
    
    79 76
             self._meta_elements = {}  # Dict of resolved meta elements by name
    
    ... ... @@ -159,30 +156,6 @@ class Loader():
    159 156
     
    
    160 157
             return ret
    
    161 158
     
    
    162
    -    # cleanup():
    
    163
    -    #
    
    164
    -    # Remove temporary checkout directories of subprojects
    
    165
    -    #
    
    166
    -    def cleanup(self):
    
    167
    -        if self._parent and not self._tempdir:
    
    168
    -            # already done
    
    169
    -            return
    
    170
    -
    
    171
    -        # recurse
    
    172
    -        for loader in self._loaders.values():
    
    173
    -            # value may be None with nested junctions without overrides
    
    174
    -            if loader is not None:
    
    175
    -                loader.cleanup()
    
    176
    -
    
    177
    -        if not self._parent:
    
    178
    -            # basedir of top-level loader is never a temporary directory
    
    179
    -            return
    
    180
    -
    
    181
    -        # safe guard to not accidentally delete directories outside builddir
    
    182
    -        if self._tempdir.startswith(self._context.builddir + os.sep):
    
    183
    -            if os.path.exists(self._tempdir):
    
    184
    -                shutil.rmtree(self._tempdir)
    
    185
    -
    
    186 159
         ###########################################
    
    187 160
         #            Private Methods              #
    
    188 161
         ###########################################
    
    ... ... @@ -540,10 +513,13 @@ class Loader():
    540 513
                                     "Subproject has no ref for junction: {}".format(filename),
    
    541 514
                                     detail=detail)
    
    542 515
     
    
    543
    -        if len(sources) == 1 and sources[0]._get_local_path():
    
    516
    +        workspace = element._get_workspace()
    
    517
    +        if workspace:
    
    518
    +            # If a workspace is open, load it from there instead
    
    519
    +            basedir = workspace.get_absolute_path()
    
    520
    +        elif len(sources) == 1 and sources[0]._get_local_path():
    
    544 521
                 # Optimization for junctions with a single local source
    
    545 522
                 basedir = sources[0]._get_local_path()
    
    546
    -            tempdir = None
    
    547 523
             else:
    
    548 524
                 # Stage sources
    
    549 525
                 element._update_state()
    
    ... ... @@ -551,14 +527,13 @@ class Loader():
    551 527
                 if not os.path.exists(basedir):
    
    552 528
                     os.makedirs(basedir, exist_ok=True)
    
    553 529
                     element._stage_sources_at(basedir, mount_workspaces=False)
    
    554
    -            tempdir = None
    
    555 530
     
    
    556 531
             # Load the project
    
    557 532
             project_dir = os.path.join(basedir, element.path)
    
    558 533
             try:
    
    559 534
                 from .._project import Project
    
    560 535
                 project = Project(project_dir, self._context, junction=element,
    
    561
    -                              parent_loader=self, tempdir=tempdir)
    
    536
    +                              parent_loader=self)
    
    562 537
             except LoadError as e:
    
    563 538
                 if e.reason == LoadErrorReason.MISSING_PROJECT_CONF:
    
    564 539
                     raise LoadError(reason=LoadErrorReason.INVALID_JUNCTION,
    

  • buildstream/_project.py
    ... ... @@ -91,7 +91,7 @@ class ProjectConfig:
    91 91
     class Project():
    
    92 92
     
    
    93 93
         def __init__(self, directory, context, *, junction=None, cli_options=None,
    
    94
    -                 default_mirror=None, parent_loader=None, tempdir=None):
    
    94
    +                 default_mirror=None, parent_loader=None):
    
    95 95
     
    
    96 96
             # The project name
    
    97 97
             self.name = None
    
    ... ... @@ -147,7 +147,7 @@ class Project():
    147 147
             self._project_includes = None
    
    148 148
     
    
    149 149
             profile_start(Topics.LOAD_PROJECT, self.directory.replace(os.sep, '-'))
    
    150
    -        self._load(parent_loader=parent_loader, tempdir=tempdir)
    
    150
    +        self._load(parent_loader=parent_loader)
    
    151 151
             profile_end(Topics.LOAD_PROJECT, self.directory.replace(os.sep, '-'))
    
    152 152
     
    
    153 153
             self._partially_loaded = True
    
    ... ... @@ -389,8 +389,6 @@ class Project():
    389 389
         # Cleans up resources used loading elements
    
    390 390
         #
    
    391 391
         def cleanup(self):
    
    392
    -        self.loader.cleanup()
    
    393
    -
    
    394 392
             # Reset the element loader state
    
    395 393
             Element._reset_load_state()
    
    396 394
     
    
    ... ... @@ -439,7 +437,7 @@ class Project():
    439 437
         #
    
    440 438
         # Raises: LoadError if there was a problem with the project.conf
    
    441 439
         #
    
    442
    -    def _load(self, parent_loader=None, tempdir=None):
    
    440
    +    def _load(self, parent_loader=None):
    
    443 441
     
    
    444 442
             # Load builtin default
    
    445 443
             projectfile = os.path.join(self.directory, _PROJECT_CONF_FILE)
    
    ... ... @@ -505,8 +503,7 @@ class Project():
    505 503
             self._fatal_warnings = _yaml.node_get(pre_config_node, list, 'fatal-warnings', default_value=[])
    
    506 504
     
    
    507 505
             self.loader = Loader(self._context, self,
    
    508
    -                             parent=parent_loader,
    
    509
    -                             tempdir=tempdir)
    
    506
    +                             parent=parent_loader)
    
    510 507
     
    
    511 508
             self._project_includes = Includes(self.loader, copy_tree=False)
    
    512 509
     
    



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