f16f160235
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
136 lines
4.7 KiB
Diff
136 lines
4.7 KiB
Diff
From 05b31a23c8d70a3867173823478defe029b89c5d Mon Sep 17 00:00:00 2001
|
|
From: Peter Lemenkov <lemenkov@gmail.com>
|
|
Date: Tue, 28 Sep 2010 23:04:36 +0400
|
|
Subject: [PATCH 1/9] No need to create bundle and don't try to load anything
|
|
from escript
|
|
|
|
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
|
|
---
|
|
bootstrap | 40 ----------------------------------------
|
|
src/rebar_templater.erl | 30 ++----------------------------
|
|
2 files changed, 2 insertions(+), 68 deletions(-)
|
|
|
|
diff --git a/bootstrap b/bootstrap
|
|
index c8a40de..be0523a 100755
|
|
--- a/bootstrap
|
|
+++ b/bootstrap
|
|
@@ -56,46 +56,6 @@ main(Args) ->
|
|
%% Run rebar to do proper .app validation and such
|
|
rebar:main(["compile"] ++ Args),
|
|
|
|
- %% Read the contents of the files in ebin and templates; note that we
|
|
- %% place all the beam files at the top level of the code archive so
|
|
- %% that code loading works properly.
|
|
- Files = load_files("*", "ebin") ++ load_files("priv/templates/*", "."),
|
|
-
|
|
- case zip:create("mem", Files, [memory]) of
|
|
- {ok, {"mem", ZipBin}} ->
|
|
- %% 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} ->
|
|
- io:format("Failed to construct rebar script archive: ~p\n",
|
|
- [ZipError]),
|
|
- halt(1)
|
|
- end,
|
|
-
|
|
- %% Finally, update executable perms for our script on *nix,
|
|
- %% or write out script files on win32.
|
|
- case os:type() of
|
|
- {unix,_} ->
|
|
- [] = os:cmd("chmod u+x rebar"),
|
|
- ok;
|
|
- {win32,_} ->
|
|
- write_windows_scripts(),
|
|
- ok;
|
|
- _ ->
|
|
- ok
|
|
- end,
|
|
-
|
|
%% Add a helpful message
|
|
io:format("Congratulations! You now have a self-contained script called"
|
|
" \"rebar\" in\n"
|
|
diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl
|
|
index f608512..450eb4d 100644
|
|
--- a/src/rebar_templater.erl
|
|
+++ b/src/rebar_templater.erl
|
|
@@ -54,11 +54,6 @@
|
|
create(Config, File).
|
|
|
|
'list-templates'(_Config, _File) ->
|
|
- %% Load a list of all the files in the escript -- cache it in the pdict
|
|
- %% since we'll potentially need to walk it several times over the course
|
|
- %% of a run.
|
|
- cache_escript_files(),
|
|
-
|
|
%% Build a list of available templates
|
|
AvailTemplates = find_disk_templates() ++ find_escript_templates(),
|
|
?CONSOLE("Available templates:\n", []),
|
|
@@ -70,11 +65,6 @@
|
|
|
|
|
|
create(_Config, _) ->
|
|
- %% Load a list of all the files in the escript -- cache it in the pdict
|
|
- %% since we'll potentially need to walk it several times over the course
|
|
- %% of a run.
|
|
- cache_escript_files(),
|
|
-
|
|
%% Build a list of available templates
|
|
AvailTemplates = find_disk_templates() ++ find_escript_templates(),
|
|
?DEBUG("Available templates: ~p\n", [AvailTemplates]),
|
|
@@ -174,18 +164,6 @@ render(Bin, Context) ->
|
|
%% Internal functions
|
|
%% ===================================================================
|
|
|
|
-%%
|
|
-%% Scan the current escript for available files and cache in pdict.
|
|
-%%
|
|
-cache_escript_files() ->
|
|
- {ok, Files} = rebar_utils:escript_foldl(
|
|
- fun(Name, _, GetBin, Acc) ->
|
|
- [{Name, GetBin()} | Acc]
|
|
- end,
|
|
- [], rebar_config:get_global(escript, undefined)),
|
|
- erlang:put(escript_files, Files).
|
|
-
|
|
-
|
|
template_id() ->
|
|
case rebar_config:get_global(template, undefined) of
|
|
undefined ->
|
|
@@ -195,8 +173,7 @@ template_id() ->
|
|
end.
|
|
|
|
find_escript_templates() ->
|
|
- [{escript, Name} || {Name, _Bin} <- erlang:get(escript_files),
|
|
- re:run(Name, ?TEMPLATE_RE, [{capture, none}]) == match].
|
|
+ [{escript, Name} || Name <- rebar_utils:find_files(code:priv_dir(rebar) ++ "/templates", ?TEMPLATE_RE)].
|
|
|
|
find_disk_templates() ->
|
|
OtherTemplates = find_other_templates(),
|
|
@@ -227,10 +204,7 @@ select_template([{Type, Avail} | Rest], Template) ->
|
|
%%
|
|
%% Read the contents of a file from the appropriate source
|
|
%%
|
|
-load_file(escript, Name) ->
|
|
- {Name, Bin} = lists:keyfind(Name, 1, erlang:get(escript_files)),
|
|
- Bin;
|
|
-load_file(file, Name) ->
|
|
+load_file(_, Name) ->
|
|
{ok, Bin} = file:read_file(Name),
|
|
Bin.
|
|
|
|
--
|
|
1.8.0.1
|
|
|