Skip to content

Commit

Permalink
Merge pull request #16 from sebastiw/allow-asn-extensions
Browse files Browse the repository at this point in the history
Allow .asn extensions
  • Loading branch information
sebastiw authored Jun 26, 2023
2 parents 2ade47c + 70e41c9 commit b8c5ca7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ The options are as follows:
the specific order to compile the ASN.1 files where the first
tuple-element is one of `wildcard` | `file` | `dir` and the second
the filename in string format. Defaults to
`[{wildcard, \"**/*.asn1\"}]`.
`[{wildcard, \"**/*.{asn1,asn}\"}]`.
* `--overrides -O` An Erlang term consisting of a tuple-list of the
compile options that will override the options per file. The first
tuple-element is one of `file` | `re` and the second the filename
Expand Down
4 changes: 2 additions & 2 deletions src/provider_asn1_clean.erl
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ do_clean(State, AppPath) ->
IncludePath = filename:join(AppPath, "include"),
SrcPath = filename:join(AppPath, "src"),

Asns = filelib:wildcard("**/*.asn1", AsnPath),
Asns = filelib:wildcard("**/*.{asn1,asn}", AsnPath),
lists:foreach(
fun(AsnFile) ->
Base = filename:basename(AsnFile, ".asn1"),
Base = provider_asn1_util:asn_basename(AsnFile),
provider_asn1_util:delete_file(State, SrcPath, Base ++ ".erl"),
provider_asn1_util:delete_file(State, IncludePath, Base ++ ".hrl")
end, Asns),
Expand Down
8 changes: 4 additions & 4 deletions src/provider_asn1_compile.erl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
-define(PROVIDER, 'compile').
-define(DEPS, [{default, app_discovery}]).
-define(DEFAULTS, [{verbose, false}, {encoding, ber}, {compile_opts, []},
{compile_order, [{wildcard, "**/*.asn1"}]}]).
{compile_order, [{wildcard, "**/*.{asn1,asn}"}]}]).

%% ===================================================================
%% Public API
Expand Down Expand Up @@ -110,7 +110,7 @@ process_app(State, AppPath) ->
move_asns(State, GenPath, SrcPath, IncludePath, Asns) ->
lists:foreach(
fun(AsnFile) ->
Base = filename:basename(AsnFile, ".asn1"),
Base = provider_asn1_util:asn_basename(AsnFile),
provider_asn1_util:move_file(State, GenPath, Base ++ ".erl", SrcPath),
provider_asn1_util:delete_file(State, GenPath, Base ++ ".asn1db"),
provider_asn1_util:move_file(State, GenPath, Base ++ ".hrl", IncludePath)
Expand Down Expand Up @@ -158,7 +158,7 @@ find_asn_files(State, BasePath) ->
[filename:join(BasePath, File)];
({dir, Dir}) ->
D = filename:join(BasePath, Dir),
[filename:join(D, F) || F <- filelib:wildcard("*.asn1", D)]
[filename:join(D, F) || F <- filelib:wildcard("*.{asn1,asn}", D)]
end, Order),
uniq(Fs).

Expand All @@ -177,7 +177,7 @@ uniq(Fs) ->

is_latest(ASNFileName, ASNPath, GenPath) ->
Source = filename:join(ASNPath, ASNFileName),
TargetFileName = filename:basename(ASNFileName, ".asn1") ++ ".erl",
TargetFileName = provider_asn1_util:asn_basename(ASNFileName) ++ ".erl",
Target = filename:join(GenPath, TargetFileName),
filelib:last_modified(Source) > filelib:last_modified(Target).

Expand Down
7 changes: 6 additions & 1 deletion src/provider_asn1_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
resolve_args/2,
get_args/1,
get_arg/2,
set_arg/3]).
set_arg/3,
asn_basename/1
]).

verbose_out(State, FormatString, Args)->
CommArgs = get_args(State),
Expand Down Expand Up @@ -71,3 +73,6 @@ set_arg(State, Key, Val) ->
Args = rebar_state:get(State, asn1_args, []),
ArgsMap = maps:from_list(Args),
rebar_state:set(State, asn1_args, maps:to_list(maps:put(Key, Val, ArgsMap))).

asn_basename(ASNFileName) ->
filename:basename(filename:basename(filename:basename(ASNFileName, ".asn1"), ".asn"), ".set").

0 comments on commit b8c5ca7

Please sign in to comment.