From ff2c2ae678f21b9e24ed030755dd9b6094f77182 Mon Sep 17 00:00:00 2001 From: Qingsong Chen Date: Mon, 25 May 2026 03:38:14 +0000 Subject: [PATCH] Add jtreg overlay to AsterNixOS AsterNixOS uses OpenJDK 21 for jtreg package, but upstream jtreg does not build in that environment out of the box. The vendored patches address two separate issues: - `0001-Make-jtreg-use-tools-from-PATH.patch` is a long-term NixOS compatibility fix. Upstream hardcodes `/bin/*` and `/usr/bin/*` tools when generating docs, jar manifests, and release metadata, which fails in the Nix sandbox. - `0002-Drop-Werror-for-helper-classes-on-JDK-21.patch` is a short-term workaround for `this-escape` warnings emitted by `javac` 21 in `SearchPath.java` and related helper classes. --- .typos.toml | 1 + .../templates/aster_configuration.nix | 1 + distro/cachix/default.nix | 1 + .../0001-Make-jtreg-use-tools-from-PATH.patch | 150 +++++++++++++++++ ...-Werror-for-helper-classes-on-JDK-21.patch | 34 ++++ distro/etc_nixos/overlays/jtreg/default.nix | 153 ++++++++++++++++++ 6 files changed, 340 insertions(+) create mode 100644 distro/etc_nixos/overlays/jtreg/0001-Make-jtreg-use-tools-from-PATH.patch create mode 100644 distro/etc_nixos/overlays/jtreg/0002-Drop-Werror-for-helper-classes-on-JDK-21.patch create mode 100644 distro/etc_nixos/overlays/jtreg/default.nix diff --git a/.typos.toml b/.typos.toml index a8661cb46..d234252a4 100644 --- a/.typos.toml +++ b/.typos.toml @@ -27,6 +27,7 @@ typ = "typ" sigfault = "sigfault" sems = "sems" THRE = "THRE" +TestNG = "TestNG" # Files with svg suffix are ignored to check. [type.svg] diff --git a/distro/aster_nixos_installer/templates/aster_configuration.nix b/distro/aster_nixos_installer/templates/aster_configuration.nix index 9ef8092b4..b7ff70099 100644 --- a/distro/aster_nixos_installer/templates/aster_configuration.nix +++ b/distro/aster_nixos_installer/templates/aster_configuration.nix @@ -36,6 +36,7 @@ (import ./overlays/podman/default.nix) (import ./overlays/switch-to-configuration-ng/default.nix) (import ./overlays/systemd/default.nix) + (import ./overlays/jtreg/default.nix) ]; # The Asterinas NixOS special options. diff --git a/distro/cachix/default.nix b/distro/cachix/default.nix index 13449842d..2eb412503 100644 --- a/distro/cachix/default.nix +++ b/distro/cachix/default.nix @@ -16,6 +16,7 @@ let podman podman.man aster_systemd + jtreg ] ++ (with nixos.config; [ system.build.toplevel systemd.package diff --git a/distro/etc_nixos/overlays/jtreg/0001-Make-jtreg-use-tools-from-PATH.patch b/distro/etc_nixos/overlays/jtreg/0001-Make-jtreg-use-tools-from-PATH.patch new file mode 100644 index 000000000..0b4e6627b --- /dev/null +++ b/distro/etc_nixos/overlays/jtreg/0001-Make-jtreg-use-tools-from-PATH.patch @@ -0,0 +1,150 @@ +From 7a8bc3c2d55f1bc4a4b472a4de2ac6d9d7690001 Mon Sep 17 00:00:00 2001 +From: Qingsong Chen +Date: Mon, 2 Mar 2026 03:26:07 +0000 +Subject: [PATCH 1/2] Make jtreg use tools from PATH + +`jtreg` hardcodes many helper tools as `/bin/*` or `/usr/bin/*`. Those +paths do not exist in the Nix build sandbox, so the build fails before +it can produce the image. Use tool names instead and rely on `PATH`, +which the Nix build environment already populates. +--- + make/Defs.gmk | 80 +++++++++++++++++++++++--------------------------- + make/Rules.gmk | 2 +- + make/jtreg.gmk | 2 +- + 3 files changed, 39 insertions(+), 45 deletions(-) + +diff --git a/make/Defs.gmk b/make/Defs.gmk +index 9089e9c7d..b37c5ffd4 100644 +--- a/make/Defs.gmk ++++ b/make/Defs.gmk +@@ -134,49 +134,31 @@ REGTEST_TOOL_JAVAC_OPTIONS = \ + + #----- Unix commands + +-AWK = /usr/bin/awk +-CAT = /bin/cat +-CHMOD = /bin/chmod +-CP = /bin/cp +-DIFF = /usr/bin/diff +-ECHO = /bin/echo +-FIND = /usr/bin/find +-GREP := $(shell if [ -r /bin/grep ]; then echo /bin/grep ; else echo /usr/bin/grep ; fi ) +-LN = /bin/ln +-LS = /bin/ls +-MKDIR = /bin/mkdir +-MV = /bin/mv +-PANDOC := $(shell if [ -r /usr/bin/pandoc ]; then \ +- echo /usr/bin/pandoc ; \ +- elif [ -r /usr/local/bin/pandoc ]; then \ +- echo /usr/local/bin/pandoc ; \ +- elif [ -r /opt/homebrew/bin/tidy ]; then \ +- echo /opt/homebrew/bin/pandoc ; \ +- else \ +- echo /bin/echo "pandoc not available" ; \ +- fi ) +-PERL = /usr/bin/perl +-PRINTF = /usr/bin/printf +-RM = /bin/rm -rf +-SED := $(shell if [ -r /bin/sed ]; then echo /bin/sed ; else echo /usr/bin/sed ; fi ) +-SH = /bin/sh +-SORT = /usr/bin/sort +-TEST = /usr/bin/test +-ifeq ($(SYSTEM_UNAME), Darwin) +-TIDY := $(shell if [ -r /usr/local/bin/tidy ]; then \ +- echo /usr/local/bin/tidy ; \ +- elif [ -r /opt/homebrew/bin/tidy ]; then \ +- echo /opt/homebrew/bin/tidy ; \ +- else \ +- echo /usr/bin/tidy ; \ +- fi ) +-else +-TIDY = /usr/bin/tidy +-endif +-TOUCH = /usr/bin/touch +-UNZIP = /usr/bin/unzip +-WC = /usr/bin/wc +-ZIP = /usr/bin/zip ++AWK = awk ++CAT = cat ++CHMOD = chmod ++CP = cp ++DIFF = diff ++ECHO = echo ++FIND = find ++GREP := grep ++LN = ln ++LS = ls ++MKDIR = mkdir ++MV = mv ++PANDOC := pandoc ++PERL = perl ++PRINTF = printf ++RM = rm -rf ++SED := sed ++SH = sh ++SORT = sort ++TEST = test ++TIDY = tidy ++TOUCH = touch ++UNZIP = unzip ++WC = wc ++ZIP = zip + + + #---------------------------------------------------------------------- +@@ -212,12 +194,12 @@ BUILD_MILESTONE = dev + BUILD_NUMBER = b00 + + # don't eval dates here directly, because that leads to unstable builds +-#BUILD_YEAR:sh = /bin/date +"%Y" +-BUILD_YEAR_CMD = /bin/date '+%Y' +-#BUILD_DOCDATE:sh = /bin/date +"%B %d, %Y" +-BUILD_DOCDATE_CMD = /bin/date +'%B %d, %Y' +-#BUILD_ZIPDATE:sh = /bin/date '+%d %h %Y' +-BUILD_ZIPDATE_CMD = /bin/date '+%d %h %Y' ++#BUILD_YEAR:sh = date +"%Y" ++BUILD_YEAR_CMD = date '+%Y' ++#BUILD_DOCDATE:sh = date +"%B %d, %Y" ++BUILD_DOCDATE_CMD = date +'%B %d, %Y' ++#BUILD_ZIPDATE:sh = date '+%d %h %Y' ++BUILD_ZIPDATE_CMD = date '+%d %h %Y' + BUILD_NONFCS_MILESTONE_sh = echo $(BUILD_MILESTONE) | sed -e 's/[fF][cC][sS]//' + BUILD_NONFCS_MILESTONE = $(BUILD_NONFCS_MILESTONE_sh:sh) + +@@ -226,7 +208,7 @@ ZIPSFX_VERSION_sh = echo '$(BUILD_VERSION)' | sed -e 's|\([^0-9][^0-9]*\)|_|g' + ZIPSFX_MILESTONE_sh = echo '$(BUILD_MILESTONE)' + ZIPSFX_BUILD_sh = echo '$(BUILD_NUMBER)' + ZIPSFX_NEWBUILD_sh = echo '$(BUILD_NUMBER)' | sed -e 's|[^[0-9]||g' | xargs printf "%d" +-ZIPSFX_DATE_sh = echo "`$(BUILD_ZIPDATE_CMD)`" | /usr/bin/tr -s '[A-Z] ' '[a-z]_' ++ZIPSFX_DATE_sh = echo "`$(BUILD_ZIPDATE_CMD)`" | tr -s '[A-Z] ' '[a-z]_' + + VERBOSE_ZIP_SUFFIX = $(shell $(ZIPSFX_VERSION_sh))-$(shell $(ZIPSFX_MILESTONE_sh))-bin-$(shell $(ZIPSFX_BUILD_sh))-$(shell $(ZIPSFX_DATE_sh)) + +diff --git a/make/Rules.gmk b/make/Rules.gmk +index 1a9a5601e..c39742150 100644 +--- a/make/Rules.gmk ++++ b/make/Rules.gmk +@@ -73,7 +73,7 @@ $(IMAGES_DIR)/%.jar: pkgsToFiles.sh + echo "$(@F:%.jar=%)-Build: $(BUILD_NUMBER)" ; \ + echo "$(@F:%.jar=%)-BuildJavaVersion: `$(JDKJAVA) -fullversion 2>&1 | awk '{print $$NF}' | \ + sed -e 's|^"\(.*\)"$$|Java(TM) 2 SDK, Version \1|'`" ; \ +- echo "$(@F:%.jar=%)-BuildDate: `/bin/date +'%B %d, %Y'`" ; \ ++ echo "$(@F:%.jar=%)-BuildDate: `date +'%B %d, %Y'`" ; \ + ) \ + > $(@:$(IMAGES_DIR)/%.jar=$(BUILDDIR)/jarData/%/manifest.txt) + sh pkgsToFiles.sh $(CLASSDIR) $($(@F:%.jar=PKGS.JAR.%)) > $(@:$(IMAGES_DIR)/%.jar=$(BUILDDIR)/jarData/%/includes.txt) +diff --git a/make/jtreg.gmk b/make/jtreg.gmk +index 5de111727..1e8f8fd27 100644 +--- a/make/jtreg.gmk ++++ b/make/jtreg.gmk +@@ -344,7 +344,7 @@ ID_COMMAND := $(PRINTF) "git:%s%s\n" \ + + $(JTREG_IMAGEDIR)/release: + echo "JTREG_VERSION=$(BUILD_VERSION) $(BUILD_NUMBER)" > $@ +- echo "BUILD_DATE=`/bin/date +'%B %d, %Y'`" >> $@ ++ echo "BUILD_DATE=`date +'%B %d, %Y'`" >> $@ + if [ -r $(TOPDIR)/.git ]; then \ + echo "SOURCE=$$($(ID_COMMAND))" >> $@ ; \ + elif [ -n "$(SRCREV)" -a -r $(SRCREV) ]; then \ +-- +2.43.0 diff --git a/distro/etc_nixos/overlays/jtreg/0002-Drop-Werror-for-helper-classes-on-JDK-21.patch b/distro/etc_nixos/overlays/jtreg/0002-Drop-Werror-for-helper-classes-on-JDK-21.patch new file mode 100644 index 000000000..4222ee0e5 --- /dev/null +++ b/distro/etc_nixos/overlays/jtreg/0002-Drop-Werror-for-helper-classes-on-JDK-21.patch @@ -0,0 +1,34 @@ +From 7a8bc3c2d55f1bc4a4b472a4de2ac6d9d7690002 Mon Sep 17 00:00:00 2001 +From: Qingsong Chen +Date: Mon, 2 Mar 2026 03:26:08 +0000 +Subject: [PATCH 2/2] Drop -Werror for helper classes on JDK 21 + +When built with OpenJDK 21, `jtreg`'s helper classes trigger +`this-escape` warnings in `SearchPath.java`. Remove `-Werror` +for the helper compilations so `jtreg` builds with the +JDK shipped in NixOS. +--- + make/Defs.gmk | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/make/Defs.gmk b/make/Defs.gmk +index b37c5ff..5a14d04 100644 +--- a/make/Defs.gmk ++++ b/make/Defs.gmk +@@ -124,12 +124,12 @@ REGTEST_TOOL_PATCH_JAVA_BASE_OPTIONS = --patch-module java.base=$(JAVADIR) + # for files needed to run agentvm and othervm tests (on platforms back to JDK 8) + REGTEST_AGENT_JAVAC = $(JDKHOME)/bin/javac + REGTEST_AGENT_JAVAC_OPTIONS = \ +- $(AGENT_JAVAC_SOURCE_TARGET) -Xlint:all,-options,-deprecation -Werror ++ $(AGENT_JAVAC_SOURCE_TARGET) -Xlint:all,-options,-deprecation + + # for files needed for jtreg tool + REGTEST_TOOL_JAVAC = $(JDKHOME)/bin/javac + REGTEST_TOOL_JAVAC_OPTIONS = \ +- $(TOOL_JAVAC_SOURCE_TARGET) -Xlint:all,-options,-deprecation -Werror ++ $(TOOL_JAVAC_SOURCE_TARGET) -Xlint:all,-options,-deprecation + + + #----- Unix commands +-- +2.43.0 diff --git a/distro/etc_nixos/overlays/jtreg/default.nix b/distro/etc_nixos/overlays/jtreg/default.nix new file mode 100644 index 000000000..b38fff9a8 --- /dev/null +++ b/distro/etc_nixos/overlays/jtreg/default.nix @@ -0,0 +1,153 @@ +final: prev: { + jtreg = let + # JT Harness + jtharness = prev.stdenv.mkDerivation rec { + pname = "jtharness"; + version = "6.0-b24"; + src = prev.fetchzip { + url = + "https://github.com/openjdk/jtharness/archive/refs/tags/jt${version}.zip"; + sha256 = "sha256-E0YlUXBVwC+m7ZVF/RYqKXpRneMYY9y3ewtz8+26T/U"; + }; + buildInputs = with prev.pkgs; [ ant openjdk21 ]; + buildPhase = '' + ant -DBUILD_DIR=$NIX_BUILD_TOP -f build/build.xml dist + ''; + installPhase = '' + mkdir -p $out + cp -r $NIX_BUILD_TOP/binaries/* $out + ''; + }; + + # AsmTools + asmtools = prev.stdenv.mkDerivation rec { + pname = "asmtools"; + version = "7.0-b09"; + src = prev.fetchzip { + url = + "https://github.com/openjdk/asmtools/archive/refs/tags/${version}.zip"; + sha256 = "sha256-jgrAmfgCPisAEMP9oTCKmdjMeLuBpVPKg4pW9SL/4lY"; + }; + buildInputs = with prev.pkgs; [ ant openjdk21 ]; + buildPhase = '' + ant -DBUILD_DIR=$NIX_BUILD_TOP -f build/build.xml release + ''; + installPhase = '' + mkdir -p $out + cp -r $NIX_BUILD_TOP/release/* $out + ''; + }; + + # JUnit Platform Console Standalone (includes JUnit Jupiter, JUnit Vintage, and dependencies) + junit = prev.stdenv.mkDerivation rec { + pname = "junit"; + version = "1.8.2"; + + junit = prev.fetchurl { + url = + "https://repo1.maven.org/maven2/org/junit/platform/junit-platform-console-standalone/${version}/junit-platform-console-standalone-${version}.jar"; + sha256 = "sha256-3EmPI0Io+ByBi+z7a39x9z3ysOmV+T8lwF/O0Md+Y1Y"; + }; + + license = prev.fetchurl { + url = + "https://github.com/junit-team/junit-framework/raw/refs/heads/main/LICENSE.md"; + sha256 = "sha256-WqTNRMERrdF40cLi/jbVikhAEsgBZ9+SX4Js1k1BG/A"; + }; + + buildCommand = '' + mkdir -p $out/lib + + cp ${license} $out/LICENSE.md + cp ${junit} $out/lib/junit-platform-console-standalone.jar + ''; + }; + + # TestNG and its dependencies + testng = prev.stdenv.mkDerivation rec { + pname = "testng"; + version = "7.3.0"; + + testng = prev.fetchurl { + url = + "https://repo1.maven.org/maven2/org/testng/testng/${version}/testng-${version}.jar"; + sha256 = "sha256-Y3J0iPlxfVfw0KD+5aH8EKK+nPz/LsOnGHZW1mPAd04"; + }; + + license = prev.fetchurl { + url = + "https://github.com/testng-team/testng/raw/refs/tags/${version}/LICENSE.txt"; + sha256 = "sha256-wbnfEnXnafPbqwANHkV6LUsPKOtdpsd+SNw37rogLtc"; + }; + + jcommander = prev.fetchurl { + url = + "https://repo1.maven.org/maven2/com/beust/jcommander/1.78/jcommander-1.78.jar"; + sha256 = "sha256-eJHeu4S1+D6b1XWT6+zjOZq74P2TjPMGs1NMV5E7lhU"; + }; + + guice = prev.fetchurl { + url = + "https://repo1.maven.org/maven2/com/google/inject/guice/4.2.3/guice-4.2.3.jar"; + sha256 = "sha256-oh5Q/7tn563FtGz3ueGkgPHg8E/UIB3bHGXakSkGAa8"; + }; + + buildCommand = '' + mkdir -p $out/lib + + cp ${license} $out/LICENSE.txt + cp ${testng} $out/lib/testng.jar + cp ${jcommander} $out/lib/jcommander.jar + cp ${guice} $out/lib/guice.jar + ''; + }; + in prev.stdenv.mkDerivation rec { + pname = "jtreg"; + version = "7.3.1"; + number = "1"; + src = prev.fetchzip { + url = + "https://github.com/openjdk/jtreg/archive/refs/tags/jtreg-${version}+${number}.zip"; + sha256 = "sha256-m9/BkM2fVfAFYMCMnCEkqZhRbYQYeo2YCyZCt+b0ggg"; + }; + + patches = [ + ./0001-Make-jtreg-use-tools-from-PATH.patch + ./0002-Drop-Werror-for-helper-classes-on-JDK-21.patch + ]; + + JAVATEST_JAR = "${jtharness}/lib/javatest.jar"; + JTHARNESS_NOTICES = "${jtharness}/legal/copyright.txt ${jtharness}/LICENSE"; + + ASMTOOLS_JAR = "${asmtools}/lib/asmtools.jar"; + ASMTOOLS_NOTICES = "${asmtools}/LICENSE"; + + JUNIT_JARS = "${junit}/lib/junit-platform-console-standalone.jar"; + JUNIT_NOTICES = "${junit}/LICENSE.md"; + + TESTNG_JARS = + "${testng}/lib/testng.jar ${testng}/lib/jcommander.jar ${testng}/lib/guice.jar"; + TESTNG_NOTICES = "${testng}/LICENSE.txt"; + + JDKHOME = "${prev.pkgs.openjdk21}"; + JAVA_SPECIFICATION_VERSION = "21"; + + buildInputs = with prev.pkgs; [ + ant + openjdk21 + hostname + pandoc + perl + html-tidy + unzip + zip + ]; + buildPhase = '' + make BUILD_VERSION=${version} BUILD_NUMBER=${number} -C make + ''; + installPhase = '' + mkdir -p $out + cp -r build/images/jtreg/* $out + ''; + }; +}