Skip to content

Commit

Permalink
[GR-47129] Rebuild modules when module-info changes.
Browse files Browse the repository at this point in the history
PullRequest: mx/1638
  • Loading branch information
dougxc committed Jul 14, 2023
2 parents 956392f + ba667e6 commit ae0601c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18423,7 +18423,7 @@ def alarm_handler(signum, frame):
abort(1, killsig=signal.SIGINT)

# The version must be updated for every PR (checked in CI) and the comment should reflect the PR's issue
version = VersionSpec("6.28.0") # LayoutDirDistribution
version = VersionSpec("6.28.1") # GR-47129: rebuild modules when module-info changes

_mx_start_datetime = datetime.utcnow()
_last_timestamp = _mx_start_datetime
Expand Down
31 changes: 30 additions & 1 deletion mx_jardistribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ def make_archive(self, javac_daemon=None):
jmd = mx.make_java_module(self, jdk, stager.bin_archive, javac_daemon=javac_daemon)
if jmd:
setattr(self, '.javaModule', jmd)
mi_file = self._module_info_save_file()
with mx.open(mi_file, 'w') as fp:
fp.write(self._module_info_as_json())
dependency_file = self._jmod_build_jdk_dependency_file()
with mx.open(dependency_file, 'w') as fp:
fp.write(jdk.home)
Expand Down Expand Up @@ -562,6 +565,20 @@ def _jmod_build_jdk_dependency_file(self):
"""
return self.original_path() + '.jdk'

def _module_info_save_file(self):
"""
Gets the path to the file saving `_module_info_as_json()`.
"""
return self.original_path() + '.module-info'

def _module_info_as_json(self):
"""
Gets the moduleInfo attribute(s) as sorted json.
"""
import json
module_infos = {name:getattr(self, name) for name in dir(self) if name == 'moduleInfo' or name.startswith('moduleInfo:')}
return json.dumps(module_infos, sort_keys=True, indent=2)

def needsUpdate(self, newestInput):
res = mx._needsUpdate(newestInput, self.path)
if res:
Expand Down Expand Up @@ -590,8 +607,20 @@ def needsUpdate(self, newestInput):
res = mx._needsUpdate(self.original_path(), pickle_path)
if res:
return res
# Rebuild the jmod file if different JDK used previously
jdk = mx.get_jdk(compliance)

# Rebuild if module info changed
mi_file = self._module_info_save_file()
if exists(mi_file):
module_info = self._module_info_as_json()
with mx.open(mi_file) as fp:
saved_module_info = fp.read()
if module_info != saved_module_info:
import difflib
mx.log(f'{self} module info changed:' + os.linesep + ''.join(difflib.unified_diff(saved_module_info.splitlines(1), module_info.splitlines(1))))
return 'module-info changed'

# Rebuild the jmod file if different JDK used previously
dependency_file = self._jmod_build_jdk_dependency_file()
if exists(dependency_file):
with mx.open(dependency_file) as fp:
Expand Down

0 comments on commit ae0601c

Please sign in to comment.