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