summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar.hrl1
-rw-r--r--src/rebar3.erl5
-rw-r--r--src/rebar_dir.erl39
-rw-r--r--src/rebar_erlc_compiler.erl6
-rw-r--r--src/rebar_packages.erl2
-rw-r--r--src/rebar_prv_dialyzer.erl3
-rw-r--r--src/rebar_prv_update.erl2
-rw-r--r--src/rebar_templater.erl24
-rw-r--r--test/rebar_new_SUITE.erl2
9 files changed, 46 insertions, 38 deletions
diff --git a/src/rebar.hrl b/src/rebar.hrl
index fdef438..bbd9a2f 100644
--- a/src/rebar.hrl
+++ b/src/rebar.hrl
@@ -22,7 +22,6 @@
-define(DEFAULT_RELEASE_DIR, "rel").
-define(DEFAULT_CONFIG_FILE, "rebar.config").
-define(LOCK_FILE, "rebar.lock").
--define(CONFIG_DIR, ".rebar3").
-ifdef(namespaced_types).
-type rebar_dict() :: dict:dict().
diff --git a/src/rebar3.erl b/src/rebar3.erl
index 268be68..5a49ca8 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -152,9 +152,8 @@ init_config() ->
Config
end,
- %% If $HOME/.rebar3/config exists load and use as global config
- Home = rebar_dir:home_dir(),
- GlobalConfigFile = filename:join([Home, ?CONFIG_DIR, "config"]),
+ %% If $HOME/.config/rebar3/config exists load and use as global config
+ GlobalConfigFile = rebar_dir:global_config(),
State = case filelib:is_regular(GlobalConfigFile) of
true ->
?DEBUG("Load global config file ~p",
diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl
index 58ce716..3962bf8 100644
--- a/src/rebar_dir.erl
+++ b/src/rebar_dir.erl
@@ -7,8 +7,13 @@
lib_dirs/1,
home_dir/0,
global_config_dir/1,
+ global_config/1,
+ global_config/0,
+ global_cache_dir/1,
+ local_cache_dir/0,
get_cwd/0,
- ensure_dir/1,
+ template_globals/1,
+ template_dir/1,
src_dirs/1,
ebin_dir/0,
processing_base_dir/1,
@@ -47,23 +52,31 @@ home_dir() ->
global_config_dir(State) ->
Home = home_dir(),
- rebar_state:get(State, global_rebar_dir, filename:join(Home, ?CONFIG_DIR)).
+ rebar_state:get(State, global_rebar_dir, filename:join([Home, ".config", "rebar3"])).
+
+global_config(State) ->
+ filename:join(global_config_dir(State), "config").
+
+global_config() ->
+ Home = home_dir(),
+ filename:join([Home, ".config", "rebar3", "config"]).
+
+global_cache_dir(State) ->
+ Home = home_dir(),
+ rebar_state:get(State, global_rebar_dir, filename:join([Home, ".cache", "rebar3"])).
+
+local_cache_dir() ->
+ filename:join(get_cwd(), ".rebar3").
get_cwd() ->
{ok, Dir} = file:get_cwd(),
Dir.
-%% TODO: filelib:ensure_dir/1 corrected in R13B04. Remove when we drop
-%% support for OTP releases older than R13B04.
-ensure_dir(Path) ->
- case filelib:ensure_dir(Path) of
- ok ->
- ok;
- {error,eexist} ->
- ok;
- Error ->
- Error
- end.
+template_globals(State) ->
+ filename:join([global_config_dir(State), "templates", "globals"]).
+
+template_dir(State) ->
+ filename:join([global_config_dir(State), "templates"]).
-spec src_dirs([string()]) -> [file:filename(), ...].
src_dirs([]) ->
diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl
index 330f20b..77b4fa2 100644
--- a/src/rebar_erlc_compiler.erl
+++ b/src/rebar_erlc_compiler.erl
@@ -283,7 +283,7 @@ check_erlcinfo(Config, _) ->
[erlcinfo_file(Config)]).
erlcinfo_file(_Config) ->
- filename:join([rebar_dir:get_cwd(), ?CONFIG_DIR, ?ERLCINFO_FILE]).
+ filename:join(rebar_dir:local_cache_dir(), ?ERLCINFO_FILE).
init_erlcinfo(Config, Erls) ->
G = restore_erlcinfo(Config),
@@ -464,8 +464,8 @@ internal_erl_compile(Config, Dir, Source, OutDir, ErlOpts, G) ->
-spec compile_mib(file:filename(), file:filename(),
rebar_state:t()) -> 'ok'.
compile_mib(Source, Target, Config) ->
- ok = rebar_dir:ensure_dir(Target),
- ok = rebar_dir:ensure_dir(filename:join("include", "dummy.hrl")),
+ ok = filelib:ensure_dir(Target),
+ ok = filelib:ensure_dir(filename:join("include", "dummy.hrl")),
Opts = [{outdir, "priv/mibs"}, {i, ["priv/mibs"]}] ++
rebar_state:get(Config, mib_opts, []),
case snmpc:compile(Source, Opts) of
diff --git a/src/rebar_packages.erl b/src/rebar_packages.erl
index 38dfbbf..5c67600 100644
--- a/src/rebar_packages.erl
+++ b/src/rebar_packages.erl
@@ -12,7 +12,7 @@
-spec get_packages(rebar_state:t()) -> {rebar_dict(), rebar_digraph()}.
get_packages(State) ->
- RebarDir = rebar_dir:global_config_dir(State),
+ RebarDir = rebar_dir:global_cache_dir(State),
RegistryDir = filename:join(RebarDir, "packages"),
DictFile = filename:join(RegistryDir, "dict"),
Edges = filename:join(RegistryDir, "edges"),
diff --git a/src/rebar_prv_dialyzer.erl b/src/rebar_prv_dialyzer.erl
index 240427b..24abc4f 100644
--- a/src/rebar_prv_dialyzer.erl
+++ b/src/rebar_prv_dialyzer.erl
@@ -311,8 +311,7 @@ build_proj_plt(State, Plt, Files) ->
end.
get_base_plt_location(State) ->
- Home = rebar_dir:home_dir(),
- GlobalConfigDir = filename:join(Home, ?CONFIG_DIR),
+ GlobalConfigDir = rebar_dir:global_config_dir(State),
BaseDir = rebar_state:get(State, dialyzer_base_plt_dir, GlobalConfigDir),
BasePlt = rebar_state:get(State, dialyzer_base_plt, default_plt()),
filename:join(BaseDir, BasePlt).
diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl
index f4985f3..20f6974 100644
--- a/src/rebar_prv_update.erl
+++ b/src/rebar_prv_update.erl
@@ -59,7 +59,7 @@ format_error(package_index_write) ->
"Failed to write package index.".
write_registry(Dict, {digraph, Edges, Vertices, Neighbors, _}, State) ->
- Dir = rebar_dir:global_config_dir(State),
+ Dir = rebar_dir:global_cache_dir(State),
RegistryDir = filename:join(Dir, "packages"),
filelib:ensure_dir(filename:join(RegistryDir, "dummy")),
ets:tab2file(Edges, filename:join(RegistryDir, "edges")),
diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl
index 47ce093..edfe3bd 100644
--- a/src/rebar_templater.erl
+++ b/src/rebar_templater.erl
@@ -48,13 +48,13 @@ new(Template, Vars, Force, State) ->
?DEBUG("Looking for ~p~n", [Template]),
case lists:keyfind(Template, 1, AvailTemplates) of
false -> {not_found, Template};
- TemplateTup -> create(TemplateTup, Files, Vars, Force)
+ TemplateTup -> create(TemplateTup, Files, Vars, Force, State)
end.
%% Give a list of templates with their expanded content
list_templates(State) ->
{AvailTemplates, Files} = find_templates(State),
- [list_template(Files, Template) || Template <- AvailTemplates].
+ [list_template(Files, Template, State) || Template <- AvailTemplates].
%% ===================================================================
%% Rendering API / legacy?
@@ -89,11 +89,11 @@ render(Template, Context) ->
%% ===================================================================
%% Expand a single template's value
-list_template(Files, {Name, Type, File}) ->
+list_template(Files, {Name, Type, File}, State) ->
TemplateTerms = consult(load_file(Files, Type, File)),
{Name, Type, File,
get_template_description(TemplateTerms),
- get_template_vars(TemplateTerms)}.
+ get_template_vars(TemplateTerms, State)}.
%% Load up the template description out from a list of attributes read in
%% a .template file.
@@ -105,12 +105,12 @@ get_template_description(TemplateTerms) ->
%% Load up the variables out from a list of attributes read in a .template file
%% and return them merged with the globally-defined and default variables.
-get_template_vars(TemplateTerms) ->
+get_template_vars(TemplateTerms, State) ->
Vars = case lists:keyfind(variables, 1, TemplateTerms) of
{_, Value} -> Value;
false -> []
end,
- override_vars(Vars, override_vars(global_variables(), default_variables())).
+ override_vars(Vars, override_vars(global_variables(State), default_variables())).
%% Provide a way to merge a set of variables with another one. The left-hand
%% set of variables takes precedence over the right-hand set.
@@ -142,9 +142,8 @@ default_variables() ->
%% Load variable definitions from the 'Globals' file in the home template
%% directory
-global_variables() ->
- Home = rebar_dir:home_dir(),
- GlobalFile = filename:join([Home, ?CONFIG_DIR, "templates", "globals"]),
+global_variables(State) ->
+ GlobalFile = rebar_dir:template_globals(State),
case file:consult(GlobalFile) of
{error, enoent} -> [];
{ok, Data} -> proplists:get_value(variables, Data, [])
@@ -157,9 +156,9 @@ drop_var_docs([{K,V}|Rest]) -> [{K,V} | drop_var_docs(Rest)].
%% Load the template index, resolve all variables, and then execute
%% the template.
-create({Template, Type, File}, Files, UserVars, Force) ->
+create({Template, Type, File}, Files, UserVars, Force, State) ->
TemplateTerms = consult(load_file(Files, Type, File)),
- Vars = drop_var_docs(override_vars(UserVars, get_template_vars(TemplateTerms))),
+ Vars = drop_var_docs(override_vars(UserVars, get_template_vars(TemplateTerms, State))),
TemplateCwd = filename:dirname(File),
execute_template(TemplateTerms, Files, {Template, Type, TemplateCwd}, Vars, Force).
@@ -270,8 +269,7 @@ find_escript_templates(Files) ->
%% Fetch template indexes that sit on disk in the user's HOME
find_disk_templates(State) ->
OtherTemplates = find_other_templates(State),
- Home = rebar_dir:home_dir(),
- HomeFiles = rebar_utils:find_files(filename:join([Home, ?CONFIG_DIR, "templates"]),
+ HomeFiles = rebar_utils:find_files(rebar_dir:template_dir(State),
?TEMPLATE_RE, true), % recursive
[{file, F} || F <- OtherTemplates ++ HomeFiles].
diff --git a/test/rebar_new_SUITE.erl b/test/rebar_new_SUITE.erl
index 62a26af..6b57b74 100644
--- a/test/rebar_new_SUITE.erl
+++ b/test/rebar_new_SUITE.erl
@@ -23,7 +23,7 @@ end_per_testcase(_, Config) ->
mock_home_dir(Path) ->
meck:new(rebar_dir, [passthrough]),
- meck:expect(rebar_dir, home_dir, fun() -> Path end).
+ meck:expect(rebar_dir, template_dir, fun(_) -> Path end).
mock_empty_escript_templates() ->
%% Can't find escript templates unless we run