Skip to content

Commit fcbfa21

Browse files
Espresso: Ensure runtime resourse is rebuilt when its id changes
1 parent d019d3d commit fcbfa21

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

espresso/mx.espresso/mx_espresso.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -727,13 +727,21 @@ def getBuildTask(self, args):
727727

728728

729729
class EspressoRuntimeResourceBuildTask(mx.JavaBuildTask):
730+
subject: EspressoRuntimeResourceProject
731+
730732
def __str__(self):
731733
return f'Generating {self.subject.name} internal resource and compiling it with {self._getCompiler().name()}'
732734

733735
@staticmethod
734736
def _template_file():
735737
return join(_suite.mxDir, 'espresso_runtime_resource.template')
736738

739+
def witness_file(self):
740+
return join(self.subject.get_output_root(), 'witness')
741+
742+
def witness_contents(self):
743+
return self.subject.resource_id
744+
737745
def needsBuild(self, newestInput):
738746
is_needed, reason = mx.ProjectBuildTask.needsBuild(self, newestInput)
739747
if is_needed:
@@ -748,6 +756,13 @@ def needsBuild(self, newestInput):
748756
])
749757
if newestInput is None or newestInput.isOlderThan(template_ts):
750758
newestInput = template_ts
759+
witness_file = self.witness_file()
760+
if not exists(witness_file):
761+
return True, witness_file + " doesn't exist"
762+
expected = self.witness_contents()
763+
with open(witness_file, 'r', encoding='utf-8') as f:
764+
if f.read() != expected:
765+
return True, "Outdated content"
751766
return super().needsBuild(newestInput)
752767

753768
@staticmethod
@@ -791,6 +806,10 @@ def build(self):
791806
with mx_util.SafeFileCreation(target_file) as sfc, open(sfc.tmpPath, 'w', encoding='utf-8') as f:
792807
f.write(file_content)
793808
super(EspressoRuntimeResourceBuildTask, self).build()
809+
witness_file = self.witness_file()
810+
mx_util.ensure_dirname_exists(witness_file)
811+
with mx_util.SafeFileCreation(witness_file) as sfc, io.open(sfc.tmpFd, mode='w', closefd=False, encoding='utf-8') as outfile:
812+
outfile.write(self.witness_contents())
794813

795814

796815
mx_sdk_vm.register_graalvm_component(mx_sdk_vm.GraalVmJreComponent(

0 commit comments

Comments
 (0)