mirror of
https://github.com/correl/rebar.git
synced 2024-11-23 19:19:54 +00:00
Extend escriptize and reuse in bootstrap
This commit is contained in:
parent
8fb552b73f
commit
1e980859e2
3 changed files with 20 additions and 92 deletions
84
bootstrap
84
bootstrap
|
@ -53,36 +53,9 @@ main(Args) ->
|
||||||
%% Add ebin/ to our path
|
%% Add ebin/ to our path
|
||||||
true = code:add_path("ebin"),
|
true = code:add_path("ebin"),
|
||||||
|
|
||||||
%% Run rebar to do proper .app validation and such
|
%% Run rebar compile to do proper .app validation etc.
|
||||||
rebar:main(["compile"] ++ Args),
|
%% and rebar escriptize to create the rebar script
|
||||||
|
rebar:main(["compile", "escriptize"] ++ Args),
|
||||||
TempDir = make_temp_dir(),
|
|
||||||
ok = copy_files(TempDir), %% Copy the ebin and priv/templates
|
|
||||||
{ok, Dirs} = file:list_dir(TempDir),
|
|
||||||
|
|
||||||
case zip:create("mem", Dirs, [memory, {cwd, TempDir}]) of
|
|
||||||
{ok, {"mem", ZipBin}} ->
|
|
||||||
ok = rebar_file_utils:rm_rf(TempDir),
|
|
||||||
%% Archive was successfully created. Prefix that binary with our
|
|
||||||
%% header and write to "rebar" file.
|
|
||||||
%% Without -noshell -noinput escript consumes all input that would
|
|
||||||
%% otherwise go to the shell for the next command.
|
|
||||||
Script = <<"#!/usr/bin/env escript\n%%! -noshell -noinput\n",
|
|
||||||
ZipBin/binary>>,
|
|
||||||
case file:write_file("rebar", Script) of
|
|
||||||
ok ->
|
|
||||||
ok;
|
|
||||||
{error, WriteError} ->
|
|
||||||
io:format("Failed to write rebar script: ~p\n",
|
|
||||||
[WriteError]),
|
|
||||||
halt(1)
|
|
||||||
end;
|
|
||||||
{error, ZipError} ->
|
|
||||||
ok = rebar_file_utils:rm_rf(TempDir),
|
|
||||||
io:format("Failed to construct rebar script archive: ~p\n",
|
|
||||||
[ZipError]),
|
|
||||||
halt(1)
|
|
||||||
end,
|
|
||||||
|
|
||||||
%% Finally, update executable perms for our script on *nix,
|
%% Finally, update executable perms for our script on *nix,
|
||||||
%% or write out script files on win32.
|
%% or write out script files on win32.
|
||||||
|
@ -104,37 +77,6 @@ main(Args) ->
|
||||||
"Place this script anywhere in your path\n"
|
"Place this script anywhere in your path\n"
|
||||||
"and you can use rebar to build OTP-compliant apps.\n").
|
"and you can use rebar to build OTP-compliant apps.\n").
|
||||||
|
|
||||||
make_temp_dir() ->
|
|
||||||
case temp_name("rebar.") of
|
|
||||||
{ok, TempDir} ->
|
|
||||||
case file:make_dir(TempDir) of
|
|
||||||
ok ->
|
|
||||||
TempDir;
|
|
||||||
Error ->
|
|
||||||
io:format("Failed to create temporary directory: ~p~n",
|
|
||||||
[Error]),
|
|
||||||
halt(1),
|
|
||||||
Error
|
|
||||||
end;
|
|
||||||
Error ->
|
|
||||||
io:format("Failed to create temporary directory: ~p~n",
|
|
||||||
[Error]),
|
|
||||||
halt(1)
|
|
||||||
end.
|
|
||||||
|
|
||||||
temp_name(Prefix) ->
|
|
||||||
temp_name(Prefix, 5).
|
|
||||||
|
|
||||||
temp_name(_Prefix, 0) ->
|
|
||||||
{error, eexist};
|
|
||||||
temp_name(Prefix, N) ->
|
|
||||||
Hash = erlang:phash2(make_ref()),
|
|
||||||
Name = Prefix ++ integer_to_list(Hash),
|
|
||||||
case filelib:is_file(Name) of
|
|
||||||
false -> {ok, Name};
|
|
||||||
true -> temp_name(Prefix, N-1)
|
|
||||||
end.
|
|
||||||
|
|
||||||
rm(Path) ->
|
rm(Path) ->
|
||||||
NativePath = filename:nativename(Path),
|
NativePath = filename:nativename(Path),
|
||||||
Cmd = case os:type() of
|
Cmd = case os:type() of
|
||||||
|
@ -149,26 +91,6 @@ build_time() ->
|
||||||
lists:flatten(io_lib:format("~4..0w~2..0w~2..0w_~2..0w~2..0w~2..0w",
|
lists:flatten(io_lib:format("~4..0w~2..0w~2..0w_~2..0w~2..0w~2..0w",
|
||||||
[Y, M, D, H, Min, S])).
|
[Y, M, D, H, Min, S])).
|
||||||
|
|
||||||
copy_files(Temp) ->
|
|
||||||
BaseEbinDir = filename:join("rebar", "ebin"),
|
|
||||||
BaseTemplatesDir = filename:join("priv", "templates"),
|
|
||||||
EbinDir = filename:join(Temp, BaseEbinDir),
|
|
||||||
TemplatesDir = filename:join(Temp, BaseTemplatesDir),
|
|
||||||
|
|
||||||
%% prepare directory structure
|
|
||||||
lists:foreach(
|
|
||||||
fun(Dir) ->
|
|
||||||
ok = filelib:ensure_dir(filename:join(Dir, "dummy"))
|
|
||||||
end, [EbinDir, TemplatesDir]),
|
|
||||||
|
|
||||||
%% copy content of ebin
|
|
||||||
EbinSrc = filename:join(["ebin", "*"]),
|
|
||||||
ok = rebar_file_utils:cp_r([EbinSrc], EbinDir),
|
|
||||||
|
|
||||||
%% copy content of priv/templates
|
|
||||||
TemplatesSrc = filename:join(BaseTemplatesDir, "*"),
|
|
||||||
ok = rebar_file_utils:cp_r([TemplatesSrc], TemplatesDir).
|
|
||||||
|
|
||||||
vcs_info([]) ->
|
vcs_info([]) ->
|
||||||
"No VCS info available.";
|
"No VCS info available.";
|
||||||
vcs_info([{Id, Dir, Cmd} | Rest]) ->
|
vcs_info([{Id, Dir, Cmd} | Rest]) ->
|
||||||
|
|
|
@ -2,6 +2,9 @@
|
||||||
%% 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_shebang, "#!/usr/bin/env escript\n"}.
|
||||||
|
{escript_emu_args, "%%! -noshell -noinput\n"}.
|
||||||
|
{escript_incl_extra, [{"priv/templates/*", "priv/templates"}]}.
|
||||||
{erl_opts, [warnings_as_errors]}.
|
{erl_opts, [warnings_as_errors]}.
|
||||||
{xref_checks, []}.
|
{xref_checks, []}.
|
||||||
{xref_queries,
|
{xref_queries,
|
||||||
|
|
|
@ -101,15 +101,12 @@ make_temp_dir(AppName) ->
|
||||||
ok ->
|
ok ->
|
||||||
TempDir;
|
TempDir;
|
||||||
Error ->
|
Error ->
|
||||||
io:format("Failed to create temporary directory: ~p~n",
|
?ABORT("Failed to create temporary directory: ~p~n",
|
||||||
[Error]),
|
[Error])
|
||||||
halt(1),
|
|
||||||
Error
|
|
||||||
end;
|
end;
|
||||||
Error ->
|
Error ->
|
||||||
io:format("Failed to create temporary directory: ~p~n",
|
?ABORT("Failed to create temporary directory: ~p~n",
|
||||||
[Error]),
|
[Error])
|
||||||
halt(1)
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
temp_name(Prefix) ->
|
temp_name(Prefix) ->
|
||||||
|
@ -130,20 +127,26 @@ copy_files(Config, AppName, Temp) ->
|
||||||
EbinDir = filename:join(Temp, BaseEbinDir),
|
EbinDir = filename:join(Temp, BaseEbinDir),
|
||||||
|
|
||||||
%% 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
|
||||||
%% to pull in all the .beam files.
|
%% these to pull in all the .beam files.
|
||||||
InclApps = rebar_config:get_local(Config, escript_incl_apps, []),
|
InclApps = rebar_config:get_local(Config, escript_incl_apps, []),
|
||||||
InclEbinDirs = get_app_ebin_dirs(InclApps, []),
|
InclEbinDirs = get_app_ebin_dirs(InclApps, []),
|
||||||
%% copy incl_apps files
|
%% copy incl_apps files
|
||||||
lists:foreach(fun(Src) -> ok = copy_files(Src, EbinDir) end, InclEbinDirs),
|
lists:foreach(fun(Src) -> ok = copy_files(Src, EbinDir) end, InclEbinDirs),
|
||||||
|
|
||||||
%% copy script's beam files
|
%% Look for a list of extra files to copy
|
||||||
|
InclExtr = rebar_config:get_local(Config, escript_incl_extra, []),
|
||||||
|
lists:foreach(fun({Src, Dst}) ->
|
||||||
|
copy_files(Src, filename:join(Temp, Dst))
|
||||||
|
end, InclExtr),
|
||||||
|
|
||||||
|
%% copy script's beam files and app file
|
||||||
EbinSrc = filename:join(["ebin", "*"]),
|
EbinSrc = filename:join(["ebin", "*"]),
|
||||||
ok = copy_files(EbinSrc, EbinDir).
|
ok = copy_files(EbinSrc, EbinDir).
|
||||||
|
|
||||||
copy_files(Src, Dst) ->
|
copy_files(Src, Dst) ->
|
||||||
ok = filelib:ensure_dir(filename:join(Dst, "dummy")),
|
ok = filelib:ensure_dir(filename:join(Dst, "dummy")),
|
||||||
ok = rebar_file_utils:cp_r([Src], Dst).
|
rebar_file_utils:cp_r([Src], Dst).
|
||||||
|
|
||||||
get_app_ebin_dirs([], Acc) ->
|
get_app_ebin_dirs([], Acc) ->
|
||||||
Acc;
|
Acc;
|
||||||
|
|
Loading…
Reference in a new issue