3
0
Fork 0
forked from mirrors/nixpkgs

Merge pull request #59999 from bb010g/swt-reproducibility

This commit is contained in:
Doron Behar 2021-10-27 15:05:30 +03:00 committed by GitHub
commit 51acb65b30
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 201 additions and 275 deletions

View file

@ -47,6 +47,8 @@ stdenv.mkDerivation {
meta = with lib; { meta = with lib; {
homepage = "http://www.areca-backup.org/"; homepage = "http://www.areca-backup.org/";
description = "An Open Source personal backup solution"; description = "An Open Source personal backup solution";
# Builds fine but fails to launch.
broken = true;
license = licenses.gpl2; license = licenses.gpl2;
maintainers = with maintainers; [ pSub ]; maintainers = with maintainers; [ pSub ];
platforms = with platforms; linux; platforms = with platforms; linux;

View file

@ -0,0 +1,9 @@
{ substituteAll, unzip, zip }:
substituteAll {
name = "canonicalize-jar";
src = ./canonicalize-jar.sh;
unzip = "${unzip}/bin/unzip";
zip = "${zip}/bin/zip";
}

View file

@ -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"
}

View file

@ -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)
'';
}
)

View file

@ -14,10 +14,6 @@ rec {
{ inherit stdenv; { inherit stdenv;
} // args); } // args);
antBuild = args: import ./ant-build.nix (
{ inherit lib pkgs;
} // args);
mvnBuild = args: import ./maven-build.nix ( mvnBuild = args: import ./maven-build.nix (
{ inherit stdenv; { inherit stdenv;
} // args); } // args);

View file

@ -11,29 +11,6 @@ findTarball() {
fi 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() { propagateImageName() {
mkdir -p $out/nix-support mkdir -p $out/nix-support
cat "$diskImage"/nix-support/full-name > $out/nix-support/full-name cat "$diskImage"/nix-support/full-name > $out/nix-support/full-name

View file

@ -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@

View file

@ -1,28 +0,0 @@
{ lib, antBuild, fetchgit, perl }:
let
version = "4.11";
in antBuild {
name = "junit-${version}";
# I think this is only used to generate the docs, and will likely disappear
# with the next release of junit since its build system completely changes.
buildInputs = [perl];
src = fetchgit {
url = "https://github.com/junit-team/junit.git";
sha256 = "1cn5dhs6vpbfbcmnm2vb1212n0kblv8cxrvnwmksjxd6bzlkac1k";
rev = "c2e4d911fadfbd64444fb285342a8f1b72336169";
};
antProperties = [
{ name = "version"; value = version; }
];
meta = {
homepage = "http://www.junit.org/";
description = "A framework for repeatable tests in Java";
license = lib.licenses.epl10;
broken = true;
};
}

View file

@ -1,20 +0,0 @@
diff -rc junixsocket-1.3/src/main/org/newsclub/net/unix/NativeUnixSocket.java junixsocket-1.3-new/src/main/org/newsclub/net/unix/NativeUnixSocket.java
*** junixsocket-1.3/src/main/org/newsclub/net/unix/NativeUnixSocket.java Tue Jul 20 14:59:41 2010
--- junixsocket-1.3-new/src/main/org/newsclub/net/unix/NativeUnixSocket.java Sun May 27 22:26:15 2012
***************
*** 43,49 ****
String prefix = "lib";
String suffix = ".so";
String os = osName.replaceAll("[^A-Za-z0-9]", "").toLowerCase();
! if ("macosx".equals(os)) {
suffix = ".dylib";
} else if ("linux".equals(os) || "freebsd".equals(os)
|| "sunos".equals(os)) {
--- 43,49 ----
String prefix = "lib";
String suffix = ".so";
String os = osName.replaceAll("[^A-Za-z0-9]", "").toLowerCase();
! if ("macosx".equals(os) || "darwin".equals(os)) {
suffix = ".dylib";
} else if ("linux".equals(os) || "freebsd".equals(os)
|| "sunos".equals(os)) {

View file

@ -1,42 +0,0 @@
{ lib, stdenv, fetchurl, ant, jdk, junit }:
stdenv.mkDerivation rec {
name = "junixsocket-1.3";
src = fetchurl {
url = "https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/junixsocket/${name}-src.tar.bz2";
sha256 = "0c6p8vmiv5nk8i6g1hgivnl3mpb2k3lhjjz0ss9dlirisfrxf1ym";
};
patches = [ ./darwin.patch ];
buildInputs = [ ant jdk junit ];
preConfigure =
''
substituteInPlace src/main/org/newsclub/net/unix/NativeUnixSocketConfig.java \
--replace /opt/newsclub/lib-native $out/lib
'';
buildPhase = "ant";
ANT_ARGS =
# Note that our OpenJDK on Darwin is currently 32-bit, so we have to build a 32-bit dylib.
(if stdenv.is64bit then [ "-Dskip32=true" ] else [ "-Dskip64=true" ])
++ [ "-Dgcc=${stdenv.cc.targetPrefix}cc" "-Dant.build.javac.source=1.6" ]
++ lib.optional stdenv.isDarwin "-DisMac=true";
installPhase =
''
mkdir -p $out/share/java $out/lib
cp -v dist/*.jar $out/share/java
cp -v lib-native/*.so lib-native/*.dylib $out/lib/
'';
meta = {
description = "A Java/JNI library for using Unix Domain Sockets from Java";
homepage = "https://github.com/kohlschutter/junixsocket";
license = lib.licenses.asl20;
platforms = lib.platforms.linux ++ lib.platforms.darwin;
};
}

View file

@ -0,0 +1,8 @@
--- a/make_linux.mak
+++ b/make_linux.mak
@@ -63,4 +63,4 @@
AWT_LFLAGS = -shared ${SWT_LFLAGS}
-AWT_LIBS = -L$(AWT_LIB_PATH) -ljawt
+AWT_LIBS = `pkg-config --libs x11` -L$(AWT_LIB_PATH) -ljawt

View file

@ -1,73 +1,158 @@
{ stdenv, lib, fetchurl, unzip, jdk, pkg-config, gtk2 { lib
, libXt, libXtst, libXi, libGLU, libGL, webkitgtk, libsoup, xorg , stdenv
, pango, gdk-pixbuf, glib , canonicalize-jars-hook
, fetchzip
, pkg-config
, atk
, glib
, gtk2
, jdk
, libGL
, libGLU
, libXt
, libXtst
, gnome2
}: }:
let let
platformMap = { platformMap = {
x86_64-linux = x86_64-linux =
{ platform = "gtk-linux-x86_64"; { platform = "gtk-linux-x86_64";
sha256 = "1qq0pjll6030v4ml0hifcaaik7sx3fl7ghybfdw95vsvxafwp2ff"; }; sha256 = "17frac2nsx22hfa72264as31rn35hfh9gfgy0n6wvc3knl5d2716"; };
i686-linux = i686-linux =
{ platform = "gtk-linux-x86"; { platform = "gtk-linux-x86";
sha256 = "03mhzraikcs4fsz7d3h5af9pw1bbcfd6dglsvbk2ciwimy9zj30q"; }; sha256 = "13ca17rga9yvdshqvh0sfzarmdcl4wv4pid0ls7v35v4844zbc8b"; };
x86_64-darwin = x86_64-darwin =
{ platform = "cocoa-macosx-x86_64"; { platform = "cocoa-macosx-x86_64";
sha256 = "00k1mfbncvyh8klgmk0891w8jwnd5niqb16j1j8yacrm2smmlb05"; }; sha256 = "0wjyxlw7i9zd2m8syd6k1q85fj8pzhxlfsrl8fpgsj37p698bd0a"; };
}; };
metadata = assert platformMap ? ${stdenv.hostPlatform.system}; platformMap.${stdenv.hostPlatform.system}; metadata = assert platformMap ? ${stdenv.hostPlatform.system};
platformMap.${stdenv.hostPlatform.system};
in stdenv.mkDerivation rec { in stdenv.mkDerivation rec {
pname = "swt";
version = "4.5"; version = "4.5";
fullVersion = "${version}-201506032000"; fullVersion = "${version}-201506032000";
pname = "swt";
hardeningDisable = [ "format" ]; hardeningDisable = [ "format" ];
# Alas, the Eclipse Project apparently doesn't produce source-only # Alas, the Eclipse Project apparently doesn't produce source-only
# releases of SWT. So we just grab a binary release and extract # releases of SWT. So we just grab a binary release and extract
# "src.zip" from that. # "src.zip" from that.
src = fetchurl { src = fetchzip {
url = "http://archive.eclipse.org/eclipse/downloads/drops4/R-${fullVersion}/${pname}-${version}-${metadata.platform}.zip"; url = "https://archive.eclipse.org/eclipse/downloads/drops4/" +
sha256 = metadata.sha256; "R-${fullVersion}/${pname}-${version}-${metadata.platform}.zip";
inherit (metadata) sha256;
stripRoot = false;
extraPostFetch = ''
mkdir "$unpackDir"
cd "$unpackDir"
renamed="$TMPDIR/src.zip"
mv "$out/src.zip" "$renamed"
unpackFile "$renamed"
rm -r "$out"
mv "$unpackDir" "$out"
'';
}; };
sourceRoot = "."; nativeBuildInputs = [
canonicalize-jars-hook
pkg-config
];
buildInputs = [
atk
gtk2
jdk
libGL
libGLU
libXtst
gnome2.gnome_vfs
gnome2.libgnome
gnome2.libgnomeui
] ++ lib.optionals (lib.hasPrefix "8u" jdk.version) [
libXt
];
nativeBuildInputs = [ unzip pkg-config ]; patches = [ ./awt-libs.patch ./gtk-libs.patch ];
buildInputs = [ jdk gtk2 libXt libXtst libXi libGLU libGL webkitgtk libsoup ];
NIX_LFLAGS = toString (map (x: "-L${lib.getLib x}/lib") [ xorg.libX11 pango gdk-pixbuf glib ]) + prePatch = ''
" -lX11 -lpango-1.0 -lgdk_pixbuf-2.0 -lglib-2.0"; # clear whitespace from makefiles (since we match on EOL later)
sed -i 's/ \+$//' ./*.mak
'';
postPatch = let makefile-sed = builtins.toFile "swt-makefile.sed" (''
# fix pkg-config invocations in CFLAGS/LIBS pairs.
#
# change:
# FOOCFLAGS = `pkg-config --cflags `foo bar`
# FOOLIBS = `pkg-config --libs-only-L foo` -lbaz
# into:
# FOOCFLAGS = `pkg-config --cflags foo bar`
# FOOLIBS = `pkg-config --libs foo bar`
#
# the latter works more consistently.
/^[A-Z0-9_]\+CFLAGS = `pkg-config --cflags [^`]\+`$/ {
N
s'' +
"/" + ''
^\([A-Z0-9_]\+\)CFLAGS = `pkg-config --cflags \(.\+\)`\
\1LIBS = `pkg-config --libs-only-L .\+$'' +
"/" + ''
\1CFLAGS = `pkg-config --cflags \2`\
\1LIBS = `pkg-config --libs \2`'' +
"/\n" + ''
}
# fix WebKit libs not being there
s/\$(WEBKIT_LIB) \$(WEBKIT_OBJECTS)$/\0 `pkg-config --libs glib-2.0`/g
''); in ''
declare -a makefiles=(./*.mak)
sed -i -f ${makefile-sed} "''${makefiles[@]}"
# assign Makefile variables eagerly & change backticks to `$(shell …)`
sed -i -e 's/ = `\([^`]\+\)`/ := $(shell \1)/' \
-e 's/`\([^`]\+\)`/$(shell \1)/' \
"''${makefiles[@]}"
'';
buildPhase = '' buildPhase = ''
unzip src.zip -d src runHook preBuild
cd src
sed -i "s#^LFLAGS =#LFLAGS = $NIX_LFLAGS #g" *.mak
export JAVA_HOME=${jdk} export JAVA_HOME=${jdk}
sh ./build.sh ./build.sh
mkdir out mkdir out
javac -d out/ $(find org/ -name "*.java") find org/ -name '*.java' -type f -exec javac -d out/ {} +
runHook postBuild
''; '';
installPhase = '' installPhase = ''
mkdir -p $out/lib runHook preInstall
cp *.so $out/lib
mkdir -p $out/jars if [ -n "$prefix" ]; then
cp version.txt out/ mkdir -p "$prefix"
cd out && jar -c * > $out/jars/swt.jar fi
mkdir -p "$out/lib"
cp -t "$out/lib" ./*.so
mkdir -p "$out/jars"
cp -t out/ version.txt
(cd out && jar -c *) > "$out/jars/swt.jar"
runHook postInstall
''; '';
meta = with lib; { meta = with lib; {
homepage = "http://www.eclipse.org/swt/"; homepage = "https://www.eclipse.org/swt/";
description = "An widget toolkit for Java to access the user-interface facilities of the operating systems on which it is implemented"; description = ''
A widget toolkit for Java to access the user-interface facilities of
the operating systems on which it is implemented.
'';
license = licenses.epl10; license = licenses.epl10;
maintainers = with maintainers; [ pSub ]; maintainers = with maintainers; [ bb010g ];
platforms = with platforms; linux; platforms = platforms.linux;
}; };
} }

View file

@ -0,0 +1,14 @@
--- a/make_linux.mak
+++ b/make_linux.mak
@@ -53,9 +53,4 @@
-# Do not use pkg-config to get libs because it includes unnecessary dependencies (i.e. pangoxft-1.0)
-GTKCFLAGS = `pkg-config --cflags gtk+-$(GTK_VERSION) gtk+-unix-print-$(GTK_VERSION)`
+GTKCFLAGS = `pkg-config --cflags gtk+-$(GTK_VERSION) gthread-2.0 gtk+-unix-print-$(GTK_VERSION) x11 xtst`
+GTKLIBS = `pkg-config --libs gtk+-$(GTK_VERSION) gthread-2.0 gtk+-unix-print-$(GTK_VERSION) x11 xtst`
-ifeq ($(GTK_VERSION), 3.0)
-GTKLIBS = `pkg-config --libs-only-L gtk+-$(GTK_VERSION) gthread-2.0` $(XLIB64) -L/usr/X11R6/lib -lgtk-3 -lgdk-3 -lcairo -lgthread-2.0 -lXtst
-else
-GTKLIBS = `pkg-config --libs-only-L gtk+-$(GTK_VERSION) gthread-2.0` $(XLIB64) -L/usr/X11R6/lib -lgtk-x11-$(GTK_VERSION) -lgthread-2.0 -lXtst
-endif

View file

@ -153,6 +153,12 @@ with pkgs;
appindicator-sharp = callPackage ../development/libraries/appindicator-sharp { }; appindicator-sharp = callPackage ../development/libraries/appindicator-sharp { };
canonicalize-jar = callPackage ../build-support/java/canonicalize-jar.nix { };
canonicalize-jars-hook = makeSetupHook {
name = "canonicalize-jars-hook";
substitutions = { canonicalize_jar = canonicalize-jar; };
} ../build-support/setup-hooks/canonicalize-jars.sh;
ensureNewerSourcesHook = { year }: makeSetupHook {} ensureNewerSourcesHook = { year }: makeSetupHook {}
(writeScript "ensure-newer-sources-hook.sh" '' (writeScript "ensure-newer-sources-hook.sh" ''
postUnpackHooks+=(_ensureNewerSources) postUnpackHooks+=(_ensureNewerSources)
@ -20153,10 +20159,6 @@ with pkgs;
jflex = callPackage ../development/libraries/java/jflex { }; jflex = callPackage ../development/libraries/java/jflex { };
junit = callPackage ../development/libraries/java/junit { antBuild = releaseTools.antBuild; };
junixsocket = callPackage ../development/libraries/java/junixsocket { };
lombok = callPackage ../development/libraries/java/lombok { }; lombok = callPackage ../development/libraries/java/lombok { };
lucene = callPackage ../development/libraries/java/lucene { }; lucene = callPackage ../development/libraries/java/lucene { };