Is it possible to compile Elixir script file?

658 views
Skip to first unread message

bengt e

unread,
Jun 24, 2015, 2:00:29 PM6/24/15
to elixir-l...@googlegroups.com
Greetings,

If possible I would like to test the functions in an Elixir script with ExUnit. It seems to me that I first need to compile the script (.exs) file.
This is not easy. Elixirc (and c from iex command line) will run the script, not compile it, but perhaps there is another way to compile?

It does not seem to be the extension. A script file that ends with .ex will be run as a script by elixirc. And a script (.exs extension and #! on the first line) with only defmodule (no "free" functions calls outside defmodule's body) will be compiled.


bengt

José Valim

unread,
Jun 24, 2015, 2:34:56 PM6/24/15
to elixir-l...@googlegroups.com
In order to compile a file, we need to execute it. The only difference between compilation and scripting is that a .beam file is written for every module. Other than that, executing and compiling a file is exactly the same.



José Valim
Skype: jv.ptec
Founder and Director of R&D

--
You received this message because you are subscribed to the Google Groups "elixir-lang-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-ta...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-talk/fb9d909f-a73a-4320-8019-99357e48112b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

bengt e

unread,
Jun 24, 2015, 3:00:17 PM6/24/15
to elixir-l...@googlegroups.com, jose....@plataformatec.com.br
Thank you for the very prompt reply.

I will try to find out myself, but perhaps you know the answer to the following:
How do I pass a flag to the script being compiled to tell it not to do anything during the execution part of the compilation?
The script will have to know of this flag, of course, but how will it get the flag?

"Elixirc -h" hints that flags after "--" will be available to "the executing code", but I do not see any beam file when I try:
elixirc -- --donothing myscript.exs


bengt

Eric Meadows-Jönsson

unread,
Jun 25, 2015, 6:57:39 AM6/25/15
to elixir-l...@googlegroups.com
You can set an environment variable and retrieve it in the script: `DO_SOMETHING=false elixirc file.exs` and then retrieve it with `System.get_env("DO_SOMETHING")`.


For more options, visit https://groups.google.com/d/optout.



--
Eric Meadows-Jönsson

bengt e

unread,
Jun 25, 2015, 9:31:41 AM6/25/15
to elixir-l...@googlegroups.com
Thank you for the suggestion. I tried to get the "--" to work, but failed, so an environment variable is what I wiil do.

What does the elixirc documentation mean when it says:
** Options given after -- are passed down to the executed code


bengt
Reply all
Reply to author
Forward
0 new messages