From 4c29a771c1a5c8d81bf727b98d40ecd9f486f66f Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Tue, 8 Sep 2015 19:27:36 -0500 Subject: add bare compile provider, for starters for use by mix --- src/rebar.app.src | 1 + src/rebar_prv_bare_compile.erl | 42 ++++++++++++++++++++++++++++++++++++++++++ src/rebar_prv_compile.erl | 6 +++++- 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/rebar_prv_bare_compile.erl diff --git a/src/rebar.app.src b/src/rebar.app.src index 4d1dfd7..69df1b2 100644 --- a/src/rebar.app.src +++ b/src/rebar.app.src @@ -36,6 +36,7 @@ {providers, [rebar_prv_app_discovery, rebar_prv_as, + rebar_prv_bare_compile, rebar_prv_clean, rebar_prv_common_test, rebar_prv_compile, diff --git a/src/rebar_prv_bare_compile.erl b/src/rebar_prv_bare_compile.erl new file mode 100644 index 0000000..911c5c5 --- /dev/null +++ b/src/rebar_prv_bare_compile.erl @@ -0,0 +1,42 @@ +-module(rebar_prv_bare_compile). + +-behaviour(provider). + +-export([init/1, + do/1, + format_error/1]). + +-include_lib("providers/include/providers.hrl"). +-include("rebar.hrl"). + +-define(PROVIDER, compile). +-define(NAMESPACE, bare). +-define(DEPS, [{default, app_discovery}]). + +%% =================================================================== +%% Public API +%% =================================================================== + +-spec init(rebar_state:t()) -> {ok, rebar_state:t()}. +init(State) -> + State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER}, + {module, ?MODULE}, + {namespace, ?NAMESPACE}, + {bare, false}, + {deps, ?DEPS}, + {example, ""}, + {short_desc, ""}, + {desc, ""}, + {opts, []}])), + {ok, State1}. + +-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. +do(State) -> + [AppInfo] = rebar_state:project_apps(State), + AppInfo1 = rebar_app_info:out_dir(AppInfo, rebar_dir:get_cwd()), + rebar_prv_compile:compile(State, AppInfo1), + {ok, State}. + +-spec format_error(any()) -> iolist(). +format_error(Reason) -> + io_lib:format("~p", [Reason]). diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index 89ea430..9811de9 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -6,7 +6,8 @@ do/1, format_error/1]). --export([compile/3]). +-export([compile/2, + compile/3]). -include_lib("providers/include/providers.hrl"). -include("rebar.hrl"). @@ -81,6 +82,9 @@ build_app(State, Providers, AppInfo) -> copy_app_dirs(AppInfo, AppDir, OutDir), compile(State, Providers, AppInfo). +compile(State, AppInfo) -> + compile(State, rebar_state:providers(State), AppInfo). + compile(State, Providers, AppInfo) -> ?INFO("Compiling ~s", [rebar_app_info:name(AppInfo)]), AppDir = rebar_app_info:dir(AppInfo), -- cgit v1.1 From 16ea08b9c3aee3608d71cd3e9baf3c16546eda09 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 11 Sep 2015 21:12:26 -0500 Subject: add rebar3 paths to the end of the code path in start script --- src/rebar_prv_local_install.erl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/rebar_prv_local_install.erl b/src/rebar_prv_local_install.erl index bf536d0..4babd14 100644 --- a/src/rebar_prv_local_install.erl +++ b/src/rebar_prv_local_install.erl @@ -58,8 +58,7 @@ format_error(Reason) -> io_lib:format("~p", [Reason]). bin_contents(OutputDir) -> - <<" -#!/usr/bin/env sh + <<"#!/usr/bin/env sh erl -pa ", (ec_cnv:to_binary(OutputDir))/binary,"/*/ebin +sbtu +A0 -noshell -boot start_clean -s rebar3 main -extra \"$@\" ">>. -- cgit v1.1 From 9dfec19c67fc72f9ff9abbef95bcfd74a4471056 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 11 Sep 2015 21:15:12 -0500 Subject: escript should append the ebin dirs to the code path not prepend --- src/rebar_prv_escriptize.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rebar_prv_escriptize.erl b/src/rebar_prv_escriptize.erl index 3cdc9bf..32f5508 100644 --- a/src/rebar_prv_escriptize.erl +++ b/src/rebar_prv_escriptize.erl @@ -107,7 +107,7 @@ escriptize(State0, App) -> ExtraFiles = usort(InclBeams ++ InclExtra), Files = get_nonempty(EbinFiles ++ ExtraFiles), - DefaultEmuArgs = ?FMT("%%! -escript main ~s -pa ~s/~s/ebin\n", + DefaultEmuArgs = ?FMT("%%! -escript main ~s -pz ~s/~s/ebin\n", [AppNameStr, AppNameStr, AppNameStr]), EscriptSections = [ {shebang, -- cgit v1.1 From 665bdf6bdb02fe5279e8a8b05b72cd4519c757bc Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Fri, 11 Sep 2015 22:41:45 -0500 Subject: add --paths option to bare compile provider --- src/rebar_prv_bare_compile.erl | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/rebar_prv_bare_compile.erl b/src/rebar_prv_bare_compile.erl index 911c5c5..201620a 100644 --- a/src/rebar_prv_bare_compile.erl +++ b/src/rebar_prv_bare_compile.erl @@ -19,22 +19,35 @@ -spec init(rebar_state:t()) -> {ok, rebar_state:t()}. init(State) -> - State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER}, - {module, ?MODULE}, - {namespace, ?NAMESPACE}, - {bare, false}, - {deps, ?DEPS}, - {example, ""}, - {short_desc, ""}, - {desc, ""}, - {opts, []}])), + State1 = + rebar_state:add_provider(State, + providers:create([{name, ?PROVIDER}, + {module, ?MODULE}, + {namespace, ?NAMESPACE}, + {bare, false}, + {deps, ?DEPS}, + {example, ""}, + {short_desc, ""}, + {desc, ""}, + {opts, [{paths, $p, "paths", string, "Wildcard path of ebin directories to add to code path"}]}])), {ok, State1}. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do(State) -> + OrigPath = code:get_path(), + + %% Add code paths from --paths to the beginning of the code path + {RawOpts, _} = rebar_state:command_parsed_args(State), + Paths = proplists:get_value(paths, RawOpts), + CodePaths = filelib:wildcard(Paths), + code:add_pathsa(CodePaths), + [AppInfo] = rebar_state:project_apps(State), AppInfo1 = rebar_app_info:out_dir(AppInfo, rebar_dir:get_cwd()), rebar_prv_compile:compile(State, AppInfo1), + + rebar_utils:cleanup_code_path(OrigPath), + {ok, State}. -spec format_error(any()) -> iolist(). -- cgit v1.1 From 7ad9f7ea75ab96aaecc4e420772ada151f2d4473 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Mon, 14 Sep 2015 20:01:25 -0500 Subject: append ebin dirs to path in local start script --- src/rebar_prv_local_install.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rebar_prv_local_install.erl b/src/rebar_prv_local_install.erl index 4babd14..172986d 100644 --- a/src/rebar_prv_local_install.erl +++ b/src/rebar_prv_local_install.erl @@ -60,7 +60,7 @@ format_error(Reason) -> bin_contents(OutputDir) -> <<"#!/usr/bin/env sh -erl -pa ", (ec_cnv:to_binary(OutputDir))/binary,"/*/ebin +sbtu +A0 -noshell -boot start_clean -s rebar3 main -extra \"$@\" +erl -pz ", (ec_cnv:to_binary(OutputDir))/binary,"/*/ebin +sbtu +A0 -noshell -boot start_clean -s rebar3 main -extra \"$@\" ">>. extract_escript(State, ScriptPath) -> -- cgit v1.1