2014-12-20: Retired because of broken deps:

unresolved dependencies for erlang-rebar-2.1.0-0.6.el6.i686:
erlang-neotoma(x86-32)
erlang-lfe(x86-32)
This commit is contained in:
Till Maas 2014-12-20 18:29:43 +01:00
parent 714c2005a9
commit 7f6ab89b3b
15 changed files with 5 additions and 1522 deletions

4
.gitignore vendored
View File

@ -1,4 +0,0 @@
/basho-rebar-RELEASE-1-327-g90058c7.tar.gz
/basho-rebar-RELEASE-1-821-g635d1a9.tar.gz
/basho-rebar-2.0.0-0-g1c98f6c.tar.gz
/basho-rebar-2.1.0-pre-0-gebb474b.tar.gz

5
dead.package Normal file
View File

@ -0,0 +1,5 @@
2014-12-20: Retired because of broken deps:
unresolved dependencies for erlang-rebar-2.1.0-0.6.el6.i686:
erlang-neotoma(x86-32)
erlang-lfe(x86-32)

View File

@ -1,179 +0,0 @@
%global realname rebar
%global upstream basho
%global debug_package %{nil}
%global git_tag ebb474b
%global patchnumber 0
Name: erlang-%{realname}
Version: 2.1.0
Release: 0.6%{?dist}
Summary: Erlang Build Tools
Group: Development/Tools
License: MIT
URL: https://github.com/rebar/rebar
# wget --content-disposition https://github.com/basho/rebar/tarball/ebb474b
Source0: %{upstream}-%{realname}-%{version}-pre-%{patchnumber}-g%{git_tag}.tar.gz
Source1: rebar.escript
# Fedora/EPEL-specific
Patch1: rebar-0001-Don-t-load-templates-from-the-bundle.patch
# Fedora/EPEL-specific
Patch2: rebar-0002-Remove-bundled-mustache.patch
# Fedora/EPEL-specific
Patch3: rebar-0003-Remove-bundled-getopt.patch
# Backported from upstream
Patch4: rebar-0004-Be-sure-to-filter-empty-sources-h-t-to-Tuncer-and-Jo.patch
# Will be proposed for inclusion
Patch5: rebar-0005-Allow-discarding-building-ports.patch
# Fedora/EPEL-specific
Patch6: rebar-0006-Check-system-wide-libdir-in-case-of-source-based-dep.patch
# Fedora/EPEL-specific
Patch7: rebar-0007-Remove-any-traces-of-long-time-obsolete-escript-fold.patch
# Fedora/EPEL-specific - unfortunately we don't have abnfc compiler available yet
Patch8: rebar-0008-Remove-abnfc-compiler-support-n-a-in-Fedora-EPEL.patch
# Fedora/EPEL-specific - cosmetic
Patch9: rebar-0009-Adjust-app-version.patch
# Backported from upstream
Patch10: rebar-0010-Fix-default-DTL-compilation-when-no-erlydtl_opts-are.patch
BuildRequires: erlang-rebar
# FIXME wip
#Requires: erlang-abnfc%{?_isa}
Requires: erlang-asn1%{?_isa}
Requires: erlang-common_test%{?_isa}
Requires: erlang-compiler%{?_isa}
Requires: erlang-crypto%{?_isa}
# FIXME does it still needed?
Requires: erlang-dialyzer%{?_isa}
Requires: erlang-edoc%{?_isa}
Requires: erlang-erlydtl%{?_isa}
Requires: erlang-erts%{?_isa}
# Requires for port compiling - no direct references in Rebar's src/*.erl files
Requires: erlang-erl_interface%{?_isa}
# Autochecker picks up a missing dependency in R16 -
# eunit_test:function_wrapper/2. This function was removed in R16, and rebar
# contains a workaround for that. So no need to worry about that.
Requires: erlang-eunit%{?_isa}
Requires: erlang-getopt%{?_isa}
Requires: erlang-kernel%{?_isa}
Requires: erlang-lfe%{?_isa}
Requires: erlang-mustache%{?_isa}
Requires: erlang-neotoma%{?_isa}
Requires: erlang-parsetools%{?_isa}
Requires: erlang-protobuffs%{?_isa}
Requires: erlang-reltool%{?_isa}
Requires: erlang-sasl%{?_isa}
Requires: erlang-snmp%{?_isa}
Requires: erlang-stdlib%{?_isa}
Requires: erlang-syntax_tools%{?_isa}
Requires: erlang-tools%{?_isa}
Provides: %{realname} = %{version}-%{release}
%description
Erlang Build Tools.
%prep
%setup -q -n %{upstream}-%{realname}-%{git_tag}
%patch1 -p1 -b .dont_load_templates
%patch2 -p1 -b .remove_bundled_mustache
%patch3 -p1 -b .remove_bundled_getopt
%patch4 -p1 -b .dont_try_building_so
%patch5 -p1 -b .allow_discarding_ports
%patch6 -p1 -b .use_locally_installed
%patch7 -p1 -b .remove_escript_foldl_3
%patch8 -p1 -b .no_abnfc
%patch9 -p1 -b .adjust_ver
%patch10 -p1 -b .fix_dtl
%build
rebar compile -v
%install
install -D -p -m 0755 %{SOURCE1} %{buildroot}%{_bindir}/rebar
mkdir -p %{buildroot}%{_libdir}/erlang/lib/%{realname}-%{version}/ebin
mkdir -p %{buildroot}%{_libdir}/erlang/lib/%{realname}-%{version}/include
install -m 644 ebin/%{realname}.app %{buildroot}%{_libdir}/erlang/lib/%{realname}-%{version}/ebin
install -m 644 ebin/*.beam %{buildroot}%{_libdir}/erlang/lib/%{realname}-%{version}/ebin
install -m 644 include/*.hrl %{buildroot}%{_libdir}/erlang/lib/%{realname}-%{version}/include
cp -a priv %{buildroot}%{_libdir}/erlang/lib/%{realname}-%{version}/
%check
#rebar eunit -v
%files
%doc LICENSE NOTES.org README.md THANKS rebar.config.sample
%{_bindir}/rebar
%{_libdir}/erlang/lib/%{realname}-%{version}
%changelog
* Sun Sep 01 2013 Peter Lemenkov <lemenkov@gmail.com> - 2.1.0-0.5
- Added missing runtime requirements
* Sat Aug 03 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.1.0-0.5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild
* Tue Mar 12 2013 Peter Lemenkov <lemenkov@gmail.com> - 2.1.0-0.4
- backported fix for ErlyDTL templates compilation
* Wed Mar 06 2013 Peter Lemenkov <lemenkov@gmail.com> - 2.1.0-0.3
- Don't bootstrap anymore - use rebar for building rebar
* Sun Mar 03 2013 Peter Lemenkov <lemenkov@gmail.com> - 2.1.0-0.2
- Backported fix for suppress building *.so libraries everytime
* Sat Mar 02 2013 Peter Lemenkov <lemenkov@gmail.com> - 2.1.0-0.1
- Ver. 2.1.0-pre
- Remove R12B-related patches (EL5-related)
* Wed Feb 13 2013 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.0.0-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_19_Mass_Rebuild
* Tue Dec 18 2012 Peter Lemenkov <lemenkov@gmail.com> - 2.0.0-3
- Fix templates
* Wed Jul 18 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2.0.0-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_18_Mass_Rebuild
* Tue Jun 05 2012 Peter Lemenkov <lemenkov@gmail.com> - 2.0.0-1
- Ver. 2.0.0
* Tue May 22 2012 Peter Lemenkov <lemenkov@gmail.com> - 2-9.20120514git635d1a9
- Fix building in EL6 and Fedora
* Mon May 21 2012 Peter Lemenkov <lemenkov@gmail.com> - 2-8.20120514git635d1a9
- Explicitly list erlang-erl_interface as a dependency
- Fixed EPEL5 dependencies
* Sun May 20 2012 Peter Lemenkov <lemenkov@gmail.com> - 2-7.20120514git635d1a9
- Enable building on EL5 (remove erlydtl-related stuff on el5)
- Remove abnfc-related stff until we package it
* Wed May 16 2012 Peter Lemenkov <lemenkov@gmail.com> - 2-6.20120514git635d1a9
- Updated to the latest git snapshot
* Fri Jan 13 2012 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2-5.20101120git90058c7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_17_Mass_Rebuild
* Tue Feb 08 2011 Fedora Release Engineering <rel-eng@lists.fedoraproject.org> - 2-4.20101120git90058c7
- Rebuilt for https://fedoraproject.org/wiki/Fedora_15_Mass_Rebuild
* Mon Nov 22 2010 Peter Lemenkov <lemenkov@gmail.com> - 2-3.20101120git90058c7
- Added missing buildrequires
* Sat Nov 20 2010 Peter Lemenkov <lemenkov@gmail.com> - 2-2.20101120git90058c7
- Removed bundled mustache and getopt
- Fixed license tag
- Removed wrong license text from package
- Simplified %%files section
- Fixed links (project was moved to GitHub)
- Changed versioning scheme (post-release)
* Sun Sep 5 2010 Peter Lemenkov <lemenkov@gmail.com> - 2-1
- Initial build

View File

@ -1,72 +0,0 @@
From b658042106136a5b471f0d248ec988c6eed77006 Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Mon, 4 Mar 2013 19:03:03 +0400
Subject: [PATCH 01/10] Don't load templates from the bundle
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
---
src/rebar_templater.erl | 31 +++++--------------------------
1 file changed, 5 insertions(+), 26 deletions(-)
diff --git a/src/rebar_templater.erl b/src/rebar_templater.erl
index 0e1eef1..7cc36f7 100644
--- a/src/rebar_templater.erl
+++ b/src/rebar_templater.erl
@@ -167,27 +167,11 @@ create1(Config, TemplateId) ->
execute_template(Files, FinalTemplate, Type, Template, Context, Force, []).
find_templates(Config) ->
- %% Load a list of all the files in the escript -- cache them since
- %% we'll potentially need to walk it several times over the course of
- %% a run.
- Files = cache_escript_files(Config),
-
%% Build a list of available templates
AvailTemplates = find_disk_templates(Config)
- ++ find_escript_templates(Files),
-
- {AvailTemplates, Files}.
+ ++ find_escript_templates(),
-%%
-%% Scan the current escript for available files
-%%
-cache_escript_files(Config) ->
- {ok, Files} = rebar_utils:escript_foldl(
- fun(Name, _, GetBin, Acc) ->
- [{Name, GetBin()} | Acc]
- end,
- [], rebar_config:get_xconf(Config, escript)),
- Files.
+ {AvailTemplates, []}.
template_id(Config) ->
case rebar_config:get_global(Config, template, undefined) of
@@ -197,10 +181,8 @@ template_id(Config) ->
TemplateId
end.
-find_escript_templates(Files) ->
- [{escript, Name}
- || {Name, _Bin} <- Files,
- re:run(Name, ?TEMPLATE_RE, [{capture, none}]) == match].
+find_escript_templates() ->
+ [{file, Name} || Name <- rebar_utils:find_files(code:priv_dir(rebar) ++ "/templates", ?TEMPLATE_RE)].
find_disk_templates(Config) ->
OtherTemplates = find_other_templates(Config),
@@ -231,10 +213,7 @@ select_template([{Type, Avail} | Rest], Template) ->
%%
%% Read the contents of a file from the appropriate source
%%
-load_file(Files, escript, Name) ->
- {Name, Bin} = lists:keyfind(Name, 1, Files),
- Bin;
-load_file(_Files, file, Name) ->
+load_file(_Files, _, Name) ->
{ok, Bin} = file:read_file(Name),
Bin.
--
1.8.1.4

View File

@ -1,263 +0,0 @@
From fce5d859e5a24dcbff1796293a4835078b758080 Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Sat, 20 Nov 2010 16:36:45 +0300
Subject: [PATCH 02/10] Remove bundled mustache
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
---
ebin/rebar.app | 3 +-
src/mustache.erl | 228 -------------------------------------------------------
2 files changed, 1 insertion(+), 230 deletions(-)
delete mode 100644 src/mustache.erl
diff --git a/ebin/rebar.app b/ebin/rebar.app
index 8df929f..9e000fa 100644
--- a/ebin/rebar.app
+++ b/ebin/rebar.app
@@ -37,8 +37,7 @@
rebar_upgrade,
rebar_utils,
rebar_xref,
- getopt,
- mustache ]},
+ getopt ]},
{registered, []},
{applications, [kernel,
stdlib,
diff --git a/src/mustache.erl b/src/mustache.erl
deleted file mode 100644
index f6963cd..0000000
--- a/src/mustache.erl
+++ /dev/null
@@ -1,228 +0,0 @@
-%% The MIT License
-%%
-%% Copyright (c) 2009 Tom Preston-Werner <tom@mojombo.com>
-%%
-%% Permission is hereby granted, free of charge, to any person obtaining a copy
-%% of this software and associated documentation files (the "Software"), to deal
-%% in the Software without restriction, including without limitation the rights
-%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-%% copies of the Software, and to permit persons to whom the Software is
-%% furnished to do so, subject to the following conditions:
-%%
-%% The above copyright notice and this permission notice shall be included in
-%% all copies or substantial portions of the Software.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-%% THE SOFTWARE.
-
-%% See the README at http://github.com/mojombo/mustache.erl for additional
-%% documentation and usage examples.
-
--module(mustache). %% v0.1.0
--author("Tom Preston-Werner").
--export([compile/1, compile/2, render/1, render/2, render/3, get/2, get/3, escape/1, start/1]).
-
--record(mstate, {mod = undefined,
- section_re = undefined,
- tag_re = undefined}).
-
-compile(Body) when is_list(Body) ->
- State = #mstate{},
- CompiledTemplate = pre_compile(Body, State),
- % io:format("~p~n~n", [CompiledTemplate]),
- % io:format(CompiledTemplate ++ "~n", []),
- {ok, Tokens, _} = erl_scan:string(CompiledTemplate),
- {ok, [Form]} = erl_parse:parse_exprs(Tokens),
- Bindings = erl_eval:new_bindings(),
- {value, Fun, _} = erl_eval:expr(Form, Bindings),
- Fun;
-compile(Mod) ->
- TemplatePath = template_path(Mod),
- compile(Mod, TemplatePath).
-
-compile(Mod, File) ->
- code:purge(Mod),
- {module, _} = code:load_file(Mod),
- {ok, TemplateBin} = file:read_file(File),
- Template = re:replace(TemplateBin, "\"", "\\\\\"", [global, {return,list}]),
- State = #mstate{mod = Mod},
- CompiledTemplate = pre_compile(Template, State),
- % io:format("~p~n~n", [CompiledTemplate]),
- % io:format(CompiledTemplate ++ "~n", []),
- {ok, Tokens, _} = erl_scan:string(CompiledTemplate),
- {ok, [Form]} = erl_parse:parse_exprs(Tokens),
- Bindings = erl_eval:new_bindings(),
- {value, Fun, _} = erl_eval:expr(Form, Bindings),
- Fun.
-
-render(Mod) ->
- TemplatePath = template_path(Mod),
- render(Mod, TemplatePath).
-
-render(Body, Ctx) when is_list(Body) ->
- TFun = compile(Body),
- render(undefined, TFun, Ctx);
-render(Mod, File) when is_list(File) ->
- render(Mod, File, dict:new());
-render(Mod, CompiledTemplate) ->
- render(Mod, CompiledTemplate, dict:new()).
-
-render(Mod, File, Ctx) when is_list(File) ->
- CompiledTemplate = compile(Mod, File),
- render(Mod, CompiledTemplate, Ctx);
-render(Mod, CompiledTemplate, Ctx) ->
- Ctx2 = dict:store('__mod__', Mod, Ctx),
- lists:flatten(CompiledTemplate(Ctx2)).
-
-pre_compile(T, State) ->
- SectionRE = "\{\{\#([^\}]*)}}\s*(.+?){{\/\\1\}\}\s*",
- {ok, CompiledSectionRE} = re:compile(SectionRE, [dotall]),
- TagRE = "\{\{(#|=|!|<|>|\{)?(.+?)\\1?\}\}+",
- {ok, CompiledTagRE} = re:compile(TagRE, [dotall]),
- State2 = State#mstate{section_re = CompiledSectionRE, tag_re = CompiledTagRE},
- "fun(Ctx) -> " ++
- "CFun = fun(A, B) -> A end, " ++
- compiler(T, State2) ++ " end.".
-
-compiler(T, State) ->
- Res = re:run(T, State#mstate.section_re),
- case Res of
- {match, [{M0, M1}, {N0, N1}, {C0, C1}]} ->
- Front = string:substr(T, 1, M0),
- Back = string:substr(T, M0 + M1 + 1),
- Name = string:substr(T, N0 + 1, N1),
- Content = string:substr(T, C0 + 1, C1),
- "[" ++ compile_tags(Front, State) ++
- " | [" ++ compile_section(Name, Content, State) ++
- " | [" ++ compiler(Back, State) ++ "]]]";
- nomatch ->
- compile_tags(T, State)
- end.
-
-compile_section(Name, Content, State) ->
- Mod = State#mstate.mod,
- Result = compiler(Content, State),
- "fun() -> " ++
- "case mustache:get(" ++ Name ++ ", Ctx, " ++ atom_to_list(Mod) ++ ") of " ++
- "\"true\" -> " ++
- Result ++ "; " ++
- "\"false\" -> " ++
- "[]; " ++
- "List when is_list(List) -> " ++
- "[fun(Ctx) -> " ++ Result ++ " end(dict:merge(CFun, SubCtx, Ctx)) || SubCtx <- List]; " ++
- "Else -> " ++
- "throw({template, io_lib:format(\"Bad context for ~p: ~p\", [" ++ Name ++ ", Else])}) " ++
- "end " ++
- "end()".
-
-compile_tags(T, State) ->
- Res = re:run(T, State#mstate.tag_re),
- case Res of
- {match, [{M0, M1}, K, {C0, C1}]} ->
- Front = string:substr(T, 1, M0),
- Back = string:substr(T, M0 + M1 + 1),
- Content = string:substr(T, C0 + 1, C1),
- Kind = tag_kind(T, K),
- Result = compile_tag(Kind, Content, State),
- "[\"" ++ Front ++
- "\" | [" ++ Result ++
- " | " ++ compile_tags(Back, State) ++ "]]";
- nomatch ->
- "[\"" ++ T ++ "\"]"
- end.
-
-tag_kind(_T, {-1, 0}) ->
- none;
-tag_kind(T, {K0, K1}) ->
- string:substr(T, K0 + 1, K1).
-
-compile_tag(none, Content, State) ->
- Mod = State#mstate.mod,
- "mustache:escape(mustache:get(" ++ Content ++ ", Ctx, " ++ atom_to_list(Mod) ++ "))";
-compile_tag("{", Content, State) ->
- Mod = State#mstate.mod,
- "mustache:get(" ++ Content ++ ", Ctx, " ++ atom_to_list(Mod) ++ ")";
-compile_tag("!", _Content, _State) ->
- "[]".
-
-template_dir(Mod) ->
- DefaultDirPath = filename:dirname(code:which(Mod)),
- case application:get_env(mustache, templates_dir) of
- {ok, DirPath} when is_list(DirPath) ->
- case filelib:ensure_dir(DirPath) of
- ok -> DirPath;
- _ -> DefaultDirPath
- end;
- _ ->
- DefaultDirPath
- end.
-template_path(Mod) ->
- DirPath = template_dir(Mod),
- Basename = atom_to_list(Mod),
- filename:join(DirPath, Basename ++ ".mustache").
-
-get(Key, Ctx) when is_list(Key) ->
- {ok, Mod} = dict:find('__mod__', Ctx),
- get(list_to_atom(Key), Ctx, Mod);
-get(Key, Ctx) ->
- {ok, Mod} = dict:find('__mod__', Ctx),
- get(Key, Ctx, Mod).
-
-get(Key, Ctx, Mod) when is_list(Key) ->
- get(list_to_atom(Key), Ctx, Mod);
-get(Key, Ctx, Mod) ->
- case dict:find(Key, Ctx) of
- {ok, Val} ->
- % io:format("From Ctx {~p, ~p}~n", [Key, Val]),
- to_s(Val);
- error ->
- case erlang:function_exported(Mod, Key, 1) of
- true ->
- Val = to_s(Mod:Key(Ctx)),
- % io:format("From Mod/1 {~p, ~p}~n", [Key, Val]),
- Val;
- false ->
- case erlang:function_exported(Mod, Key, 0) of
- true ->
- Val = to_s(Mod:Key()),
- % io:format("From Mod/0 {~p, ~p}~n", [Key, Val]),
- Val;
- false ->
- []
- end
- end
- end.
-
-to_s(Val) when is_integer(Val) ->
- integer_to_list(Val);
-to_s(Val) when is_float(Val) ->
- io_lib:format("~.2f", [Val]);
-to_s(Val) when is_atom(Val) ->
- atom_to_list(Val);
-to_s(Val) ->
- Val.
-
-escape(HTML) ->
- escape(HTML, []).
-
-escape([], Acc) ->
- lists:reverse(Acc);
-escape(["<" | Rest], Acc) ->
- escape(Rest, lists:reverse("&lt;", Acc));
-escape([">" | Rest], Acc) ->
- escape(Rest, lists:reverse("&gt;", Acc));
-escape(["&" | Rest], Acc) ->
- escape(Rest, lists:reverse("&amp;", Acc));
-escape([X | Rest], Acc) ->
- escape(Rest, [X | Acc]).
-
-%%---------------------------------------------------------------------------
-
-start([T]) ->
- Out = render(list_to_atom(T)),
- io:format(Out ++ "~n", []).
--
1.8.1.4

View File

@ -1,656 +0,0 @@
From e200556bfca9db7e496a50b62fa09a5f46f22b25 Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Sat, 20 Nov 2010 16:40:15 +0300
Subject: [PATCH 03/10] Remove bundled getopt
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
---
ebin/rebar.app | 3 +-
src/getopt.erl | 621 ---------------------------------------------------------
2 files changed, 1 insertion(+), 623 deletions(-)
delete mode 100644 src/getopt.erl
diff --git a/ebin/rebar.app b/ebin/rebar.app
index 9e000fa..cba8bf8 100644
--- a/ebin/rebar.app
+++ b/ebin/rebar.app
@@ -36,8 +36,7 @@
rebar_templater,
rebar_upgrade,
rebar_utils,
- rebar_xref,
- getopt ]},
+ rebar_xref]},
{registered, []},
{applications, [kernel,
stdlib,
diff --git a/src/getopt.erl b/src/getopt.erl
deleted file mode 100644
index 175b7a5..0000000
--- a/src/getopt.erl
+++ /dev/null
@@ -1,621 +0,0 @@
-%%%-------------------------------------------------------------------
-%%% @author Juan Jose Comellas <juanjo@comellas.org>
-%%% @copyright (C) 2009 Juan Jose Comellas
-%%% @doc Parses command line options with a format similar to that of GNU getopt.
-%%% @end
-%%%
-%%% This source file is subject to the New BSD License. You should have received
-%%% a copy of the New BSD license with this software. If not, it can be
-%%% retrieved from: http://www.opensource.org/licenses/bsd-license.php
-%%%-------------------------------------------------------------------
--module(getopt).
--author('juanjo@comellas.org').
-
--export([parse/2, usage/2, usage/3, usage/4]).
-
--export_type([arg_type/0,
- arg_value/0,
- arg_spec/0,
- simple_option/0,
- compound_option/0,
- option/0,
- option_spec/0]).
-
--define(TAB_LENGTH, 8).
-%% Indentation of the help messages in number of tabs.
--define(INDENTATION, 3).
-
-%% Position of each field in the option specification tuple.
--define(OPT_NAME, 1).
--define(OPT_SHORT, 2).
--define(OPT_LONG, 3).
--define(OPT_ARG, 4).
--define(OPT_HELP, 5).
-
--define(IS_OPT_SPEC(Opt), (tuple_size(Opt) =:= ?OPT_HELP)).
-
-
-%% Atom indicating the data type that an argument can be converted to.
--type arg_type() :: 'atom' | 'binary' | 'boolean' | 'float' | 'integer' | 'string'.
-%% Data type that an argument can be converted to.
--type arg_value() :: atom() | binary() | boolean() | float() | integer() | string().
-%% Argument specification.
--type arg_spec() :: arg_type() | {arg_type(), arg_value()} | undefined.
-%% Option type and optional default argument.
--type simple_option() :: atom().
--type compound_option() :: {atom(), arg_value()}.
--type option() :: simple_option() | compound_option().
-%% Command line option specification.
--type option_spec() :: {
- Name :: atom(),
- Short :: char() | undefined,
- Long :: string() | undefined,
- ArgSpec :: arg_spec(),
- Help :: string() | undefined
- }.
-%% Output streams
--type output_stream() :: 'standard_io' | 'standard_error'.
-
-
-%% @doc Parse the command line options and arguments returning a list of tuples
-%% and/or atoms using the Erlang convention for sending options to a
-%% function.
--spec parse([option_spec()], string() | [string()]) ->
- {ok, {[option()], [string()]}} | {error, {Reason :: atom(), Data :: any()}}.
-parse(OptSpecList, CmdLine) ->
- try
- Args = if
- is_integer(hd(CmdLine)) ->
- string:tokens(CmdLine, " \t\n");
- true ->
- CmdLine
- end,
- parse(OptSpecList, [], [], 0, Args)
- catch
- throw: {error, {_Reason, _Data}} = Error ->
- Error
- end.
-
-
--spec parse([option_spec()], [option()], [string()], integer(), [string()]) ->
- {ok, {[option()], [string()]}}.
-%% Process the option terminator.
-parse(OptSpecList, OptAcc, ArgAcc, _ArgPos, ["--" | Tail]) ->
- %% Any argument present after the terminator is not considered an option.
- {ok, {lists:reverse(append_default_options(OptSpecList, OptAcc)), lists:reverse(ArgAcc, Tail)}};
-%% Process long options.
-parse(OptSpecList, OptAcc, ArgAcc, ArgPos, ["--" ++ OptArg = OptStr | Tail]) ->
- parse_long_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Tail, OptStr, OptArg);
-%% Process short options.
-parse(OptSpecList, OptAcc, ArgAcc, ArgPos, ["-" ++ ([_Char | _] = OptArg) = OptStr | Tail]) ->
- parse_short_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Tail, OptStr, OptArg);
-%% Process non-option arguments.
-parse(OptSpecList, OptAcc, ArgAcc, ArgPos, [Arg | Tail]) ->
- case find_non_option_arg(OptSpecList, ArgPos) of
- {value, OptSpec} when ?IS_OPT_SPEC(OptSpec) ->
- parse(OptSpecList, add_option_with_arg(OptSpec, Arg, OptAcc), ArgAcc, ArgPos + 1, Tail);
- false ->
- parse(OptSpecList, OptAcc, [Arg | ArgAcc], ArgPos, Tail)
- end;
-parse(OptSpecList, OptAcc, ArgAcc, _ArgPos, []) ->
- %% Once we have completed gathering the options we add the ones that were
- %% not present but had default arguments in the specification.
- {ok, {lists:reverse(append_default_options(OptSpecList, OptAcc)), lists:reverse(ArgAcc)}}.
-
-
-%% @doc Parse a long option, add it to the option accumulator and continue
-%% parsing the rest of the arguments recursively.
-%% A long option can have the following syntax:
-%% --foo Single option 'foo', no argument
-%% --foo=bar Single option 'foo', argument "bar"
-%% --foo bar Single option 'foo', argument "bar"
--spec parse_long_option([option_spec()], [option()], [string()], integer(), [string()], string(), string()) ->
- {ok, {[option()], [string()]}}.
-parse_long_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, OptArg) ->
- case split_assigned_arg(OptArg) of
- {Long, Arg} ->
- %% Get option that has its argument within the same string
- %% separated by an equal ('=') character (e.g. "--port=1000").
- parse_long_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Long, Arg);
-
- Long ->
- case lists:keyfind(Long, ?OPT_LONG, OptSpecList) of
- {Name, _Short, Long, undefined, _Help} ->
- parse(OptSpecList, [Name | OptAcc], ArgAcc, ArgPos, Args);
-
- {_Name, _Short, Long, _ArgSpec, _Help} = OptSpec ->
- %% The option argument string is empty, but the option requires
- %% an argument, so we look into the next string in the list.
- %% e.g ["--port", "1000"]
- parse_long_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptSpec);
- false ->
- throw({error, {invalid_option, OptStr}})
- end
- end.
-
-
-%% @doc Parse an option where the argument is 'assigned' in the same string using
-%% the '=' character, add it to the option accumulator and continue parsing the
-%% rest of the arguments recursively. This syntax is only valid for long options.
--spec parse_long_option_assigned_arg([option_spec()], [option()], [string()], integer(),
- [string()], string(), string(), string()) ->
- {ok, {[option()], [string()]}}.
-parse_long_option_assigned_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, Long, Arg) ->
- case lists:keyfind(Long, ?OPT_LONG, OptSpecList) of
- {_Name, _Short, Long, ArgSpec, _Help} = OptSpec ->
- case ArgSpec of
- undefined ->
- throw({error, {invalid_option_arg, OptStr}});
- _ ->
- parse(OptSpecList, add_option_with_assigned_arg(OptSpec, Arg, OptAcc), ArgAcc, ArgPos, Args)
- end;
- false ->
- throw({error, {invalid_option, OptStr}})
- end.
-
-
-%% @doc Split an option string that may contain an option with its argument
-%% separated by an equal ('=') character (e.g. "port=1000").
--spec split_assigned_arg(string()) -> {Name :: string(), Arg :: string()} | string().
-split_assigned_arg(OptStr) ->
- split_assigned_arg(OptStr, OptStr, []).
-
-split_assigned_arg(_OptStr, "=" ++ Tail, Acc) ->
- {lists:reverse(Acc), Tail};
-split_assigned_arg(OptStr, [Char | Tail], Acc) ->
- split_assigned_arg(OptStr, Tail, [Char | Acc]);
-split_assigned_arg(OptStr, [], _Acc) ->
- OptStr.
-
-
-%% @doc Retrieve the argument for an option from the next string in the list of
-%% command-line parameters or set the value of the argument from the argument
-%% specification (for boolean and integer arguments), if possible.
-parse_long_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, {Name, _Short, _Long, ArgSpec, _Help} = OptSpec) ->
- ArgSpecType = arg_spec_type(ArgSpec),
- case Args =:= [] orelse is_implicit_arg(ArgSpecType, hd(Args)) of
- true ->
- parse(OptSpecList, add_option_with_implicit_arg(OptSpec, OptAcc), ArgAcc, ArgPos, Args);
- false ->
- [Arg | Tail] = Args,
- try
- parse(OptSpecList, [{Name, to_type(ArgSpecType, Arg)} | OptAcc], ArgAcc, ArgPos, Tail)
- catch
- error:_ ->
- throw({error, {invalid_option_arg, {Name, Arg}}})
- end
- end.
-
-
-%% @doc Parse a short option, add it to the option accumulator and continue
-%% parsing the rest of the arguments recursively.
-%% A short option can have the following syntax:
-%% -a Single option 'a', no argument or implicit boolean argument
-%% -a foo Single option 'a', argument "foo"
-%% -afoo Single option 'a', argument "foo"
-%% -abc Multiple options: 'a'; 'b'; 'c'
-%% -bcafoo Multiple options: 'b'; 'c'; 'a' with argument "foo"
-%% -aaa Multiple repetitions of option 'a' (only valid for options with integer arguments)
--spec parse_short_option([option_spec()], [option()], [string()], integer(), [string()], string(), string()) ->
- {ok, {[option()], [string()]}}.
-parse_short_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, OptArg) ->
- parse_short_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, first, OptArg).
-
-parse_short_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptStr, OptPos, [Short | Arg]) ->
- case lists:keyfind(Short, ?OPT_SHORT, OptSpecList) of
- {Name, Short, _Long, undefined, _Help} ->
- parse_short_option(OptSpecList, [Name | OptAcc], ArgAcc, ArgPos, Args, OptStr, first, Arg);
-
- {_Name, Short, _Long, ArgSpec, _Help} = OptSpec ->
- %% The option has a specification, so it requires an argument.
- case Arg of
- [] ->
- %% The option argument string is empty, but the option requires
- %% an argument, so we look into the next string in the list.
- parse_short_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, OptSpec, OptPos);
-
- _ ->
- case is_valid_arg(ArgSpec, Arg) of
- true ->
- parse(OptSpecList, add_option_with_arg(OptSpec, Arg, OptAcc), ArgAcc, ArgPos, Args);
- _ ->
- NewOptAcc = case OptPos of
- first -> add_option_with_implicit_arg(OptSpec, OptAcc);
- _ -> add_option_with_implicit_incrementable_arg(OptSpec, OptAcc)
- end,
- parse_short_option(OptSpecList, NewOptAcc, ArgAcc, ArgPos, Args, OptStr, next, Arg)
- end
- end;
-
- false ->
- throw({error, {invalid_option, OptStr}})
- end;
-parse_short_option(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, _OptStr, _OptPos, []) ->
- parse(OptSpecList, OptAcc, ArgAcc, ArgPos, Args).
-
-
-%% @doc Retrieve the argument for an option from the next string in the list of
-%% command-line parameters or set the value of the argument from the argument
-%% specification (for boolean and integer arguments), if possible.
-parse_short_option_next_arg(OptSpecList, OptAcc, ArgAcc, ArgPos, Args, {Name, _Short, _Long, ArgSpec, _Help} = OptSpec, OptPos) ->
- case Args =:= [] orelse is_implicit_arg(ArgSpec, hd(Args)) of
- true when OptPos =:= first ->
- parse(OptSpecList, add_option_with_implicit_arg(OptSpec, OptAcc), ArgAcc, ArgPos, Args);
- true ->
- parse(OptSpecList, add_option_with_implicit_incrementable_arg(OptSpec, OptAcc), ArgAcc, ArgPos, Args);
- false ->
- [Arg | Tail] = Args,
- try
- parse(OptSpecList, [{Name, to_type(ArgSpec, Arg)} | OptAcc], ArgAcc, ArgPos, Tail)
- catch
- error:_ ->
- throw({error, {invalid_option_arg, {Name, Arg}}})
- end
- end.
-
-
-%% @doc Find the option for the discrete argument in position specified in the
-%% Pos argument.
--spec find_non_option_arg([option_spec()], integer()) -> {value, option_spec()} | false.
-find_non_option_arg([{_Name, undefined, undefined, _ArgSpec, _Help} = OptSpec | _Tail], 0) ->
- {value, OptSpec};
-find_non_option_arg([{_Name, undefined, undefined, _ArgSpec, _Help} | Tail], Pos) ->
- find_non_option_arg(Tail, Pos - 1);
-find_non_option_arg([_Head | Tail], Pos) ->
- find_non_option_arg(Tail, Pos);
-find_non_option_arg([], _Pos) ->
- false.
-
-
-%% @doc Append options that were not present in the command line arguments with
-%% their default arguments.
--spec append_default_options([option_spec()], [option()]) -> [option()].
-append_default_options([{Name, _Short, _Long, {_Type, DefaultArg}, _Help} | Tail], OptAcc) ->
- append_default_options(Tail,
- case lists:keymember(Name, 1, OptAcc) of
- false ->
- [{Name, DefaultArg} | OptAcc];
- _ ->
- OptAcc
- end);
-%% For options with no default argument.
-append_default_options([_Head | Tail], OptAcc) ->
- append_default_options(Tail, OptAcc);
-append_default_options([], OptAcc) ->
- OptAcc.
-
-
-%% @doc Add an option with argument converting it to the data type indicated by the
-%% argument specification.
--spec add_option_with_arg(option_spec(), string(), [option()]) -> [option()].
-add_option_with_arg({Name, _Short, _Long, ArgSpec, _Help} = OptSpec, Arg, OptAcc) ->
- case is_valid_arg(ArgSpec, Arg) of
- true ->
- try
- [{Name, to_type(ArgSpec, Arg)} | OptAcc]
- catch
- error:_ ->
- throw({error, {invalid_option_arg, {Name, Arg}}})
- end;
- false ->
- add_option_with_implicit_arg(OptSpec, OptAcc)
- end.
-
-
-%% @doc Add an option with argument that was part of an assignment expression
-%% (e.g. "--verbose=3") converting it to the data type indicated by the
-%% argument specification.
--spec add_option_with_assigned_arg(option_spec(), string(), [option()]) -> [option()].
-add_option_with_assigned_arg({Name, _Short, _Long, ArgSpec, _Help}, Arg, OptAcc) ->
- try
- [{Name, to_type(ArgSpec, Arg)} | OptAcc]
- catch
- error:_ ->
- throw({error, {invalid_option_arg, {Name, Arg}}})
- end.
-
-
-%% @doc Add an option that required an argument but did not have one. Some data
-%% types (boolean, integer) allow implicit or assumed arguments.
--spec add_option_with_implicit_arg(option_spec(), [option()]) -> [option()].
-add_option_with_implicit_arg({Name, _Short, _Long, ArgSpec, _Help}, OptAcc) ->
- case arg_spec_type(ArgSpec) of
- boolean ->
- %% Special case for boolean arguments: if there is no argument we
- %% set the value to 'true'.
- [{Name, true} | OptAcc];
- integer ->
- %% Special case for integer arguments: if the option had not been set
- %% before we set the value to 1. This is needed to support options like
- %% "-v" to return something like {verbose, 1}.
- [{Name, 1} | OptAcc];
- _ ->
- throw({error, {missing_option_arg, Name}})
- end.
-
-
-%% @doc Add an option with an implicit or assumed argument.
--spec add_option_with_implicit_incrementable_arg(option_spec() | arg_spec(), [option()]) -> [option()].
-add_option_with_implicit_incrementable_arg({Name, _Short, _Long, ArgSpec, _Help}, OptAcc) ->
- case arg_spec_type(ArgSpec) of
- boolean ->
- %% Special case for boolean arguments: if there is no argument we
- %% set the value to 'true'.
- [{Name, true} | OptAcc];
- integer ->
- %% Special case for integer arguments: if the option had not been set
- %% before we set the value to 1; if not we increment the previous value
- %% the option had. This is needed to support options like "-vvv" to
- %% return something like {verbose, 3}.
- case OptAcc of
- [{Name, Count} | Tail] ->
- [{Name, Count + 1} | Tail];
- _ ->
- [{Name, 1} | OptAcc]
- end;
- _ ->
- throw({error, {missing_option_arg, Name}})
- end.
-
-
-%% @doc Retrieve the data type form an argument specification.
--spec arg_spec_type(arg_spec()) -> arg_type() | undefined.
-arg_spec_type({Type, _DefaultArg}) ->
- Type;
-arg_spec_type(Type) when is_atom(Type) ->
- Type.
-
-
-%% @doc Convert an argument string to its corresponding data type.
--spec to_type(arg_spec() | arg_type(), string()) -> arg_value().
-to_type({Type, _DefaultArg}, Arg) ->
- to_type(Type, Arg);
-to_type(binary, Arg) ->
- list_to_binary(Arg);
-to_type(atom, Arg) ->
- list_to_atom(Arg);
-to_type(integer, Arg) ->
- list_to_integer(Arg);
-to_type(float, Arg) ->
- list_to_float(Arg);
-to_type(boolean, Arg) ->
- LowerArg = string:to_lower(Arg),
- case is_arg_true(LowerArg) of
- true ->
- true;
- _ ->
- case is_arg_false(LowerArg) of
- true ->
- false;
- false ->
- erlang:error(badarg)
- end
- end;
-to_type(_Type, Arg) ->
- Arg.
-
-
--spec is_arg_true(string()) -> boolean().
-is_arg_true(Arg) ->
- (Arg =:= "true") orelse (Arg =:= "t") orelse
- (Arg =:= "yes") orelse (Arg =:= "y") orelse
- (Arg =:= "on") orelse (Arg =:= "enabled") orelse
- (Arg =:= "1").
-
-
--spec is_arg_false(string()) -> boolean().
-is_arg_false(Arg) ->
- (Arg =:= "false") orelse (Arg =:= "f") orelse
- (Arg =:= "no") orelse (Arg =:= "n") orelse
- (Arg =:= "off") orelse (Arg =:= "disabled") orelse
- (Arg =:= "0").
-
-
--spec is_valid_arg(arg_spec(), nonempty_string()) -> boolean().
-is_valid_arg({Type, _DefaultArg}, Arg) ->
- is_valid_arg(Type, Arg);
-is_valid_arg(boolean, Arg) ->
- is_boolean_arg(Arg);
-is_valid_arg(integer, Arg) ->
- is_non_neg_integer_arg(Arg);
-is_valid_arg(float, Arg) ->
- is_non_neg_float_arg(Arg);
-is_valid_arg(_Type, _Arg) ->
- true.
-
-
--spec is_implicit_arg(arg_spec(), nonempty_string()) -> boolean().
-is_implicit_arg({Type, _DefaultArg}, Arg) ->
- is_implicit_arg(Type, Arg);
-is_implicit_arg(boolean, Arg) ->
- not is_boolean_arg(Arg);
-is_implicit_arg(integer, Arg) ->
- not is_integer_arg(Arg);
-is_implicit_arg(_Type, _Arg) ->
- false.
-
-
--spec is_boolean_arg(string()) -> boolean().
-is_boolean_arg(Arg) ->
- LowerArg = string:to_lower(Arg),
- is_arg_true(LowerArg) orelse is_arg_false(LowerArg).
-
-
--spec is_integer_arg(string()) -> boolean().
-is_integer_arg("-" ++ Tail) ->
- is_non_neg_integer_arg(Tail);
-is_integer_arg(Arg) ->
- is_non_neg_integer_arg(Arg).
-
-
--spec is_non_neg_integer_arg(string()) -> boolean().
-is_non_neg_integer_arg([Head | Tail]) when Head >= $0, Head =< $9 ->
- is_non_neg_integer_arg(Tail);
-is_non_neg_integer_arg([_Head | _Tail]) ->
- false;
-is_non_neg_integer_arg([]) ->
- true.
-
-
--spec is_non_neg_float_arg(string()) -> boolean().
-is_non_neg_float_arg([Head | Tail]) when (Head >= $0 andalso Head =< $9) orelse Head =:= $. ->
- is_non_neg_float_arg(Tail);
-is_non_neg_float_arg([_Head | _Tail]) ->
- false;
-is_non_neg_float_arg([]) ->
- true.
-
-
-%% @doc Show a message on standard_error indicating the command line options and
-%% arguments that are supported by the program.
--spec usage([option_spec()], string()) -> ok.
-usage(OptSpecList, ProgramName) ->
- usage(OptSpecList, ProgramName, standard_error).
-
-
-%% @doc Show a message on standard_error or standard_io indicating the command line options and
-%% arguments that are supported by the program.
--spec usage([option_spec()], string(), output_stream() | string()) -> ok.
-usage(OptSpecList, ProgramName, OutputStream) when is_atom(OutputStream) ->
- io:format(OutputStream, "Usage: ~s~s~n~n~s~n",
- [ProgramName, usage_cmd_line(OptSpecList), usage_options(OptSpecList)]);
-%% @doc Show a message on standard_error indicating the command line options and
-%% arguments that are supported by the program. The CmdLineTail argument
-%% is a string that is added to the end of the usage command line.
-usage(OptSpecList, ProgramName, CmdLineTail) ->
- usage(OptSpecList, ProgramName, CmdLineTail, standard_error).
-
-
-%% @doc Show a message on standard_error or standard_io indicating the command line options and
-%% arguments that are supported by the program. The CmdLineTail argument
-%% is a string that is added to the end of the usage command line.
--spec usage([option_spec()], string(), string(), output_stream() | [{string(), string()}]) -> ok.
-usage(OptSpecList, ProgramName, CmdLineTail, OutputStream) when is_atom(OutputStream) ->
- io:format(OutputStream, "Usage: ~s~s ~s~n~n~s~n",
- [ProgramName, usage_cmd_line(OptSpecList), CmdLineTail, usage_options(OptSpecList)]);
-%% @doc Show a message on standard_error indicating the command line options and
-%% arguments that are supported by the program. The CmdLineTail and OptionsTail
-%% arguments are a string that is added to the end of the usage command line
-%% and a list of tuples that are added to the end of the options' help lines.
-usage(OptSpecList, ProgramName, CmdLineTail, OptionsTail) ->
- usage(OptSpecList, ProgramName, CmdLineTail, OptionsTail, standard_error).
-
-
-%% @doc Show a message on standard_error or standard_io indicating the command line options and
-%% arguments that are supported by the program. The CmdLineTail and OptionsTail
-%% arguments are a string that is added to the end of the usage command line
-%% and a list of tuples that are added to the end of the options' help lines.
--spec usage([option_spec()], string(), string(), [{string(), string()}], output_stream()) -> ok.
-usage(OptSpecList, ProgramName, CmdLineTail, OptionsTail, OutputStream) ->
- UsageOptions = lists:foldl(
- fun ({Prefix, Help}, Acc) ->
- add_option_help(Prefix, Help, Acc)
- end, usage_options_reverse(OptSpecList, []), OptionsTail),
- io:format(OutputStream, "Usage: ~s~s ~s~n~n~s~n",
- [ProgramName, usage_cmd_line(OptSpecList), CmdLineTail,
- lists:flatten(lists:reverse(UsageOptions))]).
-
-
-%% @doc Return a string with the syntax for the command line options and
-%% arguments.
--spec usage_cmd_line([option_spec()]) -> string().
-usage_cmd_line(OptSpecList) ->
- usage_cmd_line(OptSpecList, []).
-
-usage_cmd_line([{Name, Short, Long, ArgSpec, _Help} | Tail], Acc) ->
- CmdLine =
- case ArgSpec of
- undefined ->
- if
- %% For options with short form and no argument.
- Short =/= undefined ->
- [$\s, $[, $-, Short, $]];
- %% For options with only long form and no argument.
- Long =/= undefined ->
- [$\s, $[, $-, $-, Long, $]];
- true ->
- []
- end;
- _ ->
- if
- %% For options with short form and argument.
- Short =/= undefined ->
- [$\s, $[, $-, Short, $\s, $<, atom_to_list(Name), $>, $]];
- %% For options with only long form and argument.
- Long =/= undefined ->
- [$\s, $[, $-, $-, Long, $\s, $<, atom_to_list(Name), $>, $]];
- %% For options with neither short nor long form and argument.
- true ->
- [$\s, $<, atom_to_list(Name), $>]
- end
- end,
- usage_cmd_line(Tail, [CmdLine | Acc]);
-usage_cmd_line([], Acc) ->
- lists:flatten(lists:reverse(Acc)).
-
-
-%% @doc Return a string with the help message for each of the options and
-%% arguments.
--spec usage_options([option_spec()]) -> string().
-usage_options(OptSpecList) ->
- lists:flatten(lists:reverse(usage_options_reverse(OptSpecList, []))).
-
-usage_options_reverse([{Name, Short, Long, _ArgSpec, Help} | Tail], Acc) ->
- Prefix =
- case Long of
- undefined ->
- case Short of
- %% Neither short nor long form (non-option argument).
- undefined ->
- [$<, atom_to_list(Name), $>];
- %% Only short form.
- _ ->
- [$-, Short]
- end;
- _ ->
- case Short of
- %% Only long form.
- undefined ->
- [$-, $- | Long];
- %% Both short and long form.
- _ ->
- [$-, Short, $,, $\s, $-, $- | Long]
- end
- end,
- usage_options_reverse(Tail, add_option_help(Prefix, Help, Acc));
-usage_options_reverse([], Acc) ->
- Acc.
-
-
-%% @doc Add the help message corresponding to an option specification to a list
-%% with the correct indentation.
--spec add_option_help(Prefix :: string(), Help :: string(), Acc :: string()) -> string().
-add_option_help(Prefix, Help, Acc) when is_list(Help), Help =/= [] ->
- FlatPrefix = lists:flatten(Prefix),
- case ((?INDENTATION * ?TAB_LENGTH) - 2 - length(FlatPrefix)) of
- TabSize when TabSize > 0 ->
- Tab = lists:duplicate(ceiling(TabSize / ?TAB_LENGTH), $\t),
- [[$\s, $\s, FlatPrefix, Tab, Help, $\n] | Acc];
- _ ->
- % The indentation for the option description is 3 tabs (i.e. 24 characters)
- % IMPORTANT: Change the number of tabs below if you change the
- % value of the INDENTATION macro.
- [[$\t, $\t, $\t, Help, $\n], [$\s, $\s, FlatPrefix, $\n] | Acc]
- end;
-add_option_help(_Opt, _Prefix, Acc) ->
- Acc.
-
-
-
-%% @doc Return the smallest integral value not less than the argument.
--spec ceiling(float()) -> integer().
-ceiling(X) ->
- T = erlang:trunc(X),
- case (X - T) of
- % Neg when Neg < 0 ->
- % T;
- Pos when Pos > 0 ->
- T + 1;
- _ ->
- T
- end.
--
1.8.1.4

View File

@ -1,45 +0,0 @@
From 53508faa9cba923751653901ba21d6025da46e5b Mon Sep 17 00:00:00 2001
From: Dave Smith <dizzyd@dizzyd.com>
Date: Mon, 12 Nov 2012 20:18:00 -0700
Subject: [PATCH 04/10] Be sure to filter empty sources (h/t to Tuncer and Joe
Norton)
---
src/rebar_port_compiler.erl | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl
index 71b27a5..70ee308 100644
--- a/src/rebar_port_compiler.erl
+++ b/src/rebar_port_compiler.erl
@@ -248,16 +248,17 @@ needs_link(SoName, NewBins) ->
%%
get_specs(Config, AppFile) ->
- case rebar_config:get_local(Config, port_specs, []) of
- [] ->
- %% No spec provided. Construct a spec
- %% from old-school so_name and sources
- [port_spec_from_legacy(Config, AppFile)];
- PortSpecs ->
- Filtered = filter_port_specs(PortSpecs),
- OsType = os:type(),
- [get_port_spec(Config, OsType, Spec) || Spec <- Filtered]
- end.
+ Specs = case rebar_config:get_local(Config, port_specs, []) of
+ [] ->
+ %% No spec provided. Construct a spec
+ %% from old-school so_name and sources
+ [port_spec_from_legacy(Config, AppFile)];
+ PortSpecs ->
+ Filtered = filter_port_specs(PortSpecs),
+ OsType = os:type(),
+ [get_port_spec(Config, OsType, Spec) || Spec <- Filtered]
+ end,
+ [S || S <- Specs, S#spec.sources /= []].
port_spec_from_legacy(Config, AppFile) ->
%% Get the target from the so_name variable
--
1.8.1.4

View File

@ -1,33 +0,0 @@
From a101ee059baff585da6d1086097e8ceb20bda5d1 Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Tue, 5 Jun 2012 15:10:12 +0400
Subject: [PATCH 05/10] Allow discarding building ports
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
Conflicts:
src/rebar_port_compiler.erl
---
src/rebar_port_compiler.erl | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/rebar_port_compiler.erl b/src/rebar_port_compiler.erl
index 70ee308..3deeb7c 100644
--- a/src/rebar_port_compiler.erl
+++ b/src/rebar_port_compiler.erl
@@ -253,6 +253,12 @@ get_specs(Config, AppFile) ->
%% No spec provided. Construct a spec
%% from old-school so_name and sources
[port_spec_from_legacy(Config, AppFile)];
+ [{null,[]}] ->
+ [];
+ [null] ->
+ [];
+ [skip] ->
+ [];
PortSpecs ->
Filtered = filter_port_specs(PortSpecs),
OsType = os:type(),
--
1.8.1.4

View File

@ -1,32 +0,0 @@
From 13fd63738960c567d32df3061a2a4e5452dac0e1 Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Sat, 2 Mar 2013 10:39:15 +0400
Subject: [PATCH 06/10] Check system-wide libdir in case of source-based
dependency
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
---
src/rebar_deps.erl | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/src/rebar_deps.erl b/src/rebar_deps.erl
index 074e929..9cc82f7 100644
--- a/src/rebar_deps.erl
+++ b/src/rebar_deps.erl
@@ -305,7 +305,12 @@ find_dep(Config, Dep, _Source) ->
%% _Source is defined. Regardless of what it is, we must find it
%% locally satisfied or fetch it from the original source
%% into the project's deps
- find_dep_in_dir(Config, Dep, get_deps_dir(Config, Dep#dep.app)).
+ case find_dep_in_dir(Config, Dep, get_deps_dir(Config, Dep#dep.app)) of
+ {_Config1, {avail, _Dir}} = Avail ->
+ Avail;
+ {Config1, {missing, _}} ->
+ find_dep_in_dir(Config1, Dep, get_lib_dir(Dep#dep.app))
+ end.
find_dep_in_dir(Config, _Dep, {false, Dir}) ->
{Config, {missing, Dir}};
--
1.8.1.4

View File

@ -1,31 +0,0 @@
From 1900df4838d7623009b09fffaa6f23daa5da46c8 Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Sat, 2 Mar 2013 13:35:36 +0400
Subject: [PATCH 07/10] Remove any traces of long-time obsolete escript:foldl/3
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
---
src/rebar_utils.erl | 7 +------
1 file changed, 1 insertion(+), 6 deletions(-)
diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl
index bb58460..c86c210 100644
--- a/src/rebar_utils.erl
+++ b/src/rebar_utils.erl
@@ -155,12 +155,7 @@ abort(String, Args) ->
%% undocumented exported fun and has been removed in R14.
escript_foldl(Fun, Acc, File) ->
{module, zip} = code:ensure_loaded(zip),
- case erlang:function_exported(zip, foldl, 3) of
- true ->
- emulate_escript_foldl(Fun, Acc, File);
- false ->
- escript:foldl(Fun, Acc, File)
- end.
+ emulate_escript_foldl(Fun, Acc, File).
find_executable(Name) ->
case os:find_executable(Name) of
--
1.8.1.4

View File

@ -1,149 +0,0 @@
From ec4f8e74c6058e6ba61e9687cccf30ed9378dca2 Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Sat, 2 Mar 2013 13:52:04 +0400
Subject: [PATCH 08/10] Remove abnfc compiler support (n/a in Fedora/EPEL)
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
---
ebin/rebar.app | 2 -
src/rebar_abnfc_compiler.erl | 108 -------------------------------------------
2 files changed, 110 deletions(-)
delete mode 100644 src/rebar_abnfc_compiler.erl
diff --git a/ebin/rebar.app b/ebin/rebar.app
index cba8bf8..e84e905 100644
--- a/ebin/rebar.app
+++ b/ebin/rebar.app
@@ -5,7 +5,6 @@
[{description, "Rebar: Erlang Build Tool"},
{vsn, "2.1.0-pre"},
{modules, [ rebar,
- rebar_abnfc_compiler,
rebar_app_utils,
rebar_appups,
rebar_asn1_compiler,
@@ -61,7 +60,6 @@
%% Dir specific processing modules
{modules, [
{app_dir, [
- rebar_abnfc_compiler,
rebar_protobuffs_compiler,
rebar_neotoma_compiler,
rebar_asn1_compiler,
diff --git a/src/rebar_abnfc_compiler.erl b/src/rebar_abnfc_compiler.erl
deleted file mode 100644
index 0e6749a..0000000
--- a/src/rebar_abnfc_compiler.erl
+++ /dev/null
@@ -1,108 +0,0 @@
-%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
-%% ex: ts=4 sw=4 et
-%% -------------------------------------------------------------------
-%%
-%% rebar: Erlang Build Tools
-%%
-%% Copyright (c) 2010 Anthony Ramine (nox@dev-extend.eu),
-%%
-%% Permission is hereby granted, free of charge, to any person obtaining a copy
-%% of this software and associated documentation files (the "Software"), to deal
-%% in the Software without restriction, including without limitation the rights
-%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-%% copies of the Software, and to permit persons to whom the Software is
-%% furnished to do so, subject to the following conditions:
-%%
-%% The above copyright notice and this permission notice shall be included in
-%% all copies or substantial portions of the Software.
-%%
-%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-%% THE SOFTWARE.
-%% -------------------------------------------------------------------
-
-%% The rebar_abnfc_compiler module is a plugin for rebar that compiles
-%% ABNF grammars into parsers. By default, it compiles all src/*.abnf
-%% to src/*.erl.
-%%
-%% Configuration options should be placed in rebar.config under
-%% 'abnfc_opts'. Available options include:
-%%
-%% doc_root: where to find the ABNF grammars to compile
-%% "src" by default
-%%
-%% out_dir: where to put the generated files.
-%% "src" by default
-%%
-%% source_ext: the file extension the ABNF grammars have.
-%% ".abnf" by default
-%%
-%% module_ext: characters to append to the parser's module name
-%% "" by default
--module(rebar_abnfc_compiler).
-
--export([compile/2]).
-
--include("rebar.hrl").
-
-%% ===================================================================
-%% Public API
-%% ===================================================================
-
-compile(Config, _AppFile) ->
- DtlOpts = abnfc_opts(Config),
- rebar_base_compiler:run(Config, [],
- option(doc_root, DtlOpts),
- option(source_ext, DtlOpts),
- option(out_dir, DtlOpts),
- option(module_ext, DtlOpts) ++ ".erl",
- fun compile_abnfc/3).
-
-
-%% ===================================================================
-%% Internal functions
-%% ===================================================================
-
-abnfc_opts(Config) ->
- rebar_config:get(Config, abnfc_opts, []).
-
-option(Opt, DtlOpts) ->
- proplists:get_value(Opt, DtlOpts, default(Opt)).
-
-default(doc_root) -> "src";
-default(out_dir) -> "src";
-default(source_ext) -> ".abnf";
-default(module_ext) -> "".
-
-abnfc_is_present() ->
- code:which(abnfc) =/= non_existing.
-
-compile_abnfc(Source, _Target, Config) ->
- case abnfc_is_present() of
- false ->
- ?ERROR("~n===============================================~n"
- " You need to install abnfc to compile ABNF grammars~n"
- " Download the latest tarball release from github~n"
- " https://github.com/nygge/abnfc~n"
- " and install it into your erlang library dir~n"
- "===============================================~n~n", []),
- ?FAIL;
- true ->
- AbnfcOpts = abnfc_opts(Config),
- SourceExt = option(source_ext, AbnfcOpts),
- Opts = [noobj,
- {o, option(out_dir, AbnfcOpts)},
- {mod, filename:basename(Source, SourceExt) ++
- option(module_ext, AbnfcOpts)}],
- case abnfc:file(Source, Opts) of
- ok -> ok;
- Error ->
- ?ERROR("Compiling grammar ~s failed:~n ~p~n",
- [Source, Error]),
- ?FAIL
- end
- end.
--
1.8.1.4

View File

@ -1,26 +0,0 @@
From 15f315f3b3ec0d4e11186b9eabb9789b4c38b1b0 Mon Sep 17 00:00:00 2001
From: Peter Lemenkov <lemenkov@gmail.com>
Date: Sat, 2 Mar 2013 13:52:35 +0400
Subject: [PATCH 09/10] Adjust app version
Signed-off-by: Peter Lemenkov <lemenkov@gmail.com>
---
ebin/rebar.app | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/ebin/rebar.app b/ebin/rebar.app
index e84e905..3f0aabe 100644
--- a/ebin/rebar.app
+++ b/ebin/rebar.app
@@ -3,7 +3,7 @@
{application, rebar,
[{description, "Rebar: Erlang Build Tool"},
- {vsn, "2.1.0-pre"},
+ {vsn, "2.1.0"},
{modules, [ rebar,
rebar_app_utils,
rebar_appups,
--
1.8.1.4

View File

@ -1,26 +0,0 @@
From 4139a739f3cfafdb46e511f09b58644cd8c9addb Mon Sep 17 00:00:00 2001
From: serge <saleyn@gmail.com>
Date: Thu, 15 Nov 2012 16:34:06 -0500
Subject: [PATCH 10/10] Fix default DTL compilation when no erlydtl_opts are
provided
---
src/rebar_erlydtl_compiler.erl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/rebar_erlydtl_compiler.erl b/src/rebar_erlydtl_compiler.erl
index b5fe899..aef41c5 100644
--- a/src/rebar_erlydtl_compiler.erl
+++ b/src/rebar_erlydtl_compiler.erl
@@ -133,7 +133,7 @@ erlydtl_opts(Config) ->
Tuples = [{K,V} || {K,V} <- Opts],
case [L || L <- Opts, is_list(L), not io_lib:printable_list(L)] of
[] ->
- lists:keysort(1, Tuples);
+ [lists:keysort(1, Tuples)];
Lists ->
lists:map(fun(L) ->
lists:keysort(1, lists:foldl(fun({K,T}, Acc) ->
--
1.8.1.4

View File

@ -1,5 +0,0 @@
#!/usr/bin/env escript
%%! -noshell -noinput
main (Args) ->
rebar:main(Args).

View File

@ -1 +0,0 @@
43a094165eb54b474e6b6aa95f1b3f8b basho-rebar-2.1.0-pre-0-gebb474b.tar.gz