[Notes] [Git][BuildStream/buildstream][tristan/error-message-regression] 3 commits: element.py: Cleanup temporary staging directories on termination



Title: GitLab

Tristan Van Berkom pushed to branch tristan/error-message-regression at BuildStream / buildstream

Commits:

5 changed files:

Changes:

  • buildstream/_exceptions.py
    ... ... @@ -262,8 +262,8 @@ class PlatformError(BstError):
    262 262
     # Raised when errors are encountered by the sandbox implementation
    
    263 263
     #
    
    264 264
     class SandboxError(BstError):
    
    265
    -    def __init__(self, message, reason=None):
    
    266
    -        super().__init__(message, domain=ErrorDomain.SANDBOX, reason=reason)
    
    265
    +    def __init__(self, message, detail=None, reason=None):
    
    266
    +        super().__init__(message, detail=detail, domain=ErrorDomain.SANDBOX, reason=reason)
    
    267 267
     
    
    268 268
     
    
    269 269
     # ArtifactError
    

  • buildstream/element.py
    ... ... @@ -1398,43 +1398,40 @@ class Element(Plugin):
    1398 1398
         #     usebuildtree (bool): use a the elements build tree as its source.
    
    1399 1399
         #
    
    1400 1400
         def _stage_sources_at(self, vdirectory, mount_workspaces=True, usebuildtree=False):
    
    1401
    -        with self.timed_activity("Staging sources", silent_nested=True):
    
    1401
    +        context = self._get_context()
    
    1402
    +
    
    1403
    +        # It's advantageous to have this temporary directory on
    
    1404
    +        # the same file system as the rest of our cache.
    
    1405
    +        with self.timed_activity("Staging sources", silent_nested=True), \
    
    1406
    +            utils._tempdir(dir=context.artifactdir, prefix='staging-temp') as temp_staging_directory:
    
    1407
    +
    
    1408
    +            import_dir = temp_staging_directory
    
    1409
    +
    
    1402 1410
                 if not isinstance(vdirectory, Directory):
    
    1403 1411
                     vdirectory = FileBasedDirectory(vdirectory)
    
    1404 1412
                 if not vdirectory.is_empty():
    
    1405 1413
                     raise ElementError("Staging directory '{}' is not empty".format(vdirectory))
    
    1406 1414
     
    
    1407
    -            # It's advantageous to have this temporary directory on
    
    1408
    -            # the same filing system as the rest of our cache.
    
    1409
    -            temp_staging_location = os.path.join(self._get_context().artifactdir, "staging_temp")
    
    1410
    -            temp_staging_directory = tempfile.mkdtemp(prefix=temp_staging_location)
    
    1411
    -            import_dir = temp_staging_directory
    
    1412
    -
    
    1413
    -            try:
    
    1414
    -                workspace = self._get_workspace()
    
    1415
    -                if workspace:
    
    1416
    -                    # If mount_workspaces is set and we're doing incremental builds,
    
    1417
    -                    # the workspace is already mounted into the sandbox.
    
    1418
    -                    if not (mount_workspaces and self.__can_build_incrementally()):
    
    1419
    -                        with self.timed_activity("Staging local files at {}"
    
    1420
    -                                                 .format(workspace.get_absolute_path())):
    
    1421
    -                            workspace.stage(temp_staging_directory)
    
    1422
    -                # Check if we have a cached buildtree to use
    
    1423
    -                elif usebuildtree:
    
    1424
    -                    artifact_base, _ = self.__extract()
    
    1425
    -                    import_dir = os.path.join(artifact_base, 'buildtree')
    
    1426
    -                else:
    
    1427
    -                    # No workspace or cached buildtree, stage source directly
    
    1428
    -                    for source in self.sources():
    
    1429
    -                        source._stage(temp_staging_directory)
    
    1415
    +            workspace = self._get_workspace()
    
    1416
    +            if workspace:
    
    1417
    +                # If mount_workspaces is set and we're doing incremental builds,
    
    1418
    +                # the workspace is already mounted into the sandbox.
    
    1419
    +                if not (mount_workspaces and self.__can_build_incrementally()):
    
    1420
    +                    with self.timed_activity("Staging local files at {}"
    
    1421
    +                                             .format(workspace.get_absolute_path())):
    
    1422
    +                        workspace.stage(temp_staging_directory)
    
    1423
    +
    
    1424
    +            # Check if we have a cached buildtree to use
    
    1425
    +            elif usebuildtree:
    
    1426
    +                artifact_base, _ = self.__extract()
    
    1427
    +                import_dir = os.path.join(artifact_base, 'buildtree')
    
    1428
    +            else:
    
    1429
    +                # No workspace or cached buildtree, stage source directly
    
    1430
    +                for source in self.sources():
    
    1431
    +                    source._stage(temp_staging_directory)
    
    1430 1432
     
    
    1431
    -                vdirectory.import_files(import_dir)
    
    1433
    +            vdirectory.import_files(import_dir)
    
    1432 1434
     
    
    1433
    -            finally:
    
    1434
    -                # Staging may produce directories with less than 'rwx' permissions
    
    1435
    -                # for the owner, which breaks tempfile. _force_rmtree will deal
    
    1436
    -                # with these.
    
    1437
    -                utils._force_rmtree(temp_staging_directory)
    
    1438 1435
             # Ensure deterministic mtime of sources at build time
    
    1439 1436
             vdirectory.set_deterministic_mtime()
    
    1440 1437
             # Ensure deterministic owners of sources at build time
    

  • buildstream/sandbox/sandbox.py
    ... ... @@ -86,10 +86,11 @@ class SandboxCommandError(SandboxError):
    86 86
     
    
    87 87
         Args:
    
    88 88
            message (str): The error message to report to the user
    
    89
    +       detail (str): The detailed error string
    
    89 90
            collect (str): An optional directory containing partial install contents
    
    90 91
         """
    
    91
    -    def __init__(self, message, *, collect=None):
    
    92
    -        super().__init__(message, reason='command-failed')
    
    92
    +    def __init__(self, message, *, detail=None, collect=None):
    
    93
    +        super().__init__(message, detail=detail, reason='command-failed')
    
    93 94
     
    
    94 95
             self.collect = collect
    
    95 96
     
    
    ... ... @@ -599,8 +600,8 @@ class _SandboxBatch():
    599 600
             if exitcode != 0:
    
    600 601
                 cmdline = ' '.join(shlex.quote(cmd) for cmd in command.command)
    
    601 602
                 label = command.label or cmdline
    
    602
    -            raise SandboxCommandError("Command '{}' failed with exitcode {}".format(label, exitcode),
    
    603
    -                                      collect=self.collect)
    
    603
    +            raise SandboxCommandError("Command failed with exitcode {}".format(exitcode),
    
    604
    +                                      detail=label, collect=self.collect)
    
    604 605
     
    
    605 606
         def execute_call(self, call):
    
    606 607
             call.callback()
    

  • buildstream/utils.py
    ... ... @@ -1023,7 +1023,7 @@ def _tempdir(suffix="", prefix="tmp", dir=None): # pylint: disable=redefined-bu
    1023 1023
     
    
    1024 1024
         def cleanup_tempdir():
    
    1025 1025
             if os.path.isdir(tempdir):
    
    1026
    -            shutil.rmtree(tempdir)
    
    1026
    +            _force_rmtree(tempdir)
    
    1027 1027
     
    
    1028 1028
         try:
    
    1029 1029
             with _signals.terminator(cleanup_tempdir):
    

  • tests/integration/sandbox-bwrap.py
    ... ... @@ -59,4 +59,4 @@ def test_sandbox_bwrap_return_subprocess(cli, tmpdir, datafiles):
    59 59
     
    
    60 60
         result = cli.run(project=project, args=['build', element_name])
    
    61 61
         result.assert_task_error(error_domain=ErrorDomain.SANDBOX, error_reason="command-failed")
    
    62
    -    assert "sandbox-bwrap/command-exit-42.bst|Command 'exit 42' failed with exitcode 42" in result.stderr
    62
    +    assert "sandbox-bwrap/command-exit-42.bst|Command failed with exitcode 42" in result.stderr



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