The number of erl files in the application I am working on is above 100. So, I want to create subfolders inside the src and test directories of the application to organize code better.
What is the support for such code organization in OTP version 25?
It depends on your build tool, but IIRC the Rebar3 do not give a damn about the directory structure.
Thanks @hualeth. I tried rebar3 but it doesn’t seem to be finding sources that are inside the subfolder.
We use subfolders in epgsql. It works fine with rebar3.
It causes some problems from time to time to the library users who use custom build tools, because it’s not common to have subfolders. But by-default it works well
What version of rebar3? Can you share an example?
Here’s an example :
$ ls src/foo/bar/
baz.erl
$ rebar3 shell
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling recurse
Erlang/OTP 24 [erts-12.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [dtrace]
Eshell V12.2 (abort with ^G)
1> baz:foo().
bar
There’s nothing special in rebar.confg
in this case.
I think the only condition is that you have <app_name>.app.src
directly in the src
directory:
$ rm -r _build
$ tree .
.
├── rebar.lock
└── src
├── rebar_subfolder.app.src
└── sub
└── foo.erl
2 directories, 3 files
$ rebar3 shell
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling rebar_subfolder
===> "<..>/rebar-subfolder/_build/default/lib/rebar_subfolder/ebin/rebar_subfolder.app" is missing description entry
Erlang/OTP 23 Klarna-gce052dd841 [erts-11.2] [source-ce052dd841] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]
Eshell V11.2 (abort with ^G)
1> foo:bar().
foo
TIL…
Thanks everyone! The problem in my case is that the -include() and -include_lib() dont work fine when the files are moved around.
I use rebar3 as well.
Does any configuration need to be changed for includes to lookup files one more level deeper.
You can check epgsql as example.
This file is in the /src/commands
subfolder:
-include("epgsql.hrl").
-include("protocol.hrl").
-include("../epgsql_copy.hrl").
epgsql.hrl
and protocol.hrl
are in /include
epgsql_copy.hrl
is in the /src