diff options
author | Fred Hebert <mononcqc@ferd.ca> | 2015-05-09 14:03:30 -0400 |
---|---|---|
committer | Fred Hebert <mononcqc@ferd.ca> | 2015-05-09 14:03:30 -0400 |
commit | e200ca1ae3f338bf324f387ee6771de7ffe74a4b (patch) | |
tree | bca2a9216a3ca0cae9d38b6784b0557c7edc214f | |
parent | bb92ba9352a21054090ff79f5f6ddd516e76b994 (diff) | |
parent | b22487df5a92c00f7b0c00156cda83b142e934ac (diff) | |
download | rebar-e200ca1ae3f338bf324f387ee6771de7ffe74a4b.tar.gz |
Merge branch 'dia_first_files' of https://github.com/fholzhauser/rebar into fholzhauser-dia_first_files
-rw-r--r-- | rebar.config.sample | 8 | ||||
-rw-r--r-- | src/rebar_dia_compiler.erl | 47 |
2 files changed, 47 insertions, 8 deletions
diff --git a/rebar.config.sample b/rebar.config.sample index 91d3dff..90ea6ee 100644 --- a/rebar.config.sample +++ b/rebar.config.sample @@ -104,6 +104,14 @@ %% if selected by the proto_compiler option {gpb_opts, []}. +%% == Diameter compiler == + +%% Diameter files to compile before the rest +{dia_first_files, []}. + +%% Options for the diameter compiler +{dia_opts, []}. + %% == EUnit == %% Options for eunit:test() diff --git a/src/rebar_dia_compiler.erl b/src/rebar_dia_compiler.erl index 5ea84d7..56d5189 100644 --- a/src/rebar_dia_compiler.erl +++ b/src/rebar_dia_compiler.erl @@ -40,12 +40,26 @@ -spec compile(rebar_config:config(), file:filename()) -> 'ok'. compile(Config, _AppFile) -> - rebar_base_compiler:run(Config, filelib:wildcard("dia/*.dia"), + DiaOpts = rebar_config:get(Config, dia_opts, []), + IncludeEbin = proplists:get_value(include, DiaOpts, []), + DiaFiles = filelib:wildcard("dia/*.dia"), + code:add_pathsz(["ebin" | IncludeEbin]), + FileSequence = case rebar_config:get(Config, dia_first_files, []) of + [] -> + DiaFiles; + CompileFirst -> + CompileFirst ++ + [F || F <- DiaFiles, not lists:member(F, CompileFirst)] + end, + rebar_base_compiler:run(Config, FileSequence, "dia", ".dia", "src", ".erl", fun compile_dia/3). -spec clean(rebar_config:config(), file:filename()) -> 'ok'. -clean(_Config, _AppFile) -> +clean(Config, _AppFile) -> + DiaOpts = rebar_config:get(Config, dia_opts, []), + IncludeEbin = proplists:get_value(include, DiaOpts, []), + code:add_pathsz(["ebin" | IncludeEbin]), GeneratedFiles = dia_generated_files("dia", "src", "include"), ok = rebar_file_utils:delete_each(GeneratedFiles), ok. @@ -64,7 +78,9 @@ info_help(Description) -> "~s.~n" "~n" "Valid rebar.config options:~n" - " {dia_opts, []} (see diameter_codegen:from_dict/4 documentation)~n", + " {dia_opts, []} (options from diameter_make:codec/2 supported with~n" + " exception of inherits)~n" + " {dia_first_files, []} (files in sequence to compile first)~n", [Description]). -spec compile_dia(file:filename(), file:filename(), @@ -79,6 +95,10 @@ compile_dia(Source, Target, Config) -> _ = diameter_codegen:from_dict(FileName, Spec, Opts, erl), _ = diameter_codegen:from_dict(FileName, Spec, Opts, hrl), HrlFile = filename:join("src", FileName ++ ".hrl"), + ErlFile = filename:join("src", FileName ++ ".erl"), + ErlCOpts = [{outdir, "ebin"}] ++ + rebar_config:get(Config, erl_opts, []), + _ = compile:file(ErlFile, ErlCOpts), case filelib:is_regular(HrlFile) of true -> ok = rebar_file_utils:mv(HrlFile, "include"); @@ -86,15 +106,26 @@ compile_dia(Source, Target, Config) -> ok end; {error, Reason} -> - ?ERROR("~s~n", [diameter_dict_util:format_error(Reason)]) + ?ABORT( + "Compiling ~s failed: ~s~n", + [Source, diameter_dict_util:format_error(Reason)] + ) end. dia_generated_files(DiaDir, SrcDir, IncDir) -> F = fun(File, Acc) -> - {ok, Spec} = diameter_dict_util:parse({path, File}, []), - FileName = dia_filename(File, Spec), - [filename:join([IncDir, FileName ++ ".hrl"]) | - filelib:wildcard(filename:join([SrcDir, FileName ++ ".*"]))] ++ Acc + case catch diameter_dict_util:parse({path, File}, []) of + {ok, Spec} -> + FileName = dia_filename(File, Spec), + [ + filename:join([IncDir, FileName ++ ".hrl"]) | + filelib:wildcard( + filename:join([SrcDir, FileName ++ ".*"]) + ) + ] ++ Acc; + _ -> + Acc + end end, lists:foldl(F, [], filelib:wildcard(filename:join([DiaDir, "*.dia"]))). |