diff options
Diffstat (limited to 'src/rcl_depsolver.erl')
-rw-r--r-- | src/rcl_depsolver.erl | 69 |
1 files changed, 36 insertions, 33 deletions
diff --git a/src/rcl_depsolver.erl b/src/rcl_depsolver.erl index 4d61d6c..e74cf3b 100644 --- a/src/rcl_depsolver.erl +++ b/src/rcl_depsolver.erl @@ -88,6 +88,7 @@ add_package_version/3, add_package_version/4, parse_version/1, + is_valid_constraint/1, filter_packages/2]). %% Internally Exported API. This should *not* be used outside of the rcl_depsolver @@ -250,7 +251,7 @@ solve({?MODULE, DepGraph0}, RawGoals) end end. -%% Parse a string version into a tuple based version +%% @doc Parse a string version into a tuple based version -spec parse_version(raw_vsn() | vsn()) -> vsn(). parse_version(RawVsn) when erlang:is_list(RawVsn); @@ -260,6 +261,40 @@ parse_version(Vsn) when erlang:is_tuple(Vsn) -> Vsn. +%% @doc check that a specified constraint is a valid constraint. +-spec is_valid_constraint(constraint()) -> boolean(). +is_valid_constraint(Pkg) when is_atom(Pkg) orelse is_binary(Pkg) -> + true; +is_valid_constraint({_Pkg, Vsn}) when is_tuple(Vsn) -> + true; +is_valid_constraint({_Pkg, Vsn, '='}) when is_tuple(Vsn) -> + true; +is_valid_constraint({_Pkg, _LVsn, gte}) -> + true; +is_valid_constraint({_Pkg, _LVsn, '>='}) -> + true; +is_valid_constraint({_Pkg, _LVsn, lte}) -> + true; +is_valid_constraint({_Pkg, _LVsn, '<='}) -> + true; +is_valid_constraint({_Pkg, _LVsn, gt}) -> + true; +is_valid_constraint({_Pkg, _LVsn, '>'}) -> + true; +is_valid_constraint({_Pkg, _LVsn, lt}) -> + true; +is_valid_constraint({_Pkg, _LVsn, '<'}) -> + true; +is_valid_constraint({_Pkg, _LVsn, pes}) -> + true; +is_valid_constraint({_Pkg, _LVsn, '~>'}) -> + true; +is_valid_constraint({_Pkg, _LVsn1, _LVsn2, between}) -> + true; +is_valid_constraint(_InvalidConstraint) -> + false. + + %% @doc given a list of package name version pairs, and a list of constraints %% return every member of that list that matches all constraints. -spec filter_packages([{pkg_name(), raw_vsn()}], [raw_constraint()]) -> @@ -422,38 +457,6 @@ dep_pkg({Pkg, _Vsn1, _Vsn2, _}) -> dep_pkg(Pkg) when is_atom(Pkg) orelse is_binary(Pkg) -> Pkg. --spec is_valid_constraint(constraint()) -> boolean(). -is_valid_constraint(Pkg) when is_atom(Pkg) orelse is_binary(Pkg) -> - true; -is_valid_constraint({_Pkg, Vsn}) when is_tuple(Vsn) -> - true; -is_valid_constraint({_Pkg, Vsn, '='}) when is_tuple(Vsn) -> - true; -is_valid_constraint({_Pkg, _LVsn, gte}) -> - true; -is_valid_constraint({_Pkg, _LVsn, '>='}) -> - true; -is_valid_constraint({_Pkg, _LVsn, lte}) -> - true; -is_valid_constraint({_Pkg, _LVsn, '<='}) -> - true; -is_valid_constraint({_Pkg, _LVsn, gt}) -> - true; -is_valid_constraint({_Pkg, _LVsn, '>'}) -> - true; -is_valid_constraint({_Pkg, _LVsn, lt}) -> - true; -is_valid_constraint({_Pkg, _LVsn, '<'}) -> - true; -is_valid_constraint({_Pkg, _LVsn, pes}) -> - true; -is_valid_constraint({_Pkg, _LVsn, '~>'}) -> - true; -is_valid_constraint({_Pkg, _LVsn1, _LVsn2, between}) -> - true; -is_valid_constraint(_InvalidConstraint) -> - false. - -spec add_constraint(pkg_name(), vsn(), [constraint()],constraint()) -> ordered_constraints(). add_constraint(SrcPkg, SrcVsn, PkgsConstraints, PkgConstraint) -> case is_valid_constraint(PkgConstraint) of |