diff options
-rwxr-xr-x | bootstrap | 102 | ||||
-rw-r--r-- | rebar.lock | 4 | ||||
-rw-r--r-- | src/rebar_app_info.erl | 2 | ||||
-rw-r--r-- | src/rebar_state.erl | 2 | ||||
-rw-r--r-- | src/rebar_templater.erl | 2 |
5 files changed, 102 insertions, 10 deletions
@@ -84,16 +84,32 @@ compile(App, FirstFiles) -> code:add_path(filename:join(Dir, "ebin")), FirstFilesPaths = [filename:join([Dir, "src", Module]) || Module <- FirstFiles], Sources = FirstFilesPaths ++ filelib:wildcard(filename:join([Dir, "src", "*.erl"])), - [compile:file(X, [{i, filename:join(Dir, "include")} + [compile_file(X, [{i, filename:join(Dir, "include")} ,{outdir, filename:join(Dir, "ebin")} - ,return]) || X <- Sources]. + ,return | additional_defines()]) || X <- Sources]. + +compile_file(File, Opts) -> + case compile:file(File, Opts) of + {ok, _Mod} -> + ok; + {ok, _Mod, []} -> + ok; + {ok, _Mod, Ws} -> + io:format("~s~n", [format_warnings(File, Ws)]), + halt(1); + {error, Es, Ws} -> + io:format("~s ~s~n", [format_errors(File, Es), format_warnings(File, Ws)]), + halt(1) + end. bootstrap_rebar3() -> filelib:ensure_dir("_build/default/lib/rebar/ebin/dummy.beam"), + code:add_path("_build/default/lib/rebar/ebin/"), file:make_symlink(filename:absname("src"), filename:absname("_build/default/lib/rebar/src")), - Sources = filelib:wildcard("src/*.erl"), - [compile:file(X, [{outdir, "_build/default/lib/rebar/ebin/"}]) || X <- Sources], - code:add_path(filename:absname("_build/default/lib/rebar/ebin")). + Sources = ["src/rebar_resource.erl" | filelib:wildcard("src/*.erl")], + [compile_file(X, [{outdir, "_build/default/lib/rebar/ebin/"} + ,return | additional_defines()]) || X <- Sources], + code:add_patha(filename:absname("_build/default/lib/rebar/ebin")). setup_env() -> %% We don't need or want erlydtl or relx providers loaded yet @@ -126,3 +142,79 @@ get_deps() -> {ok, Config} = file:consult("rebar.config"), proplists:get_value(deps, Config) end. + +format_errors(Source, Errors) -> + format_errors(Source, "", Errors). + +format_warnings(Source, Warnings) -> + format_warnings(Source, Warnings, []). + +format_warnings(Source, Warnings, Opts) -> + Prefix = case lists:member(warnings_as_errors, Opts) of + true -> ""; + false -> "Warning: " + end, + format_errors(Source, Prefix, Warnings). + +format_errors(_MainSource, Extra, Errors) -> + [begin + [format_error(Source, Extra, Desc) || Desc <- Descs] + end + || {Source, Descs} <- Errors]. + +format_error(AbsSource, Extra, {{Line, Column}, Mod, Desc}) -> + ErrorDesc = Mod:format_error(Desc), + io_lib:format("~s:~w:~w: ~s~s~n", [AbsSource, Line, Column, Extra, ErrorDesc]); +format_error(AbsSource, Extra, {Line, Mod, Desc}) -> + ErrorDesc = Mod:format_error(Desc), + io_lib:format("~s:~w: ~s~s~n", [AbsSource, Line, Extra, ErrorDesc]); +format_error(AbsSource, Extra, {Mod, Desc}) -> + ErrorDesc = Mod:format_error(Desc), + io_lib:format("~s: ~s~s~n", [AbsSource, Extra, ErrorDesc]). + +additional_defines() -> + [{d, D} || {Re, D} <- [{"^[0-9]+", namespaced_types}, {"^R1[4|5]", deprecated_crypto}], is_otp_release(Re)]. + +is_otp_release(ArchRegex) -> + case re:run(otp_release(), ArchRegex, [{capture, none}]) of + match -> + true; + nomatch -> + false + end. + +otp_release() -> + otp_release1(erlang:system_info(otp_release)). + +%% If OTP <= R16, otp_release is already what we want. +otp_release1([$R,N|_]=Rel) when is_integer(N) -> + Rel; +%% If OTP >= 17.x, erlang:system_info(otp_release) returns just the +%% major version number, we have to read the full version from +%% a file. See http://www.erlang.org/doc/system_principles/versions.html +%% Read vsn string from the 'OTP_VERSION' file and return as list without +%% the "\n". +otp_release1(Rel) -> + File = filename:join([code:root_dir(), "releases", Rel, "OTP_VERSION"]), + {ok, Vsn} = file:read_file(File), + + %% It's fine to rely on the binary module here because we can + %% be sure that it's available when the otp_release string does + %% not begin with $R. + Size = byte_size(Vsn), + %% The shortest vsn string consists of at least two digits + %% followed by "\n". Therefore, it's safe to assume Size >= 3. + case binary:part(Vsn, {Size, -3}) of + <<"**\n">> -> + %% The OTP documentation mentions that a system patched + %% using the otp_patch_apply tool available to licensed + %% customers will leave a '**' suffix in the version as a + %% flag saying the system consists of application versions + %% from multiple OTP versions. We ignore this flag and + %% drop the suffix, given for all intents and purposes, we + %% cannot obtain relevant information from it as far as + %% tooling is concerned. + binary:bin_to_list(Vsn, {0, Size - 3}); + _ -> + binary:bin_to_list(Vsn, {0, Size - 1}) + end. @@ -12,7 +12,7 @@ 1}, {<<"relx">>, {git,"https://github.com/erlware/relx.git", - {ref,"3f2462807fe4afb82bc52dd3ff8ff9244aad3bd3"}}, + {ref,"f8af9f5cd9f70ff43a043fe274dda4e56be82a2d"}}, 0}, {<<"providers">>, {git,"https://github.com/tsloughter/providers.git", @@ -28,5 +28,5 @@ 0}, {<<"erlware_commons">>, {git,"https://github.com/erlware/erlware_commons.git", - {ref,"05b956da26788f30b3cb793fa6ace02b75f481d0"}}, + {ref,"ef0d252b11c863f9c228af2fe93a4e42fba2f7f3"}}, 0}]. diff --git a/src/rebar_app_info.erl b/src/rebar_app_info.erl index 9659c0b..7894e75 100644 --- a/src/rebar_app_info.erl +++ b/src/rebar_app_info.erl @@ -61,7 +61,7 @@ %%============================================================================ %% types %%============================================================================ --type t() :: record(app_info_t). +-type t() :: #app_info_t{}. %%============================================================================ %% API diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 3909a39..ddac9d2 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -65,7 +65,7 @@ -export_type([t/0]). --type t() :: record(state_t). +-type t() :: #state_t{}. -spec new() -> t(). new() -> diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl index 75cbb87..78d1e83 100644 --- a/src/rebar_templater.erl +++ b/src/rebar_templater.erl @@ -394,7 +394,7 @@ write_file(Output, Data, Force) -> -spec make_template_name(string(), term()) -> module(). make_template_name(Base, Value) -> %% Seed so we get different values each time - random:seed(erlang:now()), + random:seed(os:timestamp()), Hash = erlang:phash2(Value), Ran = random:uniform(10000000), erlang:list_to_atom(Base ++ "_" ++ |