mirror of
https://github.com/correl/rebar.git
synced 2024-11-14 19:19:30 +00:00
Change escript zip archive creation as suggested by Siri Hansen
1. manually insert directory entries to work around issues fixed in R15B02 erl_prim_loader 2. put the escript archive's beams in appname/appname/ebin Tested with R13B03 and R15B01.
This commit is contained in:
parent
795f9345a7
commit
563607bc02
2 changed files with 45 additions and 9 deletions
|
@ -2,7 +2,6 @@
|
||||||
%% ex: ts=4 sw=4 ft=erlang et
|
%% ex: ts=4 sw=4 ft=erlang et
|
||||||
|
|
||||||
{app_bin, ["priv/rebar"]}.
|
{app_bin, ["priv/rebar"]}.
|
||||||
{escript_emu_args, "%%! -noshell -noinput\n"}.
|
|
||||||
%% escript_incl_extra is for internal rebar-private use only.
|
%% escript_incl_extra is for internal rebar-private use only.
|
||||||
%% Do not use outside rebar. Config interface is not stable.
|
%% Do not use outside rebar. Config interface is not stable.
|
||||||
{escript_incl_extra, [{"priv/templates/*", "."}]}.
|
{escript_incl_extra, [{"priv/templates/*", "."}]}.
|
||||||
|
|
|
@ -40,6 +40,7 @@ escriptize(Config0, AppFile) ->
|
||||||
%% Extract the application name from the archive -- this is the default
|
%% Extract the application name from the archive -- this is the default
|
||||||
%% name of the generated script
|
%% name of the generated script
|
||||||
{Config, AppName} = rebar_app_utils:app_name(Config0, AppFile),
|
{Config, AppName} = rebar_app_utils:app_name(Config0, AppFile),
|
||||||
|
AppNameStr = atom_to_list(AppName),
|
||||||
|
|
||||||
%% Get the output filename for the escript -- this may include dirs
|
%% Get the output filename for the escript -- this may include dirs
|
||||||
Filename = rebar_config:get_local(Config, escript_name, AppName),
|
Filename = rebar_config:get_local(Config, escript_name, AppName),
|
||||||
|
@ -57,7 +58,10 @@ escriptize(Config0, AppFile) ->
|
||||||
|
|
||||||
%% Construct the archive of everything in ebin/ dir -- put it on the
|
%% Construct the archive of everything in ebin/ dir -- put it on the
|
||||||
%% top-level of the zip file so that code loading works properly.
|
%% top-level of the zip file so that code loading works properly.
|
||||||
Files = load_files("*", "ebin") ++ InclBeams ++ InclExtra,
|
EbinPrefix = filename:join(AppNameStr, "ebin"),
|
||||||
|
EbinFiles = usort(load_files(EbinPrefix, "*", "ebin")),
|
||||||
|
ExtraFiles = usort(InclBeams ++ InclExtra),
|
||||||
|
Files = EbinFiles ++ ExtraFiles,
|
||||||
|
|
||||||
case zip:create("mem", Files, [memory]) of
|
case zip:create("mem", Files, [memory]) of
|
||||||
{ok, {"mem", ZipBin}} ->
|
{ok, {"mem", ZipBin}} ->
|
||||||
|
@ -66,7 +70,10 @@ escriptize(Config0, AppFile) ->
|
||||||
Shebang = rebar_config:get(Config, escript_shebang,
|
Shebang = rebar_config:get(Config, escript_shebang,
|
||||||
"#!/usr/bin/env escript\n"),
|
"#!/usr/bin/env escript\n"),
|
||||||
Comment = rebar_config:get(Config, escript_comment, "%%\n"),
|
Comment = rebar_config:get(Config, escript_comment, "%%\n"),
|
||||||
EmuArgs = rebar_config:get(Config, escript_emu_args, "%%!\n"),
|
DefaultEmuArgs = ?FMT("%%! -pa ~s/~s/ebin -noshell -noinput\n",
|
||||||
|
[AppNameStr, AppNameStr]),
|
||||||
|
EmuArgs = rebar_config:get(Config, escript_emu_args,
|
||||||
|
DefaultEmuArgs),
|
||||||
Script = iolist_to_binary([Shebang, Comment, EmuArgs, ZipBin]),
|
Script = iolist_to_binary([Shebang, Comment, EmuArgs, ZipBin]),
|
||||||
case file:write_file(Filename, Script) of
|
case file:write_file(Filename, Script) of
|
||||||
ok ->
|
ok ->
|
||||||
|
@ -109,9 +116,8 @@ get_app_beams([App | Rest], Acc) ->
|
||||||
?ABORT("Failed to get ebin/ directory for "
|
?ABORT("Failed to get ebin/ directory for "
|
||||||
"~p escript_incl_apps.", [App]);
|
"~p escript_incl_apps.", [App]);
|
||||||
Path ->
|
Path ->
|
||||||
Acc2 = [{filename:join([App, ebin, F]),
|
Prefix = filename:join(atom_to_list(App), "ebin"),
|
||||||
file_contents(filename:join(Path, F))} ||
|
Acc2 = load_files(Prefix, "*", Path),
|
||||||
F <- filelib:wildcard("*", Path)],
|
|
||||||
get_app_beams(Rest, Acc2 ++ Acc)
|
get_app_beams(Rest, Acc2 ++ Acc)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -122,11 +128,42 @@ get_extra(Config) ->
|
||||||
end, [], Extra).
|
end, [], Extra).
|
||||||
|
|
||||||
load_files(Wildcard, Dir) ->
|
load_files(Wildcard, Dir) ->
|
||||||
[read_file(Filename, Dir) || Filename <- filelib:wildcard(Wildcard, Dir)].
|
load_files("", Wildcard, Dir).
|
||||||
|
|
||||||
read_file(Filename, Dir) ->
|
load_files(Prefix, Wildcard, Dir) ->
|
||||||
{Filename, file_contents(filename:join(Dir, Filename))}.
|
[read_file(Prefix, Filename, Dir)
|
||||||
|
|| Filename <- filelib:wildcard(Wildcard, Dir)].
|
||||||
|
|
||||||
|
read_file(Prefix, Filename, Dir) ->
|
||||||
|
Filename1 = case Prefix of
|
||||||
|
"" ->
|
||||||
|
Filename;
|
||||||
|
_ ->
|
||||||
|
filename:join([Prefix, Filename])
|
||||||
|
end,
|
||||||
|
[dir_entries(filename:dirname(Filename1)),
|
||||||
|
{Filename1, file_contents(filename:join(Dir, Filename))}].
|
||||||
|
|
||||||
file_contents(Filename) ->
|
file_contents(Filename) ->
|
||||||
{ok, Bin} = file:read_file(Filename),
|
{ok, Bin} = file:read_file(Filename),
|
||||||
Bin.
|
Bin.
|
||||||
|
|
||||||
|
%% given a filename return zip archive dir entries for each sub-dir
|
||||||
|
dir_entries(File) ->
|
||||||
|
Dirs = dirs(File),
|
||||||
|
[{Dir ++ "/", <<>>} || Dir <- Dirs].
|
||||||
|
|
||||||
|
%% given "foo/bar/baz" return ["foo", "foo/bar", "foo/bar/baz"]
|
||||||
|
dirs(Dir) ->
|
||||||
|
dirs1(filename:split(Dir), "", []).
|
||||||
|
|
||||||
|
dirs1([], _, Acc) ->
|
||||||
|
lists:reverse(Acc);
|
||||||
|
dirs1([H|T], "", []) ->
|
||||||
|
dirs1(T, H, [H]);
|
||||||
|
dirs1([H|T], Last, Acc) ->
|
||||||
|
Dir = filename:join(Last, H),
|
||||||
|
dirs1(T, Dir, [Dir|Acc]).
|
||||||
|
|
||||||
|
usort(List) ->
|
||||||
|
lists:ukeysort(1, lists:flatten(List)).
|
||||||
|
|
Loading…
Reference in a new issue