Skip to content

Commit

Permalink
RFR [GR-53780] Introduce DownloadableLibrary to expose the specified …
Browse files Browse the repository at this point in the history
…download urls

PullRequest: mx/1791
  • Loading branch information
zapster committed May 2, 2024
2 parents 1a03439 + 892d789 commit 6caac1b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion common.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Jsonnet files should not include this file directly but use ci/common.jsonnet instead."
],

"mx_version": "7.22.6",
"mx_version": "7.22.7",

"COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet",
"jdks": {
Expand Down
4 changes: 4 additions & 0 deletions src/mx/_impl/build/suite/dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ def isBaseLibrary(self):
from ...mx import BaseLibrary
return isinstance(self, BaseLibrary)

def isDownloadableLibrary(self):
from ...mx import DownloadableLibrary
return isinstance(self, DownloadableLibrary)

def isLibrary(self):
from ...mx import Library
return isinstance(self, Library)
Expand Down
36 changes: 23 additions & 13 deletions src/mx/_impl/mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
"ZipExtractor",
"FileInfo",
"BaseLibrary",
"DownloadableLibrary",
"ResourceLibrary",
"PackedResourceLibrary",
"JreLibrary",
Expand Down Expand Up @@ -8275,15 +8276,29 @@ def _check_hash_specified(self, path, name):
self.abort(f'Missing "{name}" property for library {self}')


class ResourceLibrary(BaseLibrary, _RewritableLibraryMixin):
class DownloadableLibrary(BaseLibrary):
def __init__(self, suite, name, optional, urls, digest, sourceUrls, sourceDigest, theLicense, **kwArgs):
BaseLibrary.__init__(self, suite, name, optional, theLicense, **kwArgs)
# These are substituted but not rewritten urls. For informational purposes only. Do not use for downloading.
self.original_urls = self.substVarsList(urls)
self.original_sourceUrls = self.substVarsList(sourceUrls) if sourceUrls is not None else None

# Perform URL and digest rewriting before potentially generating cache path.
assert digest is None or isinstance(digest, Digest), f'{digest} is of type {type(digest)}'
self.urls, self.digest = mx_urlrewrites._rewrite_urls_and_digest(self.original_urls, digest)
if sourceUrls is not None:
assert sourceDigest is None or isinstance(sourceDigest, Digest), f'{sourceDigest} is of type {type(sourceDigest)}'
self.sourceUrls, self.sourceDigest = mx_urlrewrites._rewrite_urls_and_digest(self.substVarsList(sourceUrls), sourceDigest)
else:
self.sourceUrls, self.sourceDigest = None, None


class ResourceLibrary(DownloadableLibrary, _RewritableLibraryMixin):
"""
A library that is just a resource and therefore not a `ClasspathDependency`.
"""
def __init__(self, suite, name, path, optional, urls, digest, ext=None, **kwArgs):
BaseLibrary.__init__(self, suite, name, optional, None, **kwArgs)

# Perform URL and digest rewriting before potentially generating cache path.
self.urls, self.digest = mx_urlrewrites._rewrite_urls_and_digest(self.substVarsList(urls), digest)
DownloadableLibrary.__init__(self, suite, name, optional, urls, digest, sourceUrls=None, sourceDigest=None, theLicense=None, **kwArgs)

# Path can be generated from URL and digest if needed.
self.ext = ext
Expand Down Expand Up @@ -8568,7 +8583,7 @@ def get_declaring_module_name(self):
return getattr(self, 'module')


class Library(BaseLibrary, ClasspathDependency, _RewritableLibraryMixin):
class Library(DownloadableLibrary, ClasspathDependency, _RewritableLibraryMixin):
"""
A library that is provided (built) by some third-party and made available via a URL.
A Library may have dependencies on other Libraries as expressed by the "deps" field.
Expand All @@ -8579,14 +8594,9 @@ class Library(BaseLibrary, ClasspathDependency, _RewritableLibraryMixin):
N.B. Not obvious but a Library can be an annotationProcessor
"""
def __init__(self, suite, name, path, optional, urls, digest, sourcePath, sourceUrls, sourceDigest, deps, theLicense, ignore=False, **kwArgs):
BaseLibrary.__init__(self, suite, name, optional, theLicense, **kwArgs)
DownloadableLibrary.__init__(self, suite, name, optional, urls, digest, sourceUrls, sourceDigest, theLicense, **kwArgs)
ClasspathDependency.__init__(self, **kwArgs)

# Perform URL and digest rewriting before potentially generating cache path.
assert digest is None or isinstance(digest, Digest), f'{digest} is of type {type(digest)}'
self.urls, self.digest = mx_urlrewrites._rewrite_urls_and_digest(self.substVarsList(urls), digest)
self.sourceUrls, self.sourceDigest = mx_urlrewrites._rewrite_urls_and_digest(self.substVarsList(sourceUrls), sourceDigest)

# Path and sourcePath can be generated from URL and digest if needed.
self.path = self._normalize_path(path)
self.sourcePath = self._normalize_path(sourcePath)
Expand Down Expand Up @@ -18170,7 +18180,7 @@ def alarm_handler(signum, frame):
_CACHE_DIR = get_env('MX_CACHE_DIR', join(dot_mx_dir(), 'cache'))

# The version must be updated for every PR (checked in CI) and the comment should reflect the PR's issue
version = VersionSpec("7.24.0") # GR-45840 Deal with encoding errors during printing
version = VersionSpec("7.25.0") # DownloadableLibrary

_mx_start_datetime = datetime.utcnow()

Expand Down

0 comments on commit 6caac1b

Please sign in to comment.