From 6fb6b0422826c4b9efa1b7ea2cad3ea18241cb08 Mon Sep 17 00:00:00 2001 From: "Paul J. Davis" Date: Fri, 18 Mar 2016 15:48:20 -0500 Subject: [PATCH] Add support for rebar3 This should hopefully allow users to use rebar3 to compile jiffy while also not breaking any project still using rebar2. --- .gitignore | 2 + rebar.config | 10 +--- rebar.config.script | 75 ++++++++++++++++++---------- test/jiffy_10_short_double_tests.erl | 9 +++- 4 files changed, 61 insertions(+), 35 deletions(-) diff --git a/.gitignore b/.gitignore index e3e5e72..8e4374c 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,10 @@ .jiffy.dev *.app *.beam +*.d *.o *.so +_build deps erln8.config hexer.config diff --git a/rebar.config b/rebar.config index 9d26448..9110127 100644 --- a/rebar.config +++ b/rebar.config @@ -33,13 +33,5 @@ ]}. {eunit_opts, [ - verbose, - {report, { - eunit_surefire, [{dir,"."}] - }} + verbose ]}. - -{plugins, [ - rebar_gdb_plugin -]}. - diff --git a/rebar.config.script b/rebar.config.script index 8a0049d..2159a10 100644 --- a/rebar.config.script +++ b/rebar.config.script @@ -7,31 +7,56 @@ % % This script is based on the example provided with Rebar. -ErlOpts = [{d, 'JIFFY_DEV'}], +IsRebar3 = erlang:function_exported(rebar3, main, 1), + +PropErUrl = "git://github.com/manopapad/proper.git", +PortCompilerUrl = "git@github.com:blt/port_compiler.git", -Proper = [ - {proper, ".*", {git, "git://github.com/manopapad/proper.git", "master"}} -], -ConfigPath = filename:dirname(SCRIPT), -DevMarker = filename:join([ConfigPath, ".jiffy.dev"]), - -case filelib:is_file(DevMarker) of - true -> - % Don't override existing dependencies - Config0 = case lists:keyfind(deps, 1, CONFIG) of - false -> - CONFIG ++ [{deps, Proper}]; - {deps, DepsList} -> - lists:keyreplace(deps, 1, CONFIG, {deps, DepsList ++ Proper}) - end, - Config1 = case lists:keyfind(erl_opts, 1, Config0) of - false -> - Config0 ++ [{erl_opts, ErlOpts}]; - {erl_opts, Opts} -> - NewOpts = {erl_opts, Opts ++ ErlOpts}, - lists:keyreplace(erl_opts, 1, Config0, NewOpts) - end; - false -> - CONFIG +IsDevEnv = begin + ConfigPath = filename:dirname(SCRIPT), + DevMarker = filename:join([ConfigPath, ".jiffy.dev"]), + filelib:is_file(DevMarker) end. + +Deps = if not IsDevEnv -> []; true -> + [{proper, ".*", {git, PropErUrl, {branch, "master"}}}] +end, + +ErlOpts = if not IsDevEnv -> []; true -> + [{d, 'JIFFY_DEV'}] +end, + +Plugins = case IsRebar3 of + true -> [{pc, {git, PortCompilerUrl, {branch, "master"}}}]; + false -> [rebar_gdb_plugin] +end, + +ProviderHooks = if not IsRebar3 -> []; true -> + [{pre, [ + {compile, {pc, compile}}, + {clean, {pc, clean}} + ]}] +end, + +OptsToAdd = [ + {deps, Deps}, + {erl_opts, ErlOpts}, + {plugins, Plugins}, + {provider_hooks, ProviderHooks} +], + +AddOpt = fun(Name, Value, Config) when is_list(Value) -> + case lists:keyfind(Name, 1, Config) of + {Name, CurrVal} when is_list(CurrVal) -> + lists:keyreplace(Name, 1, Config, {Name, CurrVal ++ Value}); + false -> + Config ++ [{Name, Value}]; + _ -> + Config + end +end, + +lists:foldl(fun({Name, Value}, CfgAcc) -> + AddOpt(Name, Value, CfgAcc) +end, CONFIG, OptsToAdd). diff --git a/test/jiffy_10_short_double_tests.erl b/test/jiffy_10_short_double_tests.erl index d66e1ea..9d9a078 100644 --- a/test/jiffy_10_short_double_tests.erl +++ b/test/jiffy_10_short_double_tests.erl @@ -8,7 +8,14 @@ -include("jiffy_util.hrl"). -filename() -> "../test/cases/short-doubles.txt". +filename() -> + {ok, Cwd} = file:get_cwd(), + case filename:basename(Cwd) of + ".eunit" -> + "../test/cases/short-doubles.txt"; + _ -> + "test/cases/short-doubles.txt" + end. short_double_test_() ->