diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rebar.app.src | 3 | ||||
-rw-r--r-- | src/rebar3.erl | 4 | ||||
-rw-r--r-- | src/rebar_app_info.erl | 6 | ||||
-rw-r--r-- | src/rebar_erlc_compiler.erl | 2 | ||||
-rw-r--r-- | src/rebar_erlydtl_compiler.erl | 13 | ||||
-rw-r--r-- | src/rebar_packages.erl | 2 | ||||
-rw-r--r-- | src/rebar_provider.erl | 4 | ||||
-rw-r--r-- | src/rebar_prv_escripter.erl | 224 | ||||
-rw-r--r-- | src/rebar_prv_install_deps.erl | 18 | ||||
-rw-r--r-- | src/rebar_templater.erl | 2 | ||||
-rw-r--r-- | src/rebar_topo.erl | 30 | ||||
-rw-r--r-- | src/rebar_utils.erl | 16 |
12 files changed, 41 insertions, 283 deletions
diff --git a/src/rebar.app.src b/src/rebar.app.src index 2e21351..daeacc0 100644 --- a/src/rebar.app.src +++ b/src/rebar.app.src @@ -21,8 +21,7 @@ {log_level, warn}, %% any_dir processing modules - {providers, [rebar_prv_escripter, - rebar_prv_deps, + {providers, [rebar_prv_deps, rebar_prv_do, rebar_prv_lock, rebar_prv_install_deps, diff --git a/src/rebar3.erl b/src/rebar3.erl index 44d7d98..ba76f80 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -103,8 +103,8 @@ init_config({Options, _NonOptArgs}) -> true -> ?DEBUG("Load global config file ~p~n", [GlobalConfigFile]), - rebar_config:consult_file(GlobalConfigFile), - rebar_state:new(GlobalConfigFile, Config1); + GlobalConfig = rebar_state:new(rebar_config:consult_file(GlobalConfigFile)), + rebar_state:new(GlobalConfig, Config1); false -> rebar_state:new(Config1) end, diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl index 5f44004..be35f79 100644 --- a/src/rebar_app_info.erl +++ b/src/rebar_app_info.erl @@ -36,7 +36,7 @@ app_file_src :: file:name() | undefined, app_file :: file:name(), config :: rebar_config:config() | undefined, - original_vsn :: string(), + original_vsn :: string() | undefined, app_details=[] :: list(), deps=[] :: list(), dep_level :: integer(), @@ -47,7 +47,7 @@ %%============================================================================ %% types %%============================================================================ --opaque t() :: record(app_info_t). +-type t() :: record(app_info_t). %%============================================================================ %% API @@ -186,7 +186,7 @@ dir(AppInfo=#app_info_t{}, Dir) -> ebin_dir(#app_info_t{dir=Dir}) -> filename:join(Dir, "ebin"). --spec source(t(), string()) -> t(). +-spec source(t(), string() | tuple()) -> t(). source(AppInfo=#app_info_t{}, Source) -> AppInfo#app_info_t{source=Source}. diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index 4076717..4f70450 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -241,7 +241,7 @@ test_compile_config_and_opts(Config, ErlOpts, Cmd) -> %% *_first_files is questionable as the file would need to exist %% in all project directories for it to work. OptsAtom = list_to_atom(Cmd ++ "_compile_opts"), - TestOpts = rebar_state:get_list(Config3, OptsAtom, []), + TestOpts = rebar_state:get(Config3, OptsAtom, []), Opts0 = [{d, 'TEST'}] ++ ErlOpts ++ TestOpts ++ TriqOpts ++ PropErOpts ++ EqcOpts, Opts = [O || O <- Opts0, O =/= no_debug_info], diff --git a/src/rebar_erlydtl_compiler.erl b/src/rebar_erlydtl_compiler.erl index 88ee20f..7d90ada 100644 --- a/src/rebar_erlydtl_compiler.erl +++ b/src/rebar_erlydtl_compiler.erl @@ -230,24 +230,15 @@ do_compile(Config, Source, Target, DtlOpts) -> Opts = lists:ukeymerge(1, DtlOpts, Sorted), ?INFO("Compiling \"~s\" -> \"~s\" with options:~n ~s~n", [Source, Target, io_lib:format("~p", [Opts])]), - case erlydtl:compile(Source, - module_name(Target), + case erlydtl:compile(ec_cnv:to_binary(Source), + ec_cnv:to_atom(module_name(Target)), Opts) of - ok -> - ok; {ok, _Mod} -> ok; {ok, _Mod, Ws} -> rebar_base_compiler:ok_tuple(Config, Source, Ws); - {ok, _Mod, _Bin, Ws} -> - rebar_base_compiler:ok_tuple(Config, Source, Ws); error -> rebar_base_compiler:error_tuple(Config, Source, [], [], Opts); - {error, {_File, _Msgs} = Error} -> - rebar_base_compiler:error_tuple(Config, Source, [Error], [], Opts); - {error, Msg} -> - Es = [{Source, [{erlydtl_parser, Msg}]}], - rebar_base_compiler:error_tuple(Config, Source, Es, [], Opts); {error, Es, Ws} -> rebar_base_compiler:error_tuple(Config, Source, Es, Ws, Opts) end. diff --git a/src/rebar_packages.erl b/src/rebar_packages.erl index dd229d3..a87c388 100644 --- a/src/rebar_packages.erl +++ b/src/rebar_packages.erl @@ -4,7 +4,7 @@ -include("rebar.hrl"). --spec get_packages(rebar_state:t()) -> {list(), rlx_depsolver:t()}. +-spec get_packages(rebar_state:t()) -> {dict:dict(), tuple()}. get_packages(State) -> RebarDir = rebar_state:get(State, global_rebar_dir, filename:join(os:getenv("HOME"), ".rebar")), PackagesFile = filename:join(RebarDir, "packages"), diff --git a/src/rebar_provider.erl b/src/rebar_provider.erl index 8a3d610..872c2e1 100644 --- a/src/rebar_provider.erl +++ b/src/rebar_provider.erl @@ -18,7 +18,7 @@ %%% Types %%%=================================================================== --opaque t() :: record(provider). +-type t() :: record(provider). -type provider_name() :: atom(). @@ -156,6 +156,6 @@ reorder_providers(OProviderList) -> case rebar_topo:sort(OProviderList) of {ok, ProviderList} -> ProviderList; - {cycle, _} -> + {error, {cycle, _}} -> ?ERROR("There was a cycle in the provider list. Unable to complete build!", []) end. diff --git a/src/rebar_prv_escripter.erl b/src/rebar_prv_escripter.erl deleted file mode 100644 index bdaf1b8..0000000 --- a/src/rebar_prv_escripter.erl +++ /dev/null @@ -1,224 +0,0 @@ -%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*- -%% ex: ts=4 sw=4 et -%% ------------------------------------------------------------------- -%% -%% 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. -%% ------------------------------------------------------------------- --module(rebar_prv_escripter). - --behaviour(rebar_provider). - --export([init/1, - do/1]). - --export([escriptize/2, - clean/2]). - -%% for internal use only --export([info/2]). - --include("rebar.hrl"). --include_lib("kernel/include/file.hrl"). - --define(PROVIDER, escriptize). --define(DEPS, [app_builder]). - -%% =================================================================== -%% Public API -%% =================================================================== - --spec init(rebar_state:t()) -> {ok, rebar_state:t()}. -init(State) -> - State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER, - provider_impl = ?MODULE, - bare = false, - deps = ?DEPS, - example = "rebar escriptize", - short_desc = "Build escript from project.", - desc = "", - opts = []}), - {ok, State1}. - --spec do(rebar_state:t()) -> {ok, rebar_state:t()}. -do(Config) -> - AppName = rebar_state:get(Config, escript_top_level_app, undefined), - App = rebar_state:get_app(Config, AppName), - {ok, Config1} = escriptize(Config, rebar_app_info:app_file(App)), - {ok, Config1}. - -escriptize(Config0, AppFile) -> - %% Extract the application name from the archive -- this is the default - %% name of the generated script - {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 - Filename = rebar_state:get(Config, escript_name, AppName), - ok = filelib:ensure_dir(Filename), - - %% Look for a list of other applications (dependencies) to include - %% in the output file. We then use the .app files for each of these - %% to pull in all the .beam files. - InclBeams = get_app_beams( - rebar_state:get(Config, escript_incl_apps, []), []), - - %% Look for a list of extra files to include in the output file. - %% For internal rebar-private use only. Do not use outside rebar. - InclExtra = get_extra(Config), - - %% Construct the archive of everything in ebin/ dir -- put it on the - %% top-level of the zip file so that code loading works properly. - 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 - {ok, {"mem", ZipBin}} -> - %% Archive was successfully created. Prefix that binary with our - %% header and write to our escript file - Shebang = rebar_state:get(Config, escript_shebang, - "#!/usr/bin/env escript\n"), - Comment = rebar_state:get(Config, escript_comment, "%%\n"), - DefaultEmuArgs = ?FMT("%%! -pa ~s/~s/ebin\n", - [AppNameStr, AppNameStr]), - EmuArgs = rebar_state:get(Config, escript_emu_args, - DefaultEmuArgs), - Script = iolist_to_binary([Shebang, Comment, EmuArgs, ZipBin]), - case file:write_file(Filename, Script) of - ok -> - ok; - {error, WriteError} -> - ?ERROR("Failed to write ~p script: ~p\n", - [AppName, WriteError]), - ?FAIL - end; - {error, ZipError} -> - ?ERROR("Failed to construct ~p escript: ~p\n", - [AppName, ZipError]), - ?FAIL - end, - - %% Finally, update executable perms for our script - {ok, #file_info{mode = Mode}} = file:read_file_info(Filename), - ok = file:change_mode(Filename, Mode bor 8#00111), - {ok, Config}. - -clean(Config0, AppFile) -> - %% Extract the application name from the archive -- this is the default - %% name of the generated script - {Config, AppName} = rebar_app_utils:app_name(Config0, AppFile), - - %% Get the output filename for the escript -- this may include dirs - Filename = rebar_state:get(Config, escript_name, AppName), - rebar_file_utils:delete_each([Filename]), - {ok, Config}. - -%% =================================================================== -%% Internal functions -%% =================================================================== - -info(help, escriptize) -> - info_help("Generate escript archive"); -info(help, clean) -> - info_help("Delete generated escript archive"). - -info_help(Description) -> - ?CONSOLE( - "~s.~n" - "~n" - "Valid rebar.config options:~n" - " ~p~n" - " ~p~n" - " ~p~n" - " ~p~n" - " ~p~n", - [ - Description, - {escript_name, "application"}, - {escript_incl_apps, []}, - {escript_shebang, "#!/usr/bin/env escript\n"}, - {escript_comment, "%%\n"}, - {escript_emu_args, "%%! -pa application/application/ebin\n"} - ]). - -get_app_beams([], Acc) -> - Acc; -get_app_beams([App | Rest], Acc) -> - case code:lib_dir(App, ebin) of - {error, bad_name} -> - ?ABORT("Failed to get ebin/ directory for " - "~p escript_incl_apps.", [App]); - Path -> - Prefix = filename:join(atom_to_list(App), "ebin"), - Acc2 = load_files(Prefix, "*", Path), - get_app_beams(Rest, Acc2 ++ Acc) - end. - -get_extra(Config) -> - Extra = rebar_state:get(Config, escript_incl_extra, []), - lists:foldl(fun({Wildcard, Dir}, Files) -> - load_files(Wildcard, Dir) ++ Files - end, [], Extra). - -load_files(Wildcard, Dir) -> - load_files("", Wildcard, Dir). - -load_files(Prefix, Wildcard, Dir) -> - [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) -> - {ok, Bin} = file:read_file(Filename), - Bin. - -%% Given a filename, return zip archive dir entries for each sub-dir. -%% Required to work around issues fixed in OTP-10071. -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)). diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 06e02cc..daae204 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -84,7 +84,7 @@ get_deps_dir(State) -> DepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR), get_deps_dir(BaseDir, DepsDir). --spec get_deps_dir(file:filename_all(), rebar_state:t()) -> file:filename_all(). +-spec get_deps_dir(file:filename_all(), file:filename_all()) -> file:filename_all(). get_deps_dir(DepsDir, App) -> filename:join(DepsDir, App). @@ -119,7 +119,7 @@ handle_deps(State, Deps, Update) -> ,Packages ,Name ,Vsn), - ok = maybe_fetch(AppInfo, Update), + maybe_fetch(AppInfo, Update), AppInfo end, S) end, @@ -141,9 +141,14 @@ handle_deps(State, Deps, Update) -> is_valid(App) -> rebar_app_info:valid(App). --spec package_to_app(file:name(), rlx_depsolver:t(), binary(), binary()) -> rebar_app_info:t(). +-spec package_to_app(file:filename_all(), dict:dict(), rlx_depsolver:name(), rlx_depsolver:vsn()) -> rebar_app_info:t(). package_to_app(DepsDir, Packages, Name, Vsn) -> - FmtVsn = ec_cnv:to_binary(rlx_depsolver:format_version(Vsn)), + FmtVsn = case Vsn of + 'NO_VSN' -> + <<"NO_VSN">>; + _ -> + iolist_to_binary(rlx_depsolver:format_version(Vsn)) + end, {ok, P} = dict:find({Name, FmtVsn}, Packages), PkgDeps = proplists:get_value(<<"deps">>, P), @@ -155,7 +160,7 @@ package_to_app(DepsDir, Packages, Name, Vsn) -> rebar_app_info:dir(AppInfo1, get_deps_dir(DepsDir, <<Name/binary, "-", FmtVsn/binary>>)), rebar_app_info:source(AppInfo2, Link). --spec update_src_deps(integer(), rebar_state:t(), boolean()) -> rebat_state:t(). +-spec update_src_deps(integer(), rebar_state:t(), boolean()) -> rebar_state:t(). update_src_deps(Level, State, Update) -> SrcDeps = rebar_state:src_deps(State), DepsDir = get_deps_dir(State), @@ -179,7 +184,8 @@ update_src_deps(Level, State, Update) -> update_src_deps(Level+1, State2, Update) end. --spec handle_dep(binary(), rebar_state:t()) -> {rebar_app_info:t(), [rebar_app_info:t()], [binary_dep()]}. +-spec handle_dep(file:filename_all(), rebar_app_info:t()) -> + {rebar_app_info:t(), [rebar_app_info:t()], [binary_dep()]}. handle_dep(DepsDir, AppInfo) -> C = rebar_config:consult(rebar_app_info:dir(AppInfo)), S = rebar_state:new(rebar_state:new(), C, rebar_app_info:dir(AppInfo)), diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl index 99a67c3..b30c517 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl @@ -80,7 +80,7 @@ create(State) -> resolve_variables([], Dict) -> Dict; resolve_variables([{Key, Value0} | Rest], Dict) when is_list(Value0) -> - Value = render(list_to_binary(Value0), Dict), + Value = render(Value0, Dict), resolve_variables(Rest, dict:store(Key, Value, Dict)); resolve_variables([{Key, {list, Dicts}} | Rest], Dict) when is_list(Dicts) -> %% just un-tag it so erlydtl can use it diff --git a/src/rebar_topo.erl b/src/rebar_topo.erl index 87ee234..5f528af 100644 --- a/src/rebar_topo.erl +++ b/src/rebar_topo.erl @@ -54,20 +54,18 @@ %% applications. This implies that you have already done the %% constraint solve before you pass the list of apps here to be %% sorted. --spec sort_apps([rebar_app_info:t()]) -> - {ok, [rebar_app_info:t()]} | - relx:error(). +-spec sort_apps([rebar_app_info:t()]) -> {ok, [rebar_app_info:t()]} | {error, any()}. sort_apps(Apps) -> Pairs = apps_to_pairs(Apps), case sort(Pairs) of {ok, Names} -> {ok, names_to_apps(Names, Apps)}; E -> - E + {error, E} end. %% @doc Do a topological sort on the list of pairs. --spec sort([pair()]) -> {ok, [atom()]} | relx:error(). +-spec sort([pair()]) -> {ok, [atom()]} | {error, any()}. sort(Pairs) -> iterate(Pairs, [], all(Pairs)). @@ -91,7 +89,7 @@ format_error({cycle, Pairs}) -> %%==================================================================== -spec names_to_apps([atom()], [rebar_app_info:t()]) -> [rebar_app_info:t()]. names_to_apps(Names, Apps) -> - [element(2, App) || App <- [find_app_by_name(Name, Apps) || Name <- Names], App =/= error]. + [element(2, App) || App <- [find_app_by_name(Name, Apps) || Name <- Names], App =/= error]. -spec find_app_by_name(atom(), [rebar_app_info:t()]) -> {ok, rebar_app_info:t()} | error. find_app_by_name(Name, Apps) -> @@ -192,8 +190,8 @@ topo_pairs_cycle_test() -> sort(Pairs)). topo_apps_cycle_test() -> - {ok, App1} = rebar_app_info:new(app1, "0.1", "/no-dir", [app2], [stdlib]), - {ok, App2} = rebar_app_info:new(app2, "0.1", "/no-dir", [app1], []), + {ok, App1} = rebar_app_info:new(app1, "0.1", "/no-dir", [app2]), + {ok, App2} = rebar_app_info:new(app2, "0.1", "/no-dir", [app1]), Apps = [App1, App2], ?assertMatch({error, {_, {cycle, [{app2,app1},{app1,app2}]}}}, sort_apps(Apps)). @@ -201,16 +199,16 @@ topo_apps_cycle_test() -> topo_apps_good_test() -> Apps = [App || {ok, App} <- - [rebar_app_info:new(app1, "0.1", "/no-dir", [app2, zapp1], [stdlib, kernel]), - rebar_app_info:new(app2, "0.1", "/no-dir", [app3], []), - rebar_app_info:new(app3, "0.1", "/no-dir", [kernel], []), - rebar_app_info:new(zapp1, "0.1", "/no-dir", [app2,app3,zapp2], []), - rebar_app_info:new(stdlib, "0.1", "/no-dir", [], []), - rebar_app_info:new(kernel, "0.1", "/no-dir", [], []), - rebar_app_info:new(zapp2, "0.1", "/no-dir", [], [])]], + [rebar_app_info:new(app1, "0.1", "/no-dir", [app2, zapp1]), + rebar_app_info:new(app2, "0.1", "/no-dir", [app3]), + rebar_app_info:new(app3, "0.1", "/no-dir", [kernel]), + rebar_app_info:new(zapp1, "0.1", "/no-dir", [app2,app3,zapp2]), + rebar_app_info:new(stdlib, "0.1", "/no-dir", []), + rebar_app_info:new(kernel, "0.1", "/no-dir", []), + rebar_app_info:new(zapp2, "0.1", "/no-dir", [])]], {ok, Sorted} = sort_apps(Apps), ?assertMatch([stdlib, kernel, zapp2, app3, app2, zapp1, app1], - [rebar_app_info:name(App) || App <- Sorted]). + [ec_cnv:to_atom(rebar_app_info:name(App)) || App <- Sorted]). -endif. diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index b83c03e..742cad2 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -34,6 +34,7 @@ wordsize/0, sh/2, sh_send/3, + escript_foldl/3, find_files/2, find_files/3, now_str/0, @@ -43,7 +44,6 @@ erl_to_mod/1, abort/0, abort/2, - escript_foldl/3, find_executable/1, prop_check/3, expand_code_path/0, @@ -203,18 +203,6 @@ abort(String, Args) -> ?ERROR(String, Args), abort(). -%% TODO: Rename emulate_escript_foldl to escript_foldl and remove -%% this function when the time is right. escript:foldl/3 was an -%% undocumented exported fun and has been removed in R14. -escript_foldl(Fun, Acc, File) -> - {module, zip} = code:ensure_loaded(zip), - case erlang:function_exported(zip, foldl, 3) of - true -> - emulate_escript_foldl(Fun, Acc, File); - false -> - escript:foldl(Fun, Acc, File) - end. - find_executable(Name) -> case os:find_executable(Name) of false -> false; @@ -528,7 +516,7 @@ beams(Dir) -> filelib:fold_files(Dir, ".*\.beam\$", true, fun(F, Acc) -> [F | Acc] end, []). -emulate_escript_foldl(Fun, Acc, File) -> +escript_foldl(Fun, Acc, File) -> case escript:extract(File, [compile_source]) of {ok, [_Shebang, _Comment, _EmuArgs, Body]} -> case Body of |