Unverified Commit 186c3e34 authored by Pol Dellaiera's avatar Pol Dellaiera Committed by GitHub
Browse files

Merge pull request #296549 from TomaSajt/strip-java-archives-hook

add stripJavaArchivesHook and use treewide
parents ced4e31b e08f26cd
Loading
Loading
Loading
Loading
+26 −3
Original line number Diff line number Diff line
@@ -4,12 +4,31 @@ Ant-based Java packages are typically built from source as follows:

```nix
stdenv.mkDerivation {
  name = "...";
  pname = "...";
  version = "...";

  src = fetchurl { ... };

  nativeBuildInputs = [ jdk ant ];
  nativeBuildInputs = [
    ant
    jdk
    stripJavaArchivesHook # removes timestamp metadata from jar files
  ];

  buildPhase = "ant";
  buildPhase = ''
    runHook preBuild
    ant # build the project using ant
    runHook postBuild
  '';

  installPhase = ''
    runHook preInstall

    # copy generated jar file(s) to an appropriate location in $out
    install -Dm644 build/foo.jar $out/share/java/foo.jar

    runHook postInstall
  '';
}
```

@@ -17,6 +36,10 @@ Note that `jdk` is an alias for the OpenJDK (self-built where available,
or pre-built via Zulu). Platforms with OpenJDK not (yet) in Nixpkgs
(`Aarch32`, `Aarch64`) point to the (unfree) `oraclejdk`.

Also note that not using `stripJavaArchivesHook` will likely cause the
generated `.jar` files to be non-deterministic, which is not optimal.
Using it, however, does not always guarantee reproducibility.

JAR files that are intended to be used by other packages should be
installed in `$out/share/java`. JDKs have a stdenv setup hook that add
any JARs in the `share/java` directories of the build inputs to the
+2 −3
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@
, dpkg
, writeScript
, bash
, strip-nondeterminism
, stripJavaArchivesHook
, tor
, zip
, xz
@@ -50,7 +50,7 @@ stdenv.mkDerivation rec {
    dpkg
    imagemagick
    makeWrapper
    strip-nondeterminism
    stripJavaArchivesHook
    xz
    zip
    findutils
@@ -89,7 +89,6 @@ stdenv.mkDerivation rec {
    tar --sort=name --mtime="@$SOURCE_DATE_EPOCH" -cJf native/linux/x64/tor.tar.xz tor
    tor_jar_file=$(find ./opt/bisq/lib/app -name "tor-binary-linux64-*.jar")
    zip -r $tor_jar_file native
    strip-nondeterminism ./opt/bisq/lib/app/*.jar
  '';

  installPhase = ''
+2 −2
Original line number Diff line number Diff line
@@ -2,7 +2,7 @@
, stdenv
, fetchzip
, ant
, canonicalize-jars-hook
, stripJavaArchivesHook
, jdk
, makeWrapper
}:
@@ -18,7 +18,7 @@ stdenv.mkDerivation (finalAttrs: {

  nativeBuildInputs = [
    ant
    canonicalize-jars-hook
    stripJavaArchivesHook
    jdk
    makeWrapper
  ];
+2 −5
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
, jre
, ant
, makeWrapper
, stripJavaArchivesHook
, doCheck ? true
, withExamples ? false
}:
@@ -30,10 +31,6 @@ stdenv.mkDerivation rec {
  ];

  postPatch = with deps; ''
    # Fix the output jar timestamps for reproducibility
    substituteInPlace build.xml \
        --replace-fail '<jar ' '<jar modificationtime="0" '

    # Manually create version properties file for reproducibility
    mkdir -p build/classes
    cat > build/classes/mkgmap-version.properties << EOF
@@ -61,7 +58,7 @@ stdenv.mkDerivation rec {
    '') testInputs}
  '';

  nativeBuildInputs = [ jdk ant makeWrapper ];
  nativeBuildInputs = [ jdk ant makeWrapper stripJavaArchivesHook ];

  buildPhase = ''
    runHook preBuild
+2 −5
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
, jre
, ant
, makeWrapper
, stripJavaArchivesHook
, doCheck ? true
}:
let
@@ -30,10 +31,6 @@ stdenv.mkDerivation rec {
  ];

  postPatch = with deps; ''
    # Fix the output jar timestamps for reproducibility
    substituteInPlace build.xml \
        --replace-fail '<jar ' '<jar modificationtime="0" '

    # Manually create version properties file for reproducibility
    mkdir -p build/classes
    cat > build/classes/splitter-version.properties << EOF
@@ -58,7 +55,7 @@ stdenv.mkDerivation rec {
    '') testInputs}
  '';

  nativeBuildInputs = [ jdk ant makeWrapper ];
  nativeBuildInputs = [ jdk ant makeWrapper stripJavaArchivesHook ];

  buildPhase = ''
    runHook preBuild
Loading