Skip to content

Commit

Permalink
'fetch' now supports version modifier atleast:
Browse files Browse the repository at this point in the history
  • Loading branch information
yrashk committed Feb 1, 2011
1 parent 18d6d21 commit c8a584a
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 101 deletions.
204 changes: 104 additions & 100 deletions src/agner_main.erl
Expand Up @@ -331,116 +331,120 @@ handle_command(fetch, Opts) ->
undefined ->
io:format("ERROR: Package name required.~n");
Package ->
Version = proplists:get_value(version, Opts),
Directory = filename:absname(proplists:get_value(directory, Opts, Package)),
Spec =
case proplists:get_value(spec, Opts) of
undefined ->
Spec0 = agner:spec(Package, Version),
{ok, RepoServer} = agner_repo_server:create(Package, agner_spec:list_to_version(Package, Version)),

os:putenv("AGNER_PACKAGE_REPO",agner_repo_server:file(RepoServer,"")),
Spec0;
File ->
{ok, T} = file:consult(File),
os:putenv("AGNER_PACKAGE_REPO",proplists:get_value(package_path, Opts, filename:absname("."))),
T
end,

io:format("~p~n",[agner:fetch(Spec,Version,
Directory)]),

Requires = proplists:get_value(requires, Spec, []),
DepsDir = filename:join(Directory, proplists:get_value(deps_dir, Spec, "deps")),
lists:foreach(fun ({ReqName, ReqVersion}) ->
io:format("[Building dependency: ~s -v ~s]~n", [ReqName, ReqVersion]),
handle_command(fetch, [{package, ReqName},{version, ReqVersion},
{directory, filename:join(DepsDir,ReqName)}|
proplists:delete(spec,Opts)]);
(ReqName) when is_list(ReqName) ->
io:format("[Building dependency: ~s]~n", [ReqName]),
handle_command(fetch, [{package, ReqName},{version, "@master"},
{directory, filename:join(DepsDir,ReqName)}|
proplists:delete(spec, Opts)])
end, Requires),

case proplists:get_value(caveats, Spec) of
case agner_spec:version_to_list(agner_spec:list_to_version(Package, proplists:get_value(version, Opts))) of
undefined ->
ignore;
Caveats when is_list(Caveats) ->
io:format("ERROR: No version satisfy criteria of ~s~n",[proplists:get_value(version, Opts)]);
Version ->
Directory = filename:absname(proplists:get_value(directory, Opts, Package)),
Spec =
case proplists:get_value(spec, Opts) of
undefined ->
Spec0 = agner:spec(Package, Version),
{ok, RepoServer} = agner_repo_server:create(Package, agner_spec:list_to_version(Package, Version)),

os:putenv("AGNER_PACKAGE_REPO",agner_repo_server:file(RepoServer,"")),
Spec0;
File ->
{ok, T} = file:consult(File),
os:putenv("AGNER_PACKAGE_REPO",proplists:get_value(package_path, Opts, filename:absname("."))),
T
end,

io:format("~p~n",[agner:fetch(Spec,Version,
Directory)]),

Requires = proplists:get_value(requires, Spec, []),
DepsDir = filename:join(Directory, proplists:get_value(deps_dir, Spec, "deps")),
lists:foreach(fun ({ReqName, ReqVersion}) ->
io:format("[Building dependency: ~s -v ~s]~n", [ReqName, ReqVersion]),
handle_command(fetch, [{package, ReqName},{version, ReqVersion},
{directory, filename:join(DepsDir,ReqName)}|
proplists:delete(spec,Opts)]);
(ReqName) when is_list(ReqName) ->
io:format("[Building dependency: ~s]~n", [ReqName]),
handle_command(fetch, [{package, ReqName},{version, "@master"},
{directory, filename:join(DepsDir,ReqName)}|
proplists:delete(spec, Opts)])
end, Requires),

case proplists:get_value(caveats, Spec) of
undefined ->
ignore;
Caveats when is_list(Caveats) ->
io:format("=== CAVEATS ===~n~n~s~n~n",[Caveats])
end,

case proplists:get_value(build, Opts) of
true ->
case proplists:get_value(rebar_compatible, Spec) of
true ->
io:format("[Building...]~n"),
{ok, Cwd} = file:get_cwd(),
file:set_cwd(Directory),
RebarCommands = proplists:get_value(rebar_commands, Spec,["get-deps","compile"]),
rebar:main(RebarCommands),
file:set_cwd(Cwd);
_ ->
ignore
end,
case proplists:get_value(build_command, Spec) of
undefined ->

case proplists:get_value(build, Opts) of
true ->
case proplists:get_value(rebar_compatible, Spec) of
true ->
ignore;
io:format("[Building...]~n"),
{ok, Cwd} = file:get_cwd(),
file:set_cwd(Directory),
RebarCommands = proplists:get_value(rebar_commands, Spec,["get-deps","compile"]),
rebar:main(RebarCommands),
file:set_cwd(Cwd);
_ ->
io:format("ERROR: No build_command specified, can't build this package")
end;
Command ->
io:format("[Building (output will be shown when done)...]~n"),
{ok, Cwd0} = file:get_cwd(),
file:set_cwd(Directory),
io:format("~s~n",[os:cmd(Command)]),
file:set_cwd(Cwd0)
end,
case proplists:get_value(addpath, Opts) of
true ->
{ok, F} = file:open(filename:join(os:getenv("HOME"),".erlang"),
[append]),
file:write(F, io_lib:format("code:add_patha(\"~s/ebin\"). %% {agner, ~s}~n", [Directory, Package])),
file:close(F);
false ->
ignore
end,
case proplists:get_value(install, Opts) of
false ->
ignore;
true ->
filelib:ensure_dir(filename:join([os:getenv("AGNER_PREFIX"),"packages"]) ++ "/"),
InstallPrefix = filename:join([os:getenv("AGNER_PREFIX"),"packages",Package ++ "-" ++ Version]),
os:cmd("rm -rf " ++ InstallPrefix),
ok = filelib:ensure_dir(InstallPrefix ++ "/"),
os:putenv("AGNER_INSTALL_PREFIX", InstallPrefix),
case proplists:get_value(install_command, Spec) of
ignore
end,
case proplists:get_value(build_command, Spec) of
undefined ->
io:format("ERROR: No install_command specified, can't install this package");
ICommand ->
io:format("[Installing (output will be shown when done)...]~n"),
{ok, Cwd1} = file:get_cwd(),
case proplists:get_value(rebar_compatible, Spec) of
true ->
ignore;
_ ->
io:format("ERROR: No build_command specified, can't build this package")
end;
Command ->
io:format("[Building (output will be shown when done)...]~n"),
{ok, Cwd0} = file:get_cwd(),
file:set_cwd(Directory),
io:format("~s~n",[os:cmd(ICommand)]),
file:set_cwd(Cwd1),
case proplists:get_value(bin_files, Spec) of
io:format("~s~n",[os:cmd(Command)]),
file:set_cwd(Cwd0)
end,
case proplists:get_value(addpath, Opts) of
true ->
{ok, F} = file:open(filename:join(os:getenv("HOME"),".erlang"),
[append]),
file:write(F, io_lib:format("code:add_patha(\"~s/ebin\"). %% {agner, ~s}~n", [Directory, Package])),
file:close(F);
false ->
ignore
end,
case proplists:get_value(install, Opts) of
false ->
ignore;
true ->
filelib:ensure_dir(filename:join([os:getenv("AGNER_PREFIX"),"packages"]) ++ "/"),
InstallPrefix = filename:join([os:getenv("AGNER_PREFIX"),"packages",Package ++ "-" ++ Version]),
os:cmd("rm -rf " ++ InstallPrefix),
ok = filelib:ensure_dir(InstallPrefix ++ "/"),
os:putenv("AGNER_INSTALL_PREFIX", InstallPrefix),
case proplists:get_value(install_command, Spec) of
undefined ->
ignore;
Files ->
lists:foreach(fun (File) ->
Symlink = filename:join(os:getenv("AGNER_BIN"),filename:basename(File)),
File1 = filename:join([InstallPrefix,File]),
file:delete(Symlink),
ok = file:make_symlink(File1, Symlink)
end, Files)
io:format("ERROR: No install_command specified, can't install this package");
ICommand ->
io:format("[Installing (output will be shown when done)...]~n"),
{ok, Cwd1} = file:get_cwd(),
file:set_cwd(Directory),
io:format("~s~n",[os:cmd(ICommand)]),
file:set_cwd(Cwd1),
case proplists:get_value(bin_files, Spec) of
undefined ->
ignore;
Files ->
lists:foreach(fun (File) ->
Symlink = filename:join(os:getenv("AGNER_BIN"),filename:basename(File)),
File1 = filename:join([InstallPrefix,File]),
file:delete(Symlink),
ok = file:make_symlink(File1, Symlink)
end, Files)
end
end
end
end;
false ->
ignore
end;
false ->
ignore
end
end
end;

Expand Down
4 changes: 3 additions & 1 deletion src/agner_spec.erl
Expand Up @@ -26,7 +26,7 @@ parse(S) ->

list_to_version(Name, "atleast:" ++ Version) ->
case lists:reverse(lists:dropwhile(fun(V) ->
V < {tag, Version}
V < {release, Version}
end, lists:usort(agner:versions(Name)))) of
[] ->
no_such_version;
Expand All @@ -41,6 +41,8 @@ list_to_version(_, Version) ->

-spec version_to_list(agner_package_version()) -> string().

version_to_list(no_such_version) ->
undefined;
version_to_list({flavour, Version}) ->
"@" ++ Version;
version_to_list({release, Version}) ->
Expand Down

0 comments on commit c8a584a

Please sign in to comment.