mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 03:00:17 +00:00
Add support for overriding the default name/location of the escript; add support for cleaning generated script file
--HG-- extra : rebase_source : 466f440dcb699e031c5c520d28ee7731b60c535a
This commit is contained in:
parent
968ef1cc77
commit
67d4fbf337
1 changed files with 18 additions and 5 deletions
|
@ -26,7 +26,8 @@
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
-module(rebar_escripter).
|
-module(rebar_escripter).
|
||||||
|
|
||||||
-export([escriptize/2]).
|
-export([escriptize/2,
|
||||||
|
clean/2]).
|
||||||
|
|
||||||
-include("rebar.hrl").
|
-include("rebar.hrl").
|
||||||
|
|
||||||
|
@ -35,10 +36,14 @@
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
|
||||||
escriptize(Config, AppFile) ->
|
escriptize(Config, AppFile) ->
|
||||||
%% Extract the application name from the archive -- this will be be what
|
%% Extract the application name from the archive -- this is the default
|
||||||
%% we call the output script
|
%% name of the generated script
|
||||||
AppName = rebar_app_utils:app_name(AppFile),
|
AppName = rebar_app_utils:app_name(AppFile),
|
||||||
|
|
||||||
|
%% Get the output filename for the escript -- this may include dirs
|
||||||
|
Filename = rebar_config:get_local(Config, escript_name, AppName),
|
||||||
|
filelib:ensure_dir(Filename),
|
||||||
|
|
||||||
%% Look for a list of other applications (dependencies) to include
|
%% Look for a list of other applications (dependencies) to include
|
||||||
%% in the output file. We then use the .app files for each of these
|
%% in the output file. We then use the .app files for each of these
|
||||||
%% to pull in all the .beam files.
|
%% to pull in all the .beam files.
|
||||||
|
@ -52,7 +57,7 @@ escriptize(Config, AppFile) ->
|
||||||
%% Archive was successfully created. Prefix that binary with our
|
%% Archive was successfully created. Prefix that binary with our
|
||||||
%% header and write to our escript file
|
%% header and write to our escript file
|
||||||
Script = <<"#!/usr/bin/env escript\n", ZipBin/binary>>,
|
Script = <<"#!/usr/bin/env escript\n", ZipBin/binary>>,
|
||||||
case file:write_file(AppName, Script) of
|
case file:write_file(Filename, Script) of
|
||||||
ok ->
|
ok ->
|
||||||
ok;
|
ok;
|
||||||
{error, WriteError} ->
|
{error, WriteError} ->
|
||||||
|
@ -65,9 +70,17 @@ escriptize(Config, AppFile) ->
|
||||||
end,
|
end,
|
||||||
|
|
||||||
%% Finally, update executable perms for our script
|
%% Finally, update executable perms for our script
|
||||||
[] = os:cmd(?FMT("chmod u+x ~p", [AppName])),
|
[] = os:cmd(?FMT("chmod u+x ~p", [Filename])),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
clean(Config, AppFile) ->
|
||||||
|
%% Extract the application name from the archive -- this is the default
|
||||||
|
%% name of the generated script
|
||||||
|
AppName = rebar_app_utils:app_name(AppFile),
|
||||||
|
|
||||||
|
%% Get the output filename for the escript -- this may include dirs
|
||||||
|
Filename = rebar_config:get_local(Config, escript_name, AppName),
|
||||||
|
rebar_file_utils:delete_each([Filename]).
|
||||||
|
|
||||||
|
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
|
Loading…
Reference in a new issue