summary refs log tree commit diff
path: root/pkgs/development/compilers/haxe
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2015-03-20 08:32:52 +0100
committeraszlig <aszlig@redmoonstudios.org>2015-03-20 08:39:21 +0100
commitd68e9b855c0a8fffef309bb5ce702b299664e591 (patch)
tree7f83ffd3d33aff168f88a7f417e5ae019fb3d63d /pkgs/development/compilers/haxe
parent9b41cf0281974ad92f8bb97f0b2a5a84e92a01ed (diff)
downloadnixlib-d68e9b855c0a8fffef309bb5ce702b299664e591.tar
nixlib-d68e9b855c0a8fffef309bb5ce702b299664e591.tar.gz
nixlib-d68e9b855c0a8fffef309bb5ce702b299664e591.tar.bz2
nixlib-d68e9b855c0a8fffef309bb5ce702b299664e591.tar.lz
nixlib-d68e9b855c0a8fffef309bb5ce702b299664e591.tar.xz
nixlib-d68e9b855c0a8fffef309bb5ce702b299664e591.tar.zst
nixlib-d68e9b855c0a8fffef309bb5ce702b299664e591.zip
haxe: Add setup-hook and patch to add haxlib path.
Introduces a new environment variable called HAXELIB_PATH and the patch
for haxelib is trying to search that environment variable for other
libraries. If the haxelib path for a particular library isn't found, it
reverts to the normal behaviour of searching the user's home directory
for a file called .haxelib, which in turn points to a repsitory path and
that in turn has .current/.dev files to point it to the right version
number.

This avoids workarounds like this when using Nix to build Haxe projects:

configurePhase = ''
  export HOME="$(pwd)"
  echo "$(pwd)" > .haxelib

  mkdir dependency1
  echo dev > dependency1/.current
  echo "${dependency1}" > dependency1/.dev

  mkdir dependency2
  echo dev > dependency2/.current
  echo "${dependency2}" > dependency2/.dev
'';

Now every haxelib is expected to be in $out/lib/haxe/$name and whenever
it is listed in buildInputs of another Haxe derivation, HAXELIB_PATH
gets automatically set in the build environment.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'pkgs/development/compilers/haxe')
-rw-r--r--pkgs/development/compilers/haxe/default.nix4
-rw-r--r--pkgs/development/compilers/haxe/haxelib-nix.patch126
-rw-r--r--pkgs/development/compilers/haxe/setup-hook.sh5
3 files changed, 135 insertions, 0 deletions
diff --git a/pkgs/development/compilers/haxe/default.nix b/pkgs/development/compilers/haxe/default.nix
index 3173b8922612..8e6828bce468 100644
--- a/pkgs/development/compilers/haxe/default.nix
+++ b/pkgs/development/compilers/haxe/default.nix
@@ -18,6 +18,8 @@ stdenv.mkDerivation {
     sed -i -e 's|com.class_path <- \[|&"'"$out/lib/haxe/std/"'";|' main.ml
   '';
 
+  patches = [ ./haxelib-nix.patch ];
+
   buildFlags = [ "all" "tools" ];
 
   installPhase = ''
@@ -26,6 +28,8 @@ stdenv.mkDerivation {
     cp -vr std "$out/lib/haxe"
   '';
 
+  setupHook = ./setup-hook.sh;
+
   dontStrip = true;
 
   meta = {
diff --git a/pkgs/development/compilers/haxe/haxelib-nix.patch b/pkgs/development/compilers/haxe/haxelib-nix.patch
new file mode 100644
index 000000000000..da7e4c8dacb8
--- /dev/null
+++ b/pkgs/development/compilers/haxe/haxelib-nix.patch
@@ -0,0 +1,126 @@
+diff --git a/extra/haxelib_src/src/tools/haxelib/Main.hx b/extra/haxelib_src/src/tools/haxelib/Main.hx
+index a44a785..0eb811a 100644
+--- a/extra/haxelib_src/src/tools/haxelib/Main.hx
++++ b/extra/haxelib_src/src/tools/haxelib/Main.hx
+@@ -996,21 +996,26 @@ class Main {
+ 	}
+ 
+ 	function checkRec( prj : String, version : String, l : List<{ project : String, version : String, info : Infos }> ) {
+-		var pdir = getRepository() + Data.safe(prj);
+-		if( !FileSystem.exists(pdir) )
+-			throw "Library "+prj+" is not installed : run 'haxelib install "+prj+"'";
+-		var version = if( version != null ) version else getCurrent(pdir);
+-		var vdir = pdir + "/" + Data.safe(version);
+-		if( vdir.endsWith("dev") )
+-			vdir = getDev(pdir);
+-		if( !FileSystem.exists(vdir) )
+-			throw "Library "+prj+" version "+version+" is not installed";
+-		for( p in l )
+-			if( p.project == prj ) {
+-				if( p.version == version )
+-					return;
+-				throw "Library "+prj+" has two version included "+version+" and "+p.version;
+-			}
++		var vdir = this.getNixLib(prj);
++		if (vdir == null) {
++			var pdir = getRepository() + Data.safe(prj);
++			if( !FileSystem.exists(pdir) )
++				throw "Library "+prj+" is not installed : run 'haxelib install "+prj+"'";
++			var version = if( version != null ) version else getCurrent(pdir);
++			var vdir = pdir + "/" + Data.safe(version);
++			if( vdir.endsWith("dev") )
++				vdir = getDev(pdir);
++			if( !FileSystem.exists(vdir) )
++				throw "Library "+prj+" version "+version+" is not installed";
++			for( p in l )
++				if( p.project == prj ) {
++					if( p.version == version )
++						return;
++					throw "Library "+prj+" has two version included "+version+" and "+p.version;
++				}
++		} else {
++			version = null;
++		}
+ 		var json = try File.getContent(vdir+"/"+Data.JSON) catch( e : Dynamic ) null;
+ 		var inf = Data.readData(json,false);
+ 		l.add({ project : prj, version : version, info: inf });
+@@ -1025,15 +1030,21 @@ class Main {
+ 			var a = args[argcur++].split(":");
+ 			checkRec(a[0],a[1],list);
+ 		}
+-		var rep = getRepository();
+ 		for( d in list ) {
+-			var pdir = Data.safe(d.project)+"/"+Data.safe(d.version)+"/";
+-			var dir = rep + pdir;
+-			try {
+-				dir = getDev(rep+Data.safe(d.project));
++			var dir = this.getNixLib(d.project);
++			var pdir = Data.safe(d.project)+"/";
++			if (dir == null) {
++				var rep = getRepository();
++				pdir += Data.safe(d.version)+"/";
++				dir = rep + pdir;
++				try {
++					dir = getDev(rep+Data.safe(d.project));
++					dir = Path.addTrailingSlash(dir);
++					pdir = dir;
++				} catch( e : Dynamic ) {}
++			} else {
+ 				dir = Path.addTrailingSlash(dir);
+-				pdir = dir;
+-			} catch( e : Dynamic ) {}
++			}
+ 			var ndir = dir + "ndll";
+ 			if( FileSystem.exists(ndir) ) {
+ 				var sysdir = ndir+"/"+Sys.systemName();
+@@ -1153,21 +1164,39 @@ class Main {
+ 		print('  Path: $devPath');
+ 	}
+ 
++	function getNixLib(project:String):Null<String>
++	{
++		var hlibPath = Sys.getEnv("HAXELIB_PATH");
++		if (hlibPath != null) {
++			for (libDir in hlibPath.split(":")) {
++				var fullpath = libDir;
++				fullpath += libDir.substr(-1, 1) == "/" ? "" : "/";
++				fullpath += Data.safe(project);
++				if (FileSystem.exists(fullpath))
++					return fullpath;
++			}
++		}
++		return null;
++	}
++
+ 	function run() {
+-		var rep = getRepository();
+ 		var project = param("Library");
+ 		var temp = project.split(":");
+ 		project = temp[0];
+-		var pdir = rep + Data.safe(project);
+-		if( !FileSystem.exists(pdir) )
+-			throw "Library "+project+" is not installed";
+-		pdir += "/";
+-		var version = temp[1] != null ? temp[1] : getCurrent(pdir);
+-		var dev = try getDev(pdir) catch ( e : Dynamic ) null;
+-		var vdir = dev!=null ? dev : pdir + Data.safe(version);
+-		var rdir = vdir + "/run.n";
+-		if( !FileSystem.exists(rdir) )
+-			throw "Library "+project+" version "+version+" does not have a run script";
++		var vdir = this.getNixLib(project);
++		if (vdir == null) {
++			var rep = getRepository();
++			var pdir = rep + Data.safe(project);
++			if( !FileSystem.exists(pdir) )
++				throw "Library "+project+" is not installed";
++			pdir += "/";
++			var version = temp[1] != null ? temp[1] : getCurrent(pdir);
++			var dev = try getDev(pdir) catch ( e : Dynamic ) null;
++			vdir = dev!=null ? dev : pdir + Data.safe(version);
++			var rdir = vdir + "/run.n";
++			if( !FileSystem.exists(rdir) )
++				throw "Library "+project+" version "+version+" does not have a run script";
++		}
+ 		args.push(Sys.getCwd());
+ 		Sys.setCwd(vdir);
+ 		var cmd = "neko run.n";
diff --git a/pkgs/development/compilers/haxe/setup-hook.sh b/pkgs/development/compilers/haxe/setup-hook.sh
new file mode 100644
index 000000000000..a29e04a989b6
--- /dev/null
+++ b/pkgs/development/compilers/haxe/setup-hook.sh
@@ -0,0 +1,5 @@
+addHaxeLibPath() {
+    addToSearchPath HAXELIB_PATH "$1/lib/haxe"
+}
+
+envHooks+=(addHaxeLibPath)