summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-02-21 17:27:16 -0500
committerFred Hebert <mononcqc@ferd.ca>2015-02-21 17:27:16 -0500
commit8988c9ff6c09da0e2e2e3b7285720e7dfe712730 (patch)
tree06c73f7b45512574b4761796b2c66125dacb2868
parentdf30a93891fd85fcad566c100c53e463448662a1 (diff)
parent24383e228373d14c23c56225fe3e974dcbb0b43d (diff)
Merge pull request #166 from tsloughter/xdg
follow xdg standard. fixes #122
-rw-r--r--doc/templates.md10
-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
-rw-r--r--test/rebar_upgrade_SUITE.erl6
11 files changed, 54 insertions, 46 deletions
diff --git a/doc/templates.md b/doc/templates.md
index 096cd37..598a689 100644
--- a/doc/templates.md
+++ b/doc/templates.md
@@ -17,7 +17,7 @@
## Global Variables
-Global variables can be set by editing the file at `$HOME/.rebar3/templates/globals`:
+Global variables can be set by editing the file at `$HOME/.config/rebar3/templates/globals`:
{variables, [
{author_name, "My Name Is A String"},
@@ -29,7 +29,7 @@ This will let you define variables for all templates.
Variables left undefined will be ignored and revert to the default value.
-The override order for these variables will be: Defaults < $HOME/.rebar3/templates/globals < command line invocation.
+The override order for these variables will be: Defaults < $HOME/.config/rebar3/templates/globals < command line invocation.
## Batteries-Included Templates ##
@@ -77,7 +77,7 @@ Then go to the directory created for the project by rebar3.
## Custom Templates ##
-Custom templates can be added in `$HOME/.rebar3/templates/`. Each template is at least two files:
+Custom templates can be added in `$HOME/.config/rebar3/templates/`. Each template is at least two files:
- `my_template.dtl`: There can be many of these files. They are regular Erlang files using the django template syntax for variable replacements.
- `my_template.template`; Called the *template index*, there is one per template callable from `rebar3`. This one will be visible when calling `rebar3 new my_template`. This file regroups the different \*.dtl files into a more cohesive template.
@@ -112,7 +112,7 @@ Specifically:
### Example ###
-As an example, we'll create a template for Common Test test suites. Create the directory structure `~/.rebar/templates/` and then go in there.
+As an example, we'll create a template for Common Test test suites. Create the directory structure `~/.config/rebar/templates/` and then go in there.
We'll start with an index for our template, called `ct_suite.template`:
@@ -173,7 +173,7 @@ Let's look at the details:
→ ./rebar3 new help ct_suite
ct_suite:
- custom template (/home/ferd/.rebar3/templates/ct_suite.template)
+ custom template (/home/ferd/.config/rebar3/templates/ct_suite.template)
Description: A basic Common Test suite for an OTP application
Variables:
name="suite" (Name of the suite, prepended to the standard _SUITE suffix)
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 03b7b98..e8a9983 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -144,9 +144,8 @@ init_config() ->
Config1 = rebar_config:merge_locks(Config, rebar_config:consult_file(?LOCK_FILE)),
- %% 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
diff --git a/test/rebar_upgrade_SUITE.erl b/test/rebar_upgrade_SUITE.erl
index b4daef9..ed0b2d8 100644
--- a/test/rebar_upgrade_SUITE.erl
+++ b/test/rebar_upgrade_SUITE.erl
@@ -357,10 +357,10 @@ upgrades(delete_d) ->
%% running the upgrade code is enough to properly upgrade things.
top_level_deps([]) -> [];
-top_level_deps([{{Name, Vsn, Ref}, _} | Deps]) ->
- [{list_to_atom(Name), Vsn, Ref} | top_level_deps(Deps)];
top_level_deps([{{pkg, Name, Vsn}, _} | Deps]) ->
- [{list_to_atom(Name), Vsn} | top_level_deps(Deps)].
+ [{list_to_atom(Name), Vsn} | top_level_deps(Deps)];
+top_level_deps([{{Name, Vsn, Ref}, _} | Deps]) ->
+ [{list_to_atom(Name), Vsn, Ref} | top_level_deps(Deps)].
mock_deps(git, Deps, Upgrades) ->
catch mock_git_resource:unmock(),