aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric <[email protected]>2012-10-26 17:21:54 -0500
committerJordan Wilberding <[email protected]>2012-10-30 09:54:42 -0600
commit92dcabc086fbb88901d9b8549c07c702f977bd73 (patch)
tree063f4e10a66c978c2c3fed198d2bb97e17bf24c8
parent0ffe8cd1a2a4e039a48d1096fc250b3f6bd3dcd1 (diff)
downloadrelx-92dcabc086fbb88901d9b8549c07c702f977bd73.tar.gz
relx-92dcabc086fbb88901d9b8549c07c702f977bd73.tar.bz2
relx-92dcabc086fbb88901d9b8549c07c702f977bd73.zip
simplify constraint parsing in rcl_release
Signed-off-by: Jordan Wilberding <[email protected]>
-rw-r--r--src/rcl_release.erl106
1 files changed, 67 insertions, 39 deletions
diff --git a/src/rcl_release.erl b/src/rcl_release.erl
index 3b5694d..aa5de72 100644
--- a/src/rcl_release.erl
+++ b/src/rcl_release.erl
@@ -72,9 +72,10 @@
{app_name(), app_vsn(), app_type() | incl_apps()} |
{app_name(), app_vsn(), app_type(), incl_apps()}.
--type application_goal() :: rcl_depsolver:constraint() |
- {rcl_depsolver:constraint(), app_type() | incl_apps()} |
- {rcl_depsolver:constraint(), app_type(), incl_apps()}.
+-type application_constraint() :: rcl_depsolver:constraint() | string() | binary().
+-type application_goal() :: application_constraint()
+ | {application_constraint(), app_type() | incl_apps()}
+ | {application_constraint(), app_type(), incl_apps() | none}.
-type annotations() :: ec_dictionary:dictionary(app_name(),
{app_type(), incl_apps() | none}).
@@ -272,48 +273,75 @@ get_app_info({PkgName, PkgVsn}, World) ->
end, World),
WorldEl.
--spec parse_goal0(application_goal(), {ok, t()} | relcool:error()) ->
- {ok, t()} | relcool:error().
parse_goal0({Constraint0, Annots}, {ok, Release})
- when erlang:is_atom(Annots) ->
- parse_goal1(Release, Constraint0, {Annots, none});
-parse_goal0({Constraint0, Annots}, {ok, Release})
- when erlang:is_list(Annots) ->
- parse_goal1(Release, Constraint0, {none, Annots});
-parse_goal0({Constraint0, AnnotsA, AnnotsB}, {ok, Release}) ->
- parse_goal1(Release, Constraint0, {AnnotsA, AnnotsB});
-parse_goal0(Constraint0, {ok, Release = #release_t{goals=Goals}})
- when erlang:is_atom(Constraint0) ->
- {ok, Release#release_t{goals = [Constraint0 | Goals]}};
-parse_goal0(Constraint0, {ok, Release = #release_t{goals=Goals}})
- when erlang:is_list(Constraint0) ->
- case rcl_goal:parse(Constraint0) of
- {fail, _Detail} ->
- ?RCL_ERROR({failed_to_parse, Constraint0});
+ when Annots =:= permanent;
+ Annots =:= transient;
+ Annots =:= temporary;
+ Annots =:= load;
+ Annots =:= none ->
+ case parse_constraint(Constraint0) of
+ {ok, Constraint1} ->
+ parse_goal1(Release, Constraint1, {Annots, none});
+ Error ->
+ Error
+ end;
+parse_goal0({Constraint0, Annots, Incls}, {ok, Release})
+ when (Annots =:= permanent orelse
+ Annots =:= transient orelse
+ Annots =:= temporary orelse
+ Annots =:= load orelse
+ Annots =:= none),
+ erlang:is_list(Incls) ->
+ case parse_constraint(Constraint0) of
{ok, Constraint1} ->
- {ok, Release#release_t{goals = [Constraint1 | Goals]}}
+ parse_goal1(Release, Constraint1, {Annots, Incls});
+ Error ->
+ Error
+ end;
+parse_goal0(Constraint0, {ok, Release}) ->
+ case parse_constraint(Constraint0) of
+ {ok, Constraint1} ->
+ parse_goal1(Release, Constraint1, {none, none});
+ Error ->
+ Error
end;
parse_goal0(_, E = {error, _}) ->
- E.
+ E;
+parse_goal0(Constraint, _) ->
+ ?RCL_ERROR({invalid_constraint, Constraint}).
--spec parse_goal1(t(), rcl_depsolver:constraint() | string(),
- app_type() | incl_apps() | {app_type(), incl_apps() | none}) ->
- {ok, t()} | relcool:error().
parse_goal1(Release = #release_t{annotations=Annots, goals=Goals},
- Constraint0, NewAnnots) ->
- case rcl_goal:parse(Constraint0) of
- {fail, _} ->
- ?RCL_ERROR({failed_to_parse, Constraint0});
- {ok, Constraint1} ->
- case get_app_name(Constraint1) of
- E1 = {error, _} ->
- E1;
- AppName ->
- {ok,
- Release#release_t{annotations=ec_dictionary:add(AppName, NewAnnots, Annots),
- goals = [Constraint1 | Goals]}}
- end
- end.
+ Constraint, NewAnnots) ->
+ case get_app_name(Constraint) of
+ E1 = {error, _} ->
+ E1;
+ AppName ->
+ {ok,
+ Release#release_t{annotations=ec_dictionary:add(AppName, NewAnnots, Annots),
+ goals = [Constraint | Goals]}}
+ end.
+
+-spec parse_constraint(application_constraint()) ->
+ rcl_depsolver:constraint() | relcool:error().
+parse_constraint(Constraint0)
+ when erlang:is_list(Constraint0); erlang:is_binary(Constraint0) ->
+ case rcl_goal:parse(Constraint0) of
+ {fail, _} ->
+ ?RCL_ERROR({failed_to_parse, Constraint0});
+ {ok, Constraint1} ->
+ {ok, Constraint1}
+ end;
+parse_constraint(Constraint)
+ when erlang:is_tuple(Constraint);
+ erlang:is_atom(Constraint) ->
+ case rcl_depsolver:is_valid_constraint(Constraint) of
+ false ->
+ ?RCL_ERROR({invalid_constraint, Constraint});
+ true ->
+ {ok, Constraint}
+ end;
+parse_constraint(Constraint) ->
+ ?RCL_ERROR({invalid_constraint, Constraint}).
-spec get_app_name(rcl_depsolver:constraint()) ->
AppName::atom() | relcool:error().