Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
213 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
From b5bc2b56e6086d7a4f529a09e88a1c2484ae25c6 Mon Sep 17 00:00:00 2001 | ||
From: Herwig Hochleitner <herwig@bendlas.net> | ||
Date: Tue, 10 Jan 2017 11:30:36 +0100 | ||
Subject: [PATCH] prepare for hardcoded sopath | ||
|
||
--- | ||
com/etsy/net/UnixDomainSocket.java | 147 +------------------------------------ | ||
1 file changed, 1 insertion(+), 146 deletions(-) | ||
|
||
diff --git a/com/etsy/net/UnixDomainSocket.java b/com/etsy/net/UnixDomainSocket.java | ||
index 332ccd9..da11418 100644 | ||
--- a/com/etsy/net/UnixDomainSocket.java | ||
+++ b/com/etsy/net/UnixDomainSocket.java | ||
@@ -8,13 +8,9 @@ import java.io.InterruptedIOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.io.File; | ||
-import java.util.jar.JarFile; | ||
-import java.util.zip.ZipEntry; | ||
import java.io.BufferedOutputStream; | ||
import java.io.FileInputStream; | ||
import java.io.FileOutputStream; | ||
-import java.net.URISyntaxException; | ||
- | ||
|
||
/** | ||
* | ||
@@ -25,150 +21,9 @@ import java.net.URISyntaxException; | ||
*/ | ||
public abstract class UnixDomainSocket { | ||
|
||
- // system property holding the preferred folder for copying the lib file to | ||
- private static final String LIB_TARGET = "juds.folder.preferred"; | ||
- | ||
- private static File jarFile; | ||
static { | ||
// Load the Unix domain socket C library | ||
- getJarPath(); | ||
- try { | ||
- loadNativeLib(); | ||
- } catch (IOException ioe) { | ||
- throwLink(ioe); | ||
- } | ||
- } | ||
- | ||
- private static void getJarPath() { | ||
- try { | ||
- jarFile = new File(JUDS.jarURL.toURI()); | ||
- } catch(URISyntaxException e) { | ||
- throwLink(e); | ||
- } | ||
- } | ||
- | ||
- private static void loadNativeLib() throws IOException { | ||
- File lib = getNativeLibTarget(); | ||
- if(!lib.exists() || jarNewer(lib)) { | ||
- try { | ||
- extractNativeLib(lib); | ||
- if(!lib.exists()) { | ||
- throwLink("The native library was not extracted"); | ||
- } | ||
- } catch(IOException e) { | ||
- throwLink(e); | ||
- } catch(URISyntaxException e) { | ||
- throwLink(e); | ||
- } | ||
- } | ||
- | ||
- String path = ""; | ||
- try { | ||
- path = lib.getCanonicalPath(); | ||
- } catch(IOException e) { | ||
- throwLink(e); | ||
- } | ||
- System.load(path); | ||
- } | ||
- | ||
- private static Boolean jarNewer(File lib) { | ||
- return lib.lastModified() < jarFile.lastModified(); | ||
- } | ||
- | ||
- private static void throwLink(Throwable e) { | ||
- throwLink(e.toString()); | ||
- } | ||
- private static void throwLink(String s) { | ||
- throw new UnsatisfiedLinkError(s); | ||
- } | ||
- | ||
- private static File getNativeLibTarget() throws IOException { | ||
- String p = platform(); | ||
- String ext = "darwin".equals(p) ? "dylib" : "so"; | ||
- | ||
- File tmpdir; | ||
- String preferred = System.getProperty(LIB_TARGET); | ||
- if (preferred != null) { | ||
- tmpdir = new File(preferred); | ||
- | ||
- if(!(tmpdir.isDirectory())) { | ||
- throw new IOException("The preffered path is not a folder: " + tmpdir.getAbsolutePath()); | ||
- } | ||
- } else { | ||
- tmpdir = File.createTempFile("juds-temp", Long.toString(System.nanoTime())); | ||
- | ||
- if(!(tmpdir.delete())) { | ||
- throw new IOException("Could not delete temp file: " + tmpdir.getAbsolutePath()); | ||
- } | ||
- | ||
- if(!(tmpdir.mkdir())) { | ||
- throw new IOException("Could not create temp directory: " + tmpdir.getAbsolutePath()); | ||
- } | ||
- | ||
- tmpdir.deleteOnExit(); | ||
- } | ||
- | ||
- String path = String.format("libunixdomainsocket-%s-%s.%s", p, arch(), ext); | ||
- File lib = new File(tmpdir, path); | ||
- if (preferred == null) { | ||
- lib.deleteOnExit(); | ||
- } | ||
- return lib; | ||
- } | ||
- | ||
- private static void extractNativeLib(File target) | ||
- throws IOException, URISyntaxException { | ||
- | ||
- InputStream in; | ||
- // Hadoop extracts the jar into a directory before running the code, so | ||
- // check to see if the file is already there, since the .jar extraction | ||
- // will fail in this case. | ||
- String preExtractedLibPath = jarFile.getCanonicalPath() + "/" + target.getName(); | ||
- File preExtractedLibFile = new File(preExtractedLibPath); | ||
- if (preExtractedLibFile.exists()) { | ||
- in = new FileInputStream(preExtractedLibFile); | ||
- } else { | ||
- JarFile jar = new JarFile(jarFile); | ||
- ZipEntry z = jar.getEntry(target.getName()); | ||
- if(z == null) { | ||
- throwLink("Could not find library: "+target.getName()); | ||
- } | ||
- in = jar.getInputStream(z); | ||
- } | ||
- try { | ||
- OutputStream out = new BufferedOutputStream( | ||
- new FileOutputStream(target)); | ||
- try { | ||
- byte[] buf = new byte[2048]; | ||
- for(;;) { | ||
- int n = in.read(buf); | ||
- if(n < 0) { | ||
- break; | ||
- } | ||
- out.write(buf, 0, n); | ||
- } | ||
- } finally { | ||
- out.close(); | ||
- } | ||
- } finally { | ||
- in.close(); | ||
- } | ||
- } | ||
- | ||
- private static String arch() { | ||
- String a = System.getProperty("os.arch"); | ||
- if("amd64".equals(a) || "x86_64".equals(a)) { | ||
- return "x86_64"; | ||
- } | ||
- return a; | ||
- } | ||
- | ||
- private static String platform() { | ||
- String p = System.getProperty("os.name").toLowerCase(); | ||
- if("mac os x".equals(p)) { | ||
- return "darwin"; | ||
- } | ||
- return p; | ||
+ System.load("@sopath@"); | ||
} | ||
|
||
protected UnixDomainSocketInputStream in; | ||
-- | ||
2.11.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,37 @@ | ||
{ stdenv, jdk, fetchgit, autoconf }: | ||
{ stdenv, stdenv_32bit, jdk, fetchFromGitHub, fetchurl, autoconf }: | ||
let | ||
|
||
version = "0.94"; | ||
version = "0.95"; | ||
|
||
in stdenv.mkDerivation rec { | ||
name = "juds-${version}.jar"; | ||
src = fetchgit { | ||
url = "https://github.com/mcfunley/juds.git"; | ||
rev = "3545035fc63aeccf3444b447e7959c7675381027"; | ||
sha256 = "6072dc200f2820544830ddfafeee42beeb4f64697645de3e921fa5ad6684ddb9"; | ||
in stdenv.mkDerivation { | ||
name = "juds-${version}"; | ||
src = fetchFromGitHub { | ||
owner = "mcfunley"; | ||
repo = "juds"; | ||
rev = "3334ede781240fd52cbc06fdc84243a73c88ea95"; | ||
sha256 = "0kizlvdax6jwnzvr6y4zfvgqxp6b02isr1bcijnmqhzs6kcdkvjg"; | ||
}; | ||
nativeBuildInputs = [ jdk autoconf ]; | ||
phases = [ "unpackPhase" "configurePhase" "buildPhase" "installPhase" ]; | ||
preConfigure = "sh autoconf.sh"; | ||
buildPhase = '' | ||
make SHELL=${stdenv.shell} \ | ||
M32="-m64" \ | ||
PREFIX=$out \ | ||
nativelib jar | ||
''; | ||
installPhase = '' | ||
cp ${name} $out | ||
nativeBuildInputs = [ jdk ]; | ||
buildInputs = [ <nixpkgs/pkgs/build-support/setup-hooks/separate-debug-info.sh> ]; | ||
outputs = [ "out" "debug" ]; | ||
patches = [ ./0001-prepare-for-hardcoded-sopath.patch ]; | ||
|
||
buildCommand = '' | ||
sopath="$out/lib/libunixdomainsocket.so" | ||
unpackPhase | ||
cd $sourceRoot | ||
patchPhase | ||
substituteInPlace com/etsy/net/UnixDomainSocket.java \ | ||
--subst-var sopath | ||
mkdir -p $out/lib $out/src | ||
cp -R com $out/src/com | ||
javac -sourcepath $out/src -d $out/lib com/etsy/net/{JUDS,UnixDomainSocket,UnixDomainSocketClient,UnixDomainSocketServer}.java | ||
javah -sourcepath . -o $out/src/com/etsy/net/UnixDomainSocket.h com.etsy.net.UnixDomainSocket | ||
gcc -fPIC -O2 -shared -o $sopath $out/src/com/etsy/net/UnixDomainSocket.c | ||
fixupPhase | ||
''; | ||
} |