nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 144 lines 5.2 kB view raw
1{ 2 jdk, 3 version, 4 src, 5 lib, 6 stdenv, 7 gradle, 8 extraConfig ? [ ], 9 extraNativeBuildInputs ? [ ], 10 rsync, 11 runCommand, 12 testers, 13}: 14 15# Each Corretto version is based on a corresponding OpenJDK version. So 16# building Corretto is more or less the same as building OpenJDK. Hence, the 17# Corretto derivation overrides the corresponding OpenJDK derivation in order 18# to have access to all the version-specific fixes for the various OpenJDK 19# builds. However, Corretto uses `gradle` as build tool (which in turn will 20# invoke `make`). The configure/build phases are adapted as needed. 21 22# The version scheme is different between OpenJDK & Corretto. 23# See https://github.com/corretto/corretto-17/blob/release-17.0.8.8.1/build.gradle#L40 24# "major.minor.security.build.revision" 25let 26 majorVersion = builtins.head (lib.strings.splitString "." version); # same as "featureVersion" for OpenJDK 27 pname = "corretto${majorVersion}"; 28in 29jdk.overrideAttrs ( 30 finalAttrs: oldAttrs: { 31 inherit pname version src; 32 33 nativeBuildInputs = 34 oldAttrs.nativeBuildInputs 35 ++ [ 36 jdk 37 gradle 38 rsync 39 ] 40 ++ extraNativeBuildInputs; 41 42 dontConfigure = true; 43 44 postPatch = 45 let 46 extra_config = builtins.concatStringsSep " " extraConfig; 47 in 48 (oldAttrs.postPatch or "") 49 + '' 50 # The rpm/deb task definitions require a Gradle plugin which we don't 51 # have and so the build fails. We'll simply empty them here because 52 # they are not needed anyways. The directories are kept because Gradle 53 # still expects them. 54 rm -rf installers/linux/universal/{rpm,deb}/{*,.*} 55 56 # These fixes are necessary as long as we use Gradle 9 to build 57 # Corretto but upstream is not yet using it. I.e. as long as upstream 58 # hasn't fixed compatibility with Gradle 9 issues. 59 find /build/source/installers -type d -exec cp /build/source/version.txt {}/version.txt \; 60 find /build/source/installers -name 'build.gradle' -exec sed -i '/fileMode =/d' {} \; 61 for d in source pre-build; do 62 # These subprojects (see settings.gradle) don't exist. Create them 63 # here so that Gradle doesn't complain. 64 mkdir /build/source/$d 65 cp /build/source/version.txt /build/source/$d/version.txt 66 done 67 68 # `/usr/bin/rsync` is invoked to copy the source tree. We don't have that. 69 for file in $(find installers -name "build.gradle"); do 70 substituteInPlace $file --replace-warn "workingDir '/usr/bin'" "workingDir '.'" 71 done 72 73 gradleFlagsArray+=(-Pcorretto.extra_config="${extra_config}") 74 ''; 75 76 # since we dontConfigure, we must run this manually 77 preBuild = "gradleConfigureHook"; 78 79 # The Linux installer is placed at linux/universal/tar whereas the MacOS 80 # one is at mac/tar. 81 gradleBuildTask = 82 if stdenv.hostPlatform.isDarwin then 83 ":installers:mac:tar:build" 84 else 85 ":installers:linux:universal:tar:packageBuildResults"; 86 87 postBuild = '' 88 # Prepare for the installPhase so that it looks like if a normal 89 # OpenJDK had been built. 90 dir=build/jdkImageName/images 91 mkdir -p $dir 92 file=$(find ./installers -name 'amazon-corretto-${version}*.tar.gz') 93 tar -xzf $file -C $dir 94 mv $dir/amazon-corretto-* $dir/jdk 95 chmod +x $dir/jdk/bin/* 96 '' 97 + oldAttrs.postBuild or ""; 98 99 installPhase = oldAttrs.installPhase + '' 100 # The installPhase will place everything in $out/lib/openjdk and 101 # reference through symlinks. We don't rewrite the installPhase but at 102 # least move the folder to convey that this is not OpenJDK anymore. 103 mv $out/lib/openjdk $out/lib/corretto 104 ln -s $out/lib/corretto $out/lib/openjdk 105 ''; 106 107 passthru = 108 let 109 pkg = finalAttrs.finalPackage; 110 in 111 oldAttrs.passthru 112 // { 113 tests = { 114 version = testers.testVersion { package = pkg; }; 115 vendor = runCommand "${pname}-vendor" { nativeBuildInputs = [ pkg ]; } '' 116 output=$(${pkg.meta.mainProgram} -XshowSettings:properties -version 2>&1 | grep vendor) 117 grep -Fq "java.vendor = Amazon.com Inc." - <<< "$output" && touch $out 118 ''; 119 compiler = runCommand "${pname}-compiler" { nativeBuildInputs = [ pkg ]; } '' 120 cat << EOF > Main.java 121 class Main { 122 public static void main(String[] args) { 123 System.out.println("Hello, World!"); 124 } 125 } 126 EOF 127 ${pkg}/bin/javac Main.java 128 ${pkg}/bin/java Main | grep -q "Hello, World!" && touch $out 129 ''; 130 }; 131 }; 132 133 # Some of the OpenJDK derivation set their `pos` by hand. We need to 134 # overwrite this in order to point to Corretto, not OpenJDK. 135 pos = __curPos; 136 meta = oldAttrs.meta // { 137 homepage = "https://aws.amazon.com/corretto"; 138 license = lib.licenses.gpl2Only; 139 description = "Amazon's distribution of OpenJDK"; 140 maintainers = with lib.maintainers; [ rollf ]; 141 teams = [ ]; 142 }; 143 } 144)