Skip to content

Commit

Permalink
[GR-58516] Added support for specifying a JDK selector on the fetch-j…
Browse files Browse the repository at this point in the history
…dk command line.

PullRequest: mx/1839
  • Loading branch information
dougxc committed Sep 26, 2024
2 parents fa8a52a + f93f581 commit f5d0e49
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/mx/_impl/mx.py
Original file line number Diff line number Diff line change
Expand Up @@ -18204,7 +18204,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.32.0") # GR-56702: fix manifest version
version = VersionSpec("7.32.1") # GR-58516] Added support for specifying a JDK selector on the fetch-jdk command line

_mx_start_datetime = datetime.utcnow()

Expand Down
9 changes: 6 additions & 3 deletions src/mx/_impl/mx_fetchjdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def _parse_args(args):
path_list.add(join(_mx_home, 'jdk-binaries.json'))
default_jdk_binaries_location = str(path_list)

parser = ArgumentParser(prog='mx fetch-jdk', usage='%(prog)s [options] [<jdk-id>]' + r"""
parser = ArgumentParser(prog='mx fetch-jdk', usage='%(prog)s [options] [<jdk-id> [<selector>]]' + r"""
Download and install JDKs.
The set of JDKs available for download are specified by the "jdks" field of the JSON
Expand Down Expand Up @@ -374,6 +374,7 @@ def _parse_args(args):
jdk_id_group = parser.add_mutually_exclusive_group()
jdk_id_group.add_argument('jdk_id_pos', action='store', metavar='<jdk-id>', nargs='?', help='see --jdk-id')
jdk_id_group.add_argument('--jdk-id', '--java-distribution', action='store', metavar='<id>', help='Identifier of the JDK that should be downloaded (e.g., "labsjdk-ce-11" or "openjdk8")')
parser.add_argument('selector', action='store', metavar='<val>', nargs='?', help=f'refine base JDK by selector <val>')
parser.add_argument('--configuration', action='store', metavar='<path>', help=f'location of JSON file containing JDK definitions (default: {default_jdk_defs_location})')
parser.add_argument('--jdk-binaries', action='store', metavar='<path>', help=f'{os.pathsep} separated JSON files specifying location of JDK binaries (default: {default_jdk_binaries_location})')
parser.add_argument('--to', action='store', metavar='<dir>', help=f"location where JDK will be installed. Specify <system> to use the system default location. (default: {settings['jdks-dir']})")
Expand Down Expand Up @@ -417,7 +418,7 @@ def _parse_args(args):
# use positional or option argument
jdk_id = args.jdk_id_pos or args.jdk_id
if jdk_id is not None:
settings["jdk-binary"] = _get_jdk_binary_or_abort(jdk_binaries, jdk_id)
settings["jdk-binary"] = _get_jdk_binary_or_abort(jdk_binaries, jdk_id, args.selector)
else:
if is_quiet():
parser.print_usage()
Expand All @@ -439,10 +440,12 @@ def _parse_args(args):
return settings


def _get_jdk_binary_or_abort(jdk_binaries, jdk_id):
def _get_jdk_binary_or_abort(jdk_binaries, jdk_id, selector):
jdk_binary = jdk_binaries.get(jdk_id)
if not jdk_binary:
mx.abort(f"Unknown JDK identifier: {jdk_id} [Known JDKs: {', '.join(jdk_binaries.keys())}]")
if selector is not None:
return jdk_binary.with_selector(selector)
return jdk_binary


Expand Down

0 comments on commit f5d0e49

Please sign in to comment.