mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 03:00:17 +00:00
Clean up rebar_appups and rebar_upgrade
This commit is contained in:
parent
377c9e86d5
commit
4e8dcfbfad
4 changed files with 92 additions and 109 deletions
|
@ -40,13 +40,13 @@
|
||||||
|
|
||||||
'generate-appups'(_Config, ReltoolFile) ->
|
'generate-appups'(_Config, ReltoolFile) ->
|
||||||
%% Get the old release path
|
%% 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
|
%% 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]),
|
NewVerPath = filename:join([".", Name]),
|
||||||
{NewName, NewVer} = rebar_utils:get_rel_release_info(Name, NewVerPath),
|
{NewName, NewVer} = rebar_rel_utils:get_rel_release_info(Name, NewVerPath),
|
||||||
{OldName, OldVer} = rebar_utils:get_rel_release_info(Name, OldVerPath),
|
{OldName, OldVer} = rebar_rel_utils:get_rel_release_info(Name, OldVerPath),
|
||||||
|
|
||||||
%% Run some simple checks
|
%% Run some simple checks
|
||||||
true = rebar_utils:prop_check(NewVer =/= OldVer,
|
true = rebar_utils:prop_check(NewVer =/= OldVer,
|
||||||
|
@ -86,8 +86,10 @@
|
||||||
%% ===================================================================
|
%% ===================================================================
|
||||||
|
|
||||||
get_upgraded_apps(OldAppFiles, NewAppFiles) ->
|
get_upgraded_apps(OldAppFiles, NewAppFiles) ->
|
||||||
OldAppsVer = [get_app_version(AppFile) || AppFile <- OldAppFiles],
|
OldAppsVer = [{rebar_app_utils:app_name(AppFile),
|
||||||
NewAppsVer = [get_app_version(AppFile) || AppFile <- NewAppFiles],
|
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),
|
UpgradedApps = lists:subtract(NewAppsVer, OldAppsVer),
|
||||||
lists:map(
|
lists:map(
|
||||||
fun({App, NewVer}) ->
|
fun({App, NewVer}) ->
|
||||||
|
@ -96,14 +98,6 @@ get_upgraded_apps(OldAppFiles, NewAppFiles) ->
|
||||||
end,
|
end,
|
||||||
UpgradedApps).
|
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) ->
|
file_to_name(File) ->
|
||||||
filename:rootname(filename:basename(File)).
|
filename:rootname(filename:basename(File)).
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,14 @@
|
||||||
%% -------------------------------------------------------------------
|
%% -------------------------------------------------------------------
|
||||||
-module(rebar_rel_utils).
|
-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() ->
|
||||||
is_rel_dir(rebar_utils:get_cwd()).
|
is_rel_dir(rebar_utils:get_cwd()).
|
||||||
|
@ -39,3 +46,42 @@ is_rel_dir(Dir) ->
|
||||||
false ->
|
false ->
|
||||||
false
|
false
|
||||||
end.
|
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.
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
%%
|
%%
|
||||||
%% rebar: Erlang Build Tools
|
%% 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
|
%% Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
%% of this software and associated documentation files (the "Software"), to deal
|
%% of this software and associated documentation files (the "Software"), to deal
|
||||||
|
@ -32,91 +32,69 @@
|
||||||
|
|
||||||
-export(['generate-upgrade'/2]).
|
-export(['generate-upgrade'/2]).
|
||||||
|
|
||||||
%% public api
|
%% ====================================================================
|
||||||
|
%% Public API
|
||||||
|
%% ====================================================================
|
||||||
|
|
||||||
'generate-upgrade'(_Config, ReltoolFile) ->
|
'generate-upgrade'(_Config, ReltoolFile) ->
|
||||||
case rebar_config:get_global(previous_release, false) of
|
%% Get the old release path
|
||||||
false ->
|
OldVerPath = rebar_rel_utils:get_previous_release_path(),
|
||||||
?ABORT("previous_release=PATH is required to "
|
|
||||||
"create upgrade package~n", []);
|
%% Run checks to make sure that building a package is possible
|
||||||
OldVerPath ->
|
{NewName, NewVer} = run_checks(OldVerPath, ReltoolFile),
|
||||||
%% Run checks to make sure that building a package is possible
|
NameVer = NewName ++ "_" ++ NewVer,
|
||||||
{NewName, NewVer} = run_checks(OldVerPath, ReltoolFile),
|
|
||||||
NameVer = NewName ++ "_" ++ NewVer,
|
|
||||||
|
|
||||||
%% Save the code path prior to doing anything
|
%% Save the code path prior to doing anything
|
||||||
OrigPath = code:get_path(),
|
OrigPath = code:get_path(),
|
||||||
|
|
||||||
%% Prepare the environment for building the package
|
%% Prepare the environment for building the package
|
||||||
ok = setup(OldVerPath, NewName, NewVer, NameVer),
|
ok = setup(OldVerPath, NewName, NewVer, NameVer),
|
||||||
|
|
||||||
%% Build the package
|
%% Build the package
|
||||||
run_systools(NameVer, NewName),
|
run_systools(NameVer, NewName),
|
||||||
|
|
||||||
%% Boot file changes
|
%% Boot file changes
|
||||||
{ok, _} = boot_files(NewVer, NewName),
|
{ok, _} = boot_files(NewVer, NewName),
|
||||||
|
|
||||||
%% Extract upgrade and tar it back up with changes
|
%% Extract upgrade and tar it back up with changes
|
||||||
make_tar(NameVer),
|
make_tar(NameVer),
|
||||||
|
|
||||||
%% Clean up files that systools created
|
%% Clean up files that systools created
|
||||||
ok = cleanup(NameVer, NewName, NewVer),
|
ok = cleanup(NameVer, NewName, NewVer),
|
||||||
|
|
||||||
%% Restore original path
|
%% Restore original path
|
||||||
true = code:set_path(OrigPath),
|
true = code:set_path(OrigPath),
|
||||||
|
|
||||||
ok
|
ok.
|
||||||
end.
|
|
||||||
|
|
||||||
%% internal api
|
%% ===================================================================
|
||||||
|
%% Internal functions
|
||||||
|
%% ==================================================================
|
||||||
|
|
||||||
run_checks(OldVerPath, ReltoolFile) ->
|
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]),
|
"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]),
|
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]),
|
"Release directory doesn't exist (~p)~n", [NamePath]),
|
||||||
|
|
||||||
{NewName, NewVer} = get_release_version(Name, NamePath),
|
{NewName, NewVer} = rebar_rel_utils:get_rel_release_info(Name, NamePath),
|
||||||
{OldName, OldVer} = get_release_version(Name, OldVerPath),
|
{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", []),
|
"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", []),
|
"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", []),
|
"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", []),
|
"Reltool and .rel versions do not match~n", []),
|
||||||
|
|
||||||
{NewName, NewVer}.
|
{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) ->
|
setup(OldVerPath, NewName, NewVer, NameVer) ->
|
||||||
NewRelPath = filename:join([".", NewName]),
|
NewRelPath = filename:join([".", NewName]),
|
||||||
Src = filename:join([NewRelPath, "releases",
|
Src = filename:join([NewRelPath, "releases",
|
||||||
|
|
|
@ -38,9 +38,6 @@
|
||||||
abort/2,
|
abort/2,
|
||||||
escript_foldl/3,
|
escript_foldl/3,
|
||||||
find_executable/1,
|
find_executable/1,
|
||||||
get_reltool_release_info/1,
|
|
||||||
get_rel_release_info/2,
|
|
||||||
get_previous_release_path/0,
|
|
||||||
prop_check/3]).
|
prop_check/3]).
|
||||||
|
|
||||||
-include("rebar.hrl").
|
-include("rebar.hrl").
|
||||||
|
@ -155,38 +152,6 @@ find_executable(Name) ->
|
||||||
"\"" ++ filename:nativename(Path) ++ "\""
|
"\"" ++ filename:nativename(Path) ++ "\""
|
||||||
end.
|
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
|
%% Helper function for checking values and aborting when needed
|
||||||
prop_check(true, _, _) -> true;
|
prop_check(true, _, _) -> true;
|
||||||
prop_check(false, Msg, Args) -> ?ABORT(Msg, Args).
|
prop_check(false, Msg, Args) -> ?ABORT(Msg, Args).
|
||||||
|
|
Loading…
Reference in a new issue