From 0f494c2a144a70e9fc6222bc8deb34c6d4016fb6 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Fri, 26 Mar 2010 19:28:01 +0100 Subject: [PATCH 1/5] Add check-deps to shell completion and commands info --- priv/shell-completion/bash/rebar | 2 +- src/rebar_core.erl | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/priv/shell-completion/bash/rebar b/priv/shell-completion/bash/rebar index 20c6ec6..3bc8387 100644 --- a/priv/shell-completion/bash/rebar +++ b/priv/shell-completion/bash/rebar @@ -8,7 +8,7 @@ _rebar() prev="${COMP_WORDS[COMP_CWORD-1]}" sopts="-h -c -v -f -j" lopts=" --help --commands --verbose --force --jobs=" - cmdsnvars="analyze build_plt check_plt clean compile \ + cmdsnvars="analyze build_plt check_plt check-deps clean compile \ create-app create-node delete-deps eunit \ get-deps generate install int_test perf_test test \ case= force=1 jobs= suite= verbose=1 appid= target= template=" diff --git a/src/rebar_core.erl b/src/rebar_core.erl index e721576..a6f2c68 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -173,6 +173,7 @@ commands() -> "create-app Create simple app skel~n" "create-node Create simple node skel~n" "~n" +"check-deps Display to be fetched dependencies~n" "get-deps Fetch dependencies~n" "delete-deps Delete fetched dependencies~n" "~n" From 3a1d2e433cca86baa06a33f5193605cbb41a8178 Mon Sep 17 00:00:00 2001 From: Tuncer Ayaz Date: Fri, 26 Mar 2010 19:31:07 +0100 Subject: [PATCH 2/5] Add create to shell completion --- priv/shell-completion/bash/rebar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/priv/shell-completion/bash/rebar b/priv/shell-completion/bash/rebar index 3bc8387..f36320a 100644 --- a/priv/shell-completion/bash/rebar +++ b/priv/shell-completion/bash/rebar @@ -9,7 +9,7 @@ _rebar() sopts="-h -c -v -f -j" lopts=" --help --commands --verbose --force --jobs=" cmdsnvars="analyze build_plt check_plt check-deps clean compile \ - create-app create-node delete-deps eunit \ + create create-app create-node delete-deps eunit \ get-deps generate install int_test perf_test test \ case= force=1 jobs= suite= verbose=1 appid= target= template=" From cf820007fcdce4b6da142321a687c523fc3749c9 Mon Sep 17 00:00:00 2001 From: Bryan Fink Date: Wed, 31 Mar 2010 11:35:06 -0400 Subject: [PATCH 3/5] add handling for yecc's .yrl files to erlc compiler --- src/rebar_erlc_compiler.erl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index 0320380..2684561 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -40,6 +40,9 @@ -spec compile(Config::#config{}, AppFile::string()) -> 'ok'. compile(Config, _AppFile) -> + rebar_base_compiler:run(Config, rebar_config:get_list(Config, yrl_first_files, []), + "src", ".yrl", "src", ".erl", + fun compile_yrl/3), doterl_compile(Config, "ebin"), rebar_base_compiler:run(Config, rebar_config:get_list(Config, mib_first_files, []), "mibs", ".mib", "priv/mibs", ".bin", @@ -52,6 +55,11 @@ clean(_Config, _AppFile) -> %% much slower. ok = rebar_file_utils:rm_rf("ebin/*.beam priv/mibs/*.bin"), + YrlFiles = rebar_utils:find_files("src", "^.*\\.yrl\$"), + rebar_file_utils:delete_each( + [ binary_to_list(iolist_to_binary(re:replace(F, "\\.yrl$", ".erl"))) + || F <- YrlFiles ]), + %% Erlang compilation is recursive, so it's possible that we have a nested %% directory structure in ebin with .beam files within. As such, we want %% to scan whatever is left in the ebin/ directory for sub-dirs which @@ -198,6 +206,33 @@ compile_mib(Source, Target, Config) -> ?FAIL end. +-spec compile_yrl(Source::string(), Target::string(), Config::#config{}) -> 'ok'. +compile_yrl(Source, Target, Config) -> + case yrl_needs_compile(Source, Target) of + true -> + Opts = [{parserfile, Target}, {return, true} + |rebar_config:get(Config, yrl_opts, [])], + case yecc:file(Source, Opts) of + {ok, _, []} -> + ok; + {ok, _, _Warnings} -> + case lists:member(fail_on_warnings, Config) of + true -> + ?FAIL; + false -> + ok + end; + _X -> + ?FAIL + end; + false -> + skipped + end. + +-spec yrl_needs_compile(Source::string(), Target::string()) -> boolean(). +yrl_needs_compile(Source, Target) -> + filelib:last_modified(Target) < filelib:last_modified(Source). + gather_src([], Srcs) -> Srcs; gather_src([Dir|Rest], Srcs) -> From e6e36834f93b3739652777ac9e3d30f0b24c94a0 Mon Sep 17 00:00:00 2001 From: Bryan Fink Date: Wed, 31 Mar 2010 15:03:29 -0400 Subject: [PATCH 4/5] add leex .xrl handling as well --- src/rebar_erlc_compiler.erl | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index 2684561..a476790 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -40,9 +40,14 @@ -spec compile(Config::#config{}, AppFile::string()) -> 'ok'. compile(Config, _AppFile) -> - rebar_base_compiler:run(Config, rebar_config:get_list(Config, yrl_first_files, []), + rebar_base_compiler:run(Config, + rebar_config:get_list(Config, xrl_yrl_first_files, []), + "src", ".xrl", "src", ".erl", + fun compile_xrl_yrl/3), + rebar_base_compiler:run(Config, + rebar_config:get_list(Config, xrl_yrl_first_files, []), "src", ".yrl", "src", ".erl", - fun compile_yrl/3), + fun compile_xrl_yrl/3), doterl_compile(Config, "ebin"), rebar_base_compiler:run(Config, rebar_config:get_list(Config, mib_first_files, []), "mibs", ".mib", "priv/mibs", ".bin", @@ -55,9 +60,9 @@ clean(_Config, _AppFile) -> %% much slower. ok = rebar_file_utils:rm_rf("ebin/*.beam priv/mibs/*.bin"), - YrlFiles = rebar_utils:find_files("src", "^.*\\.yrl\$"), + YrlFiles = rebar_utils:find_files("src", "^.*\\.[x|y]rl\$"), rebar_file_utils:delete_each( - [ binary_to_list(iolist_to_binary(re:replace(F, "\\.yrl$", ".erl"))) + [ binary_to_list(iolist_to_binary(re:replace(F, "\\.[x|y]rl$", ".erl"))) || F <- YrlFiles ]), %% Erlang compilation is recursive, so it's possible that we have a nested @@ -206,13 +211,12 @@ compile_mib(Source, Target, Config) -> ?FAIL end. --spec compile_yrl(Source::string(), Target::string(), Config::#config{}) -> 'ok'. -compile_yrl(Source, Target, Config) -> - case yrl_needs_compile(Source, Target) of +-spec compile_xrl_yrl(Source::string(), Target::string(), Config::#config{}) -> 'ok'. +compile_xrl_yrl(Source, Target, Config) -> + case xrl_yrl_needs_compile(Source, Target) of true -> - Opts = [{parserfile, Target}, {return, true} - |rebar_config:get(Config, yrl_opts, [])], - case yecc:file(Source, Opts) of + {match, [Ext]} = re:run(Source, "[x|y]rl$", [{capture, first, list}]), + case compile_xrl_yrl1(Source, Target, Config, Ext) of {ok, _, []} -> ok; {ok, _, _Warnings} -> @@ -229,8 +233,17 @@ compile_yrl(Source, Target, Config) -> skipped end. --spec yrl_needs_compile(Source::string(), Target::string()) -> boolean(). -yrl_needs_compile(Source, Target) -> +compile_xrl_yrl1(Source, Target, Config, "yrl") -> + Opts = [{parserfile, Target}, {return, true} + |rebar_config:get(Config, yrl_opts, [])], + yecc:file(Source, Opts); +compile_xrl_yrl1(Source, Target, Config, "xrl") -> + Opts = [{scannerfile, Target}, {return, true} + |rebar_config:get(Config, xrl_opts, [])], + leex:file(Source, Opts). + +-spec xrl_yrl_needs_compile(Source::string(), Target::string()) -> boolean(). +xrl_yrl_needs_compile(Source, Target) -> filelib:last_modified(Target) < filelib:last_modified(Source). gather_src([], Srcs) -> From 4f470fcddd6326dd85c3183fd78dbd0414a45ef5 Mon Sep 17 00:00:00 2001 From: Bryan Fink Date: Wed, 31 Mar 2010 15:21:13 -0400 Subject: [PATCH 5/5] clean up .yrl and .xrl handling --- src/rebar_erlc_compiler.erl | 43 ++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/src/rebar_erlc_compiler.erl b/src/rebar_erlc_compiler.erl index a476790..760111f 100644 --- a/src/rebar_erlc_compiler.erl +++ b/src/rebar_erlc_compiler.erl @@ -41,13 +41,13 @@ -spec compile(Config::#config{}, AppFile::string()) -> 'ok'. compile(Config, _AppFile) -> rebar_base_compiler:run(Config, - rebar_config:get_list(Config, xrl_yrl_first_files, []), + rebar_config:get_list(Config, xrl_first_files, []), "src", ".xrl", "src", ".erl", - fun compile_xrl_yrl/3), + fun compile_xrl/3), rebar_base_compiler:run(Config, - rebar_config:get_list(Config, xrl_yrl_first_files, []), + rebar_config:get_list(Config, yrl_first_files, []), "src", ".yrl", "src", ".erl", - fun compile_xrl_yrl/3), + fun compile_yrl/3), doterl_compile(Config, "ebin"), rebar_base_compiler:run(Config, rebar_config:get_list(Config, mib_first_files, []), "mibs", ".mib", "priv/mibs", ".bin", @@ -211,12 +211,24 @@ compile_mib(Source, Target, Config) -> ?FAIL end. --spec compile_xrl_yrl(Source::string(), Target::string(), Config::#config{}) -> 'ok'. -compile_xrl_yrl(Source, Target, Config) -> - case xrl_yrl_needs_compile(Source, Target) of +-spec compile_xrl(Source::string(), Target::string(), Config::#config{}) -> 'ok'. +compile_xrl(Source, Target, Config) -> + Opts = [{scannerfile, Target}, {return, true} + |rebar_config:get(Config, xrl_opts, [])], + compile_xrl_yrl(Source, Target, Config, Opts, leex). + +-spec compile_yrl(Source::string(), Target::string(), Config::#config{}) -> 'ok'. +compile_yrl(Source, Target, Config) -> + Opts = [{parserfile, Target}, {return, true} + |rebar_config:get(Config, yrl_opts, [])], + compile_xrl_yrl(Source, Target, Config, Opts, yecc). + +-spec compile_xrl_yrl(Source::string(), Target::string(), Config::#config{}, + Opts::list(), Mod::atom()) -> 'ok'. +compile_xrl_yrl(Source, Target, Config, Opts, Mod) -> + case needs_compile(Source, Target, []) of true -> - {match, [Ext]} = re:run(Source, "[x|y]rl$", [{capture, first, list}]), - case compile_xrl_yrl1(Source, Target, Config, Ext) of + case Mod:file(Source, Opts) of {ok, _, []} -> ok; {ok, _, _Warnings} -> @@ -233,19 +245,6 @@ compile_xrl_yrl(Source, Target, Config) -> skipped end. -compile_xrl_yrl1(Source, Target, Config, "yrl") -> - Opts = [{parserfile, Target}, {return, true} - |rebar_config:get(Config, yrl_opts, [])], - yecc:file(Source, Opts); -compile_xrl_yrl1(Source, Target, Config, "xrl") -> - Opts = [{scannerfile, Target}, {return, true} - |rebar_config:get(Config, xrl_opts, [])], - leex:file(Source, Opts). - --spec xrl_yrl_needs_compile(Source::string(), Target::string()) -> boolean(). -xrl_yrl_needs_compile(Source, Target) -> - filelib:last_modified(Target) < filelib:last_modified(Source). - gather_src([], Srcs) -> Srcs; gather_src([Dir|Rest], Srcs) ->