list_deps/0
This commit is contained in:
parent
3410bbbffb
commit
aaf4ec124c
@ -99,6 +99,10 @@ do(["init", "app", PackageString]) ->
|
|||||||
do(["init", "lib", PackageString]) ->
|
do(["init", "lib", PackageString]) ->
|
||||||
ok = compatibility_check([unix]),
|
ok = compatibility_check([unix]),
|
||||||
done(zx_local:initialize(lib, PackageString));
|
done(zx_local:initialize(lib, PackageString));
|
||||||
|
do(["list", "deps"]) ->
|
||||||
|
done(zx_local:list_deps());
|
||||||
|
do(["list", "deps", PackageString]) ->
|
||||||
|
done(zx_local:list_deps(PackageString));
|
||||||
do(["install", PackageFile]) ->
|
do(["install", PackageFile]) ->
|
||||||
done(zx_local:assimilate(PackageFile));
|
done(zx_local:assimilate(PackageFile));
|
||||||
do(["set", "dep", PackageString]) ->
|
do(["set", "dep", PackageString]) ->
|
||||||
|
|||||||
@ -10,9 +10,9 @@
|
|||||||
-copyright("Craig Everett <zxq9@zxq9.com>").
|
-copyright("Craig Everett <zxq9@zxq9.com>").
|
||||||
-license("GPL-3.0").
|
-license("GPL-3.0").
|
||||||
|
|
||||||
-export([initialize/2, assimilate/1, set_dep/1, set_version/1,
|
-export([initialize/2, assimilate/1, set_version/1,
|
||||||
list_realms/0, list_packages/1, list_versions/1,
|
list_realms/0, list_packages/1, list_versions/1,
|
||||||
drop_dep/1, verup/1, package/1,
|
set_dep/1, list_deps/0, list_deps/1, drop_dep/1, verup/1, package/1,
|
||||||
add_realm/1, drop_realm/1,
|
add_realm/1, drop_realm/1,
|
||||||
takeover/1, abdicate/1,
|
takeover/1, abdicate/1,
|
||||||
create_plt/0, dialyze/0,
|
create_plt/0, dialyze/0,
|
||||||
@ -286,65 +286,6 @@ assimilate2(CWD, PackageID) ->
|
|||||||
log(info, Message, [PackageString]).
|
log(info, Message, [PackageString]).
|
||||||
|
|
||||||
|
|
||||||
-spec set_dep(PackageString :: string()) -> zx:outcome().
|
|
||||||
%% @private
|
|
||||||
%% Set a dependency in the current project. If the project currently has a dependency
|
|
||||||
%% on the same package then the version of that dependency is updated to reflect that
|
|
||||||
%% in the PackageString argument.
|
|
||||||
|
|
||||||
set_dep(PackageString) ->
|
|
||||||
case zx_lib:package_id(PackageString) of
|
|
||||||
{ok, {_, _, {_, _, z}}} ->
|
|
||||||
Message =
|
|
||||||
"Incomplete version tuple. Dependencies must be fully specified.",
|
|
||||||
{error, Message, 22};
|
|
||||||
{ok, PackageID} ->
|
|
||||||
set_dep2(PackageID);
|
|
||||||
{error, invalid_package_string} ->
|
|
||||||
{error, "Invalid package string", 22}
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
-spec set_dep2(zx:package_id()) -> ok.
|
|
||||||
|
|
||||||
set_dep2(PackageID) ->
|
|
||||||
{ok, Meta} = zx_lib:read_project_meta(),
|
|
||||||
Deps = maps:get(deps, Meta),
|
|
||||||
case lists:member(PackageID, Deps) of
|
|
||||||
true -> ok;
|
|
||||||
false -> set_dep(PackageID, Deps, Meta)
|
|
||||||
end.
|
|
||||||
|
|
||||||
|
|
||||||
-spec set_dep(PackageID, Deps, Meta) -> ok
|
|
||||||
when PackageID :: zx:package_id(),
|
|
||||||
Deps :: [zx:package_id()],
|
|
||||||
Meta :: [term()].
|
|
||||||
%% @private
|
|
||||||
%% Given the PackageID, list of Deps and the current contents of the project Meta, add
|
|
||||||
%% or update Deps to include (or update) Deps to reflect a dependency on PackageID, if
|
|
||||||
%% such a dependency is not already present. Then write the project meta back to its
|
|
||||||
%% file and exit.
|
|
||||||
|
|
||||||
set_dep(PackageID = {Realm, Name, NewVersion}, Deps, Meta) ->
|
|
||||||
ExistingPackageIDs = fun({R, N, _}) -> {R, N} == {Realm, Name} end,
|
|
||||||
NewDeps =
|
|
||||||
case lists:partition(ExistingPackageIDs, Deps) of
|
|
||||||
{[{Realm, Name, OldVersion}], Rest} ->
|
|
||||||
Message = "Updating dep ~ts to ~ts",
|
|
||||||
{ok, OldPS} = zx_lib:package_string({Realm, Name, OldVersion}),
|
|
||||||
{ok, NewPS} = zx_lib:package_string({Realm, Name, NewVersion}),
|
|
||||||
ok = log(info, Message, [OldPS, NewPS]),
|
|
||||||
[PackageID | Rest];
|
|
||||||
{[], Deps} ->
|
|
||||||
{ok, PackageString} = zx_lib:package_string(PackageID),
|
|
||||||
ok = log(info, "Adding dep ~ts", [PackageString]),
|
|
||||||
[PackageID | Deps]
|
|
||||||
end,
|
|
||||||
NewMeta = maps:put(deps, NewDeps, Meta),
|
|
||||||
zx_lib:write_project_meta(NewMeta).
|
|
||||||
|
|
||||||
|
|
||||||
-spec set_version(VersionString) -> zx:outcome()
|
-spec set_version(VersionString) -> zx:outcome()
|
||||||
when VersionString :: string().
|
when VersionString :: string().
|
||||||
%% @private
|
%% @private
|
||||||
@ -501,6 +442,103 @@ add_realm2(Data) ->
|
|||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
-spec set_dep(PackageString :: string()) -> zx:outcome().
|
||||||
|
%% @private
|
||||||
|
%% Set a dependency in the current project. If the project currently has a dependency
|
||||||
|
%% on the same package then the version of that dependency is updated to reflect that
|
||||||
|
%% in the PackageString argument.
|
||||||
|
|
||||||
|
set_dep(PackageString) ->
|
||||||
|
case zx_lib:package_id(PackageString) of
|
||||||
|
{ok, {_, _, {_, _, z}}} ->
|
||||||
|
Message =
|
||||||
|
"Incomplete version tuple. Dependencies must be fully specified.",
|
||||||
|
{error, Message, 22};
|
||||||
|
{ok, PackageID} ->
|
||||||
|
set_dep2(PackageID);
|
||||||
|
{error, invalid_package_string} ->
|
||||||
|
{error, "Invalid package string", 22}
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
-spec set_dep2(zx:package_id()) -> ok.
|
||||||
|
|
||||||
|
set_dep2(PackageID) ->
|
||||||
|
{ok, Meta} = zx_lib:read_project_meta(),
|
||||||
|
Deps = maps:get(deps, Meta),
|
||||||
|
case lists:member(PackageID, Deps) of
|
||||||
|
true -> ok;
|
||||||
|
false -> set_dep(PackageID, Deps, Meta)
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
-spec set_dep(PackageID, Deps, Meta) -> ok
|
||||||
|
when PackageID :: zx:package_id(),
|
||||||
|
Deps :: [zx:package_id()],
|
||||||
|
Meta :: [term()].
|
||||||
|
%% @private
|
||||||
|
%% Given the PackageID, list of Deps and the current contents of the project Meta, add
|
||||||
|
%% or update Deps to include (or update) Deps to reflect a dependency on PackageID, if
|
||||||
|
%% such a dependency is not already present. Then write the project meta back to its
|
||||||
|
%% file and exit.
|
||||||
|
|
||||||
|
set_dep(PackageID = {Realm, Name, NewVersion}, Deps, Meta) ->
|
||||||
|
ExistingPackageIDs = fun({R, N, _}) -> {R, N} == {Realm, Name} end,
|
||||||
|
NewDeps =
|
||||||
|
case lists:partition(ExistingPackageIDs, Deps) of
|
||||||
|
{[{Realm, Name, OldVersion}], Rest} ->
|
||||||
|
Message = "Updating dep ~ts to ~ts",
|
||||||
|
{ok, OldPS} = zx_lib:package_string({Realm, Name, OldVersion}),
|
||||||
|
{ok, NewPS} = zx_lib:package_string({Realm, Name, NewVersion}),
|
||||||
|
ok = log(info, Message, [OldPS, NewPS]),
|
||||||
|
[PackageID | Rest];
|
||||||
|
{[], Deps} ->
|
||||||
|
{ok, PackageString} = zx_lib:package_string(PackageID),
|
||||||
|
ok = log(info, "Adding dep ~ts", [PackageString]),
|
||||||
|
[PackageID | Deps]
|
||||||
|
end,
|
||||||
|
NewMeta = maps:put(deps, NewDeps, Meta),
|
||||||
|
zx_lib:write_project_meta(NewMeta).
|
||||||
|
|
||||||
|
|
||||||
|
-spec list_deps() -> zx:outcome().
|
||||||
|
%% @private
|
||||||
|
%% List deps in the current (local) project directory.
|
||||||
|
%% This is very different from list_deps/1, which makes a remote query to a Zomp
|
||||||
|
%% realm to discover deps for potentially unknown or locally uncached packages.
|
||||||
|
|
||||||
|
list_deps() ->
|
||||||
|
case zx_lib:read_project_meta() of
|
||||||
|
{ok, Meta} ->
|
||||||
|
Deps = maps:get(deps, Meta),
|
||||||
|
Print =
|
||||||
|
fun(P) ->
|
||||||
|
{ok, PackageString} = zx_lib:package_string(P),
|
||||||
|
io:format("~ts~n", [PackageString])
|
||||||
|
end,
|
||||||
|
lists:foreach(Print, Deps);
|
||||||
|
Error ->
|
||||||
|
Error
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
-spec list_deps(zx:package_id()) -> zx:outcome().
|
||||||
|
%% @private
|
||||||
|
%% List deps for the specified package. This quite often requires a query to a Zomp
|
||||||
|
%% realm over the network, but not if the referenced package happens to be cached
|
||||||
|
%% locally.
|
||||||
|
|
||||||
|
list_deps(PackageString) ->
|
||||||
|
case zx_lib:package_id(PackageString) of
|
||||||
|
{ok, {_, _, {_, _, z}}} ->
|
||||||
|
{error, "Packages must be fully specified; no partial versions.", 22};
|
||||||
|
{ok, PackageID} ->
|
||||||
|
log(info, "Phooey! list_deps(~tp) isn't yet implemented!", [PackageID]);
|
||||||
|
{error, invalid_package_string} ->
|
||||||
|
{error, "Invalid package string.", 22}
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
-spec drop_dep(zx:package_id()) -> ok.
|
-spec drop_dep(zx:package_id()) -> ok.
|
||||||
%% @private
|
%% @private
|
||||||
%% Remove the indicate dependency from the local project's zomp.meta record.
|
%% Remove the indicate dependency from the local project's zomp.meta record.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user