Speeding up the Erlang Edit, Compile, Run/Debug cycle

我的未来我决定 提交于 2019-12-04 08:38:27

问题


What is the fastest way to edit an Erlang application, compile the code and see the running result? Preferably jumping in the Erlang shell on the last step.

My current newbie setup:

  • A script that compiles the app and starts up the erl shell.
  • Then I type in application:start(foo).
  • When I fix a typo I recompile the module with c('module') and restart the app.

Is there a faster way? BTW. my editor of choice is Emacs.


回答1:


Here's my setup:

  • While developing, I keep the Erlang shell open in a separate terminal window.
  • I start compilation from the editor (using an key combination), or just by typing make in the source directory.
  • After compilation, I load all changed modules at once by typing l() in Erlang shell. You can find this and some other useful macros here: http://www.snookles.com/erlang/user_default.erl

There's rarely a need to restart the whole Erlang application. Reloading changed modules is a more common use-case and it is usually enough to apply your changes.

Regarding application start: if your application depends on other applications, application:start() will fail, until you start all the dependencies. Because of that, it is common to write a helper function <your-app-name>:start(). Here's an example. Another useful function is <your-app-name>:stop().

With all these techniques applied, a workflow would look like this:

  • Start the Erlang shell and keep it open; type<your-app-name>:start().
  • Make changes; run compilation; type l() in your Erlang shell.
  • When changes require application restart, type <your-app-name>:stop(), <your-app-name>:start().



回答2:


You might look at rebar as a building tool. make:all/0 and the whole make module could help as well. To explicitly reload a module from the shell you can use l(Module). Finally, you might also be interested in creating an Erlang release to "wrap" all your Erlang applications.




回答3:


editing and compiling is done by the IDE (Eclispe with erlide) which i use.

I also created a script which starts the vm my application and helpful tools. The script is only used for dev time.

For reloading the changed sources and then compiled bins, i use the reloader from mochiweb. The reloader observes the bin dir and if there are changes, it loads the moduls and runs the eunit tests, if you have some inside.

Example:

erl +A 5 +K true -name @127.0.0.1 -pa $PWD/ebin $PWD/test $PWD/deps/*/ebin -boot start_sasl -s reloader -s toolbar -s




回答4:


what you can also try is erlbuild. Erlbuild is an simple application which looks in src directory for changed source files and if it finds some files, than it compiles and load the modules again. After loading the modules, erlbuild runs the the tests of the modules.

You can find the project under : https://github.com/ulfa/erlbuild

~Ulf



来源:https://stackoverflow.com/questions/5809525/speeding-up-the-erlang-edit-compile-run-debug-cycle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!