From 727819f296416124d66d619a29d206b3d5663ccf Mon Sep 17 00:00:00 2001 From: Gregory Borodin Date: Sat, 5 Oct 2024 03:13:41 +0200 Subject: [PATCH] Use LnBinary instead of hardcoded /bin/ln in jvm.sh (#21488) Fixes https://github.com/pantsbuild/pants/issues/21487 --- docs/notes/2.24.x.md | 2 ++ src/python/pants/jvm/jdk_rules.py | 6 ++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/notes/2.24.x.md b/docs/notes/2.24.x.md index 48f6c233fbb..039226cab3c 100644 --- a/docs/notes/2.24.x.md +++ b/docs/notes/2.24.x.md @@ -42,6 +42,8 @@ Compression of class files into a jar file is not reading or writing from the re Fixed a coursier fetch wrapper script bug on nixos. +Fixed a jvm.sh script bug on nixos. + #### Kotlin The kotlin linter, [ktlint](https://pinterest.github.io/ktlint/), has been updated to version 1.3.1. diff --git a/src/python/pants/jvm/jdk_rules.py b/src/python/pants/jvm/jdk_rules.py index 12d3dbdbd07..3d4619b9ff4 100644 --- a/src/python/pants/jvm/jdk_rules.py +++ b/src/python/pants/jvm/jdk_rules.py @@ -14,7 +14,7 @@ from typing import ClassVar, Iterable, Mapping from pants.core.util_rules.environments import EnvironmentTarget -from pants.core.util_rules.system_binaries import BashBinary +from pants.core.util_rules.system_binaries import BashBinary, LnBinary from pants.engine.fs import CreateDigest, Digest, FileContent, FileDigest, MergeDigests from pants.engine.internals.selectors import Get from pants.engine.process import FallibleProcessResult, Process, ProcessCacheScope @@ -201,6 +201,7 @@ async def prepare_jdk_environment( coursier: Coursier, nailgun_: Nailgun, bash: BashBinary, + ln: LnBinary, request: JdkRequest, env_target: EnvironmentTarget, ) -> JdkEnvironment: @@ -276,13 +277,14 @@ def prefixed(arg: str) -> str: # TODO: Locate `ln`. version_comment = "\n".join(f"# {line}" for line in java_version.splitlines()) + ln_path = shlex.quote(ln.path) jdk_preparation_script = textwrap.dedent( # noqa: PNT20 f"""\ # pants javac script using Coursier {coursier_jdk_option}. `java -version`:" {version_comment} set -eu - /bin/ln -s "$({java_home_command})" "${{PANTS_INTERNAL_ABSOLUTE_PREFIX}}{JdkEnvironment.java_home}" + {ln_path} -s "$({java_home_command})" "${{PANTS_INTERNAL_ABSOLUTE_PREFIX}}{JdkEnvironment.java_home}" exec "$@" """ )