Skip to content

Commit

Permalink
Relief haxelib.json check for haxelib path (#485)
Browse files Browse the repository at this point in the history
  • Loading branch information
RealyUniqueName authored Nov 8, 2019
1 parent c994dc4 commit e7cb621
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 9 deletions.
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
- mysql

install:
- git submodule update --init --recursive
- ps: Set-Service wuauserv -StartupType Manual
- cinst haxe -y
- cinst nssm -y
Expand Down
4 changes: 3 additions & 1 deletion ci.hxml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
-cp test
-x RunCi
-main RunCi
-neko bin/ci.n
-cmd neko bin/ci.n
Binary file modified run.n
Binary file not shown.
9 changes: 9 additions & 0 deletions src/Package.hx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,16 @@ class Package {

static function main() {
checkVersion();
switch Sys.systemName() {
case 'Windows':
zipWindows();
case _:
var exitCode = Sys.command('zip', ['-r', outPath, 'src/haxelib', 'haxelib.json', 'run.n', 'README.md']);
Sys.exit(exitCode);
}
}

static function zipWindows() {
var entries = new List<Entry>();

function add(path:String, ?target:String) {
Expand Down
24 changes: 20 additions & 4 deletions src/haxelib/Data.hx
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ typedef ProjectInfos = {
var tags : List<String>;
}

@:enum abstract CheckLevel(Int) {
var NoCheck = 0;
var CheckSyntax = 1;
var CheckData = 2;

@:from static inline function fromBool(check:Bool):CheckLevel {
return check ? CheckData : NoCheck;
}

@:op(A > B) function gt(b:CheckLevel):Bool;
@:op(A >= B) function gte(b:CheckLevel):Bool;
@:op(A == B) function eq(b:CheckLevel):Bool;
@:op(A <= B) function lte(b:CheckLevel):Bool;
@:op(A < B) function lt(b:CheckLevel):Bool;
}

abstract DependencyVersion(String) to String from SemVer {
inline function new(s:String)
this = s;
Expand Down Expand Up @@ -298,7 +314,7 @@ class Data {
}


public static function readInfos( zip : List<Entry>, check : Bool ) : Infos
public static function readInfos( zip : List<Entry>, check : CheckLevel ) : Infos
return readData(Reader.unzip(getJson(zip)).toString(), check);

public static function checkClassPath( zip : List<Entry>, infos : Infos ) {
Expand All @@ -314,11 +330,11 @@ class Data {
}
}

public static function readData( jsondata: String, check : Bool ) : Infos {
public static function readData( jsondata: String, check : CheckLevel ) : Infos {
var doc:Infos =
try Json.parse(jsondata)
catch ( e : Dynamic )
if (check)
if (check >= CheckLevel.CheckSyntax)
throw 'JSON parse error: $e';
else {
name : ProjectName.DEFAULT,
Expand All @@ -330,7 +346,7 @@ class Data {
contributors: [],
}

if (check)
if (check >= CheckLevel.CheckData)
Validator.validate(doc);
else {
if (!doc.version.valid)
Expand Down
2 changes: 1 addition & 1 deletion src/haxelib/client/Main.hx
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ class Main {
throw "Library "+prj+" has two versions included : "+version+" and "+p.version;
}
var json = try File.getContent(vdir+"/"+Data.JSON) catch( e : Dynamic ) null;
var inf = Data.readData(json, json != null);
var inf = Data.readData(json, json != null ? CheckSyntax : NoCheck);
l.add({ project : prj, version : version, dir : Path.addTrailingSlash(vdir), info: inf });
if( returnDependencies ) {
for( d in inf.dependencies )
Expand Down
16 changes: 13 additions & 3 deletions test/Prepare.hx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import sys.*;
import sys.io.*;
import haxe.io.*;
using StringTools;

class Prepare {
static function zipDir(dir:String, outPath:String):Void {
Expand Down Expand Up @@ -38,15 +37,26 @@ class Prepare {
}

static function main():Void {
var system = Sys.systemName();
var cwd = Sys.getCwd();
/*
(re)package the dummy libraries
*/
var libsPath = "test/libraries";
for (item in FileSystem.readDirectory(libsPath)) {
var path = Path.join([libsPath, item]);
if (FileSystem.isDirectory(path)) {
trace('Preparing $item');
zipDir(path, 'test/libraries/${item}.zip');
switch system {
case 'Windows':
zipDir(path, 'test/libraries/${item}.zip');
case _:
Sys.setCwd(path);
var exitCode = Sys.command('zip', ['-r', '../${item}.zip', '.']);
Sys.setCwd(cwd);
if(exitCode != 0) {
Sys.stderr().writeString('Failed to zip $item\n');
}
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions test/RunCi.hx
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ Listen 2000
return;
} catch (e:Dynamic) {
trace(e);
trace(CallStack.toString(CallStack.exceptionStack()));
Sys.sleep(5.0);
}
throw "cannot config database";
Expand Down

0 comments on commit e7cb621

Please sign in to comment.