summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjoewilliams <joe@joetify.com>2011-02-16 09:46:40 -0800
committerTuncer Ayaz <tuncer.ayaz@gmail.com>2011-02-17 17:13:19 +0100
commit4e8dcfbfade08b48fe38bfe041459960b0ff74c3 (patch)
tree0692a946e174c73ea94d4bd1bd69633c7b72e3b0 /src
parent377c9e86d5f8e8cf24cc2b2feab54bda067f569b (diff)
Clean up rebar_appups and rebar_upgrade
Diffstat (limited to 'src')
-rw-r--r--src/rebar_appups.erl22
-rw-r--r--src/rebar_rel_utils.erl48
-rw-r--r--src/rebar_upgrade.erl96
-rw-r--r--src/rebar_utils.erl35
4 files changed, 92 insertions, 109 deletions
diff --git a/src/rebar_appups.erl b/src/rebar_appups.erl
index b3a730e..dbc1561 100644
--- a/src/rebar_appups.erl
+++ b/src/rebar_appups.erl
@@ -40,13 +40,13 @@
'generate-appups'(_Config, ReltoolFile) ->
%% Get the old release path
- OldVerPath = rebar_utils:get_previous_release_path(),
+ OldVerPath = rebar_rel_utils:get_previous_release_path(),
%% Get the new and old release name and versions
- {Name, _Ver} = rebar_utils:get_reltool_release_info(ReltoolFile),
+ {Name, _Ver} = rebar_rel_utils:get_reltool_release_info(ReltoolFile),
NewVerPath = filename:join([".", Name]),
- {NewName, NewVer} = rebar_utils:get_rel_release_info(Name, NewVerPath),
- {OldName, OldVer} = rebar_utils:get_rel_release_info(Name, OldVerPath),
+ {NewName, NewVer} = rebar_rel_utils:get_rel_release_info(Name, NewVerPath),
+ {OldName, OldVer} = rebar_rel_utils:get_rel_release_info(Name, OldVerPath),
%% Run some simple checks
true = rebar_utils:prop_check(NewVer =/= OldVer,
@@ -86,8 +86,10 @@
%% ===================================================================
get_upgraded_apps(OldAppFiles, NewAppFiles) ->
- OldAppsVer = [get_app_version(AppFile) || AppFile <- OldAppFiles],
- NewAppsVer = [get_app_version(AppFile) || AppFile <- NewAppFiles],
+ OldAppsVer = [{rebar_app_utils:app_name(AppFile),
+ rebar_app_utils:app_vsn(AppFile)} || AppFile <- OldAppFiles],
+ NewAppsVer = [{rebar_app_utils:app_name(AppFile),
+ rebar_app_utils:app_vsn(AppFile)} || AppFile <- NewAppFiles],
UpgradedApps = lists:subtract(NewAppsVer, OldAppsVer),
lists:map(
fun({App, NewVer}) ->
@@ -96,14 +98,6 @@ get_upgraded_apps(OldAppFiles, NewAppFiles) ->
end,
UpgradedApps).
-get_app_version(File) ->
- case file:consult(File) of
- {ok,[{application, Name,[_,{vsn,Ver}|_]}]} ->
- {Name, Ver};
- _ ->
- ?ABORT("Failed to parse ~s~n", [File])
- end.
-
file_to_name(File) ->
filename:rootname(filename:basename(File)).
diff --git a/src/rebar_rel_utils.erl b/src/rebar_rel_utils.erl
index 91031e8..94a10b0 100644
--- a/src/rebar_rel_utils.erl
+++ b/src/rebar_rel_utils.erl
@@ -26,7 +26,14 @@
%% -------------------------------------------------------------------
-module(rebar_rel_utils).
--export([is_rel_dir/0, is_rel_dir/1]).
+-export([is_rel_dir/0,
+ is_rel_dir/1,
+ get_reltool_release_info/1,
+ get_rel_release_info/1,
+ get_rel_release_info/2,
+ get_previous_release_path/0]).
+
+-include("rebar.hrl").
is_rel_dir() ->
is_rel_dir(rebar_utils:get_cwd()).
@@ -39,3 +46,42 @@ is_rel_dir(Dir) ->
false ->
false
end.
+
+%% Get release name and version from a reltool.config
+get_reltool_release_info(ReltoolFile) ->
+ %% expect sys to be the first proplist in reltool.config
+ case file:consult(ReltoolFile) of
+ {ok, [{sys, Config}| _]} ->
+ %% expect the first rel in the proplist to be the one you want
+ {rel, Name, Ver, _} = proplists:lookup(rel, Config),
+ {Name, Ver};
+ _ ->
+ ?ABORT("Failed to parse ~s~n", [ReltoolFile])
+ end.
+
+%% Get release name and version from a rel file
+get_rel_release_info(RelFile) ->
+ case file:consult(RelFile) of
+ {ok, [{release, {Name, Ver}, _, _}]} ->
+ {Name, Ver};
+ _ ->
+ ?ABORT("Failed to parse ~s~n", [RelFile])
+ end.
+
+%% Get release name and version from a name and a path
+get_rel_release_info(Name, Path) ->
+ [RelFile] = filelib:wildcard(filename:join([Path, "releases", "*",
+ Name ++ ".rel"])),
+ [BinDir|_] = re:replace(RelFile, Name ++ "\\.rel", ""),
+ get_rel_release_info(filename:join([binary_to_list(BinDir),
+ Name ++ ".rel"])).
+
+%% Get the previous release path from a global variable
+get_previous_release_path() ->
+ case rebar_config:get_global(previous_release, false) of
+ false ->
+ ?ABORT("previous_release=PATH is required to "
+ "create upgrade package~n", []);
+ OldVerPath ->
+ OldVerPath
+ end.
diff --git a/src/rebar_upgrade.erl b/src/rebar_upgrade.erl
index 639ddef..a1b34df 100644
--- a/src/rebar_upgrade.erl
+++ b/src/rebar_upgrade.erl
@@ -4,7 +4,7 @@
%%
%% rebar: Erlang Build Tools
%%
-%% Copyright (c) 2011 Joe Williams <joe@joetify.com>
+%% Copyright (c) 2011 Joe Williams (joe@joetify.com)
%%
%% Permission is hereby granted, free of charge, to any person obtaining a copy
%% of this software and associated documentation files (the "Software"), to deal
@@ -32,91 +32,69 @@
-export(['generate-upgrade'/2]).
-%% public api
+%% ====================================================================
+%% Public API
+%% ====================================================================
'generate-upgrade'(_Config, ReltoolFile) ->
- case rebar_config:get_global(previous_release, false) of
- false ->
- ?ABORT("previous_release=PATH is required to "
- "create upgrade package~n", []);
- OldVerPath ->
- %% Run checks to make sure that building a package is possible
- {NewName, NewVer} = run_checks(OldVerPath, ReltoolFile),
- NameVer = NewName ++ "_" ++ NewVer,
+ %% Get the old release path
+ OldVerPath = rebar_rel_utils:get_previous_release_path(),
+
+ %% Run checks to make sure that building a package is possible
+ {NewName, NewVer} = run_checks(OldVerPath, ReltoolFile),
+ NameVer = NewName ++ "_" ++ NewVer,
- %% Save the code path prior to doing anything
- OrigPath = code:get_path(),
+ %% Save the code path prior to doing anything
+ OrigPath = code:get_path(),
- %% Prepare the environment for building the package
- ok = setup(OldVerPath, NewName, NewVer, NameVer),
+ %% Prepare the environment for building the package
+ ok = setup(OldVerPath, NewName, NewVer, NameVer),
- %% Build the package
- run_systools(NameVer, NewName),
+ %% Build the package
+ run_systools(NameVer, NewName),
- %% Boot file changes
- {ok, _} = boot_files(NewVer, NewName),
+ %% Boot file changes
+ {ok, _} = boot_files(NewVer, NewName),
- %% Extract upgrade and tar it back up with changes
- make_tar(NameVer),
+ %% Extract upgrade and tar it back up with changes
+ make_tar(NameVer),
- %% Clean up files that systools created
- ok = cleanup(NameVer, NewName, NewVer),
+ %% Clean up files that systools created
+ ok = cleanup(NameVer, NewName, NewVer),
- %% Restore original path
- true = code:set_path(OrigPath),
+ %% Restore original path
+ true = code:set_path(OrigPath),
- ok
- end.
+ ok.
-%% internal api
+%% ===================================================================
+%% Internal functions
+%% ==================================================================
run_checks(OldVerPath, ReltoolFile) ->
- true = prop_check(filelib:is_dir(OldVerPath),
+ true = rebar_utils:prop_check(filelib:is_dir(OldVerPath),
"Release directory doesn't exist (~p)~n", [OldVerPath]),
- {Name, Ver} = get_release_name(ReltoolFile),
+ {Name, Ver} = rebar_rel_utils:get_reltool_release_info(ReltoolFile),
NamePath = filename:join([".", Name]),
- true = prop_check(filelib:is_dir(NamePath),
+ true = rebar_utils:prop_check(filelib:is_dir(NamePath),
"Release directory doesn't exist (~p)~n", [NamePath]),
- {NewName, NewVer} = get_release_version(Name, NamePath),
- {OldName, OldVer} = get_release_version(Name, OldVerPath),
+ {NewName, NewVer} = rebar_rel_utils:get_rel_release_info(Name, NamePath),
+ {OldName, OldVer} = rebar_rel_utils:get_rel_release_info(Name, OldVerPath),
- true = prop_check(NewName == OldName,
+ true = rebar_utils:prop_check(NewName == OldName,
"New and old .rel release names do not match~n", []),
- true = prop_check(Name == NewName,
+ true = rebar_utils:prop_check(Name == NewName,
"Reltool and .rel release names do not match~n", []),
- true = prop_check(NewVer =/= OldVer,
+ true = rebar_utils:prop_check(NewVer =/= OldVer,
"New and old .rel contain the same version~n", []),
- true = prop_check(Ver == NewVer,
+ true = rebar_utils:prop_check(Ver == NewVer,
"Reltool and .rel versions do not match~n", []),
{NewName, NewVer}.
-get_release_name(ReltoolFile) ->
- %% expect sys to be the first proplist in reltool.config
- case file:consult(ReltoolFile) of
- {ok, [{sys, Config}| _]} ->
- %% expect the first rel in the proplist to be the one you want
- {rel, Name, Ver, _} = proplists:lookup(rel, Config),
- {Name, Ver};
- _ ->
- ?ABORT("Failed to parse ~s~n", [ReltoolFile])
- end.
-
-get_release_version(Name, Path) ->
- [RelFile] = filelib:wildcard(filename:join([Path, "releases", "*",
- Name ++ ".rel"])),
- [BinDir|_] = re:replace(RelFile, Name ++ "\\.rel", ""),
- {ok, [{release, {Name1, Ver}, _, _}]} =
- file:consult(filename:join([binary_to_list(BinDir),
- Name ++ ".rel"])),
- {Name1, Ver}.
-
-prop_check(true, _, _) -> true;
-prop_check(false, Msg, Args) -> ?ABORT(Msg, Args).
-
setup(OldVerPath, NewName, NewVer, NameVer) ->
NewRelPath = filename:join([".", NewName]),
Src = filename:join([NewRelPath, "releases",
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index dc7de9b..2822c0f 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -38,9 +38,6 @@
abort/2,
escript_foldl/3,
find_executable/1,
- get_reltool_release_info/1,
- get_rel_release_info/2,
- get_previous_release_path/0,
prop_check/3]).
-include("rebar.hrl").
@@ -155,38 +152,6 @@ find_executable(Name) ->
"\"" ++ filename:nativename(Path) ++ "\""
end.
-%% Get release name and version from a reltool.config
-get_reltool_release_info(ReltoolFile) ->
- %% expect sys to be the first proplist in reltool.config
- case file:consult(ReltoolFile) of
- {ok, [{sys, Config}| _]} ->
- %% expect the first rel in the proplist to be the one you want
- {rel, Name, Ver, _} = proplists:lookup(rel, Config),
- {Name, Ver};
- _ ->
- ?ABORT("Failed to parse ~s~n", [ReltoolFile])
- end.
-
-%% Get release name and version from a rel file
-get_rel_release_info(Name, Path) ->
- [RelFile] = filelib:wildcard(filename:join([Path, "releases", "*",
- Name ++ ".rel"])),
- [BinDir|_] = re:replace(RelFile, Name ++ "\\.rel", ""),
- {ok, [{release, {Name1, Ver}, _, _}]} =
- file:consult(filename:join([binary_to_list(BinDir),
- Name ++ ".rel"])),
- {Name1, Ver}.
-
-%% Get the previous release path from a global variable
-get_previous_release_path() ->
- case rebar_config:get_global(previous_release, false) of
- false ->
- ?ABORT("previous_release=PATH is required to "
- "create upgrade package~n", []);
- OldVerPath ->
- OldVerPath
- end.
-
%% Helper function for checking values and aborting when needed
prop_check(true, _, _) -> true;
prop_check(false, Msg, Args) -> ?ABORT(Msg, Args).