From eda264af8a7e9fd8d5c20ce0098f46eef9f50efd Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 21 Feb 2020 15:48:14 +0000 Subject: [PATCH] Allow specifying the outdir in bare compiler Currently, we just write to ebin/ in the current working directory; this implies that the source _should_ always be in the same subpath as the ebin/ directory. In the cases of utils like Mix, which store downloaded dependencies in deps/ and artifacts in _build/, this may force more rebuild or less caching that would be ideal. This PR adds --outdir / -o as options to the bare compiler, which lets the user specify another path, with a default kept to $CWD. --- src/rebar_prv_bare_compile.erl | 39 ++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/src/rebar_prv_bare_compile.erl b/src/rebar_prv_bare_compile.erl index 5d3e977e..f458dd4d 100644 --- a/src/rebar_prv_bare_compile.erl +++ b/src/rebar_prv_bare_compile.erl @@ -19,18 +19,30 @@ -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, [{paths, $p, "paths", string, "Wildcard paths of ebin directories to add to code path, separated by a colon"}, - {separator, $s, "separator", string, "In case of multiple return paths, the separator character to use to join them."}]}])), + 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 paths of ebin directories to add to code path, " + "separated by a colon"}, + {separator, $s, "separator", string, + "In case of multiple return paths, the separator character " + "to use to join them."}, + {outdir, $o, "outdir", string, + "Path where build artifacts are located. Defaults to the " + "current directory."} + ]} + ]) + ), {ok, State1}. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. @@ -41,11 +53,12 @@ do(State) -> {RawOpts, _} = rebar_state:command_parsed_args(State), Paths = proplists:get_value(paths, RawOpts), Sep = proplists:get_value(separator, RawOpts, " "), + OutDir = proplists:get_value(outdir, RawOpts, rebar_dir:get_cwd()), [ code:add_pathsa(filelib:wildcard(PathWildcard)) || PathWildcard <- rebar_string:lexemes(Paths, Sep) ], [AppInfo] = rebar_state:project_apps(State), - AppInfo1 = rebar_app_info:out_dir(AppInfo, rebar_dir:get_cwd()), + AppInfo1 = rebar_app_info:out_dir(AppInfo, OutDir), %% run compile in the default namespace rebar_prv_compile:compile(rebar_state:namespace(State, default), AppInfo1),