Created
June 27, 2013 20:28
-
-
Save jcomellas/5880102 to your computer and use it in GitHub Desktop.
rebar script to dynamically set the CloudI path in rebar.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% Script that add the CloudI Erlang applications from an installed instance to | |
%% rebar's lib_dirs configuration setting (code path). | |
%% If the 'CLOUDI_DIR' environment variable is set, then we add its "lib" | |
%% subdirectory to the code path. If not, we check for the CloudI directory in the | |
%% /usr/local/lib path. | |
LibDir = case os:getenv("CLOUDI_DIR") of | |
Dir when Dir =:= false; Dir =:= "" -> | |
%% Look for the CloudI directory in /usr/local/lib | |
case os:type() of | |
{unix, _Osname} -> | |
case filelib:wildcard("/usr/local/lib/cloudi*") of | |
[Dir1] -> | |
LibDir1 = filename:join([Dir1, "lib"]), | |
io:format("Adding CloudI dir ~p to rebar lib_dirs~n", [LibDir1]), | |
LibDir1; | |
[_ | _] = Dirs1 -> | |
%% When there are multiple CloudI directories, | |
%% always choose the latest one | |
SortedDirs = lists:sort(fun (D1, D2) -> D1 > D2 end, Dirs1), | |
LibDir1 = filename:join([hd(SortedDirs), "lib"]), | |
io:format("Adding CloudI dir ~p to rebar lib_dirs (out of ~p)~n", | |
[LibDir1, [filename:join([SortedDir, "lib"]) || SortedDir <- SortedDirs]]), | |
LibDir1; | |
[] -> | |
undefined | |
end; | |
_ -> | |
%% Unsupported operating system, most probably Windows | |
undefined | |
end; | |
Dir -> | |
LibDir1 = filename:join([Dir, "lib"]), | |
io:format("Adding CloudI dir ~p from 'CLOUDI_DIR' env var to rebar lib_dirs~n", [LibDir1]), | |
LibDir1 | |
end, | |
if | |
LibDir =/= undefined -> | |
case lists:keyfind(lib_dirs, 1, CONFIG) of | |
{lib_dirs, LibDirs} -> | |
NewLibDirs = LibDirs ++ [LibDir], | |
lists:keystore(lib_dirs, 1, CONFIG, {lib_dirs, NewLibDirs}); | |
false -> | |
[{lib_dirs, [LibDir]} | CONFIG] | |
end; | |
true -> | |
io:format("WARNING: CloudI was not found; the project may not compile properly without it~n", []), | |
CONFIG | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment