⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 systools_make.erl

📁 OTP是开放电信平台的简称
💻 ERL
📖 第 1 页 / 共 5 页
字号:
				     "erts-" ++ EVsn, "bin"]),	    dirp(FromDir),	    ToDir = filename:join("erts-" ++ EVsn, "bin"),	    add_to_tar(Tar, FromDir, ToDir);	_ ->	    ok    end.%%______________________________________________________________________%% Tar functions.open_tar(TarName) ->    case erl_tar:open(TarName, [write, compressed]) of	{ok, Tar} ->	    Tar;	{error, Error} ->	    throw({error,{tar_error, {open, TarName, Error}}})    end.close_tar(Tar) ->    erl_tar:close(Tar).del_tar(Tar, TarName) ->    close_tar(Tar),    del_file(TarName).add_to_tar(Tar, FromFile, ToFile) ->    case erl_tar:add(Tar, FromFile, ToFile, [compressed, dereference]) of	ok -> ok;	{error, Error} ->	    throw({error, {tar_error, {add, FromFile, Error}}})    end.%%______________________________________________________________________%%______________________________________________________________________%% utilities!make_set([]) -> [];make_set([""|T]) -> % Ignore empty items.    make_set(T);make_set([H|T]) ->    [H | [ Y || Y<- make_set(T),		Y =/= H]].to_list(A) when is_atom(A) -> atom_to_list(A);to_list(L)                 -> L.mk_path(Path0) ->    Path1 = map(fun(Dir) when is_atom(Dir) -> atom_to_list(Dir);		   (Dir)                   -> Dir		end, Path0),    systools_lib:get_path(Path1).%% duplicates([Tuple]) -> List of pairs where %%    element(1, T1) == element(1, T2) and  where T1 and T2 are %%    taken from [Tuple]duplicates(X) -> duplicates(keysort(1,X), []).duplicates([H1,H2|T], L) ->     case {element(1,H1),element(1,H2)} of	{X,X} -> duplicates([H2|T],[{H1,H2}|L]);        _     -> duplicates([H2|T],L)    end;duplicates(_, L) -> L.%% read_file(File, Path) -> {ok, Term, FullName} | {error, Error}%% read a file and check the syntax, i.e. that it contains a correct%% Erlang term.read_file(File, Path) ->    case file:path_open(Path, File, read) of	{ok, Stream, FullName} ->	    Return = case systools_lib:read_term_from_stream(Stream, File) of			 {ok, Term} ->			     {ok, Term, FullName};			 Other ->			     Other		     end,	    file:close(Stream),	    Return;	_Other ->	    {error, {not_found, File}}    end.del_file(File) -> file:delete(File).dirp(Dir) ->    case file:read_file_info(Dir) of	{ok, FileInfo} -> FileInfo#file_info.type == directory;	_ ->              false    end.%% Create the include path. Assumptions about the code path is done%% and an include directory is added.%% Add the official include dir for each found application first in%% path !!%% If .../ebin exists in a path an .../include directory is assumed to%% exist at the same level. If .../ebin is not existing the .../include%% directory is assumed anyhow.%% Local includes are added for each application later on.create_include_path(Appls, Path) ->    FoundAppDirs = map(fun({_,A}) -> A#application.dir end, Appls),    map(fun(Dir) ->		case reverse(filename:split(Dir)) of		    ["ebin"|D] ->			filename:join(reverse(D) ++ ["include"]);		    _ ->			filename:join(Dir, "include")		end	end,	FoundAppDirs ++ no_dupl(Path, FoundAppDirs)).no_dupl([Dir|Path], FoundAppDirs) ->    case member(Dir, FoundAppDirs) of	true ->	    no_dupl(Path, FoundAppDirs);	_ ->	    [Dir|no_dupl(Path, FoundAppDirs)]    end;no_dupl([], _) ->    [].is_app_type(permanent) -> true;is_app_type(transient) -> true;is_app_type(temporary) -> true;is_app_type(none) -> true;is_app_type(load) -> true;is_app_type(_) -> false.% check if a term is a string.string_p([H|T]) when is_integer(H), H >= $ , H < 255 ->    string_p(T);string_p([$\n|T]) -> string_p(T);string_p([$\r|T]) -> string_p(T);string_p([$\t|T]) -> string_p(T);string_p([$\v|T]) -> string_p(T);string_p([$\b|T]) -> string_p(T);string_p([$\f|T]) -> string_p(T);string_p([$\e|T]) -> string_p(T);string_p([]) -> true;string_p(_) ->  false.% check if a term is a list of two tuples with the first% element as an atom.t_list_p([{A,_}|T]) when is_atom(A) -> t_list_p(T);t_list_p([])                        -> true;t_list_p(_)                         -> false.% check if a term is a list of atoms or two-tuples with the first% element as an atom.mod_list_p([{A,_}|T]) when is_atom(A) -> mod_list_p(T);mod_list_p([A|T]) when is_atom(A)     -> mod_list_p(T);mod_list_p([])                        -> true;mod_list_p(_)                         -> false.% check if a term is a list of atoms.a_list_p([A|T]) when is_atom(A) -> a_list_p(T);a_list_p([])                    -> true;a_list_p(_)                     -> false.%% Get a key-value tuple flag from a list.get_flag(F,[{F,D}|_]) -> {F,D};get_flag(F,[_|Fs])    -> get_flag(F,Fs);get_flag(_,_)         -> false.%% Check Options for make_scriptcheck_args_script(Args) ->    cas(Args,	{undef, undef, undef, undef, undef, undef, undef, undef, []}). cas([], {_Path,_Sil,_Loc,_Test,_Var,_Mach,_Xref,_XrefApps, X}) ->    X;%%% path ---------------------------------------------------------------cas([{path, P} | Args], {Path, Sil, Loc, Test, Var, Mach, 			 Xref, XrefApps, X}) when is_list(P) ->     case check_path(P) of	ok ->	    cas(Args, {P, Sil, Loc, Test, Var, Mach, Xref, XrefApps,X});	error ->	    cas(Args, {Path, Sil, Loc, Test, Var, Mach, Xref, XrefApps,		       X++[{path,P}]})    end;%%% silent -------------------------------------------------------------cas([silent | Args], {Path, _Sil, Loc, Test, Var, Mach,		      Xref, XrefApps, X}) ->    cas(Args, {Path, silent, Loc, Test, Var, Mach, Xref, XrefApps, X});%%% local --------------------------------------------------------------cas([local | Args], {Path, Sil, _Loc, Test, Var, Mach,		     Xref, XrefApps, X}) ->    cas(Args, {Path, Sil, local, Test, Var, Mach, Xref, XrefApps, X});%%% no_module_tests ----------------------------------------------------cas([no_module_tests | Args], {Path, Sil, Loc, _Test, Var, Mach,			       Xref, XrefApps, X}) ->    cas(Args,	{Path, Sil, Loc, no_module_tests, Var, Mach, Xref, XrefApps,X});%%% variables ----------------------------------------------------------cas([{variables, V} | Args], {Path, Sil, Loc, Test, Var, Mach, 				 Xref, XrefApps, X}) when is_list(V) ->    case check_vars(V) of	ok ->	    cas(Args,		{Path, Sil, Loc, Test, V, Mach, Xref, XrefApps, X});	error ->	    cas(Args, {Path, Sil, Loc, Test, Var, Mach, Xref, XrefApps,		       X++[{variables, V}]})    end;%%% machine ------------------------------------------------------------cas([{machine, M} | Args], {Path, Sil, Loc, Test, Var, Mach, 			    Xref, XrefApps, X}) when is_atom(M) ->    cas(Args, {Path, Sil, Loc, Test, Var, Mach, Xref, XrefApps, X});%%% exref --------------------------------------------------------------cas([exref | Args], {Path, Sil, Loc, Test, Var, Mach,		     _Xref, XrefApps, X})  ->    cas(Args, {Path, Sil, Loc, Test, Var, Mach, exref, XrefApps, X});%%% exref Apps ---------------------------------------------------------cas([{exref, Apps} | Args], {Path, Sil, Loc, Test, Var, Mach, 			     Xref, XrefApps, X}) when is_list(Apps) ->    case check_apps(Apps) of 	ok ->	    cas(Args, {Path, Sil, Loc, Test, Var, Mach, 			     Xref, Apps, X});	error ->	    cas(Args, {Path, Sil, Loc, Test, Var, Mach, 			     Xref, XrefApps, X++[{exref, Apps}]})    end;%%% outdir Dir ---------------------------------------------------------cas([{outdir, Dir} | Args], {Path, Sil, Loc, Test, Var, Mach,			     Xref, XrefApps, X}) when is_list(Dir) ->    cas(Args, {Path, Sil, Loc, Test, Var, Mach, Xref, XrefApps, X});%%% otp_build (secret, not documented) ---------------------------------cas([otp_build | Args], {Path, Sil, Loc, Test, Var, Mach,			 Xref, XrefApps, X}) ->    cas(Args, {Path, Sil, Loc, Test, Var, Mach, Xref, XrefApps, X});%%% ERROR --------------------------------------------------------------cas([Y | Args], {Path, Sil, Loc, Test, Var, Mach, Xref, XrefApps, X}) ->    cas(Args, {Path, Sil, Loc, Test, Var, Mach, Xref, XrefApps,X++[Y]}).%% Check Options for make_tarcheck_args_tar(Args) ->    cat(Args, {undef, undef, undef, undef, undef, undef, undef, undef, undef, undef, []}). cat([], {_Path,_Sil,_Dirs,_Erts,_Test,_Var,_VarTar,_Mach,_Xref,_XrefApps, X}) ->    X;%%% path ---------------------------------------------------------------cat([{path, P} | Args], {Path, Sil, Dirs, Erts, Test, 			 Var, VarTar, Mach, Xref, XrefApps, X}) when is_list(P) ->     case check_path(P) of	ok ->	    cat(Args, {P, Sil, Dirs, Erts, Test, Var, VarTar, Mach, Xref, XrefApps, X});	error ->	    cat(Args, {Path, Sil, Dirs, Erts, Test, 		       Var, VarTar, Mach, Xref, XrefApps, X++[{path,P}]})    end;%%% silent -------------------------------------------------------------cat([silent | Args], {Path, _Sil, Dirs, Erts, Test, Var, VarTar, Mach, Xref, XrefApps, X}) ->    cat(Args, {Path, silent, Dirs, Erts, Test, Var, VarTar, Mach, Xref, XrefApps, X});%%% dirs ---------------------------------------------------------------cat([{dirs, D} | Args], {Path, Sil, Dirs, Erts, Test, 			    Var, VarTar, Mach, Xref, XrefApps, X}) ->    case check_dirs(D) of	ok ->	    cat(Args, {Path, Sil, D, Erts, Test, Var, VarTar, Mach, Xref, XrefApps, X});	error ->	    cat(Args, {Path, Sil, Dirs, Erts, Test, 		       Var, VarTar, Mach, Xref, XrefApps, X++[{dirs, D}]})    end;%%% erts ---------------------------------------------------------------cat([{erts, E} | Args], {Path, Sil, Dirs, _Erts, Test, 			 Var, VarTar, Mach, Xref, XrefApps, X}) when is_list(E)->    cat(Args, {Path, Sil, Dirs, E, Test, Var, VarTar, Mach, Xref, XrefApps, X});%%% no_module_tests ----------------------------------------------------cat([no_module_tests | Args], {Path, Sil, Dirs, Erts, _Test, Var, VarTar, Mach, Xref, XrefApps, X}) ->    cat(Args, {Path, Sil, Dirs, Erts, no_module_tests, Var, VarTar, Mach, 		     Xref, XrefApps, X});%%% variables ----------------------------------------------------------cat([{variables, V} | Args], {Path, Sil, Dirs, Erts, Test, Var, VarTar, Mach, Xref, XrefApps, X}) when is_list(V) ->    case check_vars(V) of	ok ->	    cat(Args, {Path, Sil, Dirs, Erts, Test, V, VarTar, Mach, Xref, XrefApps, X});	error ->	    cat(Args, {Path, Sil, Dirs, Erts, Test, Var, VarTar, Mach, 			     Xref, XrefApps, X++[{variables, V}]})    end;%%% var_tar ------------------------------------------------------------cat([{var_tar, VT} | Args], {Path, Sil, Dirs, Erts, Test, 			    Var, _VarTar, Mach, Xref, XrefApps, X}) when VT == include ->    cat(Args, {Path, Sil, Dirs, Erts, Test, Var, include, Mach, Xref, XrefApps, X});cat([{var_tar, VT} | Args], {Path, Sil, Dirs, Erts, Test, 			    Var, _VarTar, Mach, Xref, XrefApps, X}) when VT == ownfile ->    cat(Args, {Path, Sil, Dirs, Erts, Test, Var, ownfile, Mach, Xref, XrefApps, X});cat([{var_tar, VT} | Args], {Path, Sil, Dirs, Erts, Test, 			    Var, _VarTar, Mach, Xref, XrefApps, X}) when VT == omit ->    cat(Args, {Path, Sil, Dirs, Erts, Test, Var, omit, Mach, Xref, XrefApps, X});%%% machine ------------------------------------------------------------cat([{machine, M} | Args], {Path, Sil, Dirs, Erts, Test, 			    Var, VarTar, Mach, Xref, XrefApps, X}) when is_atom(M) ->    cat(Args, {Path, Sil, Dirs, Erts, Test, Var, VarTar, Mach, Xref, XrefApps, X});%%% exref --------------------------------------------------------------cat([exref | Args], {Path, Sil, Dirs, Erts, Test, Var, VarTar, Mach, _Xref, XrefApps, X})  ->    cat(Args, {Path, Sil, Dirs, Erts, Test, Var, VarTar, Mach, exref, XrefApps, X});%%% exref Apps ---------------------------------------------------------cat([{exref, Apps} | Args], {Path, Sil, Dirs, Erts, Test, Var, VarTar, Mach, Xref, XrefApps, X}) when is_list(Apps) ->    case check_apps(Apps) of 	ok ->	    cat(Args, {Path, Sil, Dirs, Erts, Test, Var, VarTar, Mach, 			     Xref, Apps, X});	error ->	    cat(Args, {Path, Sil, Dirs, Erts, Test, Var, VarTar, Mach, 			     Xref, XrefApps, X++[{exref, Apps}]})    end;%%% outdir Dir ---------------------------------------------------------cat([{outdir, Dir} | Args], {Path, Sil, Dirs, Erts, Test, Var, VarTar, Mach, Xref, XrefApps, X}) when is_list(Dir) ->    cat(Args, {Path, Sil, Dirs, Erts, Test, Var, VarTar, Mach,	       Xref, XrefApps, X});%%% otp_build (secret, not documented) ---------------------------------cat([otp_build | Args], {Path, Sil, Dirs, Erts, Test, Var, VarTar, Mach, Xref, XrefApps, X})  ->    cat(Args, {Path, Sil, Dirs, Erts, Test, Var, VarTar, Mach, Xref, XrefApps, X});%%% ERROR --------------------------------------------------------------cat([Y | Args], {Path, Sil, Dirs, Erts, Test, Var, VarTar, Mach, Xref, XrefApps, X}) ->    cat(Args, {Path, Sil, Dirs, Erts, Test, Var, VarTar, Mach, Xref, XrefApps, X++[Y]}).check_path([]) ->    ok;check_path([H|T]) when is_list(H) ->    check_path(T);check_path([_H|_T]) ->    error.check_dirs([]) ->    ok;check_dirs([H|T]) when is_atom(H) ->    check_dirs(T);check_dirs([_H|_T]) ->    error.check_vars([]) ->    ok;check_vars([{Name, Dir} | T]) ->    if	is_atom(Name), is_list(Dir) ->	    check_vars(T);	is_list(Name), is_list(Dir) ->	    check_vars(T);	true ->	    error    end;check_vars(_) ->    error.check_apps([]) ->    ok;check_apps([H|T]) when is_atom(H) ->    check_apps(T);check_apps(_) ->    error.%% Format errorformat_error(badly_formatted_release) ->    io_lib:format("Syntax error in the release file~n",[]);format_error({illegal_name, Name}) ->    io_lib:format("Illegal name (~p) in the release file~n",[Name]);format_error({illegal_form, Form}) ->    io_lib:format("Illegal tag in the release file: ~p~n",[Form]);format_error({missing_parameter,Par}) ->    io_lib:format("Missing parameter (~p) in the release file~n",[Par]);format_error({illegal_applications,Names}) ->    io_lib:format("Illegal applications in the release file: ~p~n",		  [Names]);format_error({missing_mandatory_app,Names}) ->    io_lib:format("Mandatory applications (~p) must be specified in the release file~n",		  [Names]);format_error({duplicate_register,Dups}) ->    io_lib:format("Duplicated register names: ~n~s",		  [map(fun({{Reg,App1,_,_},{Reg,App2,_,_}}) ->			       io_lib:format("\t~p registered in ~p and ~p~n",					     [Reg,App1,App2])		       end, Dups)]);format_error({undefined_applications,Apps}) ->    io_lib:format("Undefined applications: ~p~n",[Apps]);format_error({duplicate_modules,Dups}) ->    io_lib:format("Duplicated modules: ~n~s",		  [map(fun({{Mod,_,App1,_,_},{Mod,_,App2,_,_}}) ->			       io_lib:format("\t~p specified in ~p and ~p~n",					     [Mod,App1,App2])		       end, Dups)]);format_error({included_and_used, Dups}) ->    io_lib:format("Applications both used and included: ~p~n",[Dups]);format_error({duplicate_include, Dups}) ->    io_lib:format("Duplicated application included: ~n~s",		  [map(fun({{Name,App1,_,_},{Name,App2,_,_}}) ->			       io_lib:format("\t~p included in ~p and ~p~n",					     [Name,App1,App2])		       end, Dups)]);format_error({modules,ModErrs}) ->    format_errors(ModErrs);format_error({circular_dependencies,Apps}) ->    io_lib:format("Circular dependencies among applications: ~p~n",[Apps]);format_error({not_found,File}) ->    io_lib:for

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -