diff options
author | github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> | 2021-10-27 18:01:02 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-27 18:01:02 +0000 |
commit | 22401dcc39cbca3998fc81165331cdccc23ee2b8 (patch) | |
tree | 258fa6956c47b1069bed2fa4350eb55889f8daba /pkgs/build-support | |
parent | d33a58f89db902e5c9fa13da6df75a8c676036c5 (diff) | |
parent | 4db3e73f73794a686689b3fa8628ec40d869c584 (diff) |
Merge master into staging-next
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/docker/default.nix | 2 | ||||
-rw-r--r-- | pkgs/build-support/java/canonicalize-jar.nix | 9 | ||||
-rw-r--r-- | pkgs/build-support/java/canonicalize-jar.sh | 29 | ||||
-rw-r--r-- | pkgs/build-support/release/ant-build.nix | 123 | ||||
-rw-r--r-- | pkgs/build-support/release/default.nix | 4 | ||||
-rw-r--r-- | pkgs/build-support/release/functions.sh | 23 | ||||
-rw-r--r-- | pkgs/build-support/setup-hooks/canonicalize-jars.sh | 17 |
7 files changed, 55 insertions, 152 deletions
diff --git a/pkgs/build-support/docker/default.nix b/pkgs/build-support/docker/default.nix index a42b025bc7f2a..dcfa5ec593d1d 100644 --- a/pkgs/build-support/docker/default.nix +++ b/pkgs/build-support/docker/default.nix @@ -31,8 +31,6 @@ , writeText , writeTextDir , writePython3 -, system -, # Note: This is the cross system we're compiling for }: let diff --git a/pkgs/build-support/java/canonicalize-jar.nix b/pkgs/build-support/java/canonicalize-jar.nix new file mode 100644 index 0000000000000..1edd9a6e0d20f --- /dev/null +++ b/pkgs/build-support/java/canonicalize-jar.nix @@ -0,0 +1,9 @@ +{ substituteAll, unzip, zip }: + +substituteAll { + name = "canonicalize-jar"; + src = ./canonicalize-jar.sh; + + unzip = "${unzip}/bin/unzip"; + zip = "${zip}/bin/zip"; +} diff --git a/pkgs/build-support/java/canonicalize-jar.sh b/pkgs/build-support/java/canonicalize-jar.sh new file mode 100644 index 0000000000000..af010bcd2b26c --- /dev/null +++ b/pkgs/build-support/java/canonicalize-jar.sh @@ -0,0 +1,29 @@ +# Canonicalize the manifest & repack with deterministic timestamps. +canonicalizeJar() { + local input='' outer='' + input="$(realpath -sm -- "$1")" + outer="$(pwd)" + # -qq: even quieter + @unzip@ -qq "$input" -d "$input-tmp" + canonicalizeJarManifest "$input-tmp/META-INF/MANIFEST.MF" + # Sets all timestamps to Jan 1 1980, the earliest mtime zips support. + find -- "$input-tmp" -exec touch -t 198001010000.00 {} + + rm "$input" + pushd "$input-tmp" 2>/dev/null + # -q|--quiet, -r|--recurse-paths + # -o|--latest-time: canonicalizes overall archive mtime + # -X|--no-extra: don't store platform-specific extra file attribute fields + @zip@ -qroX "$outer/tmp-out.jar" . 2> /dev/null + popd 2>/dev/null + rm -rf "$input-tmp" + mv "$outer/tmp-out.jar" "$input" +} + +# See also the Java specification's JAR requirements: +# https://docs.oracle.com/javase/8/docs/technotes/guides/jar/jar.html#Notes_on_Manifest_and_Signature_Files +canonicalizeJarManifest() { + local input='' + input="$(realpath -sm -- "$1")" + (head -n 1 "$input" && tail -n +2 "$input" | sort | grep -v '^\s*$') > "$input-tmp" + mv "$input-tmp" "$input" +} diff --git a/pkgs/build-support/release/ant-build.nix b/pkgs/build-support/release/ant-build.nix deleted file mode 100644 index 6b59241e01edb..0000000000000 --- a/pkgs/build-support/release/ant-build.nix +++ /dev/null @@ -1,123 +0,0 @@ -{ src -, pkgs -, lib -, stdenv ? pkgs.stdenv -, name -, antTargets ? [] -, jars ? [] -, jarWrappers ? [] -, antProperties ? [] -, antBuildInputs ? [] -, buildfile ? "build.xml" -, ant ? pkgs.ant -, jre ? pkgs.jdk -, hydraAntLogger ? pkgs.hydraAntLogger -, zip ? pkgs.zip -, unzip ? pkgs.unzip -, ... } @ args: - -let - antFlags = "-f ${buildfile} " + lib.concatMapStrings ({name, value}: "-D${name}=${value} " ) antProperties ; -in -stdenv.mkDerivation ( - - { - inherit jre ant; - showBuildStats = true; - - postPhases = - ["generateWrappersPhase" "finalPhase"]; - - prePhases = - ["antSetupPhase"]; - - antSetupPhase = with lib; '' - if test "$hydraAntLogger" != "" ; then - export ANT_ARGS="-logger org.hydra.ant.HydraLogger -lib `ls $hydraAntLogger/share/java/*.jar | head -1`" - fi - for abi in ${concatStringsSep " " (map (f: "`find ${f} -name '*.jar'`") antBuildInputs)}; do - export ANT_ARGS="$ANT_ARGS -lib $abi" - done - ''; - - installPhase = '' - runHook preInstall - - mkdir -p $out/share/java - ${ if jars == [] then '' - find . -name "*.jar" | xargs -I{} cp -v {} $out/share/java - '' else lib.concatMapStrings (j: '' - cp -v ${j} $out/share/java - '') jars } - - . ${./functions.sh} - for j in $out/share/java/*.jar ; do - canonicalizeJar $j - echo file jar $j >> $out/nix-support/hydra-build-products - done - - runHook postInstall - ''; - - generateWrappersPhase = - let - cp = w: "-cp '${lib.optionalString (w ? classPath) w.classPath}${lib.optionalString (w ? mainClass) ":$out/share/java/*"}'"; - in - '' - header "Generating jar wrappers" - '' + (lib.concatMapStrings (w: '' - - mkdir -p $out/bin - cat >> $out/bin/${w.name} <<EOF - #!${pkgs.runtimeShell} - export JAVA_HOME=$jre - $jre/bin/java ${cp w} ${if w ? mainClass then w.mainClass else "-jar ${w.jar}"} \$@ - EOF - - chmod a+x $out/bin/${w.name} || exit 1 - '') jarWrappers) + '' - closeNest - ''; - - buildPhase = '' - runHook preBuild - '' + (if antTargets == [] then '' - header "Building default ant target" - ant ${antFlags} - closeNest - '' else lib.concatMapStrings (t: '' - header "Building '${t}' target" - ant ${antFlags} ${t} - closeNest - '') antTargets) + '' - runHook postBuild - ''; - - finalPhase = - '' - # Propagate the release name of the source tarball. This is - # to get nice package names in channels. - if test -e $origSrc/nix-support/hydra-release-name; then - cp $origSrc/nix-support/hydra-release-name $out/nix-support/hydra-release-name - fi - ''; - } - - // removeAttrs args ["antProperties" "buildInputs" "pkgs" "lib" "jarWrappers"] // - - { - name = name + (if src ? version then "-" + src.version else ""); - - nativeBuildInputs = [ unzip ]; - buildInputs = [ant jre zip] ++ lib.optional (args ? buildInputs) args.buildInputs ; - - postHook = '' - mkdir -p $out/nix-support - echo "$system" > $out/nix-support/system - . ${./functions.sh} - - origSrc=$src - src=$(findTarball $src) - ''; - } -) diff --git a/pkgs/build-support/release/default.nix b/pkgs/build-support/release/default.nix index 83f755b2becec..d593ec81197e4 100644 --- a/pkgs/build-support/release/default.nix +++ b/pkgs/build-support/release/default.nix @@ -14,10 +14,6 @@ rec { { inherit stdenv; } // args); - antBuild = args: import ./ant-build.nix ( - { inherit lib pkgs; - } // args); - mvnBuild = args: import ./maven-build.nix ( { inherit stdenv; } // args); diff --git a/pkgs/build-support/release/functions.sh b/pkgs/build-support/release/functions.sh index 120d196854274..0c4b81edf822e 100644 --- a/pkgs/build-support/release/functions.sh +++ b/pkgs/build-support/release/functions.sh @@ -11,29 +11,6 @@ findTarball() { fi } -canonicalizeJarManifest() { - local input=$1 - # http://docs.oracle.com/javase/7/docs/technotes/guides/jar/jar.html#Notes_on_Manifest_and_Signature_Files - (head -n 1 $input && tail -n +2 $input | sort | grep -v '^\s*$') > $input-tmp - mv $input-tmp $input -} - -# Post-process a jar file to contain canonical timestamps and metadata ordering -canonicalizeJar() { - local input=$1 - local outer=$(pwd) - unzip -qq $input -d $input-tmp - canonicalizeJarManifest $input-tmp/META-INF/MANIFEST.MF - # Set all timestamps to Jan 1 1980, which is the earliest date the zip format supports... - find $input-tmp -exec touch -t 198001010000.00 {} + - rm $input - pushd $input-tmp - zip -q -r -o -X $outer/tmp-out.jar . 2> /dev/null - popd - rm -rf $input-tmp - mv $outer/tmp-out.jar $input -} - propagateImageName() { mkdir -p $out/nix-support cat "$diskImage"/nix-support/full-name > $out/nix-support/full-name diff --git a/pkgs/build-support/setup-hooks/canonicalize-jars.sh b/pkgs/build-support/setup-hooks/canonicalize-jars.sh new file mode 100644 index 0000000000000..8c55810748ea0 --- /dev/null +++ b/pkgs/build-support/setup-hooks/canonicalize-jars.sh @@ -0,0 +1,17 @@ +# This setup hook causes the fixup phase to repack all JAR files in a +# canonical & deterministic fashion, e.g. resetting mtimes (like with normal +# store files) and avoiding impure metadata. + +fixupOutputHooks+=('if [ -z "$dontCanonicalizeJars" -a -e "$prefix" ]; then canonicalizeJarsIn "$prefix"; fi') + +canonicalizeJarsIn() { + local dir="$1" + header "canonicalizing jars in $dir" + dir="$(realpath -sm -- "$dir")" + while IFS= read -rd '' f; do + canonicalizeJar "$f" + done < <(find -- "$dir" -type f -name '*.jar' -print0) + stopNest +} + +source @canonicalize_jar@ |