[Notes] [Git][BuildStream/buildstream][bst-1.2] 5 commits: element.py: Schedule assemble for key of workspaced elements



Title: GitLab

Jürg Billeter pushed to branch bst-1.2 at BuildStream / buildstream

Commits:

2 changed files:

Changes:

  • buildstream/element.py
    ... ... @@ -1085,9 +1085,12 @@ class Element(Plugin):
    1085 1085
                 # until the full cache query below.
    
    1086 1086
                 cached = self.__artifacts.contains(self, self.__weak_cache_key)
    
    1087 1087
                 if (not self.__assemble_scheduled and not self.__assemble_done and
    
    1088
    -                    not cached and not self._pull_pending() and self._is_required()):
    
    1089
    -                self._schedule_assemble()
    
    1090
    -                return
    
    1088
    +                    not cached and not self._pull_pending()):
    
    1089
    +                # For uncached workspaced elements, assemble is required
    
    1090
    +                # even if we only need the cache key
    
    1091
    +                if self._is_required() or self._get_workspace():
    
    1092
    +                    self._schedule_assemble()
    
    1093
    +                    return
    
    1091 1094
     
    
    1092 1095
             if self.__strict_cache_key is None:
    
    1093 1096
                 dependencies = [
    
    ... ... @@ -1107,13 +1110,17 @@ class Element(Plugin):
    1107 1110
                 self.__strong_cached = self.__artifacts.contains(self, self.__strict_cache_key)
    
    1108 1111
     
    
    1109 1112
             if (not self.__assemble_scheduled and not self.__assemble_done and
    
    1110
    -                not self.__cached and not self._pull_pending() and self._is_required()):
    
    1113
    +                not self.__cached and not self._pull_pending()):
    
    1111 1114
                 # Workspaced sources are considered unstable if a build is pending
    
    1112 1115
                 # as the build will modify the contents of the workspace.
    
    1113 1116
                 # Determine as early as possible if a build is pending to discard
    
    1114 1117
                 # unstable cache keys.
    
    1115
    -            self._schedule_assemble()
    
    1116
    -            return
    
    1118
    +
    
    1119
    +            # For uncached workspaced elements, assemble is required
    
    1120
    +            # even if we only need the cache key
    
    1121
    +            if self._is_required() or self._get_workspace():
    
    1122
    +                self._schedule_assemble()
    
    1123
    +                return
    
    1117 1124
     
    
    1118 1125
             if self.__cache_key is None:
    
    1119 1126
                 # Calculate strong cache key
    
    ... ... @@ -1382,7 +1389,6 @@ class Element(Plugin):
    1382 1389
         # in a subprocess.
    
    1383 1390
         #
    
    1384 1391
         def _schedule_assemble(self):
    
    1385
    -        assert self._is_required()
    
    1386 1392
             assert not self.__assemble_scheduled
    
    1387 1393
             self.__assemble_scheduled = True
    
    1388 1394
     
    
    ... ... @@ -1390,6 +1396,8 @@ class Element(Plugin):
    1390 1396
             for dep in self.dependencies(Scope.BUILD, recurse=False):
    
    1391 1397
                 dep._set_required()
    
    1392 1398
     
    
    1399
    +        self._set_required()
    
    1400
    +
    
    1393 1401
             # Invalidate workspace key as the build modifies the workspace directory
    
    1394 1402
             workspace = self._get_workspace()
    
    1395 1403
             if workspace:
    
    ... ... @@ -1579,6 +1587,10 @@ class Element(Plugin):
    1579 1587
         #   (bool): Whether a pull operation is pending
    
    1580 1588
         #
    
    1581 1589
         def _pull_pending(self):
    
    1590
    +        if self._get_workspace():
    
    1591
    +            # Workspace builds are never pushed to artifact servers
    
    1592
    +            return False
    
    1593
    +
    
    1582 1594
             if self.__strong_cached:
    
    1583 1595
                 # Artifact already in local cache
    
    1584 1596
                 return False
    

  • tests/frontend/workspace.py
    ... ... @@ -712,3 +712,73 @@ def test_inconsitent_pipeline_message(cli, tmpdir, datafiles, kind):
    712 712
             'build', element_name
    
    713 713
         ])
    
    714 714
         result.assert_main_error(ErrorDomain.PIPELINE, "inconsistent-pipeline-workspaced")
    
    715
    +
    
    716
    +
    
    717
    +@pytest.mark.datafiles(DATA_DIR)
    
    718
    +@pytest.mark.parametrize("strict", [("strict"), ("non-strict")])
    
    719
    +def test_cache_key_workspace_in_dependencies(cli, tmpdir, datafiles, strict):
    
    720
    +    checkout = os.path.join(str(tmpdir), 'checkout')
    
    721
    +    element_name, project, workspace = open_workspace(cli, os.path.join(str(tmpdir), 'repo-a'),
    
    722
    +                                                      datafiles, 'git', False)
    
    723
    +
    
    724
    +    element_path = os.path.join(project, 'elements')
    
    725
    +    back_dep_element_name = 'workspace-test-back-dep.bst'
    
    726
    +
    
    727
    +    # Write out our test target
    
    728
    +    element = {
    
    729
    +        'kind': 'compose',
    
    730
    +        'depends': [
    
    731
    +            {
    
    732
    +                'filename': element_name,
    
    733
    +                'type': 'build'
    
    734
    +            }
    
    735
    +        ]
    
    736
    +    }
    
    737
    +    _yaml.dump(element,
    
    738
    +               os.path.join(element_path,
    
    739
    +                            back_dep_element_name))
    
    740
    +
    
    741
    +    # Modify workspace
    
    742
    +    shutil.rmtree(os.path.join(workspace, 'usr', 'bin'))
    
    743
    +    os.makedirs(os.path.join(workspace, 'etc'))
    
    744
    +    with open(os.path.join(workspace, 'etc', 'pony.conf'), 'w') as f:
    
    745
    +        f.write("PONY='pink'")
    
    746
    +
    
    747
    +    # Configure strict mode
    
    748
    +    strict_mode = True
    
    749
    +    if strict != 'strict':
    
    750
    +        strict_mode = False
    
    751
    +    cli.configure({
    
    752
    +        'projects': {
    
    753
    +            'test': {
    
    754
    +                'strict': strict_mode
    
    755
    +            }
    
    756
    +        }
    
    757
    +    })
    
    758
    +
    
    759
    +    # Build artifact with dependency's modified workspace
    
    760
    +    assert cli.get_element_state(project, element_name) == 'buildable'
    
    761
    +    assert cli.get_element_key(project, element_name) == "{:?<64}".format('')
    
    762
    +    assert cli.get_element_state(project, back_dep_element_name) == 'waiting'
    
    763
    +    assert cli.get_element_key(project, back_dep_element_name) == "{:?<64}".format('')
    
    764
    +    result = cli.run(project=project, args=['build', back_dep_element_name])
    
    765
    +    result.assert_success()
    
    766
    +    assert cli.get_element_state(project, element_name) == 'cached'
    
    767
    +    assert cli.get_element_key(project, element_name) != "{:?<64}".format('')
    
    768
    +    assert cli.get_element_state(project, back_dep_element_name) == 'cached'
    
    769
    +    assert cli.get_element_key(project, back_dep_element_name) != "{:?<64}".format('')
    
    770
    +    result = cli.run(project=project, args=['build', back_dep_element_name])
    
    771
    +    result.assert_success()
    
    772
    +
    
    773
    +    # Checkout the result
    
    774
    +    result = cli.run(project=project, args=[
    
    775
    +        'checkout', back_dep_element_name, checkout
    
    776
    +    ])
    
    777
    +    result.assert_success()
    
    778
    +
    
    779
    +    # Check that the pony.conf from the modified workspace exists
    
    780
    +    filename = os.path.join(checkout, 'etc', 'pony.conf')
    
    781
    +    assert os.path.exists(filename)
    
    782
    +
    
    783
    +    # Check that the original /usr/bin/hello is not in the checkout
    
    784
    +    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]