waneck / testrepo

0 stars 0 forks source link

Issue 1080 - Proposal for new compiler argument - haxe #1080

Closed waneck closed 11 years ago

waneck commented 11 years ago

[Google Issue #1080 : http://code.google.com/haxe/issues/detail?id=1080] by mpcref, at 2012-07-23T06:46:58.000Z Haxe has a "--next" compiler argument that allows for multiple compiles in one call. Take for example the following compile.hxml contents:

-main Main -neko out.n --next -main Main -js out.js --next -main Main -swf out.swf

This can be compiled using: haxe compile.hxml

The problem is, when I want an argument to be the same for each compile task, I need to create a copy of the hxml file and add the argument in each task. (or make some kind of build script)

I propose a new argument to be used in conjunction with "--next". This argument could be called "--each". All arguments following "--each" should then be activated for each compile task, for example, I could now write the above example as:

-neko out.n --next -js out.js --next -swf out.swf --each -main Main

If I want debug mode for each task, I can now do:

-neko out.n --next -js out.js --next -swf out.swf --each -main Main -debug

Or better yet, I can do: haxe compile.hxml -debug

Since the haxe compiler will concatenate the "-debug" argument after the "--each" argument in the hxml file. This is especially useful as it can be controlled from the FlashDevelop IDE for custom builds. A simple addition that will allow for more flexibility and which prevents having to repeat yourself.

waneck commented 11 years ago

[comment from simon.kr...@simn.de, published at 2012-07-27T11:18:43.000Z] I like the general idea, but I think it could create some really confusing scenarios where you include a .hxml that has an --each argument. Not sure if it's worth it.

waneck commented 11 years ago

[comment from andy@onthewings.net, published at 2012-07-27T12:11:14.000Z] What about allowing multiple targets at once?

eg: -main Main -neko out.n -js out.js -swf out.swf

waneck commented 11 years ago

[comment from mpcref, published at 2012-07-27T18:41:55.000Z] @Simon: what do you mean by "include a .hxml" and what kind of confusing scenarios do you foresee?

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 2012-07-28T12:53:35.000Z] The proposed semantics is not very clear at all.

We could propose instead :

haxe --each -debug compile.hxml

That would apply -debug to each of the compilation steps in compile.hxml

If you want to apply several parameters, you would need several --each :

haxe --each -debug --each "-D dev" compile.hxml

What do you think ?

waneck commented 11 years ago

[comment from net.just...@googlemail.com, published at 2012-07-28T13:24:40.000Z] haxe --each -debug --each "-D dev" compile.hxml

how would this work with editors like flashdevelop? Are you suggesting nested .hxml? If it is nested I don't see any need for --each, but if you wanted to put it in a single file you may need some sort of additional syntax so that you can have more complex conditions.

-main Main < -neko out.n -js out.js -swf out.swf

so on command line haxe -main Main < -neko out.n -js out.js -swf out.swf >

I often wondered if you could add conditionals in the hxml

if all && !js

-main Main

else

-main MainJs

end

if mac || linux

-main Main

elseif pc

-main MainPC

end

but I guess that would get messy on the commandline, not quite sure how you would write that.

I don't think 'each' as proposed is obvious enough, or flexible enough, it just saves a small amount of typing but adds confusion, I think new users using complex libraries should be considered here, I can imagine --each being a source of much confusion if not implemented well.

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 2012-07-28T13:40:01.000Z] There is no nesting in hxml : everytime the compiler find a parameter ending with .hxml, he replaces it with the parameters stored inside this file.

You can then have .hxml including other .hxml, and crash the compiler by doing recursive references if you want to try.

waneck commented 11 years ago

[comment from mpcref, published at 2012-07-29T17:47:12.000Z] several --each parameters works as well but I was thinking the compiler could just apply each parameter it encounters following "--each" to each compile job. It is fully backwards compatible, I see no reason why this could break anything. My main reason for the requested feature is an easy way to set the debug flag when compiling a client-server application. You can then switch debug mode for both client and server code. In FlashDevelop you can set up a custom build and do a debug compile depending on the value of the dropdown box. But that's just one example. This is not about having to type less, it's about the abillity to centralize compiler parameters. I realise now that this can also be accomplished using several hxml files but this is more complicated then the "--each" parameter I propose. Allow me to show you the difference.

Say, I have a client that communicates with a server. I want to always compile both so I need a "--next" parameter. Whenever debug mode is active, I want both the client and the server to be compiled as such. Not only do I want debug mode to always be the same for each target but I also want some other parameters that must always be the same for each target. I also do not want to repeat myself (DRY) so I want every parameter specified just once, as in, in one single location. This makes my project maintainable and less error-prone. I could setup my hxml files like this: (without using "--each")

clientserver.hxml: client.hxml each.hxml --next server.hxml each.hxml

clientserver-debug.hxml: client.hxml each.hxml -debug --next server.hxml each.hxml -debug

client.hxml: -js out.js -main MyClient

server.hxml: -php out -main MyServer

each.hxml: -D haxe3 -resource foo.txt@foo -resource bar.txt@bar

In my FlashDevelop project settings, I choose "Custom Build" and I set the pre-build command to "haxe clientserver-debug.hxml". FlashDevelop will automatically remove "-debug" when doing a release compile. I now have 5 hxml files and only the references to the hxml files are repeated. Compare that to this solution using the "--each" parameter:

clientserver.hxml: -js out.js -main MyClient --next -php out -main MyServer --each -D haxe3 -resource foo.txt@foo -resource bar.txt@bar

clientserver-debug.hxml: clientserver.hxml -debug

Much cleaner and more maintainable I believe. Using clientserver-debug.hxml isn't even really needed but it's currently the easiest way to let FlashDevelop do the right thing without using a batch script. Ideally, the pre-build command would just be "haxe clientserver.hxml -$(BuildConfig)" but because "-release" is an invalid haxe parameter, this won't work.

I hope I made things a bit more clear.

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 2012-08-06T11:05:52.000Z] Because haxe process params in order, I made the following implementation in r5240

--each This will apply all parameters BEFORE --each to all compilations. Exemple : -debug -main Test --each -swf test.swf --each -neko test.n
waneck commented 11 years ago

[comment from simon.kr...@simn.de, published at 2012-08-06T11:18:26.000Z] Could we add a version of --next which does not apply the --each arguments? Currently we could not replace our use of params.hxml in the unit tests because there are two --next steps which do not use params.hxml.

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 2012-08-06T12:12:30.000Z] You can use another --each to reset the each list :

-debug --each

--next --next --each (reset)
waneck commented 11 years ago

[comment from mpcref, published at 2012-08-06T13:44:14.000Z] So, if I understand correctly the above example now becomes:

clientserver.hxml: -D haxe3 -resource foo.txt@foo -resource bar.txt@bar --each -js out.js -main MyClient --next -php out -main MyServer

clientserver-debug.hxml: -debug clientserver.hxml

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 2012-08-06T13:48:46.000Z] Yes, this is correct

waneck commented 11 years ago

[comment from mpcref, published at 2012-08-06T13:49:47.000Z] that works too, thanks for the effort, will test soon!

waneck commented 11 years ago

[comment from mpcref, published at 2012-08-06T14:23:36.000Z] By the way, speaking of "-release" not being a valid haxe parameter when attempting to use "haxe -$(BuildConfig) clientserver.hxml" ...

Until now I wouldn't consider this to be something that should be 'fixed' in haxe as it is FlashDevelop specific. But now that this "--each" parameter is here and considering "-debug" is a switch, we could also implement "-release" as a valid (default) parameter that can be used to override "-debug --each".

As an added bonus, this would enable us to use "haxe -$(BuildConfig)", allowing for smoother integration between FlashDevelop and the haxe compiler. What do you think?

waneck commented 11 years ago

[comment from ncanna...@gmail.com, published at 2012-08-06T16:26:54.000Z] Seems too much like a hack. Instead you should ask to FD team to insert -debug --each if the compiler version > 2.11 when compiling in Debug mode.