[Notes] [Git][BuildStream/buildstream][master] 4 commits: element.py: Schedule assemble for key of workspaced elements



Title: GitLab

Tristan Van Berkom pushed to branch master at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • buildstream/element.py
    ... ... @@ -1101,9 +1101,12 @@ class Element(Plugin):
    1101 1101
                 # until the full cache query below.
    
    1102 1102
                 if (not self.__assemble_scheduled and not self.__assemble_done and
    
    1103 1103
                         not self.__cached_success(keystrength=_KeyStrength.WEAK) and
    
    1104
    -                    not self._pull_pending() and self._is_required()):
    
    1105
    -                self._schedule_assemble()
    
    1106
    -                return
    
    1104
    +                    not self._pull_pending()):
    
    1105
    +                # For uncached workspaced elements, assemble is required
    
    1106
    +                # even if we only need the cache key
    
    1107
    +                if self._is_required() or self._get_workspace():
    
    1108
    +                    self._schedule_assemble()
    
    1109
    +                    return
    
    1107 1110
     
    
    1108 1111
             if self.__strict_cache_key is None:
    
    1109 1112
                 dependencies = [
    
    ... ... @@ -1126,13 +1129,17 @@ class Element(Plugin):
    1126 1129
                     self.__weak_cached = self.__artifacts.contains(self, self.__weak_cache_key)
    
    1127 1130
     
    
    1128 1131
             if (not self.__assemble_scheduled and not self.__assemble_done and
    
    1129
    -                not self._cached_success() and not self._pull_pending() and self._is_required()):
    
    1132
    +                not self._cached_success() and not self._pull_pending()):
    
    1130 1133
                 # Workspaced sources are considered unstable if a build is pending
    
    1131 1134
                 # as the build will modify the contents of the workspace.
    
    1132 1135
                 # Determine as early as possible if a build is pending to discard
    
    1133 1136
                 # unstable cache keys.
    
    1134
    -            self._schedule_assemble()
    
    1135
    -            return
    
    1137
    +
    
    1138
    +            # For uncached workspaced elements, assemble is required
    
    1139
    +            # even if we only need the cache key
    
    1140
    +            if self._is_required() or self._get_workspace():
    
    1141
    +                self._schedule_assemble()
    
    1142
    +                return
    
    1136 1143
     
    
    1137 1144
             if self.__cache_key is None:
    
    1138 1145
                 # Calculate strong cache key
    
    ... ... @@ -1430,7 +1437,6 @@ class Element(Plugin):
    1430 1437
         # in a subprocess.
    
    1431 1438
         #
    
    1432 1439
         def _schedule_assemble(self):
    
    1433
    -        assert self._is_required()
    
    1434 1440
             assert not self.__assemble_scheduled
    
    1435 1441
             self.__assemble_scheduled = True
    
    1436 1442
     
    
    ... ... @@ -1438,6 +1444,8 @@ class Element(Plugin):
    1438 1444
             for dep in self.dependencies(Scope.BUILD, recurse=False):
    
    1439 1445
                 dep._set_required()
    
    1440 1446
     
    
    1447
    +        self._set_required()
    
    1448
    +
    
    1441 1449
             # Invalidate workspace key as the build modifies the workspace directory
    
    1442 1450
             workspace = self._get_workspace()
    
    1443 1451
             if workspace:
    
    ... ... @@ -1661,6 +1669,10 @@ class Element(Plugin):
    1661 1669
         #   (bool): Whether a pull operation is pending
    
    1662 1670
         #
    
    1663 1671
         def _pull_pending(self):
    
    1672
    +        if self._get_workspace():
    
    1673
    +            # Workspace builds are never pushed to artifact servers
    
    1674
    +            return False
    
    1675
    +
    
    1664 1676
             if self.__strong_cached:
    
    1665 1677
                 # Artifact already in local cache
    
    1666 1678
                 return False
    

  • tests/frontend/workspace.py
    ... ... @@ -780,3 +780,73 @@ def test_inconsitent_pipeline_message(cli, tmpdir, datafiles, kind):
    780 780
             'build', element_name
    
    781 781
         ])
    
    782 782
         result.assert_main_error(ErrorDomain.PIPELINE, "inconsistent-pipeline-workspaced")
    
    783
    +
    
    784
    +
    
    785
    +@pytest.mark.datafiles(DATA_DIR)
    
    786
    +@pytest.mark.parametrize("kind", repo_kinds)
    
    787
    +@pytest.mark.parametrize("strict", [("strict"), ("non-strict")])
    
    788
    +def test_cache_key_workspace_in_dependencies(cli, tmpdir, datafiles, kind, strict):
    
    789
    +    checkout = os.path.join(str(tmpdir), 'checkout')
    
    790
    +    element_name, project, workspace = open_workspace(cli, os.path.join(str(tmpdir), 'repo-a'), datafiles, kind, False)
    
    791
    +
    
    792
    +    element_path = os.path.join(project, 'elements')
    
    793
    +    back_dep_element_name = 'workspace-test-{}-back-dep.bst'.format(kind)
    
    794
    +
    
    795
    +    # Write out our test target
    
    796
    +    element = {
    
    797
    +        'kind': 'compose',
    
    798
    +        'depends': [
    
    799
    +            {
    
    800
    +                'filename': element_name,
    
    801
    +                'type': 'build'
    
    802
    +            }
    
    803
    +        ]
    
    804
    +    }
    
    805
    +    _yaml.dump(element,
    
    806
    +               os.path.join(element_path,
    
    807
    +                            back_dep_element_name))
    
    808
    +
    
    809
    +    # Modify workspace
    
    810
    +    shutil.rmtree(os.path.join(workspace, 'usr', 'bin'))
    
    811
    +    os.makedirs(os.path.join(workspace, 'etc'))
    
    812
    +    with open(os.path.join(workspace, 'etc', 'pony.conf'), 'w') as f:
    
    813
    +        f.write("PONY='pink'")
    
    814
    +
    
    815
    +    # Configure strict mode
    
    816
    +    strict_mode = True
    
    817
    +    if strict != 'strict':
    
    818
    +        strict_mode = False
    
    819
    +    cli.configure({
    
    820
    +        'projects': {
    
    821
    +            'test': {
    
    822
    +                'strict': strict_mode
    
    823
    +            }
    
    824
    +        }
    
    825
    +    })
    
    826
    +
    
    827
    +    # Build artifact with dependency's modified workspace
    
    828
    +    assert cli.get_element_state(project, element_name) == 'buildable'
    
    829
    +    assert cli.get_element_key(project, element_name) == "{:?<64}".format('')
    
    830
    +    assert cli.get_element_state(project, back_dep_element_name) == 'waiting'
    
    831
    +    assert cli.get_element_key(project, back_dep_element_name) == "{:?<64}".format('')
    
    832
    +    result = cli.run(project=project, args=['build', back_dep_element_name])
    
    833
    +    result.assert_success()
    
    834
    +    assert cli.get_element_state(project, element_name) == 'cached'
    
    835
    +    assert cli.get_element_key(project, element_name) != "{:?<64}".format('')
    
    836
    +    assert cli.get_element_state(project, back_dep_element_name) == 'cached'
    
    837
    +    assert cli.get_element_key(project, back_dep_element_name) != "{:?<64}".format('')
    
    838
    +    result = cli.run(project=project, args=['build', back_dep_element_name])
    
    839
    +    result.assert_success()
    
    840
    +
    
    841
    +    # Checkout the result
    
    842
    +    result = cli.run(project=project, args=[
    
    843
    +        'checkout', back_dep_element_name, checkout
    
    844
    +    ])
    
    845
    +    result.assert_success()
    
    846
    +
    
    847
    +    # Check that the pony.conf from the modified workspace exists
    
    848
    +    filename = os.path.join(checkout, 'etc', 'pony.conf')
    
    849
    +    assert os.path.exists(filename)
    
    850
    +
    
    851
    +    # Check that the original /usr/bin/hello is not in the checkout
    
    852
    +    assert not os.path.exists(os.path.join(checkout, 'usr', 'bin', 'hello'))



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