浏览代码

follow xdg standard. fixes #122

pull/166/head
Tristan Sloughter 10 年前
父节点
当前提交
e73ed97cfd
共有 9 个文件被更改,包括 46 次插入38 次删除
  1. +0
    -1
      src/rebar.hrl
  2. +2
    -3
      src/rebar3.erl
  3. +26
    -13
      src/rebar_dir.erl
  4. +3
    -3
      src/rebar_erlc_compiler.erl
  5. +1
    -1
      src/rebar_packages.erl
  6. +1
    -2
      src/rebar_prv_dialyzer.erl
  7. +1
    -1
      src/rebar_prv_update.erl
  8. +11
    -13
      src/rebar_templater.erl
  9. +1
    -1
      test/rebar_new_SUITE.erl

+ 0
- 1
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().

+ 2
- 3
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",

+ 26
- 13
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([]) ->

+ 3
- 3
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

+ 1
- 1
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"),

+ 1
- 2
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).

+ 1
- 1
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")),

+ 11
- 13
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].

+ 1
- 1
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

正在加载...
取消
保存