Cross-platform way to handle cmd in hxml


(Thomas J Webb) #1

I want to have haxe run a command after it has compiled it. But even if I run haxe from, say, git bash it still uses the standard windows shell to run any commands specified in the .hxml (which makes sense). Unfortunately the Windows command-line doesn’t like the unix slashes, at least not when specifying executable.

Note that this isn’t a problem with running js and probably not with other scripting languages (it’s ultimately up to the interpreter itself, which is going to be smart) so this works linux, windows, mac:

-cmd node bin/tests.js

However if I want to run something that has been build as a binary executable (using cpp or hl + cl) it won’t work cross-platform:

-cmd ./bin/tests/RunTests (works in unixen)
-cmd .\\bin\\tests\\RunTests (works in Windows)

I know there are other workarounds if I use wrappers, etc. but is there a simple way just through editing the hxml to handle both types of slashes? Or to switch by platform? I see some really old examples of using macros to accomplish this but again involves adding entire files and doesn’t work for me in haxe 4.

(Eric Bishton) #2

Set the COMSPEC (or ComSpec) environment variable to the path of GitBash or whatever it is you want Windows to use as your command line when it runs system commands.

(Thomas J Webb) #4

I don’t want devs to have to set an environment variable just to use this and I don’t want git bash to be a requirement, particularly when I’m not using any fancy shell features, I’m simply calling an executable. The only requirement should be the haxe compiler.

(Ian Harrigan) #5

I hit a similar problem, this seems to work:

-cmd ./bin/tests
-cmd RunTests

something like that should work, this is what im using:

-cmd cd build/android
-cmd gradlew build -x lint


(Thomas J Webb) #6

I think you meant to include a cd in the first one. That does work in Windows (but so does the way I said earlier, using \ instead of /), but doesn’t work in mac or linux. If I include ./ then it works in linux and mac but not Windows. I also have other reasons for wanting to select by os than just the slashes issue.

(Jens Fischer) #7

You might be able to simply use --cwd instead of -cmd cd.

(Ian Harrigan) #8

Right, gotcha, i thought it was just a slash issue

(Adrian V) #9

why not write a hx file which does what you want and call it with:

-cmd haxe -main AfterCompile --interp

(Matan Uberstein) #10

Slightly related, I’ve adapted a haxex script that allows you easily execute haxe as a shell script. Check it out here:

(Thomas J Webb) #11

I was hoping to avoid having to do that, but at this point I think that’s the only reliable way to do it right. I’ll just make a general purpose class that does nothing but call an arbitrary executable with whatever command-line arguments.

(Thomas J Webb) #12

Doesn’t solve the problem. Note what I said about ./