From 4374999d9567acf93fbd3515aa19319c4e502390 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 18 Apr 2015 11:56:51 -0500 Subject: real bootstrapping --- .gitignore | 4 +- .travis.yml | 3 +- bootstrap | 129 ++++++++++++++++++++++++++++++++++++++++++ bootstrap.bat | 2 + bootstrap/bootstrap | 66 --------------------- bootstrap/bootstrap.bat | 2 - bootstrap/rebar | Bin 160323 -> 0 bytes rebar.config | 65 ++++++++++++++------- rebar.lock | 32 +++++++++++ src/rebar3.erl | 1 + src/rebar_api.erl | 2 +- src/rebar_config.erl | 1 - src/rebar_erlc_compiler.erl | 3 +- src/rebar_otp_app.erl | 1 - src/rebar_prv_common_test.erl | 2 +- src/rebar_prv_compile.erl | 3 +- src/rebar_prv_dialyzer.erl | 2 +- src/rebar_prv_eunit.erl | 2 +- src/rebar_prv_shell.erl | 2 +- src/rebar_prv_xref.erl | 2 +- test/rebar_eunit_SUITE.erl | 12 ++-- test/rebar_profiles_SUITE.erl | 2 +- 22 files changed, 230 insertions(+), 108 deletions(-) create mode 100755 bootstrap create mode 100644 bootstrap.bat delete mode 100755 bootstrap/bootstrap delete mode 100644 bootstrap/bootstrap.bat delete mode 100755 bootstrap/rebar create mode 100644 rebar.lock diff --git a/.gitignore b/.gitignore index 4bfc3fe..c84f451 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,9 @@ +rebar3 +_build .depsolver_plt *.beam test/*_data logs -rebar3 /rebar *~ *.orig @@ -13,6 +14,5 @@ rebar3 /.eunit /deps /.rebar -rebar.lock priv/templates/*.dtl.erl ebin diff --git a/.travis.yml b/.travis.yml index df04fd2..b0729f8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,8 @@ otp_release: - 17.0 - R16B03-1 - R15B03 -script: make travis +before_script: "./bootstrap" +script: "./rebar3 ct" branches: only: - master diff --git a/bootstrap b/bootstrap new file mode 100755 index 0000000..7409cbe --- /dev/null +++ b/bootstrap @@ -0,0 +1,129 @@ +#!/usr/bin/env escript +%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- +%% ex: ft=erlang ts=4 sw=4 et + +main(_Args) -> + %% Fetch and build deps required to build rebar3 + BaseDeps = [{providers, []} + ,{getopt, []} + ,{erlware_commons, ["ec_dictionary.erl", "ec_vsn.erl"]}], + Deps = get_deps(), + [fetch_and_compile(Dep, Deps) || Dep <- BaseDeps], + + %% Build rebar3 modules with compile:file + bootstrap_rebar3(), + + %% Build rebar.app from rebar.app.src + {ok, App} = rebar_app_info:new(rebar, "3.0.0", filename:absname("_build/default/lib/rebar/")), + rebar_otp_app:compile(rebar_state:new(), App), + + %% Because we are compiling files that are loaded already we want to silence + %% not_purged errors in rebar_erlc_compiler:opts_changed/1 + error_logger:tty(false), + + setup_env(), + os:putenv("REBAR_PROFILE", "bootstrap"), + {ok, State} = rebar3:run(["compile"]), + reset_env(), + os:unsetenv("REBAR_PROFILE"), + %% Build erlydtl files (a hook on compile in the default profile) and escript file + DepsPaths = rebar_state:code_paths(State, all_deps), + code:add_pathsa(DepsPaths), + + rebar3:run(["clean", "-a"]), + rebar3:run(["escriptize"]), + + %% Done with compile, can turn back on error logger + error_logger:tty(true), + + %% Finally, update executable perms for our script on *nix, + %% or write out script files on win32. + ec_file:copy("_build/default/bin/rebar3", "./rebar3"), + case os:type() of + {unix,_} -> + [] = os:cmd("chmod u+x rebar3"), + ok; + {win32,_} -> + write_windows_scripts(), + ok; + _ -> + ok + end. + +fetch_and_compile({Name, ErlFirstFiles}, Deps) -> + {Name, _, Repo} = lists:keyfind(Name, 1, Deps), + ok = fetch(Repo, Name), + compile(Name, ErlFirstFiles). + +fetch({git, Url, Source}, App) -> + Dir = filename:join([filename:absname("_build/default/lib/"), App]), + case filelib:is_dir(Dir) of + true -> + true = code:add_path(filename:join(Dir, "ebin")), + ok; + false -> + fetch_source(Dir, Url, Source), + ok + end. + +fetch_source(Dir, Url, {ref, Ref}) -> + ok = filelib:ensure_dir(Dir), + os:cmd(io_lib:format("git clone ~s ~s", [Url, Dir])), + {ok, Cwd} = file:get_cwd(), + file:set_cwd(Dir), + os:cmd(io_lib:format("git checkout -q ~s", [Ref])), + file:set_cwd(Cwd); +fetch_source(Dir, Url, {_, Branch}) -> + ok = filelib:ensure_dir(Dir), + os:cmd(io_lib:format("git clone ~s ~s -b ~s --single-branch", + [Url, Dir, Branch])). + +compile(App, FirstFiles) -> + Dir = filename:join(filename:absname("_build/default/lib/"), App), + filelib:ensure_dir(filename:join([Dir, "ebin", "dummy.beam"])), + 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")} + ,{outdir, filename:join(Dir, "ebin")} + ,return]) || X <- Sources]. + +bootstrap_rebar3() -> + filelib:ensure_dir("_build/default/lib/rebar/ebin/dummy.beam"), + filelib:ensure_dir("_build/default/lib/rebar/src/dummy.erl"), + ec_file:copy("src", "_build/default/lib/rebar/src", [recursive]), + 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")). + +setup_env() -> + %% We don't need or want erlydtl or relx providers loaded yet + application:load(rebar), + {ok, Providers} = application:get_env(rebar, providers), + Providers1 = Providers -- [rebar_prv_erlydtl_compiler, + rebar_prv_release, + rebar_prv_tar], + application:set_env(rebar, providers, Providers1). + +reset_env() -> + %% Reset the env so we get all providers and can build erlydtl files + application:unset_env(rebar, providers), + application:unload(rebar), + application:load(rebar). + +write_windows_scripts() -> + CmdScript= + "@echo off\r\n" + "setlocal\r\n" + "set rebarscript=%~f0\r\n" + "escript.exe \"%rebarscript:.cmd=%\" %*\r\n", + ok = file:write_file("rebar3.cmd", CmdScript). + +get_deps() -> + case file:consult("rebar.lock") of + {ok, [Deps]} -> + [{binary_to_atom(Name, utf8), "", Source} || {Name, Source, _Level} <- Deps]; + _ -> + {ok, Config} = file:consult("rebar.config"), + proplists:get_value(deps, Config) + end. diff --git a/bootstrap.bat b/bootstrap.bat new file mode 100644 index 0000000..b646a7d --- /dev/null +++ b/bootstrap.bat @@ -0,0 +1,2 @@ +@echo off +escript.exe bootstrap %* diff --git a/bootstrap/bootstrap b/bootstrap/bootstrap deleted file mode 100755 index 4e3d304..0000000 --- a/bootstrap/bootstrap +++ /dev/null @@ -1,66 +0,0 @@ -#!/usr/bin/env escript -%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- -%% ex: ft=erlang ts=4 sw=4 et - -main(Args) -> - case lists:member("--help", Args) of - true -> - usage(), - halt(0); - false -> - ok - end, - - %% Check for force=1 flag to force a rebuild - case lists:member("force=1", Args) of - true -> - rm("ebin/*.beam"); - false -> - rm("ebin/rebar.beam") - end, - - %% Extract the system info of the version of OTP we use to compile rebar - - os:cmd("./bootstrap/rebar get-deps compile escriptize"), - - %% 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 rebar3"), - ok; - {win32,_} -> - write_windows_scripts(), - ok; - _ -> - ok - end, - - %% Add a helpful message - io:format("Congratulations! You now have a self-contained script called" - " \"rebar3\" in\n" - "your current working directory. " - "Place this script anywhere in your path\n" - "and you can use rebar to build OTP-compliant apps.\n"). - -usage() -> - io:format("Usage: bootstrap [OPTION]...~n"), - io:format(" force=1 unconditional build~n"), - io:format(" debug add debug information~n"). - -rm(Path) -> - NativePath = filename:nativename(Path), - Cmd = case os:type() of - {unix,_} -> "rm -f "; - {win32,_} -> "del /q " - end, - [] = os:cmd(Cmd ++ NativePath), - ok. - -write_windows_scripts() -> - CmdScript= - "@echo off\r\n" - "setlocal\r\n" - "set rebarscript=%~f0\r\n" - "escript.exe \"%rebarscript:.cmd=%\" %*\r\n", - ok = file:write_file("rebar.cmd", CmdScript). diff --git a/bootstrap/bootstrap.bat b/bootstrap/bootstrap.bat deleted file mode 100644 index b646a7d..0000000 --- a/bootstrap/bootstrap.bat +++ /dev/null @@ -1,2 +0,0 @@ -@echo off -escript.exe bootstrap %* diff --git a/bootstrap/rebar b/bootstrap/rebar deleted file mode 100755 index 14e5c22..0000000 Binary files a/bootstrap/rebar and /dev/null differ diff --git a/rebar.config b/rebar.config index 36ce9a4..62c7085 100644 --- a/rebar.config +++ b/rebar.config @@ -1,9 +1,22 @@ %% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*- %% ex: ts=4 sw=4 ft=erlang et -%% escript_incl_extra is for internal rebar-private use only. -%% Do not use outside rebar. Config interface is not stable. -{escript_incl_extra, [{"priv/templates/*", "."}, {"rebar/include/*", "."}]}. +{deps, [ + {erlware_commons, "", + {git, "https://github.com/erlware/erlware_commons.git", + {branch, "master"}}}, + {providers, "", + {git, "https://github.com/tsloughter/providers.git", + {tag, "v1.3.1"}}}, + {erlydtl, "", + {git, "https://github.com/erlydtl/erlydtl.git", + {branch, "master"}}}, + {relx, "", + {git, "https://github.com/erlware/relx.git", + {branch, "master"}}}, + {getopt, "", + {git, "https://github.com/jcomellas/getopt.git", + {branch, "master"}}}]}. {escript_incl_apps, [getopt, merl, erlydtl, erlware_commons, relx, providers, rebar]}. @@ -18,23 +31,37 @@ debug_info, warnings_as_errors]}. -{deps, [ - {erlware_commons, ".*", - {git, "https://github.com/erlware/erlware_commons.git", - {branch, "master"}}}, - {providers, "", - {git, "https://github.com/tsloughter/providers.git", - {tag, "v1.3.1"}}}, - {erlydtl, ".*", - {git, "https://github.com/erlydtl/erlydtl.git", - {tag, "0.10.0"}}}, - {relx, "", - {git, "https://github.com/erlware/relx.git", - {branch, "master"}}}, - {getopt, "", {git, "https://github.com/jcomellas/getopt.git", {branch, "master"}}}, - {meck, "", {git, "https://github.com/eproxus/meck.git", {tag, "0.8.2"}}}]}. - {erlydtl_opts, [{doc_root, "priv/templates"}, {compiler_options, [report, return, debug_info]}]}. {dialyzer_plt_apps, [common_test, dialyzer, erlydtl, eunit, snmp]}. + +{provider_hooks, [{post, [{compile, {erlydtl, compile}}]}]}. + +%% Profiles +{profiles, [{test, + [{deps, [ + {meck, "", {git, "https://github.com/eproxus/meck.git", {tag, "0.8.2"}}} + ]} + ] + }, + + %% We don't want erlydtl to attempt to run on the first compile pass to bootstrap + {bootstrap, [{overrides, [{override, relx, [{provider_hooks, [{post, []}]}]}]}, + {provider_hooks, [{post, []}]}]} + ]}. + +%% Overrides +{overrides, [{override, erlware_commons, [{plugins, []}]}, + {override, merl, [{pre_hooks, [{"(linux|darwin|solaris)", compile, "make -C \"$REBAR_DEPS_DIR/merl\" all -W test"}, + {"(freebsd|netbsd|openbsd)", compile, "gmake -C \"$REBAR_DEPS_DIR/merl\" all"}, + {"win32", compile, "make -C \"%REBAR_DEPS_DIR%/merl\" all -W test"}, + {eunit, + "erlc -I include/erlydtl_preparser.hrl -o test" + " test/erlydtl_extension_testparser.yrl"}, + {"(linux|darwin|solaris)", eunit, "make -C \"$REBAR_DEPS_DIR/merl\" test"}, + {"(freebsd|netbsd|openbsd)", eunit, "gmake -C \"$REBAR_DEPS_DIR/merl\" test"}, + {"win32", eunit, "make -C \"%REBAR_DEPS_DIR%/merl\" test"} + ]}]}, + {override, erlydtl, [{pre_hooks, []}]} + ]}. diff --git a/rebar.lock b/rebar.lock new file mode 100644 index 0000000..cc619ef --- /dev/null +++ b/rebar.lock @@ -0,0 +1,32 @@ +[{<<"rebar_vsn_plugin">>, + {git,"https://github.com/erlware/rebar_vsn_plugin.git", + {ref,"fd40c960c7912193631d948fe962e1162a8d1334"}}, + 1}, + {<<"merl">>, + {git,"git://github.com/erlydtl/merl.git", + {ref,"750b09d44425f435ff579a4d28bf5844bb5b4ef1"}}, + 1}, + {<<"eunit_formatters">>, + {git,"git://github.com/seancribbs/eunit_formatters", + {ref,"2c73eb6e46b0863f19507857b386a48a53aaf141"}}, + 1}, + {<<"relx">>, + {git,"https://github.com/erlware/relx.git", + {ref,"3f2462807fe4afb82bc52dd3ff8ff9244aad3bd3"}}, + 0}, + {<<"providers">>, + {git,"https://github.com/tsloughter/providers.git", + {ref,"7563ba7e916d5a35972b25b3aa1945ffe0a8e7a5"}}, + 0}, + {<<"getopt">>, + {git,"https://github.com/jcomellas/getopt.git", + {ref,"626698975e63866156159661d100785d65eab6f9"}}, + 0}, + {<<"erlydtl">>, + {git,"https://github.com/erlydtl/erlydtl.git", + {ref,"a4ac28680d6e066aabf86b3be9f073352a1a4d40"}}, + 0}, + {<<"erlware_commons">>, + {git,"https://github.com/erlware/erlware_commons.git", + {ref,"05b956da26788f30b3cb793fa6ace02b75f481d0"}}, + 0}]. diff --git a/src/rebar3.erl b/src/rebar3.erl index e5e3173..fbbda51 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -27,6 +27,7 @@ -module(rebar3). -export([main/1, + run/1, run/2, global_option_spec_list/0, init_config/0, diff --git a/src/rebar_api.erl b/src/rebar_api.erl index a398b53..88c7538 100644 --- a/src/rebar_api.erl +++ b/src/rebar_api.erl @@ -54,7 +54,7 @@ wordsize() -> %% Add deps to the code path add_deps_to_path(State) -> - code:add_paths(rebar_state:code_paths(State, all_deps)). + code:add_pathsa(rebar_state:code_paths(State, all_deps)). %% Revert to only having the beams necessary for running rebar3 and plugins in the path restore_code_path(State) -> diff --git a/src/rebar_config.erl b/src/rebar_config.erl index 76e03ea..58b2c4d 100644 --- a/src/rebar_config.erl +++ b/src/rebar_config.erl @@ -57,7 +57,6 @@ consult_file(File) -> {ok, Terms} = consult_and_eval(File, Script), Terms; false -> - ?DEBUG("Consult config file ~p", [File]), try_consult(File) end end. diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index ced8ca8..f906463 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -148,7 +148,8 @@ doterl_compile(Config, Dir, OutDir, MoreSources, ErlOpts) -> %% Make sure that ebin/ exists and is on the path ok = filelib:ensure_dir(filename:join(OutDir, "dummy.beam")), - true = code:add_path(filename:absname(OutDir)), + true = code:add_patha(filename:absname(OutDir)), + OutDir1 = proplists:get_value(outdir, ErlOpts, OutDir), G = init_erlcinfo(proplists:get_all_values(i, ErlOpts), AllErlFiles, Dir), diff --git a/src/rebar_otp_app.erl b/src/rebar_otp_app.erl index 41cd5f3..260343d 100644 --- a/src/rebar_otp_app.erl +++ b/src/rebar_otp_app.erl @@ -128,7 +128,6 @@ preprocess(State, AppInfo, AppSrcFile) -> load_app_vars(State) -> case rebar_state:get(State, app_vars_file, undefined) of undefined -> - ?DEBUG("No app_vars_file defined.", []), []; Filename -> ?INFO("Loading app vars from ~p", [Filename]), diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index a398144..a848401 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -39,7 +39,7 @@ init(State) -> do(State) -> ?INFO("Running Common Test suites...", []), - code:add_paths(rebar_state:code_paths(State, all_deps)), + code:add_pathsa(rebar_state:code_paths(State, all_deps)), %% Run ct provider prehooks Providers = rebar_state:providers(State), diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index 25bda8c..1fb29bd 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -32,7 +32,7 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> DepsPaths = rebar_state:code_paths(State, all_deps), - code:add_paths(DepsPaths), + code:add_pathsa(DepsPaths), ProjectApps = rebar_state:project_apps(State), Providers = rebar_state:providers(State), @@ -83,7 +83,6 @@ build_app(State, Providers, AppInfo) -> end, %% Legacy hook support - rebar_hooks:run_all_hooks(AppDir, pre, ?PROVIDER, Providers, S), AppInfo1 = compile(S, AppInfo), rebar_hooks:run_all_hooks(AppDir, post, ?PROVIDER, Providers, S), diff --git a/src/rebar_prv_dialyzer.erl b/src/rebar_prv_dialyzer.erl index f7cdf3b..67cf4b9 100644 --- a/src/rebar_prv_dialyzer.erl +++ b/src/rebar_prv_dialyzer.erl @@ -64,7 +64,7 @@ short_desc() -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> ?INFO("Dialyzer starting, this may take a while...", []), - code:add_paths(rebar_state:code_paths(State, all_deps)), + code:add_pathsa(rebar_state:code_paths(State, all_deps)), Plt = get_plt_location(State), Apps = rebar_state:project_apps(State), diff --git a/src/rebar_prv_eunit.erl b/src/rebar_prv_eunit.erl index 3ee912d..12dd5f9 100644 --- a/src/rebar_prv_eunit.erl +++ b/src/rebar_prv_eunit.erl @@ -37,7 +37,7 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> ?INFO("Performing EUnit tests...", []), - code:add_paths(rebar_state:code_paths(State, all_deps)), + code:add_pathsa(rebar_state:code_paths(State, all_deps)), %% Run eunit provider prehooks Providers = rebar_state:providers(State), Cwd = rebar_dir:get_cwd(), diff --git a/src/rebar_prv_shell.erl b/src/rebar_prv_shell.erl index b6a85ab..6153952 100644 --- a/src/rebar_prv_shell.erl +++ b/src/rebar_prv_shell.erl @@ -93,7 +93,7 @@ shell(State) -> %% error_logger added by the tty handler ok = remove_error_handler(3), %% Add deps to path - code:add_paths(rebar_state:code_paths(State, all_deps)), + code:add_pathsa(rebar_state:code_paths(State, all_deps)), %% add project app test paths ok = add_test_paths(State), %% this call never returns (until user quits shell) diff --git a/src/rebar_prv_xref.erl b/src/rebar_prv_xref.erl index baec57f..1d1afa0 100644 --- a/src/rebar_prv_xref.erl +++ b/src/rebar_prv_xref.erl @@ -36,7 +36,7 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> - code:add_paths(rebar_state:code_paths(State, all_deps)), + code:add_pathsa(rebar_state:code_paths(State, all_deps)), XrefChecks = prepare(State), %% Run xref checks diff --git a/test/rebar_eunit_SUITE.erl b/test/rebar_eunit_SUITE.erl index 4ec92f2..ac74146 100644 --- a/test/rebar_eunit_SUITE.erl +++ b/test/rebar_eunit_SUITE.erl @@ -164,8 +164,8 @@ test_basic_defines(Config) -> AppOpts = proplists:get_value(options, App:module_info(compile), []), SuiteOpts = proplists:get_value(options, Suite:module_info(compile), []), Expect = [{d, some_define}], - lists:foreach(fun(Expect) -> true = lists:member(Expect, AppOpts) end, Expect), - lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts) end, Expect). + lists:foreach(fun(E) -> true = lists:member(E, AppOpts) end, Expect), + lists:foreach(fun(E) -> true = lists:member(E, SuiteOpts) end, Expect). test_multi_defines(Config) -> AppDir = ?config(apps, Config), @@ -198,10 +198,10 @@ test_multi_defines(Config) -> AppOpts2 = proplists:get_value(options, App2:module_info(compile), []), SuiteOpts2 = proplists:get_value(options, Suite2:module_info(compile), []), Expect = [{d, some_define}], - lists:foreach(fun(Expect) -> true = lists:member(Expect, AppOpts1) end, Expect), - lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts1) end, Expect), - lists:foreach(fun(Expect) -> true = lists:member(Expect, AppOpts2) end, Expect), - lists:foreach(fun(Expect) -> true = lists:member(Expect, SuiteOpts2) end, Expect). + lists:foreach(fun(E) -> true = lists:member(E, AppOpts1) end, Expect), + lists:foreach(fun(E) -> true = lists:member(E, SuiteOpts1) end, Expect), + lists:foreach(fun(E) -> true = lists:member(E, AppOpts2) end, Expect), + lists:foreach(fun(E) -> true = lists:member(E, SuiteOpts2) end, Expect). test_single_app_flag(Config) -> AppDir = ?config(apps, Config), diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl index 72969d3..f0d1c48 100644 --- a/test/rebar_profiles_SUITE.erl +++ b/test/rebar_profiles_SUITE.erl @@ -160,7 +160,7 @@ profiles_remain_applied_with_config_present(Config) -> rebar_test_utils:create_config(AppDir, RebarConfig), - {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, + rebar_test_utils:run_and_check(Config, RebarConfig, ["as", "not_ok", "compile"], {ok, [{app, Name}]}), Path = filename:join([AppDir, "_build", "not_ok", "lib", Name, "ebin"]), -- cgit v1.1 From 16e9b3ffa2ddd81e26238530fd1e25a54a42b7dc Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Wed, 22 Apr 2015 21:43:59 -0500 Subject: fix tracking of all profiles dep paths --- bootstrap | 3 +-- src/rebar_prv_common_test.erl | 1 - src/rebar_prv_install_deps.erl | 4 ++-- src/rebar_state.erl | 15 +++++++++++++-- test/rebar_profiles_SUITE.erl | 39 +++++++++++++++++++++++++++++++++++++-- 5 files changed, 53 insertions(+), 9 deletions(-) diff --git a/bootstrap b/bootstrap index 7409cbe..8f7af30 100755 --- a/bootstrap +++ b/bootstrap @@ -90,8 +90,7 @@ compile(App, FirstFiles) -> bootstrap_rebar3() -> filelib:ensure_dir("_build/default/lib/rebar/ebin/dummy.beam"), - filelib:ensure_dir("_build/default/lib/rebar/src/dummy.erl"), - ec_file:copy("src", "_build/default/lib/rebar/src", [recursive]), + 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")). diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index a848401..9038759 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -38,7 +38,6 @@ init(State) -> -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> ?INFO("Running Common Test suites...", []), - code:add_pathsa(rebar_state:code_paths(State, all_deps)), %% Run ct provider prehooks diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 3b2c9ab..0fa843f 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -151,9 +151,9 @@ handle_deps(Profile, State0, Deps, Upgrade, Locks) -> ,lists:ukeysort(2, SrcApps) ,lists:ukeysort(2, Solved)), - State3 = rebar_state:all_deps(State2, AllDeps), + State3 = rebar_state:update_all_deps(State2, AllDeps), CodePaths = [rebar_app_info:ebin_dir(A) || A <- AllDeps], - State4 = rebar_state:code_paths(State3, all_deps, CodePaths), + State4 = rebar_state:update_code_paths(State3, all_deps, CodePaths), {ok, AllDeps, State4}. diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 705f723..3909a39 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -3,7 +3,7 @@ -export([new/0, new/1, new/2, new/3, get/2, get/3, set/3, - code_paths/2, code_paths/3, + code_paths/2, code_paths/3, update_code_paths/3, opts/1, opts/2, default/1, default/2, @@ -24,7 +24,7 @@ project_apps/1, project_apps/2, deps_to_build/1, deps_to_build/2, - all_deps/1, all_deps/2, + all_deps/1, all_deps/2, update_all_deps/2, namespace/1, namespace/2, deps_names/1, @@ -146,6 +146,14 @@ code_paths(#state_t{code_paths=CodePaths}, Key) -> code_paths(State=#state_t{code_paths=CodePaths}, Key, CodePath) -> State#state_t{code_paths=dict:store(Key, CodePath, CodePaths)}. +update_code_paths(State=#state_t{code_paths=CodePaths}, Key, CodePath) -> + case dict:is_key(Key, CodePaths) of + true -> + State#state_t{code_paths=dict:append_list(Key, CodePath, CodePaths)}; + false -> + State#state_t{code_paths=dict:store(Key, CodePath, CodePaths)} + end. + opts(#state_t{opts=Opts}) -> Opts. @@ -312,6 +320,9 @@ all_deps(#state_t{all_deps=Apps}) -> all_deps(State=#state_t{}, NewApps) -> State#state_t{all_deps=NewApps}. +update_all_deps(State=#state_t{all_deps=Apps}, NewApps) -> + State#state_t{all_deps=Apps++NewApps}. + namespace(#state_t{namespace=Namespace}) -> Namespace. diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl index f0d1c48..59c65e9 100644 --- a/test/rebar_profiles_SUITE.erl +++ b/test/rebar_profiles_SUITE.erl @@ -7,6 +7,7 @@ all/0, profile_new_key/1, profile_merge_keys/1, + all_deps_code_paths/1, profile_merges/1, add_to_profile/1, add_to_existing_profile/1, @@ -21,7 +22,7 @@ -include_lib("kernel/include/file.hrl"). all() -> - [profile_new_key, profile_merge_keys, profile_merges, + [profile_new_key, profile_merge_keys, all_deps_code_paths, profile_merges, add_to_profile, add_to_existing_profile, profiles_remain_applied_with_config_present, test_profile_applied_at_completion, @@ -95,6 +96,40 @@ profile_merge_keys(Config) -> ,{dep, "a", "1.0.0"} ,{dep, "b", "2.0.0"}]}). +all_deps_code_paths(Config) -> + AppDir = ?config(apps, Config), + + AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []} + ,{"b", "2.0.0", []}]), + mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]), + + Name = rebar_test_utils:create_random_name("all_deps_code_paths"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + Deps = rebar_test_utils:top_level_deps( + rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}])), + ProfileDeps = rebar_test_utils:top_level_deps( + rebar_test_utils:expand_deps(git, [{"b", "2.0.0", []}])), + + RebarConfig = [{deps, Deps}, + {profiles, + [{all_deps_test, + [{deps, ProfileDeps}]}]}], + os:putenv("REBAR_PROFILE", "all_deps_test"), + {ok, State} = rebar_test_utils:run_and_check(Config, RebarConfig, + ["compile"], {ok, [{app, Name} + ,{dep, "a", "1.0.0"} + ,{dep, "b", "2.0.0"}]}), + os:unsetenv("REBAR_PROFILE"), + + Paths = rebar_state:code_paths(State, all_deps), + Path = lists:reverse(["_build", "all_deps_test", "lib", "b", "ebin"]), + ?assert(lists:any(fun(X) -> + Path =:= lists:sublist(lists:reverse(filename:split(X)), 5) + end, Paths)). + + profile_merges(_Config) -> RebarConfig = [{test1, [{key1, 1, 2}, key2]}, {test2, "hello"}, @@ -164,7 +199,7 @@ profiles_remain_applied_with_config_present(Config) -> ["as", "not_ok", "compile"], {ok, [{app, Name}]}), Path = filename:join([AppDir, "_build", "not_ok", "lib", Name, "ebin"]), - code:add_path(Path), + code:add_patha(Path), Mod = list_to_atom("not_a_real_src_" ++ Name), -- cgit v1.1 From e5988f69e0fc577f9c759f0907bd8b6840851035 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Wed, 22 Apr 2015 21:51:11 -0500 Subject: R15 support, replace unsetenv with putenv empty string --- bootstrap | 2 +- src/rebar3.erl | 2 ++ test/rebar_profiles_SUITE.erl | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bootstrap b/bootstrap index 8f7af30..3ed7b2b 100755 --- a/bootstrap +++ b/bootstrap @@ -25,7 +25,7 @@ main(_Args) -> os:putenv("REBAR_PROFILE", "bootstrap"), {ok, State} = rebar3:run(["compile"]), reset_env(), - os:unsetenv("REBAR_PROFILE"), + os:putenv("REBAR_PROFILE", ""), %% Build erlydtl files (a hook on compile in the default profile) and escript file DepsPaths = rebar_state:code_paths(State, all_deps), code:add_pathsa(DepsPaths), diff --git a/src/rebar3.erl b/src/rebar3.erl index fbbda51..b0cc949 100644 --- a/src/rebar3.erl +++ b/src/rebar3.erl @@ -115,6 +115,8 @@ run_aux(State, RawArgs) -> State2 = case os:getenv("REBAR_PROFILE") of false -> State; + "" -> + State; Profile -> rebar_state:apply_profiles(State, [list_to_atom(Profile)]) end, diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl index 59c65e9..2d03432 100644 --- a/test/rebar_profiles_SUITE.erl +++ b/test/rebar_profiles_SUITE.erl @@ -121,7 +121,7 @@ all_deps_code_paths(Config) -> ["compile"], {ok, [{app, Name} ,{dep, "a", "1.0.0"} ,{dep, "b", "2.0.0"}]}), - os:unsetenv("REBAR_PROFILE"), + os:putenv("REBAR_PROFILE", ""), Paths = rebar_state:code_paths(State, all_deps), Path = lists:reverse(["_build", "all_deps_test", "lib", "b", "ebin"]), -- cgit v1.1 From acf8c5ce65718fbaaae666baf312890f3e8857af Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Wed, 22 Apr 2015 22:00:40 -0500 Subject: update readme bootstrap instructions --- README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 320b3cf..555cddf 100644 --- a/README.md +++ b/README.md @@ -123,11 +123,7 @@ https://s3.amazonaws.com/rebar3/rebar3 ```sh $ git clone https://github.com/rebar/rebar3 $ cd rebar3 -$ ./bootstrap/bootstrap -==> rebar (compile) -Congratulations! You now have a self-contained script called "rebar3" in -your current working directory. Place this script anywhere in your path -and you can use rebar to build OTP-compliant apps. +$ ./bootstrap ``` -- cgit v1.1 From 390d1afb77fe58c0f083b46ad114a37d1ad1d91d Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Wed, 22 Apr 2015 22:01:13 -0500 Subject: update readme provider --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 555cddf..bc2accd 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,8 @@ Example: -behaviour(rebar_provider). -export([init/1, - do/1]). + do/1, + format_error/1]). -define(PROVIDER, something). -define(DEPS, []). @@ -98,6 +99,10 @@ init(State) -> do(State) -> %% Do something {ok, State}. + +-spec format_error(any()) -> iolist(). +format_error(Reason) -> + io_lib:format("~p", [Reason]). ``` -- cgit v1.1 From 605b7e9f7f2f476d5df9d4bd45a2cc97bdb06dfa Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Wed, 22 Apr 2015 22:02:26 -0500 Subject: remove makefile --- Makefile | 43 ------------------------------------------- 1 file changed, 43 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index 49f5758..0000000 --- a/Makefile +++ /dev/null @@ -1,43 +0,0 @@ -.PHONY: clean xref_warnings deps test - -REBAR=$(PWD)/rebar3 -RETEST=$(PWD)/deps/retest/retest - -DEPS_PLT=$(CURDIR)/.depsolver_plt - -all: - @./bootstrap/rebar get-deps compile escriptize - -clean: - @rm -rf rebar3 ebin/*.beam inttest/rt.work rt.work .eunit - @rm -f .rebarinfo - -distclean: clean - @rm -rf deps - -debug: - @./bootstrap/bootstrap debug - -check: debug xref deps test - -xref: - @./rebar3 xref - -$(DEPS_PLT): - @echo Building local erts plt at $(DEPS_PLT) - @echo - dialyzer --output_plt $(DEPS_PLT) --build_plt \ - --apps erts kernel stdlib -r deps - -dialyzer: $(DEPS_PLT) - dialyzer --fullpath --plt $(DEPS_PLT) -Wno_opaque -Wrace_conditions -r ./ebin - -binary: VSN = $(shell ./rebar3 -V) -binary: clean all - @cp rebar3 ../rebar.wiki/rebar - (cd ../rebar.wiki && git commit -m "Update $(VSN)" rebar) - -test: - rebar ct - -travis: all test -- cgit v1.1 From 7b723d3a87230a893e61130024b5dbc38a3a749c Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Wed, 22 Apr 2015 22:03:45 -0500 Subject: update readme instructions --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bc2accd..1fb3f57 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ You can download a pre-built binary version of rebar3 based on the last commit f https://s3.amazonaws.com/rebar3/rebar3 -#### Building rebar +#### Bootstrapping rebar3 ```sh $ git clone https://github.com/rebar/rebar3 @@ -131,6 +131,15 @@ $ cd rebar3 $ ./bootstrap ``` +### Developing on rebar3 + +When developing you can simply run `escriptize` to build your changes but the new escript is under `_build/default/bin/rebar3` + +```sh +$ ./rebar3 escriptize +$ _build/default/bin/rebar3 +``` + Contributing to rebar ===================== -- cgit v1.1