PageRenderTime 5ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/support/gen_app_file.erl

http://github.com/skarab/ewgi
Erlang | 40 lines | 23 code | 6 blank | 11 comment | 1 complexity | 93abc5a703691ab0f43ff3c9489b2ba1 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception
  1. #!/usr/bin/env escript
  2. %% -*- erlang -*-
  3. %% @author Davide MarquĂŞs <nesrait@gmail.com>
  4. %% @copyright 2009 Davide MarquĂŞs <nesrait@gmail.com>
  5. %%
  6. %% @doc .app file generator: copies AppSrc to AppTarget replacing %VSN% by the
  7. %% Version passed as a parameter and %MODULES% by the names of the modules
  8. %% for which we can find .beam files under the AppTargets directory.
  9. %% @end
  10. %%
  11. %% Licensed under the MIT license:
  12. %% http://www.opensource.org/licenses/mit-license.php
  13. main([AppSrc, AppTarget, Version]) ->
  14. EBinFolder = filename:dirname(AppTarget) ++ "/",
  15. Modules = get_app_modules(EBinFolder),
  16. generate_app_file(AppSrc, AppTarget, Version, Modules),
  17. ok;
  18. main(_) ->
  19. io:format("Invalid arguments to gen_app.erl!").
  20. get_app_modules(EBinFolder) ->
  21. BeamFiles = filelib:wildcard(EBinFolder ++ "*.beam"),
  22. Names = [extract_module(beam_lib:info(X)) || X <- BeamFiles],
  23. string:join(Names, ", ").
  24. extract_module([]) ->
  25. "undefined";
  26. extract_module([{module, Mod}|_]) ->
  27. atom_to_list(Mod);
  28. extract_module([_|R]) ->
  29. extract_module(R).
  30. generate_app_file(AppSrc, AppTarget, Version, Modules) ->
  31. {ok, AppFile} = file:read_file(AppSrc),
  32. App1 = re:replace(AppFile, "%VSN%", Version),
  33. App2 = re:replace(App1, "%MODULES%", Modules),
  34. ok = file:write_file(AppTarget, App2).