I am currently having difficulty implementing a “run” module for my project, for which I am currently only adding build functionality.
package;
import haxe.Json;
import haxe.io.Path;
import sys.FileSystem;
import sys.io.File;
import sys.io.Process;
using StringTools;
class Main
{
public static function main()
{
var args = Sys.args();
var dir:String = args[args.length - 1];
var useVerbose = false;
var includedCompilationOptions = new Array<String>();
var _application_path = Sys.getCwd();
var _source_folder = "./";
Sys.setCwd(dir);
for (i in 1...args.length)
{
switch (args[i])
{
case "-v":
useVerbose = true;
includedCompilationOptions.push(args[i]);
case "-D":
includedCompilationOptions.push(args[i]);
includedCompilationOptions.push(args[i + 1]);
case "-input":
_source_folder = args[i + 1];
}
}
var commandLine:String = "";
var convos = new Array<String>();
if (args[0] == "build")
{
if (FileSystem.exists(dir + "/project.json"))
{
var data:Dynamic = Json.parse(File.getContent(dir + "/project.json"));
var target:String = data.target;
var output:String = data.output;
convos = data.convos;
if (data.source)
_source_folder = data.source;
commandLine = 'haxe -cp $_source_folder -main Main -$target $output -lib sd2 -lib hscript ';
for (i in 0...convos.length)
{
var filePath:String = Path.normalize(convos[i]);
var fileName:String = filePath.substring(filePath.lastIndexOf('/') + 1, filePath.lastIndexOf('.'));
commandLine += '-resource "$filePath"@$fileName ';
}
commandLine += includedCompilationOptions.join(' ');
}
if (useVerbose)
{
Sys.println("Resources used: ");
for (i in 0...convos.length)
Sys.println(convos[i]);
}
Sys.println("Starting build...");
Sys.println(commandLine);
Sys.command(commandLine);
}
}
}
When I use haxelib run sd2 build -v -D hscriptPos
I get the following command generated:
haxe -cp ./ -main Main -js ../../scripts/sd2.js -lib sd2 -lib hscript -resource "../../chapters/01/start.sdc"@start -v -D hscriptPos
I execute this command later using Sys.command
but I keep getting The system cannot find the path specified.
errors. I’ve been trying to tackle this problem for several days, trying to find out the source of the problem.
When I trace the arguments being passed from the run module, the last argument is the path of the working directory, which I set using Sys.setCwd
but this doesn’t seem to be the reason why I’m getting the errors. I’ve tried normalising the paths I’m using but that also doesn’t seem to make a difference.
I just don’t understand what’s causing these errors. If I copy and paste the command above and execute it directly in command line, it works.
I can’t see why the code implementation above doesn’t work. Can anyone notice the problem? Thanks in advance.