nixpkgs/pkgs/development/compilers/haxe/haxelib-nix.patch
aszlig d68e9b855c
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>
2015-03-20 08:39:21 +01:00

127 lines
4.4 KiB
Diff

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";