Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:ErlangPro
rpm-build-erlang
erlang_req.erl
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File erlang_req.erl of Package rpm-build-erlang
%% Copyright (C) 2008, 2012 Led <led@massivesolutions.co.uk> Massive Solutions Ltd. %% %% This program is free software; you can redistribute it and/or modify %% it under the terms of the GNU General Public License as published by %% the Free Software Foundation; either version 3 of the License, or %% (at your option) any later version. %% %% This program is distributed in the hope that it will be useful, %% but WITHOUT ANY WARRANTY; without even the implied warranty of %% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the %% GNU General Public License for more details. %% %% You should have received a copy of the GNU General Public License %% along with this program; if not, write to the Free Software %% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA %% -module(erlang_req). -vsn('0.8.5'). -author('Led <led@massivesolutions.co.uk>'). -export([main/1, start/0]). -define(ERROR_NO_APP_FILE, 4). -define(ERROR_READ_APP_FILE, 5). -define(ERROR_UNKNOWN_FILE, 6). -define(ERROR_OPEN_APP_FILE, 7). -define(ERROR_UNKNOWN, 255). warning(S) -> io:put_chars(standard_error, "WARNING: " ++ S ++ '\n'). err0(S, Arg) -> warning(S ++ [' '|Arg]), {ok, []}. err1(S, Arg) -> warning(S ++ " '" ++ Arg ++ $'). err(Error, Args) -> case Error of missing_chunk -> err1("Missing chunk 'imports' (ImpT) in module", Args); key_missing_or_invalid -> err1("Key missing or invalid in module", Args); no_beam_file -> err0("No Erlang beam file", Args); open_app_file -> err0("Can't open application file", Args); read_app_file -> err0("Can't read application file", Args); no_app_file -> err0("No Erlang application file", Args); beam_unexpected -> err0("Unexpected error while processing beam file", Args); app_unexpected -> err0("Unexpected error while processing application file", Args); unknown_file -> err0("Unknown file", Args); unexpected -> err0("Unexpected error while processing file", Args); _ -> warning("Unrecognized error"), {ok, []} end. get_skiplist(V) when is_list(V) -> case os:getenv(V) of false -> ordsets:new(); Val -> ordsets:from_list(lists:map(fun(S) -> list_to_atom(S) end, string:tokens(Val, ", "))) end. get_mod_skiplist() -> get_skiplist("RPM_ERLANG_REQ_MODULES_SKIPLIST"). get_app_skiplist() -> get_skiplist("RPM_ERLANG_REQ_APPS_SKIPLIST"). requires_app(Apps) -> requires_app(Apps, ordsets:new()). requires_app([], Apps) -> ordsets:to_list(Apps); requires_app([App|L], Apps) -> requires_app(L, case file:open(App, [read]) of {error, _} -> err(open_app_file, App), Apps; {ok, F} -> case io:read(F, '') of {ok, {application, _, List}} -> case lists:keysearch(applications, 1, List) of false -> Apps; {value, {applications, A}} -> ordsets:union(Apps, ordsets:from_list(A)) end; eof -> err(no_app_file, App), Apps; {error, _} -> err(read_app_file, App), Apps end end ). requires_beam(Mods) -> GetMod = fun({Mod, _, _}) -> [M0|_] = string:tokens(atom_to_list(Mod), ":"), list_to_atom(M0) end, lists:foldl( fun(M, L) -> case beam_lib:chunks(M, [imports]) of {ok, {_, [{imports, IF}]}} when is_list(IF) -> ordsets:union(L, ordsets:from_list(lists:map(GetMod, IF))); {error, beam_lib, Reason} -> case Reason of {missing_chunk, F, _} -> err(missing_chunk, F); {key_missing_or_invalid, F, _} -> err(key_missing_or_invalid, F); _ -> err(beam_unexpected, M) end, L end end, ordsets:new(), Mods ). subtract(S, Files, E) -> ordsets:subtract(S, ordsets:from_list(lists:map(fun(F) -> list_to_atom(filename:basename(F, E)) end, Files))). requires({Apps, Mods}) -> {subtract(requires_app(Apps), Apps, ".app"), subtract(requires_beam(Mods), Mods, ".beam")}. read_lines() -> read_line([], []). read_line(Apps, Mods) -> case io:fread('', "~s") of eof -> {Apps, Mods}; {error, What} -> warning(What), halt(?ERROR_UNKNOWN); {ok, S} -> F = string:strip(S, right, $\n), case filename:extension(F) of ".beam" -> A = Apps, M = [F|Mods]; ".app" -> A = [F|Apps], M = Mods end, read_line(A, M) end. write_req(S, E) -> io:fwrite("erlang_~s(~s)~n", [E, S]). write_requires_app(App) -> write_req(App, "app"). write_requires_mod(Mod) -> write_req(Mod, "mod"). write_requires({Apps, Mods}) -> lists:foreach(fun(A) -> write_requires_app(A) end, ordsets:subtract(Apps, get_app_skiplist())), lists:foreach(fun(M) -> write_requires_mod(M) end, ordsets:subtract(Mods, get_mod_skiplist())). main(_) -> write_requires(requires(read_lines())). start() -> main(none), halt().
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor