as3hx
as3hx copied to clipboard
Hidden 3rd CLI argument gives different behaviour between `haxelib run as3hx` and `neko run.n`
This was confusing me for a while, because it seemed a random error : When the output directory exists already, we'll get an error on neko. This is because if the last argument exists, it will change the directory into that folder and remove that argument.
calling with haxelib
Haxelib appends a directory as last argument ( not sure where this is defined ), so :
haxelib run as3hx ./test/my/as3 ./test/my/hx
Actually calls :
neko run.n ./test/my/as3 ./test/my/hx /current_directory/
as3hx.Config then changes directory to /current_directory/ and eats that argument. Config.hx#L244-L251
calling with neko
But if we call the neko command ourselves, and the output directory exists:
neko run.n ./test/my/as3 ./test/my/hx
as3hx.Config then changes directory to /test/my/hx and eats that argument.
What happens then is, we :
cd ./test/my/hx(!)- try to read
./test/my/as3there (!) ( which is now./test/my/hx/./test/my/as3 - and output to
./test/my/hx/./out
Point 2 fails, and causes the famous
Called from sys.io.FileOutput::$statics line 1
Called from Run::main line 118
Called from Run::loop line 34
Called from sys.FileSystem::readDirectory line 94
Uncaught exception - std@sys_read_dir
Solution
So to fix that issue, only cd into the last argument if more than 2 arguments have been passed on to the script. Adding if(args.length > 2) { ... } around Config.hx#L244-L251 should fix this.