Refactor rebar to build a self-contained script

This commit is contained in:
Dave Smith 2009-12-04 13:48:57 -07:00
parent 63d4968e36
commit b491898690
7 changed files with 59 additions and 61 deletions

View file

@ -1 +1,2 @@
.beam .beam
rebar

53
bootstrap Executable file
View file

@ -0,0 +1,53 @@
#!/usr/bin/env escript
%% -*- erlang -*-
main(Args) ->
%% Compile all src/*.erl to ebin
case make:files(filelib:wildcard("src/*.erl"), [{outdir, "ebin"}, {i, "include"}]) of
up_to_date ->
ok;
error ->
io:format("Failed to compile rebar files!\n"),
halt(1)
end,
%% Make sure file:consult can parse the .app file
case file:consult("ebin/rebar.app") of
{ok, _} ->
ok;
{error, Reason} ->
io:format("Invalid syntax in ebin/rebar.app: ~p\n", [Reason]),
halt(1)
end,
%% Add ebin/ to our path
true = code:add_path("ebin"),
%% Run rebar to do proper .app validation and such
rebar:main(["compile"] ++ Args),
%% Construct the archive of everything in ebin/ dir -- put it on the
%% top-level of the zip file so that code loading works properly.
Files = filelib:wildcard("*", "ebin"),
case zip:create("mem", Files, [{cwd, "ebin"}, memory]) of
{ok, {"mem", ZipBin}} ->
%% Archive was successfully created. Prefix that binary with our
%% header and write to "rebar" file
Script = <<"#!/usr/bin/env escript\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
[] = os:cmd("chmod u+x rebar").

View file

@ -1,7 +1,8 @@
{application, rebar, {application, rebar,
[{description, "Rebar: Erlang Build Tool"}, [{description, "Rebar: Erlang Build Tool"},
{vsn, "1"}, {vsn, "1"},
{modules, [ rebar_app_utils, {modules, [ rebar,
rebar_app_utils,
rebar_config, rebar_config,
rebar_core, rebar_core,
rebar_ct, rebar_ct,

20
install
View file

@ -1,20 +0,0 @@
#!/bin/bash
## Check path for exiting rebar instance -- if it's around, use it
## for compilation (NOT installation!)
`which -s rebar`
if [ $? == 0 ]; then
rebar compile ${@}
else
## Use raw erlc..
erlc -I include -o ebin src/*.erl
fi
if [ $? != 0 ]; then
exit $?
fi
## Use application installer to perform actual installation
## into erlang distro
export ERL_LIBS=`(cd .. && pwd)`
priv/rebar install ${@}

View file

@ -1,37 +0,0 @@
#!/usr/bin/env escript
%% -*- erlang -*-
%% -------------------------------------------------------------------
%%
%% rebar: Erlang Build Tools
%%
%% Copyright (c) 2009 Dave Smith (dizzyd@dizzyd.com)
%%
%% Permission is hereby granted, free of charge, to any person obtaining a copy
%% of this software and associated documentation files (the "Software"), to deal
%% in the Software without restriction, including without limitation the rights
%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
%% copies of the Software, and to permit persons to whom the Software is
%% furnished to do so, subject to the following conditions:
%%
%% The above copyright notice and this permission notice shall be included in
%% all copies or substantial portions of the Software.
%%
%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
%% THE SOFTWARE.
%% -------------------------------------------------------------------
-include_lib("rebar/include/rebar.hrl").
main(Args) ->
case rebar_core:run(Args) of
ok ->
ok;
_ ->
halt(1)
end.

View file

@ -51,8 +51,8 @@ load_app_file(Filename) ->
{ok, AppName, AppData}; {ok, AppName, AppData};
{error, Reason} -> {error, Reason} ->
?ERROR("Failed to load app file from ~s: ~p\n", [Filename, Reason]), ?ERROR("Failed to load app file from ~s: ~p\n", [Filename, Reason]),
error; ?FAIL;
Other -> Other ->
?ERROR("Unexpected terms from app file ~s: ~p\n", [Filename, Other]), ?ERROR("Unexpected terms from app file ~s: ~p\n", [Filename, Other]),
error ?FAIL
end. end.

View file

@ -38,7 +38,7 @@ run(Args) ->
Commands = filter_flags(Args, []), Commands = filter_flags(Args, []),
%% Pre-load the rebar app so that we get default configuration %% Pre-load the rebar app so that we get default configuration
application:load(rebar), ok = application:load(rebar),
%% Initialize logging system %% Initialize logging system
rebar_log:init(), rebar_log:init(),